KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > java > lexer > JavaStringTokenId


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
20 package org.netbeans.api.java.lexer;
21
22 import java.util.Collection JavaDoc;
23 import java.util.EnumSet JavaDoc;
24 import java.util.Map JavaDoc;
25 import org.netbeans.api.lexer.Language;
26 import org.netbeans.api.lexer.TokenId;
27 import org.netbeans.lib.java.lexer.JavaStringLexer;
28 import org.netbeans.spi.lexer.LanguageHierarchy;
29 import org.netbeans.spi.lexer.Lexer;
30 import org.netbeans.spi.lexer.LexerRestartInfo;
31
32 /**
33  * Token ids for java string language
34  * (embedded in java string or character literals).
35  *
36  * @author Miloslav Metelka
37  * @version 1.00
38  */

39 public enum JavaStringTokenId implements TokenId {
40
41     TEXT("string"),
42     BACKSPACE("string-escape"),
43     FORM_FEED("string-escape"),
44     NEWLINE("string-escape"),
45     CR("string-escape"),
46     TAB("string-escape"),
47     SINGLE_QUOTE("string-escape"),
48     DOUBLE_QUOTE("string-escape"),
49     BACKSLASH("string-escape"),
50     OCTAL_ESCAPE("string-escape"),
51     OCTAL_ESCAPE_INVALID("string-escape-invalid"),
52     ESCAPE_SEQUENCE_INVALID("string-escape-invalid");
53
54     private final String JavaDoc primaryCategory;
55
56     JavaStringTokenId() {
57         this(null);
58     }
59
60     JavaStringTokenId(String JavaDoc primaryCategory) {
61         this.primaryCategory = primaryCategory;
62     }
63
64     public String JavaDoc primaryCategory() {
65         return primaryCategory;
66     }
67
68     private static final Language<JavaStringTokenId> language = new LanguageHierarchy<JavaStringTokenId>() {
69         @Override JavaDoc
70         protected Collection JavaDoc<JavaStringTokenId> createTokenIds() {
71             return EnumSet.allOf(JavaStringTokenId.class);
72         }
73         
74         @Override JavaDoc
75         protected Map JavaDoc<String JavaDoc, Collection JavaDoc<JavaStringTokenId>> createTokenCategories() {
76             return null; // no extra categories
77
}
78
79         @Override JavaDoc
80         protected Lexer<JavaStringTokenId> createLexer(LexerRestartInfo<JavaStringTokenId> info) {
81             return new JavaStringLexer(info);
82         }
83
84         @Override JavaDoc
85         protected String JavaDoc mimeType() {
86             return "text/x-java-string";
87         }
88     }.language();
89
90     public static Language<JavaStringTokenId> language() {
91         return language;
92     }
93
94 }
95
Popular Tags