KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > css > text > syntax > CSSEditorSyntaxMapper


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.css.text.syntax;
20
21 import org.netbeans.editor.*;
22 import org.netbeans.modules.css.text.syntax.javacc.lib.*;
23 import org.netbeans.modules.css.text.syntax.javacc.CSSSyntaxConstants;
24
25 /**
26  * Factory mappring jjID => TokenID.
27  *
28  * @author Petr Kuzel
29  * @version 1.0
30  */

31 public class CSSEditorSyntaxMapper implements JJMapperInterface, JJConstants, CSSSyntaxConstants {
32
33
34     /** Create token for particular ID. */
35     public JJTokenID createToken(int id) {
36
37         switch(id) {
38
39             case JJ_EOL:
40                 return CSSTokenContext.EOL;
41                 
42             case JJ_EOF:
43                 throw new Error JavaDoc("guessToken() must be called for such case."); // NOI18N
44

45             case JJ_ERR:
46             case ERR_IN_COMMENT:
47
48                 return CSSTokenContext.ERROR;
49                 
50                 
51             case MEDIA_DECL:
52             case ATKW:
53                 
54                 return CSSTokenContext.ATKW;
55                 
56             case COMMENT_IN_RULESET:
57             case CCOMMENT_IN_RULESET:
58             case COMMENT_START:
59             case TEXT_IN_COMMENT:
60             case COMMENT_END:
61             case CCOMMENT_START:
62             case CCOMMENT_END:
63             case TEXT_IN_CCOMMENT:
64                 
65                 return CSSTokenContext.COMMENT;
66                 
67             case SELECTOR:
68                 
69                 return CSSTokenContext.SELECTOR;
70                 
71             case PROP:
72                 return CSSTokenContext.PROPERTY;
73                 
74             default:
75                 return CSSTokenContext.PLAIN;
76         }
77         
78     }
79     /** @return token guessed for particular state. */
80     public final JJTokenID guessToken(String JavaDoc token,int state,boolean lastBuffer) {
81         
82         switch (state) {
83              default:
84                  return cannotGuess(lastBuffer);
85         }
86     }
87     
88     private JJTokenID cannotGuess(boolean lastBuffer) {
89         return cannotGuess(lastBuffer, CSSTokenContext.PLAIN);
90     }
91     
92     private JJTokenID cannotGuess(boolean lastBuffer, JJTokenID supposed) {
93         if (lastBuffer) {
94             return supposed;
95         } else {
96             //ask for next buffer
97
return null;
98         }
99     }
100     
101     /** Called if createToken(int id) return isError() token.
102     * @return supposed token for particular id and state.
103      */

104     public JJTokenID supposedToken(String JavaDoc token,int state,int id) {
105         
106         switch (state) {
107             case IN_COMMENT:
108                 return CSSTokenContext.COMMENT;
109                 
110             default:
111                 return null;
112         }
113     }
114     
115 }
116
Popular Tags