update copyrights
[fedora-idea.git] / platform / lang-impl / src / com / intellij / codeInsight / template / impl / Variable.java
blob6144d980a4b39800142687923ec71d849b0ec202
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.intellij.codeInsight.template.impl;
19 import com.intellij.codeInsight.template.Expression;
21 public class Variable implements Cloneable {
22 private final String myName;
23 private boolean myAlwaysStopAt;
25 private String myExpressionString;
26 private Expression myExpression = null;
28 private String myDefaultValueString;
29 private Expression myDefaultValueExpression;
31 public Variable(String name, Expression expression, Expression defaultValueExpression, boolean alwaysStopAt) {
32 myName = name;
33 myExpression = expression;
34 myDefaultValueExpression = defaultValueExpression;
35 myAlwaysStopAt = alwaysStopAt;
38 public Variable(String name, String expression, String defaultValueString, boolean alwaysStopAt) {
39 myName = name;
40 myExpressionString = expression;
41 myDefaultValueString = defaultValueString;
42 myAlwaysStopAt = alwaysStopAt;
45 public String getExpressionString() {
46 return myExpressionString;
49 public void setExpressionString(String expressionString) {
50 myExpressionString = expressionString;
51 myExpression = null;
54 public Expression getExpression() {
55 if (myExpression == null) {
56 if (myName.equals(TemplateImpl.SELECTION)) {
57 myExpression = new SelectionNode();
59 else {
60 myExpression = MacroParser.parse(myExpressionString);
63 return myExpression;
66 public String getDefaultValueString() {
67 return myDefaultValueString;
70 public void setDefaultValueString(String defaultValueString) {
71 myDefaultValueString = defaultValueString;
72 myDefaultValueExpression = null;
75 public Expression getDefaultValueExpression() {
76 if (myDefaultValueExpression == null) {
77 myDefaultValueExpression = MacroParser.parse(myDefaultValueString);
79 return myDefaultValueExpression;
82 public String getName() {
83 return myName;
86 public boolean isAlwaysStopAt() {
87 if (myName.equals(TemplateImpl.SELECTION)) return false;
88 return myAlwaysStopAt;
91 public void setAlwaysStopAt(boolean alwaysStopAt) {
92 myAlwaysStopAt = alwaysStopAt;
95 public Object clone() {
96 return new Variable(myName, myExpressionString, myDefaultValueString, myAlwaysStopAt);
99 public boolean equals(Object o) {
100 if (this == o) return true;
101 if (!(o instanceof Variable)) return false;
103 final Variable variable = (Variable) o;
105 if (myAlwaysStopAt != variable.myAlwaysStopAt) return false;
106 if (myDefaultValueString != null ? !myDefaultValueString.equals(variable.myDefaultValueString) : variable.myDefaultValueString != null) return false;
107 if (myExpressionString != null ? !myExpressionString.equals(variable.myExpressionString) : variable.myExpressionString != null) return false;
108 if (myName != null ? !myName.equals(variable.myName) : variable.myName != null) return false;
110 return true;
113 public int hashCode() {
114 int result;
115 result = (myName != null ? myName.hashCode() : 0);
116 result = 29 * result + (myAlwaysStopAt ? 1 : 0);
117 result = 29 * result + (myExpressionString != null ? myExpressionString.hashCode() : 0);
118 result = 29 * result + (myDefaultValueString != null ? myDefaultValueString.hashCode() : 0);
119 return result;