Index: java/editor/nbproject/project.xml =================================================================== RCS file: /cvs/java/editor/nbproject/project.xml,v retrieving revision 1.24 diff -u -r1.24 project.xml --- java/editor/nbproject/project.xml 8 Feb 2007 08:18:34 -0000 1.24 +++ java/editor/nbproject/project.xml 3 Mar 2007 19:20:36 -0000 @@ -129,7 +129,7 @@ 1 - 1.0 + 1.2 @@ -146,7 +146,7 @@ 2 - 1.4 + 1.14 Index: java/editor/src/org/netbeans/modules/editor/java/Utilities.java =================================================================== RCS file: /cvs/java/editor/src/org/netbeans/modules/editor/java/Utilities.java,v retrieving revision 1.17 diff -u -r1.17 Utilities.java --- java/editor/src/org/netbeans/modules/editor/java/Utilities.java 1 Mar 2007 10:44:00 -0000 1.17 +++ java/editor/src/org/netbeans/modules/editor/java/Utilities.java 3 Mar 2007 19:20:36 -0000 @@ -101,19 +101,15 @@ if (ts.token().text().charAt(0) == '.') break; case CHAR_LITERAL: - case CHAR_LITERAL_INCOMPLETE: case FLOAT_LITERAL: case FLOAT_LITERAL_INVALID: case INT_LITERAL: case INVALID_COMMENT_END: case JAVADOC_COMMENT: - case JAVADOC_COMMENT_INCOMPLETE: case LONG_LITERAL: case STRING_LITERAL: - case STRING_LITERAL_INCOMPLETE: case LINE_COMMENT: case BLOCK_COMMENT: - case BLOCK_COMMENT_INCOMPLETE: return false; } return true; Index: java/lexer/manifest.mf =================================================================== RCS file: /cvs/java/lexer/manifest.mf,v retrieving revision 1.4 diff -u -r1.4 manifest.mf --- java/lexer/manifest.mf 14 Dec 2006 13:02:59 -0000 1.4 +++ java/lexer/manifest.mf 3 Mar 2007 19:20:39 -0000 @@ -1,5 +1,5 @@ OpenIDE-Module: org.netbeans.modules.java.lexer/1 OpenIDE-Module-Localizing-Bundle: org/netbeans/lib/java/lexer/Bundle.properties -OpenIDE-Module-Specification-Version: 1.1 +OpenIDE-Module-Specification-Version: 1.2 OpenIDE-Module-Layer: org/netbeans/lib/java/lexer/layer.xml Index: java/lexer/nbproject/project.xml =================================================================== RCS file: /cvs/java/lexer/nbproject/project.xml,v retrieving revision 1.4 diff -u -r1.4 project.xml --- java/lexer/nbproject/project.xml 14 Dec 2006 13:02:59 -0000 1.4 +++ java/lexer/nbproject/project.xml 3 Mar 2007 19:20:40 -0000 @@ -29,7 +29,7 @@ 2 - 1.12 + 1.14 Index: java/lexer/src/org/netbeans/api/java/lexer/JavaTokenId.java =================================================================== RCS file: /cvs/java/lexer/src/org/netbeans/api/java/lexer/JavaTokenId.java,v retrieving revision 1.7 diff -u -r1.7 JavaTokenId.java --- java/lexer/src/org/netbeans/api/java/lexer/JavaTokenId.java 6 Dec 2006 15:26:45 -0000 1.7 +++ java/lexer/src/org/netbeans/api/java/lexer/JavaTokenId.java 3 Mar 2007 19:20:40 -0000 @@ -162,11 +162,7 @@ BLOCK_COMMENT(null, "comment"), JAVADOC_COMMENT(null, "comment"), - // Errors and incomplete tokens - CHAR_LITERAL_INCOMPLETE(null, "character"), - STRING_LITERAL_INCOMPLETE(null, "string"), - BLOCK_COMMENT_INCOMPLETE(null, "comment"), - JAVADOC_COMMENT_INCOMPLETE(null, "comment"), + // Errors INVALID_COMMENT_END("*/", "error"), FLOAT_LITERAL_INVALID(null, "number"); @@ -203,35 +199,19 @@ @Override protected Map> createTokenCategories() { Map> cats = new HashMap>(); - // Incomplete tokens - cats.put("incomplete", EnumSet.of( - JavaTokenId.CHAR_LITERAL_INCOMPLETE, - JavaTokenId.STRING_LITERAL_INCOMPLETE, - JavaTokenId.BLOCK_COMMENT_INCOMPLETE, - JavaTokenId.JAVADOC_COMMENT_INCOMPLETE - )); // Additional literals being a lexical error cats.put("error", EnumSet.of( - JavaTokenId.CHAR_LITERAL_INCOMPLETE, - JavaTokenId.STRING_LITERAL_INCOMPLETE, - JavaTokenId.BLOCK_COMMENT_INCOMPLETE, - JavaTokenId.JAVADOC_COMMENT_INCOMPLETE, JavaTokenId.FLOAT_LITERAL_INVALID )); - // Complete and incomplete literals + // Literals category EnumSet l = EnumSet.of( JavaTokenId.INT_LITERAL, JavaTokenId.LONG_LITERAL, JavaTokenId.FLOAT_LITERAL, JavaTokenId.DOUBLE_LITERAL, JavaTokenId.CHAR_LITERAL - ); - l.addAll(EnumSet.of( - JavaTokenId.CHAR_LITERAL_INCOMPLETE, - JavaTokenId.STRING_LITERAL, - JavaTokenId.STRING_LITERAL_INCOMPLETE - )); + l.add(JavaTokenId.STRING_LITERAL); cats.put("literal", l); return cats; @@ -250,7 +230,6 @@ case JAVADOC_COMMENT: return LanguageEmbedding.create(JavadocTokenId.language(), 3, 2); case STRING_LITERAL: - case STRING_LITERAL_INCOMPLETE: return LanguageEmbedding.create(JavaStringTokenId.language(), 1, 1); } return null; // No embedding Index: java/lexer/src/org/netbeans/lib/java/lexer/JavaLexer.java =================================================================== RCS file: /cvs/java/lexer/src/org/netbeans/lib/java/lexer/JavaLexer.java,v retrieving revision 1.4 diff -u -r1.4 JavaLexer.java --- java/lexer/src/org/netbeans/lib/java/lexer/JavaLexer.java 14 Dec 2006 13:03:00 -0000 1.4 +++ java/lexer/src/org/netbeans/lib/java/lexer/JavaLexer.java 3 Mar 2007 19:20:40 -0000 @@ -20,6 +20,7 @@ package org.netbeans.lib.java.lexer; import org.netbeans.api.java.lexer.JavaTokenId; +import org.netbeans.api.lexer.PartType; import org.netbeans.api.lexer.Token; import org.netbeans.spi.lexer.Lexer; import org.netbeans.spi.lexer.LexerInput; @@ -79,7 +80,8 @@ case '\r': input.consumeNewline(); case '\n': case EOF: - return token(JavaTokenId.STRING_LITERAL_INCOMPLETE); + return tokenFactory.createToken(JavaTokenId.STRING_LITERAL, + input.readLength(), PartType.START); } case '\'': // char literal @@ -93,7 +95,8 @@ case '\r': input.consumeNewline(); case '\n': case EOF: - return token(JavaTokenId.CHAR_LITERAL_INCOMPLETE); + return tokenFactory.createToken(JavaTokenId.CHAR_LITERAL, + input.readLength(), PartType.START); } case '/': @@ -120,10 +123,12 @@ if (c == '/') return token(JavaTokenId.JAVADOC_COMMENT); else if (c == EOF) - return token(JavaTokenId.JAVADOC_COMMENT_INCOMPLETE); + return tokenFactory.createToken(JavaTokenId.JAVADOC_COMMENT, + input.readLength(), PartType.START); } if (c == EOF) - return token(JavaTokenId.JAVADOC_COMMENT_INCOMPLETE); + return tokenFactory.createToken(JavaTokenId.JAVADOC_COMMENT, + input.readLength(), PartType.START); c = input.read(); } @@ -135,10 +140,12 @@ if (c == '/') return token(JavaTokenId.BLOCK_COMMENT); else if (c == EOF) - return token(JavaTokenId.BLOCK_COMMENT_INCOMPLETE); + return tokenFactory.createToken(JavaTokenId.BLOCK_COMMENT, + input.readLength(), PartType.START); } if (c == EOF) - return token(JavaTokenId.BLOCK_COMMENT_INCOMPLETE); + return tokenFactory.createToken(JavaTokenId.BLOCK_COMMENT, + input.readLength(), PartType.START); } } } // end of switch() Index: java/lexer/test/unit/data/testfiles/testInput.java.txt.tokens.txt =================================================================== RCS file: /cvs/java/lexer/test/unit/data/testfiles/testInput.java.txt.tokens.txt,v retrieving revision 1.1 diff -u -r1.1 testInput.java.txt.tokens.txt --- java/lexer/test/unit/data/testfiles/testInput.java.txt.tokens.txt 7 Nov 2006 16:17:16 -0000 1.1 +++ java/lexer/test/unit/data/testfiles/testInput.java.txt.tokens.txt 3 Mar 2007 19:20:40 -0000 @@ -3,7 +3,7 @@ BLOCK_COMMENT "/**/" JAVADOC_COMMENT "/***/" JAVADOC_COMMENT "/**\n*javadoc-comment*/" -BLOCK_COMMENT_INCOMPLETE "/* a", la=1 +BLOCK_COMMENT "/* a", la=1 ----- EOF ----- .t.e.s.t. Identifiers @@ -37,7 +37,7 @@ WHITESPACE " ", la=1 CHAR_LITERAL "'\\n'" WHITESPACE " ", la=1 -CHAR_LITERAL_INCOMPLETE "'a", la=1 +CHAR_LITERAL "'a", la=1 ----- EOF ----- .t.e.s.t. String Literals @@ -51,7 +51,7 @@ WHITESPACE "\n", la=1 STRING_LITERAL ""\\\\\\\\\\\\\\"\\""" WHITESPACE "\n", la=1 -STRING_LITERAL_INCOMPLETE ""\\n\\" \\"a", la=1 +STRING_LITERAL ""\\n\\" \\"a", la=1 ----- EOF ----- .t.e.s.t. Number Literals Index: java/lexer/test/unit/src/org/netbeans/lib/java/lexer/JavaLanguageTest.java =================================================================== RCS file: /cvs/java/lexer/test/unit/src/org/netbeans/lib/java/lexer/JavaLanguageTest.java,v retrieving revision 1.2 diff -u -r1.2 JavaLanguageTest.java --- java/lexer/test/unit/src/org/netbeans/lib/java/lexer/JavaLanguageTest.java 26 Oct 2006 20:45:19 -0000 1.2 +++ java/lexer/test/unit/src/org/netbeans/lib/java/lexer/JavaLanguageTest.java 3 Mar 2007 19:20:40 -0000 @@ -56,7 +56,7 @@ Set testCats = language.tokenCategories(); Collection cats = Arrays.asList(new String[] { "error", "identifier", "operator", "separator", "whitespace", "error", "comment", - "keyword", "string", "character", "number", "literal", "incomplete", + "keyword", "string", "character", "number", "literal", }); LexerTestUtilities.assertCollectionsEqual("Invalid categories", cats, testCats); Index: java/lexer/test/unit/src/org/netbeans/lib/java/lexer/JavaLexerBatchTest.java =================================================================== RCS file: /cvs/java/lexer/test/unit/src/org/netbeans/lib/java/lexer/JavaLexerBatchTest.java,v retrieving revision 1.2 diff -u -r1.2 JavaLexerBatchTest.java --- java/lexer/test/unit/src/org/netbeans/lib/java/lexer/JavaLexerBatchTest.java 4 Dec 2006 15:43:56 -0000 1.2 +++ java/lexer/test/unit/src/org/netbeans/lib/java/lexer/JavaLexerBatchTest.java 3 Mar 2007 19:20:40 -0000 @@ -23,6 +23,7 @@ import org.netbeans.api.java.lexer.JavaStringTokenId; import org.netbeans.api.java.lexer.JavaTokenId; import org.netbeans.api.java.lexer.JavadocTokenId; +import org.netbeans.api.lexer.PartType; import org.netbeans.api.lexer.TokenHierarchy; import org.netbeans.api.lexer.TokenId; import org.netbeans.api.lexer.TokenSequence; @@ -55,7 +56,8 @@ LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.BLOCK_COMMENT, "/**/"); LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.JAVADOC_COMMENT, "/***/"); LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.JAVADOC_COMMENT, "/**\n*javadoc-comment*/"); - LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.BLOCK_COMMENT_INCOMPLETE, "/* a"); + LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.BLOCK_COMMENT, "/* a"); + assertEquals(PartType.START, ts.token().partType()); } public void testIdentifiers() { @@ -95,7 +97,8 @@ LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.WHITESPACE, " "); LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.CHAR_LITERAL, "'\\n'"); LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.WHITESPACE, " "); - LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.CHAR_LITERAL_INCOMPLETE, "'a"); + LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.CHAR_LITERAL, "'a"); + assertEquals(PartType.START, ts.token().partType()); } public void testStringLiterals() { @@ -115,7 +118,8 @@ LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.WHITESPACE, " "); LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.STRING_LITERAL, "\"\\n\""); LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.WHITESPACE, " "); - LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.STRING_LITERAL_INCOMPLETE, "\"a"); + LexerTestUtilities.assertNextTokenEquals(ts, JavaTokenId.STRING_LITERAL, "\"a"); + assertEquals(PartType.START, ts.token().partType()); } public void testNumberLiterals() { Index: java/source/test/unit/src/org/netbeans/api/java/source/gen/WhitespaceIgnoringDiff.java =================================================================== RCS file: /cvs/java/source/test/unit/src/org/netbeans/api/java/source/gen/WhitespaceIgnoringDiff.java,v retrieving revision 1.3 diff -u -r1.3 WhitespaceIgnoringDiff.java --- java/source/test/unit/src/org/netbeans/api/java/source/gen/WhitespaceIgnoringDiff.java 31 Jan 2007 15:32:13 -0000 1.3 +++ java/source/test/unit/src/org/netbeans/api/java/source/gen/WhitespaceIgnoringDiff.java 3 Mar 2007 19:20:42 -0000 @@ -42,7 +42,7 @@ public WhitespaceIgnoringDiff() { } - private Set IGNORED_TOKENS = EnumSet.of(JavaTokenId.WHITESPACE, JavaTokenId.LINE_COMMENT, JavaTokenId.BLOCK_COMMENT, JavaTokenId.BLOCK_COMMENT_INCOMPLETE, JavaTokenId.JAVADOC_COMMENT, JavaTokenId.JAVADOC_COMMENT_INCOMPLETE); + private Set IGNORED_TOKENS = EnumSet.of(JavaTokenId.WHITESPACE, JavaTokenId.LINE_COMMENT, JavaTokenId.BLOCK_COMMENT, JavaTokenId.JAVADOC_COMMENT); public boolean diff(File first, File second, File diff) throws IOException { boolean result = diffImpl(first, second); Index: javadoc/nbproject/project.xml =================================================================== RCS file: /cvs/javadoc/nbproject/project.xml,v retrieving revision 1.18 diff -u -r1.18 project.xml --- javadoc/nbproject/project.xml 16 Feb 2007 18:02:20 -0000 1.18 +++ javadoc/nbproject/project.xml 3 Mar 2007 19:20:43 -0000 @@ -54,7 +54,7 @@ 1 - 1.1 + 1.2 @@ -80,7 +80,7 @@ 2 - 1.13 + 1.14 Index: javadoc/src/org/netbeans/modules/javadoc/hints/JavadocUtilities.java =================================================================== RCS file: /cvs/javadoc/src/org/netbeans/modules/javadoc/hints/JavadocUtilities.java,v retrieving revision 1.2 diff -u -r1.2 JavadocUtilities.java --- javadoc/src/org/netbeans/modules/javadoc/hints/JavadocUtilities.java 16 Feb 2007 01:49:30 -0000 1.2 +++ javadoc/src/org/netbeans/modules/javadoc/hints/JavadocUtilities.java 3 Mar 2007 19:20:43 -0000 @@ -578,7 +578,6 @@ IGNORE_TOKES = new HashSet(); IGNORE_TOKES.add(JavaTokenId.WHITESPACE); IGNORE_TOKES.add(JavaTokenId.BLOCK_COMMENT); - IGNORE_TOKES.add(JavaTokenId.BLOCK_COMMENT_INCOMPLETE); } } Index: languages/engine/src/org/netbeans/modules/languages/lexer/SLexer.java =================================================================== RCS file: /cvs/languages/engine/src/org/netbeans/modules/languages/lexer/SLexer.java,v retrieving revision 1.15 diff -u -r1.15 SLexer.java --- languages/engine/src/org/netbeans/modules/languages/lexer/SLexer.java 27 Feb 2007 16:02:09 -0000 1.15 +++ languages/engine/src/org/netbeans/modules/languages/lexer/SLexer.java 3 Mar 2007 19:20:45 -0000 @@ -25,6 +25,7 @@ import java.util.Map; import org.netbeans.api.languages.CharInput; import org.netbeans.api.languages.ASTToken; +import org.netbeans.api.lexer.PartType; import org.netbeans.api.languages.LanguagesManager; import org.netbeans.api.languages.ParseException; import org.netbeans.api.lexer.Token; @@ -232,14 +233,14 @@ tokenId, v.endOffset - v.startOffset, (TokenProperties) v.property, - null + PartType.COMPLETE ); else return tokenFactory.createPropertyToken ( tokenId, v.endOffset - v.startOffset, - tokenPropertyProvider, - v.property + new TokenPropProvider(v.property), + PartType.COMPLETE ); } @@ -264,22 +265,21 @@ // innerclasses ............................................................ - private static TokenPropertyProvider tokenPropertyProvider = new TokenPropertyProvider () { + private static final class TokenPropProvider implements TokenPropertyProvider { - public Object getValue (Token token, Object key) { - return null; + private final Object value; + + TokenPropProvider(Object value) { + this.value = value; } - - public Object getValue (Token token, Object tokenStoreKey, Object tokenStoreValue) { - if (tokenStoreKey.equals ("type")) - return tokenStoreValue; + + public Object getValue (Token token, Object key) { + if ("type".equals(key)) + return value; return null; } - public Object tokenStoreKey() { - return "type"; - } - }; + } static class TokenProperties implements TokenPropertyProvider { @@ -304,13 +304,6 @@ return null; } - public Object getValue (Token token, Object tokenStoreKey, Object tokenStoreValue) { - return null; - } - - public Object tokenStoreKey() { - return null; - } }; static class Vojta { Index: lexer/manifest.mf =================================================================== RCS file: /cvs/lexer/manifest.mf,v retrieving revision 1.14 diff -u -r1.14 manifest.mf --- lexer/manifest.mf 29 Jan 2007 14:27:16 -0000 1.14 +++ lexer/manifest.mf 3 Mar 2007 19:20:45 -0000 @@ -1,4 +1,4 @@ OpenIDE-Module: org.netbeans.modules.lexer/2 OpenIDE-Module-Localizing-Bundle: org/netbeans/lib/lexer/Bundle.properties -OpenIDE-Module-Specification-Version: 1.13.0 +OpenIDE-Module-Specification-Version: 1.14.0 OpenIDE-Module-Recommends: org.netbeans.spi.lexer.LanguageProvider Index: lexer/api/apichanges.xml =================================================================== RCS file: /cvs/lexer/api/apichanges.xml,v retrieving revision 1.12 diff -u -r1.12 apichanges.xml --- lexer/api/apichanges.xml 2 Feb 2007 14:46:23 -0000 1.12 +++ lexer/api/apichanges.xml 3 Mar 2007 19:20:45 -0000 @@ -93,6 +93,22 @@ + Added PartInfo for token parts support + + + + + +

+ Added PartInfo enum and Token.partInfo() + that identifies whether the token is COMPLETE or which part + of a complete token this part represents (START, INNER or END). +

+
+
+ + + Changed TokenSequence.move() and moveIndex() use Index: lexer/src/org/netbeans/api/lexer/PartType.java =================================================================== RCS file: lexer/src/org/netbeans/api/lexer/PartType.java diff -N lexer/src/org/netbeans/api/lexer/PartType.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lexer/src/org/netbeans/api/lexer/PartType.java 3 Mar 2007 19:20:46 -0000 @@ -0,0 +1,57 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.api.lexer; + +/** + * Whether {@link Token} represents a complete token + * or just a part of a complete token. + *
+ * A complete token may consist of one start token, zero or more middle tokens + * and zero or more end tokens (there may be incomplete token + * at the end of input e.g. an incomplete block comment so there is just a start + * part of a token). + * + * @author Miloslav Metelka + * @version 1.00 + */ + +public enum PartType { + + /** + * A given token represents a complete token. + */ + COMPLETE, + + /** + * A given token represents initial part of a complete token. + */ + START, + + /** + * A given token represents middle part of a complete token. + */ + MIDDLE, + + /** + * A given token represents end part of a complete token. + */ + END; + +} Index: lexer/src/org/netbeans/api/lexer/Token.java =================================================================== RCS file: /cvs/lexer/src/org/netbeans/api/lexer/Token.java,v retrieving revision 1.7 diff -u -r1.7 Token.java --- lexer/src/org/netbeans/api/lexer/Token.java 2 Feb 2007 14:47:08 -0000 1.7 +++ lexer/src/org/netbeans/api/lexer/Token.java 3 Mar 2007 19:20:46 -0000 @@ -194,6 +194,12 @@ * @return true if the token is flyweight or false otherwise. */ public abstract boolean isFlyweight(); + + /** + * Check whether this token represents a complete token + * or whether it's a part of a complete token. + */ + public abstract PartType partType(); /** * Check whether this token has preprocessed text Index: lexer/src/org/netbeans/lib/lexer/LexerInputOperation.java =================================================================== RCS file: /cvs/lexer/src/org/netbeans/lib/lexer/LexerInputOperation.java,v retrieving revision 1.6 diff -u -r1.6 LexerInputOperation.java --- lexer/src/org/netbeans/lib/lexer/LexerInputOperation.java 2 Feb 2007 14:47:16 -0000 1.6 +++ lexer/src/org/netbeans/lib/lexer/LexerInputOperation.java 3 Mar 2007 19:20:46 -0000 @@ -25,12 +25,13 @@ import org.netbeans.api.lexer.LanguagePath; import org.netbeans.api.lexer.TokenId; import org.netbeans.lib.editor.util.GapList; +import org.netbeans.lib.lexer.token.ComplexToken; +import org.netbeans.lib.lexer.token.PreprocessedTextToken; import org.netbeans.spi.lexer.CharPreprocessor; import org.netbeans.spi.lexer.Lexer; import org.netbeans.spi.lexer.LexerInput; import org.netbeans.lib.lexer.token.AbstractToken; -import org.netbeans.lib.lexer.token.PreprocessedTextToken; -import org.netbeans.lib.lexer.token.PropertyCustomTextToken; +import org.netbeans.lib.lexer.token.ComplexToken; import org.netbeans.spi.lexer.LexerRestartInfo; import org.netbeans.spi.lexer.TokenFactory; @@ -318,8 +319,8 @@ PreprocessedTextStorage storage = preprocessorOperation.createPreprocessedTextStorage( token.text(), extraPreprocessedChars); - if (token.getClass() == PropertyCustomTextToken.class) { - ((PropertyCustomTextToken)token).initPrep(storage, error); + if (token.getClass() == ComplexToken.class) { + ((ComplexToken)token).initPrep(storage, error); } else { ((PreprocessedTextToken)token).initPrep(storage, error); } Index: lexer/src/org/netbeans/lib/lexer/LexerUtilsConstants.java =================================================================== RCS file: /cvs/lexer/src/org/netbeans/lib/lexer/LexerUtilsConstants.java,v retrieving revision 1.7 diff -u -r1.7 LexerUtilsConstants.java --- lexer/src/org/netbeans/lib/lexer/LexerUtilsConstants.java 2 Feb 2007 14:47:17 -0000 1.7 +++ lexer/src/org/netbeans/lib/lexer/LexerUtilsConstants.java 3 Mar 2007 19:20:46 -0000 @@ -257,16 +257,6 @@ || (state1 != null && state1.equals(state2)); } - public static Object getTokenProperty(Token token, - TokenPropertyProvider propertyProvider, Object key, Object tokenStoreValue) { - Object tokenStoreKey = propertyProvider.tokenStoreKey(); - if (tokenStoreKey != null && tokenStoreKey.equals(key)) { // token store value - return propertyProvider.getValue(token, tokenStoreKey, tokenStoreValue); - } else { - return propertyProvider.getValue(token, key); - } - } - public static String idToString(TokenId id) { return id.name() + '[' + id.ordinal() + ']'; // NOI18N; } Index: lexer/src/org/netbeans/lib/lexer/token/AbstractToken.java =================================================================== RCS file: /cvs/lexer/src/org/netbeans/lib/lexer/token/AbstractToken.java,v retrieving revision 1.4 diff -u -r1.4 AbstractToken.java --- lexer/src/org/netbeans/lib/lexer/token/AbstractToken.java 2 Feb 2007 14:47:28 -0000 1.4 +++ lexer/src/org/netbeans/lib/lexer/token/AbstractToken.java 3 Mar 2007 19:20:46 -0000 @@ -19,6 +19,7 @@ package org.netbeans.lib.lexer.token; +import org.netbeans.api.lexer.PartType; import org.netbeans.api.lexer.Token; import org.netbeans.api.lexer.TokenHierarchy; import org.netbeans.api.lexer.TokenId; @@ -63,6 +64,7 @@ * * @return non-null identification of this token. */ + @Override public final T id() { return id; } @@ -70,6 +72,7 @@ /** * Get text represented by this token. */ + @Override public CharSequence text() { if (tokenList != null) { if (tokenList.getClass() == EmbeddedTokenList.class) { @@ -113,6 +116,7 @@ this.rawOffset = rawOffset; } + @Override public final boolean isFlyweight() { return (rawOffset == -1); } @@ -121,10 +125,17 @@ setRawOffset(-1); } + @Override + public PartType partType() { + return PartType.COMPLETE; + } + + @Override public boolean isCustomText() { return false; } + @Override public final int offset(TokenHierarchy tokenHierarchy) { if (rawOffset == -1) { // flyweight token return -1; @@ -140,26 +151,32 @@ } } + @Override public boolean isPreprocessedText() { return false; } + @Override public CharSequence preprocessedText() { return null; } + @Override public String preprocessError() { return null; } + @Override public int preprocessErrorIndex() { return -1; } + @Override public boolean hasProperties() { return false; } + @Override public Object getProperty(Object key) { return null; } Index: lexer/src/org/netbeans/lib/lexer/token/ComplexToken.java =================================================================== RCS file: lexer/src/org/netbeans/lib/lexer/token/ComplexToken.java diff -N lexer/src/org/netbeans/lib/lexer/token/ComplexToken.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lexer/src/org/netbeans/lib/lexer/token/ComplexToken.java 3 Mar 2007 19:20:46 -0000 @@ -0,0 +1,83 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.lib.lexer.token; + +import org.netbeans.api.lexer.PartType; +import org.netbeans.api.lexer.TokenId; +import org.netbeans.lib.lexer.LexerUtilsConstants; +import org.netbeans.lib.lexer.PreprocessedTextStorage; +import org.netbeans.spi.lexer.CharPreprocessor; +import org.netbeans.spi.lexer.TokenPropertyProvider; + +/** + * Token that holds information about preprocessed characters + * and also carries properties. + * + *

+ * Instances of this token are more costly than other token types + * because in addition to regular information they store preprocessed + * text of the token. + * + * @author Miloslav Metelka + * @version 1.00 + */ + +public final class ComplexToken extends PreprocessedTextToken { + + private final TokenPropertyProvider propertyProvider; // 36 bytes (32-super + 4) + + private final CharSequence customText; // 40 bytes + + private final PartType partType; // 44 bytes + + public ComplexToken(T id, int length, + TokenPropertyProvider propertyProvider, CharSequence customText, PartType partType) { + super(id, length); + this.propertyProvider = propertyProvider; + this.customText = customText; + this.partType = partType; + } + + @Override + public boolean hasProperties() { + return (propertyProvider != null); + } + + @Override + public Object getProperty(Object key) { + return (propertyProvider != null) ? propertyProvider.getValue(this, key) : null; + } + + @Override + public CharSequence text() { + return (customText != null) ? customText : super.text(); + } + + @Override + public PartType partType() { + return partType; + } + + @Override + protected String dumpInfoTokenType() { + return "PPrT"; // NOI18N "PrepToken" + } + +} Index: lexer/src/org/netbeans/lib/lexer/token/CustomTextToken.java =================================================================== RCS file: /cvs/lexer/src/org/netbeans/lib/lexer/token/CustomTextToken.java,v retrieving revision 1.4 diff -u -r1.4 CustomTextToken.java --- lexer/src/org/netbeans/lib/lexer/token/CustomTextToken.java 2 Feb 2007 14:47:28 -0000 1.4 +++ lexer/src/org/netbeans/lib/lexer/token/CustomTextToken.java 3 Mar 2007 19:20:46 -0000 @@ -19,6 +19,7 @@ package org.netbeans.lib.lexer.token; +import org.netbeans.api.lexer.PartType; import org.netbeans.api.lexer.TokenId; /** @@ -32,24 +33,29 @@ */ public class CustomTextToken extends DefaultToken { - + private final CharSequence text; // 28 bytes (24-super + 4) - + + private final PartType partType; // 32 bytes + /** * @param id non-null identification of the token. * @param length length of the token. * @param text non-null text of the token. */ - public CustomTextToken(T id, int length, CharSequence text) { + public CustomTextToken(T id, int length, CharSequence text, PartType partType) { super(id, length); assert (text != null); this.text = text; + this.partType = partType; } - + + @Override public final CharSequence text() { return text; } + @Override protected String dumpInfoTokenType() { return "CusT"; // NOI18N "TextToken" or "FlyToken" } Index: lexer/src/org/netbeans/lib/lexer/token/DefaultToken.java =================================================================== RCS file: /cvs/lexer/src/org/netbeans/lib/lexer/token/DefaultToken.java,v retrieving revision 1.5 diff -u -r1.5 DefaultToken.java --- lexer/src/org/netbeans/lib/lexer/token/DefaultToken.java 2 Feb 2007 14:47:28 -0000 1.5 +++ lexer/src/org/netbeans/lib/lexer/token/DefaultToken.java 3 Mar 2007 19:20:46 -0000 @@ -58,10 +58,12 @@ this.length = 0; } + @Override public final int length() { return length; } + @Override protected String dumpInfoTokenType() { return "DefT"; // NOI18N "TextToken" or "FlyToken" } Index: lexer/src/org/netbeans/lib/lexer/token/PreprocessedTextToken.java =================================================================== RCS file: /cvs/lexer/src/org/netbeans/lib/lexer/token/PreprocessedTextToken.java,v retrieving revision 1.3 diff -u -r1.3 PreprocessedTextToken.java --- lexer/src/org/netbeans/lib/lexer/token/PreprocessedTextToken.java 2 Feb 2007 14:47:29 -0000 1.3 +++ lexer/src/org/netbeans/lib/lexer/token/PreprocessedTextToken.java 3 Mar 2007 19:20:46 -0000 @@ -50,22 +50,27 @@ this.prepError = prepError; } + @Override public synchronized CharSequence preprocessedText() { return prepTextStorage; } + @Override public synchronized boolean isPreprocessedText() { - return true; + return (prepTextStorage != null); } + @Override public String preprocessError() { return (prepError != null) ? prepError.message() : null; } + @Override public int preprocessErrorIndex() { return (prepError != null) ? prepError.index() : -1; } + @Override protected String dumpInfoTokenType() { return "PreT"; // NOI18N "PrepToken" } Index: lexer/src/org/netbeans/lib/lexer/token/PropertyCustomTextToken.java =================================================================== RCS file: lexer/src/org/netbeans/lib/lexer/token/PropertyCustomTextToken.java diff -N lexer/src/org/netbeans/lib/lexer/token/PropertyCustomTextToken.java --- lexer/src/org/netbeans/lib/lexer/token/PropertyCustomTextToken.java 2 Feb 2007 14:47:29 -0000 1.3 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,90 +0,0 @@ -/* - * The contents of this file are subject to the terms of the Common Development - * and Distribution License (the License). You may not use this file except in - * compliance with the License. - * - * You can obtain a copy of the License at http://www.netbeans.org/cddl.html - * or http://www.netbeans.org/cddl.txt. - * - * When distributing Covered Code, include this CDDL Header Notice in each file - * and include the License file at http://www.netbeans.org/cddl.txt. - * If applicable, add the following below the CDDL Header, with the fields - * enclosed by brackets [] replaced by your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun - * Microsystems, Inc. All Rights Reserved. - */ - -package org.netbeans.lib.lexer.token; - -import org.netbeans.api.lexer.TokenId; -import org.netbeans.lib.lexer.CharPreprocessorError; -import org.netbeans.lib.lexer.LexerUtilsConstants; -import org.netbeans.lib.lexer.PreprocessedTextStorage; -import org.netbeans.spi.lexer.TokenPropertyProvider; - -/** - * Token that holds information about preprocessed characters. - * - *

- * Instances of this token are more costly than other token types - * because in addition to regular information they store preprocessed - * text of the token. - * - * @author Miloslav Metelka - * @version 1.00 - */ - -public final class PropertyCustomTextToken extends CustomTextToken { - - private TokenPropertyProvider propertyProvider; // 36 bytes (32-super + 4) - - private Object tokenStoreValue; // 40 bytes - - private PreprocessedTextStorage prepTextStorage; // 44 bytes - - private CharPreprocessorError prepError; // 48 bytes - - public PropertyCustomTextToken(T id, int length, CharSequence text, - TokenPropertyProvider propertyProvider, Object tokenStoreValue) { - super(id, length, text); - this.propertyProvider = propertyProvider; - this.tokenStoreValue = tokenStoreValue; - } - - public void initPrep(PreprocessedTextStorage prepTextStorage, CharPreprocessorError prepError) { - this.prepTextStorage = prepTextStorage; - this.prepError = prepError; - } - - public synchronized CharSequence preprocessedText() { - return prepTextStorage; - } - - public synchronized boolean isPreprocessedText() { - return true; - } - - public String preprocessError() { - return (prepError != null) ? prepError.message() : null; - } - - public int preprocessErrorIndex() { - return (prepError != null) ? prepError.index() : -1; - } - - public boolean hasProperties() { - return true; - } - - public Object getProperty(Object key) { - return LexerUtilsConstants.getTokenProperty(this, propertyProvider, key, tokenStoreValue); - } - - protected String dumpInfoTokenType() { - return "PPCT"; // NOI18N - } - -} Index: lexer/src/org/netbeans/lib/lexer/token/PropertyPreprocessedTextToken.java =================================================================== RCS file: lexer/src/org/netbeans/lib/lexer/token/PropertyPreprocessedTextToken.java diff -N lexer/src/org/netbeans/lib/lexer/token/PropertyPreprocessedTextToken.java --- lexer/src/org/netbeans/lib/lexer/token/PropertyPreprocessedTextToken.java 2 Feb 2007 14:47:29 -0000 1.3 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,67 +0,0 @@ -/* - * The contents of this file are subject to the terms of the Common Development - * and Distribution License (the License). You may not use this file except in - * compliance with the License. - * - * You can obtain a copy of the License at http://www.netbeans.org/cddl.html - * or http://www.netbeans.org/cddl.txt. - * - * When distributing Covered Code, include this CDDL Header Notice in each file - * and include the License file at http://www.netbeans.org/cddl.txt. - * If applicable, add the following below the CDDL Header, with the fields - * enclosed by brackets [] replaced by your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun - * Microsystems, Inc. All Rights Reserved. - */ - -package org.netbeans.lib.lexer.token; - -import org.netbeans.api.lexer.TokenId; -import org.netbeans.lib.lexer.LexerUtilsConstants; -import org.netbeans.lib.lexer.PreprocessedTextStorage; -import org.netbeans.spi.lexer.CharPreprocessor; -import org.netbeans.spi.lexer.TokenPropertyProvider; - -/** - * Token that holds information about preprocessed characters - * and also carries properties. - * - *

- * Instances of this token are more costly than other token types - * because in addition to regular information they store preprocessed - * text of the token. - * - * @author Miloslav Metelka - * @version 1.00 - */ - -public final class PropertyPreprocessedTextToken extends PreprocessedTextToken { - - private TokenPropertyProvider propertyProvider; // 28 bytes (24-super + 4) - - private Object tokenStoreValue; // 32 bytes - - public PropertyPreprocessedTextToken(T id, int length, - TokenPropertyProvider propertyProvider, Object tokenStoreValue) { - super(id, length); - this.propertyProvider = propertyProvider; - this.tokenStoreValue = tokenStoreValue; - } - - public boolean hasProperties() { - return true; - } - - public Object getProperty(Object key) { - return LexerUtilsConstants.getTokenProperty(this, propertyProvider, key, tokenStoreValue); - } - - protected String dumpInfoTokenType() { - return "PPrT"; // NOI18N "PrepToken" - } - -} - Index: lexer/src/org/netbeans/lib/lexer/token/PropertyToken.java =================================================================== RCS file: /cvs/lexer/src/org/netbeans/lib/lexer/token/PropertyToken.java,v retrieving revision 1.3 diff -u -r1.3 PropertyToken.java --- lexer/src/org/netbeans/lib/lexer/token/PropertyToken.java 2 Feb 2007 14:47:30 -0000 1.3 +++ lexer/src/org/netbeans/lib/lexer/token/PropertyToken.java 3 Mar 2007 19:20:46 -0000 @@ -19,6 +19,8 @@ package org.netbeans.lib.lexer.token; +import org.netbeans.api.lexer.PartType; +import org.netbeans.api.lexer.Token; import org.netbeans.api.lexer.TokenId; import org.netbeans.lib.lexer.LexerUtilsConstants; import org.netbeans.spi.lexer.TokenPropertyProvider; @@ -37,27 +39,35 @@ public final class PropertyToken extends DefaultToken { - private TokenPropertyProvider propertyProvider; // 28 bytes (24-super + 4) + private final TokenPropertyProvider propertyProvider; // 28 bytes (24-super + 4) - private Object tokenStoreValue; // 32 bytes + private final PartType partType; // 32 bytes public PropertyToken(T id, int length, - TokenPropertyProvider propertyProvider, Object tokenStoreValue) { + TokenPropertyProvider propertyProvider, PartType partType) { super(id, length); this.propertyProvider = propertyProvider; - this.tokenStoreValue = tokenStoreValue; + this.partType = partType; } + @Override public boolean hasProperties() { - return true; + return (propertyProvider != null); } + @Override public Object getProperty(Object key) { - return LexerUtilsConstants.getTokenProperty(this, propertyProvider, key, tokenStoreValue); + return (propertyProvider != null) ? propertyProvider.getValue(this, key) : null; + } + + @Override + public PartType partType() { + return partType; } + @Override protected String dumpInfoTokenType() { return "ProT"; // NOI18N "PrepToken" } - + } Index: lexer/src/org/netbeans/lib/lexer/token/TextToken.java =================================================================== RCS file: /cvs/lexer/src/org/netbeans/lib/lexer/token/TextToken.java,v retrieving revision 1.4 diff -u -r1.4 TextToken.java --- lexer/src/org/netbeans/lib/lexer/token/TextToken.java 2 Feb 2007 14:47:30 -0000 1.4 +++ lexer/src/org/netbeans/lib/lexer/token/TextToken.java 3 Mar 2007 19:20:46 -0000 @@ -69,10 +69,12 @@ this.text = text; } + @Override public final int length() { return text.length(); } + @Override public final CharSequence text() { return text; } @@ -81,6 +83,7 @@ return new TextToken(id(), tokenList, rawOffset, text()); } + @Override protected String dumpInfoTokenType() { return isFlyweight() ? "FlyT" : "TexT"; // NOI18N "TextToken" or "FlyToken" } Index: lexer/src/org/netbeans/spi/lexer/TokenFactory.java =================================================================== RCS file: /cvs/lexer/src/org/netbeans/spi/lexer/TokenFactory.java,v retrieving revision 1.6 diff -u -r1.6 TokenFactory.java --- lexer/src/org/netbeans/spi/lexer/TokenFactory.java 2 Feb 2007 14:47:34 -0000 1.6 +++ lexer/src/org/netbeans/spi/lexer/TokenFactory.java 3 Mar 2007 19:20:46 -0000 @@ -20,6 +20,7 @@ package org.netbeans.spi.lexer; import java.util.Set; +import org.netbeans.api.lexer.PartType; import org.netbeans.api.lexer.Token; import org.netbeans.api.lexer.TokenId; import org.netbeans.lib.editor.util.CharSequenceUtilities; @@ -28,9 +29,9 @@ import org.netbeans.lib.lexer.TokenIdImpl; import org.netbeans.lib.lexer.token.CustomTextToken; import org.netbeans.lib.lexer.token.DefaultToken; +import org.netbeans.lib.lexer.token.ComplexToken; import org.netbeans.lib.lexer.token.PreprocessedTextToken; -import org.netbeans.lib.lexer.token.PropertyCustomTextToken; -import org.netbeans.lib.lexer.token.PropertyPreprocessedTextToken; +import org.netbeans.lib.lexer.token.ComplexToken; import org.netbeans.lib.lexer.token.PropertyToken; import org.netbeans.lib.lexer.token.TextToken; @@ -104,6 +105,39 @@ } /** + * Create regular token instance with an explicit length and part type. + * + * @param id non-null token id recognized by the lexer. + * @param length >=0 length of the token to be created. The length must not + * exceed the number of characters read from the lexer input. + * @param partType whether this token is complete token or a part of a complete token. + * @return non-null regular token instance. + *
+ * If there were any characters preprocessed by {@link CharPreprocessor} + * then a special token instance will be created for it. + *
+ * {@link #SKIP_TOKEN} will be returned + * if tokens for the given token id should be skipped + * because of token id filter. + */ + public Token createToken(T id, int length, PartType partType) { + checkPartTypeNonNull(partType); + if (partType == PartType.COMPLETE) + return createToken(id, length); + + if (isSkipToken(id)) { + operation.tokenRecognized(length, true); + return skipToken(); + } else { // Do not skip the token + if (operation.tokenRecognized(length, false)) { // Create preprocessed token + return new ComplexToken(id, operation.tokenLength(), null, null, partType); + } else { + return new PropertyToken(id, operation.tokenLength(), null, partType); + } + } + } + + /** * Get flyweight token for the given arguments. *
* Note: The returned token will not be flyweight under certain @@ -165,9 +199,7 @@ * @param length >=0 length of the token to be created. The length must not * exceed the number of characters read from the lexer input. * @param propertyProvider non-null token property provider. - * @param tokenStoreValue explicit value for property stored in the token itself - * or null if there is no explicit value (value will be computed lazily when asked). - *
+ * @param partType whether this token is complete or just a part of complete token. * See {@link TokenPropertyProvider} for examples how this parameter may be used. * @return non-null property token instance. *
@@ -179,17 +211,18 @@ * because of token id filter. */ public Token createPropertyToken(T id, int length, - TokenPropertyProvider propertyProvider, Object tokenStoreValue) { + TokenPropertyProvider propertyProvider, PartType partType) { + checkPartTypeNonNull(partType); if (isSkipToken(id)) { operation.tokenRecognized(length, true); return skipToken(); } else { // Do not skip the token if (operation.tokenRecognized(length, false)) { // Create preprocessed token - return new PropertyPreprocessedTextToken(id, operation.tokenLength(), - propertyProvider, tokenStoreValue); + return new ComplexToken(id, operation.tokenLength(), + propertyProvider, null, partType); } else { return new PropertyToken(id, operation.tokenLength(), - propertyProvider, tokenStoreValue); + propertyProvider, partType); } } } @@ -198,16 +231,16 @@ * Create token with a custom text that possibly differs from the text * represented by the token in the input text. */ - public Token createCustomTextToken(T id, CharSequence text, int length) { + public Token createCustomTextToken(T id, CharSequence text, int length, PartType partType) { + checkPartTypeNonNull(partType); if (isSkipToken(id)) { operation.tokenRecognized(length, true); return skipToken(); } else { // Do not skip the token if (operation.tokenRecognized(length, false)) { // Create preprocessed token - return new PropertyCustomTextToken(id, - operation.tokenLength(), text, null, null); + return new ComplexToken(id, operation.tokenLength(), null, text, partType); } else { - return new CustomTextToken(id, operation.tokenLength(), text); + return new CustomTextToken(id, operation.tokenLength(), text, partType); } } } @@ -220,6 +253,11 @@ @SuppressWarnings("unchecked") // NOI18N private Token skipToken() { return SKIP_TOKEN; + } + + private void checkPartTypeNonNull(PartType partType) { + if (partType == null) + throw new IllegalArgumentException("partType must be non-null"); } } Index: lexer/src/org/netbeans/spi/lexer/TokenPropertyProvider.java =================================================================== RCS file: /cvs/lexer/src/org/netbeans/spi/lexer/TokenPropertyProvider.java,v retrieving revision 1.5 diff -u -r1.5 TokenPropertyProvider.java --- lexer/src/org/netbeans/spi/lexer/TokenPropertyProvider.java 2 Feb 2007 14:47:35 -0000 1.5 +++ lexer/src/org/netbeans/spi/lexer/TokenPropertyProvider.java 3 Mar 2007 19:20:46 -0000 @@ -25,121 +25,53 @@ /** * Provides extra properties of a token. *
- * A special kind of token PropertyToken allows to carry token properties. + * Normally each token has an extra instance of the property provider: + *

+ * final class MyTokenPropertyProvider implements TokenPropertyProvider {
+ *
+ *     private final Object value;
+ *
+ *     TokenPropProvider(Object value) {
+ *         this.value = value;
+ *     }
+ *      
+ *     public Object getValue (Token token, Object key) {
+ *         if ("type".equals(key))
+ *             return value;
+ *         return null;
+ *     }
+ *
+ * }
+ * 
*
- * That token may store a value of one property in its instance - * (see PropertyToken.tokenStoreValue. If the provider - * wants to use that field for storing of the value it needs to return - * the corresponding key for that value from {@link #tokenStoreKey()}. - * - *

- * Generally this interface can be used in multiple ways: - *

    - *
  • - * A new instance of the provider per each token. - *
    - * Example of storing a value for "key" key in the provider: - *
    - *    final class MyTokenPropertyProvider implements TokenPropertyProvider {
    - * 
    - *       private final Object value;
    - * 
    - *       MyTokenPropertyProvider(Object value) {
    - *           this.value = value;
    - *       }
    - *
    - *       public Object getValue(Token token, Object key) {
    - *           if ("key".equals(key)) {
    - *               return value;
    - *           }
    - *           return null;
    - *       }
    - * 
    - *       public Object getValue(Token token, Object tokenStoreKey, Object tokenStoreValue) {
    - *           return null; // not using token's storage
    - *       }
    - * 
    - *       public Object tokenStoreKey() {
    - *           return null; // not using token's storage
    - *       }
    - * 
    - *    }
    - *    
    - *
  • - * - *
  • - * A single instance of the provider for multiple tokens. - * Each token may have a specific value of the given property. - *
    - * This might be achieved by returning the particular key - * from {@link #tokenStoreKey()} and using the token store value - * for the storage of the property value. - *
    - * Example of storing a value for "key" by the token's storage: - *
    - *    final class MyTokenPropertyProvider implements TokenPropertyProvider {
    - * 
    - *       static final MyTokenPropertyProvider INSTANCE = new MyTokenPropertyProvider();
    - * 
    - *       private MyTokenPropertyProvider() {
    - *       }
    + * However multiple flyweight instances of the provider may be used to save memory
    + * if there are just several values for a property.
    + * 
    + * Example of two instances of a provider for boolean property "key": + *
    + * final class MyTokenPropertyProvider implements TokenPropertyProvider {
      *
    - *       public Object getValue(Token token, Object key) {
    - *           return null; // no extra properties
    - *       }
    - * 
    - *       public Object getValue(Token token, Object tokenStoreKey, Object tokenStoreValue) {
    - *           // Assuming that the appropriate tokenStoreValue was passed to
    - *           // TokenFactory.createPropertyToken(id, length, propertyProvider, tokenStoreValue);
    - *           return tokenStoreValue;
    - *       }
    - * 
    - *       public Object tokenStoreKey() {
    - *           return "key";
    - *       }
    - * 
    - *    }
    - *    
    - *
  • - * - *
  • - * Multiple flyweight instances of the provider. - * This might be useful if there is just several values for the property. - *
    - * Example of two instances of a provider for "key": - *
    - *    final class MyTokenPropertyProvider implements TokenPropertyProvider {
    - * 
    - *       static final MyTokenPropertyProvider TRUE = new MyTokenPropertyProvider(Boolean.TRUE);
    - * 
    - *       static final MyTokenPropertyProvider FALSE = new MyTokenPropertyProvider(Boolean.FALSE);
    - * 
    - *       private final Boolean value;
    - * 
    - *       private MyTokenPropertyProvider(Boolean value) {
    - *           this.value = value;
    - *       }
    - *
    - *       public Object getValue(Token token, Object key) {
    - *           if ("key".equals(key)) {
    - *               return value;
    - *           }
    - *           return null;
    - *       }
    - * 
    - *       public Object getValue(Token token, Object tokenStoreKey, Object tokenStoreValue) {
    - *           return null; // not using token's storage
    - *       }
    - * 
    - *       public Object tokenStoreKey() {
    - *           return null; // not using token's storage
    - *       }
    + *     static final MyTokenPropertyProvider TRUE = new MyTokenPropertyProvider(Boolean.TRUE);
    + *
    + *     static final MyTokenPropertyProvider FALSE = new MyTokenPropertyProvider(Boolean.FALSE);
      * 
    - *    }
    - *    
    - *
  • - *
+ * private final Boolean value; + * + * private MyTokenPropertyProvider(Boolean value) { + * this.value = value; + * } + * + * public Object getValue(Token token, Object key) { + * if ("key".equals(key)) { + * return value; + * } + * return null; + * } * + * } + * + *
+ * A special kind of token PropertyToken allows to carry token properties. * * @author Miloslav Metelka * @version 1.00 @@ -148,41 +80,13 @@ public interface TokenPropertyProvider { /** - * Get value of a property which is not a token-store property. + * Get value of a token property. * * @param token non-null token for which the property is being retrieved. + * It might be useful if the property would be computed dynamically. * @param key non-null key for which the value should be retrieved. * @return value of the property or null if there is no value for the given key. */ Object getValue(Token token, Object key); - - /** - * Get value of a token-store property. - *
- * This method is only invoked if {@link #tokenStoreKey()} returned non-null value. - *
- * When called for the first time the tokenStoreValue - * will have the value given to - * {@link TokenFactory#createPropertyToken(TokenId,int,TokenPropertyProvider,Object)}. - *
- * For subsequent invocations of this method the value returned from - * a last call to it (for the given token) will be used. - * - * @param token non-null token for which the property is being retrieved. - * @param tokenStoreKey non-null key for which the value should be retrieved. - * @param tokenStoreValue value that was is currently stored in the token. - * @return value for the tokenStoreKey. The value will be both returned - * and stored in the token. - */ - Object getValue(Token token, Object tokenStoreKey, Object tokenStoreValue); - - /** - * Get a key of the property that is stored in the token. - * - * @return key of the property which is stored in the token itself - * or null if the property provider does not want any property - * to be stored in the token. - */ - Object tokenStoreKey(); } Index: lexer/test/unit/src/org/netbeans/api/lexer/CustomTokenClassTest.java =================================================================== RCS file: /cvs/lexer/test/unit/src/org/netbeans/api/lexer/CustomTokenClassTest.java,v retrieving revision 1.3 diff -u -r1.3 CustomTokenClassTest.java --- lexer/test/unit/src/org/netbeans/api/lexer/CustomTokenClassTest.java 2 Feb 2007 14:47:37 -0000 1.3 +++ lexer/test/unit/src/org/netbeans/api/lexer/CustomTokenClassTest.java 3 Mar 2007 19:20:46 -0000 @@ -90,6 +90,10 @@ return false; } + public PartType partType() { + return null; + } + } } Index: lexer/test/unit/src/org/netbeans/lib/lexer/test/LexerTestUtilities.java =================================================================== RCS file: /cvs/lexer/test/unit/src/org/netbeans/lib/lexer/test/LexerTestUtilities.java,v retrieving revision 1.8 diff -u -r1.8 LexerTestUtilities.java --- lexer/test/unit/src/org/netbeans/lib/lexer/test/LexerTestUtilities.java 2 Feb 2007 14:47:43 -0000 1.8 +++ lexer/test/unit/src/org/netbeans/lib/lexer/test/LexerTestUtilities.java 3 Mar 2007 19:20:47 -0000 @@ -217,6 +217,7 @@ TestCase.assertEquals(message + "Invalid token.state()", state(ts), state(ts2)); } TestCase.assertEquals(message + "Invalid token length", t.length(), t2.length()); + TestCase.assertEquals(message + "Invalid token part", t.partType(), t2.partType()); } /** Index: lexer/test/unit/src/org/netbeans/lib/lexer/test/dump/TokenDumpCheck.java =================================================================== RCS file: /cvs/lexer/test/unit/src/org/netbeans/lib/lexer/test/dump/TokenDumpCheck.java,v retrieving revision 1.3 diff -u -r1.3 TokenDumpCheck.java --- lexer/test/unit/src/org/netbeans/lib/lexer/test/dump/TokenDumpCheck.java 2 Feb 2007 14:47:46 -0000 1.3 +++ lexer/test/unit/src/org/netbeans/lib/lexer/test/dump/TokenDumpCheck.java 3 Mar 2007 19:20:47 -0000 @@ -27,7 +27,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.regex.Pattern; import org.netbeans.api.lexer.Language; import org.netbeans.api.lexer.Token; import org.netbeans.api.lexer.TokenHierarchy; Index: lexer/test/unit/src/org/netbeans/lib/lexer/test/dump/TokenDumpLexer.java =================================================================== RCS file: /cvs/lexer/test/unit/src/org/netbeans/lib/lexer/test/dump/TokenDumpLexer.java,v retrieving revision 1.3 diff -u -r1.3 TokenDumpLexer.java --- lexer/test/unit/src/org/netbeans/lib/lexer/test/dump/TokenDumpLexer.java 2 Feb 2007 14:47:46 -0000 1.3 +++ lexer/test/unit/src/org/netbeans/lib/lexer/test/dump/TokenDumpLexer.java 3 Mar 2007 19:20:47 -0000 @@ -19,6 +19,7 @@ package org.netbeans.lib.lexer.test.dump; +import org.netbeans.api.lexer.PartType; import org.netbeans.api.lexer.Token; import org.netbeans.spi.lexer.Lexer; import org.netbeans.spi.lexer.LexerInput; @@ -182,7 +183,7 @@ case EOF: input.backup(1); return tokenFactory.createPropertyToken(id, input.readLength(), - UnicodeCharValueProvider.INSTANCE, new Character(ch)); + new UnicodeCharValueProvider(new Character(ch)), PartType.COMPLETE); } } input.backup(1); @@ -198,18 +199,16 @@ private static final class UnicodeCharValueProvider implements TokenPropertyProvider { - static final UnicodeCharValueProvider INSTANCE = new UnicodeCharValueProvider(); + private Character ch; - public Object getValue(Token token, Object key) { - return null; // no non-tokenStore value - } - - public Object getValue(Token token, Object tokenStoreKey, Object tokenStoreValue) { - return tokenStoreValue; + UnicodeCharValueProvider(Character ch) { + this.ch = ch; } - public Object tokenStoreKey() { - return TokenDumpTokenId.UNICODE_CHAR_TOKEN_PROPERTY; + public Object getValue(Token token, Object key) { + if (TokenDumpTokenId.UNICODE_CHAR_TOKEN_PROPERTY.equals(key)) + return ch; + return null; // no non-tokenStore value } } Index: web/jspsyntax/lexer/nbproject/project.xml =================================================================== RCS file: /cvs/web/jspsyntax/lexer/nbproject/project.xml,v retrieving revision 1.7 diff -u -r1.7 project.xml --- web/jspsyntax/lexer/nbproject/project.xml 12 Jan 2007 13:15:58 -0000 1.7 +++ web/jspsyntax/lexer/nbproject/project.xml 3 Mar 2007 19:21:05 -0000 @@ -46,7 +46,7 @@ 1 - 1.1 + 1.2
@@ -55,7 +55,7 @@ 2 - 1.12 + 1.14 Index: web/jspsyntax/lexer/src/org/netbeans/lib/jsp/lexer/JspLexer.java =================================================================== RCS file: /cvs/web/jspsyntax/lexer/src/org/netbeans/lib/jsp/lexer/JspLexer.java,v retrieving revision 1.20 diff -u -r1.20 JspLexer.java --- web/jspsyntax/lexer/src/org/netbeans/lib/jsp/lexer/JspLexer.java 22 Jan 2007 14:49:49 -0000 1.20 +++ web/jspsyntax/lexer/src/org/netbeans/lib/jsp/lexer/JspLexer.java 3 Mar 2007 19:21:06 -0000 @@ -24,6 +24,7 @@ import org.netbeans.api.jsp.lexer.JspTokenId; import org.netbeans.api.lexer.InputAttributes; import org.netbeans.api.lexer.LanguagePath; +import org.netbeans.api.lexer.PartType; import org.netbeans.api.lexer.Token; import org.netbeans.spi.jsp.lexer.JspParseData; import org.netbeans.spi.lexer.Lexer; @@ -1112,7 +1113,8 @@ throw new IllegalStateException("Unsupported scriptlet type " + lexerStateJspScriptlet); } - return tokenFactory.createPropertyToken(tokenId, input.readLength(), new JspTokenPropertyProvider(), scriptletType); + return tokenFactory.createPropertyToken(tokenId, input.readLength(), + new JspTokenPropertyProvider(scriptletType), PartType.COMPLETE); } private void checkToken(JspTokenId tokenId) { @@ -1127,19 +1129,19 @@ private static class JspTokenPropertyProvider implements TokenPropertyProvider { - public Object getValue(Token token, Object key) { - return null; + private final JspTokenId.JavaCodeType scriptletType; + + JspTokenPropertyProvider(JspTokenId.JavaCodeType scriptletType) { + this.scriptletType = scriptletType; } - public Object getValue(Token token, Object tokenStoreKey, - Object tokenStoreValue) { - return tokenStoreValue; + public Object getValue(Token token, Object key) { + if (JspTokenId.SCRIPTLET_TOKEN_TYPE_PROPERTY.equals(key)) + return scriptletType; + return null; } - public Object tokenStoreKey() { - return JspTokenId.SCRIPTLET_TOKEN_TYPE_PROPERTY; - } -} + } }