Source Code Cross Referenced for MutableTokenId.java in  » IDE-Netbeans » lexer » org » netbeans » modules » lexer » gen » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » lexer » org.netbeans.modules.lexer.gen 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package org.netbeans.modules.lexer.gen;
043:
044:        import java.util.HashMap;
045:        import java.util.List;
046:        import java.util.ArrayList;
047:        import java.util.Iterator;
048:        import org.netbeans.modules.lexer.gen.util.LexerGenUtilities;
049:
050:        /**
051:         * Mutable alternative of the {@link org.netbeans.api.lexer.TokenId}
052:         * used when the generated language source is being composed.
053:         *
054:         * @author Miloslav Metelka
055:         * @version 1.00
056:         */
057:
058:        public class MutableTokenId {
059:
060:            public static final String SAMPLE_TEXT_CHECK_NONE = "none";
061:            public static final String SAMPLE_TEXT_CHECK_LENGTH = "length";
062:            public static final String SAMPLE_TEXT_CHECK_TEXT = "text";
063:
064:            private final LanguageData languageData;
065:
066:            private final String name;
067:
068:            private int intId;
069:
070:            private String tokenTypeName;
071:
072:            private List categoryNames;
073:
074:            private List sampleTexts;
075:
076:            private String sampleTextCheck;
077:
078:            private boolean caseInsensitive;
079:
080:            private String comment;
081:
082:            /**
083:             * Construct new MutableTokenId. All the properties
084:             * are set by corresponding setters.
085:             */
086:            public MutableTokenId(LanguageData languageData, String name) {
087:                this .languageData = languageData;
088:                this .name = name;
089:                this .intId = -1; // assign invalid int id initially
090:
091:                categoryNames = new ArrayList();
092:                sampleTexts = new ArrayList();
093:            }
094:
095:            /**
096:             * @return the language data to which this mutable tokenId belongs.
097:             */
098:            public final LanguageData getLanguageData() {
099:                return languageData;
100:            }
101:
102:            /**
103:             * @return name of this tokenId.
104:             */
105:            public String getName() {
106:                return name;
107:            }
108:
109:            /**
110:             * @return numeric identification of this tokenId.
111:             *  The initially assigned intId is set to -1.
112:             */
113:            public int getIntId() {
114:                return intId;
115:            }
116:
117:            /**
118:             * Override the currently set intId (if any).
119:             * <BR>The value being set
120:             * will be skipped in the LanguageData automatically.
121:             * @param intId integer identification of this tokenId.
122:             */
123:            public void setIntId(int intId) {
124:                this .intId = intId;
125:                // Skip this numeric intId
126:                languageData.skipIntId(intId);
127:            }
128:
129:            /**
130:             * @return name of the static field for this tokenId
131:             *  in the generated language class.
132:             */
133:            public String getFieldName() {
134:                return LexerGenUtilities.idToUpperCase(getName());
135:            }
136:
137:            /**
138:             * @return name of the static field for the integer constant
139:             *  for this tokenId in the generated language class.
140:             */
141:            public String getIntIdFieldName() {
142:                return getFieldName() + "_INT";
143:            }
144:
145:            /**
146:             * Assign unique int identification by using
147:             * {@link LanguageData#uniqueIntId()}.
148:             */
149:            public void assignUniqueIntId() {
150:                setIntId(languageData.uniqueIntId());
151:            }
152:
153:            /**
154:             * @return name of the field in the token-types class
155:             * (e.g. xxxConstants for javacc or xxxTokenTypes for antlr)
156:             * that corresponds to this token id or null
157:             * if this token-id does not have any associated field
158:             * in the token-types class.
159:             */
160:            public String getTokenTypeName() {
161:                return tokenTypeName;
162:            }
163:
164:            public void updateByTokenType(String tokenTypeName) {
165:                this .tokenTypeName = tokenTypeName;
166:                languageData.getTokenTypes().updateId(this );
167:            }
168:
169:            /**
170:             * @return list of category names to which this token belongs.
171:             * The list can be modified by adding/removing category names.
172:             */
173:            public List getCategoryNames() {
174:                return categoryNames;
175:            }
176:
177:            /**
178:             * @return whether this tokenId is case insensitive
179:             * which means that when adding a new sampleText
180:             * by {@link addSampleText(String)} then
181:             * the corresponding upper-case and lower-case
182:             * representations are added too.
183:             * <BR>For "html" sample text the "HTML"
184:             * will be added too.
185:             * <BR>For "Begin" sample text the "begin" and "BEGIN"
186:             * will be added too.
187:             *
188:             * <P>The value of this flag is not transferred
189:             * into resulting {@link org.netbeans.api.lexer.TokenId}
190:             * in any way.
191:             */
192:            public boolean isCaseInsensitive() {
193:                return caseInsensitive;
194:            }
195:
196:            /**
197:             * Set whether this tokenId is case insensitive or not.
198:             * @param caseInsensitive whether this tokenId is case insensitive.
199:             *  If the value is true then all the existing sample texts
200:             *  will be re-added so the number of the sample
201:             *  texts can grow as explained in {@link #isCaseInsensitive()}.
202:             * @see #isCaseInsensitive()
203:             */
204:            public void setCaseInsensitive(boolean caseInsensitive) {
205:                this .caseInsensitive = caseInsensitive;
206:
207:                if (caseInsensitive) { // re-add the existing samples
208:                    Iterator currentSamplesIterator = new ArrayList(sampleTexts)
209:                            .iterator();
210:                    sampleTexts.clear();
211:                    while (currentSamplesIterator.hasNext()) {
212:                        addSampleText((String) currentSamplesIterator.next());
213:                    }
214:                }
215:            }
216:
217:            /** Add a sample text to the tokenId.
218:             * @param sampleText sample text to add to the current list of sample texts.
219:             */
220:            public void addSampleText(String sampleText) {
221:                addUniqueSampleText(sampleText);
222:
223:                if (caseInsensitive) {
224:                    addUniqueSampleText(sampleText.toLowerCase());
225:                    addUniqueSampleText(sampleText.toUpperCase());
226:                }
227:            }
228:
229:            private void addUniqueSampleText(String sampleText) {
230:                if (sampleTexts.indexOf(sampleText) == -1) {
231:                    sampleTexts.add(sampleText);
232:                }
233:            }
234:
235:            /** Get the sample texts list.
236:             */
237:            public List getSampleTexts() {
238:                return sampleTexts;
239:            }
240:
241:            /**
242:             * Clear all existing sample texts.
243:             */
244:            public void resetSamples() {
245:                sampleTexts.clear();
246:            }
247:
248:            public String getSampleTextCheck() {
249:                return sampleTextCheck;
250:            }
251:
252:            public void setSampleTextCheck(String sampleTextCheck) {
253:                this .sampleTextCheck = sampleTextCheck;
254:            }
255:
256:            public String getComment() {
257:                return comment;
258:            }
259:
260:            public void setComment(String comment) {
261:                this .comment = comment;
262:            }
263:
264:            public String toString() {
265:                StringBuffer sb = new StringBuffer();
266:                sb.append(getName());
267:                sb.append(", intId=");
268:                sb.append(getIntId());
269:                sb.append(", tokenType=");
270:                sb.append(getTokenTypeName());
271:                List samples = getSampleTexts();
272:                int samplesCount = samples.size();
273:                for (int i = 0; i < samplesCount; i++) {
274:                    if (i == 0) {
275:                        sb.append(", samples={");
276:                    }
277:                    sb.append('"');
278:                    sb.append(samples.get(i));
279:                    sb.append('"');
280:                    if (i == samplesCount - 1) {
281:                        sb.append('}');
282:                    }
283:                }
284:                sb.append(", sampleTextCheck=");
285:                sb.append(getSampleTextCheck());
286:
287:                return sb.toString();
288:            }
289:
290:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.