references #81

This commit is contained in:
Andreas Dangel
2016-01-15 10:18:53 +01:00
parent e8e950ad20
commit 69dbbdfe2d
3 changed files with 46 additions and 1 deletions

View File

@ -9,6 +9,7 @@ import java.util.List;
import java.util.ListIterator;
import net.sourceforge.pmd.lang.java.ast.ASTAllocationExpression;
import net.sourceforge.pmd.lang.java.ast.ASTAnnotationTypeDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTArguments;
import net.sourceforge.pmd.lang.java.ast.ASTArrayDimsAndInits;
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration;
@ -224,6 +225,39 @@ public class AccessorClassGenerationRule extends AbstractJavaRule {
return o;
}
@Override
public Object visit(ASTAnnotationTypeDeclaration node, Object data) {
if (!(node.jjtGetParent().jjtGetParent() instanceof ASTCompilationUnit)) {
// not a toplevel annotation type
String interfaceName = node.getImage();
int formerID = getClassID();
setClassID(classDataList.size());
ClassData newClassData = new ClassData(interfaceName);
// store the names of any outer classes of this class in the
// classQualifyingName List
ClassData formerClassData = classDataList.get(formerID);
newClassData.addClassQualifyingName(formerClassData.getClassName());
classDataList.add(getClassID(), newClassData);
Object o = super.visit(node, data);
setClassID(formerID);
return o;
}
// top-level annotation type
String interfaceName = node.getImage();
classDataList.clear();
setClassID(0);
classDataList.add(getClassID(), new ClassData(interfaceName));
Object o = super.visit(node, data);
if (o != null) {
processRule(o);
} else {
processRule(data);
}
setClassID(-1);
return o;
}
/**
* Store all target constructors
*/

View File

@ -120,4 +120,12 @@ public class Foo1 {
}
]]></code>
</test-code> -->
<test-code>
<description>#1452 ArrayIndexOutOfBoundsException with Annotations for AccessorClassGenerationRule</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public @interface Something { public interface SomthingElse{}; }
]]></code>
</test-code>
</test-data>