Fixed annotation bug: ClassCastException when a formal parameter had multiple annotations
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@5626 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -1,3 +1,7 @@
|
||||
????, 2007 - 4.1:
|
||||
|
||||
Fixed annotation bug: ClassCastException when a formal parameter had multiple annotations
|
||||
|
||||
November 01, 2007 - 4.1rc1:
|
||||
New rules:
|
||||
Basic ruleset: AvoidUsingHardCodedIP,CheckResultSet
|
||||
|
@ -37,11 +37,25 @@ public class ASTVariableDeclaratorIdTest extends ParserTst {
|
||||
assertEquals("String", name.getImage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnnotations() throws Throwable {
|
||||
ASTCompilationUnit acu = super.getNodes(ASTCompilationUnit.class, TEST_ANNOTATIONS).iterator().next();
|
||||
ASTVariableDeclaratorId id = acu.findChildrenOfType(ASTVariableDeclaratorId.class).get(0);
|
||||
|
||||
ASTClassOrInterfaceType name = (ASTClassOrInterfaceType) id.getTypeNameNode().jjtGetChild(0);
|
||||
assertEquals("String", name.getImage());
|
||||
}
|
||||
|
||||
private static final String TYPE_NAME_NODE =
|
||||
"public class Test {" + PMD.EOL +
|
||||
" private String bar;" + PMD.EOL +
|
||||
"}";
|
||||
|
||||
private static final String TEST_ANNOTATIONS =
|
||||
"public class Foo {" + PMD.EOL +
|
||||
" public void bar(@A1 @A2 String s) {}" + PMD.EOL +
|
||||
"}";
|
||||
|
||||
public static junit.framework.Test suite() {
|
||||
return new junit.framework.JUnit4TestAdapter(ASTVariableDeclaratorIdTest.class);
|
||||
}
|
||||
|
@ -75,11 +75,12 @@ public class ASTVariableDeclaratorId extends SimpleJavaNode implements TypeNode
|
||||
}
|
||||
|
||||
private SimpleNode findTypeNameNode(Node node) {
|
||||
if (node.jjtGetChild(0) instanceof ASTAnnotation) {
|
||||
ASTType typeNode = (ASTType) node.jjtGetChild(1);
|
||||
return (SimpleNode) typeNode.jjtGetChild(0);
|
||||
int i = 0;
|
||||
while (node.jjtGetChild(i) instanceof ASTAnnotation) {
|
||||
// skip annotations
|
||||
i++;
|
||||
}
|
||||
ASTType typeNode = (ASTType) node.jjtGetChild(0);
|
||||
ASTType typeNode = (ASTType) node.jjtGetChild(i);
|
||||
return (SimpleNode) typeNode.jjtGetChild(0);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user