1 7 8 package javax.lang.model; 9 10 import java.util.Collections ; 11 import java.util.Set ; 12 import java.util.HashSet ; 13 14 31 public enum SourceVersion { 32 41 42 48 RELEASE_0, 49 50 57 RELEASE_1, 58 59 67 RELEASE_2, 68 69 75 RELEASE_3, 76 77 83 RELEASE_4, 84 85 94 RELEASE_5, 95 96 102 RELEASE_6; 103 104 105 110 public static SourceVersion latest() { 111 return RELEASE_6; 112 } 113 114 121 public static SourceVersion latestSupported() { 122 return RELEASE_6; 123 } 124 125 142 public static boolean isIdentifier(CharSequence name) { 143 String id = name.toString(); 144 145 if (id.length() == 0) { 146 return false; 147 } 148 int cp = id.codePointAt(0); 149 if (!Character.isJavaIdentifierStart(cp)) { 150 return false; 151 } 152 for (int i = Character.charCount(cp); 153 i < id.length(); 154 i += Character.charCount(cp)) { 155 cp = id.codePointAt(i); 156 if (!Character.isJavaIdentifierPart(cp)) { 157 return false; 158 } 159 } 160 return true; 161 } 162 163 174 public static boolean isName(CharSequence name) { 175 String id = name.toString(); 176 177 for(String s : id.split("\\.", -1)) { 178 if (!isIdentifier(s) || isKeyword(s)) 179 return false; 180 } 181 return true; 182 } 183 184 private final static Set <String > keywords; 185 static { 186 Set <String > s = new HashSet <String >(); 187 String [] kws = { 188 "abstract", "continue", "for", "new", "switch", 189 "assert", "default", "if", "package", "synchronized", 190 "boolean", "do", "goto", "private", "this", 191 "break", "double", "implements", "protected", "throw", 192 "byte", "else", "import", "public", "throws", 193 "case", "enum", "instanceof", "return", "transient", 194 "catch", "extends", "int", "short", "try", 195 "char", "final", "interface", "static", "void", 196 "class", "finally", "long", "strictfp", "volatile", 197 "const", "float", "native", "super", "while", 198 "null", "true", "false" 200 }; 201 for(String kw : kws) 202 s.add(kw); 203 keywords = Collections.unmodifiableSet(s); 204 } 205 206 213 public static boolean isKeyword(CharSequence s) { 214 String keywordOrLiteral = s.toString(); 215 return keywords.contains(keywordOrLiteral); 216 } 217 } 218 | Popular Tags |