KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > lexer > test > dump > TokenDumpTokenId


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.lib.lexer.test.dump;
21
22 import java.util.Collection JavaDoc;
23 import java.util.EnumSet JavaDoc;
24 import java.util.Set JavaDoc;
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 /**
32  * Ids for parsing of the input file of a particular language
33  * for the token dump check.
34  * <br/>
35  * The text of the special tokens is interlarded with dots
36  * to eliminate the possibility that the particular special token will clash
37  * with the target language.
38  *
39  * @author mmetelka
40  */

41 public enum TokenDumpTokenId implements TokenId {
42     
43     /** Single line of text without newline. */
44     TEXT(null),
45     
46     /** Unicode character as line containing ".\.u.XXXX." only where XXXX
47      * is sequence of (lowercase or uppercase) hex digits.
48      * <code>(Character)Token.getProperty({@link UNICODE_CHAR_TOKEN_PROPERTY}))</code>
49      * gives the character.
50      */

51     UNICODE_CHAR("character"),
52     
53     /** Line containing ".\.b." only defines \b char in the input.
54      * <code>(Character)Token.getProperty({@link UNICODE_CHAR_TOKEN_PROPERTY}))</code>
55      * gives the \b character.
56      */

57     BACKSPACE_CHAR("character"),
58     /** Line containing ".\.f." only defines \f char in the input.
59      * <code>(Character)Token.getProperty({@link UNICODE_CHAR_TOKEN_PROPERTY}))</code>
60      * gives the \f character.
61      */

62     FORM_FEED_CHAR("character"),
63     /** Line containing ".\.b." only defines \b char in the input.
64      * <code>(Character)Token.getProperty({@link UNICODE_CHAR_TOKEN_PROPERTY}))</code>
65      * gives the \b character.
66      */

67     CR_CHAR("character"),
68     /** Line containing ".\.r." only defines \r char in the input.
69      * <code>(Character)Token.getProperty({@link UNICODE_CHAR_TOKEN_PROPERTY}))</code>
70      * gives the \r character.
71      */

72     NEWLINE_CHAR("character"),
73     /** Line containing ".\.t." only defines \t char in the input.
74      * <code>(Character)Token.getProperty({@link UNICODE_CHAR_TOKEN_PROPERTY}))</code>
75      * gives the \t character.
76      */

77     TAB_CHAR("character"),
78     
79     /** EOF mark as line containing ".e.o.f." only.
80      * It helps to separate tests and test lexer's behavior at the end of buffer.
81      */

82     EOF_VIRTUAL(null),
83     
84     /** Test name as line starting with ".t.e.s.t." to help debugging
85      * where a possible problem occurred. It should be used at begining
86      * or inside a test between virtual eofs.
87      */

88     TEST_NAME(null),
89     
90     /** Newline '\r', '\n' or '\r\n'.
91      * <br/>
92      * The test itself will replace this with '\n' because otherwise the output
93      * of the token dump would contain the particular line separator depending on the platform
94      * where the file would be checked out which would break the test.
95      * <br/>
96      * To test specific line separators the {@link #CR_CHAR} or {@link #NEWLINE_CHAR} may be used.
97      */

98     NEWLINE(null);
99     
100     private String JavaDoc primaryCategory;
101
102     private TokenDumpTokenId(String JavaDoc primaryCategory) {
103         this.primaryCategory = primaryCategory;
104     }
105     
106     public String JavaDoc primaryCategory() {
107         return primaryCategory;
108     }
109     
110     private static final Language<TokenDumpTokenId> lang = new LanguageHierarchy<TokenDumpTokenId>() {
111
112         @Override JavaDoc
113         protected String JavaDoc mimeType() {
114             return "text/x-eof-mark";
115         }
116
117         @Override JavaDoc
118         protected Collection JavaDoc<TokenDumpTokenId> createTokenIds() {
119             return EnumSet.allOf(TokenDumpTokenId.class);
120         }
121
122         @Override JavaDoc
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 JavaDoc<TokenDumpTokenId> charLiterals;
134     
135     public static boolean isCharLiteral(TokenDumpTokenId id) {
136         Set JavaDoc<TokenDumpTokenId> catMembers = charLiterals;
137         if (catMembers == null) {
138             catMembers = language().tokenCategoryMembers("character");
139             charLiterals = catMembers;
140         }
141         return catMembers.contains(id);
142     }
143
144     /**
145      * Token property giving the unicode character value.
146      */

147     public static final String JavaDoc UNICODE_CHAR_TOKEN_PROPERTY = "unicode-char";
148         
149 }
150
Popular Tags