From eaceefc39e97df247667ccf1990a7fe1b414f19c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Thu, 21 Feb 2019 16:51:07 +0100 Subject: [PATCH 01/49] Update XPath rules to 2.0 --- .../resources/category/apex/codestyle.xml | 12 ++-- .../resources/category/apex/errorprone.xml | 2 +- .../pmd/lang/ast/xpath/saxon/ElementNode.java | 7 +++ .../sourceforge/pmd/lang/rule/XPathRule.java | 6 +- .../net/sourceforge/pmd/xml/j2ee.xml | 4 +- .../resources/category/java/bestpractices.xml | 12 ++-- .../resources/category/java/codestyle.xml | 57 ++++++++--------- .../main/resources/category/java/design.xml | 20 +++--- .../resources/category/java/documentation.xml | 6 +- .../resources/category/java/errorprone.xml | 63 +++++++++---------- .../category/java/multithreading.xml | 8 +-- .../resources/category/java/performance.xml | 4 +- .../category/ecmascript/bestpractices.xml | 2 +- .../category/ecmascript/codestyle.xml | 16 ++--- .../category/ecmascript/errorprone.xml | 6 +- .../resources/category/plsql/codestyle.xml | 4 +- .../resources/category/xsl/performance.xml | 2 +- 17 files changed, 117 insertions(+), 114 deletions(-) diff --git a/pmd-apex/src/main/resources/category/apex/codestyle.xml b/pmd-apex/src/main/resources/category/apex/codestyle.xml index 262b6f9757..72c22c83ce 100644 --- a/pmd-apex/src/main/resources/category/apex/codestyle.xml +++ b/pmd-apex/src/main/resources/category/apex/codestyle.xml @@ -48,9 +48,9 @@ from the rest. 0] +//IfBlockStatement/BlockStatement[@CurlyBrace= false()][count(child::*) > 0] | -//IfElseBlockStatement/BlockStatement[@CurlyBrace='false'][count(child::*) > 0] +//IfElseBlockStatement/BlockStatement[@CurlyBrace= false()][count(child::*) > 0] ]]> @@ -85,7 +85,7 @@ controlled from the rest. @@ -142,9 +142,9 @@ from the rest. @@ -348,7 +348,7 @@ controlled from the rest. diff --git a/pmd-apex/src/main/resources/category/apex/errorprone.xml b/pmd-apex/src/main/resources/category/apex/errorprone.xml index c96110f960..17c9182938 100644 --- a/pmd-apex/src/main/resources/category/apex/errorprone.xml +++ b/pmd-apex/src/main/resources/category/apex/errorprone.xml @@ -189,7 +189,7 @@ Empty block statements serve no purpose and should be removed. diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java index 4663e7f1bf..94bec1fbb1 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java @@ -122,6 +122,13 @@ public class ElementNode extends AbstractNodeInfo { return result; } + + @Override + public String getDisplayName() { + return getLocalPart(); + } + + @SuppressWarnings("PMD.MissingBreakInSwitch") @Override public AxisIterator iterateAxis(byte axisNumber) { diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/XPathRule.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/XPathRule.java index 773d64a5c0..55257976f9 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/XPathRule.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/XPathRule.java @@ -41,8 +41,8 @@ public class XPathRule extends AbstractRule { static { Map tmp = new HashMap<>(); - tmp.put(XPATH_1_0, XPATH_1_0); - tmp.put(XPATH_1_0_COMPATIBILITY, XPATH_1_0_COMPATIBILITY); + tmp.put(XPATH_1_0, XPATH_2_0); + tmp.put(XPATH_1_0_COMPATIBILITY, XPATH_2_0); tmp.put(XPATH_2_0, XPATH_2_0); XPATH_VERSIONS = Collections.unmodifiableMap(tmp); } @@ -51,7 +51,7 @@ public class XPathRule extends AbstractRule { public static final EnumeratedProperty VERSION_DESCRIPTOR = EnumeratedProperty.named("version") .desc("XPath specification version") .mappings(XPATH_VERSIONS) - .defaultValue(XPATH_1_0) + .defaultValue(XPATH_2_0) .type(String.class) .uiOrder(2.0f) .build(); diff --git a/pmd-core/src/test/resources/net/sourceforge/pmd/xml/j2ee.xml b/pmd-core/src/test/resources/net/sourceforge/pmd/xml/j2ee.xml index f158927f95..607967f6fd 100644 --- a/pmd-core/src/test/resources/net/sourceforge/pmd/xml/j2ee.xml +++ b/pmd-core/src/test/resources/net/sourceforge/pmd/xml/j2ee.xml @@ -324,9 +324,9 @@ behavior especially when instances are distributed by the container on several J ) and (./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration[ - (./FieldDeclaration[@Static = 'true']) + (./FieldDeclaration[@Static = true()]) and - (./FieldDeclaration[@Final = 'false']) + (./FieldDeclaration[@Final = false()]) ]) ] ]]> diff --git a/pmd-java/src/main/resources/category/java/bestpractices.xml b/pmd-java/src/main/resources/category/java/bestpractices.xml index 5c089e46d7..7dd321aee1 100644 --- a/pmd-java/src/main/resources/category/java/bestpractices.xml +++ b/pmd-java/src/main/resources/category/java/bestpractices.xml @@ -27,8 +27,8 @@ directly) a protected constructor can be provided prevent direct instantiation. @@ -380,7 +380,7 @@ better placed in classes or enums. See Effective Java, item 19. @@ -426,8 +426,8 @@ By convention, the default label should be the last label in a switch statement. @@ -1075,7 +1075,7 @@ can be avoided, they will just return false. //PrimaryExpression[ PrimaryPrefix[Name[(ends-with(@Image, '.equals'))]] [ - (../PrimarySuffix/Arguments/ArgumentList/Expression/PrimaryExpression/PrimaryPrefix/Literal[@StringLiteral='true']) + (../PrimarySuffix/Arguments/ArgumentList/Expression/PrimaryExpression/PrimaryPrefix/Literal[@StringLiteral= true()]) and ( count(../PrimarySuffix/Arguments/ArgumentList/Expression) = 1 ) ] diff --git a/pmd-java/src/main/resources/category/java/codestyle.xml b/pmd-java/src/main/resources/category/java/codestyle.xml index 6f8e3e2ae4..1cb7beabeb 100644 --- a/pmd-java/src/main/resources/category/java/codestyle.xml +++ b/pmd-java/src/main/resources/category/java/codestyle.xml @@ -28,12 +28,12 @@ by {% rule java/codestyle/ClassNamingConventions %}. @@ -116,7 +116,7 @@ If the goal is to avoid defining constants in a scope smaller than the class, th @@ -244,12 +244,13 @@ visibility cannot be reduced). Clarify your intent by using private or package a 3 + @@ -318,7 +319,7 @@ prefix for these methods. @@ -623,16 +624,16 @@ usage by developers who should be implementing their own versions in the concret 1 or - string:upper-case(@Image) != @Image + upper-case(@Image) != @Image ] ]]> @@ -947,7 +948,7 @@ by the rule {% rule java/codestyle/ControlStatementBraces %}. @@ -1728,9 +1729,9 @@ by the more general rule {% rule java/codestyle/FieldNamingConventions %}. @@ -1767,7 +1768,7 @@ which class a static member comes from (Sun 1.5 Language Guide). $maximumStaticImports] +.[count(ImportDeclaration[@Static = true()]) > $maximumStaticImports] ]]> @@ -1970,15 +1971,15 @@ which makes the code also more readable. @@ -2031,7 +2032,7 @@ List stringsWithDiamond = new ArrayList<>(); // using the diamond operat not(./CastExpression) and not(./EqualityExpression)] | -//Expression/AdditiveExpression[not(./PrimaryExpression/PrimaryPrefix/Literal[@StringLiteral='true'])] +//Expression/AdditiveExpression[not(./PrimaryExpression/PrimaryPrefix/Literal[@StringLiteral= true()])] /PrimaryExpression[1]/PrimaryPrefix/Expression[ count(*)=1 and not(./CastExpression) and @@ -2093,9 +2094,9 @@ public class Foo { diff --git a/pmd-java/src/main/resources/category/java/design.xml b/pmd-java/src/main/resources/category/java/design.xml index 73008d3e30..4a3dfa92dc 100644 --- a/pmd-java/src/main/resources/category/java/design.xml +++ b/pmd-java/src/main/resources/category/java/design.xml @@ -27,7 +27,7 @@ protected constructor in order to prevent instantiation than make the class misl @@ -339,9 +339,9 @@ is invoked by a inner class. = 1 ] -[count(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration[(@Public = 'true') or (@Protected = 'true') or (@PackagePrivate = 'true')]) = 0 ] +[@Final = false()] +[count(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration[@Private = true()]) >= 1 ] +[count(./ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/ConstructorDeclaration[(@Public = true()) or (@Protected = true()) or (@PackagePrivate = true())]) = 0 ] [not(.//ClassOrInterfaceDeclaration)] ]]> @@ -370,12 +370,12 @@ Sometimes two consecutive 'if' statements can be consolidated by separating thei @@ -727,7 +727,7 @@ in each object at runtime. @@ -1373,7 +1373,7 @@ ConditionalAndExpression [EqualityExpression[@Image='!=']//NullLiteral and InstanceOfExpression - [PrimaryExpression[count(PrimarySuffix[@ArrayDereference='true'])=0] + [PrimaryExpression[count(PrimarySuffix[@ArrayDereference= true()])=0] //Name[not(contains(@Image,'.'))]/@Image = ancestor::ConditionalAndExpression /EqualityExpression/PrimaryExpression/PrimaryPrefix/Name/@Image] and diff --git a/pmd-java/src/main/resources/category/java/documentation.xml b/pmd-java/src/main/resources/category/java/documentation.xml index 7b6d5cd81f..daee1d547d 100644 --- a/pmd-java/src/main/resources/category/java/documentation.xml +++ b/pmd-java/src/main/resources/category/java/documentation.xml @@ -94,8 +94,8 @@ and unintentional empty constructors. @@ -128,7 +128,7 @@ empty methods. diff --git a/pmd-java/src/main/resources/category/java/errorprone.xml b/pmd-java/src/main/resources/category/java/errorprone.xml index 938ca51d55..3415522b1e 100644 --- a/pmd-java/src/main/resources/category/java/errorprone.xml +++ b/pmd-java/src/main/resources/category/java/errorprone.xml @@ -734,7 +734,7 @@ public String bar(String string) { @Name='onStart' ] /Block[not( - (BlockStatement[1]/Statement/StatementExpression/PrimaryExpression[./PrimaryPrefix[@SuperModifier='true']]/PrimarySuffix[@Image= ancestor::MethodDeclaration/@Name]))] + (BlockStatement[1]/Statement/StatementExpression/PrimaryExpression[./PrimaryPrefix[@SuperModifier= true()]]/PrimarySuffix[@Image= ancestor::MethodDeclaration/@Name]))] [ancestor::ClassOrInterfaceDeclaration[ExtendsList/ClassOrInterfaceType[ pmd-java:typeIs('android.app.Activity') or pmd-java:typeIs('android.app.Application') or @@ -779,7 +779,7 @@ Super should be called at the end of the method @Name='onTerminate' ] /Block/BlockStatement[last()] - [not(Statement/StatementExpression/PrimaryExpression[./PrimaryPrefix[@SuperModifier='true']]/PrimarySuffix[@Image= ancestor::MethodDeclaration/@Name])] + [not(Statement/StatementExpression/PrimaryExpression[./PrimaryPrefix[@SuperModifier= true()]]/PrimarySuffix[@Image= ancestor::MethodDeclaration/@Name])] [ancestor::ClassOrInterfaceDeclaration[ExtendsList/ClassOrInterfaceType[ pmd-java:typeIs('android.app.Activity') or pmd-java:typeIs('android.app.Application') or @@ -892,7 +892,7 @@ Object.clone (which is protected) with a public method." @@ -1013,7 +1013,7 @@ and count(NameList/Name[contains (@Image,'CloneNotSupportedException')]) = 0 ] [ -../../../../ClassOrInterfaceDeclaration[@Final = 'false'] +../../../../ClassOrInterfaceDeclaration[@Final = false()] ] ]]> @@ -1474,7 +1474,7 @@ or reported. /Block /BlockStatement[last()] [not(Statement/StatementExpression/PrimaryExpression - [./PrimaryPrefix[@SuperModifier='true']] + [./PrimaryPrefix[@SuperModifier= true()]] [./PrimarySuffix[@Image='finalize']] ) ] [not(Statement/TryStatement/FinallyStatement /Block/BlockStatement/Statement/StatementExpression/PrimaryExpression - [./PrimaryPrefix[@SuperModifier='true']] + [./PrimaryPrefix[@SuperModifier= true()]] [./PrimarySuffix[@Image='finalize']] ) ] @@ -1924,7 +1924,7 @@ If the finalize() is implemented, it should do something besides just calling su /Block[count(BlockStatement)=1] /BlockStatement[ Statement/StatementExpression/PrimaryExpression - [./PrimaryPrefix[@SuperModifier='true']] + [./PrimaryPrefix[@SuperModifier= true()]] [./PrimarySuffix[@Image='finalize']] ] ]]> @@ -1990,7 +1990,7 @@ Note that Oracle has declared Object.finalize() as deprecated since JDK 9. @@ -2199,7 +2199,7 @@ The suite() method in a JUnit test needs to be both public and static. @@ -2333,7 +2333,7 @@ Either the check is useless (the variable will never be "null") or it is incorre public class Foo { void bar() { if (a.equals(baz) && a != null) {} // a could be null, misplaced null check - + if (a != null && a.equals(baz)) {} // correct null check } } @@ -2344,7 +2344,7 @@ public class Foo { public class Foo { void bar() { if (a.equals(baz) || a == null) {} // a could be null, misplaced null check - + if (a == null || a.equals(baz)) {} // correct null check } } @@ -2372,7 +2372,7 @@ may indicate problematic behaviour. Empty cases are ignored as these indicate an + count(BlockStatement//Statement/ReturnStatement) + count(BlockStatement//Statement/ContinueStatement) + count(BlockStatement//Statement/ThrowStatement) - + count(BlockStatement//Statement/IfStatement[@Else='true' and Statement[2][ReturnStatement|ContinueStatement|ThrowStatement]]/Statement[1][ReturnStatement|ContinueStatement|ThrowStatement]) + + count(BlockStatement//Statement/IfStatement[@Else= true() and Statement[2][ReturnStatement|ContinueStatement|ThrowStatement]]/Statement[1][ReturnStatement|ContinueStatement|ThrowStatement]) + count(SwitchLabel[name(following-sibling::node()) = 'SwitchLabel']) + count(SwitchLabel[count(following-sibling::node()) = 0]) < count (SwitchLabel))] @@ -2421,7 +2421,7 @@ chain needs an own serialVersionUID field. See also [Should an abstract class ha @@ -3377,7 +3372,7 @@ To make sure the full stacktrace is printed out, use the logging statement with concat(ancestor::ClassOrInterfaceDeclaration/ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/FieldDeclaration [Type//ClassOrInterfaceType[@Image='Log']] /VariableDeclarator/VariableDeclaratorId/@Image, '.'))]] -[PrimarySuffix/Arguments[@Size='1']] +[PrimarySuffix/Arguments[@Size= 1]] [PrimarySuffix/Arguments//Name/@Image = ancestor::CatchStatement/FormalParameter/VariableDeclaratorId/@Image] ]]> diff --git a/pmd-java/src/main/resources/category/java/multithreading.xml b/pmd-java/src/main/resources/category/java/multithreading.xml index c1ca1d5c2f..35a0d2ec5c 100644 --- a/pmd-java/src/main/resources/category/java/multithreading.xml +++ b/pmd-java/src/main/resources/category/java/multithreading.xml @@ -23,7 +23,7 @@ gets it. 3 - //MethodDeclaration[@Synchronized='true'] + //MethodDeclaration[@Synchronized= true()] @@ -102,7 +102,7 @@ the volatile keyword should not be used for maintenance purpose and portability. 2 - //FieldDeclaration[contains(@Volatile,'true')] + //FieldDeclaration[@Volatile = true()] @@ -379,7 +379,7 @@ one is chosen. The thread chosen is arbitrary; thus its usually safer to call n - \ No newline at end of file + diff --git a/pmd-java/src/main/resources/category/java/performance.xml b/pmd-java/src/main/resources/category/java/performance.xml index 7d0c75b226..7f1b0e4308 100644 --- a/pmd-java/src/main/resources/category/java/performance.xml +++ b/pmd-java/src/main/resources/category/java/performance.xml @@ -850,7 +850,7 @@ You must use new ArrayList<>(Arrays.asList(...)) if that is inconvenient for you (Arrays.asList(...)) if that is inconvenient for you and PrimaryExpression/PrimarySuffix/Arguments/ArgumentList/Expression/PrimaryExpression/PrimaryPrefix/Name [ - @Image = ancestor::MethodDeclaration[1]//LocalVariableDeclaration/VariableDeclarator/VariableDeclaratorId[@ArrayType="true"]/@Image + @Image = ancestor::MethodDeclaration[1]//LocalVariableDeclaration/VariableDeclarator/VariableDeclaratorId[@ArrayType=true()]/@Image or @Image = ancestor::MethodDeclaration[1]//FormalParameter/VariableDeclaratorId/@Image ] diff --git a/pmd-javascript/src/main/resources/category/ecmascript/bestpractices.xml b/pmd-javascript/src/main/resources/category/ecmascript/bestpractices.xml index 52cdac1822..a6ce322d0e 100644 --- a/pmd-javascript/src/main/resources/category/ecmascript/bestpractices.xml +++ b/pmd-javascript/src/main/resources/category/ecmascript/bestpractices.xml @@ -82,7 +82,7 @@ Global variables can lead to side-effects that are hard to debug. diff --git a/pmd-javascript/src/main/resources/category/ecmascript/codestyle.xml b/pmd-javascript/src/main/resources/category/ecmascript/codestyle.xml index 285262c59d..04d4e1abb2 100644 --- a/pmd-javascript/src/main/resources/category/ecmascript/codestyle.xml +++ b/pmd-javascript/src/main/resources/category/ecmascript/codestyle.xml @@ -25,17 +25,17 @@ indicative of the bug where the assignment operator '=' was used instead of the @@ -110,7 +110,7 @@ Avoid using if..else statements without using curly braces. @@ -149,7 +149,7 @@ Avoid using if statements without using curly braces. diff --git a/pmd-javascript/src/main/resources/category/ecmascript/errorprone.xml b/pmd-javascript/src/main/resources/category/ecmascript/errorprone.xml index 4b48e85dfe..a39190db2e 100644 --- a/pmd-javascript/src/main/resources/category/ecmascript/errorprone.xml +++ b/pmd-javascript/src/main/resources/category/ecmascript/errorprone.xml @@ -23,9 +23,9 @@ This rule helps improve code portability due to differences in browser treatment @@ -62,7 +62,7 @@ same type. The === operator avoids the casting. Date: Thu, 19 Mar 2020 01:49:55 +0100 Subject: [PATCH 02/49] Add relevant property tag --- .../resources/category/apex/codestyle.xml | 5 ++ .../resources/category/apex/errorprone.xml | 6 ++ .../sourceforge/pmd/lang/rule/XPathRule.java | 4 +- .../net/sourceforge/pmd/xml/j2ee.xml | 9 +++ .../test/resources/rulesets/dummy/basic.xml | 4 +- .../resources/rulesets/ruledoctest/sample.xml | 3 + .../rulesets/ruledoctest/sample2.xml | 1 + .../resources/category/java/bestpractices.xml | 22 +++++++ .../resources/category/java/codestyle.xml | 32 ++++++++++ .../main/resources/category/java/design.xml | 18 ++++++ .../resources/category/java/documentation.xml | 4 +- .../resources/category/java/errorprone.xml | 58 +++++++++++++++++++ .../category/java/multithreading.xml | 7 +++ .../resources/category/java/performance.xml | 13 +++++ .../pmd/ant/classpathtest/ruleset.xml | 1 + .../category/ecmascript/bestpractices.xml | 4 ++ .../category/ecmascript/codestyle.xml | 9 +++ .../category/ecmascript/errorprone.xml | 3 + .../resources/category/jsp/bestpractices.xml | 4 ++ .../main/resources/category/jsp/design.xml | 3 + .../resources/category/jsp/errorprone.xml | 1 + .../main/resources/category/jsp/security.xml | 1 + .../category/plsql/bestpractices.xml | 1 + .../resources/category/plsql/codestyle.xml | 2 + .../main/resources/category/plsql/design.xml | 1 + .../resources/category/plsql/errorprone.xml | 3 + .../main/resources/rulesets/dummy/basic.xml | 3 +- .../src/main/resources/category/vm/design.xml | 1 + .../resources/category/pom/errorprone.xml | 2 + .../resources/category/xml/errorprone.xml | 1 + .../main/resources/category/xsl/codestyle.xml | 1 + .../resources/category/xsl/performance.xml | 1 + 32 files changed, 223 insertions(+), 5 deletions(-) diff --git a/pmd-apex/src/main/resources/category/apex/codestyle.xml b/pmd-apex/src/main/resources/category/apex/codestyle.xml index 72c22c83ce..e76d6ebb8a 100644 --- a/pmd-apex/src/main/resources/category/apex/codestyle.xml +++ b/pmd-apex/src/main/resources/category/apex/codestyle.xml @@ -45,6 +45,7 @@ from the rest. 3 + 3 + 3 + 1 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + tmp = new HashMap<>(); - tmp.put(XPATH_1_0, XPATH_2_0); - tmp.put(XPATH_1_0_COMPATIBILITY, XPATH_2_0); + tmp.put(XPATH_1_0, XPATH_1_0); + tmp.put(XPATH_1_0_COMPATIBILITY, XPATH_1_0_COMPATIBILITY); tmp.put(XPATH_2_0, XPATH_2_0); XPATH_VERSIONS = Collections.unmodifiableMap(tmp); } diff --git a/pmd-core/src/test/resources/net/sourceforge/pmd/xml/j2ee.xml b/pmd-core/src/test/resources/net/sourceforge/pmd/xml/j2ee.xml index 607967f6fd..17443c62ab 100644 --- a/pmd-core/src/test/resources/net/sourceforge/pmd/xml/j2ee.xml +++ b/pmd-core/src/test/resources/net/sourceforge/pmd/xml/j2ee.xml @@ -20,6 +20,7 @@ 3 + 4 + 4 + 4 + 4 + 4 + 3 + 3 + 3 + 3 + 3 + - \ No newline at end of file + diff --git a/pmd-doc/src/test/resources/rulesets/ruledoctest/sample.xml b/pmd-doc/src/test/resources/rulesets/ruledoctest/sample.xml index 44e2bb76fb..78591da860 100644 --- a/pmd-doc/src/test/resources/rulesets/ruledoctest/sample.xml +++ b/pmd-doc/src/test/resources/rulesets/ruledoctest/sample.xml @@ -57,6 +57,7 @@ Here might be <script>alert('XSS');</script> as well. And "quotes". 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + + //ForInit/LocalVariableDeclaration[count(VariableDeclarator) > $maximumVariables] @@ -587,6 +593,7 @@ through the @RunWith(Suite.class) annotation. 3 + 3 + 3 + 3 + 3 + 4 + 3 + 3 + 3 + 3 + //Type/ReferenceType/ClassOrInterfaceType[@Image='Hashtable'] @@ -1206,6 +1222,7 @@ Consider replacing Vector usages with the newer java.util.ArrayList if expensive 3 + //Type/ReferenceType/ClassOrInterfaceType[@Image='Vector'] @@ -1267,6 +1284,7 @@ will (and by priority) and avoid clogging the Standard out log. 2 + 3 + 3 + 3 + 3 + 3 + 3 + 4 + 3 + 2 + //Name[starts-with(@Image,'System.loadLibrary')] @@ -314,6 +319,7 @@ prefix for these methods. 4 + 3 + 3 + 1 + No need to explicitly extend Object. 4 + 3 + 3 + //ForStatement[not(Statement/Block)] @@ -861,6 +873,7 @@ Names for references to generic values should be limited to a single uppercase l 4 + 3 + 3 + 4 + 4 + 3 + 4 + 3 + 3 + //PackageDeclaration/Name[lower-case(@Image)!=@Image] @@ -1532,6 +1553,7 @@ Remote Interface of a Session EJB should not have a suffix. 4 + 4 + 4 + 3 + 3 + + 3 + stringsWithDiamond = new ArrayList<>(); // using the diamond operat Useless parentheses should be removed. 4 + 3 + 3 + 3 + //WhileStatement[not(Statement/Block)] diff --git a/pmd-java/src/main/resources/category/java/design.xml b/pmd-java/src/main/resources/category/java/design.xml index 4a3dfa92dc..04ac51af08 100644 --- a/pmd-java/src/main/resources/category/java/design.xml +++ b/pmd-java/src/main/resources/category/java/design.xml @@ -23,6 +23,7 @@ protected constructor in order to prevent instantiation than make the class misl 1 + 3 + 3 + 3 + 1 + 1 + 3 + 1 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3 +
+ +
 /home/pmd/source/pmd-core/src/main/java/net/sourceforge/pmd/RuleContext.java
124   Logger calls should be surrounded by log level guards.
+ +
 /home/pmd/source/pmd-core/src/main/java/net/sourceforge/pmd/benchmark/Benchmarker.java
58   This for loop can be replaced by a foreach loop

 Problems found
/home/pmd/source/pmd-core/src/test/resources/net/sourceforge/pmd/cpd/files/file_with_ISO-8859-1_encoding.java
net.sourceforge.pmd.PMDException: Error while parsing /home/pmd/source/pmd-core/src/test/resources/net/sourceforge/pmd/cpd/files/file_with_ISO-8859-1_encoding.java
+    at net.sourceforge.pmd.SourceCodeProcessor.processSourceCodeWithoutCache(SourceCodeProcessor.java:110)
+    at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:89)
+    at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:51)
+    at net.sourceforge.pmd.processor.PmdRunnable.call(PmdRunnable.java:78)
+    at net.sourceforge.pmd.processor.PmdRunnable.call(PmdRunnable.java:24)
+    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
+    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
+    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
+    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
+    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
+    at java.base/java.lang.Thread.run(Thread.java:832)
+Caused by: net.sourceforge.pmd.lang.java.ast.ParseException: Encountered " "-" "- "" at line 6, column 30.
+Was expecting one of:
+    "extends" ...
+    "implements" ...
+    "{" ...
+    "<" ...
+    
+    at net.sourceforge.pmd.lang.java.ast.JavaParser.generateParseException(JavaParser.java:12713)
+    at net.sourceforge.pmd.lang.java.ast.JavaParser.jj_consume_token(JavaParser.java:12597)
+    at net.sourceforge.pmd.lang.java.ast.JavaParser.ClassOrInterfaceBody(JavaParser.java:1554)
+    at net.sourceforge.pmd.lang.java.ast.JavaParser.ClassOrInterfaceDeclaration(JavaParser.java:732)
+    at net.sourceforge.pmd.lang.java.ast.JavaParser.TypeDeclaration(JavaParser.java:639)
+    at net.sourceforge.pmd.lang.java.ast.JavaParser.CompilationUnit(JavaParser.java:373)
+    at net.sourceforge.pmd.lang.java.AbstractJavaParser.parse(AbstractJavaParser.java:62)
+    at net.sourceforge.pmd.SourceCodeProcessor.parse(SourceCodeProcessor.java:121)
+    at net.sourceforge.pmd.SourceCodeProcessor.processSource(SourceCodeProcessor.java:185)
+    at net.sourceforge.pmd.SourceCodeProcessor.processSourceCodeWithoutCache(SourceCodeProcessor.java:107)
+    ... 10 more
+
 Configuration problems found
LoosePackageCouplingNo packages or classes specified
diff --git a/docs/report-examples/pmd-report-yahtml/Benchmarker.html b/docs/report-examples/pmd-report-yahtml/Benchmarker.html new file mode 100644 index 0000000000..2e0da807d1 --- /dev/null +++ b/docs/report-examples/pmd-report-yahtml/Benchmarker.html @@ -0,0 +1,15 @@ + + + + + PMD - Benchmarker + + +

Class View

+

Class: Benchmarker

+ + + +
MethodViolation
findBooleanSwitch
Rule:ForLoopCanBeForeach
Description:This for loop can be replaced by a foreach loop
Line:58 and 62
+ + diff --git a/docs/report-examples/pmd-report-yahtml/RuleContext.html b/docs/report-examples/pmd-report-yahtml/RuleContext.html new file mode 100644 index 0000000000..1f401103f4 --- /dev/null +++ b/docs/report-examples/pmd-report-yahtml/RuleContext.html @@ -0,0 +1,15 @@ + + + + + PMD - RuleContext + + +

Class View

+

Class: RuleContext

+ + + +
MethodViolation
setSourceCodeFilename
Rule:GuardLogStatement
Description:Logger calls should be surrounded by log level guards.
Line:124 and 125
+ + diff --git a/docs/report-examples/pmd-report-yahtml/index.html b/docs/report-examples/pmd-report-yahtml/index.html new file mode 100644 index 0000000000..c8a696b998 --- /dev/null +++ b/docs/report-examples/pmd-report-yahtml/index.html @@ -0,0 +1,20 @@ + + + + + PMD + + +

Package View

+ + + + + + + + + +
PackageClass#
Aggregate - 2
net - 2
net.sourceforge - 2
net.sourceforge.pmd - 2
net.sourceforge.pmd RuleContext 1
net.sourceforge.pmd.benchmark - 1
net.sourceforge.pmd.benchmark Benchmarker 1
+ + From 97f35f60d472adabe87b9871bb70fd142991a946 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 11 Apr 2020 19:48:48 +0200 Subject: [PATCH 11/49] [doc] Fix doc for IDEA tool integration (refs #2117) --- docs/pages/pmd/userdocs/tools/tools.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/pages/pmd/userdocs/tools/tools.md b/docs/pages/pmd/userdocs/tools/tools.md index b8427311fe..b3e8d550c9 100644 --- a/docs/pages/pmd/userdocs/tools/tools.md +++ b/docs/pages/pmd/userdocs/tools/tools.md @@ -243,11 +243,11 @@ Here's how to set it up as an "External Tool": * Name: PMD * Description: PMD, good for what ails you. * Menu: Select the "Main menu", "Project views", "Editor menu", and "Search results" checkboxes. - * Program: $JDKPath$\bin\java.exe + * Program: `c:\pmd\bin\pmd.bat` * For the next parameter you'll need to plug in the location of your PMD installation and the rulesets you want to use * Parameters: - `-cp %CLASSPATH%;c:\pmd\lib\pmd-{{pmd.site.version}}.jar;c:\pmd\lib\asm-3.2.jar;c:\pmd\lib\jaxen-1.1.1.jar net.sourceforge.pmd.PMD "$FilePath$" ideaj unusedcode,imports "$Sourcepath$" $FileClass$.method $FileName$` + `-d "$FilePath$" -f ideaj -R rulesets/java/quickstart.xml -P sourcePath="$Sourcepath$" -P classAndMethodName=$FileClass$.method -P fileName=$FileName$` That's pretty much it. Now you can right click on a source directory and select PMD, it'll run recursively on the source files, and the results should From ad1e196173096cd84090abbbf7b8153b5ee23d1e Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 11 Apr 2020 19:49:11 +0200 Subject: [PATCH 12/49] [core] CodeClimateRenderer: correct links to spec --- .../pmd/renderers/CodeClimateRenderer.java | 6 +++--- .../pmd/renderers/CodeClimateRendererTest.java | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/renderers/CodeClimateRenderer.java b/pmd-core/src/main/java/net/sourceforge/pmd/renderers/CodeClimateRenderer.java index 4cc5645b92..0463368e8a 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/renderers/CodeClimateRenderer.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/renderers/CodeClimateRenderer.java @@ -33,7 +33,7 @@ public class CodeClimateRenderer extends AbstractIncrementingRenderer { public static final int REMEDIATION_POINTS_DEFAULT = 50000; public static final String[] CODECLIMATE_DEFAULT_CATEGORIES = new String[] {"Style"}; - // Note: required by https://github.com/codeclimate/spec/blob/master/SPEC.md + // Note: required by https://github.com/codeclimate/platform/blob/master/spec/analyzers/SPEC.md protected static final String NULL_CHARACTER = "\u0000"; protected static final List INTERNAL_DEV_PROPERTIES = Arrays.asList("version", "xpath"); private static final String PMD_PROPERTIES_URL = getPmdPropertiesURL(); @@ -146,9 +146,9 @@ public class CodeClimateRenderer extends AbstractIncrementingRenderer { private String getBody() { String result = "## " + rule.getName() + "\\n\\n" + "Since: PMD " + rule.getSince() + "\\n\\n" + "Priority: " + rule.getPriority() + "\\n\\n" - + "[Categories](https://github.com/codeclimate/spec/blob/master/SPEC.md#categories): " + + "[Categories](https://github.com/codeclimate/platform/blob/master/spec/analyzers/SPEC.md#categories): " + Arrays.toString(getCategories()).replaceAll("[\\[\\]]", "") + "\\n\\n" - + "[Remediation Points](https://github.com/codeclimate/spec/blob/master/SPEC.md#remediation-points): " + + "[Remediation Points](https://github.com/codeclimate/platform/blob/master/spec/analyzers/SPEC.md#remediation-points): " + getRemediationPoints() + "\\n\\n" + cleaned(rule.getDescription()); if (!rule.getExamples().isEmpty()) { diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/renderers/CodeClimateRendererTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/renderers/CodeClimateRendererTest.java index 28ca250b06..c81b425668 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/renderers/CodeClimateRendererTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/renderers/CodeClimateRendererTest.java @@ -30,8 +30,8 @@ public class CodeClimateRendererTest extends AbstractRendererTest { public String getExpected() { return "{\"type\":\"issue\",\"check_name\":\"Foo\",\"description\":\"blah\"," + "\"content\":{\"body\":\"## Foo\\n\\nSince: PMD null\\n\\nPriority: Low\\n\\n" - + "[Categories](https://github.com/codeclimate/spec/blob/master/SPEC.md#categories): Style\\n\\n" - + "[Remediation Points](https://github.com/codeclimate/spec/blob/master/SPEC.md#remediation-points): 50000\\n\\n" + + "[Categories](https://github.com/codeclimate/platform/blob/master/spec/analyzers/SPEC.md#categories): Style\\n\\n" + + "[Remediation Points](https://github.com/codeclimate/platform/blob/master/spec/analyzers/SPEC.md#remediation-points): 50000\\n\\n" + "desc\\n\\n" + "### [PMD properties](https://pmd.github.io/latest/pmd_devdocs_working_with_properties.html)\\n\\n" + "Name | Value | Description\\n" + "--- | --- | ---\\n" @@ -45,8 +45,8 @@ public class CodeClimateRendererTest extends AbstractRendererTest { public String getExpectedWithProperties() { return "{\"type\":\"issue\",\"check_name\":\"Foo\",\"description\":\"blah\"," + "\"content\":{\"body\":\"## Foo\\n\\nSince: PMD null\\n\\nPriority: Low\\n\\n" - + "[Categories](https://github.com/codeclimate/spec/blob/master/SPEC.md#categories): Style\\n\\n" - + "[Remediation Points](https://github.com/codeclimate/spec/blob/master/SPEC.md#remediation-points): 50000\\n\\n" + + "[Categories](https://github.com/codeclimate/platform/blob/master/spec/analyzers/SPEC.md#categories): Style\\n\\n" + + "[Remediation Points](https://github.com/codeclimate/platform/blob/master/spec/analyzers/SPEC.md#remediation-points): 50000\\n\\n" + "desc\\n\\n" + "### [PMD properties](https://pmd.github.io/latest/pmd_devdocs_working_with_properties.html)\\n\\n" + "Name | Value | Description\\n" + "--- | --- | ---\\n" @@ -67,8 +67,8 @@ public class CodeClimateRendererTest extends AbstractRendererTest { public String getExpectedMultiple() { return "{\"type\":\"issue\",\"check_name\":\"Foo\",\"description\":\"blah\"," + "\"content\":{\"body\":\"## Foo\\n\\nSince: PMD null\\n\\nPriority: Low\\n\\n" - + "[Categories](https://github.com/codeclimate/spec/blob/master/SPEC.md#categories): Style\\n\\n" - + "[Remediation Points](https://github.com/codeclimate/spec/blob/master/SPEC.md#remediation-points): 50000\\n\\n" + + "[Categories](https://github.com/codeclimate/platform/blob/master/spec/analyzers/SPEC.md#categories): Style\\n\\n" + + "[Remediation Points](https://github.com/codeclimate/platform/blob/master/spec/analyzers/SPEC.md#remediation-points): 50000\\n\\n" + "desc\\n\\n" + "### [PMD properties](https://pmd.github.io/latest/pmd_devdocs_working_with_properties.html)\\n\\n" + "Name | Value | Description\\n" + "--- | --- | ---\\n" @@ -77,8 +77,8 @@ public class CodeClimateRendererTest extends AbstractRendererTest { + "\"},\"categories\":[\"Style\"],\"location\":{\"path\":\"" + getSourceCodeFilename() + "\",\"lines\":{\"begin\":1,\"end\":1}},\"severity\":\"info\",\"remediation_points\":50000}" + "\u0000" + PMD.EOL + "{\"type\":\"issue\",\"check_name\":\"Foo\",\"description\":\"blah\"," + "\"content\":{\"body\":\"## Foo\\n\\nSince: PMD null\\n\\nPriority: Low\\n\\n" - + "[Categories](https://github.com/codeclimate/spec/blob/master/SPEC.md#categories): Style\\n\\n" - + "[Remediation Points](https://github.com/codeclimate/spec/blob/master/SPEC.md#remediation-points): 50000\\n\\n" + + "[Categories](https://github.com/codeclimate/platform/blob/master/spec/analyzers/SPEC.md#categories): Style\\n\\n" + + "[Remediation Points](https://github.com/codeclimate/platform/blob/master/spec/analyzers/SPEC.md#remediation-points): 50000\\n\\n" + "desc\\n\\n" + "### [PMD properties](https://pmd.github.io/latest/pmd_devdocs_working_with_properties.html)\\n\\n" + "Name | Value | Description\\n" + "--- | --- | ---\\n" From a007b0b0cc9b8128ca2eebf08d143d89f9c376e4 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 11 Apr 2020 21:22:35 +0200 Subject: [PATCH 13/49] Fix dead links --- docs/pages/pmd/userdocs/cli_reference.md | 2 +- .../java/net/sourceforge/pmd/docs/DeadLinksChecker.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/pages/pmd/userdocs/cli_reference.md b/docs/pages/pmd/userdocs/cli_reference.md index 25fb1da3b0..a43c809081 100644 --- a/docs/pages/pmd/userdocs/cli_reference.md +++ b/docs/pages/pmd/userdocs/cli_reference.md @@ -198,5 +198,5 @@ Example: ## Available Report Formats PMD comes with many different renderers. -All formats are described at [PMD Report formats](pmd_userdos_report_formats.html) +All formats are described at [PMD Report formats](pmd_userdocs_report_formats.html) diff --git a/pmd-doc/src/main/java/net/sourceforge/pmd/docs/DeadLinksChecker.java b/pmd-doc/src/main/java/net/sourceforge/pmd/docs/DeadLinksChecker.java index 1ab25d40a6..66d8c45a7e 100644 --- a/pmd-doc/src/main/java/net/sourceforge/pmd/docs/DeadLinksChecker.java +++ b/pmd-doc/src/main/java/net/sourceforge/pmd/docs/DeadLinksChecker.java @@ -177,6 +177,12 @@ public class DeadLinksChecker { } else { linkOk = linkTarget.isEmpty() || htmlPages.contains(linkTarget); } + + // maybe a local file + if (!linkOk) { + Path localResource = docsDirectory.resolve(linkTarget); + linkOk = Files.exists(localResource); + } } if (!linkOk) { From feee0b8f9174bbbb52c70acefc88a6df3702d673 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 16 Apr 2020 18:57:10 +0200 Subject: [PATCH 14/49] [java] Replace XPath ProperCloneImplementation with Java Rule --- .../ProperCloneImplementationRule.java | 52 +++++++++++++++++++ .../resources/category/java/errorprone.xml | 17 +----- 2 files changed, 53 insertions(+), 16 deletions(-) create mode 100644 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/ProperCloneImplementationRule.java diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/ProperCloneImplementationRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/ProperCloneImplementationRule.java new file mode 100644 index 0000000000..19262a5535 --- /dev/null +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/ProperCloneImplementationRule.java @@ -0,0 +1,52 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + + +package net.sourceforge.pmd.lang.java.rule.errorprone; + +import java.util.List; + +import net.sourceforge.pmd.lang.java.ast.ASTAllocationExpression; +import net.sourceforge.pmd.lang.java.ast.ASTBlock; +import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration; +import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceType; +import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration; +import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule; + +public class ProperCloneImplementationRule extends AbstractJavaRule { + + public ProperCloneImplementationRule() { + addRuleChainVisit(ASTMethodDeclaration.class); + } + + @Override + public Object visit(ASTMethodDeclaration node, Object data) { + if (!"clone".equals(node.getName()) || node.getArity() > 0) { + return data; + } + + ASTBlock block = node.getFirstChildOfType(ASTBlock.class); + if (block == null) { + return data; + } + + String enclosingClassName = node.getFirstParentOfType(ASTClassOrInterfaceDeclaration.class).getSimpleName(); + if (blockHasAllocations(block, enclosingClassName)) { + addViolation(data, node); + } + + return data; + } + + private boolean blockHasAllocations(ASTBlock block, String enclosingClassName) { + List allocations = block.findDescendantsOfType(ASTAllocationExpression.class); + for (ASTAllocationExpression alloc : allocations) { + ASTClassOrInterfaceType type = alloc.getFirstChildOfType(ASTClassOrInterfaceType.class); + if (type.hasImageEqualTo(enclosingClassName)) { + return true; + } + } + return false; + } +} diff --git a/pmd-java/src/main/resources/category/java/errorprone.xml b/pmd-java/src/main/resources/category/java/errorprone.xml index 15c60185ea..3617a84f41 100644 --- a/pmd-java/src/main/resources/category/java/errorprone.xml +++ b/pmd-java/src/main/resources/category/java/errorprone.xml @@ -2719,27 +2719,12 @@ public class Foo { // perfect, both methods provided language="java" since="1.4" message="Object clone() should be implemented with super.clone()" - class="net.sourceforge.pmd.lang.rule.XPathRule" + class="net.sourceforge.pmd.lang.java.rule.errorprone.ProperCloneImplementationRule" externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#propercloneimplementation"> Object clone() should be implemented with super.clone(). 2 - - - - - - - - Date: Thu, 16 Apr 2020 18:57:36 +0200 Subject: [PATCH 15/49] [java] Simplify AvoidDecimalLiteralsInBigDecimalConstructor with type res --- .../resources/category/java/errorprone.xml | 22 +++------- ...DecimalLiteralsInBigDecimalConstructor.xml | 40 ++++++++++--------- 2 files changed, 28 insertions(+), 34 deletions(-) diff --git a/pmd-java/src/main/resources/category/java/errorprone.xml b/pmd-java/src/main/resources/category/java/errorprone.xml index 3617a84f41..e0de33036d 100644 --- a/pmd-java/src/main/resources/category/java/errorprone.xml +++ b/pmd-java/src/main/resources/category/java/errorprone.xml @@ -288,23 +288,13 @@ exactly equal to 0.1, as one would expect. Therefore, it is generally recommend diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/AvoidDecimalLiteralsInBigDecimalConstructor.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/AvoidDecimalLiteralsInBigDecimalConstructor.xml index 0c20b4e280..9098d2fb3f 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/AvoidDecimalLiteralsInBigDecimalConstructor.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/AvoidDecimalLiteralsInBigDecimalConstructor.xml @@ -4,11 +4,11 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pmd.sourceforge.net/rule-tests http://pmd.sourceforge.net/rule-tests_1_0_0.xsd"> - + bad, new BigDecimal(.1) 1 - + ok, new BigDecimal(".1") 0 ok, new BigDecimal(10) 0 - + bad, same as #1 but outside an initializer context 1 #1187 double variable with AvoidDecimalLiteralsInBigDecimalConstructor 8 - 4,8,11,14,18,22,25,28 + 6,10,13,16,20,24,27,30 From 12e843cb47d81390610778185e50a596d3fa242a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Fri, 17 Apr 2020 08:36:28 +0200 Subject: [PATCH 16/49] Pool names, optimize getNodeKind NameTest::matches is a very hot spot in saxon. Profiling shows that most of its runtime is spent doing virtual method dispatch on NodeInfo#getNodeKind We optimise this by making a base class with the node kind as a field. Also, we now pool xpath names using saxon's name pool, which reduces name tests to integer comparison instead of string.equals Saxon now spends 80x less time in the name test overall shaving off 30% of execution time of XPath rules. --- .../lang/ast/xpath/saxon/AttributeNode.java | 24 ++------ .../lang/ast/xpath/saxon/BaseNodeInfo.java | 59 +++++++++++++++++++ .../lang/ast/xpath/saxon/DocumentNode.java | 21 ++++--- .../pmd/lang/ast/xpath/saxon/ElementNode.java | 36 +++++------ .../lang/rule/xpath/SaxonXPathRuleQuery.java | 12 +++- 5 files changed, 103 insertions(+), 49 deletions(-) create mode 100644 pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/BaseNodeInfo.java diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/AttributeNode.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/AttributeNode.java index 5bea99b879..79dc9273cf 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/AttributeNode.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/AttributeNode.java @@ -23,9 +23,8 @@ import net.sf.saxon.value.Value; */ @Deprecated @InternalApi -public class AttributeNode extends AbstractNodeInfo { +public class AttributeNode extends BaseNodeInfo { - private final ElementNode parent; protected final Attribute attribute; protected final int id; protected Value value; @@ -34,35 +33,20 @@ public class AttributeNode extends AbstractNodeInfo { /** * Creates a new AttributeNode from a PMD Attribute. * - * @param parent - * @param id The index within the attribute order + * @param parent Parent elemtn + * @param id The index within the attribute order */ public AttributeNode(ElementNode parent, Attribute attribute, int id) { - this.parent = parent; + super(Type.ATTRIBUTE, parent.getNamePool(), attribute.getName(), parent); this.attribute = attribute; this.id = id; } - @Override - public int getNodeKind() { - return Type.ATTRIBUTE; - } - @Override public String getLocalPart() { return attribute.getName(); } - @Override - public String getURI() { - return ""; - } - - @Override - public ElementNode getParent() { - return parent; - } - @Override public Value atomize() { if (value == null) { diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/BaseNodeInfo.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/BaseNodeInfo.java new file mode 100644 index 0000000000..a460cfb6d7 --- /dev/null +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/BaseNodeInfo.java @@ -0,0 +1,59 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.ast.xpath.saxon; + + +import net.sf.saxon.om.FingerprintedNode; +import net.sf.saxon.om.NamePool; +import net.sf.saxon.om.NodeInfo; +import net.sf.saxon.om.SiblingCountingNode; +import net.sf.saxon.om.VirtualNode; + +abstract class BaseNodeInfo extends AbstractNodeInfo implements VirtualNode, SiblingCountingNode, FingerprintedNode { + + private final int nodeKind; + private final NamePool namePool; + private final int fingerprint; + + private final ElementNode parent; + + BaseNodeInfo(int nodeKind, NamePool namePool, String localName, ElementNode parent) { + this.nodeKind = nodeKind; + this.namePool = namePool; + this.fingerprint = namePool.allocate("", "", localName); + this.parent = parent; + } + + @Override + public final String getURI() { + return ""; + } + + @Override + public final String getBaseURI() { + return ""; + } + + @Override + public final NodeInfo getParent() { + return parent; + } + + @Override + public final int getFingerprint() { + return fingerprint; + } + + @Override + public final NamePool getNamePool() { + return namePool; + } + + @Override + public final int getNodeKind() { + return nodeKind; + } + +} diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/DocumentNode.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/DocumentNode.java index f91718c816..1a9213c826 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/DocumentNode.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/DocumentNode.java @@ -10,10 +10,12 @@ import java.util.Map; import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.ast.Node; +import net.sourceforge.pmd.lang.rule.xpath.SaxonXPathRuleQuery; import net.sf.saxon.om.Axis; import net.sf.saxon.om.AxisIterator; import net.sf.saxon.om.DocumentInfo; +import net.sf.saxon.om.NamePool; import net.sf.saxon.om.Navigator; import net.sf.saxon.om.NodeInfo; import net.sf.saxon.om.SingleNodeIterator; @@ -24,7 +26,7 @@ import net.sf.saxon.type.Type; */ @Deprecated @InternalApi -public class DocumentNode extends AbstractNodeInfo implements DocumentInfo { +public class DocumentNode extends BaseNodeInfo implements DocumentInfo { /** * The root ElementNode of the DocumentNode. @@ -40,13 +42,19 @@ public class DocumentNode extends AbstractNodeInfo implements DocumentInfo { * Construct a DocumentNode, with the given AST Node serving as the root * ElementNode. * - * @param node - * The root AST Node. + * @param node The root AST Node. + * @param namePool Pool to share names * * @see ElementNode */ + public DocumentNode(Node node, NamePool namePool) { + super(Type.DOCUMENT, namePool, "", null); + this.rootNode = new ElementNode(this, new IdGenerator(), null, node, -1, namePool); + } + + @Deprecated public DocumentNode(Node node) { - this.rootNode = new ElementNode(this, new IdGenerator(), null, node, -1); + this(node, SaxonXPathRuleQuery.getNamePool()); } @Override @@ -64,11 +72,6 @@ public class DocumentNode extends AbstractNodeInfo implements DocumentInfo { throw createUnsupportedOperationException("DocumentInfo.selectID(String)"); } - @Override - public int getNodeKind() { - return Type.DOCUMENT; - } - @Override public DocumentInfo getDocumentRoot() { return this; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java index ef600ed7ab..4e0c1ec698 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java @@ -6,11 +6,13 @@ package net.sourceforge.pmd.lang.ast.xpath.saxon; import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.ast.Node; +import net.sourceforge.pmd.lang.rule.xpath.SaxonXPathRuleQuery; import net.sf.saxon.om.Axis; import net.sf.saxon.om.AxisIterator; import net.sf.saxon.om.DocumentInfo; import net.sf.saxon.om.EmptyIterator; +import net.sf.saxon.om.NamePool; import net.sf.saxon.om.Navigator; import net.sf.saxon.om.NodeArrayIterator; import net.sf.saxon.om.NodeInfo; @@ -28,7 +30,7 @@ import net.sf.saxon.value.Value; */ @Deprecated @InternalApi -public class ElementNode extends AbstractNodeInfo { +public class ElementNode extends BaseNodeInfo { protected final DocumentNode document; protected final ElementNode parent; @@ -37,17 +39,29 @@ public class ElementNode extends AbstractNodeInfo { protected final int siblingPosition; protected final NodeInfo[] children; - public ElementNode(DocumentNode document, IdGenerator idGenerator, ElementNode parent, Node node, - int siblingPosition) { + @Deprecated + public ElementNode(DocumentNode document, IdGenerator idGenerator, ElementNode parent, Node node, int siblingPosition) { + this(document, idGenerator, parent, node, siblingPosition, SaxonXPathRuleQuery.getNamePool()); + } + + public ElementNode(DocumentNode document, + IdGenerator idGenerator, + ElementNode parent, + Node node, + int siblingPosition, + NamePool namePool) { + super(Type.ELEMENT, namePool, node.getXPathNodeName(), parent); + this.document = document; this.parent = parent; this.node = node; this.id = idGenerator.getNextId(); this.siblingPosition = siblingPosition; + if (node.getNumChildren() > 0) { this.children = new NodeInfo[node.getNumChildren()]; for (int i = 0; i < children.length; i++) { - children[i] = new ElementNode(document, idGenerator, this, node.getChild(i), i); + children[i] = new ElementNode(document, idGenerator, this, node.getChild(i), i, namePool); } } else { this.children = null; @@ -80,11 +94,6 @@ public class ElementNode extends AbstractNodeInfo { return children != null; } - @Override - public int getNodeKind() { - return Type.ELEMENT; - } - @Override public DocumentInfo getDocumentRoot() { return document; @@ -95,15 +104,6 @@ public class ElementNode extends AbstractNodeInfo { return node.getXPathNodeName(); } - @Override - public String getURI() { - return ""; - } - - @Override - public NodeInfo getParent() { - return parent; - } @Override public SequenceIterator getTypedValue() { diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/SaxonXPathRuleQuery.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/SaxonXPathRuleQuery.java index 231bd0a917..856c4ed794 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/SaxonXPathRuleQuery.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/SaxonXPathRuleQuery.java @@ -26,6 +26,7 @@ import net.sourceforge.pmd.properties.PropertyDescriptor; import net.sf.saxon.expr.Expression; import net.sf.saxon.om.Item; +import net.sf.saxon.om.NamePool; import net.sf.saxon.om.NamespaceConstant; import net.sf.saxon.om.SequenceIterator; import net.sf.saxon.om.ValueRepresentation; @@ -57,6 +58,7 @@ import net.sf.saxon.value.Value; @Deprecated @InternalApi public class SaxonXPathRuleQuery extends AbstractXPathRuleQuery { + /** * Special nodeName that references the root expression. */ @@ -64,6 +66,8 @@ public class SaxonXPathRuleQuery extends AbstractXPathRuleQuery { private static final Logger LOG = Logger.getLogger(SaxonXPathRuleQuery.class.getName()); + private static final NamePool NAME_POOL = NamePool.getDefaultNamePool(); + private static final int MAX_CACHE_SIZE = 20; private static final Map CACHE = new LinkedHashMap(MAX_CACHE_SIZE) { private static final long serialVersionUID = -7653916493967142443L; @@ -97,7 +101,6 @@ public class SaxonXPathRuleQuery extends AbstractXPathRuleQuery { } @Override - @SuppressWarnings("unchecked") public List evaluate(final Node node, final RuleContext data) { initializeXPathExpression(); @@ -191,7 +194,7 @@ public class SaxonXPathRuleQuery extends AbstractXPathRuleQuery { synchronized (CACHE) { documentNode = CACHE.get(root); if (documentNode == null) { - documentNode = new DocumentNode(root); + documentNode = new DocumentNode(root, NAME_POOL); CACHE.put(root, documentNode); } } @@ -229,6 +232,7 @@ public class SaxonXPathRuleQuery extends AbstractXPathRuleQuery { try { final XPathEvaluator xpathEvaluator = new XPathEvaluator(); final XPathStaticContext xpathStaticContext = xpathEvaluator.getStaticContext(); + xpathStaticContext.getConfiguration().setNamePool(NAME_POOL); // Enable XPath 1.0 compatibility if (XPATH_1_0_COMPATIBILITY.equals(version)) { @@ -354,4 +358,8 @@ public class SaxonXPathRuleQuery extends AbstractXPathRuleQuery { initializeXPathExpression(); return super.getRuleChainVisits(); } + + public static NamePool getNamePool() { + return NAME_POOL; + } } From dde5b29da8f62bc4b2047bd1c4e5b582289441cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Fri, 17 Apr 2020 09:02:19 +0200 Subject: [PATCH 17/49] Optimise attribute fetch Use a map to fetch the attribute, also don't recreate attribute nodes so much, so that the cache behind Method::invoke in Attribute amounts to something. --- .../ast/xpath/saxon/AbstractNodeInfo.java | 10 +-- .../lang/ast/xpath/saxon/BaseNodeInfo.java | 21 +++++- .../pmd/lang/ast/xpath/saxon/ElementNode.java | 66 ++++++++++++++++++- 3 files changed, 88 insertions(+), 9 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/AbstractNodeInfo.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/AbstractNodeInfo.java index 1e7c8e0825..822bb9d797 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/AbstractNodeInfo.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/AbstractNodeInfo.java @@ -260,11 +260,11 @@ public class AbstractNodeInfo implements VirtualNode, SiblingCountingNode { */ @Override public AxisIterator iterateAxis(byte axisNumber, NodeTest nodeTest) { - AxisIterator axisIterator = iterateAxis(axisNumber); - if (nodeTest != null) { - axisIterator = new AxisFilter(axisIterator, nodeTest); - } - return axisIterator; + return filter(iterateAxis(axisNumber), nodeTest); + } + + protected static AxisIterator filter(AxisIterator axisIterator, NodeTest nodeTest) { + return nodeTest != null ? new AxisFilter(axisIterator, nodeTest) : axisIterator; } /** diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/BaseNodeInfo.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/BaseNodeInfo.java index a460cfb6d7..ea6e4477ac 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/BaseNodeInfo.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/BaseNodeInfo.java @@ -13,16 +13,19 @@ import net.sf.saxon.om.VirtualNode; abstract class BaseNodeInfo extends AbstractNodeInfo implements VirtualNode, SiblingCountingNode, FingerprintedNode { + // It's important that all our NodeInfo implementations share the + // same getNodeKind implementation, otherwise NameTest spends a lot + // of time in virtual dispatch private final int nodeKind; private final NamePool namePool; private final int fingerprint; - private final ElementNode parent; + protected final ElementNode parent; BaseNodeInfo(int nodeKind, NamePool namePool, String localName, ElementNode parent) { this.nodeKind = nodeKind; this.namePool = namePool; - this.fingerprint = namePool.allocate("", "", localName); + this.fingerprint = namePool.allocate("", "", localName) & NamePool.FP_MASK; this.parent = parent; } @@ -36,11 +39,25 @@ abstract class BaseNodeInfo extends AbstractNodeInfo implements VirtualNode, Sib return ""; } + @Override + public String getPrefix() { + return ""; + } + @Override public final NodeInfo getParent() { return parent; } + @Override + public int getNameCode() { + // note: the nameCode is only equal to the fingerprint because + // this implementation does not use namespace prefixes + // if we change that (eg for embedded language support) then + // we'll need to worry about this. See NamePool.FP_MASK + return fingerprint; + } + @Override public final int getFingerprint() { return fingerprint; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java index 4e0c1ec698..146b7f3553 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java @@ -4,8 +4,13 @@ package net.sourceforge.pmd.lang.ast.xpath.saxon; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.ast.Node; +import net.sourceforge.pmd.lang.ast.xpath.Attribute; import net.sourceforge.pmd.lang.rule.xpath.SaxonXPathRuleQuery; import net.sf.saxon.om.Axis; @@ -14,11 +19,14 @@ import net.sf.saxon.om.DocumentInfo; import net.sf.saxon.om.EmptyIterator; import net.sf.saxon.om.NamePool; import net.sf.saxon.om.Navigator; +import net.sf.saxon.om.Navigator.BaseEnumeration; import net.sf.saxon.om.NodeArrayIterator; import net.sf.saxon.om.NodeInfo; import net.sf.saxon.om.SequenceIterator; import net.sf.saxon.om.SingleNodeIterator; import net.sf.saxon.om.SingletonIterator; +import net.sf.saxon.pattern.NameTest; +import net.sf.saxon.pattern.NodeTest; import net.sf.saxon.type.Type; import net.sf.saxon.value.AtomicValue; import net.sf.saxon.value.StringValue; @@ -39,6 +47,8 @@ public class ElementNode extends BaseNodeInfo { protected final int siblingPosition; protected final NodeInfo[] children; + private Map attributes; + @Deprecated public ElementNode(DocumentNode document, IdGenerator idGenerator, ElementNode parent, Node node, int siblingPosition) { this(document, idGenerator, parent, node, siblingPosition, SaxonXPathRuleQuery.getNamePool()); @@ -69,6 +79,20 @@ public class ElementNode extends BaseNodeInfo { document.nodeToElementNode.put(node, this); } + private Map getAttributes() { + if (attributes == null) { + attributes = new HashMap<>(); + Iterator iter = node.getXPathAttributesIterator(); + int idx = 0; + while (iter.hasNext()) { + Attribute next = iter.next(); + AttributeNode attrNode = new AttributeNode(this, next, idx++); + attributes.put(attrNode.getFingerprint(), attrNode); + } + } + return attributes; + } + @Override public Object getUnderlyingNode() { return node; @@ -156,16 +180,33 @@ public class ElementNode extends BaseNodeInfo { } + @Override + public AxisIterator iterateAxis(byte axisNumber, NodeTest nodeTest) { + if (axisNumber == Axis.ATTRIBUTE) { + if (nodeTest instanceof NameTest) { + if ((nodeTest.getNodeKindMask() & (1 << Type.ATTRIBUTE)) == 0) { + return EmptyIterator.getInstance(); + } else { + int fp = nodeTest.getFingerprint(); + if (fp != -1) { + return SingleNodeIterator.makeIterator(getAttributes().get(fp)); + } + } + } + } + return super.iterateAxis(axisNumber, nodeTest); + } + @SuppressWarnings("PMD.MissingBreakInSwitch") @Override - public AxisIterator iterateAxis(byte axisNumber) { + public AxisIterator iterateAxis(final byte axisNumber) { switch (axisNumber) { case Axis.ANCESTOR: return new Navigator.AncestorEnumeration(this, false); case Axis.ANCESTOR_OR_SELF: return new Navigator.AncestorEnumeration(this, true); case Axis.ATTRIBUTE: - return new AttributeAxisIterator(this); + return new AttributeEnumeration(); case Axis.CHILD: if (children == null) { return EmptyIterator.getInstance(); @@ -205,4 +246,25 @@ public class ElementNode extends BaseNodeInfo { } } + private class AttributeEnumeration extends BaseEnumeration { + + private final Iterator iter = getAttributes().values().iterator(); + + public AttributeEnumeration() { + } + + @Override + public void advance() { + if (iter.hasNext()) { + current = iter.next(); + } else { + current = null; + } + } + + @Override + public SequenceIterator getAnother() { + return new AttributeEnumeration(); + } + } } From e81fee9ee54d74f7a0c1ace57a5efd32f1bc2e2a Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 17 Apr 2020 11:24:23 +0200 Subject: [PATCH 18/49] [java] Convert PositionLiteralsFirstIn*Comparisons to Java rules --- ...actPositionLiteralsFirstInComparisons.java | 119 ++++++++++++++++++ ...FirstInCaseInsensitiveComparisonsRule.java | 13 ++ ...ositionLiteralsFirstInComparisonsRule.java | 13 ++ .../resources/category/java/bestpractices.xml | 46 +------ .../PositionLiteralsFirstInComparisons.xml | 9 ++ 5 files changed, 156 insertions(+), 44 deletions(-) create mode 100644 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AbstractPositionLiteralsFirstInComparisons.java create mode 100644 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/PositionLiteralsFirstInCaseInsensitiveComparisonsRule.java create mode 100644 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/PositionLiteralsFirstInComparisonsRule.java diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AbstractPositionLiteralsFirstInComparisons.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AbstractPositionLiteralsFirstInComparisons.java new file mode 100644 index 0000000000..3b09462725 --- /dev/null +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AbstractPositionLiteralsFirstInComparisons.java @@ -0,0 +1,119 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.java.rule.bestpractices; + +import net.sourceforge.pmd.lang.ast.Node; +import net.sourceforge.pmd.lang.java.ast.ASTArgumentList; +import net.sourceforge.pmd.lang.java.ast.ASTArguments; +import net.sourceforge.pmd.lang.java.ast.ASTConditionalAndExpression; +import net.sourceforge.pmd.lang.java.ast.ASTConditionalOrExpression; +import net.sourceforge.pmd.lang.java.ast.ASTEqualityExpression; +import net.sourceforge.pmd.lang.java.ast.ASTExpression; +import net.sourceforge.pmd.lang.java.ast.ASTLiteral; +import net.sourceforge.pmd.lang.java.ast.ASTName; +import net.sourceforge.pmd.lang.java.ast.ASTNullLiteral; +import net.sourceforge.pmd.lang.java.ast.ASTPrimaryExpression; +import net.sourceforge.pmd.lang.java.ast.ASTPrimaryPrefix; +import net.sourceforge.pmd.lang.java.ast.ASTPrimarySuffix; +import net.sourceforge.pmd.lang.java.ast.JavaNode; +import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule; + +class AbstractPositionLiteralsFirstInComparisons extends AbstractJavaRule { + + private final String equalsImage; + + AbstractPositionLiteralsFirstInComparisons(String equalsImage) { + addRuleChainVisit(ASTPrimaryExpression.class); + this.equalsImage = equalsImage; + } + + @Override + public Object visit(ASTPrimaryExpression node, Object data) { + ASTPrimaryPrefix primaryPrefix = node.getFirstChildOfType(ASTPrimaryPrefix.class); + ASTPrimarySuffix primarySuffix = node.getFirstChildOfType(ASTPrimarySuffix.class); + if (primaryPrefix != null && primarySuffix != null) { + ASTName name = primaryPrefix.getFirstChildOfType(ASTName.class); + if (name == null || !name.getImage().endsWith(equalsImage)) { + return data; + } + if (!isSingleStringLiteralArgument(primarySuffix)) { + return data; + } + if (isWithinNullComparison(node)) { + return data; + } + addViolation(data, node); + } + return node; + } + + private boolean isWithinNullComparison(ASTPrimaryExpression node) { + for (ASTExpression parentExpr : node.getParentsOfType(ASTExpression.class)) { + if (isComparisonWithNull(parentExpr, "==", ASTConditionalOrExpression.class) + || isComparisonWithNull(parentExpr, "!=", ASTConditionalAndExpression.class)) { + return true; + } + } + return false; + } + + /* + * Expression/ConditionalAndExpression//EqualityExpression(@Image='!=']//NullLiteral + * Expression/ConditionalOrExpression//EqualityExpression(@Image='==']//NullLiteral + */ + private boolean isComparisonWithNull(ASTExpression parentExpr, String equalOperator, Class condition) { + Node condExpr = null; + ASTEqualityExpression eqExpr = null; + if (parentExpr != null) { + condExpr = parentExpr.getFirstChildOfType(condition); + } + if (condExpr != null) { + eqExpr = condExpr.getFirstDescendantOfType(ASTEqualityExpression.class); + } + if (eqExpr != null) { + return eqExpr.hasImageEqualTo(equalOperator) && eqExpr.hasDescendantOfType(ASTNullLiteral.class); + } + return false; + } + + /* + * This corresponds to the following XPath expression: + * (../PrimarySuffix/Arguments/ArgumentList/Expression/PrimaryExpression/PrimaryPrefix/Literal[@StringLiteral= true()]) + * and + * ( count(../PrimarySuffix/Arguments/ArgumentList/Expression) = 1 ) + */ + private boolean isSingleStringLiteralArgument(ASTPrimarySuffix primarySuffix) { + if (!primarySuffix.isArguments() || primarySuffix.getArgumentCount() != 1) { + return false; + } + Node node = primarySuffix; + node = node.getFirstChildOfType(ASTArguments.class); + if (node != null) { + node = node.getFirstChildOfType(ASTArgumentList.class); + if (node.getNumChildren() != 1) { + return false; + } + } + if (node != null) { + node = node.getFirstChildOfType(ASTExpression.class); + } + if (node != null) { + node = node.getFirstChildOfType(ASTPrimaryExpression.class); + } + if (node != null) { + node = node.getFirstChildOfType(ASTPrimaryPrefix.class); + } + if (node != null) { + node = node.getFirstChildOfType(ASTLiteral.class); + } + if (node != null) { + ASTLiteral literal = (ASTLiteral) node; + if (literal.isStringLiteral()) { + return true; + } + } + return false; + } +} diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/PositionLiteralsFirstInCaseInsensitiveComparisonsRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/PositionLiteralsFirstInCaseInsensitiveComparisonsRule.java new file mode 100644 index 0000000000..1c84769c01 --- /dev/null +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/PositionLiteralsFirstInCaseInsensitiveComparisonsRule.java @@ -0,0 +1,13 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.java.rule.bestpractices; + +public class PositionLiteralsFirstInCaseInsensitiveComparisonsRule extends AbstractPositionLiteralsFirstInComparisons { + + public PositionLiteralsFirstInCaseInsensitiveComparisonsRule() { + super(".equalsIgnoreCase"); + } + +} diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/PositionLiteralsFirstInComparisonsRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/PositionLiteralsFirstInComparisonsRule.java new file mode 100644 index 0000000000..2b9edd12c4 --- /dev/null +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/PositionLiteralsFirstInComparisonsRule.java @@ -0,0 +1,13 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.java.rule.bestpractices; + +public class PositionLiteralsFirstInComparisonsRule extends AbstractPositionLiteralsFirstInComparisons { + + public PositionLiteralsFirstInComparisonsRule() { + super(".equals"); + } + +} diff --git a/pmd-java/src/main/resources/category/java/bestpractices.xml b/pmd-java/src/main/resources/category/java/bestpractices.xml index aa0c9b6115..1087f49b67 100644 --- a/pmd-java/src/main/resources/category/java/bestpractices.xml +++ b/pmd-java/src/main/resources/category/java/bestpractices.xml @@ -1029,36 +1029,13 @@ String name, language="java" since="5.1" message="Position literals first in String comparisons for EqualsIgnoreCase" - class="net.sourceforge.pmd.lang.rule.XPathRule" + class="net.sourceforge.pmd.lang.java.rule.bestpractices.PositionLiteralsFirstInCaseInsensitiveComparisonsRule" externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_bestpractices.html#positionliteralsfirstincaseinsensitivecomparisons"> Position literals first in comparisons, if the second argument is null then NullPointerExceptions can be avoided, they will just return false. 3 - - - - - - - - Position literals first in comparisons, if the second argument is null then NullPointerExceptions can be avoided, they will just return false. 3 - - - - - - - - From 797a965c4b34a1e2454078b5b1c97f6a387cd552 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 17 Apr 2020 11:51:06 +0200 Subject: [PATCH 19/49] [java] Convert JUnitSpelling to Java rule --- .../rule/errorprone/JUnitSpellingRule.java | 28 +++++++++++++++++++ .../resources/category/java/errorprone.xml | 27 +----------------- 2 files changed, 29 insertions(+), 26 deletions(-) create mode 100644 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/JUnitSpellingRule.java diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/JUnitSpellingRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/JUnitSpellingRule.java new file mode 100644 index 0000000000..8fd2249133 --- /dev/null +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/JUnitSpellingRule.java @@ -0,0 +1,28 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + + +package net.sourceforge.pmd.lang.java.rule.errorprone; + +import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration; +import net.sourceforge.pmd.lang.java.rule.AbstractJUnitRule; + +public class JUnitSpellingRule extends AbstractJUnitRule { + + @Override + public Object visit(ASTMethodDeclaration node, Object data) { + if (node.getArity() != 0) { + return super.visit(node, data); + } + + String name = node.getName(); + if (!"setUp".equals(name) && "setup".equalsIgnoreCase(name)) { + addViolation(data, node); + } + if (!"tearDown".equals(name) && "teardown".equalsIgnoreCase(name)) { + addViolation(data, node); + } + return super.visit(node, data); + } +} diff --git a/pmd-java/src/main/resources/category/java/errorprone.xml b/pmd-java/src/main/resources/category/java/errorprone.xml index e0de33036d..755221f73e 100644 --- a/pmd-java/src/main/resources/category/java/errorprone.xml +++ b/pmd-java/src/main/resources/category/java/errorprone.xml @@ -2172,37 +2172,12 @@ public class JumbledIncrementerRule1 { language="java" since="1.0" message="You may have misspelled a JUnit framework method (setUp or tearDown)" - class="net.sourceforge.pmd.lang.rule.XPathRule" + class="net.sourceforge.pmd.lang.java.rule.errorprone.JUnitSpellingRule" externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#junitspelling"> Some JUnit framework methods are easy to misspell. 3 - - - - - - - - Date: Fri, 17 Apr 2020 12:01:27 +0200 Subject: [PATCH 20/49] [java] Convert AbstractClassWithoutAbstractMethod to Java rule --- ...bstractClassWithoutAbstractMethodRule.java | 50 +++++++++++++++++++ .../resources/category/java/bestpractices.xml | 16 +----- 2 files changed, 51 insertions(+), 15 deletions(-) create mode 100644 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AbstractClassWithoutAbstractMethodRule.java diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AbstractClassWithoutAbstractMethodRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AbstractClassWithoutAbstractMethodRule.java new file mode 100644 index 0000000000..3f20b559d5 --- /dev/null +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AbstractClassWithoutAbstractMethodRule.java @@ -0,0 +1,50 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + + +package net.sourceforge.pmd.lang.java.rule.bestpractices; + +import net.sourceforge.pmd.lang.java.ast.ASTAnyTypeBodyDeclaration; +import net.sourceforge.pmd.lang.java.ast.ASTAnyTypeBodyDeclaration.DeclarationKind; +import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration; +import net.sourceforge.pmd.lang.java.ast.ASTExtendsList; +import net.sourceforge.pmd.lang.java.ast.ASTImplementsList; +import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration; +import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule; + +public class AbstractClassWithoutAbstractMethodRule extends AbstractJavaRule { + + public AbstractClassWithoutAbstractMethodRule() { + addRuleChainVisit(ASTClassOrInterfaceDeclaration.class); + } + + @Override + public Object visit(ASTClassOrInterfaceDeclaration node, Object data) { + if (!node.isAbstract() || doesExtend(node) || doesImplement(node)) { + return data; + } + + int countOfAbstractMethods = 0; + for (ASTAnyTypeBodyDeclaration decl : node.getDeclarations()) { + if (decl.getKind() == DeclarationKind.METHOD) { + ASTMethodDeclaration methodDecl = (ASTMethodDeclaration) decl.getDeclarationNode(); + if (methodDecl.isAbstract()) { + countOfAbstractMethods++; + } + } + } + if (countOfAbstractMethods == 0) { + addViolation(data, node); + } + return data; + } + + private boolean doesExtend(ASTClassOrInterfaceDeclaration node) { + return node.getFirstChildOfType(ASTExtendsList.class) != null; + } + + private boolean doesImplement(ASTClassOrInterfaceDeclaration node) { + return node.getFirstChildOfType(ASTImplementsList.class) != null; + } +} diff --git a/pmd-java/src/main/resources/category/java/bestpractices.xml b/pmd-java/src/main/resources/category/java/bestpractices.xml index 1087f49b67..3264cd40a3 100644 --- a/pmd-java/src/main/resources/category/java/bestpractices.xml +++ b/pmd-java/src/main/resources/category/java/bestpractices.xml @@ -13,7 +13,7 @@ Rules which enforce generally accepted best practices. language="java" since="3.0" message="This abstract class does not have any abstract methods" - class="net.sourceforge.pmd.lang.rule.XPathRule" + class="net.sourceforge.pmd.lang.java.rule.bestpractices.AbstractClassWithoutAbstractMethodRule" externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_bestpractices.html#abstractclasswithoutabstractmethod"> The abstract class does not contain any abstract methods. An abstract class suggests @@ -22,20 +22,6 @@ abstract methods. If the class is intended to be used as a base class only (not directly) a protected constructor can be provided prevent direct instantiation. 3 - - - - - - - - Date: Fri, 17 Apr 2020 14:53:26 +0200 Subject: [PATCH 21/49] [java] UseCorrectExceptionLogging - fix problem with multiple loggers --- .../resources/category/java/errorprone.xml | 16 ++++--- .../xml/UseCorrectExceptionLogging.xml | 44 ++++++++++++------- 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/pmd-java/src/main/resources/category/java/errorprone.xml b/pmd-java/src/main/resources/category/java/errorprone.xml index 755221f73e..2b4d81319a 100644 --- a/pmd-java/src/main/resources/category/java/errorprone.xml +++ b/pmd-java/src/main/resources/category/java/errorprone.xml @@ -3380,12 +3380,16 @@ To make sure the full stacktrace is printed out, use the logging statement with diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/UseCorrectExceptionLogging.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/UseCorrectExceptionLogging.xml index cc94e27c55..6722f48456 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/UseCorrectExceptionLogging.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/UseCorrectExceptionLogging.xml @@ -3,10 +3,9 @@ xmlns="http://pmd.sourceforge.net/rule-tests" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pmd.sourceforge.net/rule-tests http://pmd.sourceforge.net/rule-tests_1_0_0.xsd"> + - + ok 0 + - + failure case - two calls 2 + - + must be in a catch block 0 + - + bug 1626232, the rule should not be confused by inner classes 0 + - + bug 1626232, should work with a static block 1 + + + XPath problem: A sequence of more than one item is not allowed as the first argument of concat() + 0 + + From de875c955a5c030e035e5a44b7919d369666a099 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 17 Apr 2020 15:21:58 +0200 Subject: [PATCH 22/49] [java] Convert JUnitStaticSuite to Java rule --- .../rule/errorprone/JUnitStaticSuiteRule.java | 24 ++++++++++++++++++ .../resources/category/java/errorprone.xml | 25 +------------------ 2 files changed, 25 insertions(+), 24 deletions(-) create mode 100644 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/JUnitStaticSuiteRule.java diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/JUnitStaticSuiteRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/JUnitStaticSuiteRule.java new file mode 100644 index 0000000000..de0f71ada6 --- /dev/null +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/JUnitStaticSuiteRule.java @@ -0,0 +1,24 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + + +package net.sourceforge.pmd.lang.java.rule.errorprone; + +import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration; +import net.sourceforge.pmd.lang.java.rule.AbstractJUnitRule; + +public class JUnitStaticSuiteRule extends AbstractJUnitRule { + + @Override + public Object visit(ASTMethodDeclaration node, Object data) { + if (node.getArity() != 0) { + return super.visit(node, data); + } + String name = node.getName(); + if ("suite".equals(name) && (!node.isStatic() || !node.isPublic())) { + addViolation(data, node); + } + return super.visit(node, data); + } +} diff --git a/pmd-java/src/main/resources/category/java/errorprone.xml b/pmd-java/src/main/resources/category/java/errorprone.xml index 2b4d81319a..d4268f7b1b 100644 --- a/pmd-java/src/main/resources/category/java/errorprone.xml +++ b/pmd-java/src/main/resources/category/java/errorprone.xml @@ -2194,36 +2194,13 @@ public class Foo extends TestCase { language="java" since="1.0" message="You have a suite() method that is not both public and static, so JUnit won't call it to get your TestSuite. Is that what you wanted to do?" - class="net.sourceforge.pmd.lang.rule.XPathRule" + class="net.sourceforge.pmd.lang.java.rule.errorprone.JUnitStaticSuiteRule" typeResolution="true" externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#junitstaticsuite"> The suite() method in a JUnit test needs to be both public and static. 3 - - - - - - - - Date: Fri, 17 Apr 2020 16:13:34 +0200 Subject: [PATCH 23/49] Add code of conduct Fixes #2357 --- README.md | 2 + code_of_conduct.md | 129 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 code_of_conduct.md diff --git a/README.md b/README.md index dbfbd7d9ca..e54a445913 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,8 @@ [![Maven Central](https://maven-badges.herokuapp.com/maven-central/net.sourceforge.pmd/pmd/badge.svg)](https://maven-badges.herokuapp.com/maven-central/net.sourceforge.pmd/pmd) [![Coverage Status](https://coveralls.io/repos/github/pmd/pmd/badge.svg)](https://coveralls.io/github/pmd/pmd) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/a674ee8642ed44c6ba7633626ee95967)](https://www.codacy.com/app/pmd/pmd?utm_source=github.com&utm_medium=referral&utm_content=pmd/pmd&utm_campaign=Badge_Grade) +[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg)](code_of_conduct.md) + ## About **PMD** is a source code analyzer. It finds common programming flaws like unused variables, empty catch blocks, diff --git a/code_of_conduct.md b/code_of_conduct.md new file mode 100644 index 0000000000..c1cf699e74 --- /dev/null +++ b/code_of_conduct.md @@ -0,0 +1,129 @@ + +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, religion, or sexual identity +and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the + overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series +of actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or +permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within +the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.0, available at +https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. + +Community Impact Guidelines were inspired by [Mozilla's code of conduct +enforcement ladder](https://github.com/mozilla/diversity). + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see the FAQ at +https://www.contributor-covenant.org/faq. Translations are available at +https://www.contributor-covenant.org/translations. From 83de15cc1e4ee5f6587d2ade858e20b1cc5f5658 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 17 Apr 2020 16:23:43 +0200 Subject: [PATCH 24/49] Update release notes --- docs/pages/release_notes.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 794293b75c..6bd1a105f4 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -14,6 +14,18 @@ This is a {{ site.pmd.release_type }} release. ### New and noteworthy +#### PMD adopts Contributor Code of Conduct + +To facilitate healthy and constructive community behavior PMD adopts +[Contributor Convenant](https://www.contributor-covenant.org/) as its code of +conduct. + +Please note that this project is released with a Contributor Code of Conduct. +By participating in this project you agree to abide by its terms. + +You can find the code of conduct in the file [code_of_conduct.md](https://github.com/pmd/pmd/blob/master/code_of_conduct.md) +in our repository. + #### Performance improvements for XPath 2.0 rules XPath rules written with XPath 2.0 now support conversion to a rulechain rule, which @@ -48,6 +60,7 @@ Note that XPath 1.0 support, the default XPath version, is deprecated since PMD * core * [#2355](https://github.com/pmd/pmd/issues/2355): \[doc] Improve documentation about incremental analysis * [#2356](https://github.com/pmd/pmd/issues/2356): \[doc] Add missing doc about pmd.github.io + * [#2357](https://github.com/pmd/pmd/issues/2357): Add code of conduct: Contributor Covenant * java * [#2378](https://github.com/pmd/pmd/issues/2378): \[java] AbstractJUnitRule has bad performance on large code bases * java-codestyle From 9629cacddd6a7bc78d5e85ab0ef74ba7a335ffde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Fri, 17 Apr 2020 16:30:37 +0200 Subject: [PATCH 25/49] Checstyle --- .../net/sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java index 146b7f3553..6db157eac4 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java @@ -250,9 +250,6 @@ public class ElementNode extends BaseNodeInfo { private final Iterator iter = getAttributes().values().iterator(); - public AttributeEnumeration() { - } - @Override public void advance() { if (iter.hasNext()) { From 2253f38ccb999430b70b4b14c47cd6eb2b1758f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Fri, 17 Apr 2020 17:10:16 +0200 Subject: [PATCH 26/49] don't use global namepool to avoid resource contention --- .../pmd/lang/rule/xpath/SaxonXPathRuleQuery.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/SaxonXPathRuleQuery.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/SaxonXPathRuleQuery.java index 856c4ed794..54cd8b6681 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/SaxonXPathRuleQuery.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/SaxonXPathRuleQuery.java @@ -66,7 +66,14 @@ public class SaxonXPathRuleQuery extends AbstractXPathRuleQuery { private static final Logger LOG = Logger.getLogger(SaxonXPathRuleQuery.class.getName()); - private static final NamePool NAME_POOL = NamePool.getDefaultNamePool(); + // Name pools are thread local to avoid contention + // (allocation *and* access are synchronized in this version of saxon) + private static final ThreadLocal NAME_POOL = new ThreadLocal() { + @Override + protected NamePool initialValue() { + return new NamePool(); + } + }; private static final int MAX_CACHE_SIZE = 20; private static final Map CACHE = new LinkedHashMap(MAX_CACHE_SIZE) { @@ -194,7 +201,7 @@ public class SaxonXPathRuleQuery extends AbstractXPathRuleQuery { synchronized (CACHE) { documentNode = CACHE.get(root); if (documentNode == null) { - documentNode = new DocumentNode(root, NAME_POOL); + documentNode = new DocumentNode(root, getNamePool()); CACHE.put(root, documentNode); } } @@ -232,7 +239,7 @@ public class SaxonXPathRuleQuery extends AbstractXPathRuleQuery { try { final XPathEvaluator xpathEvaluator = new XPathEvaluator(); final XPathStaticContext xpathStaticContext = xpathEvaluator.getStaticContext(); - xpathStaticContext.getConfiguration().setNamePool(NAME_POOL); + xpathStaticContext.getConfiguration().setNamePool(getNamePool()); // Enable XPath 1.0 compatibility if (XPATH_1_0_COMPATIBILITY.equals(version)) { @@ -360,6 +367,6 @@ public class SaxonXPathRuleQuery extends AbstractXPathRuleQuery { } public static NamePool getNamePool() { - return NAME_POOL; + return NAME_POOL.get(); } } From 97f0a8e866f27db8f812e993db788294b0fd4725 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 17 Apr 2020 18:02:34 +0200 Subject: [PATCH 27/49] Mention code of conduct in CONTRIBUTING.md --- CONTRIBUTING.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f86d7d2287..68b0cdc2ce 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,6 +2,10 @@ First off, thanks for taking the time to contribute! +Please note that this project is released with a Contributor Code of Conduct. +By participating in this project you agree to abide by its terms. + +You can find the code of conduct in the file [code_of_conduct.md](code_of_conduct.md). | NB: the rule designer is developed over at [pmd/pmd-designer](https://github.com/pmd/pmd-designer). Please refer to the specific [contributor documentation](https://github.com/pmd/pmd-designer#contributing) if your issue, feature request or PR touches the designer. | | --- | From 7a37be55db49865cac52b5c7aedadec50af8dcf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Fri, 17 Apr 2020 18:03:57 +0200 Subject: [PATCH 28/49] Revert "don't use global namepool to avoid resource contention" Actually benchmarking with different levels of parallelism shows that there is no contention, and that sharing the namepool is beneficial even with many threads. When the number of threads is very high, using independent namepools increases the amount of work to allocate names. This reverts commit 2253f38ccb999430b70b4b14c47cd6eb2b1758f7. --- .../pmd/lang/rule/xpath/SaxonXPathRuleQuery.java | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/SaxonXPathRuleQuery.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/SaxonXPathRuleQuery.java index 54cd8b6681..856c4ed794 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/SaxonXPathRuleQuery.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/SaxonXPathRuleQuery.java @@ -66,14 +66,7 @@ public class SaxonXPathRuleQuery extends AbstractXPathRuleQuery { private static final Logger LOG = Logger.getLogger(SaxonXPathRuleQuery.class.getName()); - // Name pools are thread local to avoid contention - // (allocation *and* access are synchronized in this version of saxon) - private static final ThreadLocal NAME_POOL = new ThreadLocal() { - @Override - protected NamePool initialValue() { - return new NamePool(); - } - }; + private static final NamePool NAME_POOL = NamePool.getDefaultNamePool(); private static final int MAX_CACHE_SIZE = 20; private static final Map CACHE = new LinkedHashMap(MAX_CACHE_SIZE) { @@ -201,7 +194,7 @@ public class SaxonXPathRuleQuery extends AbstractXPathRuleQuery { synchronized (CACHE) { documentNode = CACHE.get(root); if (documentNode == null) { - documentNode = new DocumentNode(root, getNamePool()); + documentNode = new DocumentNode(root, NAME_POOL); CACHE.put(root, documentNode); } } @@ -239,7 +232,7 @@ public class SaxonXPathRuleQuery extends AbstractXPathRuleQuery { try { final XPathEvaluator xpathEvaluator = new XPathEvaluator(); final XPathStaticContext xpathStaticContext = xpathEvaluator.getStaticContext(); - xpathStaticContext.getConfiguration().setNamePool(getNamePool()); + xpathStaticContext.getConfiguration().setNamePool(NAME_POOL); // Enable XPath 1.0 compatibility if (XPATH_1_0_COMPATIBILITY.equals(version)) { @@ -367,6 +360,6 @@ public class SaxonXPathRuleQuery extends AbstractXPathRuleQuery { } public static NamePool getNamePool() { - return NAME_POOL.get(); + return NAME_POOL; } } From 74200132e395a3e46c0de36a225e29b05e57e198 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 17 Apr 2020 18:43:56 +0200 Subject: [PATCH 29/49] [apex] Internalize AST constructors and helper implementations --- docs/pages/release_notes.md | 20 ++++++++++--------- .../pmd/lang/apex/ast/ASTAnnotation.java | 5 ++++- .../lang/apex/ast/ASTAnnotationParameter.java | 6 +++++- .../pmd/lang/apex/ast/ASTAnonymousClass.java | 6 +++++- .../lang/apex/ast/ASTArrayLoadExpression.java | 6 +++++- .../apex/ast/ASTArrayStoreExpression.java | 6 +++++- .../apex/ast/ASTAssignmentExpression.java | 6 +++++- .../lang/apex/ast/ASTBinaryExpression.java | 6 +++++- .../pmd/lang/apex/ast/ASTBindExpressions.java | 6 +++++- .../pmd/lang/apex/ast/ASTBlockStatement.java | 6 +++++- .../lang/apex/ast/ASTBooleanExpression.java | 6 +++++- .../pmd/lang/apex/ast/ASTBreakStatement.java | 6 +++++- .../lang/apex/ast/ASTBridgeMethodCreator.java | 6 +++++- .../pmd/lang/apex/ast/ASTCastExpression.java | 6 +++++- .../lang/apex/ast/ASTCatchBlockStatement.java | 6 +++++- .../lang/apex/ast/ASTClassRefExpression.java | 6 +++++- .../lang/apex/ast/ASTConstructorPreamble.java | 6 +++++- .../ast/ASTConstructorPreambleStatement.java | 6 +++++- .../lang/apex/ast/ASTContinueStatement.java | 6 +++++- .../lang/apex/ast/ASTDmlDeleteStatement.java | 6 +++++- .../lang/apex/ast/ASTDmlInsertStatement.java | 6 +++++- .../lang/apex/ast/ASTDmlMergeStatement.java | 6 +++++- .../apex/ast/ASTDmlUndeleteStatement.java | 6 +++++- .../lang/apex/ast/ASTDmlUpdateStatement.java | 6 +++++- .../lang/apex/ast/ASTDmlUpsertStatement.java | 6 +++++- .../pmd/lang/apex/ast/ASTDoLoopStatement.java | 6 +++++- .../pmd/lang/apex/ast/ASTExpression.java | 6 +++++- .../lang/apex/ast/ASTExpressionStatement.java | 6 +++++- .../pmd/lang/apex/ast/ASTField.java | 5 ++++- .../lang/apex/ast/ASTFieldDeclaration.java | 6 +++++- .../ast/ASTFieldDeclarationStatements.java | 5 ++++- .../lang/apex/ast/ASTForEachStatement.java | 6 +++++- .../lang/apex/ast/ASTForLoopStatement.java | 6 +++++- .../pmd/lang/apex/ast/ASTFormalComment.java | 5 ++++- .../lang/apex/ast/ASTIfBlockStatement.java | 6 +++++- .../apex/ast/ASTIfElseBlockStatement.java | 6 +++++- .../apex/ast/ASTIllegalStoreExpression.java | 6 +++++- .../apex/ast/ASTInstanceOfExpression.java | 6 +++++- .../apex/ast/ASTJavaMethodCallExpression.java | 6 +++++- .../apex/ast/ASTJavaVariableExpression.java | 6 +++++- .../lang/apex/ast/ASTLiteralExpression.java | 6 +++++- .../pmd/lang/apex/ast/ASTMapEntryNode.java | 6 +++++- .../pmd/lang/apex/ast/ASTMethod.java | 5 ++++- .../apex/ast/ASTMethodBlockStatement.java | 6 +++++- .../apex/ast/ASTMethodCallExpression.java | 6 +++++- .../pmd/lang/apex/ast/ASTModifier.java | 6 +++++- .../pmd/lang/apex/ast/ASTModifierNode.java | 6 +++++- .../apex/ast/ASTModifierOrAnnotation.java | 6 +++++- .../pmd/lang/apex/ast/ASTMultiStatement.java | 6 +++++- .../lang/apex/ast/ASTNestedExpression.java | 6 +++++- .../apex/ast/ASTNestedStoreExpression.java | 6 +++++- .../ast/ASTNewKeyValueObjectExpression.java | 6 +++++- .../apex/ast/ASTNewListInitExpression.java | 6 +++++- .../apex/ast/ASTNewListLiteralExpression.java | 6 +++++- .../apex/ast/ASTNewMapInitExpression.java | 6 +++++- .../apex/ast/ASTNewMapLiteralExpression.java | 6 +++++- .../lang/apex/ast/ASTNewObjectExpression.java | 6 +++++- .../apex/ast/ASTNewSetInitExpression.java | 6 +++++- .../apex/ast/ASTNewSetLiteralExpression.java | 6 +++++- .../apex/ast/ASTPackageVersionExpression.java | 6 +++++- .../pmd/lang/apex/ast/ASTParameter.java | 5 ++++- .../lang/apex/ast/ASTPostfixExpression.java | 6 +++++- .../lang/apex/ast/ASTPrefixExpression.java | 7 +++++-- .../pmd/lang/apex/ast/ASTProperty.java | 6 +++++- .../lang/apex/ast/ASTReferenceExpression.java | 6 +++++- .../pmd/lang/apex/ast/ASTReturnStatement.java | 6 +++++- .../lang/apex/ast/ASTRunAsBlockStatement.java | 6 +++++- .../pmd/lang/apex/ast/ASTSoqlExpression.java | 6 +++++- .../pmd/lang/apex/ast/ASTSoslExpression.java | 6 +++++- .../lang/apex/ast/ASTStandardCondition.java | 6 +++++- .../pmd/lang/apex/ast/ASTStatement.java | 6 +++++- .../lang/apex/ast/ASTStatementExecuted.java | 6 +++++- .../ast/ASTSuperMethodCallExpression.java | 6 +++++- .../apex/ast/ASTSuperVariableExpression.java | 6 +++++- .../lang/apex/ast/ASTTernaryExpression.java | 6 +++++- .../apex/ast/ASTThisMethodCallExpression.java | 6 +++++- .../apex/ast/ASTThisVariableExpression.java | 6 +++++- .../pmd/lang/apex/ast/ASTThrowStatement.java | 6 +++++- .../ast/ASTTriggerVariableExpression.java | 6 +++++- .../ast/ASTTryCatchFinallyBlockStatement.java | 6 +++++- .../pmd/lang/apex/ast/ASTUserClass.java | 5 ++++- .../lang/apex/ast/ASTUserClassMethods.java | 6 +++++- .../apex/ast/ASTUserClassOrInterface.java | 2 +- .../pmd/lang/apex/ast/ASTUserEnum.java | 6 +++++- .../apex/ast/ASTUserExceptionMethods.java | 6 +++++- .../pmd/lang/apex/ast/ASTUserInterface.java | 5 ++++- .../pmd/lang/apex/ast/ASTUserTrigger.java | 6 +++++- .../lang/apex/ast/ASTVariableDeclaration.java | 5 ++++- .../ast/ASTVariableDeclarationStatements.java | 6 +++++- .../lang/apex/ast/ASTVariableExpression.java | 6 +++++- .../lang/apex/ast/ASTWhileLoopStatement.java | 6 +++++- .../pmd/lang/apex/ast/AbstractApexNode.java | 4 +++- .../lang/apex/ast/AbstractApexNodeBase.java | 4 +++- .../pmd/lang/apex/ast/AccessNode.java | 2 +- .../pmd/lang/apex/ast/ApexNode.java | 6 +++++- .../pmd/lang/apex/ast/ApexParser.java | 2 +- .../pmd/lang/apex/ast/ApexParserVisitor.java | 2 +- .../apex/ast/ApexParserVisitorAdapter.java | 2 +- .../ast/ApexParserVisitorReducedAdapter.java | 2 +- .../lang/apex/ast/ApexQualifiableNode.java | 2 +- .../pmd/lang/apex/ast/ApexQualifiedName.java | 2 +- .../pmd/lang/apex/ast/ApexRootNode.java | 7 ++++++- .../pmd/lang/apex/ast/ApexTreeBuilder.java | 5 ++++- .../lang/apex/ast/CanSuppressWarnings.java | 2 +- .../pmd/lang/apex/ast/CompilerService.java | 6 +++++- .../lang/apex/ast/EmptySymbolProvider.java | 6 +++++- .../lang/apex/ast/TestAccessEvaluator.java | 6 +++++- .../lang/apex/ast/TestQueryValidators.java | 6 +++++- .../pmd/lang/apex/ast/TriggerUsage.java | 2 +- 109 files changed, 498 insertions(+), 118 deletions(-) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 320b997bb8..ed0e4d1b2a 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -80,7 +80,7 @@ You can identify them with the `@InternalApi` annotation. You'll also get a depr As part of the changes we'd like to do to AST classes for 7.0.0, we would like to hide some methods and constructors that rule writers should not have access to. -The following usages are now deprecated in the **Visualforce** and **PLSQL** ASTs: +The following usages are now deprecated in the **Apex**, **Visualforce** and **PLSQL** ASTs: * Manual instantiation of nodes. **Constructors of node classes are deprecated** and marked {% jdoc core::annotation.InternalApi %}. Nodes should only be obtained from the parser, @@ -101,6 +101,7 @@ The following usages are now deprecated in the **Visualforce** and **PLSQL** AST These deprecations are added to the following language modules in this release. Please look at the package documentation to find out the full list of deprecations. +* Apex: **{% jdoc_package apex::lang.apex.ast %}** * Visualforce: **{% jdoc_package visualforce::lang.vf.ast %}** * PL/SQL: **{% jdoc_package plsql::lang.plsql.ast %}** @@ -113,17 +114,18 @@ following languages: Outside of these packages, these changes also concern the following TokenManager implementations, and their corresponding Parser if it exists (in the same package): -* {% jdoc vm::lang.vm.VmTokenManager %} +* {% jdoc cpp::lang.cpp.CppTokenManager %} * {% jdoc java::lang.java.JavaTokenManager %} +* {% jdoc javascript::lang.ecmascript5.Ecmascript5TokenManager %} +* {% jdoc jsp::lang.jsp.JspTokenManager %} +* {% jdoc matlab::lang.matlab.MatlabTokenManager %} +* {% jdoc modelica::lang.modelica.ModelicaTokenManager %} +* {% jdoc objectivec::lang.objectivec.ObjectiveCTokenManager %} +* {% jdoc plsql::lang.plsql.PLSQLTokenManager %} * {% jdoc python::lang.python.PythonTokenManager %} * {% jdoc visualforce::lang.vf.VfTokenManager %} -* {% jdoc plsql::lang.plsql.PLSQLTokenManager %} -* {% jdoc jsp::lang.jsp.JspTokenManager %} -* {% jdoc modelica::lang.modelica.ModelicaTokenManager %} -* {% jdoc cpp::lang.cpp.CppTokenManager %} -* {% jdoc javascript::lang.ecmascript5.Ecmascript5TokenManager %} -* {% jdoc matlab::lang.matlab.MatlabTokenManager %} -* {% jdoc objectivec::lang.objectivec.ObjectiveCTokenManager %} +* {% jdoc vm::lang.vm.VmTokenManager %} + ##### For removal diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTAnnotation.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTAnnotation.java index 4297f536bf..3c702d517c 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTAnnotation.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTAnnotation.java @@ -1,4 +1,4 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ @@ -9,11 +9,14 @@ import java.util.Set; import java.util.TreeSet; import net.sourceforge.pmd.Rule; +import net.sourceforge.pmd.annotation.InternalApi; import apex.jorje.semantic.ast.modifier.Annotation; public class ASTAnnotation extends AbstractApexNode { + @Deprecated + @InternalApi public ASTAnnotation(Annotation annotation) { super(annotation); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTAnnotationParameter.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTAnnotationParameter.java index 43bbc8cada..9229ac1d0c 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTAnnotationParameter.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTAnnotationParameter.java @@ -1,14 +1,18 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.modifier.AnnotationParameter; public class ASTAnnotationParameter extends AbstractApexNode { public static final String SEE_ALL_DATA = "seeAllData"; + @Deprecated + @InternalApi public ASTAnnotationParameter(AnnotationParameter annotationParameter) { super(annotationParameter); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTAnonymousClass.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTAnonymousClass.java index 4f63c004b1..549c1c3057 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTAnonymousClass.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTAnonymousClass.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.compilation.AnonymousClass; public class ASTAnonymousClass extends ApexRootNode { + @Deprecated + @InternalApi public ASTAnonymousClass(AnonymousClass anonymousClass) { super(anonymousClass); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTArrayLoadExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTArrayLoadExpression.java index d5f938bb6e..6d97d4d0a4 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTArrayLoadExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTArrayLoadExpression.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.expression.ArrayLoadExpression; public class ASTArrayLoadExpression extends AbstractApexNode { + @Deprecated + @InternalApi public ASTArrayLoadExpression(ArrayLoadExpression arrayLoadExpression) { super(arrayLoadExpression); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTArrayStoreExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTArrayStoreExpression.java index 0585b121f2..112e6ed729 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTArrayStoreExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTArrayStoreExpression.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.expression.ArrayStoreExpression; public class ASTArrayStoreExpression extends AbstractApexNode { + @Deprecated + @InternalApi public ASTArrayStoreExpression(ArrayStoreExpression arrayStoreExpression) { super(arrayStoreExpression); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTAssignmentExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTAssignmentExpression.java index de3531be71..64db7c1687 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTAssignmentExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTAssignmentExpression.java @@ -1,14 +1,18 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.data.ast.AssignmentOp; import apex.jorje.semantic.ast.expression.AssignmentExpression; public class ASTAssignmentExpression extends AbstractApexNode { + @Deprecated + @InternalApi public ASTAssignmentExpression(AssignmentExpression assignmentExpression) { super(assignmentExpression); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTBinaryExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTBinaryExpression.java index e0db793c28..4c90defcbc 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTBinaryExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTBinaryExpression.java @@ -1,14 +1,18 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.data.ast.BinaryOp; import apex.jorje.semantic.ast.expression.BinaryExpression; public class ASTBinaryExpression extends AbstractApexNode { + @Deprecated + @InternalApi public ASTBinaryExpression(BinaryExpression binaryExpression) { super(binaryExpression); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTBindExpressions.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTBindExpressions.java index 7501f3ab8f..21e081da87 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTBindExpressions.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTBindExpressions.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.expression.BindExpressions; public class ASTBindExpressions extends AbstractApexNode { + @Deprecated + @InternalApi public ASTBindExpressions(BindExpressions bindExpressions) { super(bindExpressions); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTBlockStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTBlockStatement.java index ab16315554..edb175047a 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTBlockStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTBlockStatement.java @@ -1,14 +1,18 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.statement.BlockStatement; public class ASTBlockStatement extends AbstractApexNode { private boolean curlyBrace; + @Deprecated + @InternalApi public ASTBlockStatement(BlockStatement blockStatement) { super(blockStatement); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTBooleanExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTBooleanExpression.java index efd46f2a2b..c6ab8b415e 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTBooleanExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTBooleanExpression.java @@ -1,15 +1,19 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.data.ast.BooleanOp; import apex.jorje.semantic.ast.expression.BooleanExpression; public class ASTBooleanExpression extends AbstractApexNode { + @Deprecated + @InternalApi public ASTBooleanExpression(BooleanExpression booleanExpression) { super(booleanExpression); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTBreakStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTBreakStatement.java index 90b947d51b..726e94b662 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTBreakStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTBreakStatement.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.statement.BreakStatement; public class ASTBreakStatement extends AbstractApexNode { + @Deprecated + @InternalApi public ASTBreakStatement(BreakStatement breakStatement) { super(breakStatement); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTBridgeMethodCreator.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTBridgeMethodCreator.java index 29be1c20c0..94ec543685 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTBridgeMethodCreator.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTBridgeMethodCreator.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.member.bridge.BridgeMethodCreator; public class ASTBridgeMethodCreator extends AbstractApexNode { + @Deprecated + @InternalApi public ASTBridgeMethodCreator(BridgeMethodCreator bridgeMethodCreator) { super(bridgeMethodCreator); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTCastExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTCastExpression.java index 1a534a6eac..76fb720d67 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTCastExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTCastExpression.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.expression.CastExpression; public class ASTCastExpression extends AbstractApexNode { + @Deprecated + @InternalApi public ASTCastExpression(CastExpression node) { super(node); } 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 5c98af83f2..f547822f94 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 @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.statement.CatchBlockStatement; public class ASTCatchBlockStatement extends AbstractApexNode { + @Deprecated + @InternalApi public ASTCatchBlockStatement(CatchBlockStatement catchBlockStatement) { super(catchBlockStatement); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTClassRefExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTClassRefExpression.java index 92f4c5a51b..9ba400b634 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTClassRefExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTClassRefExpression.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.expression.ClassRefExpression; public class ASTClassRefExpression extends AbstractApexNode { + @Deprecated + @InternalApi public ASTClassRefExpression(ClassRefExpression classRefExpression) { super(classRefExpression); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTConstructorPreamble.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTConstructorPreamble.java index 3f532db8d6..0e546ae17c 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTConstructorPreamble.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTConstructorPreamble.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.compilation.ConstructorPreamble; public class ASTConstructorPreamble extends AbstractApexNode { + @Deprecated + @InternalApi public ASTConstructorPreamble(ConstructorPreamble node) { super(node); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTConstructorPreambleStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTConstructorPreambleStatement.java index e8613c2844..df6b61bb22 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTConstructorPreambleStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTConstructorPreambleStatement.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.statement.ConstructorPreambleStatement; public class ASTConstructorPreambleStatement extends AbstractApexNode { + @Deprecated + @InternalApi public ASTConstructorPreambleStatement(ConstructorPreambleStatement constructorPreambleStatement) { super(constructorPreambleStatement); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTContinueStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTContinueStatement.java index 9a5a80aeab..9a4a9a4bc2 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTContinueStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTContinueStatement.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.statement.ContinueStatement; public class ASTContinueStatement extends AbstractApexNode { + @Deprecated + @InternalApi public ASTContinueStatement(ContinueStatement continueStatement) { super(continueStatement); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlDeleteStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlDeleteStatement.java index d876498594..daaa487939 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlDeleteStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlDeleteStatement.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.statement.DmlDeleteStatement; public class ASTDmlDeleteStatement extends AbstractApexNode { + @Deprecated + @InternalApi public ASTDmlDeleteStatement(DmlDeleteStatement dmlDeleteStatement) { super(dmlDeleteStatement); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlInsertStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlInsertStatement.java index 2b818a94f4..6cd9727de2 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlInsertStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlInsertStatement.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.statement.DmlInsertStatement; public class ASTDmlInsertStatement extends AbstractApexNode { + @Deprecated + @InternalApi public ASTDmlInsertStatement(DmlInsertStatement dmlInsertStatement) { super(dmlInsertStatement); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlMergeStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlMergeStatement.java index 7e1bebb433..8ba9c05e5d 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlMergeStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlMergeStatement.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.statement.DmlMergeStatement; public class ASTDmlMergeStatement extends AbstractApexNode { + @Deprecated + @InternalApi public ASTDmlMergeStatement(DmlMergeStatement dmlMergeStatement) { super(dmlMergeStatement); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlUndeleteStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlUndeleteStatement.java index 6e91324bd7..b37f2935e4 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlUndeleteStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlUndeleteStatement.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.statement.DmlUndeleteStatement; public class ASTDmlUndeleteStatement extends AbstractApexNode { + @Deprecated + @InternalApi public ASTDmlUndeleteStatement(DmlUndeleteStatement dmlUndeleteStatement) { super(dmlUndeleteStatement); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlUpdateStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlUpdateStatement.java index 587a536542..729969b608 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlUpdateStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlUpdateStatement.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.statement.DmlUpdateStatement; public class ASTDmlUpdateStatement extends AbstractApexNode { + @Deprecated + @InternalApi public ASTDmlUpdateStatement(DmlUpdateStatement dmlUpdateStatement) { super(dmlUpdateStatement); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlUpsertStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlUpsertStatement.java index 8f7512ec31..2cd7d0305a 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlUpsertStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlUpsertStatement.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.statement.DmlUpsertStatement; public class ASTDmlUpsertStatement extends AbstractApexNode { + @Deprecated + @InternalApi public ASTDmlUpsertStatement(DmlUpsertStatement dmlUpsertStatement) { super(dmlUpsertStatement); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDoLoopStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDoLoopStatement.java index 6ac37c8bbe..33c2c2a361 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDoLoopStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDoLoopStatement.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.statement.DoLoopStatement; public class ASTDoLoopStatement extends AbstractApexNode { + @Deprecated + @InternalApi public ASTDoLoopStatement(DoLoopStatement doLoopStatement) { super(doLoopStatement); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTExpression.java index 690ae31f5a..fa0f011f89 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTExpression.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.expression.Expression; public class ASTExpression extends AbstractApexNode { + @Deprecated + @InternalApi public ASTExpression(Expression expression) { super(expression); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTExpressionStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTExpressionStatement.java index b913893a47..19a613a244 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTExpressionStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTExpressionStatement.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.statement.ExpressionStatement; public class ASTExpressionStatement extends AbstractApexNode { + @Deprecated + @InternalApi public ASTExpressionStatement(ExpressionStatement expressionStatement) { super(expressionStatement); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTField.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTField.java index 42b7375342..f0b2b7de1f 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTField.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTField.java @@ -1,15 +1,18 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; import net.sourceforge.pmd.Rule; +import net.sourceforge.pmd.annotation.InternalApi; import apex.jorje.semantic.ast.member.Field; public class ASTField extends AbstractApexNode implements CanSuppressWarnings { + @Deprecated + @InternalApi public ASTField(Field field) { super(field); } 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 7198442c65..34a63873d1 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 @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.statement.FieldDeclaration; public class ASTFieldDeclaration extends AbstractApexNode { + @Deprecated + @InternalApi public ASTFieldDeclaration(FieldDeclaration fieldDeclaration) { super(fieldDeclaration); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTFieldDeclarationStatements.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTFieldDeclarationStatements.java index 358b3fb733..e756923db5 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTFieldDeclarationStatements.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTFieldDeclarationStatements.java @@ -1,16 +1,19 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; import net.sourceforge.pmd.Rule; +import net.sourceforge.pmd.annotation.InternalApi; import apex.jorje.semantic.ast.statement.FieldDeclarationStatements; public class ASTFieldDeclarationStatements extends AbstractApexNode implements CanSuppressWarnings { + @Deprecated + @InternalApi public ASTFieldDeclarationStatements(FieldDeclarationStatements fieldDeclarationStatements) { super(fieldDeclarationStatements); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTForEachStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTForEachStatement.java index cfabdcab9f..14f701551c 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTForEachStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTForEachStatement.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.statement.ForEachStatement; public class ASTForEachStatement extends AbstractApexNode { + @Deprecated + @InternalApi public ASTForEachStatement(ForEachStatement forEachStatement) { super(forEachStatement); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTForLoopStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTForLoopStatement.java index 8fb8b9610f..8d164ba3f9 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTForLoopStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTForLoopStatement.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.statement.ForLoopStatement; public class ASTForLoopStatement extends AbstractApexNode { + @Deprecated + @InternalApi public ASTForLoopStatement(ForLoopStatement forLoopStatement) { super(forLoopStatement); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTFormalComment.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTFormalComment.java index d9ca521600..c2a9750bfc 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTFormalComment.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTFormalComment.java @@ -1,4 +1,4 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ @@ -7,6 +7,7 @@ package net.sourceforge.pmd.lang.apex.ast; import org.antlr.runtime.Token; +import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.apex.ast.ASTFormalComment.AstComment; import apex.jorje.data.Location; @@ -50,6 +51,8 @@ public class ASTFormalComment extends AbstractApexNode { } + @Deprecated + @InternalApi public static final class AstComment implements AstNode { private final Location loc; diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTIfBlockStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTIfBlockStatement.java index e2f633e6d2..7beca82eae 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTIfBlockStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTIfBlockStatement.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.statement.IfBlockStatement; public class ASTIfBlockStatement extends AbstractApexNode { + @Deprecated + @InternalApi public ASTIfBlockStatement(IfBlockStatement ifBlockStatement) { super(ifBlockStatement); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTIfElseBlockStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTIfElseBlockStatement.java index 92571c5cad..b4f29c69c9 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTIfElseBlockStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTIfElseBlockStatement.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.statement.IfElseBlockStatement; public class ASTIfElseBlockStatement extends AbstractApexNode { + @Deprecated + @InternalApi public ASTIfElseBlockStatement(IfElseBlockStatement ifElseBlockStatement) { super(ifElseBlockStatement); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTIllegalStoreExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTIllegalStoreExpression.java index 29f7017037..cb93c7a4ee 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTIllegalStoreExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTIllegalStoreExpression.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.expression.IllegalStoreExpression; public class ASTIllegalStoreExpression extends AbstractApexNode { + @Deprecated + @InternalApi public ASTIllegalStoreExpression(IllegalStoreExpression node) { super(node); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTInstanceOfExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTInstanceOfExpression.java index f1e94593cd..f06a8fe277 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTInstanceOfExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTInstanceOfExpression.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.expression.InstanceOfExpression; public class ASTInstanceOfExpression extends AbstractApexNode { + @Deprecated + @InternalApi public ASTInstanceOfExpression(InstanceOfExpression instanceOfExpression) { super(instanceOfExpression); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTJavaMethodCallExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTJavaMethodCallExpression.java index ba8c2b56f0..3ec75ab95d 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTJavaMethodCallExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTJavaMethodCallExpression.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.expression.JavaMethodCallExpression; public class ASTJavaMethodCallExpression extends AbstractApexNode { + @Deprecated + @InternalApi public ASTJavaMethodCallExpression(JavaMethodCallExpression javaMethodCallExpression) { super(javaMethodCallExpression); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTJavaVariableExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTJavaVariableExpression.java index 78c3f14e2d..a4a90e06b7 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTJavaVariableExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTJavaVariableExpression.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.expression.JavaVariableExpression; public class ASTJavaVariableExpression extends AbstractApexNode { + @Deprecated + @InternalApi public ASTJavaVariableExpression(JavaVariableExpression javaVariableExpression) { super(javaVariableExpression); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTLiteralExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTLiteralExpression.java index 23f6182e4b..18a8a7afbc 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTLiteralExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTLiteralExpression.java @@ -1,4 +1,4 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ @@ -7,6 +7,8 @@ package net.sourceforge.pmd.lang.apex.ast; import java.lang.reflect.Field; import java.util.Optional; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.data.Identifier; import apex.jorje.data.ast.LiteralType; import apex.jorje.semantic.ast.expression.LiteralExpression; @@ -15,6 +17,8 @@ import apex.jorje.semantic.ast.expression.NewKeyValueObjectExpression.NameValueP public class ASTLiteralExpression extends AbstractApexNode { + @Deprecated + @InternalApi public ASTLiteralExpression(LiteralExpression literalExpression) { super(literalExpression); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTMapEntryNode.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTMapEntryNode.java index e5518792af..4ca122784f 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTMapEntryNode.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTMapEntryNode.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.expression.MapEntryNode; public class ASTMapEntryNode extends AbstractApexNode { + @Deprecated + @InternalApi public ASTMapEntryNode(MapEntryNode mapEntryNode) { super(mapEntryNode); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTMethod.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTMethod.java index 61a8f9505d..0e76eb9e1c 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTMethod.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTMethod.java @@ -1,10 +1,11 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; import net.sourceforge.pmd.Rule; +import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.apex.metrics.signature.ApexOperationSignature; import net.sourceforge.pmd.lang.ast.SignedNode; @@ -13,6 +14,8 @@ import apex.jorje.semantic.ast.member.Method; public class ASTMethod extends AbstractApexNode implements ApexQualifiableNode, SignedNode, CanSuppressWarnings { + @Deprecated + @InternalApi public ASTMethod(Method method) { super(method); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTMethodBlockStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTMethodBlockStatement.java index 98459d4634..008e4c817a 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTMethodBlockStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTMethodBlockStatement.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.statement.MethodBlockStatement; public class ASTMethodBlockStatement extends AbstractApexNode { + @Deprecated + @InternalApi public ASTMethodBlockStatement(MethodBlockStatement node) { super(node); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTMethodCallExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTMethodCallExpression.java index 99bcd1a37f..739c8d9617 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTMethodCallExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTMethodCallExpression.java @@ -1,4 +1,4 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ @@ -6,11 +6,15 @@ package net.sourceforge.pmd.lang.apex.ast; import java.util.Iterator; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.data.Identifier; import apex.jorje.semantic.ast.expression.MethodCallExpression; public class ASTMethodCallExpression extends AbstractApexNode { + @Deprecated + @InternalApi public ASTMethodCallExpression(MethodCallExpression methodCallExpression) { super(methodCallExpression); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTModifier.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTModifier.java index bed065951a..ffa78f78fe 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTModifier.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTModifier.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.modifier.Modifier; public class ASTModifier extends AbstractApexNode { + @Deprecated + @InternalApi public ASTModifier(Modifier node) { super(node); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTModifierNode.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTModifierNode.java index 0fff8cab0b..59ce9ec6d3 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTModifierNode.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTModifierNode.java @@ -1,14 +1,18 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.modifier.ModifierNode; import apex.jorje.semantic.symbol.type.ModifierTypeInfos; public class ASTModifierNode extends AbstractApexNode implements AccessNode { + @Deprecated + @InternalApi public ASTModifierNode(ModifierNode modifierNode) { super(modifierNode); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTModifierOrAnnotation.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTModifierOrAnnotation.java index 56e200334d..73f1daac17 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTModifierOrAnnotation.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTModifierOrAnnotation.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.modifier.ModifierOrAnnotation; public class ASTModifierOrAnnotation extends AbstractApexNode { + @Deprecated + @InternalApi public ASTModifierOrAnnotation(ModifierOrAnnotation modifierOrAnnotation) { super(modifierOrAnnotation); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTMultiStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTMultiStatement.java index 2b5f7e1d0e..8269e4625f 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTMultiStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTMultiStatement.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.statement.MultiStatement; public class ASTMultiStatement extends AbstractApexNode { + @Deprecated + @InternalApi public ASTMultiStatement(MultiStatement node) { super(node); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNestedExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNestedExpression.java index 9042880702..da2ffbb30f 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNestedExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNestedExpression.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.expression.NestedExpression; public class ASTNestedExpression extends AbstractApexNode { + @Deprecated + @InternalApi public ASTNestedExpression(NestedExpression node) { super(node); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNestedStoreExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNestedStoreExpression.java index 22fc1c9f96..fa7390f268 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNestedStoreExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNestedStoreExpression.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.expression.NestedStoreExpression; public class ASTNestedStoreExpression extends AbstractApexNode { + @Deprecated + @InternalApi public ASTNestedStoreExpression(NestedStoreExpression node) { super(node); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNewKeyValueObjectExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNewKeyValueObjectExpression.java index 9ffa7b764e..f035763dc8 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNewKeyValueObjectExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNewKeyValueObjectExpression.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.expression.NewKeyValueObjectExpression; public class ASTNewKeyValueObjectExpression extends AbstractApexNode { + @Deprecated + @InternalApi public ASTNewKeyValueObjectExpression(NewKeyValueObjectExpression node) { super(node); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNewListInitExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNewListInitExpression.java index 7ee5f8ef5b..696fffe383 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNewListInitExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNewListInitExpression.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.expression.NewListInitExpression; public class ASTNewListInitExpression extends AbstractApexNode { + @Deprecated + @InternalApi public ASTNewListInitExpression(NewListInitExpression newListInitExpression) { super(newListInitExpression); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNewListLiteralExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNewListLiteralExpression.java index 35d2f73e81..fd7cf10b55 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNewListLiteralExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNewListLiteralExpression.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.expression.NewListLiteralExpression; public class ASTNewListLiteralExpression extends AbstractApexNode { + @Deprecated + @InternalApi public ASTNewListLiteralExpression(NewListLiteralExpression newListLiteralExpression) { super(newListLiteralExpression); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNewMapInitExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNewMapInitExpression.java index 3b3e7eaca1..63ddf8d54f 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNewMapInitExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNewMapInitExpression.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.expression.NewMapInitExpression; public class ASTNewMapInitExpression extends AbstractApexNode { + @Deprecated + @InternalApi public ASTNewMapInitExpression(NewMapInitExpression newMapInitExpression) { super(newMapInitExpression); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNewMapLiteralExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNewMapLiteralExpression.java index 77cac52fa0..36bac109f7 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNewMapLiteralExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNewMapLiteralExpression.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.expression.NewMapLiteralExpression; public class ASTNewMapLiteralExpression extends AbstractApexNode { + @Deprecated + @InternalApi public ASTNewMapLiteralExpression(NewMapLiteralExpression newMapLiteralExpression) { super(newMapLiteralExpression); } 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 63c6465538..71247eea83 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 @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.expression.NewObjectExpression; public class ASTNewObjectExpression extends AbstractApexNode { + @Deprecated + @InternalApi public ASTNewObjectExpression(NewObjectExpression newObjectExpression) { super(newObjectExpression); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNewSetInitExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNewSetInitExpression.java index 130a0603fd..5302e1fc42 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNewSetInitExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNewSetInitExpression.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.expression.NewSetInitExpression; public class ASTNewSetInitExpression extends AbstractApexNode { + @Deprecated + @InternalApi public ASTNewSetInitExpression(NewSetInitExpression newSetInitExpression) { super(newSetInitExpression); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNewSetLiteralExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNewSetLiteralExpression.java index 43517f85c6..b01d551a68 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNewSetLiteralExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTNewSetLiteralExpression.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.expression.NewSetLiteralExpression; public class ASTNewSetLiteralExpression extends AbstractApexNode { + @Deprecated + @InternalApi public ASTNewSetLiteralExpression(NewSetLiteralExpression newSetLiteralExpression) { super(newSetLiteralExpression); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTPackageVersionExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTPackageVersionExpression.java index 3313363370..2ddb588532 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTPackageVersionExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTPackageVersionExpression.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.expression.PackageVersionExpression; public class ASTPackageVersionExpression extends AbstractApexNode { + @Deprecated + @InternalApi public ASTPackageVersionExpression(PackageVersionExpression packageVersionExpression) { super(packageVersionExpression); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTParameter.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTParameter.java index 22c1924e65..54e7fbbebd 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTParameter.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTParameter.java @@ -1,15 +1,18 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; import net.sourceforge.pmd.Rule; +import net.sourceforge.pmd.annotation.InternalApi; import apex.jorje.semantic.ast.member.Parameter; public class ASTParameter extends AbstractApexNode implements CanSuppressWarnings { + @Deprecated + @InternalApi public ASTParameter(Parameter parameter) { super(parameter); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTPostfixExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTPostfixExpression.java index 5a760da8b2..5d3c288fbc 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTPostfixExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTPostfixExpression.java @@ -1,15 +1,19 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.data.ast.PostfixOp; import apex.jorje.semantic.ast.expression.PostfixExpression; public class ASTPostfixExpression extends AbstractApexNode { + @Deprecated + @InternalApi public ASTPostfixExpression(PostfixExpression postfixExpression) { super(postfixExpression); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTPrefixExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTPrefixExpression.java index 4dd4a20cde..c79fa8214f 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTPrefixExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTPrefixExpression.java @@ -1,14 +1,18 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.data.ast.PrefixOp; import apex.jorje.semantic.ast.expression.PrefixExpression; public class ASTPrefixExpression extends AbstractApexNode { + @Deprecated + @InternalApi public ASTPrefixExpression(PrefixExpression prefixExpression) { super(prefixExpression); } @@ -22,5 +26,4 @@ public class ASTPrefixExpression extends AbstractApexNode { public PrefixOp getOperator() { return node.getOp(); } - } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTProperty.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTProperty.java index f73ac2c761..415a4b73d2 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTProperty.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTProperty.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.member.Property; public class ASTProperty extends AbstractApexNode { + @Deprecated + @InternalApi public ASTProperty(Property property) { super(property); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTReferenceExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTReferenceExpression.java index 3d76d4f12e..64732b9f24 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTReferenceExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTReferenceExpression.java @@ -1,9 +1,11 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.expression.IdentifierContext; import apex.jorje.semantic.ast.expression.ReferenceExpression; import apex.jorje.semantic.ast.expression.ReferenceType; @@ -11,6 +13,8 @@ import apex.jorje.semantic.ast.expression.ReferenceType; public class ASTReferenceExpression extends AbstractApexNode { + @Deprecated + @InternalApi public ASTReferenceExpression(ReferenceExpression referenceExpression) { super(referenceExpression); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTReturnStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTReturnStatement.java index dfe345408e..327737875d 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTReturnStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTReturnStatement.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.statement.ReturnStatement; public class ASTReturnStatement extends AbstractApexNode { + @Deprecated + @InternalApi public ASTReturnStatement(ReturnStatement returnStatement) { super(returnStatement); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTRunAsBlockStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTRunAsBlockStatement.java index ff2b84eef4..d28a058fa0 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTRunAsBlockStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTRunAsBlockStatement.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.statement.RunAsBlockStatement; public class ASTRunAsBlockStatement extends AbstractApexNode { + @Deprecated + @InternalApi public ASTRunAsBlockStatement(RunAsBlockStatement runAsBlockStatement) { super(runAsBlockStatement); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTSoqlExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTSoqlExpression.java index 844789a8b8..7028ff0542 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTSoqlExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTSoqlExpression.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.expression.SoqlExpression; public class ASTSoqlExpression extends AbstractApexNode { + @Deprecated + @InternalApi public ASTSoqlExpression(SoqlExpression soqlExpression) { super(soqlExpression); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTSoslExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTSoslExpression.java index b773d346aa..8c18d396ef 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTSoslExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTSoslExpression.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.expression.SoslExpression; public class ASTSoslExpression extends AbstractApexNode { + @Deprecated + @InternalApi public ASTSoslExpression(SoslExpression soslExpression) { super(soslExpression); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTStandardCondition.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTStandardCondition.java index 9260962ef9..b79ca67745 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTStandardCondition.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTStandardCondition.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.condition.StandardCondition; public class ASTStandardCondition extends AbstractApexNode { + @Deprecated + @InternalApi public ASTStandardCondition(StandardCondition standardCondition) { super(standardCondition); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTStatement.java index 9fe6e7dd1c..e48abb09c5 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTStatement.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.statement.Statement; public class ASTStatement extends AbstractApexNode { + @Deprecated + @InternalApi public ASTStatement(Statement statement) { super(statement); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTStatementExecuted.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTStatementExecuted.java index 0e4b865065..914e3ccf64 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTStatementExecuted.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTStatementExecuted.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.statement.StatementExecuted; public class ASTStatementExecuted extends AbstractApexNode { + @Deprecated + @InternalApi public ASTStatementExecuted(StatementExecuted node) { super(node); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTSuperMethodCallExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTSuperMethodCallExpression.java index 1dfbd47f46..b9a212218d 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTSuperMethodCallExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTSuperMethodCallExpression.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.expression.SuperMethodCallExpression; public class ASTSuperMethodCallExpression extends AbstractApexNode { + @Deprecated + @InternalApi public ASTSuperMethodCallExpression(SuperMethodCallExpression superMethodCallExpression) { super(superMethodCallExpression); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTSuperVariableExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTSuperVariableExpression.java index 2b13cb7171..de53c55be1 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTSuperVariableExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTSuperVariableExpression.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.expression.SuperVariableExpression; public class ASTSuperVariableExpression extends AbstractApexNode { + @Deprecated + @InternalApi public ASTSuperVariableExpression(SuperVariableExpression superVariableExpression) { super(superVariableExpression); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTTernaryExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTTernaryExpression.java index 3aa5622d52..f1ae4308f1 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTTernaryExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTTernaryExpression.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.expression.TernaryExpression; public class ASTTernaryExpression extends AbstractApexNode { + @Deprecated + @InternalApi public ASTTernaryExpression(TernaryExpression ternaryExpression) { super(ternaryExpression); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTThisMethodCallExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTThisMethodCallExpression.java index b3f1194c2e..da3fd387bb 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTThisMethodCallExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTThisMethodCallExpression.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.expression.ThisMethodCallExpression; public class ASTThisMethodCallExpression extends AbstractApexNode { + @Deprecated + @InternalApi public ASTThisMethodCallExpression(ThisMethodCallExpression thisMethodCallExpression) { super(thisMethodCallExpression); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTThisVariableExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTThisVariableExpression.java index d28e79a949..45e195008b 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTThisVariableExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTThisVariableExpression.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.expression.ThisVariableExpression; public class ASTThisVariableExpression extends AbstractApexNode { + @Deprecated + @InternalApi public ASTThisVariableExpression(ThisVariableExpression thisVariableExpression) { super(thisVariableExpression); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTThrowStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTThrowStatement.java index 00c977f9ca..3473633cf6 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTThrowStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTThrowStatement.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.statement.ThrowStatement; public class ASTThrowStatement extends AbstractApexNode { + @Deprecated + @InternalApi public ASTThrowStatement(ThrowStatement throwStatement) { super(throwStatement); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTTriggerVariableExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTTriggerVariableExpression.java index 45260316cc..b1edad0a55 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTTriggerVariableExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTTriggerVariableExpression.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.expression.TriggerVariableExpression; public class ASTTriggerVariableExpression extends AbstractApexNode { + @Deprecated + @InternalApi public ASTTriggerVariableExpression(TriggerVariableExpression triggerVariableExpression) { super(triggerVariableExpression); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTTryCatchFinallyBlockStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTTryCatchFinallyBlockStatement.java index 07d8e8e83f..e2d81d20e1 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTTryCatchFinallyBlockStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTTryCatchFinallyBlockStatement.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.statement.TryCatchFinallyBlockStatement; public class ASTTryCatchFinallyBlockStatement extends AbstractApexNode { + @Deprecated + @InternalApi public ASTTryCatchFinallyBlockStatement(TryCatchFinallyBlockStatement tryCatchFinallyBlockStatement) { super(tryCatchFinallyBlockStatement); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserClass.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserClass.java index e84927e931..3c4591c633 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserClass.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserClass.java @@ -1,4 +1,4 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ @@ -8,6 +8,7 @@ import java.util.List; import java.util.stream.Collectors; import net.sourceforge.pmd.Rule; +import net.sourceforge.pmd.annotation.InternalApi; import apex.jorje.data.Identifier; import apex.jorje.data.ast.TypeRef; @@ -18,6 +19,8 @@ public class ASTUserClass extends ApexRootNode implements ASTUserClas private ApexQualifiedName qname; + @Deprecated + @InternalApi public ASTUserClass(UserClass userClass) { super(userClass); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserClassMethods.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserClassMethods.java index 0146a2d3c6..76cd5b07a7 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserClassMethods.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserClassMethods.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.compilation.UserClassMethods; public class ASTUserClassMethods extends AbstractApexNode { + @Deprecated + @InternalApi public ASTUserClassMethods(UserClassMethods userClassMethods) { super(userClassMethods); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserClassOrInterface.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserClassOrInterface.java index 467656d132..ba1004562a 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserClassOrInterface.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserClassOrInterface.java @@ -1,4 +1,4 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserEnum.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserEnum.java index 54e5034fdc..ccb0487fcd 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserEnum.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserEnum.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.compilation.UserEnum; public class ASTUserEnum extends ApexRootNode { + @Deprecated + @InternalApi public ASTUserEnum(UserEnum userEnum) { super(userEnum); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserExceptionMethods.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserExceptionMethods.java index 25306a1e5c..7e64a79f7c 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserExceptionMethods.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserExceptionMethods.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.compilation.UserExceptionMethods; public class ASTUserExceptionMethods extends AbstractApexNode { + @Deprecated + @InternalApi public ASTUserExceptionMethods(UserExceptionMethods userExceptionMethods) { super(userExceptionMethods); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserInterface.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserInterface.java index fa3d25a075..14b705e1b0 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserInterface.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserInterface.java @@ -1,4 +1,4 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ @@ -7,6 +7,7 @@ package net.sourceforge.pmd.lang.apex.ast; import java.util.stream.Collectors; import net.sourceforge.pmd.Rule; +import net.sourceforge.pmd.annotation.InternalApi; import apex.jorje.data.Identifier; import apex.jorje.data.ast.TypeRef; @@ -17,6 +18,8 @@ public class ASTUserInterface extends ApexRootNode implements AST private ApexQualifiedName qname; + @Deprecated + @InternalApi public ASTUserInterface(UserInterface userInterface) { super(userInterface); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserTrigger.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserTrigger.java index 001655fed6..d057801267 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserTrigger.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserTrigger.java @@ -1,4 +1,4 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ @@ -7,11 +7,15 @@ package net.sourceforge.pmd.lang.apex.ast; import java.util.List; import java.util.stream.Collectors; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.data.Identifier; import apex.jorje.semantic.ast.compilation.UserTrigger; public class ASTUserTrigger extends ApexRootNode { + @Deprecated + @InternalApi public ASTUserTrigger(UserTrigger userTrigger) { super(userTrigger); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTVariableDeclaration.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTVariableDeclaration.java index 9e105150a2..3e58f0a021 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTVariableDeclaration.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTVariableDeclaration.java @@ -1,15 +1,18 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; import net.sourceforge.pmd.Rule; +import net.sourceforge.pmd.annotation.InternalApi; import apex.jorje.semantic.ast.statement.VariableDeclaration; public class ASTVariableDeclaration extends AbstractApexNode implements CanSuppressWarnings { + @Deprecated + @InternalApi public ASTVariableDeclaration(VariableDeclaration variableDeclaration) { super(variableDeclaration); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTVariableDeclarationStatements.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTVariableDeclarationStatements.java index 77dbb33074..3d6ba600b4 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTVariableDeclarationStatements.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTVariableDeclarationStatements.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.statement.VariableDeclarationStatements; public class ASTVariableDeclarationStatements extends AbstractApexNode { + @Deprecated + @InternalApi public ASTVariableDeclarationStatements(VariableDeclarationStatements variableDeclarationStatements) { super(variableDeclarationStatements); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTVariableExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTVariableExpression.java index 146d2c0c0c..735c2839ce 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTVariableExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTVariableExpression.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.expression.VariableExpression; public class ASTVariableExpression extends AbstractApexNode { + @Deprecated + @InternalApi public ASTVariableExpression(VariableExpression variableExpression) { super(variableExpression); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTWhileLoopStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTWhileLoopStatement.java index f24d2854f8..0b2aa1c6bb 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTWhileLoopStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTWhileLoopStatement.java @@ -1,13 +1,17 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.statement.WhileLoopStatement; public class ASTWhileLoopStatement extends AbstractApexNode { + @Deprecated + @InternalApi public ASTWhileLoopStatement(WhileLoopStatement whileLoopStatement) { super(whileLoopStatement); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/AbstractApexNode.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/AbstractApexNode.java index 9fb1539229..730290a0ee 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/AbstractApexNode.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/AbstractApexNode.java @@ -1,4 +1,4 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ @@ -54,6 +54,8 @@ public abstract class AbstractApexNode extends AbstractApexNo // default implementation does nothing } + @Deprecated + @InternalApi @Override public T getNode() { return node; diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/AbstractApexNodeBase.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/AbstractApexNodeBase.java index c02a8a72c8..620d154409 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/AbstractApexNodeBase.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/AbstractApexNodeBase.java @@ -1,9 +1,10 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.ast.AbstractNode; import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.ast.SourceCodePositioner; @@ -12,6 +13,7 @@ import net.sourceforge.pmd.lang.ast.SourceCodePositioner; * @deprecated Use {@link ApexNode} */ @Deprecated +@InternalApi public abstract class AbstractApexNodeBase extends AbstractNode { public AbstractApexNodeBase(Class klass) { diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/AccessNode.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/AccessNode.java index e3016d3b86..2255a734b3 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/AccessNode.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/AccessNode.java @@ -1,4 +1,4 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexNode.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexNode.java index c7889f6beb..f30bc61240 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexNode.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexNode.java @@ -1,4 +1,4 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ @@ -35,7 +35,11 @@ public interface ApexNode extends Node { /** * Get the underlying AST node. + * @deprecated the underlying AST node should not be available outside of the AST node. + * If information is needed from the underlying node, then PMD's AST node need to expose + * this information. */ + @Deprecated T getNode(); diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexParser.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexParser.java index 5bec6fbace..798c330966 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexParser.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexParser.java @@ -1,4 +1,4 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexParserVisitor.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexParserVisitor.java index cb6497ce7d..bda42b7e8c 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexParserVisitor.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexParserVisitor.java @@ -1,4 +1,4 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexParserVisitorAdapter.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexParserVisitorAdapter.java index 3a58a233f1..45218ccd21 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexParserVisitorAdapter.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexParserVisitorAdapter.java @@ -1,4 +1,4 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexParserVisitorReducedAdapter.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexParserVisitorReducedAdapter.java index f989a95bde..1a55a5f148 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexParserVisitorReducedAdapter.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexParserVisitorReducedAdapter.java @@ -1,4 +1,4 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexQualifiableNode.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexQualifiableNode.java index 13cfb51347..b7bd43667b 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexQualifiableNode.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexQualifiableNode.java @@ -1,4 +1,4 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexQualifiedName.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexQualifiedName.java index 0757b833f6..8fd38b45a6 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexQualifiedName.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexQualifiedName.java @@ -1,4 +1,4 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexRootNode.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexRootNode.java index f2a0fcfa40..333d6963ad 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexRootNode.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexRootNode.java @@ -1,16 +1,21 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.ast.RootNode; import net.sourceforge.pmd.lang.ast.SourceCodePositioner; import apex.jorje.semantic.ast.AstNode; import apex.jorje.services.Version; +@Deprecated +@InternalApi public abstract class ApexRootNode extends AbstractApexNode implements RootNode { + @Deprecated + @InternalApi public ApexRootNode(T node) { super(node); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexTreeBuilder.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexTreeBuilder.java index 40e1577601..648644b743 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexTreeBuilder.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexTreeBuilder.java @@ -1,4 +1,4 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ @@ -15,6 +15,7 @@ import java.util.Stack; import org.antlr.runtime.ANTLRStringStream; import org.antlr.runtime.Token; +import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.apex.ApexParserOptions; import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.ast.SourceCodePositioner; @@ -122,6 +123,8 @@ import apex.jorje.semantic.ast.visitor.AdditionalPassScope; import apex.jorje.semantic.ast.visitor.AstVisitor; import apex.jorje.semantic.exception.Errors; +@Deprecated +@InternalApi public final class ApexTreeBuilder extends AstVisitor { private static final Map, Constructor>> diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/CanSuppressWarnings.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/CanSuppressWarnings.java index 0aa0b9ba84..0792cacce6 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/CanSuppressWarnings.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/CanSuppressWarnings.java @@ -1,4 +1,4 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/CompilerService.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/CompilerService.java index 5b62b786b4..3fa0de818b 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/CompilerService.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/CompilerService.java @@ -1,4 +1,4 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ @@ -11,6 +11,8 @@ import java.util.stream.Collectors; import org.apache.commons.lang3.reflect.FieldUtils; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.visitor.AdditionalPassScope; import apex.jorje.semantic.ast.visitor.AstVisitor; import apex.jorje.semantic.compiler.ApexCompiler; @@ -36,6 +38,8 @@ import com.google.common.collect.ImmutableList; * @author nchen * */ +@Deprecated +@InternalApi public class CompilerService { public static final CompilerService INSTANCE = new CompilerService(); private final SymbolProvider symbolProvider; diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/EmptySymbolProvider.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/EmptySymbolProvider.java index 3a01f8925b..1f09b977f4 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/EmptySymbolProvider.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/EmptySymbolProvider.java @@ -1,4 +1,4 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ // Note: taken from https://github.com/forcedotcom/idecore/blob/3083815933c2d015d03417986f57bd25786d58ce/com.salesforce.ide.apex.core/src/com/salesforce/ide/apex/internal/core/EmptySymbolProvider.java @@ -21,6 +21,8 @@ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.compiler.Namespace; import apex.jorje.semantic.compiler.sfdc.SymbolProvider; import apex.jorje.semantic.symbol.resolver.SymbolResolver; @@ -29,6 +31,8 @@ import apex.jorje.semantic.symbol.type.TypeInfo; /** * @author jspagnola */ +@Deprecated +@InternalApi public final class EmptySymbolProvider implements SymbolProvider { private static final EmptySymbolProvider INSTANCE = new EmptySymbolProvider(); diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/TestAccessEvaluator.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/TestAccessEvaluator.java index 9e22af4e7b..48e62d76fc 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/TestAccessEvaluator.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/TestAccessEvaluator.java @@ -1,4 +1,4 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ // Note: taken from https://github.com/forcedotcom/idecore/blob/3083815933c2d015d03417986f57bd25786d58ce/com.salesforce.ide.apex.core/src/apex/jorje/semantic/common/TestAccessEvaluator.java @@ -26,6 +26,8 @@ import java.util.HashSet; import java.util.Objects; import java.util.Set; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.compiler.Namespace; import apex.jorje.semantic.compiler.StructuredVersion; import apex.jorje.semantic.compiler.sfdc.AccessEvaluator; @@ -45,6 +47,8 @@ import com.google.common.collect.SetMultimap; * * @author jspagnola */ +@Deprecated +@InternalApi public class TestAccessEvaluator implements AccessEvaluator { private final SetMultimap validPageVersions; diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/TestQueryValidators.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/TestQueryValidators.java index 5396c5bb34..3d62ce3a33 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/TestQueryValidators.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/TestQueryValidators.java @@ -1,4 +1,4 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ // Note: taken from https://github.com/forcedotcom/idecore/blob/3083815933c2d015d03417986f57bd25786d58ce/com.salesforce.ide.apex.core/src/apex/jorje/semantic/common/TestQueryValidators.java @@ -22,6 +22,8 @@ package net.sourceforge.pmd.lang.apex.ast; +import net.sourceforge.pmd.annotation.InternalApi; + import apex.jorje.semantic.ast.expression.SoqlExpression; import apex.jorje.semantic.ast.expression.SoslExpression; import apex.jorje.semantic.ast.visitor.ValidationScope; @@ -35,6 +37,8 @@ import apex.jorje.semantic.symbol.resolver.SymbolResolver; * @author jspagnola */ @SuppressWarnings("PMD.MissingStaticMethodInNonInstantiatableClass") // this class provides utility classes +@Deprecated +@InternalApi public final class TestQueryValidators { private TestQueryValidators() { diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/TriggerUsage.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/TriggerUsage.java index 55352bc032..c64dfe54a4 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/TriggerUsage.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/TriggerUsage.java @@ -1,4 +1,4 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ From 798cce1666da6ec947ecda813f1600ec53f6248e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Fri, 17 Apr 2020 19:59:01 +0200 Subject: [PATCH 30/49] Dont use global tree cache --- .../lang/rule/xpath/SaxonXPathRuleQuery.java | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/SaxonXPathRuleQuery.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/SaxonXPathRuleQuery.java index 856c4ed794..431fc86a79 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/SaxonXPathRuleQuery.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/SaxonXPathRuleQuery.java @@ -7,7 +7,6 @@ package net.sourceforge.pmd.lang.rule.xpath; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -23,6 +22,9 @@ import net.sourceforge.pmd.lang.ast.xpath.saxon.ElementNode; import net.sourceforge.pmd.lang.rule.xpath.internal.RuleChainAnalyzer; import net.sourceforge.pmd.lang.xpath.Initializer; import net.sourceforge.pmd.properties.PropertyDescriptor; +import net.sourceforge.pmd.util.DataMap; +import net.sourceforge.pmd.util.DataMap.DataKey; +import net.sourceforge.pmd.util.DataMap.SimpleDataKey; import net.sf.saxon.expr.Expression; import net.sf.saxon.om.Item; @@ -68,15 +70,9 @@ public class SaxonXPathRuleQuery extends AbstractXPathRuleQuery { private static final NamePool NAME_POOL = NamePool.getDefaultNamePool(); - private static final int MAX_CACHE_SIZE = 20; - private static final Map CACHE = new LinkedHashMap(MAX_CACHE_SIZE) { - private static final long serialVersionUID = -7653916493967142443L; + /** Cache key for the wrapped tree for saxon. */ + private static final SimpleDataKey SAXON_TREE_CACHE_KEY = DataMap.simpleDataKey("saxon.tree"); - @Override - protected boolean removeEldestEntry(final Map.Entry eldest) { - return size() > MAX_CACHE_SIZE; - } - }; /** * Contains for each nodeName a sub expression, used for implementing rule chain. @@ -190,15 +186,13 @@ public class SaxonXPathRuleQuery extends AbstractXPathRuleQuery { private DocumentNode getDocumentNodeForRootNode(final Node node) { final Node root = getRootNode(node); - DocumentNode documentNode; - synchronized (CACHE) { - documentNode = CACHE.get(root); - if (documentNode == null) { - documentNode = new DocumentNode(root, NAME_POOL); - CACHE.put(root, documentNode); - } + DataMap> userMap = root.getUserMap(); + DocumentNode docNode = userMap.get(SAXON_TREE_CACHE_KEY); + if (docNode == null) { + docNode = new DocumentNode(root, getNamePool()); + userMap.set(SAXON_TREE_CACHE_KEY, docNode); } - return documentNode; + return docNode; } /** From 48294ae66839810d221a809fd32fb7a0c46b6285 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Fri, 17 Apr 2020 20:03:39 +0200 Subject: [PATCH 31/49] Cleanup --- .../pmd/lang/rule/xpath/SaxonXPathRuleQuery.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/SaxonXPathRuleQuery.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/SaxonXPathRuleQuery.java index 431fc86a79..9e8b976732 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/SaxonXPathRuleQuery.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/SaxonXPathRuleQuery.java @@ -68,7 +68,7 @@ public class SaxonXPathRuleQuery extends AbstractXPathRuleQuery { private static final Logger LOG = Logger.getLogger(SaxonXPathRuleQuery.class.getName()); - private static final NamePool NAME_POOL = NamePool.getDefaultNamePool(); + private static final NamePool NAME_POOL = new NamePool(); /** Cache key for the wrapped tree for saxon. */ private static final SimpleDataKey SAXON_TREE_CACHE_KEY = DataMap.simpleDataKey("saxon.tree"); @@ -226,14 +226,14 @@ public class SaxonXPathRuleQuery extends AbstractXPathRuleQuery { try { final XPathEvaluator xpathEvaluator = new XPathEvaluator(); final XPathStaticContext xpathStaticContext = xpathEvaluator.getStaticContext(); - xpathStaticContext.getConfiguration().setNamePool(NAME_POOL); + xpathStaticContext.getConfiguration().setNamePool(getNamePool()); // Enable XPath 1.0 compatibility if (XPATH_1_0_COMPATIBILITY.equals(version)) { ((AbstractStaticContext) xpathStaticContext).setBackwardsCompatibilityMode(true); } - ((IndependentContext) xpathEvaluator.getStaticContext()).declareNamespace("fn", NamespaceConstant.FN); + ((IndependentContext) xpathStaticContext).declareNamespace("fn", NamespaceConstant.FN); // Register PMD functions Initializer.initialize((IndependentContext) xpathStaticContext); From 9dca569cc4efd99bca4165f1d6beb16df5467f05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Fri, 17 Apr 2020 00:10:12 +0200 Subject: [PATCH 32/49] Make deprecation warnings for xpath rules mention the name of the rule Fix #2019 --- .../sourceforge/pmd/lang/XPathHandler.java | 3 +- .../pmd/lang/ast/xpath/Attribute.java | 24 +---- .../internal/ContextualizedNavigator.java | 26 ++++++ .../xpath/internal/DeprecatedAttrLogger.java | 87 ++++++++++++++++++ .../lang/ast/xpath/saxon/AttributeNode.java | 13 +++ .../lang/ast/xpath/saxon/DocumentNode.java | 11 +++ .../sourceforge/pmd/lang/rule/XPathRule.java | 17 +++- .../lang/rule/xpath/JaxenXPathRuleQuery.java | 23 ++++- .../lang/rule/xpath/SaxonXPathRuleQuery.java | 15 ++- .../sourceforge/pmd/lang/ast/DummyNode.java | 15 +++ .../ast/xpath/AttributeAxisIteratorTest.java | 34 +------ .../pmd/lang/rule/XPathRuleTest.java | 92 ++++++++++++++++++- 12 files changed, 295 insertions(+), 65 deletions(-) create mode 100644 pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/internal/ContextualizedNavigator.java create mode 100644 pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/internal/DeprecatedAttrLogger.java diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/XPathHandler.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/XPathHandler.java index 2895550346..ebdf801d80 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/XPathHandler.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/XPathHandler.java @@ -38,7 +38,8 @@ public interface XPathHandler { * Get a Jaxen Navigator for this Language. May return null if * there is no Jaxen Navigation for this language. * - * @deprecated Support for Jaxen will be removed come 7.0.0 + * @deprecated Support for Jaxen will be removed come 7.0.0. This isn't used + * anymore */ @Deprecated Navigator getNavigator(); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/Attribute.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/Attribute.java index cee0734a9c..a1259b816d 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/Attribute.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/Attribute.java @@ -9,10 +9,6 @@ import java.lang.reflect.Method; import java.util.Collections; import java.util.List; import java.util.Objects; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.logging.Level; -import java.util.logging.Logger; import net.sourceforge.pmd.annotation.Experimental; import net.sourceforge.pmd.lang.ast.Node; @@ -29,11 +25,6 @@ import net.sourceforge.pmd.lang.ast.xpath.internal.DeprecatedAttribute; * @author daniels */ public class Attribute { - - - private static final Logger LOG = Logger.getLogger(Attribute.class.getName()); - static final ConcurrentMap DETECTED_DEPRECATED_ATTRIBUTES = new ConcurrentHashMap<>(); - private static final Object[] EMPTY_OBJ_ARRAY = new Object[0]; private final Node parent; @@ -73,9 +64,9 @@ public class Attribute { return method == null ? String.class : method.getReturnType(); } - private boolean isAttributeDeprecated() { + public boolean isAttributeDeprecated() { return method != null && (method.isAnnotationPresent(Deprecated.class) - || method.isAnnotationPresent(DeprecatedAttribute.class)); + || method.isAnnotationPresent(DeprecatedAttribute.class)); } public Object getValue() { @@ -83,12 +74,6 @@ public class Attribute { return value.get(0); } - if (LOG.isLoggable(Level.WARNING) && isAttributeDeprecated() - && DETECTED_DEPRECATED_ATTRIBUTES.putIfAbsent(getLoggableAttributeName(), Boolean.TRUE) == null) { - // this message needs to be kept in sync with PMDCoverageTest / BinaryDistributionIT - LOG.warning("Use of deprecated attribute '" + getLoggableAttributeName() + "' in XPath query"); - } - // this lazy loading reduces calls to Method.invoke() by about 90% try { value = Collections.singletonList(method.invoke(parent, EMPTY_OBJ_ARRAY)); @@ -129,11 +114,6 @@ public class Attribute { return Objects.hash(parent, name); } - - private String getLoggableAttributeName() { - return parent.getXPathNodeName() + "/@" + name; - } - @Override public String toString() { return name + ':' + getValue() + ':' + parent.getXPathNodeName(); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/internal/ContextualizedNavigator.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/internal/ContextualizedNavigator.java new file mode 100644 index 0000000000..f48dc03031 --- /dev/null +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/internal/ContextualizedNavigator.java @@ -0,0 +1,26 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ +package net.sourceforge.pmd.lang.ast.xpath.internal; + +import net.sourceforge.pmd.lang.ast.xpath.Attribute; +import net.sourceforge.pmd.lang.ast.xpath.DocumentNavigator; + +/** + * Navigator that records attribute usages. + */ +public class ContextualizedNavigator extends DocumentNavigator { + + private final DeprecatedAttrLogger ctx; + + public ContextualizedNavigator(DeprecatedAttrLogger ctx) { + this.ctx = ctx; + } + + @Override + public String getAttributeStringValue(Object arg0) { + Attribute attr = (Attribute) arg0; + ctx.recordUsageOf(attr); + return attr.getStringValue(); + } +} diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/internal/DeprecatedAttrLogger.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/internal/DeprecatedAttrLogger.java new file mode 100644 index 0000000000..3dd180f211 --- /dev/null +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/internal/DeprecatedAttrLogger.java @@ -0,0 +1,87 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.ast.xpath.internal; + +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.logging.Level; +import java.util.logging.Logger; + +import net.sourceforge.pmd.lang.ast.xpath.Attribute; +import net.sourceforge.pmd.lang.rule.XPathRule; + +/** + * Records usages of deprecated attributes in XPath rules. This needs + * to be threadsafe, XPath rules have one each (and share it). + */ +public abstract class DeprecatedAttrLogger { + + private static final Logger LOG = Logger.getLogger(Attribute.class.getName()); + + + public abstract void recordUsageOf(Attribute attribute); + + /** + * Create a new context for the given rule, returns a noop implementation + * if the warnings would be ignored anyway. + */ + public static DeprecatedAttrLogger create(XPathRule rule) { + if (LOG.isLoggable(Level.WARNING)) { + return new AttrLoggerImpl(rule); + } else { + return noop(); + } + } + + public static Noop noop() { + return Noop.INSTANCE; + } + + private static String getLoggableAttributeName(Attribute attr) { + return attr.getParent().getXPathNodeName() + "/@" + attr.getName(); + } + + private static class Noop extends DeprecatedAttrLogger { + + static final Noop INSTANCE = new Noop(); + + @Override + public void recordUsageOf(Attribute attribute) { + // do nothing + } + } + + private static class AttrLoggerImpl extends DeprecatedAttrLogger { + + private final ConcurrentMap deprecated = new ConcurrentHashMap<>(); + private final XPathRule rule; + + private AttrLoggerImpl(XPathRule rule) { + this.rule = rule; + } + + @Override + public void recordUsageOf(Attribute attribute) { + if (attribute.isAttributeDeprecated()) { + String name = getLoggableAttributeName(attribute); + Boolean b = deprecated.putIfAbsent(name, Boolean.TRUE); + if (b == null) { + // this message needs to be kept in sync with PMDCoverageTest / BinaryDistributionIT + LOG.warning("Use of deprecated attribute '" + name + "' by rule " + ruleToString()); + } + } + } + + public String ruleToString() { + // we can't compute that beforehand because the name is set + // outside of the rule constructor + String name = rule.getName(); + if (rule.getRuleSetName() != null) { + name = rule.getRuleSetName() + "/" + name; + } + return name; + } + } +} diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/AttributeNode.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/AttributeNode.java index 79dc9273cf..9da1b6753c 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/AttributeNode.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/AttributeNode.java @@ -8,6 +8,7 @@ import java.util.List; import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.ast.xpath.Attribute; +import net.sourceforge.pmd.lang.ast.xpath.internal.DeprecatedAttrLogger; import net.sourceforge.pmd.lang.rule.xpath.SaxonXPathRuleQuery; import net.sf.saxon.om.NodeInfo; @@ -47,8 +48,19 @@ public class AttributeNode extends BaseNodeInfo { return attribute.getName(); } + private DeprecatedAttrLogger getAttrCtx() { + return parent == null ? DeprecatedAttrLogger.noop() + : parent.document.getAttrCtx(); + } + + @Override + public ElementNode getParent() { + return parent; + } + @Override public Value atomize() { + getAttrCtx().recordUsageOf(attribute); if (value == null) { Object data = attribute.getValue(); if (data instanceof List) { @@ -72,6 +84,7 @@ public class AttributeNode extends BaseNodeInfo { @Override public int compareOrder(NodeInfo other) { + return Integer.signum(this.id - ((AttributeNode) other).id); } } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/DocumentNode.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/DocumentNode.java index 1a9213c826..d91f1828a6 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/DocumentNode.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/DocumentNode.java @@ -10,6 +10,7 @@ import java.util.Map; import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.ast.Node; +import net.sourceforge.pmd.lang.ast.xpath.internal.DeprecatedAttrLogger; import net.sourceforge.pmd.lang.rule.xpath.SaxonXPathRuleQuery; import net.sf.saxon.om.Axis; @@ -38,6 +39,8 @@ public class DocumentNode extends BaseNodeInfo implements DocumentInfo { */ public final Map nodeToElementNode = new HashMap<>(); + private DeprecatedAttrLogger attrCtx; + /** * Construct a DocumentNode, with the given AST Node serving as the root * ElementNode. @@ -95,4 +98,12 @@ public class DocumentNode extends BaseNodeInfo implements DocumentInfo { return super.iterateAxis(axisNumber); } } + + public DeprecatedAttrLogger getAttrCtx() { + return attrCtx == null ? DeprecatedAttrLogger.noop() : attrCtx; + } + + public void setAttrCtx(DeprecatedAttrLogger attrCtx) { + this.attrCtx = attrCtx; + } } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/XPathRule.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/XPathRule.java index d2c438a6df..0f91715bcc 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/XPathRule.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/XPathRule.java @@ -16,8 +16,10 @@ import java.util.Objects; import org.apache.commons.lang3.StringUtils; +import net.sourceforge.pmd.Rule; import net.sourceforge.pmd.RuleContext; import net.sourceforge.pmd.lang.ast.Node; +import net.sourceforge.pmd.lang.ast.xpath.internal.DeprecatedAttrLogger; import net.sourceforge.pmd.lang.rule.xpath.JaxenXPathRuleQuery; import net.sourceforge.pmd.lang.rule.xpath.SaxonXPathRuleQuery; import net.sourceforge.pmd.lang.rule.xpath.XPathRuleQuery; @@ -68,6 +70,9 @@ public class XPathRule extends AbstractRule { */ private XPathRuleQuery xpathRuleQuery; + // this is shared with rules forked by deepCopy, used by the XPathRuleQuery + private DeprecatedAttrLogger attrLogger = DeprecatedAttrLogger.create(this); + /** * Creates a new XPathRule without the corresponding XPath query. * @@ -106,6 +111,14 @@ public class XPathRule extends AbstractRule { setVersion(version.getXmlName()); } + + @Override + public Rule deepCopy() { + XPathRule rule = (XPathRule) super.deepCopy(); + rule.attrLogger = this.attrLogger; + return rule; + } + /** * Returns the version for this rule. Returns null if this is not * set or invalid. @@ -179,9 +192,9 @@ public class XPathRule extends AbstractRule { } if (version == XPathVersion.XPATH_1_0) { - xpathRuleQuery = new JaxenXPathRuleQuery(); + xpathRuleQuery = new JaxenXPathRuleQuery(attrLogger); } else { - xpathRuleQuery = new SaxonXPathRuleQuery(); + xpathRuleQuery = new SaxonXPathRuleQuery(attrLogger); } xpathRuleQuery.setXPath(xpath); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/JaxenXPathRuleQuery.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/JaxenXPathRuleQuery.java index 1e331a7b28..4ef992f19d 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/JaxenXPathRuleQuery.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/JaxenXPathRuleQuery.java @@ -33,6 +33,8 @@ import org.jaxen.saxpath.Axis; import net.sourceforge.pmd.RuleContext; import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.ast.Node; +import net.sourceforge.pmd.lang.ast.xpath.internal.ContextualizedNavigator; +import net.sourceforge.pmd.lang.ast.xpath.internal.DeprecatedAttrLogger; import net.sourceforge.pmd.properties.PropertyDescriptor; /** @@ -46,15 +48,21 @@ public class JaxenXPathRuleQuery extends AbstractXPathRuleQuery { private static final Logger LOG = Logger.getLogger(JaxenXPathRuleQuery.class.getName()); - private enum InitializationStatus { - NONE, PARTIAL, FULL - } + static final String AST_ROOT = "_AST_ROOT_"; private InitializationStatus initializationStatus = InitializationStatus.NONE; // Mapping from Node name to applicable XPath queries Map> nodeNameToXPaths; - static final String AST_ROOT = "_AST_ROOT_"; + private final DeprecatedAttrLogger attrCtx; + + public JaxenXPathRuleQuery() { + this(DeprecatedAttrLogger.noop()); + } + + public JaxenXPathRuleQuery(DeprecatedAttrLogger attrCtx) { + this.attrCtx = attrCtx; + } @Override public boolean isSupportedVersion(String version) { @@ -66,7 +74,7 @@ public class JaxenXPathRuleQuery extends AbstractXPathRuleQuery { final List results = new ArrayList<>(); try { - initializeExpressionIfStatusIsNoneOrPartial(data.getLanguageVersion().getLanguageVersionHandler().getXPathHandler().getNavigator()); + initializeExpressionIfStatusIsNoneOrPartial(new ContextualizedNavigator(attrCtx)); List xPaths = getXPathsForNodeOrDefault(node.getXPathNodeName()); for (XPath xpath : xPaths) { @@ -266,4 +274,9 @@ public class JaxenXPathRuleQuery extends AbstractXPathRuleQuery { } return xpath; } + + + private enum InitializationStatus { + NONE, PARTIAL, FULL + } } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/SaxonXPathRuleQuery.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/SaxonXPathRuleQuery.java index 9e8b976732..4bcb8f7423 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/SaxonXPathRuleQuery.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/SaxonXPathRuleQuery.java @@ -17,6 +17,7 @@ import java.util.regex.Pattern; import net.sourceforge.pmd.RuleContext; import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.ast.Node; +import net.sourceforge.pmd.lang.ast.xpath.internal.DeprecatedAttrLogger; import net.sourceforge.pmd.lang.ast.xpath.saxon.DocumentNode; import net.sourceforge.pmd.lang.ast.xpath.saxon.ElementNode; import net.sourceforge.pmd.lang.rule.xpath.internal.RuleChainAnalyzer; @@ -73,7 +74,6 @@ public class SaxonXPathRuleQuery extends AbstractXPathRuleQuery { /** Cache key for the wrapped tree for saxon. */ private static final SimpleDataKey SAXON_TREE_CACHE_KEY = DataMap.simpleDataKey("saxon.tree"); - /** * Contains for each nodeName a sub expression, used for implementing rule chain. */ @@ -91,6 +91,17 @@ public class SaxonXPathRuleQuery extends AbstractXPathRuleQuery { */ private List xpathVariables; + private final DeprecatedAttrLogger attrCtx; + + @Deprecated + public SaxonXPathRuleQuery() { + this(DeprecatedAttrLogger.noop()); + } + + public SaxonXPathRuleQuery(DeprecatedAttrLogger attrCtx) { + this.attrCtx = attrCtx; + } + @Override public boolean isSupportedVersion(String version) { return XPATH_1_0_COMPATIBILITY.equals(version) || XPATH_2_0.equals(version); @@ -102,9 +113,11 @@ public class SaxonXPathRuleQuery extends AbstractXPathRuleQuery { try { final DocumentNode documentNode = getDocumentNodeForRootNode(node); + documentNode.setAttrCtx(attrCtx); // // Map AST Node -> Saxon Node final ElementNode rootElementNode = documentNode.nodeToElementNode.get(node); + assert rootElementNode != null : "Cannot find " + node; final XPathDynamicContext xpathDynamicContext = createDynamicContext(rootElementNode); final List nodes = new LinkedList<>(); diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/DummyNode.java b/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/DummyNode.java index 8cfa55925e..10ddb52a1d 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/DummyNode.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/DummyNode.java @@ -26,6 +26,21 @@ public class DummyNode extends AbstractNode { this.xpathName = xpathName; } + public void setBeginColumn(int i) { + beginColumn = i; + } + + public void setBeginLine(int i) { + beginLine = i; + } + + public void setCoords(int bline, int bcol, int eline, int ecol) { + beginLine = bline; + beginColumn = bcol; + endLine = eline; + endColumn = ecol; + } + @Override public String toString() { return xpathName; diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/xpath/AttributeAxisIteratorTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/xpath/AttributeAxisIteratorTest.java index 1d9e274921..d5697ed3bd 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/xpath/AttributeAxisIteratorTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/xpath/AttributeAxisIteratorTest.java @@ -5,7 +5,6 @@ package net.sourceforge.pmd.lang.ast.xpath; -import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -16,15 +15,10 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.hamcrest.Matchers; -import org.hamcrest.collection.IsMapContaining; import org.junit.Assert; -import org.junit.Rule; import org.junit.Test; -import net.sourceforge.pmd.junit.JavaUtilLoggingRule; import net.sourceforge.pmd.lang.ast.DummyNode; -import net.sourceforge.pmd.lang.ast.DummyNodeWithDeprecatedAttribute; import net.sourceforge.pmd.lang.ast.Node; @@ -33,32 +27,6 @@ import net.sourceforge.pmd.lang.ast.Node; */ public class AttributeAxisIteratorTest { - @Rule - public JavaUtilLoggingRule loggingRule = new JavaUtilLoggingRule(Attribute.class.getName()); - - /** - * Verifies that attributes are returned, even if they are deprecated. - * Deprecated attributes are still accessible, but a warning is logged, when - * the value is used. - */ - @Test - public void testAttributeDeprecation() { - // make sure, we log - Attribute.DETECTED_DEPRECATED_ATTRIBUTES.clear(); - - Node dummy = new DummyNodeWithDeprecatedAttribute(2); - Map attributes = toMap(new AttributeAxisIterator(dummy)); - assertThat(attributes, IsMapContaining.hasKey("Size")); - assertThat(attributes, IsMapContaining.hasKey("Name")); - - assertThat(attributes.get("Size").getStringValue(), Matchers.is("2")); - assertThat(attributes.get("Name").getStringValue(), Matchers.is("foo")); - - String log = loggingRule.getLog(); - assertThat(log, Matchers.containsString("Use of deprecated attribute 'dummyNode/@Size' in XPath query")); - assertThat(log, Matchers.containsString("Use of deprecated attribute 'dummyNode/@Name' in XPath query")); - } - /** * Test hasNext and next. */ @@ -103,7 +71,7 @@ public class AttributeAxisIteratorTest { assertFalse(atts.containsKey("NodeList")); } - private Map toMap(AttributeAxisIterator it) { + public Map toMap(AttributeAxisIterator it) { Map atts = new HashMap<>(); while (it.hasNext()) { Attribute attribute = it.next(); diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/XPathRuleTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/XPathRuleTest.java index e9bc85a985..9d906d7708 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/XPathRuleTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/XPathRuleTest.java @@ -4,18 +4,37 @@ package net.sourceforge.pmd.lang.rule; +import static java.util.Collections.singletonList; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertEquals; + +import org.hamcrest.Matchers; import org.junit.Assert; +import org.junit.Rule; import org.junit.Test; +import net.sourceforge.pmd.RuleContext; +import net.sourceforge.pmd.junit.JavaUtilLoggingRule; +import net.sourceforge.pmd.lang.DummyLanguageModule; +import net.sourceforge.pmd.lang.LanguageRegistry; +import net.sourceforge.pmd.lang.ast.DummyNode; +import net.sourceforge.pmd.lang.ast.DummyNodeWithDeprecatedAttribute; +import net.sourceforge.pmd.lang.ast.xpath.Attribute; +import net.sourceforge.pmd.lang.rule.xpath.XPathVersion; + public class XPathRuleTest { + @Rule + public JavaUtilLoggingRule loggingRule = new JavaUtilLoggingRule(Attribute.class.getName()); + /** * It's easy to forget the attribute "typeResolution=true" when * defining XPath rules in xml. Therefore we by default enable * typeresolution. For Java rules, type resolution was enabled by * default long time ago. * - * @see #2048 [core] Enable type resolution by default for XPath rules + * @see #2048 [core] Enable type resolution by default for XPath + * rules */ @Test public void typeResolutionShouldBeEnabledByDefault() { @@ -26,4 +45,75 @@ public class XPathRuleTest { Assert.assertTrue(rule2.isTypeResolution()); } + + @Test + public void testAttributeDeprecation10() { + testDeprecation(XPathVersion.XPATH_1_0); + } + + @Test + public void testAttributeDeprecation20() { + testDeprecation(XPathVersion.XPATH_2_0); + } + + public void testDeprecation(XPathVersion version) { + XPathRule xpr = makeRule(version, "SomeRule"); + + loggingRule.clear(); + + RuleContext ctx = new RuleContext(); + ctx.setLanguageVersion(LanguageRegistry.getLanguage(DummyLanguageModule.NAME).getDefaultVersion()); + DummyNode firstNode = newNode(); + eval(ctx, xpr, firstNode); + assertEquals(1, ctx.getReport().size()); + + String log = loggingRule.getLog(); + assertThat(log, Matchers.containsString("Use of deprecated attribute 'dummyNode/@Size' by rule SomeRule")); + assertThat(log, Matchers.containsString("Use of deprecated attribute 'dummyNode/@Name' by rule SomeRule")); + + + loggingRule.clear(); + + eval(ctx, xpr, newNode()); // with another node + assertEquals(2, ctx.getReport().size()); + + assertEquals("", loggingRule.getLog()); // no additional warnings + + + // with another rule forked from the same one (in multithreaded processor) + eval(ctx, xpr.deepCopy(), newNode()); + assertEquals(3, ctx.getReport().size()); + + assertEquals("", loggingRule.getLog()); // no additional warnings + + // with another rule on the same node, new warnings + XPathRule otherRule = makeRule(version, "OtherRule"); + otherRule.setRuleSetName("rset.xml"); + eval(ctx, otherRule, firstNode); + assertEquals(4, ctx.getReport().size()); + + log = loggingRule.getLog(); + assertThat(log, Matchers.containsString("Use of deprecated attribute 'dummyNode/@Size' by rule rset.xml/OtherRule")); + assertThat(log, Matchers.containsString("Use of deprecated attribute 'dummyNode/@Name' by rule rset.xml/OtherRule")); + + } + + public XPathRule makeRule(XPathVersion version, String name) { + XPathRule xpr = new XPathRule(version, "//dummyNode[@Size >= 2 and @Name='foo']"); + xpr.setName(name); + xpr.setMessage("gotcha"); + return xpr; + } + + public void eval(RuleContext ctx, net.sourceforge.pmd.Rule rule, DummyNode node) { + rule.apply(singletonList(node), ctx); + } + + public DummyNode newNode() { + DummyNode dummy = new DummyNodeWithDeprecatedAttribute(2); + dummy.setCoords(1, 1, 1, 2); + return dummy; + } + + } From 56ab75bfd175e0fa1bd5311e581475def4989c25 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 17 Apr 2020 20:01:52 +0200 Subject: [PATCH 33/49] [apex] Refactor usage of internal getNode() This exposes more information directly on PMD's AST node rather then giving away the inner jorje node. --- .../ast/ASTFieldDeclarationStatements.java | 40 +++++++ .../apex/ast/ASTIfElseBlockStatement.java | 4 + .../pmd/lang/apex/ast/ASTMethod.java | 10 +- .../apex/ast/ASTMethodCallExpression.java | 6 +- .../lang/apex/ast/ASTReferenceExpression.java | 13 ++ .../pmd/lang/apex/ast/ASTSoqlExpression.java | 6 +- .../pmd/lang/apex/ast/ASTUserClass.java | 2 +- .../pmd/lang/apex/ast/ASTUserEnum.java | 2 +- .../pmd/lang/apex/ast/ASTUserInterface.java | 2 +- .../pmd/lang/apex/ast/ASTUserTrigger.java | 2 +- .../pmd/lang/apex/ast/AbstractApexNode.java | 16 +++ .../pmd/lang/apex/ast/ApexNode.java | 4 + .../pmd/lang/apex/ast/ApexQualifiedName.java | 10 +- .../pmd/lang/apex/ast/ApexRootNode.java | 2 +- .../visitors/CognitiveComplexityVisitor.java | 10 +- .../pmd/lang/apex/rule/internal/Helper.java | 70 +++-------- .../rule/security/ApexCRUDViolationRule.java | 112 ++++++------------ .../pmd/lang/apex/rule/security/Helper.java | 104 +++------------- .../pmd/lang/apex/ast/ASTMethodTest.java | 3 +- .../pmd/lang/apex/ast/ApexParserTest.java | 3 - 20 files changed, 185 insertions(+), 236 deletions(-) diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTFieldDeclarationStatements.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTFieldDeclarationStatements.java index e756923db5..d9b54d5691 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTFieldDeclarationStatements.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTFieldDeclarationStatements.java @@ -4,9 +4,17 @@ package net.sourceforge.pmd.lang.apex.ast; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + import net.sourceforge.pmd.Rule; import net.sourceforge.pmd.annotation.InternalApi; +import apex.jorje.data.Identifier; +import apex.jorje.data.ast.TypeRef; +import apex.jorje.data.ast.TypeRefs.ArrayTypeRef; +import apex.jorje.data.ast.TypeRefs.ClassTypeRef; import apex.jorje.semantic.ast.statement.FieldDeclarationStatements; public class ASTFieldDeclarationStatements extends AbstractApexNode @@ -38,4 +46,36 @@ public class ASTFieldDeclarationStatements extends AbstractApexNode names = node.getTypeName().getNames(); + return names.stream().map(Identifier::getValue).collect(Collectors.joining(".")); + } + return null; + } + + private static String identifiersToString(List identifiers) { + return identifiers.stream().map(Identifier::getValue).collect(Collectors.joining(".")); + } + + public List getTypeArguments() { + List result = new ArrayList<>(); + + if (node.getTypeName() != null) { + List typeArgs = node.getTypeName().getTypeArguments(); + for (TypeRef arg : typeArgs) { + if (arg instanceof ClassTypeRef) { + result.add(identifiersToString(arg.getNames())); + } else if (arg instanceof ArrayTypeRef) { + ArrayTypeRef atr = (ArrayTypeRef) arg; + if (atr.getHeldType() instanceof ClassTypeRef) { + result.add(identifiersToString(atr.getHeldType().getNames())); + } + } + } + } + + return result; + } } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTIfElseBlockStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTIfElseBlockStatement.java index b4f29c69c9..8d04a8a568 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTIfElseBlockStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTIfElseBlockStatement.java @@ -20,4 +20,8 @@ public class ASTIfElseBlockStatement extends AbstractApexNode implements ApexQualifiab return node.getMethodInfo().getName(); } + public String getCanonicalName() { + return node.getMethodInfo().getCanonicalName(); + } + @Override public int getEndLine() { ASTBlockStatement block = getFirstChildOfType(ASTBlockStatement.class); @@ -82,6 +86,10 @@ public class ASTMethod extends AbstractApexNode implements ApexQualifiab } public String getReturnType() { - return node.getReturnTypeRef().toString(); + return node.getMethodInfo().getEmitSignature().getReturnType().getApexName(); + } + + public int getArity() { + return node.getMethodInfo().getParameterTypes().size(); } } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTMethodCallExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTMethodCallExpression.java index 739c8d9617..f929a33916 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTMethodCallExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTMethodCallExpression.java @@ -11,8 +11,8 @@ import net.sourceforge.pmd.annotation.InternalApi; import apex.jorje.data.Identifier; import apex.jorje.semantic.ast.expression.MethodCallExpression; -public class ASTMethodCallExpression extends AbstractApexNode { +public class ASTMethodCallExpression extends AbstractApexNode { @Deprecated @InternalApi public ASTMethodCallExpression(MethodCallExpression methodCallExpression) { @@ -36,4 +36,8 @@ public class ASTMethodCallExpression extends AbstractApexNode getNames() { + List identifiers = node.getNames(); + if (identifiers != null) { + return identifiers.stream().map(id -> id.getValue()).collect(Collectors.toList()); + } + return Collections.emptyList(); + } } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTSoqlExpression.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTSoqlExpression.java index 7028ff0542..2bc1e4c1b6 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTSoqlExpression.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTSoqlExpression.java @@ -22,6 +22,10 @@ public class ASTSoqlExpression extends AbstractApexNode { } public String getQuery() { - return getNode().getRawQuery(); + return node.getRawQuery(); + } + + public String getCanonicalQuery() { + return node.getCanonicalQuery(); } } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserClass.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserClass.java index 3c4591c633..6f24713f30 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserClass.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserClass.java @@ -34,7 +34,7 @@ public class ASTUserClass extends ApexRootNode implements ASTUserClas @Override public String getImage() { - String apexName = node.getDefiningType().getApexName(); + String apexName = getDefiningType(); return apexName.substring(apexName.lastIndexOf('.') + 1); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserEnum.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserEnum.java index ccb0487fcd..4aef1641cc 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserEnum.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserEnum.java @@ -23,7 +23,7 @@ public class ASTUserEnum extends ApexRootNode { @Override public String getImage() { - String apexName = node.getDefiningType().getApexName(); + String apexName = getDefiningType(); return apexName.substring(apexName.lastIndexOf('.') + 1); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserInterface.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserInterface.java index 14b705e1b0..0b3baa8899 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserInterface.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserInterface.java @@ -31,7 +31,7 @@ public class ASTUserInterface extends ApexRootNode implements AST @Override public String getImage() { - String apexName = node.getDefiningType().getApexName(); + String apexName = getDefiningType(); return apexName.substring(apexName.lastIndexOf('.') + 1); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserTrigger.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserTrigger.java index d057801267..d956874681 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserTrigger.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTUserTrigger.java @@ -27,7 +27,7 @@ public class ASTUserTrigger extends ApexRootNode { @Override public String getImage() { - return node.getDefiningType().getApexName(); + return getDefiningType(); } public ASTModifierNode getModifiers() { diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/AbstractApexNode.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/AbstractApexNode.java index 730290a0ee..42e27a12c1 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/AbstractApexNode.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/AbstractApexNode.java @@ -81,4 +81,20 @@ public abstract class AbstractApexNode extends AbstractApexNo return "no location"; } } + + @Override + public String getDefiningType() { + if (node.getDefiningType() != null) { + return node.getDefiningType().getApexName(); + } + return null; + } + + @Override + public String getNamespace() { + if (node.getDefiningType() != null) { + return node.getDefiningType().getNamespace().toString(); + } + return null; + } } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexNode.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexNode.java index f30bc61240..a89ac64f48 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexNode.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexNode.java @@ -55,4 +55,8 @@ public interface ApexNode extends Node { ApexNode getParent(); boolean hasRealLoc(); + + String getDefiningType(); + + String getNamespace(); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexQualifiedName.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexQualifiedName.java index 8fd38b45a6..6c8e5b48ac 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexQualifiedName.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexQualifiedName.java @@ -133,8 +133,8 @@ public final class ApexQualifiedName implements QualifiedName { } - static ApexQualifiedName ofOuterClass(ASTUserClassOrInterface astUserClass) { - String ns = astUserClass.getNode().getDefiningType().getNamespace().toString(); + static ApexQualifiedName ofOuterClass(ASTUserClassOrInterface astUserClass) { + String ns = astUserClass.getNamespace(); String[] classes = {astUserClass.getImage()}; return new ApexQualifiedName(StringUtils.isEmpty(ns) ? "c" : ns, classes, null); } @@ -153,7 +153,7 @@ public final class ApexQualifiedName implements QualifiedName { sb.append(node.getImage()).append('('); - List paramTypes = node.getNode().getMethodInfo().getParameterTypes(); + List paramTypes = node.node.getMethodInfo().getParameterTypes(); if (!paramTypes.isEmpty()) { sb.append(paramTypes.get(0).getApexName()); @@ -174,8 +174,8 @@ public final class ApexQualifiedName implements QualifiedName { ASTUserClassOrInterface parent = node.getFirstParentOfType(ASTUserClassOrInterface.class); if (parent == null) { ASTUserTrigger trigger = node.getFirstParentOfType(ASTUserTrigger.class); - String ns = trigger.getNode().getDefiningType().getNamespace().toString(); - String targetObj = trigger.getNode().getTargetName().get(0).getValue(); + String ns = trigger.getNamespace(); + String targetObj = trigger.getTargetName(); return new ApexQualifiedName(StringUtils.isEmpty(ns) ? "c" : ns, new String[]{"trigger", targetObj}, trigger.getImage()); // uses a reserved word as a class name to prevent clashes diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexRootNode.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexRootNode.java index 333d6963ad..13f756ca1d 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexRootNode.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexRootNode.java @@ -35,6 +35,6 @@ public abstract class ApexRootNode extends AbstractApexNode child : node.children()) { // If we don't have an else statement, we get an empty block statement which we shouldn't count if (!hasElseStatement && child instanceof ASTBlockStatement) { @@ -184,7 +184,7 @@ public class CognitiveComplexityVisitor extends ApexParserVisitorAdapter { public Object visit(ASTBooleanExpression node, Object data) { State state = (State) data; - BooleanOp op = node.getNode().getOp(); + BooleanOp op = node.getOperator(); if (op == BooleanOp.AND || op == BooleanOp.OR) { state.booleanOperation(op); } @@ -196,7 +196,7 @@ public class CognitiveComplexityVisitor extends ApexParserVisitorAdapter { public Object visit(ASTPrefixExpression node, Object data) { State state = (State) data; - PrefixOp op = node.getNode().getOp(); + PrefixOp op = node.getOperator(); if (op == PrefixOp.NOT) { state.booleanOperation(null); } @@ -222,14 +222,14 @@ public class CognitiveComplexityVisitor extends ApexParserVisitorAdapter { @Override public Object visit(ASTMethod node, Object data) { State state = (State) data; - state.setMethodName(node.getNode().getMethodInfo().getCanonicalName()); + state.setMethodName(node.getCanonicalName()); return super.visit(node, data); } @Override public Object visit(ASTMethodCallExpression node, Object data) { State state = (State) data; - state.methodCall(node.getNode().getMethodName()); + state.methodCall(node.getMethodName()); return super.visit(node, data); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/internal/Helper.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/internal/Helper.java index c2145d05c7..1901420c19 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/internal/Helper.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/internal/Helper.java @@ -7,7 +7,6 @@ package net.sourceforge.pmd.lang.apex.rule.internal; import java.util.Arrays; import java.util.List; import java.util.Locale; -import java.util.stream.Collectors; import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.apex.ast.ASTDmlDeleteStatement; @@ -30,14 +29,6 @@ import net.sourceforge.pmd.lang.apex.ast.ASTVariableDeclaration; import net.sourceforge.pmd.lang.apex.ast.ASTVariableExpression; import net.sourceforge.pmd.lang.apex.ast.ApexNode; -import apex.jorje.data.Identifier; -import apex.jorje.data.ast.TypeRef; -import apex.jorje.semantic.ast.expression.MethodCallExpression; -import apex.jorje.semantic.ast.expression.VariableExpression; -import apex.jorje.semantic.ast.member.Field; -import apex.jorje.semantic.ast.member.Parameter; -import apex.jorje.semantic.ast.statement.VariableDeclaration; - /** * Helper methods * @@ -60,7 +51,7 @@ public final class Helper { } } - final String className = node.getNode().getDefiningType().getApexName(); + final String className = node.getDefiningType(); return className.endsWith("Test"); } @@ -96,16 +87,12 @@ public final class Helper { final String methodName) { final ASTReferenceExpression reference = methodNode.getFirstChildOfType(ASTReferenceExpression.class); - return reference != null && reference.getNode().getNames().size() == 1 - && reference.getNode().getNames().get(0).getValue().equalsIgnoreCase(className) + return reference != null && reference.getNames().size() == 1 + && reference.getNames().get(0).equalsIgnoreCase(className) && (methodName.equals(ANY_METHOD) || isMethodName(methodNode, methodName)); } public static boolean isMethodName(final ASTMethodCallExpression m, final String methodName) { - return isMethodName(m.getNode(), methodName); - } - - static boolean isMethodName(final MethodCallExpression m, final String methodName) { return m.getMethodName().equalsIgnoreCase(methodName); } @@ -134,67 +121,54 @@ public final class Helper { public static String getFQVariableName(final ASTVariableExpression variable) { final ASTReferenceExpression ref = variable.getFirstChildOfType(ASTReferenceExpression.class); String objectName = ""; - if (ref != null && ref.getNode().getNames().size() == 1) { - objectName = ref.getNode().getNames().get(0).getValue() + "."; + if (ref != null && ref.getNames().size() == 1) { + objectName = ref.getNames().get(0) + "."; } - VariableExpression n = variable.getNode(); - StringBuilder sb = new StringBuilder().append(n.getDefiningType().getApexName()).append(":").append(objectName) - .append(n.getIdentifier().getValue()); + StringBuilder sb = new StringBuilder().append(variable.getDefiningType()).append(":").append(objectName) + .append(variable.getImage()); return sb.toString(); } public static String getFQVariableName(final ASTVariableDeclaration variable) { - VariableDeclaration n = variable.getNode(); - StringBuilder sb = new StringBuilder().append(n.getDefiningType().getApexName()).append(":") - .append(n.getLocalInfo().getName()); + StringBuilder sb = new StringBuilder().append(variable.getDefiningType()).append(":") + .append(variable.getImage()); return sb.toString(); } public static String getFQVariableName(final ASTField variable) { - Field n = variable.getNode(); StringBuilder sb = new StringBuilder() - .append(n.getDefiningType().getApexName()).append(":") - .append(n.getFieldInfo().getName()); + .append(variable.getDefiningType()).append(":") + .append(variable.getName()); return sb.toString(); } static String getVariableType(final ASTField variable) { - Field n = variable.getNode(); - StringBuilder sb = new StringBuilder().append(n.getDefiningType().getApexName()).append(":") - .append(n.getFieldInfo().getName()); + StringBuilder sb = new StringBuilder().append(variable.getDefiningType()).append(":") + .append(variable.getName()); return sb.toString(); } public static String getFQVariableName(final ASTFieldDeclaration variable) { StringBuilder sb = new StringBuilder() - .append(variable.getNode().getDefiningType().getApexName()).append(":") + .append(variable.getDefiningType()).append(":") .append(variable.getImage()); return sb.toString(); } public static String getFQVariableName(final ASTNewKeyValueObjectExpression variable) { StringBuilder sb = new StringBuilder() - .append(variable.getNode().getDefiningType().getApexName()).append(":") + .append(variable.getDefiningType()).append(":") .append(variable.getType()); return sb.toString(); } public static boolean isSystemLevelClass(ASTUserClass node) { - List interfaces = node.getNode().getDefiningType().getCodeUnitDetails().getInterfaceTypeRefs(); - - for (TypeRef intObject : interfaces) { - if (isWhitelisted(intObject.getNames())) { - return true; - } - } - - return false; + List interfaces = node.getInterfaceNames(); + return interfaces.stream().anyMatch(Helper::isWhitelisted); } - private static boolean isWhitelisted(List ids) { - String identifier = ids.stream().map(Identifier::getValue).collect(Collectors.joining(".")); - + private static boolean isWhitelisted(String identifier) { switch (identifier.toLowerCase(Locale.ROOT)) { case "queueable": case "database.batchable": @@ -206,15 +180,9 @@ public final class Helper { return false; } - public static String getFQVariableName(Parameter p) { - StringBuilder sb = new StringBuilder(); - sb.append(p.getDefiningType()).append(":").append(p.getName().getValue()); - return sb.toString(); - } - public static String getFQVariableName(ASTParameter p) { StringBuilder sb = new StringBuilder(); - sb.append(p.getNode().getDefiningType()).append(":").append(p.getImage()); + sb.append(p.getDefiningType()).append(":").append(p.getImage()); return sb.toString(); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexCRUDViolationRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexCRUDViolationRule.java index 7616100ee3..90fcb023a8 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexCRUDViolationRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/ApexCRUDViolationRule.java @@ -45,10 +45,6 @@ import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule; import net.sourceforge.pmd.lang.apex.rule.internal.Helper; import net.sourceforge.pmd.lang.ast.Node; -import apex.jorje.data.Identifier; -import apex.jorje.data.ast.TypeRef; -import apex.jorje.data.ast.TypeRefs.ArrayTypeRef; -import apex.jorje.data.ast.TypeRefs.ClassTypeRef; import com.google.common.base.Objects; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ListMultimap; @@ -108,9 +104,9 @@ public class ApexCRUDViolationRule extends AbstractApexRule { className = node.getImage(); for (ASTMethod n : node.findDescendantsOfType(ASTMethod.class)) { - StringBuilder sb = new StringBuilder().append(n.getNode().getDefiningType().getApexName()).append(":") - .append(n.getNode().getMethodInfo().getCanonicalName()).append(":") - .append(n.getNode().getMethodInfo().getParameterTypes().size()); + StringBuilder sb = new StringBuilder().append(n.getDefiningType()).append(":") + .append(n.getCanonicalName()).append(":") + .append(n.getArity()); classMethods.put(sb.toString(), n); } @@ -166,7 +162,7 @@ public class ApexCRUDViolationRule extends AbstractApexRule { @Override public Object visit(final ASTVariableDeclaration node, Object data) { - String type = node.getNode().getLocalInfo().getType().getApexName(); + String type = node.getType(); addVariableToMapping(Helper.getFQVariableName(node), type); final ASTSoqlExpression soql = node.getFirstChildOfType(ASTSoqlExpression.class); @@ -182,23 +178,18 @@ public class ApexCRUDViolationRule extends AbstractApexRule { public Object visit(final ASTFieldDeclaration node, Object data) { ASTFieldDeclarationStatements field = node.getFirstParentOfType(ASTFieldDeclarationStatements.class); if (field != null) { - TypeRef a = field.getNode().getTypeName(); - List names = a.getNames(); - List typeArgs = a.getTypeArguments(); + String namesString = field.getTypeName(); - if (!names.isEmpty()) { - String namesString = names.stream().map(Identifier::getValue).collect(Collectors.joining(".")); - - switch (namesString.toLowerCase(Locale.ROOT)) { - case "list": - case "map": - addParametersToMapping(node, typeArgs); - break; - default: - varToTypeMapping.put(Helper.getFQVariableName(node), getSimpleType(namesString)); - break; + switch (namesString.toLowerCase(Locale.ROOT)) { + case "list": + case "map": + for (String typeArg : field.getTypeArguments()) { + varToTypeMapping.put(Helper.getFQVariableName(node), typeArg); } - + break; + default: + varToTypeMapping.put(Helper.getFQVariableName(node), getSimpleType(namesString)); + break; } } final ASTSoqlExpression soql = node.getFirstChildOfType(ASTSoqlExpression.class); @@ -210,30 +201,6 @@ public class ApexCRUDViolationRule extends AbstractApexRule { } - private void addParametersToMapping(final ASTFieldDeclaration node, List typeArgs) { - for (int i = 0; i < typeArgs.size(); i++) { - if (typeArgs.get(i) instanceof ClassTypeRef) { - innerAddParametrizedClassToMapping(node, (ClassTypeRef) typeArgs.get(i)); - } - if (typeArgs.get(i) instanceof ArrayTypeRef) { - ArrayTypeRef atr = (ArrayTypeRef) typeArgs.get(i); - if (atr.getHeldType() instanceof ClassTypeRef) { - innerAddParametrizedClassToMapping(node, (ClassTypeRef) atr.getHeldType()); - } - } - } - } - - private void innerAddParametrizedClassToMapping(final ASTFieldDeclaration node, final ClassTypeRef innerClassRef) { - List ids = innerClassRef.getNames(); - StringBuffer argType = new StringBuffer(); - for (Identifier id : ids) { - argType.append(id.getValue()).append("."); - } - argType.deleteCharAt(argType.length() - 1); - addVariableToMapping(Helper.getFQVariableName(node), argType.toString()); - } - @Override public Object visit(final ASTReturnStatement node, Object data) { final ASTSoqlExpression soql = node.getFirstChildOfType(ASTSoqlExpression.class); @@ -286,9 +253,9 @@ public class ApexCRUDViolationRule extends AbstractApexRule { return; } - List a = ref.getNode().getNames(); + List a = ref.getNames(); if (!a.isEmpty()) { - extractObjectAndFields(a, method, node.getNode().getDefiningType().getApexName()); + extractObjectAndFields(a, method, node.getDefiningType()); } else { // see if ESAPI if (Helper.isMethodCallChain(node, ESAPI_ISAUTHORIZED_TO_VIEW)) { @@ -325,8 +292,8 @@ public class ApexCRUDViolationRule extends AbstractApexRule { private boolean isLastMethodName(final ASTMethodCallExpression methodNode, final String className, final String methodName) { final ASTReferenceExpression reference = methodNode.getFirstChildOfType(ASTReferenceExpression.class); - if (reference != null && reference.getNode().getNames().size() > 0) { - if (reference.getNode().getNames().get(reference.getNode().getNames().size() - 1).getValue() + if (reference != null && reference.getNames().size() > 0) { + if (reference.getNames().get(reference.getNames().size() - 1) .equalsIgnoreCase(className) && Helper.isMethodName(methodNode, methodName)) { return true; } @@ -344,20 +311,19 @@ public class ApexCRUDViolationRule extends AbstractApexRule { private String getType(final ASTMethodCallExpression methodNode) { final ASTReferenceExpression reference = methodNode.getFirstChildOfType(ASTReferenceExpression.class); - if (reference.getNode().getNames().size() > 0) { - return new StringBuilder().append(reference.getNode().getDefiningType().getApexName()).append(":") - .append(reference.getNode().getNames().get(0).getValue()).toString(); + if (reference.getNames().size() > 0) { + return new StringBuilder().append(reference.getDefiningType()).append(":") + .append(reference.getNames().get(0)).toString(); } return ""; } - private void extractObjectAndFields(final List listIdentifiers, final String method, + private void extractObjectAndFields(final List listIdentifiers, final String method, final String definingType) { - final List strings = listIdentifiers.stream().map(id -> id.getValue()).collect(Collectors.toList()); - int flsIndex = Collections.lastIndexOfSubList(strings, Arrays.asList(RESERVED_KEYS_FLS)); + int flsIndex = Collections.lastIndexOfSubList(listIdentifiers, Arrays.asList(RESERVED_KEYS_FLS)); if (flsIndex != -1) { - String objectTypeName = strings.get(flsIndex + RESERVED_KEYS_FLS.length); + String objectTypeName = listIdentifiers.get(flsIndex + RESERVED_KEYS_FLS.length); if (!typeToDMLOperationMapping.get(definingType + ":" + objectTypeName).contains(method)) { typeToDMLOperationMapping.put(definingType + ":" + objectTypeName, method); } @@ -388,7 +354,7 @@ public class ApexCRUDViolationRule extends AbstractApexRule { if (variable != null) { final String type = varToTypeMapping.get(Helper.getFQVariableName(variable)); if (type != null) { - StringBuilder typeCheck = new StringBuilder().append(node.getNode().getDefiningType().getApexName()) + StringBuilder typeCheck = new StringBuilder().append(node.getDefiningType()) .append(":").append(type); validateCRUDCheckPresent(node, data, crudMethod, typeCheck.toString()); @@ -471,8 +437,8 @@ public class ApexCRUDViolationRule extends AbstractApexRule { } private ASTMethod resolveMethodCalls(final ASTMethodCallExpression node) { - StringBuilder sb = new StringBuilder().append(node.getNode().getDefiningType().getApexName()).append(":") - .append(node.getNode().getMethodName()).append(":").append(node.getNode().getInputParameters().size()); + StringBuilder sb = new StringBuilder().append(node.getDefiningType()).append(":") + .append(node.getMethodName()).append(":").append(node.getInputParametersSize()); return classMethods.get(sb.toString()); } @@ -495,10 +461,10 @@ public class ApexCRUDViolationRule extends AbstractApexRule { if (var != null) { final ASTReferenceExpression reference = var.getFirstChildOfType(ASTReferenceExpression.class); if (reference != null) { - List identifiers = reference.getNode().getNames(); + List identifiers = reference.getNames(); if (identifiers.size() == 1) { - StringBuilder sb = new StringBuilder().append(node.getNode().getDefiningType().getApexName()) - .append(":").append(identifiers.get(0).getValue()); + StringBuilder sb = new StringBuilder().append(node.getDefiningType()) + .append(":").append(identifiers.get(0)); checkedTypeToDMLOperationViaESAPI.put(sb.toString(), dmlOperation); } @@ -540,7 +506,7 @@ public class ApexCRUDViolationRule extends AbstractApexRule { } private void checkForAccessibility(final ASTSoqlExpression node, Object data) { - final boolean isCount = node.getNode().getCanonicalQuery().startsWith("SELECT COUNT()"); + final boolean isCount = node.getCanonicalQuery().startsWith("SELECT COUNT()"); final Set typesFromSOQL = getTypesFromSOQLQuery(node); final Set prevCalls = getPreviousMethodCalls(node); @@ -567,9 +533,9 @@ public class ApexCRUDViolationRule extends AbstractApexRule { final ASTVariableDeclaration variableDecl = node.getFirstParentOfType(ASTVariableDeclaration.class); if (variableDecl != null) { - String type = variableDecl.getNode().getLocalInfo().getType().getApexName(); + String type = variableDecl.getType(); type = getSimpleType(type); - StringBuilder typeCheck = new StringBuilder().append(variableDecl.getNode().getDefiningType().getApexName()) + StringBuilder typeCheck = new StringBuilder().append(variableDecl.getDefiningType()) .append(":").append(type); if (!isGetter) { @@ -622,25 +588,25 @@ public class ApexCRUDViolationRule extends AbstractApexRule { private Set getTypesFromSOQLQuery(final ASTSoqlExpression node) { final Set retVal = new HashSet<>(); - final String canonQuery = node.getNode().getCanonicalQuery(); + final String canonQuery = node.getCanonicalQuery(); Matcher m = SELECT_FROM_PATTERN.matcher(canonQuery); while (m.find()) { - retVal.add(new StringBuffer().append(node.getNode().getDefiningType().getApexName()).append(":") + retVal.add(new StringBuffer().append(node.getDefiningType()).append(":") .append(m.group(1)).toString()); } return retVal; } private String getReturnType(final ASTMethod method) { - return new StringBuilder().append(method.getNode().getDefiningType().getApexName()).append(":") - .append(method.getNode().getMethodInfo().getEmitSignature().getReturnType().getApexName()).toString(); + return new StringBuilder().append(method.getDefiningType()).append(":") + .append(method.getReturnType()).toString(); } private boolean isMethodAGetter(final ASTMethod method) { - final boolean startsWithGet = method.getNode().getMethodInfo().getCanonicalName().startsWith("get"); + final boolean startsWithGet = method.getCanonicalName().startsWith("get"); final boolean voidOrString = VOID_OR_STRING_PATTERN - .matcher(method.getNode().getMethodInfo().getEmitSignature().getReturnType().getApexName()).matches(); + .matcher(method.getReturnType()).matches(); final boolean noParams = method.findChildrenOfType(ASTParameter.class).isEmpty(); return startsWithGet && noParams && !voidOrString; diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/Helper.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/Helper.java index cb83f24cae..b51c0c2f68 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/Helper.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/security/Helper.java @@ -6,7 +6,6 @@ package net.sourceforge.pmd.lang.apex.rule.security; import java.util.Arrays; import java.util.List; -import java.util.Locale; import net.sourceforge.pmd.lang.apex.ast.ASTDmlDeleteStatement; import net.sourceforge.pmd.lang.apex.ast.ASTDmlInsertStatement; @@ -17,7 +16,6 @@ import net.sourceforge.pmd.lang.apex.ast.ASTDmlUpsertStatement; import net.sourceforge.pmd.lang.apex.ast.ASTField; import net.sourceforge.pmd.lang.apex.ast.ASTFieldDeclaration; import net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression; -import net.sourceforge.pmd.lang.apex.ast.ASTModifierNode; import net.sourceforge.pmd.lang.apex.ast.ASTNewKeyValueObjectExpression; import net.sourceforge.pmd.lang.apex.ast.ASTParameter; import net.sourceforge.pmd.lang.apex.ast.ASTReferenceExpression; @@ -28,13 +26,7 @@ import net.sourceforge.pmd.lang.apex.ast.ASTVariableDeclaration; import net.sourceforge.pmd.lang.apex.ast.ASTVariableExpression; import net.sourceforge.pmd.lang.apex.ast.ApexNode; -import apex.jorje.data.Identifier; -import apex.jorje.data.ast.TypeRef; -import apex.jorje.semantic.ast.expression.MethodCallExpression; -import apex.jorje.semantic.ast.expression.VariableExpression; -import apex.jorje.semantic.ast.member.Field; import apex.jorje.semantic.ast.member.Parameter; -import apex.jorje.semantic.ast.statement.VariableDeclaration; /** * Helper methods @@ -52,15 +44,7 @@ public final class Helper { } static boolean isTestMethodOrClass(final ApexNode node) { - final List modifierNode = node.findChildrenOfType(ASTModifierNode.class); - for (final ASTModifierNode m : modifierNode) { - if (m.isTest()) { - return true; - } - } - - final String className = node.getNode().getDefiningType().getApexName(); - return className.endsWith("Test"); + return net.sourceforge.pmd.lang.apex.rule.internal.Helper.isTestMethodOrClass(node); } static boolean foundAnySOQLorSOSL(final ApexNode node) { @@ -95,16 +79,12 @@ public final class Helper { final String methodName) { final ASTReferenceExpression reference = methodNode.getFirstChildOfType(ASTReferenceExpression.class); - return reference != null && reference.getNode().getNames().size() == 1 - && reference.getNode().getNames().get(0).getValue().equalsIgnoreCase(className) + return reference != null && reference.getNames().size() == 1 + && reference.getNames().get(0).equalsIgnoreCase(className) && (methodName.equals(ANY_METHOD) || isMethodName(methodNode, methodName)); } static boolean isMethodName(final ASTMethodCallExpression m, final String methodName) { - return isMethodName(m.getNode(), methodName); - } - - static boolean isMethodName(final MethodCallExpression m, final String methodName) { return m.getMethodName().equalsIgnoreCase(methodName); } @@ -131,100 +111,44 @@ public final class Helper { } static String getFQVariableName(final ASTVariableExpression variable) { - final ASTReferenceExpression ref = variable.getFirstChildOfType(ASTReferenceExpression.class); - String objectName = ""; - if (ref != null) { - if (ref.getNode().getNames().size() == 1) { - objectName = ref.getNode().getNames().get(0).getValue() + "."; - } - } - - VariableExpression n = variable.getNode(); - StringBuilder sb = new StringBuilder().append(n.getDefiningType().getApexName()).append(":").append(objectName) - .append(n.getIdentifier().getValue()); - return sb.toString(); + return net.sourceforge.pmd.lang.apex.rule.internal.Helper.getFQVariableName(variable); } static String getFQVariableName(final ASTVariableDeclaration variable) { - VariableDeclaration n = variable.getNode(); - StringBuilder sb = new StringBuilder().append(n.getDefiningType().getApexName()).append(":") - .append(n.getLocalInfo().getName()); - return sb.toString(); + return net.sourceforge.pmd.lang.apex.rule.internal.Helper.getFQVariableName(variable); } static String getFQVariableName(final ASTField variable) { - Field n = variable.getNode(); - StringBuilder sb = new StringBuilder() - .append(n.getDefiningType().getApexName()).append(":") - .append(n.getFieldInfo().getName()); - return sb.toString(); + return net.sourceforge.pmd.lang.apex.rule.internal.Helper.getFQVariableName(variable); } static String getVariableType(final ASTField variable) { - Field n = variable.getNode(); - StringBuilder sb = new StringBuilder().append(n.getDefiningType().getApexName()).append(":") - .append(n.getFieldInfo().getName()); + StringBuilder sb = new StringBuilder().append(variable.getDefiningType()).append(":") + .append(variable.getName()); return sb.toString(); } static String getFQVariableName(final ASTFieldDeclaration variable) { - StringBuilder sb = new StringBuilder() - .append(variable.getNode().getDefiningType().getApexName()).append(":") - .append(variable.getImage()); - return sb.toString(); + return net.sourceforge.pmd.lang.apex.rule.internal.Helper.getFQVariableName(variable); } static String getFQVariableName(final ASTNewKeyValueObjectExpression variable) { - StringBuilder sb = new StringBuilder() - .append(variable.getNode().getDefiningType().getApexName()).append(":") - .append(variable.getType()); - return sb.toString(); + return net.sourceforge.pmd.lang.apex.rule.internal.Helper.getFQVariableName(variable); } static boolean isSystemLevelClass(ASTUserClass node) { - List interfaces = node.getNode().getDefiningType().getCodeUnitDetails().getInterfaceTypeRefs(); - - for (TypeRef intObject : interfaces) { - if (isWhitelisted(intObject.getNames())) { - return true; - } - } - - return false; - } - - private static boolean isWhitelisted(List ids) { - StringBuffer sb = new StringBuffer(); - - for (int i = 0; i < ids.size(); i++) { - sb.append(ids.get(i).getValue()); - - if (i != ids.size() - 1) { - sb.append("."); - } - } - - switch (sb.toString().toLowerCase(Locale.ROOT)) { - case "queueable": - case "database.batchable": - case "installhandler": - return true; - default: - break; - } - return false; + return net.sourceforge.pmd.lang.apex.rule.internal.Helper.isSystemLevelClass(node); } + @Deprecated public static String getFQVariableName(Parameter p) { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append(p.getDefiningType()).append(":").append(p.getName().getValue()); return sb.toString(); } static String getFQVariableName(ASTParameter p) { - StringBuffer sb = new StringBuffer(); - sb.append(p.getNode().getDefiningType()).append(":").append(p.getImage()); - return sb.toString(); + return net.sourceforge.pmd.lang.apex.rule.internal.Helper.getFQVariableName(p); } } diff --git a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/ast/ASTMethodTest.java b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/ast/ASTMethodTest.java index d29e8116d1..832ab9e976 100644 --- a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/ast/ASTMethodTest.java +++ b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/ast/ASTMethodTest.java @@ -1,4 +1,4 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ @@ -19,6 +19,7 @@ public class ASTMethodTest extends ApexParserTestBase { Assert.assertSame(ASTUserClass.class, node.getClass()); List methods = node.findChildrenOfType(ASTMethod.class); Assert.assertEquals("Foo", methods.get(0).getImage()); // constructor + Assert.assertEquals("", methods.get(0).getCanonicalName()); Assert.assertEquals("bar", methods.get(1).getImage()); // normal method } } diff --git a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/ast/ApexParserTest.java b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/ast/ApexParserTest.java index 0cc7c50297..9e0303a41d 100644 --- a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/ast/ApexParserTest.java +++ b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/ast/ApexParserTest.java @@ -6,7 +6,6 @@ package net.sourceforge.pmd.lang.apex.ast; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; @@ -127,8 +126,6 @@ public class ApexParserTest extends ApexParserTestBase { ApexNode comment = root.getChild(0); assertThat(comment, instanceOf(ASTFormalComment.class)); - assertNotEquals(comment.getNode(), null); - assertThat(comment.getNode(), instanceOf(ASTFormalComment.AstComment.class)); assertPosition(comment, 1, 9, 1, 31); assertEquals("/** Comment on Class */", ((ASTFormalComment) comment).getToken()); From be152e92a8a58df7889c7db58b68c62148151942 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Fri, 17 Apr 2020 20:18:32 +0200 Subject: [PATCH 34/49] Output replacement as well --- .../pmd/lang/ast/xpath/Attribute.java | 20 +++++++++++++++++++ .../xpath/internal/DeprecatedAttrLogger.java | 9 +++++++-- .../xpath/internal/DeprecatedAttribute.java | 9 +++++++++ .../lang/ast/xpath/saxon/AttributeNode.java | 5 ----- .../lang/java/ast/ASTAdditiveExpression.java | 11 ++++++++++ .../lang/java/ast/ASTAnyTypeDeclaration.java | 2 ++ 6 files changed, 49 insertions(+), 7 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/Attribute.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/Attribute.java index a1259b816d..8c9ed3e59d 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/Attribute.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/Attribute.java @@ -11,6 +11,7 @@ import java.util.List; import java.util.Objects; import net.sourceforge.pmd.annotation.Experimental; +import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.ast.xpath.internal.DeprecatedAttribute; @@ -64,11 +65,30 @@ public class Attribute { return method == null ? String.class : method.getReturnType(); } + @InternalApi public boolean isAttributeDeprecated() { return method != null && (method.isAnnotationPresent(Deprecated.class) || method.isAnnotationPresent(DeprecatedAttribute.class)); } + /** + * Returns null for "not deprecated", empty string for "deprecated for removal", + * otherwise name of replacement attribute. + */ + @InternalApi + public String replacementIfDeprecated() { + if (method == null) { + return null; + } else { + DeprecatedAttribute annot = method.getAnnotation(DeprecatedAttribute.class); + if (annot == null) { + return method.isAnnotationPresent(Deprecated.class) ? DeprecatedAttribute.NO_REPLACEMENT + : null; + } + return annot.replaceWith(); + } + } + public Object getValue() { if (value != null) { return value.get(0); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/internal/DeprecatedAttrLogger.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/internal/DeprecatedAttrLogger.java index 3dd180f211..22a9a64d4a 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/internal/DeprecatedAttrLogger.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/internal/DeprecatedAttrLogger.java @@ -64,12 +64,17 @@ public abstract class DeprecatedAttrLogger { @Override public void recordUsageOf(Attribute attribute) { - if (attribute.isAttributeDeprecated()) { + String replacement = attribute.replacementIfDeprecated(); + if (replacement != null) { String name = getLoggableAttributeName(attribute); Boolean b = deprecated.putIfAbsent(name, Boolean.TRUE); if (b == null) { // this message needs to be kept in sync with PMDCoverageTest / BinaryDistributionIT - LOG.warning("Use of deprecated attribute '" + name + "' by rule " + ruleToString()); + String msg = "Use of deprecated attribute '" + name + "' by rule " + ruleToString(); + if (!replacement.isEmpty()) { + msg += ", please use " + replacement + " instead"; + } + LOG.warning(msg); } } } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/internal/DeprecatedAttribute.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/internal/DeprecatedAttribute.java index 75e80d4f5f..cb443d35ae 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/internal/DeprecatedAttribute.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/internal/DeprecatedAttribute.java @@ -22,4 +22,13 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface DeprecatedAttribute { + + String NO_REPLACEMENT = ""; + + + /** + * The simple name of the attribute to use for replacement. + * If empty, then the attribute is deprecated for removal. + */ + String replaceWith() default NO_REPLACEMENT; } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/AttributeNode.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/AttributeNode.java index 9da1b6753c..7a919967ef 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/AttributeNode.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/AttributeNode.java @@ -53,11 +53,6 @@ public class AttributeNode extends BaseNodeInfo { : parent.document.getAttrCtx(); } - @Override - public ElementNode getParent() { - return parent; - } - @Override public Value atomize() { getAttrCtx().recordUsageOf(attribute); diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTAdditiveExpression.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTAdditiveExpression.java index b2176402ff..9d6c995cb9 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTAdditiveExpression.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTAdditiveExpression.java @@ -5,6 +5,7 @@ package net.sourceforge.pmd.lang.java.ast; import net.sourceforge.pmd.annotation.InternalApi; +import net.sourceforge.pmd.lang.ast.xpath.internal.DeprecatedAttribute; /** * Represents an addition operation on two or more values, or string concatenation. @@ -40,6 +41,16 @@ public class ASTAdditiveExpression extends AbstractJavaTypeNode { } + /** + * @deprecated Use {@link #getOperator()} + */ + @Override + @Deprecated + @DeprecatedAttribute(replaceWith = "@Operator") + public String getImage() { + return super.getImage(); + } + /** * Returns the image of the operator, i.e. "+" or "-". */ diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTAnyTypeDeclaration.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTAnyTypeDeclaration.java index 2c39b1dbf8..d672a49046 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTAnyTypeDeclaration.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTAnyTypeDeclaration.java @@ -7,6 +7,7 @@ package net.sourceforge.pmd.lang.java.ast; import java.util.List; import java.util.Locale; +import net.sourceforge.pmd.lang.ast.xpath.internal.DeprecatedAttribute; import net.sourceforge.pmd.lang.java.ast.internal.PrettyPrintingUtil; import net.sourceforge.pmd.lang.java.qname.JavaTypeQualifiedName; @@ -32,6 +33,7 @@ public interface ASTAnyTypeDeclaration extends TypeNode, JavaQualifiableNode, Ac * @deprecated Use {@link #getSimpleName()} */ @Deprecated + @DeprecatedAttribute(replaceWith = "@SimpleName") @Override String getImage(); From f3db39641a393f050bc93457266f1e8f60df097a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Fri, 17 Apr 2020 20:28:00 +0200 Subject: [PATCH 35/49] Test with ASTVariableDeclaratorId#getName --- .../xpath/internal/DeprecatedAttrLogger.java | 5 ++++- .../xpath/internal/DeprecatedAttribute.java | 2 +- .../lang/java/ast/ASTMethodDeclaration.java | 2 ++ .../lang/java/ast/ASTMethodDeclarator.java | 3 +++ .../java/ast/ASTVariableDeclaratorId.java | 22 ++++++++++++++++++- 5 files changed, 31 insertions(+), 3 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/internal/DeprecatedAttrLogger.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/internal/DeprecatedAttrLogger.java index 22a9a64d4a..5b7993d78c 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/internal/DeprecatedAttrLogger.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/internal/DeprecatedAttrLogger.java @@ -74,7 +74,10 @@ public abstract class DeprecatedAttrLogger { if (!replacement.isEmpty()) { msg += ", please use " + replacement + " instead"; } - LOG.warning(msg); + // ok this circumvents the logger, because otherwise + // messages get lost in ugly header lines + System.err.println("WARNING: " + msg); + // LOG.warning(msg); } } } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/internal/DeprecatedAttribute.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/internal/DeprecatedAttribute.java index cb443d35ae..430cf5dd73 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/internal/DeprecatedAttribute.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/internal/DeprecatedAttribute.java @@ -27,7 +27,7 @@ public @interface DeprecatedAttribute { /** - * The simple name of the attribute to use for replacement. + * The simple name of the attribute to use for replacement (with '@' prefix). * If empty, then the attribute is deprecated for removal. */ String replaceWith() default NO_REPLACEMENT; diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTMethodDeclaration.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTMethodDeclaration.java index fe39f9db94..3715ac4a7f 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTMethodDeclaration.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTMethodDeclaration.java @@ -6,6 +6,7 @@ package net.sourceforge.pmd.lang.java.ast; import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.ast.Node; +import net.sourceforge.pmd.lang.ast.xpath.internal.DeprecatedAttribute; import net.sourceforge.pmd.lang.dfa.DFAGraphMethod; @@ -42,6 +43,7 @@ public class ASTMethodDeclaration extends AbstractMethodOrConstructorDeclaration * @deprecated Use {@link #getName()} */ @Deprecated + @DeprecatedAttribute(replaceWith = "@Name") public String getMethodName() { return getName(); } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTMethodDeclarator.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTMethodDeclarator.java index c8f17b95ab..be6ad8216d 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTMethodDeclarator.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTMethodDeclarator.java @@ -5,6 +5,7 @@ package net.sourceforge.pmd.lang.java.ast; import net.sourceforge.pmd.annotation.InternalApi; +import net.sourceforge.pmd.lang.ast.xpath.internal.DeprecatedAttribute; /** * @deprecated This node will be removed with 7.0.0. You @@ -29,6 +30,7 @@ public class ASTMethodDeclarator extends AbstractJavaNode { /** * @deprecated Use {@link ASTMethodDeclaration#getArity()} */ + @DeprecatedAttribute(replaceWith = "MethodDeclaration/@Arity") @Deprecated public int getParameterCount() { return getFirstChildOfType(ASTFormalParameters.class).size(); @@ -38,6 +40,7 @@ public class ASTMethodDeclarator extends AbstractJavaNode { * @deprecated Use {@link ASTMethodDeclaration#getName()} */ @Deprecated + @DeprecatedAttribute(replaceWith = "MethodDeclaration/@Name") @Override public String getImage() { return super.getImage(); diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTVariableDeclaratorId.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTVariableDeclaratorId.java index a8f04258ab..cde67aa449 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTVariableDeclaratorId.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTVariableDeclaratorId.java @@ -9,6 +9,7 @@ import java.util.List; import net.sourceforge.pmd.annotation.Experimental; import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.ast.Node; +import net.sourceforge.pmd.lang.ast.xpath.internal.DeprecatedAttribute; import net.sourceforge.pmd.lang.java.symboltable.VariableNameDeclaration; import net.sourceforge.pmd.lang.symboltable.NameOccurrence; @@ -98,6 +99,21 @@ public class ASTVariableDeclaratorId extends AbstractJavaTypeNode implements Dim return arrayDepth > 0; } + /** + * @deprecated Use {@link #getName()} + * @return + */ + @Override + @DeprecatedAttribute(replaceWith = "@Name") + @Deprecated + public String getImage() { + return super.getImage(); + } + + /** Returns the name of the variable. */ + public String getName() { + return getImage(); + } /** * Returns true if the declared variable has an array type. @@ -161,9 +177,13 @@ public class ASTVariableDeclaratorId extends AbstractJavaTypeNode implements Dim /** * Returns the name of the variable. + * + * @deprecated Use {@link #getName()} */ + @Deprecated + @DeprecatedAttribute(replaceWith = "@Name") public String getVariableName() { - return getImage(); + return getName(); } From e2ec5450ffe69103fad814bfbed2d16dcad5b081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Fri, 17 Apr 2020 20:31:09 +0200 Subject: [PATCH 36/49] Update rules WARNING: Use of deprecated attribute 'VariableDeclaratorId/@Image' by rule Error Prone/AvoidEnumAsIdentifier, please use @Name instead WARNING: Use of deprecated attribute 'VariableDeclaratorId/@Image' by rule Error Prone/AvoidAssertAsIdentifier, please use @Name instead WARNING: Use of deprecated attribute 'VariableDeclaratorId/@Image' by rule Error Prone/ProperLogger, please use @Name instead WARNING: Use of deprecated attribute 'VariableDeclaratorId/@Image' by rule Error Prone/JumbledIncrementer, please use @Name instead WARNING: Use of deprecated attribute 'VariableDeclaratorId/@Image' by rule Error Prone/AvoidLosingExceptionInformation, please use @Name instead WARNING: Use of deprecated attribute 'VariableDeclaratorId/@Image' by rule Error Prone/EmptyCatchBlock, please use @Name instead --- .../resources/category/java/codestyle.xml | 4 ++-- .../resources/category/java/errorprone.xml | 24 +++++++++---------- .../resources/category/java/performance.xml | 6 ++--- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/pmd-java/src/main/resources/category/java/codestyle.xml b/pmd-java/src/main/resources/category/java/codestyle.xml index 57d59a88bd..4de7330e0d 100644 --- a/pmd-java/src/main/resources/category/java/codestyle.xml +++ b/pmd-java/src/main/resources/category/java/codestyle.xml @@ -1236,7 +1236,7 @@ Fields, formal arguments, or local variable names that are too long can make the $minimum] +//VariableDeclaratorId[string-length(@Name) > $minimum] ]]> @@ -1704,7 +1704,7 @@ Fields, local variables, or parameter names that are very short are not helpful - //VariableDeclaratorId[@Image='assert'] + //VariableDeclaratorId[@Name='assert']
@@ -347,7 +347,7 @@ Use of the term 'enum' will conflict with newer versions of Java since it is a r - //VariableDeclaratorId[@Image='enum'] + //VariableDeclaratorId[@Name='enum'] @@ -546,15 +546,15 @@ only add to code size. Either remove the invocation, or use the return result.
@@ -1487,7 +1487,7 @@ or reported. [FormalParameter/Type/ReferenceType /ClassOrInterfaceType[@Image != 'InterruptedException' and @Image != 'CloneNotSupportedException'] ] - [FormalParameter/VariableDeclaratorId[not(matches(@Image, $allowExceptionNameRegex))]] + [FormalParameter/VariableDeclaratorId[not(matches(@Name, $allowExceptionNameRegex))]] ]]>
@@ -2147,7 +2147,7 @@ Avoid jumbled loop incrementers - its usually a mistake, and is confusing even i [ ForUpdate/StatementExpressionList/StatementExpression/PostfixExpression/PrimaryExpression/PrimaryPrefix/Name/@Image = - ancestor::ForStatement/ForInit//VariableDeclaratorId/@Image + ancestor::ForStatement/ForInit//VariableDeclaratorId/@Name ] ]]>
@@ -2702,8 +2702,8 @@ with the restriction that the logger needs to be passed into the constructor. (: check modifiers :) (@Private = false() or @Final = false()) (: check logger name :) - or (@Static and VariableDeclarator/VariableDeclaratorId[@Image != $staticLoggerName]) - or (@Static = false() and VariableDeclarator/VariableDeclaratorId[@Image != $loggerName]) + or (@Static and VariableDeclarator/VariableDeclaratorId[@Name != $staticLoggerName]) + or (@Static = false() and VariableDeclarator/VariableDeclaratorId[@Name != $loggerName]) (: check logger argument type matches class or enum name :) or .//ArgumentList//ClassOrInterfaceType[@Image != ancestor::ClassOrInterfaceDeclaration/@SimpleName] @@ -2717,7 +2717,7 @@ with the restriction that the logger needs to be passed into the constructor. ancestor::ClassOrInterfaceBody//ConstructorDeclaration//StatementExpression [PrimaryExpression[PrimaryPrefix[@ThisModifier]]/PrimarySuffix[@Image=$loggerName]] [AssignmentOperator[@Image = '=']] - [Expression/PrimaryExpression/PrimaryPrefix/Name[@Image = ancestor::ConstructorDeclaration//FormalParameter/VariableDeclaratorId/@Image]] + [Expression/PrimaryExpression/PrimaryPrefix/Name[@Image = ancestor::ConstructorDeclaration//FormalParameter/VariableDeclaratorId/@Name]] [not(.//AllocationExpression)] ) ] diff --git a/pmd-java/src/main/resources/category/java/performance.xml b/pmd-java/src/main/resources/category/java/performance.xml index 9afd4f220b..8213f85f83 100644 --- a/pmd-java/src/main/resources/category/java/performance.xml +++ b/pmd-java/src/main/resources/category/java/performance.xml @@ -878,14 +878,14 @@ You must use new ArrayList<>(Arrays.asList(...)) if that is inconvenient for you @Image="ArrayList" ] )=1 - ]/@Image + ]/@Name ] and PrimaryExpression/PrimarySuffix/Arguments/ArgumentList/Expression/PrimaryExpression/PrimaryPrefix/Name [ - @Image = ancestor::MethodDeclaration[1]//LocalVariableDeclaration/VariableDeclarator/VariableDeclaratorId[@ArrayType=true()]/@Image + @Image = ancestor::MethodDeclaration[1]//LocalVariableDeclaration/VariableDeclarator/VariableDeclaratorId[@ArrayType=true()]/@Name or - @Image = ancestor::MethodDeclaration[1]//FormalParameter/VariableDeclaratorId/@Image + @Image = ancestor::MethodDeclaration[1]//FormalParameter/VariableDeclaratorId/@Name ] /../..[count(.//PrimarySuffix) =1]/PrimarySuffix/Expression/PrimaryExpression/PrimaryPrefix From be19da5a07557677293b5dc080b19360f62e6672 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Fri, 17 Apr 2020 20:38:40 +0200 Subject: [PATCH 37/49] Test in pmd-core --- .../pmd/lang/ast/xpath/Attribute.java | 18 ++++++------------ .../xpath/internal/DeprecatedAttrLogger.java | 11 ++++------- .../ast/DummyNodeWithDeprecatedAttribute.java | 2 +- .../pmd/lang/rule/XPathRuleTest.java | 8 ++++---- 4 files changed, 15 insertions(+), 24 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/Attribute.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/Attribute.java index 8c9ed3e59d..7f4573ce97 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/Attribute.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/Attribute.java @@ -65,14 +65,8 @@ public class Attribute { return method == null ? String.class : method.getReturnType(); } - @InternalApi - public boolean isAttributeDeprecated() { - return method != null && (method.isAnnotationPresent(Deprecated.class) - || method.isAnnotationPresent(DeprecatedAttribute.class)); - } - /** - * Returns null for "not deprecated", empty string for "deprecated for removal", + * Returns null for "not deprecated", empty string for "deprecated without replacement", * otherwise name of replacement attribute. */ @InternalApi @@ -81,11 +75,11 @@ public class Attribute { return null; } else { DeprecatedAttribute annot = method.getAnnotation(DeprecatedAttribute.class); - if (annot == null) { - return method.isAnnotationPresent(Deprecated.class) ? DeprecatedAttribute.NO_REPLACEMENT - : null; - } - return annot.replaceWith(); + return annot != null + ? annot.replaceWith() + : method.isAnnotationPresent(Deprecated.class) + ? DeprecatedAttribute.NO_REPLACEMENT + : null; } } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/internal/DeprecatedAttrLogger.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/internal/DeprecatedAttrLogger.java index 5b7993d78c..b0501e7a78 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/internal/DeprecatedAttrLogger.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/internal/DeprecatedAttrLogger.java @@ -70,14 +70,11 @@ public abstract class DeprecatedAttrLogger { Boolean b = deprecated.putIfAbsent(name, Boolean.TRUE); if (b == null) { // this message needs to be kept in sync with PMDCoverageTest / BinaryDistributionIT - String msg = "Use of deprecated attribute '" + name + "' by rule " + ruleToString(); + String msg = "Use of deprecated attribute '" + name + "' by XPath rule " + ruleToString(); if (!replacement.isEmpty()) { msg += ", please use " + replacement + " instead"; } - // ok this circumvents the logger, because otherwise - // messages get lost in ugly header lines - System.err.println("WARNING: " + msg); - // LOG.warning(msg); + LOG.warning(msg); } } } @@ -85,9 +82,9 @@ public abstract class DeprecatedAttrLogger { public String ruleToString() { // we can't compute that beforehand because the name is set // outside of the rule constructor - String name = rule.getName(); + String name = "'" + rule.getName() + "'"; if (rule.getRuleSetName() != null) { - name = rule.getRuleSetName() + "/" + name; + name += " (in ruleset '" + rule.getRuleSetName() + "')"; } return name; } diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/DummyNodeWithDeprecatedAttribute.java b/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/DummyNodeWithDeprecatedAttribute.java index 7deca9984b..0e5dd20606 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/DummyNodeWithDeprecatedAttribute.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/DummyNodeWithDeprecatedAttribute.java @@ -25,7 +25,7 @@ public class DummyNodeWithDeprecatedAttribute extends DummyNode { // this is a attribute that is deprecated for xpath, because it will be removed. // it should still be available via Java. - @DeprecatedAttribute + @DeprecatedAttribute(replaceWith = "@Image") public String getName() { return "foo"; } diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/XPathRuleTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/XPathRuleTest.java index 9d906d7708..07605202d5 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/XPathRuleTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/XPathRuleTest.java @@ -68,8 +68,8 @@ public class XPathRuleTest { assertEquals(1, ctx.getReport().size()); String log = loggingRule.getLog(); - assertThat(log, Matchers.containsString("Use of deprecated attribute 'dummyNode/@Size' by rule SomeRule")); - assertThat(log, Matchers.containsString("Use of deprecated attribute 'dummyNode/@Name' by rule SomeRule")); + assertThat(log, Matchers.containsString("Use of deprecated attribute 'dummyNode/@Size' by XPath rule 'SomeRule'")); + assertThat(log, Matchers.containsString("Use of deprecated attribute 'dummyNode/@Name' by XPath rule 'SomeRule', please use @Image instead")); loggingRule.clear(); @@ -93,8 +93,8 @@ public class XPathRuleTest { assertEquals(4, ctx.getReport().size()); log = loggingRule.getLog(); - assertThat(log, Matchers.containsString("Use of deprecated attribute 'dummyNode/@Size' by rule rset.xml/OtherRule")); - assertThat(log, Matchers.containsString("Use of deprecated attribute 'dummyNode/@Name' by rule rset.xml/OtherRule")); + assertThat(log, Matchers.containsString("Use of deprecated attribute 'dummyNode/@Size' by XPath rule 'OtherRule' (in ruleset 'rset.xml')")); + assertThat(log, Matchers.containsString("Use of deprecated attribute 'dummyNode/@Name' by XPath rule 'OtherRule' (in ruleset 'rset.xml'), please use @Image instead")); } From 9c98508fec572dd8b489a622a27ef1b34ad71a3a Mon Sep 17 00:00:00 2001 From: Harsh Kukreja Date: Sat, 18 Apr 2020 02:34:14 +0530 Subject: [PATCH 38/49] Operator Wrap Issue Solved --- .../java/net/sourceforge/pmd/cpd/AbstractTokenizer.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/AbstractTokenizer.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/AbstractTokenizer.java index 87c5acb924..66870ef1ef 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/AbstractTokenizer.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/AbstractTokenizer.java @@ -117,14 +117,14 @@ public abstract class AbstractTokenizer implements Tokenizer { loc++; } // Handling multiple lines string - if (!done && // ... we didn't find the end of the string - loc >= currentLine.length() && // ... we have reach the end of + if (!done // ... we didn't find the end of the string + && loc >= currentLine.length() // ... we have reach the end of // the line ( the String is // incomplete, for the moment at // least) - spanMultipleLinesString && // ... the language allow multiple + && spanMultipleLinesString // ... the language allow multiple // line span Strings - lineNumber < code.size() - 1 // ... there is still more lines to + && lineNumber < code.size() - 1 // ... there is still more lines to // parse ) { // removes last character, if it is the line continuation (e.g. From 9caadee7640e9dbff25af5d0008f1d7b3b589f6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sat, 18 Apr 2020 01:53:44 +0200 Subject: [PATCH 39/49] Update release notes, refs #2423 --- docs/pages/release_notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 320b997bb8..5f1a7eebc0 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -150,6 +150,7 @@ implementations, and their corresponding Parser if it exists (in the same packag * [#2403](https://github.com/pmd/pmd/pull/2403): \[java] #2402 fix false-positives on Primitive Streams - [Bernd Farka](https://github.com/BerndFarkaDyna) * [#2409](https://github.com/pmd/pmd/pull/2409): \[java] ClassNamingConventions suggests to add Util for class containing only static constants, fixes #1164 - [Binu R J](https://github.com/binu-r) * [#2411](https://github.com/pmd/pmd/pull/2411): \[java] Fix UseAssertEqualsInsteadOfAssertTrue Example - [Moritz Scheve](https://github.com/Blightbuster) +* [#2423](https://github.com/pmd/pmd/pull/2423): \[core] Fix Checkstyle OperatorWrap in AbstractTokenizer - [Harsh Kukreja](https://github.com/harsh-kukreja) {% endtocmaker %} From 4db656a6795b292199f2f4ad35825c4df1f6800e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sat, 18 Apr 2020 01:56:10 +0200 Subject: [PATCH 40/49] Cleanup --- .../pmd/cpd/AbstractTokenizer.java | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/AbstractTokenizer.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/AbstractTokenizer.java index 66870ef1ef..a79aee80d4 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/AbstractTokenizer.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/AbstractTokenizer.java @@ -99,7 +99,7 @@ public abstract class AbstractTokenizer implements Tokenizer { private int parseString(StringBuilder token, int loc, char stringDelimiter) { boolean escaped = false; boolean done = false; - char tok = ' '; // this will be replaced. + char tok; while (loc < currentLine.length() && !done) { tok = currentLine.charAt(loc); if (escaped && tok == stringDelimiter) { // Found an escaped string @@ -107,30 +107,24 @@ public abstract class AbstractTokenizer implements Tokenizer { } else if (tok == stringDelimiter && token.length() > 0) { // We are done, we found the end of the string... done = true; - } else if (tok == '\\') { // Found an escaped char - escaped = true; - } else { // Adding char... - escaped = false; + } else { + // Found an escaped char? + escaped = tok == '\\'; } // Adding char to String:" + token.toString()); token.append(tok); loc++; } // Handling multiple lines string - if (!done // ... we didn't find the end of the string - && loc >= currentLine.length() // ... we have reach the end of - // the line ( the String is - // incomplete, for the moment at - // least) - && spanMultipleLinesString // ... the language allow multiple - // line span Strings - && lineNumber < code.size() - 1 // ... there is still more lines to - // parse + if (!done // ... we didn't find the end of the string (but the end of the line) + && spanMultipleLinesString // ... the language allow multiple line span Strings + && lineNumber < code.size() - 1 // ... there is still more lines to parse ) { // removes last character, if it is the line continuation (e.g. // backslash) character - if (spanMultipleLinesLineContinuationCharacter != null && token.length() > 0 - && token.charAt(token.length() - 1) == spanMultipleLinesLineContinuationCharacter.charValue()) { + if (spanMultipleLinesLineContinuationCharacter != null + && token.length() > 0 + && token.charAt(token.length() - 1) == spanMultipleLinesLineContinuationCharacter) { token.deleteCharAt(token.length() - 1); } // parsing new line From 815c87bd17b62a4c59aff29f2f32a0a2523733a9 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 18 Apr 2020 10:28:37 +0200 Subject: [PATCH 41/49] Add simple stats for releases --- do-release.sh | 38 ++++++++++++++++--- .../pmd/projectdocs/committers/releasing.md | 19 ++++++++++ 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/do-release.sh b/do-release.sh index 614c8f12c4..f276238301 100755 --- a/do-release.sh +++ b/do-release.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -e # Make sure, everything is English... @@ -15,7 +15,7 @@ if [ ! -f pom.xml -o ! -d ../pmd.github.io ]; then exit 1 fi - +LAST_VERSION= RELEASE_VERSION= DEVELOPMENT_VERSION= CURRENT_BRANCH= @@ -33,11 +33,16 @@ PATCH=$(echo $RELEASE_VERSION | cut -d . -f 3) if [ "$PATCH" == "0" ]; then NEXT_MINOR=$(expr ${MINOR} + 1) NEXT_PATCH="0" + LAST_MINOR=$(expr ${MINOR} - 1) + LAST_PATCH="0" else # this is a bugfixing release NEXT_MINOR="${MINOR}" NEXT_PATCH=$(expr ${PATCH} + 1) + LAST_MINOR="${MINOR}" + LAST_PATCH=$(expr ${PATCH} - 1) fi +LAST_VERSION="$MAJOR.$LAST_MINOR.$LAST_PATCH" DEVELOPMENT_VERSION="$MAJOR.$NEXT_MINOR.$NEXT_PATCH" DEVELOPMENT_VERSION="${DEVELOPMENT_VERSION}-SNAPSHOT" @@ -52,17 +57,18 @@ CURRENT_BRANCH=$(git symbolic-ref -q HEAD) CURRENT_BRANCH=${CURRENT_BRANCH##refs/heads/} CURRENT_BRANCH=${CURRENT_BRANCH:-HEAD} -echo "RELEASE_VERSION: ${RELEASE_VERSION}" -echo "DEVELOPMENT_VERSION: ${DEVELOPMENT_VERSION}" +echo "LAST_VERSION: ${LAST_VERSION}" +echo "RELEASE_VERSION: ${RELEASE_VERSION} (this release)" +echo "DEVELOPMENT_VERSION: ${DEVELOPMENT_VERSION} (the next version after the release)" echo "CURRENT_BRANCH: ${CURRENT_BRANCH}" echo echo "Is this correct?" echo -echo "Press enter to continue..." +echo "Press enter to continue... (or CTRL+C to cancel)" read - +export LAST_VERSION export RELEASE_VERSION export DEVELOPMENT_VERSION export CURRENT_BRANCH @@ -89,6 +95,26 @@ echo echo "Press enter to continue..." read + +# calculating stats for release notes + +STATS=$( +echo "### Stats" +echo "* $(git log pmd_releases/${LAST_VERSION}..HEAD --oneline --no-merges |wc -l) commits" +echo "* $(curl -s https://api.github.com/repos/pmd/pmd/milestones|jq ".[] | select(.title == \"$RELEASE_VERSION\") | .closed_issues") closed tickets & PRs" +echo "* Days since last release: $(( ( $(date +%s) - $(git log --max-count=1 --format="%at" pmd_releases/${LAST_VERSION}) ) / 86400))" +) + +TEMP_RELEASE_NOTES=$(cat docs/pages/release_notes.md) +TEMP_RELEASE_NOTES=${TEMP_RELEASE_NOTES/\{\% endtocmaker \%\}/$STATS$'\n'$'\n'\{\% endtocmaker \%\}$'\n'} +echo "${TEMP_RELEASE_NOTES}" > docs/pages/release_notes.md + +echo +echo "Updated stats in release notes:" +echo "$STATS" +echo +echo + # install bundles needed for rendering release notes bundle install --with=release_notes_preprocessing --path vendor/bundle diff --git a/docs/pages/pmd/projectdocs/committers/releasing.md b/docs/pages/pmd/projectdocs/committers/releasing.md index 0951ac7e16..f8966a7730 100644 --- a/docs/pages/pmd/projectdocs/committers/releasing.md +++ b/docs/pages/pmd/projectdocs/committers/releasing.md @@ -53,6 +53,25 @@ The designer lives at [pmd/pmd-designer](https://github.com/pmd/pmd-designer). Update property `pmd-designer.version` in **pom.xml** to reference the latest pmd-designer release. See for the available releases. +Starting with PMD 6.23.0 we'll provide small statistics for every release. This needs to be added +to the release notes as the last section. To count the closed issues and pull requests, the milestone +on github with the title of the new release is searched. Make sure, there is a milestone +on . The following snippet will +create the numbers, that can be attached to the release notes as a last section: + +```shell +LAST_VERSION=6.22.0 +NEW_VERSION=6.23.0 +NEW_VERSION_COMMITISH=HEAD + +echo "### Stats" +echo "* $(git log pmd_releases/${LAST_VERSION}..${NEW_VERSION_COMMITISH} --oneline --no-merges |wc -l) commits" +echo "* $(curl -s https://api.github.com/repos/pmd/pmd/milestones|jq ".[] | select(.title == \"$NEW_VERSION\") | .closed_issues") closed tickets & PRs" +echo "* Days since last release: $(( ( $(date +%s) - $(git log --max-count=1 --format="%at" pmd_releases/${LAST_VERSION}) ) / 86400))" +``` + +Note: this part is also integrated into `do-release.sh`. + Check in all (version) changes to branch master or any other branch, from which the release takes place: $ git commit -a -m "Prepare pmd release " From 2da636305e06500eaf7e530212ca9d772940ee68 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 18 Apr 2020 10:34:21 +0200 Subject: [PATCH 42/49] Update pull request template --- .github/PULL_REQUEST_TEMPLATE.md | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 6d529e9e99..a1c9a7bd37 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,10 +1,19 @@ - +## Describe the PR -Before submitting a PR, please check that: - - [ ] The PR is submitted against `master`. The PMD team will merge back to support branches as needed. - - [ ] `./mvnw clean verify` passes. This will [build](https://github.com/pmd/pmd/blob/master/BUILDING.md) and test PMD, execute PMD and checkstyle rules. [Check this for more info](https://github.com/pmd/pmd/blob/master/CONTRIBUTING.md#code-style) + -**PR Description:** +## Related issues + + + +- Fixes # + +## Ready? + + + +- [ ] Added unit tests for fixed bug/feature +- [ ] Passing all unit tests +- [ ] Complete build `./mvnw clean verify` passes (checked automatically by travis) +- [ ] Added (in-code) documentation (if needed) From 054b3acf6735c44f18a608af78d7c49177779b94 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 18 Apr 2020 11:49:37 +0200 Subject: [PATCH 43/49] [doc] Update release notes, fixes #2398 --- docs/pages/release_notes.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 794293b75c..4e45593dd7 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -50,6 +50,8 @@ Note that XPath 1.0 support, the default XPath version, is deprecated since PMD * [#2356](https://github.com/pmd/pmd/issues/2356): \[doc] Add missing doc about pmd.github.io * java * [#2378](https://github.com/pmd/pmd/issues/2378): \[java] AbstractJUnitRule has bad performance on large code bases +* java-bestpractices + * [#2398](https://github.com/pmd/pmd/issues/2398): \[java] AbstractClassWithoutAbstractMethod false negative with inner abstract classes * java-codestyle * [#1164](https://github.com/pmd/pmd/issues/1164): \[java] ClassNamingConventions suggests to add Util for class containing only static constants * [#1723](https://github.com/pmd/pmd/issues/1723): \[java] UseDiamondOperator false-positive inside lambda From 400ca5dca5a52bdc93de17b0e06290f640914bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sat, 18 Apr 2020 17:42:56 +0200 Subject: [PATCH 44/49] Delete test for findChildNodesWithXPath --- .../pmd/lang/ast/AbstractNodeTest.java | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/AbstractNodeTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/AbstractNodeTest.java index b5ece64c46..64136ef446 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/AbstractNodeTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/AbstractNodeTest.java @@ -6,10 +6,8 @@ package net.sourceforge.pmd.lang.ast; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import org.jaxen.JaxenException; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -228,24 +226,4 @@ public class AbstractNodeTest { assertEquals(0, grandChild.getNumChildren()); } - - @Test - public void testDeprecatedAttributeXPathQuery() throws JaxenException { - class MyRootNode extends DummyNode implements RootNode { - - private MyRootNode(int id) { - super(id); - } - } - - addChild(new MyRootNode(nextId()), new DummyNodeWithDeprecatedAttribute(2)).findChildNodesWithXPath("//dummyNode[@Size=1]"); - - String log = loggingRule.getLog(); - - assertTrue(log.contains("deprecated")); - assertTrue(log.contains("attribute")); - assertTrue(log.contains("dummyNode/@Size")); - } - - } From 4a9aa1a926ae07cc6b9dd4e4424eb02c17551278 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 18 Apr 2020 17:43:18 +0200 Subject: [PATCH 45/49] [core] Log deprecated attribute usage in findChildNodesWithXPath queries --- .../pmd/lang/ast/AbstractNode.java | 5 +++- .../internal/ContextualizedNavigator.java | 1 + .../xpath/internal/DeprecatedAttrLogger.java | 25 +++++++++++++++++++ .../pmd/lang/ast/AbstractNodeTest.java | 3 ++- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/AbstractNode.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/AbstractNode.java index c14ede1d12..2f8d3eb78c 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/AbstractNode.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/AbstractNode.java @@ -25,6 +25,8 @@ import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.ast.xpath.Attribute; import net.sourceforge.pmd.lang.ast.xpath.AttributeAxisIterator; import net.sourceforge.pmd.lang.ast.xpath.DocumentNavigator; +import net.sourceforge.pmd.lang.ast.xpath.internal.ContextualizedNavigator; +import net.sourceforge.pmd.lang.ast.xpath.internal.DeprecatedAttrLogger; import net.sourceforge.pmd.lang.dfa.DataFlowNode; import net.sourceforge.pmd.util.DataMap; import net.sourceforge.pmd.util.DataMap.DataKey; @@ -513,7 +515,8 @@ public abstract class AbstractNode implements Node { @Override @SuppressWarnings("unchecked") public List findChildNodesWithXPath(final String xpathString) throws JaxenException { - return new BaseXPath(xpathString, new DocumentNavigator()).selectNodes(this); + return new BaseXPath(xpathString, new ContextualizedNavigator(DeprecatedAttrLogger.createAdHocLogger())) + .selectNodes(this); } @Override diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/internal/ContextualizedNavigator.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/internal/ContextualizedNavigator.java index f48dc03031..358d7d7ce7 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/internal/ContextualizedNavigator.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/internal/ContextualizedNavigator.java @@ -1,6 +1,7 @@ /* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ + package net.sourceforge.pmd.lang.ast.xpath.internal; import net.sourceforge.pmd.lang.ast.xpath.Attribute; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/internal/DeprecatedAttrLogger.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/internal/DeprecatedAttrLogger.java index b0501e7a78..e6c2358a06 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/internal/DeprecatedAttrLogger.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/internal/DeprecatedAttrLogger.java @@ -35,6 +35,14 @@ public abstract class DeprecatedAttrLogger { } } + public static DeprecatedAttrLogger createAdHocLogger() { + if (LOG.isLoggable(Level.WARNING)) { + return new AdhocLoggerImpl(); + } else { + return noop(); + } + } + public static Noop noop() { return Noop.INSTANCE; } @@ -89,4 +97,21 @@ public abstract class DeprecatedAttrLogger { return name; } } + + private static class AdhocLoggerImpl extends DeprecatedAttrLogger { + @Override + public void recordUsageOf(Attribute attribute) { + String replacement = attribute.replacementIfDeprecated(); + if (replacement != null) { + String name = getLoggableAttributeName(attribute); + // this message needs to be kept in sync with PMDCoverageTest / BinaryDistributionIT + String msg = "Use of deprecated attribute '" + name + "' in a findChildNodesWithXPath navigation"; + if (!replacement.isEmpty()) { + msg += ", please use " + replacement + " instead"; + } + // log with execption stack trace to help figure out where exactly the xpath is used. + LOG.log(Level.WARNING, msg, new RuntimeException(msg)); + } + } + } } diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/AbstractNodeTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/AbstractNodeTest.java index b5ece64c46..5cc793c267 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/AbstractNodeTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/AbstractNodeTest.java @@ -238,7 +238,8 @@ public class AbstractNodeTest { } } - addChild(new MyRootNode(nextId()), new DummyNodeWithDeprecatedAttribute(2)).findChildNodesWithXPath("//dummyNode[@Size=1]"); + Node root = addChild(new MyRootNode(nextId()), new DummyNodeWithDeprecatedAttribute(2)); + root.findChildNodesWithXPath("//dummyNode[@Size=1]"); String log = loggingRule.getLog(); From bcae7e52437da422ab85e97afd9230808f913b04 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 18 Apr 2020 18:10:05 +0200 Subject: [PATCH 46/49] Small corrections --- .../pmd/lang/ast/xpath/AttributeAxisIteratorTest.java | 2 +- .../pmd/lang/java/ast/ASTAdditiveExpression.java | 4 ++-- .../pmd/lang/java/ast/ASTVariableDeclaratorId.java | 4 ++-- .../pmd/lang/java/ast/AbstractAnyTypeDeclaration.java | 11 ++++++++--- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/xpath/AttributeAxisIteratorTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/xpath/AttributeAxisIteratorTest.java index d5697ed3bd..a1dda2cb58 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/xpath/AttributeAxisIteratorTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/xpath/AttributeAxisIteratorTest.java @@ -71,7 +71,7 @@ public class AttributeAxisIteratorTest { assertFalse(atts.containsKey("NodeList")); } - public Map toMap(AttributeAxisIterator it) { + private Map toMap(AttributeAxisIterator it) { Map atts = new HashMap<>(); while (it.hasNext()) { Attribute attribute = it.next(); diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTAdditiveExpression.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTAdditiveExpression.java index 9d6c995cb9..f60a30e32d 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTAdditiveExpression.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTAdditiveExpression.java @@ -48,13 +48,13 @@ public class ASTAdditiveExpression extends AbstractJavaTypeNode { @Deprecated @DeprecatedAttribute(replaceWith = "@Operator") public String getImage() { - return super.getImage(); + return getOperator(); } /** * Returns the image of the operator, i.e. "+" or "-". */ public String getOperator() { - return getImage(); + return super.getImage(); } } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTVariableDeclaratorId.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTVariableDeclaratorId.java index cde67aa449..f20ecb7034 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTVariableDeclaratorId.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTVariableDeclaratorId.java @@ -107,12 +107,12 @@ public class ASTVariableDeclaratorId extends AbstractJavaTypeNode implements Dim @DeprecatedAttribute(replaceWith = "@Name") @Deprecated public String getImage() { - return super.getImage(); + return getName(); } /** Returns the name of the variable. */ public String getName() { - return getImage(); + return super.getImage(); } /** diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AbstractAnyTypeDeclaration.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AbstractAnyTypeDeclaration.java index 4bd5fc0607..ed9076c669 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AbstractAnyTypeDeclaration.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AbstractAnyTypeDeclaration.java @@ -6,6 +6,7 @@ package net.sourceforge.pmd.lang.java.ast; import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.ast.Node; +import net.sourceforge.pmd.lang.ast.xpath.internal.DeprecatedAttribute; import net.sourceforge.pmd.lang.java.qname.JavaTypeQualifiedName; import net.sourceforge.pmd.lang.java.typeresolution.typedefinition.JavaTypeDefinition; @@ -37,10 +38,14 @@ public abstract class AbstractAnyTypeDeclaration extends AbstractJavaAccessTypeN || getParent() instanceof ASTRecordBody; } - @Override + /** + * @deprecated Use {@link #getSimpleName()} + */ @Deprecated + @DeprecatedAttribute(replaceWith = "@SimpleName") + @Override public String getImage() { - return super.getImage(); + return getSimpleName(); } @Override @@ -50,7 +55,7 @@ public abstract class AbstractAnyTypeDeclaration extends AbstractJavaAccessTypeN @Override public String getSimpleName() { - return getImage(); + return super.getImage(); } From 5cad2ff741b4dacc312d1769b9b5894f513e9035 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 18 Apr 2020 18:22:07 +0200 Subject: [PATCH 47/49] [doc] Update release notes, refs #2425, fixes #2019 --- docs/pages/release_notes.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 794293b75c..5b7f998098 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -46,6 +46,7 @@ Note that XPath 1.0 support, the default XPath version, is deprecated since PMD * [#2210](https://github.com/pmd/pmd/issues/2210): \[apex] ApexCRUDViolation: Support WITH SECURITY_ENFORCED * [#2399](https://github.com/pmd/pmd/issues/2399): \[apex] ApexCRUDViolation: false positive with security enforced with line break * core + * [#2019](https://github.com/pmd/pmd/issues/2019): \[core] Insufficient deprecation warnings for XPath attributes * [#2355](https://github.com/pmd/pmd/issues/2355): \[doc] Improve documentation about incremental analysis * [#2356](https://github.com/pmd/pmd/issues/2356): \[doc] Add missing doc about pmd.github.io * java @@ -123,6 +124,12 @@ implementations, and their corresponding Parser if it exists (in the same packag * {% jdoc matlab::lang.matlab.MatlabTokenManager %} * {% jdoc objectivec::lang.objectivec.ObjectiveCTokenManager %} +In the **Java AST** the following attributes are deprecated and will issue a warning when used in XPath rules: + +* {% jdoc !!java::lang.java.ast.ASTAdditiveExpression#getImage() %} - use `getOperator()` instead +* {% jdoc !!java::lang.java.ast.ASTVariableDeclaratorId#getImage() %} - use `getName()` instead +* {% jdoc !!java::lang.java.ast.ASTVariableDeclaratorId#getVariableName() %} - use `getName()` instead + ##### For removal * {% jdoc !!core::lang.Parser#getTokenManager(java.lang.String,java.io.Reader) %} From aee04b4c6890b3bf64236c8d7665ac31db9e4536 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 18 Apr 2020 19:06:29 +0200 Subject: [PATCH 48/49] [java] Fix more deprecated attribute usages --- .../ForLoopCanBeForeachRule.java | 2 +- .../resources/category/java/codestyle.xml | 8 ++--- .../main/resources/category/java/design.xml | 2 +- .../resources/category/java/errorprone.xml | 8 ++--- .../java/net/sourceforge/pmd/ReportTest.java | 2 +- .../pmd/lang/java/rule/XPathRuleTest.java | 12 ++++---- .../typeresolution/ClassTypeResolverTest.java | 29 ++++++++----------- .../xml/UnusedFormalParameter.xml | 2 +- 8 files changed, 30 insertions(+), 35 deletions(-) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/ForLoopCanBeForeachRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/ForLoopCanBeForeachRule.java index fccfd94132..fb7873371d 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/ForLoopCanBeForeachRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/ForLoopCanBeForeachRule.java @@ -229,7 +229,7 @@ public class ForLoopCanBeForeachRule extends AbstractJavaRule { + "/Name[matches(@Image,'\\w+\\.(size|length)')]" + "|" + "./RelationalExpression[@Image='<=']/AdditiveExpression[count(*)=2 and " - + "@Image='-' and PrimaryExpression/PrimaryPrefix/Literal[@Image='1']]" + + "@Operator='-' and PrimaryExpression/PrimaryPrefix/Literal[@Image='1']]" + "/PrimaryExpression/PrimaryPrefix/Name[matches(@Image,'\\w+\\.(size|length)')]"); if (left.isEmpty()) { diff --git a/pmd-java/src/main/resources/category/java/codestyle.xml b/pmd-java/src/main/resources/category/java/codestyle.xml index 4de7330e0d..e8995ca3a9 100644 --- a/pmd-java/src/main/resources/category/java/codestyle.xml +++ b/pmd-java/src/main/resources/category/java/codestyle.xml @@ -164,7 +164,7 @@ by the more general rule {% rule java/codestyle/FormalParameterNamingConventions @@ -1364,7 +1364,7 @@ by the more general rule @@ -1758,7 +1758,7 @@ by the more general rule {% rule java/codestyle/FieldNamingConventions %}. //ClassOrInterfaceDeclaration[@Interface= false()] /ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/FieldDeclaration [@Final= false()] - [VariableDeclarator/VariableDeclaratorId[upper-case(@Image)=@Image]] + [VariableDeclarator/VariableDeclaratorId[upper-case(@Name)=@Name]] ]]>
@@ -2067,7 +2067,7 @@ List stringsWithDiamond = new ArrayList<>(); // using the diamond operat /PrimaryExpression[1]/PrimaryPrefix/Expression[ count(*)=1 and not(./CastExpression) and - not(./AdditiveExpression[@Image = '-']) and + not(./AdditiveExpression[@Operator = '-']) and not(./ShiftExpression) and not(./RelationalExpression) and not(./InstanceOfExpression) and diff --git a/pmd-java/src/main/resources/category/java/design.xml b/pmd-java/src/main/resources/category/java/design.xml index fd13c4cf42..dba3f14cec 100644 --- a/pmd-java/src/main/resources/category/java/design.xml +++ b/pmd-java/src/main/resources/category/java/design.xml @@ -133,7 +133,7 @@ Catch blocks that merely rethrow a caught exception only add to code size and ru diff --git a/pmd-java/src/main/resources/category/java/errorprone.xml b/pmd-java/src/main/resources/category/java/errorprone.xml index 5b2b1f5929..07d265c0ba 100644 --- a/pmd-java/src/main/resources/category/java/errorprone.xml +++ b/pmd-java/src/main/resources/category/java/errorprone.xml @@ -422,7 +422,7 @@ Each caught exception type should be handled in its own catch clause. /following-sibling::Block//InstanceOfExpression/PrimaryExpression/PrimaryPrefix /Name[ @Image = ./ancestor::Block/preceding-sibling::FormalParameter - /VariableDeclaratorId/@Image + /VariableDeclaratorId/@Name ] ]]> @@ -2414,7 +2414,7 @@ chain needs an own serialVersionUID field. See also [Should an abstract class ha //ClassOrInterfaceDeclaration [@Interface = false()] [count(ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration - /FieldDeclaration/VariableDeclarator/VariableDeclaratorId[@Image='serialVersionUID']) = 0] + /FieldDeclaration/VariableDeclarator/VariableDeclaratorId[@Name='serialVersionUID']) = 0] [(ImplementsList | ExtendsList)/ClassOrInterfaceType[pmd-java:typeIs('java.io.Serializable')]] ]]>
@@ -3362,11 +3362,11 @@ To make sure the full stacktrace is printed out, use the logging statement with [starts-with(@Image, concat((ancestor::ClassOrInterfaceDeclaration/ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/FieldDeclaration [Type//ClassOrInterfaceType[@Image='Log']] - /VariableDeclarator/VariableDeclaratorId/@Image)[1], '.')) + /VariableDeclarator/VariableDeclaratorId/@Name)[1], '.')) ] ] [PrimarySuffix/Arguments[@Size= 1]] - [PrimarySuffix/Arguments//Name/@Image = ancestor::CatchStatement/FormalParameter/VariableDeclaratorId/@Image] + [PrimarySuffix/Arguments//Name/@Image = ancestor::CatchStatement/FormalParameter/VariableDeclaratorId/@Name] ]]>
diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/ReportTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/ReportTest.java index cac861109b..383d64cbde 100644 --- a/pmd-java/src/test/java/net/sourceforge/pmd/ReportTest.java +++ b/pmd-java/src/test/java/net/sourceforge/pmd/ReportTest.java @@ -40,7 +40,7 @@ public class ReportTest extends RuleTst { public void testExclusionsInReportWithRuleViolationSuppressXPath() { Report rpt = new Report(); Rule rule = new FooRule(); - rule.setProperty(Rule.VIOLATION_SUPPRESS_XPATH_DESCRIPTOR, ".[@Image = 'Foo']"); + rule.setProperty(Rule.VIOLATION_SUPPRESS_XPATH_DESCRIPTOR, ".[@SimpleName = 'Foo']"); runTestFromString(TEST1, rule, rpt, defaultLanguage); assertTrue(rpt.isEmpty()); assertEquals(1, rpt.getSuppressedRuleViolations().size()); diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/XPathRuleTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/XPathRuleTest.java index a82c36426b..90e01fabe5 100644 --- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/XPathRuleTest.java +++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/XPathRuleTest.java @@ -1,4 +1,4 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ @@ -53,7 +53,7 @@ public class XPathRuleTest extends RuleTst { @Test public void testPluginname() throws Exception { - XPathRule rule = makeXPath("//VariableDeclaratorId[string-length(@Image) < 3]"); + XPathRule rule = makeXPath("//VariableDeclaratorId[string-length(@Name) < 3]"); rule.setMessage("{0}"); Report report = getReportForTestString(rule, TEST1); RuleViolation rv = report.iterator().next(); @@ -63,7 +63,7 @@ public class XPathRuleTest extends RuleTst { @Test public void testXPathMultiProperty() throws Exception { - XPathRule rule = makeXPath("//VariableDeclaratorId[@Image=$forbiddenNames]"); + XPathRule rule = makeXPath("//VariableDeclaratorId[@Name=$forbiddenNames]"); rule.setMessage("Avoid vars"); PropertyDescriptor> varDescriptor = PropertyFactory.stringListProperty("forbiddenNames") @@ -86,7 +86,7 @@ public class XPathRuleTest extends RuleTst { @Test public void testVariables() throws Exception { - XPathRule rule = makeXPath("//VariableDeclaratorId[@Image=$var]"); + XPathRule rule = makeXPath("//VariableDeclaratorId[@Name=$var]"); rule.setMessage("Avoid vars"); PropertyDescriptor varDescriptor = PropertyFactory.stringProperty("var").desc("Test var").defaultValue("").build(); @@ -99,7 +99,7 @@ public class XPathRuleTest extends RuleTst { @Test public void testFnPrefixOnSaxon() throws Exception { - XPathRule rule = makeXPath("//VariableDeclaratorId[fn:matches(@Image, 'fiddle')]"); + XPathRule rule = makeXPath("//VariableDeclaratorId[fn:matches(@Name, 'fiddle')]"); Report report = getReportForTestString(rule, TEST2); RuleViolation rv = report.iterator().next(); assertEquals(3, rv.getBeginLine()); @@ -107,7 +107,7 @@ public class XPathRuleTest extends RuleTst { @Test public void testNoFnPrefixOnSaxon() throws Exception { - XPathRule rule = makeXPath("//VariableDeclaratorId[matches(@Image, 'fiddle')]"); + XPathRule rule = makeXPath("//VariableDeclaratorId[matches(@Name, 'fiddle')]"); Report report = getReportForTestString(rule, TEST2); RuleViolation rv = report.iterator().next(); assertEquals(3, rv.getBeginLine()); diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/typeresolution/ClassTypeResolverTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/typeresolution/ClassTypeResolverTest.java index 57ae0deec3..94756287bb 100644 --- a/pmd-java/src/test/java/net/sourceforge/pmd/typeresolution/ClassTypeResolverTest.java +++ b/pmd-java/src/test/java/net/sourceforge/pmd/typeresolution/ClassTypeResolverTest.java @@ -452,8 +452,7 @@ public class ClassTypeResolverTest { ASTCompilationUnit acu = java5.parseClass(Promotion.class); List expressions = convertList( acu.findChildNodesWithXPath( - "//Block[preceding-sibling::MethodDeclarator[@Image = " - + "'unaryNumericPromotion']]//Expression[UnaryExpression]"), + "//MethodDeclaration[@Name = 'unaryNumericPromotion']/Block//Expression[UnaryExpression]"), ASTExpression.class); int index = 0; @@ -474,8 +473,7 @@ public class ClassTypeResolverTest { ASTCompilationUnit acu = java5.parseClass(Promotion.class); List expressions = convertList( acu.findChildNodesWithXPath( - "//Block[preceding-sibling::MethodDeclarator[@Image = " - + "'binaryNumericPromotion']]//Expression[AdditiveExpression]"), + "//MethodDeclaration[@Name = 'binaryNumericPromotion']/Block//Expression[AdditiveExpression]"), ASTExpression.class); int index = 0; @@ -545,7 +543,7 @@ public class ClassTypeResolverTest { ASTCompilationUnit acu = java5.parseClass(Promotion.class); List expressions = convertList( acu.findChildNodesWithXPath( - "//Block[preceding-sibling::MethodDeclarator[@Image = 'binaryStringPromotion']]//Expression"), + "//MethodDeclaration[@Name = 'binaryStringPromotion']/Block//Expression"), ASTExpression.class); int index = 0; @@ -564,7 +562,7 @@ public class ClassTypeResolverTest { ASTCompilationUnit acu = java5.parseClass(Operators.class); List expressions = convertList( acu.findChildNodesWithXPath( - "//Block[preceding-sibling::MethodDeclarator[@Image = 'unaryLogicalOperators']]//Expression"), + "//MethodDeclaration[@Name = 'unaryLogicalOperators']/Block//Expression"), ASTExpression.class); int index = 0; @@ -580,7 +578,7 @@ public class ClassTypeResolverTest { ASTCompilationUnit acu = java5.parseClass(Operators.class); List expressions = convertList( acu.findChildNodesWithXPath( - "//Block[preceding-sibling::MethodDeclarator[@Image = 'binaryLogicalOperators']]//Expression"), + "//MethodDeclaration[@Name = 'binaryLogicalOperators']/Block//Expression"), ASTExpression.class); int index = 0; @@ -606,24 +604,22 @@ public class ClassTypeResolverTest { public void testUnaryNumericOperators() throws JaxenException { ASTCompilationUnit acu = java5.parseClass(Operators.class); List expressions = new ArrayList<>(); + final String baseXPath = "//MethodDeclaration[@Name = 'unaryNumericOperators']/Block"; expressions.addAll(convertList( acu.findChildNodesWithXPath( - "//Block[preceding-sibling::MethodDeclarator[@Image = 'unaryNumericOperators']]//Expression"), + baseXPath + "//Expression"), TypeNode.class)); expressions.addAll(convertList( acu.findChildNodesWithXPath( - "//Block[preceding-sibling::MethodDeclarator[@Image = " - + "'unaryNumericOperators']]//PostfixExpression"), + baseXPath + "//PostfixExpression"), TypeNode.class)); expressions.addAll(convertList( acu.findChildNodesWithXPath( - "//Block[preceding-sibling::MethodDeclarator[@Image = " - + "'unaryNumericOperators']]//PreIncrementExpression"), + baseXPath + "//PreIncrementExpression"), TypeNode.class)); expressions.addAll(convertList( acu.findChildNodesWithXPath( - "//Block[preceding-sibling::MethodDeclarator[@Image = " - + "'unaryNumericOperators']]//PreDecrementExpression"), + baseXPath + "//PreDecrementExpression"), TypeNode.class)); int index = 0; @@ -643,7 +639,7 @@ public class ClassTypeResolverTest { ASTCompilationUnit acu = java5.parseClass(Operators.class); List expressions = convertList( acu.findChildNodesWithXPath( - "//Block[preceding-sibling::MethodDeclarator[@Image = 'binaryNumericOperators']]//Expression"), + "//MethodDeclaration[@Name = 'binaryNumericOperators']/Block//Expression"), ASTExpression.class); int index = 0; @@ -665,8 +661,7 @@ public class ClassTypeResolverTest { ASTCompilationUnit acu = java5.parseClass(Operators.class); List expressions = convertList( acu.findChildNodesWithXPath( - "//Block[preceding-sibling::MethodDeclarator[@Image = " - + "'assignmentOperators']]//StatementExpression"), + "//MethodDeclaration[@Name = 'assignmentOperators']/Block//StatementExpression"), ASTStatementExpression.class); int index = 0; diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/bestpractices/xml/UnusedFormalParameter.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/bestpractices/xml/UnusedFormalParameter.xml index ba281bbf8a..879d7d748a 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/bestpractices/xml/UnusedFormalParameter.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/bestpractices/xml/UnusedFormalParameter.xml @@ -217,7 +217,7 @@ class Foo { violation suppression xpath works, by name ]]> - .[@Image = 'paramB'] + .[@Name = 'paramB'] 0 Date: Mon, 20 Apr 2020 09:46:11 +0200 Subject: [PATCH 49/49] Update release notes Refs #2413 --- docs/pages/release_notes.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index a470494bab..5265da4b23 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -45,9 +45,10 @@ Note that XPath 1.0 support, the default XPath version, is deprecated since PMD * apex-security * [#2210](https://github.com/pmd/pmd/issues/2210): \[apex] ApexCRUDViolation: Support WITH SECURITY_ENFORCED * [#2399](https://github.com/pmd/pmd/issues/2399): \[apex] ApexCRUDViolation: false positive with security enforced with line break -* core +* doc * [#2355](https://github.com/pmd/pmd/issues/2355): \[doc] Improve documentation about incremental analysis * [#2356](https://github.com/pmd/pmd/issues/2356): \[doc] Add missing doc about pmd.github.io + * [#2413](https://github.com/pmd/pmd/issues/2413): \[doc] Improve documentation about the available renderers (PMD/CPD) * java * [#2378](https://github.com/pmd/pmd/issues/2378): \[java] AbstractJUnitRule has bad performance on large code bases * java-codestyle