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:
pmd
etc
src/net/sourceforge/pmd/ast
@ -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.
|
||||
Added RuleViolation.getBeginColumn()/getEndColumn()
|
||||
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:
|
||||
New rules:
|
||||
|
@ -1080,7 +1080,7 @@ void ImportDeclaration() :
|
||||
* syntax errors for simple modifier mistakes. It will also enable us to give
|
||||
* better error messages.
|
||||
*/
|
||||
int Modifiers():
|
||||
int Modifiers() #void:
|
||||
{
|
||||
int modifiers = 0;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
package net.sourceforge.pmd.ast;
|
||||
|
||||
public class ASTModifiers extends SimpleJavaNode {
|
||||
|
||||
public ASTModifiers(int id) {
|
||||
super(id);
|
||||
}
|
||||
@ -11,49 +12,6 @@ public class ASTModifiers extends SimpleJavaNode {
|
||||
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. *
|
||||
*/
|
||||
|
@ -6,25 +6,9 @@ import java.util.List;
|
||||
public class DiscardableNodeCleaner {
|
||||
|
||||
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,
|
||||
ASTUnaryExpressionNotPlusMinus.class,
|
||||
ASTPostfixExpression.class,
|
||||
ASTModifiers.class
|
||||
};
|
||||
|
||||
public void clean(ASTCompilationUnit root) {
|
||||
|
@ -282,94 +282,69 @@ public class JavaParser/*@bgen(jjtree)*/implements JavaParserTreeConstants, Java
|
||||
* better error messages.
|
||||
*/
|
||||
final public int Modifiers() throws ParseException {
|
||||
/*@bgen(jjtree) Modifiers */
|
||||
ASTModifiers jjtn000 = new ASTModifiers(this, JJTMODIFIERS);
|
||||
boolean jjtc000 = true;
|
||||
jjtree.openNodeScope(jjtn000);int modifiers = 0;
|
||||
try {
|
||||
label_3:
|
||||
while (true) {
|
||||
if (jj_2_1(2)) {
|
||||
;
|
||||
} else {
|
||||
break label_3;
|
||||
}
|
||||
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
||||
case PUBLIC:
|
||||
jj_consume_token(PUBLIC);
|
||||
modifiers |= AccessNode.PUBLIC;
|
||||
break;
|
||||
case STATIC:
|
||||
jj_consume_token(STATIC);
|
||||
modifiers |= AccessNode.STATIC;
|
||||
break;
|
||||
case PROTECTED:
|
||||
jj_consume_token(PROTECTED);
|
||||
modifiers |= AccessNode.PROTECTED;
|
||||
break;
|
||||
case PRIVATE:
|
||||
jj_consume_token(PRIVATE);
|
||||
modifiers |= AccessNode.PRIVATE;
|
||||
break;
|
||||
case FINAL:
|
||||
jj_consume_token(FINAL);
|
||||
modifiers |= AccessNode.FINAL;
|
||||
break;
|
||||
case ABSTRACT:
|
||||
jj_consume_token(ABSTRACT);
|
||||
modifiers |= AccessNode.ABSTRACT;
|
||||
break;
|
||||
case SYNCHRONIZED:
|
||||
jj_consume_token(SYNCHRONIZED);
|
||||
modifiers |= AccessNode.SYNCHRONIZED;
|
||||
break;
|
||||
case NATIVE:
|
||||
jj_consume_token(NATIVE);
|
||||
modifiers |= AccessNode.NATIVE;
|
||||
break;
|
||||
case TRANSIENT:
|
||||
jj_consume_token(TRANSIENT);
|
||||
modifiers |= AccessNode.TRANSIENT;
|
||||
break;
|
||||
case VOLATILE:
|
||||
jj_consume_token(VOLATILE);
|
||||
modifiers |= AccessNode.VOLATILE;
|
||||
break;
|
||||
case STRICTFP:
|
||||
jj_consume_token(STRICTFP);
|
||||
modifiers |= AccessNode.STRICTFP;
|
||||
break;
|
||||
case AT:
|
||||
Annotation();
|
||||
break;
|
||||
default:
|
||||
jj_la1[7] = jj_gen;
|
||||
jj_consume_token(-1);
|
||||
throw new ParseException();
|
||||
}
|
||||
int modifiers = 0;
|
||||
label_3:
|
||||
while (true) {
|
||||
if (jj_2_1(2)) {
|
||||
;
|
||||
} else {
|
||||
break label_3;
|
||||
}
|
||||
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
|
||||
case PUBLIC:
|
||||
jj_consume_token(PUBLIC);
|
||||
modifiers |= AccessNode.PUBLIC;
|
||||
break;
|
||||
case STATIC:
|
||||
jj_consume_token(STATIC);
|
||||
modifiers |= AccessNode.STATIC;
|
||||
break;
|
||||
case PROTECTED:
|
||||
jj_consume_token(PROTECTED);
|
||||
modifiers |= AccessNode.PROTECTED;
|
||||
break;
|
||||
case PRIVATE:
|
||||
jj_consume_token(PRIVATE);
|
||||
modifiers |= AccessNode.PRIVATE;
|
||||
break;
|
||||
case FINAL:
|
||||
jj_consume_token(FINAL);
|
||||
modifiers |= AccessNode.FINAL;
|
||||
break;
|
||||
case ABSTRACT:
|
||||
jj_consume_token(ABSTRACT);
|
||||
modifiers |= AccessNode.ABSTRACT;
|
||||
break;
|
||||
case SYNCHRONIZED:
|
||||
jj_consume_token(SYNCHRONIZED);
|
||||
modifiers |= AccessNode.SYNCHRONIZED;
|
||||
break;
|
||||
case NATIVE:
|
||||
jj_consume_token(NATIVE);
|
||||
modifiers |= AccessNode.NATIVE;
|
||||
break;
|
||||
case TRANSIENT:
|
||||
jj_consume_token(TRANSIENT);
|
||||
modifiers |= AccessNode.TRANSIENT;
|
||||
break;
|
||||
case VOLATILE:
|
||||
jj_consume_token(VOLATILE);
|
||||
modifiers |= AccessNode.VOLATILE;
|
||||
break;
|
||||
case STRICTFP:
|
||||
jj_consume_token(STRICTFP);
|
||||
modifiers |= AccessNode.STRICTFP;
|
||||
break;
|
||||
case AT:
|
||||
Annotation();
|
||||
break;
|
||||
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");
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ public interface JavaParserTreeConstants
|
||||
public int JJTCOMPILATIONUNIT = 0;
|
||||
public int JJTPACKAGEDECLARATION = 1;
|
||||
public int JJTIMPORTDECLARATION = 2;
|
||||
public int JJTMODIFIERS = 3;
|
||||
public int JJTVOID = 3;
|
||||
public int JJTTYPEDECLARATION = 4;
|
||||
public int JJTCLASSORINTERFACEDECLARATION = 5;
|
||||
public int JJTEXTENDSLIST = 6;
|
||||
@ -119,7 +119,7 @@ public interface JavaParserTreeConstants
|
||||
"CompilationUnit",
|
||||
"PackageDeclaration",
|
||||
"ImportDeclaration",
|
||||
"Modifiers",
|
||||
"void",
|
||||
"TypeDeclaration",
|
||||
"ClassOrInterfaceDeclaration",
|
||||
"ExtendsList",
|
||||
|
@ -8,7 +8,6 @@ public interface JavaParserVisitor
|
||||
public Object visit(ASTCompilationUnit node, Object data);
|
||||
public Object visit(ASTPackageDeclaration 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(ASTClassOrInterfaceDeclaration node, Object data);
|
||||
public Object visit(ASTExtendsList node, Object data);
|
||||
|
Reference in New Issue
Block a user