KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > ruby > lexer > RubyStringTokenId


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.ruby.lexer;
20
21 import java.util.Collection JavaDoc;
22 import java.util.EnumSet JavaDoc;
23 import java.util.Map JavaDoc;
24
25 import org.netbeans.modules.ruby.lexer.RubyStringLexer;
26 import org.netbeans.modules.ruby.lexer.RubyTokenId;
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.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 /**
38  * Token ids for java string language
39  * (embedded in java string or character literals).
40  *
41  * @author Miloslav Metelka
42  * @version 1.00
43  */

44 public enum RubyStringTokenId implements TokenId {
45     STRING_TEXT("string"),
46     STRING_ESCAPE("string-escape"),
47     STRING_INVALID("string-escape-invalid"),
48     EMBEDDED_RUBY("string");
49
50     private final String JavaDoc primaryCategory;
51
52     RubyStringTokenId() {
53         this(null);
54     }
55
56     RubyStringTokenId(String JavaDoc primaryCategory) {
57         this.primaryCategory = primaryCategory;
58     }
59
60     public String JavaDoc primaryCategory() {
61         return primaryCategory;
62     }
63
64     /** Language for double quoted strings */
65     private static final Language<RubyStringTokenId> languageDouble =
66         new LanguageHierarchy<RubyStringTokenId>() {
67                 @Override JavaDoc
68                 protected Collection JavaDoc<RubyStringTokenId> createTokenIds() {
69                     return EnumSet.allOf(RubyStringTokenId.class);
70                 }
71
72                 @Override JavaDoc
73                 protected Map JavaDoc<String JavaDoc, Collection JavaDoc<RubyStringTokenId>> createTokenCategories() {
74                     return null; // no extra categories
75
}
76
77                 @Override JavaDoc
78                 protected Lexer<RubyStringTokenId> createLexer(
79                     LexerRestartInfo<RubyStringTokenId> info) {
80                     return new RubyStringLexer(info, true);
81                 }
82
83                 @Override JavaDoc
84                 protected LanguageEmbedding<? extends TokenId> embedding(Token<RubyStringTokenId> token,
85                     LanguagePath languagePath, InputAttributes inputAttributes) {
86                     RubyStringTokenId id = token.id();
87
88                     if (id == EMBEDDED_RUBY) {
89                         return LanguageEmbedding.create(RubyTokenId.language(), 0, 0);
90                     }
91
92                     return null; // No embedding
93
}
94
95                 @Override JavaDoc
96                 public String JavaDoc mimeType() {
97                     return "text/x-ruby-string-double";
98                 }
99             }.language();
100
101     /** Language for single quoted strings */
102     private static final Language<RubyStringTokenId> languageSingle =
103         new LanguageHierarchy<RubyStringTokenId>() {
104                 @Override JavaDoc
105                 protected Collection JavaDoc<RubyStringTokenId> createTokenIds() {
106                     return EnumSet.allOf(RubyStringTokenId.class);
107                 }
108
109                 @Override JavaDoc
110                 protected Map JavaDoc<String JavaDoc, Collection JavaDoc<RubyStringTokenId>> createTokenCategories() {
111                     return null; // no extra categories
112
}
113
114                 @Override JavaDoc
115                 protected Lexer<RubyStringTokenId> createLexer(
116                     LexerRestartInfo<RubyStringTokenId> info) {
117                     return new RubyStringLexer(info, false);
118                 }
119
120                 @Override JavaDoc
121                 protected LanguageEmbedding<? extends TokenId> embedding(Token<RubyStringTokenId> token,
122                     LanguagePath languagePath, InputAttributes inputAttributes) {
123                     RubyStringTokenId id = token.id();
124
125                     if (id == EMBEDDED_RUBY) {
126                         return LanguageEmbedding.create(RubyTokenId.language(), 0, 0);
127                     }
128
129                     return null; // No embedding
130
}
131
132                 @Override JavaDoc
133                 public String JavaDoc mimeType() {
134                     return "text/x-ruby-string-single";
135                 }
136             }.language();
137
138     public static Language<RubyStringTokenId> languageDouble() {
139         return languageDouble;
140     }
141
142     public static Language<RubyStringTokenId> languageSingle() {
143         return languageSingle;
144     }
145 }
146
Popular Tags