1 19 20 package org.netbeans.api.java.lexer; 21 22 import java.util.Collection ; 23 import java.util.EnumSet ; 24 import java.util.HashMap ; 25 import java.util.Map ; 26 import org.netbeans.api.lexer.InputAttributes; 27 import org.netbeans.api.lexer.Language; 28 import org.netbeans.api.lexer.LanguagePath; 29 import org.netbeans.api.lexer.Token; 30 import org.netbeans.api.lexer.TokenId; 31 import org.netbeans.lib.java.lexer.JavaLexer; 32 import org.netbeans.spi.lexer.LanguageEmbedding; 33 import org.netbeans.spi.lexer.LanguageHierarchy; 34 import org.netbeans.spi.lexer.Lexer; 35 import org.netbeans.spi.lexer.LexerRestartInfo; 36 37 42 public enum JavaTokenId implements TokenId { 43 44 ERROR(null, "error"), 45 IDENTIFIER(null, "identifier"), 46 47 ABSTRACT("abstract", "keyword"), 48 ASSERT("assert", "keyword"), 49 BOOLEAN("boolean", "keyword"), 50 BREAK("break", "keyword"), 51 BYTE("byte", "keyword"), 52 CASE("case", "keyword"), 53 CATCH("catch", "keyword"), 54 CHAR("char", "keyword"), 55 CLASS("class", "keyword"), 56 CONST("const", "keyword"), 57 CONTINUE("continue", "keyword"), 58 DEFAULT("default", "keyword"), 59 DO("do", "keyword"), 60 DOUBLE("double", "keyword"), 61 ELSE("else", "keyword"), 62 ENUM("enum", "keyword"), 63 EXTENDS("extends", "keyword"), 64 FINAL("final", "keyword"), 65 FINALLY("finally", "keyword"), 66 FLOAT("float", "keyword"), 67 FOR("for", "keyword"), 68 GOTO("goto", "keyword"), 69 IF("if", "keyword"), 70 IMPLEMENTS("implements", "keyword"), 71 IMPORT("import", "keyword"), 72 INSTANCEOF("instanceof", "keyword"), 73 INT("int", "keyword"), 74 INTERFACE("interface", "keyword"), 75 LONG("long", "keyword"), 76 NATIVE("native", "keyword"), 77 NEW("new", "keyword"), 78 PACKAGE("package", "keyword"), 79 PRIVATE("private", "keyword"), 80 PROTECTED("protected", "keyword"), 81 PUBLIC("public", "keyword"), 82 RETURN("return", "keyword"), 83 SHORT("short", "keyword"), 84 STATIC("static", "keyword"), 85 STRICTFP("strictfp", "keyword"), 86 SUPER("super", "keyword"), 87 SWITCH("switch", "keyword"), 88 SYNCHRONIZED("synchronized", "keyword"), 89 THIS("this", "keyword"), 90 THROW("throw", "keyword"), 91 THROWS("throws", "keyword"), 92 TRANSIENT("transient", "keyword"), 93 TRY("try", "keyword"), 94 VOID("void", "keyword"), 95 VOLATILE("volatile", "keyword"), 96 WHILE("while", "keyword"), 97 98 INT_LITERAL(null, "number"), 99 LONG_LITERAL(null, "number"), 100 FLOAT_LITERAL(null, "number"), 101 DOUBLE_LITERAL(null, "number"), 102 CHAR_LITERAL(null, "character"), 103 STRING_LITERAL(null, "string"), 104 105 TRUE("true", "literal"), 106 FALSE("false", "literal"), 107 NULL("null", "literal"), 108 109 LPAREN("(", "separator"), 110 RPAREN(")", "separator"), 111 LBRACE("{", "separator"), 112 RBRACE("}", "separator"), 113 LBRACKET("[", "separator"), 114 RBRACKET("]", "separator"), 115 SEMICOLON(";", "separator"), 116 COMMA(",", "separator"), 117 DOT(".", "separator"), 118 119 EQ("=", "operator"), 120 GT(">", "operator"), 121 LT("<", "operator"), 122 BANG("!", "operator"), 123 TILDE("~", "operator"), 124 QUESTION("?", "operator"), 125 COLON(":", "operator"), 126 EQEQ("==", "operator"), 127 LTEQ("<=", "operator"), 128 GTEQ(">=", "operator"), 129 BANGEQ("!=","operator"), 130 AMPAMP("&&", "operator"), 131 BARBAR("||", "operator"), 132 PLUSPLUS("++", "operator"), 133 MINUSMINUS("--","operator"), 134 PLUS("+", "operator"), 135 MINUS("-", "operator"), 136 STAR("*", "operator"), 137 SLASH("/", "operator"), 138 AMP("&", "operator"), 139 BAR("|", "operator"), 140 CARET("^", "operator"), 141 PERCENT("%", "operator"), 142 LTLT("<<", "operator"), 143 GTGT(">>", "operator"), 144 GTGTGT(">>>", "operator"), 145 PLUSEQ("+=", "operator"), 146 MINUSEQ("-=", "operator"), 147 STAREQ("*=", "operator"), 148 SLASHEQ("/=", "operator"), 149 AMPEQ("&=", "operator"), 150 BAREQ("|=", "operator"), 151 CARETEQ("^=", "operator"), 152 PERCENTEQ("%=", "operator"), 153 LTLTEQ("<<=", "operator"), 154 GTGTEQ(">>=", "operator"), 155 GTGTGTEQ(">>>=", "operator"), 156 157 ELLIPSIS("...", null), 158 AT("@", null), 159 160 WHITESPACE(null, "whitespace"), 161 LINE_COMMENT(null, "comment"), 162 BLOCK_COMMENT(null, "comment"), 163 JAVADOC_COMMENT(null, "comment"), 164 165 INVALID_COMMENT_END("*/", "error"), 167 FLOAT_LITERAL_INVALID(null, "number"); 168 169 170 private final String fixedText; 171 172 private final String primaryCategory; 173 174 JavaTokenId(String fixedText, String primaryCategory) { 175 this.fixedText = fixedText; 176 this.primaryCategory = primaryCategory; 177 } 178 179 public String fixedText() { 180 return fixedText; 181 } 182 183 public String primaryCategory() { 184 return primaryCategory; 185 } 186 187 private static final Language<JavaTokenId> language = new LanguageHierarchy<JavaTokenId>() { 188 189 @Override 190 protected String mimeType() { 191 return "text/x-java"; 192 } 193 194 @Override 195 protected Collection <JavaTokenId> createTokenIds() { 196 return EnumSet.allOf(JavaTokenId.class); 197 } 198 199 @Override 200 protected Map <String ,Collection <JavaTokenId>> createTokenCategories() { 201 Map <String ,Collection <JavaTokenId>> cats = new HashMap <String ,Collection <JavaTokenId>>(); 202 cats.put("error", EnumSet.of( 204 JavaTokenId.FLOAT_LITERAL_INVALID 205 )); 206 EnumSet <JavaTokenId> l = EnumSet.of( 208 JavaTokenId.INT_LITERAL, 209 JavaTokenId.LONG_LITERAL, 210 JavaTokenId.FLOAT_LITERAL, 211 JavaTokenId.DOUBLE_LITERAL, 212 JavaTokenId.CHAR_LITERAL 213 ); 214 l.add(JavaTokenId.STRING_LITERAL); 215 cats.put("literal", l); 216 217 return cats; 218 } 219 220 @Override 221 protected Lexer<JavaTokenId> createLexer(LexerRestartInfo<JavaTokenId> info) { 222 return new JavaLexer(info); 223 } 224 225 @Override 226 protected LanguageEmbedding<? extends TokenId> embedding( 227 Token<JavaTokenId> token, LanguagePath languagePath, InputAttributes inputAttributes) { 228 switch (token.id()) { 230 case JAVADOC_COMMENT: 231 return LanguageEmbedding.create(JavadocTokenId.language(), 3, 2); 232 case STRING_LITERAL: 233 return LanguageEmbedding.create(JavaStringTokenId.language(), 1, 1); 234 } 235 return null; } 237 238 242 }.language(); 243 244 public static Language<JavaTokenId> language() { 245 return language; 246 } 247 248 } 249 | Popular Tags |