Added capability in Java and JSP parser for tracking tokens. It is often useful to keep track of each node's first and last token so that input can be easily reproduced again. Ref - https://javacc.java.net/doc/JJTree.html

This commit is contained in:
amitbitcse 2015-10-06 11:04:22 +05:30
parent 84c407f5d2
commit 1d190605e5
6 changed files with 48 additions and 1 deletions

View File

@ -14,6 +14,7 @@ import javax.xml.parsers.ParserConfigurationException;
import net.sourceforge.pmd.lang.ast.xpath.Attribute;
import net.sourceforge.pmd.lang.ast.xpath.DocumentNavigator;
import net.sourceforge.pmd.lang.dfa.DataFlowNode;
import net.sourceforge.pmd.lang.ast.GenericToken;
import org.jaxen.BaseXPath;
import org.jaxen.JaxenException;
@ -397,4 +398,22 @@ public abstract class AbstractNode implements Node {
public void setUserData(Object userData) {
this.userData = userData;
}
protected GenericToken firstToken, lastToken;
public GenericToken jjtGetFirstToken() {
return firstToken;
}
public void jjtSetFirstToken(GenericToken token) {
this.firstToken = token;
}
public GenericToken jjtGetLastToken() {
return lastToken;
}
public void jjtSetLastToken(GenericToken token) {
this.lastToken = token;
}
}

View File

@ -0,0 +1,5 @@
package net.sourceforge.pmd.lang.ast;
public class GenericToken {
}

View File

@ -1,4 +1,8 @@
/**
* Added capability for Tracking Tokens.
*
* Amit Kumar Prasad 10/2015
*====================================================================
* Fix for Lambda expressions without variables.
*
* Andreas Dangel 11/2014
@ -104,6 +108,7 @@ options {
MULTI = true;
VISITOR = true;
NODE_USES_PARSER = true;
TRACK_TOKENS = true;
NODE_PACKAGE="net.sourceforge.pmd.lang.java.ast";
//DEBUG_PARSER = true;

View File

@ -81,6 +81,12 @@ public class]]></replacevalue>
}
]]></replacevalue>
</replace>
<replace file="${target}/net/sourceforge/pmd/lang/java/ast/Token.java">
<replacetoken>public class Token</replacetoken>
<replacevalue><![CDATA[import net.sourceforge.pmd.lang.ast.GenericToken;
public class Token extends GenericToken]]></replacevalue>
</replace>
<delete>
<fileset dir="${target}/net/sourceforge/pmd/lang/java/ast">

View File

@ -1,4 +1,9 @@
/* JSP Parser for PMD.
/*
* Added capability for Tracking Tokens.
*
* Amit Kumar Prasad 10/2015
*====================================================================
* JSP Parser for PMD.
* It supports supports more-or-less well written JSP files.
* The JSP Document style is supported, except for inline DTD.
* The JSP Page style (<% ... %>) is supported.
@ -16,6 +21,7 @@ options {
MULTI=true;
VISITOR=true;
TRACK_TOKENS = true;
}
PARSER_BEGIN(JspParser)

View File

@ -61,6 +61,12 @@
public class]]></replacevalue>
</replace>
<replace file="${target}/net/sourceforge/pmd/lang/jsp/ast/Token.java">
<replacetoken>public class Token</replacetoken>
<replacevalue><![CDATA[import net.sourceforge.pmd.lang.ast.GenericToken;
public class Token extends GenericToken]]></replacevalue>
</replace>
<delete>
<fileset dir="${target}/net/sourceforge/pmd/lang/jsp/ast">