From e8f8e1ac7a9f4f21bb7a0f9242a81fe7ab7e599c Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 29 Mar 2019 14:03:32 +0100 Subject: [PATCH] Update release notes, document apex attributes --- docs/pages/release_notes.md | 24 +++++++++++++++++++ .../lang/apex/ast/ASTCatchBlockStatement.java | 2 +- .../pmd/lang/apex/ast/ASTField.java | 6 ++++- .../lang/apex/ast/ASTFieldDeclaration.java | 4 ++++ .../lang/apex/ast/ASTNewObjectExpression.java | 2 +- .../rule/security/ApexOpenRedirectRule.java | 2 +- 6 files changed, 36 insertions(+), 4 deletions(-) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index a7f700fafa..c55fcc2f93 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -33,6 +33,30 @@ will be developed at [pmd/pmd-designer](https://github.com/pmd/pmd-designer) from now on. The maven coordinates will stay the same for the time being. The designer will still be shipped with PMD's binaries. +#### Improved Apex Support + +* Many AST nodes now expose more information which makes it easier to write XPath-based rules for Apex. Here are + some examples: + * `Annotation[@Resolved = false()]` finds unsupported annotations. + * `AnnotationParameter[@Name='RestResource'][@Value='/myurl']` gives access to + annotation parameters. + * `CatchBlockStatement[@ExceptionType='Exception'][@VariableName='e']` finds catch + block for specific exception types. + * `Field[@Type='String']` find all String fields, `Field[string-length(@Name) < 5]` + finds all fields with short names and `Field[@Value='a']` find alls fields, that are + initialized with a specific value. + * `LiteralExpression[@String = true()]` finds all String literals. There are attributes + for each type: `@Boolean`, `@Integer`, `@Double`, `@Long`, `@Decimal`, `@Null`. + * `Method[@Constructor = true()]` selects all constructors. `Method[@ReturnType = 'String']` + selects all methods that return a String. + * The `ModifierNode` node has a couple of attributes to check for the existence of specific + modifiers: `@Test`, `@TestOrTestSetup`, `@WithSharing`, `@WithoutSharing`, `@InheritedSharing`, + `@WebService`, `@Global`, `@Override`. + * Many nodes now expose their type. E.g. with `Parameter[@Type='Integer']` you can find all + method parameters of type Integer. The same attribute `Type` exists as well for: + `NewObjectExpression`, `Property`, `VariableDeclaration`. + * `VariableExpression[@Image='i']` finds all variable usages of the variable "i". + #### New Rules * The new Java rule {% rule "java/design/AvoidUncheckedExceptionsInSignatures" %} (`java-design`) finds methods or constructors diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTCatchBlockStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTCatchBlockStatement.java index 217f803fd8..5c98af83f2 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTCatchBlockStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTCatchBlockStatement.java @@ -17,7 +17,7 @@ public class ASTCatchBlockStatement extends AbstractApexNode implements CanSuppressWarn @Override public String getImage() { - return node.getFieldInfo().getName(); + return getName(); } @Override @@ -44,6 +44,10 @@ public class ASTField extends AbstractApexNode implements CanSuppressWarn return getFirstChildOfType(ASTModifierNode.class); } + public String getName() { + return node.getFieldInfo().getName(); + } + public String getValue() { if (node.getFieldInfo().getValue() != null) { return String.valueOf(node.getFieldInfo().getValue()); diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTFieldDeclaration.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTFieldDeclaration.java index 5c382e3574..7198442c65 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTFieldDeclaration.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTFieldDeclaration.java @@ -19,6 +19,10 @@ public class ASTFieldDeclaration extends AbstractApexNode { @Override public String getImage() { + return getName(); + } + + public String getName() { if (node.getFieldInfo() != null) { return node.getFieldInfo().getName(); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNewObjectExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNewObjectExpression.java index 745578637a..63c6465538 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNewObjectExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNewObjectExpression.java @@ -17,7 +17,7 @@ public class ASTNewObjectExpression extends AbstractApexNode