diff --git a/pmd-java/etc/grammar/Java.jjt b/pmd-java/etc/grammar/Java.jjt
index ee668ea9c4..cc4afba736 100644
--- a/pmd-java/etc/grammar/Java.jjt
+++ b/pmd-java/etc/grammar/Java.jjt
@@ -232,7 +232,7 @@ options {
STATIC = false;
USER_CHAR_STREAM = true;
JDK_VERSION = "1.5";
- TOKEN_FACTORY = "JavaTokenUtils";
+ TOKEN_FACTORY = "JavaTokenFactory";
MULTI = true;
VISITOR = true;
@@ -2999,14 +2999,14 @@ void AssertStatement() :
void RUNSIGNEDSHIFT() #void:
{}
{
- LOOKAHEAD({ JavaTokenUtils.getRealKind(getToken(1)) == RUNSIGNEDSHIFT})
+ LOOKAHEAD({ JavaTokenFactory.getRealKind(getToken(1)) == RUNSIGNEDSHIFT})
">" ">" ">"
}
void RSIGNEDSHIFT() #void:
{}
{
- LOOKAHEAD({ JavaTokenUtils.getRealKind(getToken(1)) == RSIGNEDSHIFT})
+ LOOKAHEAD({ JavaTokenFactory.getRealKind(getToken(1)) == RSIGNEDSHIFT})
">" ">"
}
diff --git a/pmd-java/src/main/ant/alljavacc.xml b/pmd-java/src/main/ant/alljavacc.xml
index 02629e976e..75faa43c60 100644
--- a/pmd-java/src/main/ant/alljavacc.xml
+++ b/pmd-java/src/main/ant/alljavacc.xml
@@ -145,20 +145,20 @@
-
-
+
+ expression="protected net.sourceforge.pmd.lang.ast.impl.JavaccToken jjFillToken() {return JavaTokenFactory.newToken(jjmatchedKind, input_stream);}"/>
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/JavaTokenUtils.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/JavaTokenFactory.java
similarity index 84%
rename from pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/JavaTokenUtils.java
rename to pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/JavaTokenFactory.java
index 6ac09c6d35..05e09d790c 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/JavaTokenUtils.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/JavaTokenFactory.java
@@ -9,15 +9,18 @@ import net.sourceforge.pmd.lang.ast.impl.JavaCharStream;
import net.sourceforge.pmd.lang.ast.impl.JavaccToken;
import net.sourceforge.pmd.lang.ast.impl.TokenDocument;
-final class JavaTokenUtils {
+final class JavaTokenFactory {
- private JavaTokenUtils() {
+ private JavaTokenFactory() {
}
static JavaccToken newToken(int kind, CharStream charStream) {
JavaCharStream jcs = (JavaCharStream) charStream;
+ // Most tokens have an entry in there, it's used to share the
+ // image string for keywords & punctuation. Those represent ~40%
+ // of token instances
String image = JavaParserTokenManager.jjstrLiteralImages[kind];
switch (kind) {
@@ -32,12 +35,12 @@ final class JavaTokenUtils {
jcs.getEndOffset(),
jcs.getTokenDocument()
);
- case JavaParserConstants.WHITESPACE:
- // unlikely that anybody cares about that, and since
- // they're still 30% of all tokens best make this assumption
- // btw 40% of all tokens have a compile-time string constant
- // as image (jjstrLiteralImages) so they're shared.
+ case JavaParserConstants.WHITESPACE:
+ // We don't create a new string for the image of whitespace tokens eagerly
+
+ // It's unlikely that anybody cares about that, and since
+ // they're still 30% of all tokens this is advantageous
return new LazyImageToken(
kind,
jcs.getStartOffset(),