1 11 package org.eclipse.jface.text.templates; 12 13 import org.eclipse.core.runtime.Assert; 14 15 import org.eclipse.jface.text.TextUtilities; 16 17 33 public class TemplateVariable { 34 35 36 private final TemplateVariableType fType; 37 38 private final String fName; 39 40 private final int fInitialLength; 41 42 private int[] fOffsets; 43 44 private boolean fIsUnambiguous; 45 46 private boolean fIsResolved; 47 51 private String [] fValues; 52 53 61 public TemplateVariable(String type, String defaultValue, int[] offsets) { 62 this(type, new String [] { defaultValue }, offsets); 63 } 64 65 73 public TemplateVariable(String type, String name, String defaultValue, int[] offsets) { 74 this(type, name, new String [] { defaultValue }, offsets); 75 } 76 77 86 public TemplateVariable(TemplateVariableType type, String name, String defaultValue, int[] offsets) { 87 this(type, name, new String [] { defaultValue }, offsets); 88 } 89 90 98 public TemplateVariable(String type, String [] values, int[] offsets) { 99 this(type, type, values, offsets); 100 } 101 102 110 public TemplateVariable(String type, String name, String [] values, int[] offsets) { 111 this(new TemplateVariableType(type), name, values, offsets); 112 } 113 114 123 TemplateVariable(TemplateVariableType type, String name, String [] values, int[] offsets) { 124 Assert.isNotNull(type); 125 Assert.isNotNull(name); 126 fType= type; 127 fName= name; 128 setValues(values); 129 setOffsets(offsets); 130 setUnambiguous(false); 131 setResolved(false); 132 fInitialLength= values[0].length(); 133 } 134 135 140 public String getType() { 141 return fType.getName(); 142 } 143 144 150 public TemplateVariableType getVariableType() { 151 return fType; 152 } 153 154 159 public String getName() { 160 return fName; 161 } 162 163 169 public String getDefaultValue() { 170 return getValues()[0]; 171 } 172 173 179 public String [] getValues() { 180 return fValues; 181 } 182 183 188 public int getLength() { 189 return getDefaultValue().length(); 190 } 191 192 200 final int getInitialLength() { 201 return fInitialLength; 202 } 203 204 209 public void setOffsets(int[] offsets) { 210 fOffsets= TextUtilities.copy(offsets); 211 } 212 213 219 public int[] getOffsets() { 220 return fOffsets; 221 } 222 223 229 public final void setValue(String value) { 230 setValues(new String [] { value }); 231 } 232 233 239 public void setValues(String [] values) { 240 Assert.isTrue(values.length > 0); 241 fValues= TextUtilities.copy(values); 242 setResolved(true); 243 } 244 245 250 public void setUnambiguous(boolean unambiguous) { 251 fIsUnambiguous= unambiguous; 252 if (unambiguous) 253 setResolved(true); 254 } 255 256 261 public boolean isUnambiguous() { 262 return fIsUnambiguous; 263 } 264 265 271 public void setResolved(boolean resolved) { 272 fIsResolved= resolved; 273 } 274 275 282 public boolean isResolved() { 283 return fIsResolved; 284 } 285 } 286 | Popular Tags |