1 19 20 package org.netbeans.lib.lexer.test.dump; 21 22 import java.util.Collection ; 23 import java.util.EnumSet ; 24 import java.util.Set ; 25 import org.netbeans.api.lexer.Language; 26 import org.netbeans.api.lexer.TokenId; 27 import org.netbeans.spi.lexer.LanguageHierarchy; 28 import org.netbeans.spi.lexer.Lexer; 29 import org.netbeans.spi.lexer.LexerRestartInfo; 30 31 41 public enum TokenDumpTokenId implements TokenId { 42 43 44 TEXT(null), 45 46 51 UNICODE_CHAR("character"), 52 53 57 BACKSPACE_CHAR("character"), 58 62 FORM_FEED_CHAR("character"), 63 67 CR_CHAR("character"), 68 72 NEWLINE_CHAR("character"), 73 77 TAB_CHAR("character"), 78 79 82 EOF_VIRTUAL(null), 83 84 88 TEST_NAME(null), 89 90 98 NEWLINE(null); 99 100 private String primaryCategory; 101 102 private TokenDumpTokenId(String primaryCategory) { 103 this.primaryCategory = primaryCategory; 104 } 105 106 public String primaryCategory() { 107 return primaryCategory; 108 } 109 110 private static final Language<TokenDumpTokenId> lang = new LanguageHierarchy<TokenDumpTokenId>() { 111 112 @Override 113 protected String mimeType() { 114 return "text/x-eof-mark"; 115 } 116 117 @Override 118 protected Collection <TokenDumpTokenId> createTokenIds() { 119 return EnumSet.allOf(TokenDumpTokenId.class); 120 } 121 122 @Override 123 protected Lexer<TokenDumpTokenId> createLexer(LexerRestartInfo<TokenDumpTokenId> info) { 124 return new TokenDumpLexer(info); 125 } 126 127 }.language(); 128 129 public static Language<TokenDumpTokenId> language() { 130 return lang; 131 } 132 133 private static Set <TokenDumpTokenId> charLiterals; 134 135 public static boolean isCharLiteral(TokenDumpTokenId id) { 136 Set <TokenDumpTokenId> catMembers = charLiterals; 137 if (catMembers == null) { 138 catMembers = language().tokenCategoryMembers("character"); 139 charLiterals = catMembers; 140 } 141 return catMembers.contains(id); 142 } 143 144 147 public static final String UNICODE_CHAR_TOKEN_PROPERTY = "unicode-char"; 148 149 } 150 | Popular Tags |