From 69dbbdfe2d6e0ce21060adeb7cfcfd9826b9fd12 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 15 Jan 2016 10:18:53 +0100 Subject: [PATCH] references #81 --- .../design/AccessorClassGenerationRule.java | 34 +++++++++++++++++++ .../design/xml/AccessorClassGeneration.xml | 8 +++++ src/site/markdown/overview/changelog.md | 5 ++- 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/AccessorClassGenerationRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/AccessorClassGenerationRule.java index babee43aeb..e7729012d5 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/AccessorClassGenerationRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/AccessorClassGenerationRule.java @@ -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 */ diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/AccessorClassGeneration.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/AccessorClassGeneration.xml index ed0ac00ae4..38c02df0d5 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/AccessorClassGeneration.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/AccessorClassGeneration.xml @@ -120,4 +120,12 @@ public class Foo1 { } ]]> --> + + + #1452 ArrayIndexOutOfBoundsException with Annotations for AccessorClassGenerationRule + 0 + + diff --git a/src/site/markdown/overview/changelog.md b/src/site/markdown/overview/changelog.md index 7f40041ea8..b813b3b3d8 100644 --- a/src/site/markdown/overview/changelog.md +++ b/src/site/markdown/overview/changelog.md @@ -16,12 +16,15 @@ **Pull Requests:** * [#27](https://github.com/adangel/pmd/pull/27): Added support for Raw String Literals (C++11). -* [#29)(https://github.com/adangel/pmd/pull/29): Added support for files with UTF-8 BOM to JSP tokenizer. +* [#29](https://github.com/adangel/pmd/pull/29): Added support for files with UTF-8 BOM to JSP tokenizer. * [#79](https://github.com/pmd/pmd/pull/79): do not flag public static void main(String[]) as UseVarargs; ignore @Override for UseVarargs * [#80](https://github.com/pmd/pmd/pull/80): Update mvn-plugin.md * [#83](https://github.com/pmd/pmd/pull/83): Adds new Code Climate-compliant JSON renderer **Bugfixes:** +* java-design/AccessorClassGeneration: + * [#1452](https://sourceforge.net/p/pmd/bugs/1452/): ArrayIndexOutOfBoundsException with Annotations for AccessorClassGenerationRule + **API Changes:**