1 19 20 package org.netbeans.modules.lexer.gen; 21 22 import java.util.HashMap ; 23 import java.util.List ; 24 import java.util.ArrayList ; 25 import java.util.Iterator ; 26 import org.netbeans.modules.lexer.gen.util.LexerGenUtilities; 27 28 35 36 public class MutableTokenId { 37 38 public static final String SAMPLE_TEXT_CHECK_NONE = "none"; 39 public static final String SAMPLE_TEXT_CHECK_LENGTH = "length"; 40 public static final String SAMPLE_TEXT_CHECK_TEXT = "text"; 41 42 private final LanguageData languageData; 43 44 private final String name; 45 46 private int intId; 47 48 private String tokenTypeName; 49 50 private List categoryNames; 51 52 private List sampleTexts; 53 54 private String sampleTextCheck; 55 56 private boolean caseInsensitive; 57 58 private String comment; 59 60 61 65 public MutableTokenId(LanguageData languageData, String name) { 66 this.languageData = languageData; 67 this.name = name; 68 this.intId = -1; 70 categoryNames = new ArrayList (); 71 sampleTexts = new ArrayList (); 72 } 73 74 77 public final LanguageData getLanguageData() { 78 return languageData; 79 } 80 81 84 public String getName() { 85 return name; 86 } 87 88 92 public int getIntId() { 93 return intId; 94 } 95 96 102 public void setIntId(int intId) { 103 this.intId = intId; 104 languageData.skipIntId(intId); 106 } 107 108 112 public String getFieldName() { 113 return LexerGenUtilities.idToUpperCase(getName()); 114 } 115 116 120 public String getIntIdFieldName() { 121 return getFieldName() + "_INT"; 122 } 123 124 128 public void assignUniqueIntId() { 129 setIntId(languageData.uniqueIntId()); 130 } 131 132 139 public String getTokenTypeName() { 140 return tokenTypeName; 141 } 142 143 public void updateByTokenType(String tokenTypeName) { 144 this.tokenTypeName = tokenTypeName; 145 languageData.getTokenTypes().updateId(this); 146 } 147 148 152 public List getCategoryNames() { 153 return categoryNames; 154 } 155 156 171 public boolean isCaseInsensitive() { 172 return caseInsensitive; 173 } 174 175 183 public void setCaseInsensitive(boolean caseInsensitive) { 184 this.caseInsensitive = caseInsensitive; 185 186 if (caseInsensitive) { Iterator currentSamplesIterator = new ArrayList (sampleTexts).iterator(); 188 sampleTexts.clear(); 189 while (currentSamplesIterator.hasNext()) { 190 addSampleText((String )currentSamplesIterator.next()); 191 } 192 } 193 } 194 195 198 public void addSampleText(String sampleText) { 199 addUniqueSampleText(sampleText); 200 201 if (caseInsensitive) { 202 addUniqueSampleText(sampleText.toLowerCase()); 203 addUniqueSampleText(sampleText.toUpperCase()); 204 } 205 } 206 207 private void addUniqueSampleText(String sampleText) { 208 if (sampleTexts.indexOf(sampleText) == -1) { 209 sampleTexts.add(sampleText); 210 } 211 } 212 213 215 public List getSampleTexts() { 216 return sampleTexts; 217 } 218 219 222 public void resetSamples() { 223 sampleTexts.clear(); 224 } 225 226 public String getSampleTextCheck() { 227 return sampleTextCheck; 228 } 229 230 public void setSampleTextCheck(String sampleTextCheck) { 231 this.sampleTextCheck = sampleTextCheck; 232 } 233 234 public String getComment() { 235 return comment; 236 } 237 238 public void setComment(String comment) { 239 this.comment = comment; 240 } 241 242 public String toString() { 243 StringBuffer sb = new StringBuffer (); 244 sb.append(getName()); 245 sb.append(", intId="); 246 sb.append(getIntId()); 247 sb.append(", tokenType="); 248 sb.append(getTokenTypeName()); 249 List samples = getSampleTexts(); 250 int samplesCount = samples.size(); 251 for (int i = 0; i < samplesCount; i++) { 252 if (i == 0) { 253 sb.append(", samples={"); 254 } 255 sb.append('"'); 256 sb.append(samples.get(i)); 257 sb.append('"'); 258 if (i == samplesCount - 1) { 259 sb.append('}'); 260 } 261 } 262 sb.append(", sampleTextCheck="); 263 sb.append(getSampleTextCheck()); 264 265 return sb.toString(); 266 } 267 268 } 269 | Popular Tags |