1 19 20 package org.netbeans.api.languages; 21 22 import java.util.List ; 23 24 27 public final class ASTToken extends ASTItem { 28 29 private String identifier; 30 private String type; 31 32 33 44 public static ASTToken create ( 45 String mimeType, 46 String type, 47 String identifier, 48 int offset, 49 int length, 50 List <? extends ASTItem> children 51 ) { 52 return new ASTToken ( 53 mimeType, 54 type, 55 identifier, 56 offset, 57 length, 58 children 59 ); 60 } 61 62 63 73 public static ASTToken create ( 74 String mimeType, 75 String type, 76 String identifier, 77 int offset 78 ) { 79 return new ASTToken ( 80 mimeType, 81 type, 82 identifier, 83 offset, 84 identifier == null ? 0 : identifier.length (), 85 null 86 ); 87 } 88 89 90 private ASTToken ( 91 String mimeType, 92 String type, 93 String identifier, 94 int offset, 95 int length, 96 List <? extends ASTItem> children 97 ) { 98 super (mimeType, offset, length, children); 99 this.identifier = identifier; 100 this.type = type; 101 } 102 103 108 public String getType () { 109 return type; 110 } 111 112 113 118 public String getIdentifier () { 119 return identifier; 120 } 121 122 private String toString; 123 124 129 public String toString () { 130 if (toString == null) { 131 StringBuffer sb = new StringBuffer (); 132 sb.append ('<').append (type); 133 if (identifier != null) 134 sb.append (",'"). 135 append (e (identifier)). 136 append ("'"); 137 sb.append ('>'); 138 toString = sb.toString (); 139 } 140 return toString; 141 } 142 143 private static String e (CharSequence t) { 144 StringBuilder sb = new StringBuilder (); 145 int i, k = t.length (); 146 for (i = 0; i < k; i++) { 147 if (t.charAt (i) == '\t') 148 sb.append ("\\t"); 149 else 150 if (t.charAt (i) == '\r') 151 sb.append ("\\r"); 152 else 153 if (t.charAt (i) == '\n') 154 sb.append ("\\n"); 155 else 156 sb.append (t.charAt (i)); 157 } 158 return sb.toString (); 159 } 160 } | Popular Tags |