From 8ee39deacee45cfadaab420f01274c8bb4825df9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=ADn=20Sotuyo=20Dodero?= Date: Sat, 23 Jun 2018 21:51:28 -0300 Subject: [PATCH] Upgrade to 6.0.0 categories --- .../AvoidNonExistentAnnotationsRule.java | 38 ++++++++++++++----- .../resources/category/apex/bestpractices.xml | 1 - .../resources/category/apex/errorprone.xml | 21 ++++++++++ .../main/resources/rulesets/apex/ruleset.xml | 3 +- .../main/resources/rulesets/apex/style.xml | 20 ---------- .../rule/errorprone/ErrorProneRulesTest.java | 4 +- .../lang/apex/rule/style/StyleRulesTest.java | 24 ------------ .../xml/AvoidNonExistentAnnotations.xml | 19 +++++++++- 8 files changed, 69 insertions(+), 61 deletions(-) rename pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/{style => errorprone}/AvoidNonExistentAnnotationsRule.java (66%) delete mode 100644 pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/style/StyleRulesTest.java rename pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/{style => errorprone}/xml/AvoidNonExistentAnnotations.xml (72%) diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/style/AvoidNonExistentAnnotationsRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/errorprone/AvoidNonExistentAnnotationsRule.java similarity index 66% rename from pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/style/AvoidNonExistentAnnotationsRule.java rename to pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/errorprone/AvoidNonExistentAnnotationsRule.java index f447780710..11eeb52b2b 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/style/AvoidNonExistentAnnotationsRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/errorprone/AvoidNonExistentAnnotationsRule.java @@ -1,26 +1,43 @@ -package net.sourceforge.pmd.lang.apex.rule.style; +/** + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ -import java.util.*; +package net.sourceforge.pmd.lang.apex.rule.errorprone; -import net.sourceforge.pmd.lang.apex.ast.*; +import java.util.HashSet; +import java.util.Set; + +import net.sourceforge.pmd.lang.apex.ast.ASTField; +import net.sourceforge.pmd.lang.apex.ast.ASTMethod; +import net.sourceforge.pmd.lang.apex.ast.ASTProperty; +import net.sourceforge.pmd.lang.apex.ast.ASTUserClass; +import net.sourceforge.pmd.lang.apex.ast.ASTUserEnum; +import net.sourceforge.pmd.lang.apex.ast.ASTUserInterface; +import net.sourceforge.pmd.lang.apex.ast.AbstractApexNode; import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule; -import apex.jorje.semantic.ast.compilation.*; -import apex.jorje.semantic.ast.member.*; +import apex.jorje.semantic.ast.compilation.UserClass; +import apex.jorje.semantic.ast.compilation.UserEnum; +import apex.jorje.semantic.ast.compilation.UserInterface; +import apex.jorje.semantic.ast.member.Field; +import apex.jorje.semantic.ast.member.Method; +import apex.jorje.semantic.ast.member.Property; import apex.jorje.semantic.ast.modifier.Annotation; import apex.jorje.semantic.ast.modifier.ModifierNode; -import apex.jorje.semantic.symbol.type.*; +import apex.jorje.semantic.symbol.type.AnnotationTypeInfos; +import apex.jorje.semantic.symbol.type.StandardAnnotationTypeInfo; /** * Apex supported non existent annotations for legacy reasons. - * In the future, use of such non-existent annotations could result in broken apex code that will not copile. + * In the future, use of such non-existent annotations could result in broken apex code that will not compile. * This will prevent users of garbage annotations from being able to use legitimate annotations added to apex in the future. + * A full list of supported annotations can be found at https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation.htm * * @author a.subramanian */ public class AvoidNonExistentAnnotationsRule extends AbstractApexRule { - private static final Set supportedApexAnnotations = getSupportedApexAnnotations(); + private static final Set SUPPORTED_APEX_ANNOTATIONS = getSupportedApexAnnotations(); @Override public Object visit(final ASTUserClass node, final Object data) { @@ -52,6 +69,7 @@ public class AvoidNonExistentAnnotationsRule extends AbstractApexRule { @Override public Object visit(final ASTProperty node, final Object data) { final Property property = node.getNode(); + // may have nested methods, don't visit children return checkForNonExistentAnnotation(node, property.getModifiersNode(), data); } @@ -61,9 +79,9 @@ public class AvoidNonExistentAnnotationsRule extends AbstractApexRule { return checkForNonExistentAnnotation(node, field.getModifiers(), data); } - private Object checkForNonExistentAnnotation(final AbstractApexNode node, final ModifierNode modifierNode, final Object data) { + private Object checkForNonExistentAnnotation(final AbstractApexNode node, final ModifierNode modifierNode, final Object data) { for (final Annotation annotation : modifierNode.getModifiers().getAnnotations()) { - if (!supportedApexAnnotations.contains(annotation.getType())) { + if (!SUPPORTED_APEX_ANNOTATIONS.contains(annotation.getType())) { addViolationWithMessage(data, node, "Use of non existent annotations will lead to broken Apex code which will not compile in the future."); } } diff --git a/pmd-apex/src/main/resources/category/apex/bestpractices.xml b/pmd-apex/src/main/resources/category/apex/bestpractices.xml index 1ad7f076e1..d6ff64a69a 100644 --- a/pmd-apex/src/main/resources/category/apex/bestpractices.xml +++ b/pmd-apex/src/main/resources/category/apex/bestpractices.xml @@ -109,5 +109,4 @@ trigger Accounts on Account (before insert, before update, before delete, after ]]> - diff --git a/pmd-apex/src/main/resources/category/apex/errorprone.xml b/pmd-apex/src/main/resources/category/apex/errorprone.xml index 2cd0249c43..64d75ca564 100644 --- a/pmd-apex/src/main/resources/category/apex/errorprone.xml +++ b/pmd-apex/src/main/resources/category/apex/errorprone.xml @@ -267,4 +267,25 @@ public class MyClass { + + + Apex supported non existent annotations for legacy reasons. + In the future, use of such non-existent annotations could result in broken apex code that will not compile. + This will prevent users of garbage annotations from being able to use legitimate annotations added to Apex in the future. + A full list of supported annotations can be found at https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation.htm + + 3 + + + + diff --git a/pmd-apex/src/main/resources/rulesets/apex/ruleset.xml b/pmd-apex/src/main/resources/rulesets/apex/ruleset.xml index dab5b5c055..d255b58d31 100644 --- a/pmd-apex/src/main/resources/rulesets/apex/ruleset.xml +++ b/pmd-apex/src/main/resources/rulesets/apex/ruleset.xml @@ -158,8 +158,7 @@ - - 3 + diff --git a/pmd-apex/src/main/resources/rulesets/apex/style.xml b/pmd-apex/src/main/resources/rulesets/apex/style.xml index 89878af6a6..7be2e9e6a1 100644 --- a/pmd-apex/src/main/resources/rulesets/apex/style.xml +++ b/pmd-apex/src/main/resources/rulesets/apex/style.xml @@ -19,24 +19,4 @@ The Style Ruleset contains rules regarding preferred usage of names and identifi - - - Apex supported non existent annotations for legacy reasons. - In the future, use of such non-existent annotations could result in broken apex code that will not copile. - This will prevent users of garbage annotations from being able to use legitimate annotations added to apex in the future. - - 3 - - - - diff --git a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/errorprone/ErrorProneRulesTest.java b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/errorprone/ErrorProneRulesTest.java index 7049e805af..dff977be84 100644 --- a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/errorprone/ErrorProneRulesTest.java +++ b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/errorprone/ErrorProneRulesTest.java @@ -10,13 +10,11 @@ public class ErrorProneRulesTest extends SimpleAggregatorTst { private static final String RULESET = "category/apex/errorprone.xml"; - - - @Override public void setUp() { addRule(RULESET, "AvoidDirectAccessTriggerMap"); addRule(RULESET, "AvoidHardcodingId"); + addRule(RULESET, "AvoidNonExistentAnnotations"); addRule(RULESET, "EmptyCatchBlock"); addRule(RULESET, "EmptyIfStmt"); addRule(RULESET, "EmptyStatementBlock"); diff --git a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/style/StyleRulesTest.java b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/style/StyleRulesTest.java deleted file mode 100644 index 2a95346bde..0000000000 --- a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/rule/style/StyleRulesTest.java +++ /dev/null @@ -1,24 +0,0 @@ -/** - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - -package net.sourceforge.pmd.lang.apex.rule.style; - -import net.sourceforge.pmd.testframework.SimpleAggregatorTst; - -public class StyleRulesTest extends SimpleAggregatorTst { - - private static final String RULESET = "apex-style"; - - @Override - public void setUp() { - addRule(RULESET, "AvoidGlobalModifier"); - addRule(RULESET, "AvoidLogicInTrigger"); - addRule(RULESET, "AvoidNonExistentAnnotations"); - addRule(RULESET, "ClassNamingConventions"); - addRule(RULESET, "MethodNamingConventions"); - addRule(RULESET, "VariableNamingConventions"); - addRule(RULESET, "MethodWithSameNameAsEnclosingClass"); - - } -} diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/style/xml/AvoidNonExistentAnnotations.xml b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/errorprone/xml/AvoidNonExistentAnnotations.xml similarity index 72% rename from pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/style/xml/AvoidNonExistentAnnotations.xml rename to pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/errorprone/xml/AvoidNonExistentAnnotations.xml index e252db3663..b07f4e9a58 100644 --- a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/style/xml/AvoidNonExistentAnnotations.xml +++ b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/rule/errorprone/xml/AvoidNonExistentAnnotations.xml @@ -1,6 +1,9 @@ - + Class with nonexistent annotation @@ -49,6 +52,20 @@ public class Foo { + + + + Valid annotations are not flagged + 0 +