diff --git a/pmd/etc/Java1.4-c.jjt b/pmd/etc/Java1.4-c.jjt index 01061bd9ec..b65a594ba2 100644 --- a/pmd/etc/Java1.4-c.jjt +++ b/pmd/etc/Java1.4-c.jjt @@ -591,10 +591,9 @@ void ConstructorDeclaration() : void ExplicitConstructorInvocation() : {} { - LOOKAHEAD("this" Arguments() ";") - "this" Arguments() ";" + LOOKAHEAD("this" Arguments() ";") "this" {((ASTExplicitConstructorInvocation)jjtThis).setIsThis();} Arguments() ";" | - [ LOOKAHEAD(2) PrimaryExpression() "." ] "super" Arguments() ";" + [ LOOKAHEAD(2) PrimaryExpression() "." ] "super" {((ASTExplicitConstructorInvocation)jjtThis).setIsSuper();} Arguments() ";" } void Initializer() : diff --git a/pmd/etc/build.xml b/pmd/etc/build.xml index 2417235a31..db1348ef4d 100644 --- a/pmd/etc/build.xml +++ b/pmd/etc/build.xml @@ -59,8 +59,8 @@ - - + + diff --git a/pmd/rulesets/design.xml b/pmd/rulesets/design.xml index 5663e04517..d056864437 100644 --- a/pmd/rulesets/design.xml +++ b/pmd/rulesets/design.xml @@ -223,7 +223,9 @@ public class Foo { Assigning a "null" to a variable (outside of its declaration) is usually in bad form. Some times, the assignment is an indication that the programmer doesn't - completely understand what is going on in the code. + completely understand what is going on in the code. NOTE: This sort of assignment + may in rare cases be useful to encourage garbage collection. If that's what you're using + it for, by all means, disregard this rule :-) 3 diff --git a/pmd/rulesets/newrules.xml b/pmd/rulesets/newrules.xml index d4f4a01286..0ba9fffac3 100644 --- a/pmd/rulesets/newrules.xml +++ b/pmd/rulesets/newrules.xml @@ -82,21 +82,6 @@ public class Foo - - - asdsad - - 3 - - - - - - diff --git a/pmd/src/net/sourceforge/pmd/ast/ASTExplicitConstructorInvocation.java b/pmd/src/net/sourceforge/pmd/ast/ASTExplicitConstructorInvocation.java index 89b32c5abf..1cd66cabc8 100644 --- a/pmd/src/net/sourceforge/pmd/ast/ASTExplicitConstructorInvocation.java +++ b/pmd/src/net/sourceforge/pmd/ast/ASTExplicitConstructorInvocation.java @@ -16,4 +16,23 @@ public class ASTExplicitConstructorInvocation extends SimpleNode { public Object jjtAccept(JavaParserVisitor visitor, Object data) { return visitor.visit(this, data); } + + private boolean isThis; + private boolean isSuper; + + public void setIsThis() { + this.isThis = true; + } + + public void setIsSuper() { + this.isSuper = true; + } + + public boolean isThis() { + return this.isThis; + } + + public boolean isSuper() { + return this.isSuper; + } } diff --git a/pmd/src/net/sourceforge/pmd/ast/JavaParser.java b/pmd/src/net/sourceforge/pmd/ast/JavaParser.java index a8f11cb0e5..0a9ee1136e 100644 --- a/pmd/src/net/sourceforge/pmd/ast/JavaParser.java +++ b/pmd/src/net/sourceforge/pmd/ast/JavaParser.java @@ -1562,6 +1562,7 @@ public class JavaParser/*@bgen(jjtree)*/implements JavaParserTreeConstants, Java try { if (jj_2_13(2147483647)) { jj_consume_token(THIS); + ((ASTExplicitConstructorInvocation)jjtn000).setIsThis(); Arguments(); jj_consume_token(SEMICOLON); } else { @@ -1594,6 +1595,7 @@ public class JavaParser/*@bgen(jjtree)*/implements JavaParserTreeConstants, Java ; } jj_consume_token(SUPER); + ((ASTExplicitConstructorInvocation)jjtn000).setIsSuper(); Arguments(); jj_consume_token(SEMICOLON); break; @@ -5077,12 +5079,6 @@ jjtree.openNodeScope(jjtn000);boolean hasElse = false; return false; } - final private boolean jj_3R_69() { - if (jj_scan_token(STATIC)) return true; - if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; - return false; - } - final private boolean jj_3_13() { if (jj_scan_token(THIS)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; @@ -5093,6 +5089,12 @@ jjtree.openNodeScope(jjtn000);boolean hasElse = false; return false; } + final private boolean jj_3R_69() { + if (jj_scan_token(STATIC)) return true; + if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; + return false; + } + final private boolean jj_3R_43() { Token xsp; xsp = jj_scanpos; @@ -6006,14 +6008,6 @@ jjtree.openNodeScope(jjtn000);boolean hasElse = false; return false; } - final private boolean jj_3R_381() { - if (jj_scan_token(COLON)) return true; - if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; - if (jj_3R_60()) return true; - if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; - return false; - } - final private boolean jj_3R_311() { if (jj_scan_token(STATIC)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; @@ -6052,6 +6046,14 @@ jjtree.openNodeScope(jjtn000);boolean hasElse = false; return false; } + final private boolean jj_3R_381() { + if (jj_scan_token(COLON)) return true; + if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; + if (jj_3R_60()) return true; + if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; + return false; + } + final private boolean jj_3R_267() { Token xsp; while (true) { @@ -6262,6 +6264,12 @@ jjtree.openNodeScope(jjtn000);boolean hasElse = false; return false; } + final private boolean jj_3R_262() { + if (jj_3R_270()) return true; + if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; + return false; + } + final private boolean jj_3R_227() { if (jj_scan_token(ASSERT)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; @@ -6276,12 +6284,6 @@ jjtree.openNodeScope(jjtn000);boolean hasElse = false; return false; } - final private boolean jj_3R_262() { - if (jj_3R_270()) return true; - if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; - return false; - } - final private boolean jj_3_3() { Token xsp; while (true) { @@ -6312,16 +6314,16 @@ jjtree.openNodeScope(jjtn000);boolean hasElse = false; return false; } - final private boolean jj_3R_380() { - if (jj_scan_token(FINALLY)) return true; - if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; - if (jj_3R_70()) return true; + final private boolean jj_3R_258() { + if (jj_3R_266()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } - final private boolean jj_3R_258() { - if (jj_3R_266()) return true; + final private boolean jj_3R_380() { + if (jj_scan_token(FINALLY)) return true; + if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; + if (jj_3R_70()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; return false; } @@ -6471,12 +6473,6 @@ jjtree.openNodeScope(jjtn000);boolean hasElse = false; return false; } - final private boolean jj_3R_375() { - if (jj_3R_387()) return true; - if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; - return false; - } - final private boolean jj_3R_250() { if (jj_3R_253()) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; @@ -6495,6 +6491,12 @@ jjtree.openNodeScope(jjtn000);boolean hasElse = false; return false; } + final private boolean jj_3R_375() { + if (jj_3R_387()) return true; + if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; + return false; + } + final private boolean jj_3R_225() { if (jj_scan_token(SYNCHRONIZED)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; @@ -6667,12 +6669,6 @@ jjtree.openNodeScope(jjtn000);boolean hasElse = false; return false; } - final private boolean jj_3R_64() { - if (jj_scan_token(FINAL)) return true; - if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; - return false; - } - final private boolean jj_3_1() { Token xsp; while (true) { @@ -6685,6 +6681,12 @@ jjtree.openNodeScope(jjtn000);boolean hasElse = false; return false; } + final private boolean jj_3R_64() { + if (jj_scan_token(FINAL)) return true; + if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; + return false; + } + final private boolean jj_3R_372() { if (jj_scan_token(ELSE)) return true; if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; diff --git a/pmd/src/net/sourceforge/pmd/rules/SymbolTableTestRule.java b/pmd/src/net/sourceforge/pmd/rules/SymbolTableTestRule.java index cfadf97805..4708a949c7 100644 --- a/pmd/src/net/sourceforge/pmd/rules/SymbolTableTestRule.java +++ b/pmd/src/net/sourceforge/pmd/rules/SymbolTableTestRule.java @@ -5,21 +5,14 @@ import net.sourceforge.pmd.AbstractRule; import net.sourceforge.pmd.ast.ASTPrimarySuffix; import net.sourceforge.pmd.ast.ASTPrimaryPrefix; import net.sourceforge.pmd.ast.ASTName; +import net.sourceforge.pmd.ast.ASTExplicitConstructorInvocation; public class SymbolTableTestRule extends AbstractRule implements Rule { - public Object visit(ASTPrimarySuffix node, Object data) { - System.out.println("ASTPrimarySuffix: image: " + node.getImage()); + public Object visit(ASTExplicitConstructorInvocation node, Object data) { + System.out.println("ASTExplicitConstructorInvocation: isSuper: " + node.isSuper()); + System.out.println("ASTExplicitConstructorInvocation: isThis: " + node.isThis()); return super.visit(node,data); } - public Object visit(ASTPrimaryPrefix node, Object data) { - System.out.println("ASTPrimaryPrefix: image: " + node.getImage()); - return super.visit(node,data); - } - - public Object visit(ASTName node, Object data) { - System.out.println("ASTName: image: " + node.getImage()); - return super.visit(node,data); - } }