Modified JJTree grammar to use node suppression for ASTModifier nodes; this replaces a bunch of DiscardableNodeCleaner hackery.
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4327 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -3,7 +3,8 @@ Fixed bug 1465574 - UnusedPrivateMethod no longer reports false positives when a
|
|||||||
Fixed major bug in CPD; it was not picking up files other than .java or .jsp.
|
Fixed major bug in CPD; it was not picking up files other than .java or .jsp.
|
||||||
Added RuleViolation.getBeginColumn()/getEndColumn()
|
Added RuleViolation.getBeginColumn()/getEndColumn()
|
||||||
Added an IRuleViolation interface and modified various code classes (include Renderer implementations and Report) to use it.
|
Added an IRuleViolation interface and modified various code classes (include Renderer implementations and Report) to use it.
|
||||||
Modified Java grammar to use conditional node descriptors for some expression nodes
|
Modified JJTree grammar to use conditional node descriptors for some expression nodes.
|
||||||
|
Modified JJTree grammar to use node suppression for ASTModifier nodes; this replaces a bunch of DiscardableNodeCleaner hackery.
|
||||||
|
|
||||||
March 29, 2006 - 3.6:
|
March 29, 2006 - 3.6:
|
||||||
New rules:
|
New rules:
|
||||||
|
@ -1080,7 +1080,7 @@ void ImportDeclaration() :
|
|||||||
* syntax errors for simple modifier mistakes. It will also enable us to give
|
* syntax errors for simple modifier mistakes. It will also enable us to give
|
||||||
* better error messages.
|
* better error messages.
|
||||||
*/
|
*/
|
||||||
int Modifiers():
|
int Modifiers() #void:
|
||||||
{
|
{
|
||||||
int modifiers = 0;
|
int modifiers = 0;
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
package net.sourceforge.pmd.ast;
|
package net.sourceforge.pmd.ast;
|
||||||
|
|
||||||
public class ASTModifiers extends SimpleJavaNode {
|
public class ASTModifiers extends SimpleJavaNode {
|
||||||
|
|
||||||
public ASTModifiers(int id) {
|
public ASTModifiers(int id) {
|
||||||
super(id);
|
super(id);
|
||||||
}
|
}
|
||||||
@ -11,49 +12,6 @@ public class ASTModifiers extends SimpleJavaNode {
|
|||||||
super(p, id);
|
super(p, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void discardIfNecessary() {
|
|
||||||
SimpleNode parent = (SimpleNode) jjtGetParent();
|
|
||||||
if (allChildrenAreAnnotations()) {
|
|
||||||
handleAnnotations(parent);
|
|
||||||
} else if (parent.jjtGetNumChildren() == 2) {
|
|
||||||
parent.children = new Node[]{parent.children[1]};
|
|
||||||
} else if (parent.jjtGetNumChildren() == 3) {
|
|
||||||
// AnnotationTypeMemberDeclaration with default value, like this:
|
|
||||||
// String defaultValue() default "";
|
|
||||||
parent.children = new Node[]{parent.children[1], parent.children[2]};
|
|
||||||
} else if (parent.jjtGetNumChildren() == 4) {
|
|
||||||
// JDK 1.5 forloop syntax
|
|
||||||
parent.children = new Node[]{parent.children[1], parent.children[2], parent.children[3]};
|
|
||||||
} else {
|
|
||||||
throw new RuntimeException("ASTModifiers.discardIfNecessary didn't see expected children");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean allChildrenAreAnnotations() {
|
|
||||||
if (jjtGetNumChildren() == 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
for (int i = 0; i < jjtGetNumChildren(); i++) {
|
|
||||||
if (!(jjtGetChild(i) instanceof ASTAnnotation)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handleAnnotations(SimpleNode parent) {
|
|
||||||
SimpleNode kid = (SimpleNode) this.jjtGetChild(0);
|
|
||||||
kid.jjtSetParent(parent);
|
|
||||||
for (int i = 0; i < jjtGetNumChildren(); i++) {
|
|
||||||
if (i == 0) {
|
|
||||||
parent.jjtReplaceChild(this, kid);
|
|
||||||
} else {
|
|
||||||
parent.jjtAddChild(jjtGetChild(i), i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Accept the visitor. *
|
* Accept the visitor. *
|
||||||
*/
|
*/
|
||||||
|
@ -6,25 +6,9 @@ import java.util.List;
|
|||||||
public class DiscardableNodeCleaner {
|
public class DiscardableNodeCleaner {
|
||||||
|
|
||||||
private static final Class[] clazzes = new Class[]{
|
private static final Class[] clazzes = new Class[]{
|
||||||
/*
|
|
||||||
ASTEqualityExpression.class,
|
|
||||||
ASTAndExpression.class,
|
|
||||||
ASTInstanceOfExpression.class,
|
|
||||||
ASTUnaryExpression.class,
|
|
||||||
ASTShiftExpression.class,
|
|
||||||
ASTConditionalOrExpression.class,
|
|
||||||
ASTInclusiveOrExpression.class,
|
|
||||||
ASTExclusiveOrExpression.class,
|
|
||||||
ASTConditionalExpression.class,
|
|
||||||
ASTRelationalExpression.class,
|
|
||||||
ASTMultiplicativeExpression.class,
|
|
||||||
ASTAdditiveExpression.class,
|
|
||||||
ASTConditionalAndExpression.class,
|
|
||||||
*/
|
|
||||||
ASTUnaryExpression.class,
|
ASTUnaryExpression.class,
|
||||||
ASTUnaryExpressionNotPlusMinus.class,
|
ASTUnaryExpressionNotPlusMinus.class,
|
||||||
ASTPostfixExpression.class,
|
ASTPostfixExpression.class,
|
||||||
ASTModifiers.class
|
|
||||||
};
|
};
|
||||||
|
|
||||||
public void clean(ASTCompilationUnit root) {
|
public void clean(ASTCompilationUnit root) {
|
||||||
|
@ -282,94 +282,69 @@ public class JavaParser/*@bgen(jjtree)*/implements JavaParserTreeConstants, Java
|
|||||||
* better error messages.
|
* better error messages.
|
||||||
*/
|
*/
|
||||||
final public int Modifiers() throws ParseException {
|
final public int Modifiers() throws ParseException {
|
||||||
/*@bgen(jjtree) Modifiers */
|
int modifiers = 0;
|
||||||
ASTModifiers jjtn000 = new ASTModifiers(this, JJTMODIFIERS);
|
label_3:
|
||||||
boolean jjtc000 = true;
|
while (true) {
|
||||||
jjtree.openNodeScope(jjtn000);int modifiers = 0;
|
if (jj_2_1(2)) {
|
||||||
try {
|
;
|
||||||
label_3:
|
} else {
|
||||||
while (true) {
|
break label_3;
|
||||||
if (jj_2_1(2)) {
|
}
|
||||||
;
|
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
||||||
} else {
|
case PUBLIC:
|
||||||
break label_3;
|
jj_consume_token(PUBLIC);
|
||||||
}
|
modifiers |= AccessNode.PUBLIC;
|
||||||
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
break;
|
||||||
case PUBLIC:
|
case STATIC:
|
||||||
jj_consume_token(PUBLIC);
|
jj_consume_token(STATIC);
|
||||||
modifiers |= AccessNode.PUBLIC;
|
modifiers |= AccessNode.STATIC;
|
||||||
break;
|
break;
|
||||||
case STATIC:
|
case PROTECTED:
|
||||||
jj_consume_token(STATIC);
|
jj_consume_token(PROTECTED);
|
||||||
modifiers |= AccessNode.STATIC;
|
modifiers |= AccessNode.PROTECTED;
|
||||||
break;
|
break;
|
||||||
case PROTECTED:
|
case PRIVATE:
|
||||||
jj_consume_token(PROTECTED);
|
jj_consume_token(PRIVATE);
|
||||||
modifiers |= AccessNode.PROTECTED;
|
modifiers |= AccessNode.PRIVATE;
|
||||||
break;
|
break;
|
||||||
case PRIVATE:
|
case FINAL:
|
||||||
jj_consume_token(PRIVATE);
|
jj_consume_token(FINAL);
|
||||||
modifiers |= AccessNode.PRIVATE;
|
modifiers |= AccessNode.FINAL;
|
||||||
break;
|
break;
|
||||||
case FINAL:
|
case ABSTRACT:
|
||||||
jj_consume_token(FINAL);
|
jj_consume_token(ABSTRACT);
|
||||||
modifiers |= AccessNode.FINAL;
|
modifiers |= AccessNode.ABSTRACT;
|
||||||
break;
|
break;
|
||||||
case ABSTRACT:
|
case SYNCHRONIZED:
|
||||||
jj_consume_token(ABSTRACT);
|
jj_consume_token(SYNCHRONIZED);
|
||||||
modifiers |= AccessNode.ABSTRACT;
|
modifiers |= AccessNode.SYNCHRONIZED;
|
||||||
break;
|
break;
|
||||||
case SYNCHRONIZED:
|
case NATIVE:
|
||||||
jj_consume_token(SYNCHRONIZED);
|
jj_consume_token(NATIVE);
|
||||||
modifiers |= AccessNode.SYNCHRONIZED;
|
modifiers |= AccessNode.NATIVE;
|
||||||
break;
|
break;
|
||||||
case NATIVE:
|
case TRANSIENT:
|
||||||
jj_consume_token(NATIVE);
|
jj_consume_token(TRANSIENT);
|
||||||
modifiers |= AccessNode.NATIVE;
|
modifiers |= AccessNode.TRANSIENT;
|
||||||
break;
|
break;
|
||||||
case TRANSIENT:
|
case VOLATILE:
|
||||||
jj_consume_token(TRANSIENT);
|
jj_consume_token(VOLATILE);
|
||||||
modifiers |= AccessNode.TRANSIENT;
|
modifiers |= AccessNode.VOLATILE;
|
||||||
break;
|
break;
|
||||||
case VOLATILE:
|
case STRICTFP:
|
||||||
jj_consume_token(VOLATILE);
|
jj_consume_token(STRICTFP);
|
||||||
modifiers |= AccessNode.VOLATILE;
|
modifiers |= AccessNode.STRICTFP;
|
||||||
break;
|
break;
|
||||||
case STRICTFP:
|
case AT:
|
||||||
jj_consume_token(STRICTFP);
|
Annotation();
|
||||||
modifiers |= AccessNode.STRICTFP;
|
break;
|
||||||
break;
|
default:
|
||||||
case AT:
|
jj_la1[7] = jj_gen;
|
||||||
Annotation();
|
jj_consume_token(-1);
|
||||||
break;
|
throw new ParseException();
|
||||||
default:
|
|
||||||
jj_la1[7] = jj_gen;
|
|
||||||
jj_consume_token(-1);
|
|
||||||
throw new ParseException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
jjtree.closeNodeScope(jjtn000, true);
|
|
||||||
jjtc000 = false;
|
|
||||||
{if (true) return modifiers;}
|
|
||||||
} catch (Throwable jjte000) {
|
|
||||||
if (jjtc000) {
|
|
||||||
jjtree.clearNodeScope(jjtn000);
|
|
||||||
jjtc000 = false;
|
|
||||||
} else {
|
|
||||||
jjtree.popNode();
|
|
||||||
}
|
|
||||||
if (jjte000 instanceof RuntimeException) {
|
|
||||||
{if (true) throw (RuntimeException)jjte000;}
|
|
||||||
}
|
|
||||||
if (jjte000 instanceof ParseException) {
|
|
||||||
{if (true) throw (ParseException)jjte000;}
|
|
||||||
}
|
|
||||||
{if (true) throw (Error)jjte000;}
|
|
||||||
} finally {
|
|
||||||
if (jjtc000) {
|
|
||||||
jjtree.closeNodeScope(jjtn000, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
{if (true) return modifiers;}
|
||||||
throw new RuntimeException("Missing return statement in function");
|
throw new RuntimeException("Missing return statement in function");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ public interface JavaParserTreeConstants
|
|||||||
public int JJTCOMPILATIONUNIT = 0;
|
public int JJTCOMPILATIONUNIT = 0;
|
||||||
public int JJTPACKAGEDECLARATION = 1;
|
public int JJTPACKAGEDECLARATION = 1;
|
||||||
public int JJTIMPORTDECLARATION = 2;
|
public int JJTIMPORTDECLARATION = 2;
|
||||||
public int JJTMODIFIERS = 3;
|
public int JJTVOID = 3;
|
||||||
public int JJTTYPEDECLARATION = 4;
|
public int JJTTYPEDECLARATION = 4;
|
||||||
public int JJTCLASSORINTERFACEDECLARATION = 5;
|
public int JJTCLASSORINTERFACEDECLARATION = 5;
|
||||||
public int JJTEXTENDSLIST = 6;
|
public int JJTEXTENDSLIST = 6;
|
||||||
@ -119,7 +119,7 @@ public interface JavaParserTreeConstants
|
|||||||
"CompilationUnit",
|
"CompilationUnit",
|
||||||
"PackageDeclaration",
|
"PackageDeclaration",
|
||||||
"ImportDeclaration",
|
"ImportDeclaration",
|
||||||
"Modifiers",
|
"void",
|
||||||
"TypeDeclaration",
|
"TypeDeclaration",
|
||||||
"ClassOrInterfaceDeclaration",
|
"ClassOrInterfaceDeclaration",
|
||||||
"ExtendsList",
|
"ExtendsList",
|
||||||
|
@ -8,7 +8,6 @@ public interface JavaParserVisitor
|
|||||||
public Object visit(ASTCompilationUnit node, Object data);
|
public Object visit(ASTCompilationUnit node, Object data);
|
||||||
public Object visit(ASTPackageDeclaration node, Object data);
|
public Object visit(ASTPackageDeclaration node, Object data);
|
||||||
public Object visit(ASTImportDeclaration node, Object data);
|
public Object visit(ASTImportDeclaration node, Object data);
|
||||||
public Object visit(ASTModifiers node, Object data);
|
|
||||||
public Object visit(ASTTypeDeclaration node, Object data);
|
public Object visit(ASTTypeDeclaration node, Object data);
|
||||||
public Object visit(ASTClassOrInterfaceDeclaration node, Object data);
|
public Object visit(ASTClassOrInterfaceDeclaration node, Object data);
|
||||||
public Object visit(ASTExtendsList node, Object data);
|
public Object visit(ASTExtendsList node, Object data);
|
||||||
|
Reference in New Issue
Block a user