Refactoring towards supporting multiple JLS versions

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@2236 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Tom Copeland
2003-09-04 14:41:44 +00:00
parent 0687038c0a
commit 7ece4f02a9
6 changed files with 1268 additions and 1 deletions

View File

@ -130,6 +130,38 @@
<replace file="src/net/sourceforge/pmd/ast/TokenMgrError.java" token="extends Error" value="extends RuntimeException"/>
</target>
<target name="jjtree11">
<jjtree target="etc/grammar/Java1.1.jjt" outputdirectory="src/net/sourceforge/pmd/ast11" javacchome="/usr/local/javacc-3.0/"/>
<javacc target="src/net/sourceforge/pmd/ast11/Java1.1.jj" outputdirectory="src/net/sourceforge/pmd/ast11" javacchome="/usr/local/javacc-3.0/"/>
<delete file="src/net/sourceforge/pmd/ast11/Java1.1.jj"/>
<replace file="src/net/sourceforge/pmd/ast11/JavaCharStream.java" token="throw new Error" value="throw new RuntimeException"/>
<replace file="src/net/sourceforge/pmd/ast11/JavaParser.java" token="throw new Error" value="throw new RuntimeException"/>
<replace file="src/net/sourceforge/pmd/ast11/JavaParser.java" token="(Error)" value="(RuntimeException)"/>
<replace file="src/net/sourceforge/pmd/ast11/JavaParserTokenManager.java" token="throw new Error" value="throw new RuntimeException"/>
<replace file="src/net/sourceforge/pmd/ast11/ParseException.java" token="throw new Error" value="throw new RuntimeException"/>
<replace file="src/net/sourceforge/pmd/ast11/TokenMgrError.java" token="extends Error" value="extends RuntimeException"/>
<delete>
<fileset dir="src/net/sourceforge/pmd/ast11/">
<include name="AST*.java"/>
<include name="SimpleNode.java"/>
</fileset>
</delete>
<copy todir="src/net/sourceforge/pmd/ast11/">
<fileset dir="src/net/sourceforge/pmd/ast/">
<include name="AST*.java"/>
<exclude name="ASTAssertStatement.java"/>
</fileset>
</copy>
<copy todir="src/net/sourceforge/pmd/ast11/">
<fileset dir="src/net/sourceforge/pmd/ast/">
<include name="AccessNode.java"/>
<include name="AccessFlags.java"/>
<include name="SimpleNode.java"/>
</fileset>
</copy>
<replace dir="src/net/sourceforge/pmd/ast11/" token="package net.sourceforge.pmd.ast;" value="package net.sourceforge.pmd.ast11;"/>
</target>
<target name="cppjavacc">
<delete>
<fileset dir="src/net/sourceforge/pmd/cpd/cppast">

1181
pmd/etc/grammar/Java1.1.jjt Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,17 @@
package net.sourceforge.pmd;
import net.sourceforge.pmd.ast.JavaParser;
import java.io.InputStream;
import java.io.Reader;
public class JLS1_1 implements JLSVersion {
public JavaParser createParser(InputStream in) {
return new JavaParser(in);
}
public JavaParser createParser(Reader in) {
return new JavaParser(in);
}
}

View File

@ -0,0 +1,16 @@
package net.sourceforge.pmd;
import net.sourceforge.pmd.ast.JavaParser;
import java.io.InputStream;
import java.io.Reader;
public class JLS1_4 implements JLSVersion {
public JavaParser createParser(InputStream in) {
return new JavaParser(in);
}
public JavaParser createParser(Reader in) {
return new JavaParser(in);
}
}

View File

@ -0,0 +1,11 @@
package net.sourceforge.pmd;
import net.sourceforge.pmd.ast.JavaParser;
import java.io.InputStream;
import java.io.Reader;
public interface JLSVersion {
public JavaParser createParser(InputStream in);
public JavaParser createParser(Reader in);
}

View File

@ -29,6 +29,16 @@ public class PMD {
public static final String EOL = System.getProperty("line.separator", "\n");
private JLSVersion jlsVersion;
public PMD() {
jlsVersion = new JLS1_4();
}
public PMD(JLSVersion jlsVersion) {
this.jlsVersion = jlsVersion;
}
/**
* @param reader - a Reader to the Java code to analyse
* @param ruleSet - the set of rules to process against the file
@ -36,7 +46,7 @@ public class PMD {
*/
public void processFile(Reader reader, RuleSet ruleSet, RuleContext ctx) throws PMDException {
try {
JavaParser parser = new JavaParser(reader);
JavaParser parser = jlsVersion.createParser(reader);
ASTCompilationUnit c = parser.CompilationUnit();
Thread.yield();
SymbolFacade stb = new SymbolFacade();