1 19 20 package org.netbeans.api.jsp.lexer; 21 22 import java.util.Collection ; 23 import java.util.EnumSet ; 24 import java.util.Map ; 25 import org.netbeans.api.html.lexer.HTMLTokenId; 26 import org.netbeans.api.java.lexer.JavaTokenId; 27 import org.netbeans.api.lexer.InputAttributes; 28 import org.netbeans.api.lexer.Language; 29 import org.netbeans.api.lexer.LanguagePath; 30 import org.netbeans.api.lexer.Token; 31 import org.netbeans.api.lexer.TokenId; 32 import org.netbeans.lib.jsp.lexer.JspLexer; 33 import org.netbeans.modules.el.lexer.api.ELTokenId; 34 import org.netbeans.spi.lexer.LanguageEmbedding; 35 import org.netbeans.spi.lexer.LanguageHierarchy; 36 import org.netbeans.spi.lexer.Lexer; 37 import org.netbeans.spi.lexer.LexerRestartInfo; 38 39 44 45 public enum JspTokenId implements TokenId { 46 47 TEXT("text"), 48 SCRIPTLET("scriptlet"), 49 ERROR("error"), 50 TAG("tag-directive"), 51 SYMBOL("symbol"), 52 SYMBOL2("scriptlet-delimiter"), 53 COMMENT("comment"), 54 ATTRIBUTE("attribute-name"), 55 ATTR_VALUE("attribute-value"), 56 EOL("EOL"), 57 WHITESPACE("jsp-whitespace"), EL("expression-language"); 59 60 61 public static enum JavaCodeType { 62 SCRIPTLET("scriptlet"), 63 DECLARATION("declaration"), 64 EXPRESSION("expression"); 65 66 private final String type; 67 68 JavaCodeType(String type) { 69 this.type = type; 70 } 71 } 72 73 74 public static final String SCRIPTLET_TOKEN_TYPE_PROPERTY = "JAVA_CODE_TYPE"; 75 76 private final String primaryCategory; 77 78 JspTokenId() { 79 this(null); 80 } 81 82 JspTokenId(String primaryCategory) { 83 this.primaryCategory = primaryCategory; 84 } 85 86 public String primaryCategory() { 87 return primaryCategory; 88 } 89 90 private static final Language<JspTokenId> language = new LanguageHierarchy<JspTokenId>() { 92 @Override 93 protected Collection <JspTokenId> createTokenIds() { 94 return EnumSet.allOf(JspTokenId.class); 95 } 96 97 @Override 98 protected Map <String ,Collection <JspTokenId>> createTokenCategories() { 99 return null; 103 } 104 105 @Override 106 protected Lexer<JspTokenId> createLexer(LexerRestartInfo<JspTokenId> info) { 107 return new JspLexer(info); 108 } 109 110 @Override 111 protected LanguageEmbedding<? extends TokenId> embedding( 112 Token<JspTokenId> token, LanguagePath languagePath, InputAttributes inputAttributes) { 113 switch(token.id()) { 114 case TEXT: 115 return LanguageEmbedding.create(HTMLTokenId.language(), 0, 0); 116 case EL: 117 int startSkipLength = token.length() > 2 ? 2 : token.length(); 119 int endSkipLength = token.length() > 2 ? 1 : 0; 120 return LanguageEmbedding.create(ELTokenId.language(), startSkipLength, endSkipLength); 121 122 case SCRIPTLET: 123 return LanguageEmbedding.create(JavaTokenId.language(), 0, 0); 124 125 default: 126 return null; 127 } 128 } 129 130 @Override 131 protected String mimeType() { 132 return "text/x-jsp"; 133 } 134 }.language(); 135 136 public static Language<JspTokenId> language() { 137 return language; 138 } 139 140 141 } 142 143 | Popular Tags |