From 5130ea03db0243fde4a0f03bdfe278416527309f Mon Sep 17 00:00:00 2001 From: Tom Copeland Date: Wed, 2 Jul 2003 15:36:14 +0000 Subject: [PATCH] Added initializer block info git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@2065 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd/etc/changelog.txt | 1 + pmd/etc/grammar/Java1.4-c.jjt | 2 +- .../pmd/symboltable/AcceptanceTest.java | 38 ++++++++++++++++--- .../sourceforge/pmd/ast/ASTInitializer.java | 10 +++++ .../net/sourceforge/pmd/ast/JavaParser.java | 1 + pmd/xdocs/credits.xml | 1 + 6 files changed, 46 insertions(+), 7 deletions(-) diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index 3e75b95a94..68cd808bc6 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -4,6 +4,7 @@ Fixed bug 583047 - ASTName column numbers are now correct Fixed bug 761048 - Symbol table now creates a scope level for anonymous inner classes Fixed bug 763529 - AccessorClassGenerationRule no longer crashes when given a final inner class Added ability to accept a comma-delimited string of files and directories on the command line. +Modified grammer to provide information on whether an initializer block is static. ASTViewer now shows node images and modifiers ASTViewer now saves last edited text to ~/.pmd_astviewer Moved the PMD Swing UI into a separate module - pmd-swingui. diff --git a/pmd/etc/grammar/Java1.4-c.jjt b/pmd/etc/grammar/Java1.4-c.jjt index 53100d2a26..ca768f15bf 100644 --- a/pmd/etc/grammar/Java1.4-c.jjt +++ b/pmd/etc/grammar/Java1.4-c.jjt @@ -599,7 +599,7 @@ void ExplicitConstructorInvocation() : void Initializer() : {} { - [ "static" ] Block() + [ "static" {jjtThis.setStatic();} ] Block() } diff --git a/pmd/regress/test/net/sourceforge/pmd/symboltable/AcceptanceTest.java b/pmd/regress/test/net/sourceforge/pmd/symboltable/AcceptanceTest.java index c467d0a15b..b4430f90a3 100644 --- a/pmd/regress/test/net/sourceforge/pmd/symboltable/AcceptanceTest.java +++ b/pmd/regress/test/net/sourceforge/pmd/symboltable/AcceptanceTest.java @@ -4,12 +4,34 @@ import junit.framework.TestCase; import net.sourceforge.pmd.PMD; import net.sourceforge.pmd.ast.ASTCompilationUnit; import net.sourceforge.pmd.ast.JavaParser; +import net.sourceforge.pmd.ast.ASTInitializer; import net.sourceforge.pmd.symboltable.SymbolFacade; import java.io.StringReader; public class AcceptanceTest extends TestCase { + public void testClashingSymbols() { + JavaParser parser = new JavaParser(new StringReader(TEST1)); + ASTCompilationUnit c = parser.CompilationUnit(); + SymbolFacade stb = new SymbolFacade(); + stb.initializeWith(c); + } + + public void testInitializer() { + JavaParser parser = new JavaParser(new StringReader(TEST2)); + ASTCompilationUnit c = parser.CompilationUnit(); + ASTInitializer a = (ASTInitializer)(c.findChildrenOfType(ASTInitializer.class)).get(0); + assertFalse(a.isStatic()); + } + + public void testStaticInitializer() { + JavaParser parser = new JavaParser(new StringReader(TEST3)); + ASTCompilationUnit c = parser.CompilationUnit(); + ASTInitializer a = (ASTInitializer)(c.findChildrenOfType(ASTInitializer.class)).get(0); + assertTrue(a.isStatic()); + } + private static final String TEST1 = "import java.io.*;" + PMD.EOL + "public class Foo {" + PMD.EOL + @@ -19,10 +41,14 @@ public class AcceptanceTest extends TestCase { " }" + PMD.EOL + "}" + PMD.EOL; - public void testClashingSymbols() { - JavaParser parser = new JavaParser(new StringReader(TEST1)); - ASTCompilationUnit c = parser.CompilationUnit(); - SymbolFacade stb = new SymbolFacade(); - stb.initializeWith(c); - } + private static final String TEST2 = + "public class Foo {" + PMD.EOL + + " {} " + PMD.EOL + + "}" + PMD.EOL; + + private static final String TEST3 = + "public class Foo {" + PMD.EOL + + " static {} " + PMD.EOL + + "}" + PMD.EOL; + } diff --git a/pmd/src/net/sourceforge/pmd/ast/ASTInitializer.java b/pmd/src/net/sourceforge/pmd/ast/ASTInitializer.java index b7e7bde31d..48ef1b292a 100644 --- a/pmd/src/net/sourceforge/pmd/ast/ASTInitializer.java +++ b/pmd/src/net/sourceforge/pmd/ast/ASTInitializer.java @@ -16,4 +16,14 @@ public class ASTInitializer extends SimpleNode { public Object jjtAccept(JavaParserVisitor visitor, Object data) { return visitor.visit(this, data); } + + private boolean isStatic; + + public boolean isStatic() { + return isStatic; + } + + public void setStatic() { + isStatic = true; + } } diff --git a/pmd/src/net/sourceforge/pmd/ast/JavaParser.java b/pmd/src/net/sourceforge/pmd/ast/JavaParser.java index 1b79c9a757..b7358e53cd 100644 --- a/pmd/src/net/sourceforge/pmd/ast/JavaParser.java +++ b/pmd/src/net/sourceforge/pmd/ast/JavaParser.java @@ -1635,6 +1635,7 @@ public class JavaParser/*@bgen(jjtree)*/implements JavaParserTreeConstants, Java switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case STATIC: jj_consume_token(STATIC); + jjtn000.setStatic(); break; default: jj_la1[43] = jj_gen; diff --git a/pmd/xdocs/credits.xml b/pmd/xdocs/credits.xml index 7f921e0f74..ba44392951 100644 --- a/pmd/xdocs/credits.xml +++ b/pmd/xdocs/credits.xml @@ -10,6 +10,7 @@
    +
  • Bernd Jansen - grammer modification
  • Jarle Naess - bug report
  • Jeff Anderson - VariableNamingConventionsRule, MethodNamingConventionsRule, ClassNamingConventionsRule
  • Frank van Puffelen - documentation suggestions