From 7ec2bc48654af2b557fd1890c72b532b954ceb06 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Tue, 30 Jan 2024 20:17:59 +0100 Subject: [PATCH] [apex] Cleanup InternalApi methods Refs #4348 --- docs/pages/release_notes.md | 7 ++++++ .../pmd/lang/apex/ApexLanguageProcessor.java | 3 ++- .../pmd/lang/apex/ast/ASTBlockStatement.java | 2 +- .../pmd/lang/apex/ast/AbstractApexNode.java | 6 +---- .../pmd/lang/apex/ast/ApexNode.java | 13 +---------- .../pmd/lang/apex/ast/ApexParser.java | 2 -- .../pmd/lang/apex/ast/ApexTreeBuilder.java | 2 +- .../apex/multifile/ApexMultifileAnalysis.java | 4 +--- .../apex/multifile/InternalApiBridge.java | 22 +++++++++++++++++++ .../AbstractApexUnitTestRule.java | 9 +++----- ...pexAssertionsShouldIncludeMessageRule.java | 1 - ...pexUnitTestClassShouldHaveAssertsRule.java | 1 - .../ApexUnitTestClassShouldHaveRunAsRule.java | 1 - ...nitTestShouldNotUseSeeAllDataTrueRule.java | 1 - .../rule/design/AbstractNcssCountRule.java | 6 +---- .../pmd/lang/apex/rule/internal/Helper.java | 2 -- 16 files changed, 40 insertions(+), 42 deletions(-) create mode 100644 pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/multifile/InternalApiBridge.java rename pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/{ => bestpractices}/AbstractApexUnitTestRule.java (80%) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index d001cb929b..51325edabb 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -188,6 +188,13 @@ package or made (package) private and are not accessible anymore. * The method `newListener(Project)` is now package private and not accessible anymore. * {%jdoc ant::ant.PMDTask %} * The method `getRelativizeRoots()` has been removed. +* pmd-apex + * {%jdoc apex::ast.ApexNode %}: Method `getNode()` has been removed - it was deprecated before. + It gave access to the wrapped Jorje node and was thus internal API. + * {%jdoc apex::ast.AbstractApexNode %}: Method `getNode()` is now package private and not accessible anymore. + * {%jdoc !!apex::multifile.ApexMultifileAnalysis#ApexMultifileAnalysis(apex::ApexLanguageProperties) } (the constructor is now package private) + * {%jdoc apex::rule.design.AbstractNcssCountRule %} (now package private) + * {%jdoc apex::rule.bestpractices.AbstractApexUnitTestRule %} (moved from package `net.sourceforge.pmd.apex.rule`, now package private) **Newly internal classes, interfaces and methods** diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexLanguageProcessor.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexLanguageProcessor.java index c1efb30f60..ca626f0976 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexLanguageProcessor.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexLanguageProcessor.java @@ -8,6 +8,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import net.sourceforge.pmd.lang.LanguageVersionHandler; import net.sourceforge.pmd.lang.apex.multifile.ApexMultifileAnalysis; +import net.sourceforge.pmd.lang.apex.multifile.InternalApiBridge; import net.sourceforge.pmd.lang.impl.BatchLanguageProcessor; public class ApexLanguageProcessor @@ -18,7 +19,7 @@ public class ApexLanguageProcessor ApexLanguageProcessor(ApexLanguageProperties bundle) { super(bundle); - this.multifileAnalysis = new ApexMultifileAnalysis(bundle); + this.multifileAnalysis = InternalApiBridge.createApexMultiFileAnalysis(bundle); this.services = new ApexLanguageHandler(); } 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 92b8ed7e82..a8fbdaab7b 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 @@ -42,6 +42,6 @@ public final class ASTBlockStatement extends AbstractApexNode { @Override public boolean hasRealLoc() { - return super.hasRealLoc() && !Objects.equals(node.getLoc(), getParent().getNode().getLoc()); + return super.hasRealLoc() && !Objects.equals(node.getLoc(), ((AbstractApexNode) getParent()).getNode().getLoc()); } } 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 48bf3aa906..b2369d41ad 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 @@ -6,7 +6,6 @@ package net.sourceforge.pmd.lang.apex.ast; import org.checkerframework.checker.nullness.qual.NonNull; -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.ast.AstVisitor; import net.sourceforge.pmd.lang.ast.FileAnalysisException; import net.sourceforge.pmd.lang.ast.impl.AbstractNode; @@ -89,10 +88,7 @@ abstract class AbstractApexNode extends AbstractNode Type of the underlying Jorje node */ @@ -33,16 +32,6 @@ public interface ApexNode extends GenericNode> { } - /** - * 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(); - - boolean hasRealLoc(); 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 ad746e7ec1..702f493d32 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 @@ -4,7 +4,6 @@ package net.sourceforge.pmd.lang.apex.ast; -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.apex.ApexJorjeLogging; import net.sourceforge.pmd.lang.apex.ApexLanguageProcessor; import net.sourceforge.pmd.lang.ast.ParseException; @@ -14,7 +13,6 @@ import net.sourceforge.pmd.lang.document.FileLocation; import apex.jorje.data.Locations; import apex.jorje.semantic.ast.compilation.Compilation; -@InternalApi public final class ApexParser implements Parser { public ApexParser() { 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 0772a386d3..82e8bef1e7 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 @@ -328,7 +328,7 @@ final class ApexTreeBuilder extends AstVisitor { } } - private boolean containsComments(ASTCommentContainer commentContainer) { + private boolean containsComments(AbstractApexCommentContainerNode commentContainer) { Location loc = commentContainer.getNode().getLoc(); if (!Locations.isReal(loc)) { // Synthetic nodes don't have a location and can't have comments diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/multifile/ApexMultifileAnalysis.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/multifile/ApexMultifileAnalysis.java index e940786551..295354ff0e 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/multifile/ApexMultifileAnalysis.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/multifile/ApexMultifileAnalysis.java @@ -16,7 +16,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import net.sourceforge.pmd.annotation.Experimental; -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.apex.ApexLanguageProcessor; import net.sourceforge.pmd.lang.apex.ApexLanguageProperties; @@ -52,8 +51,7 @@ public final class ApexMultifileAnalysis { } - @InternalApi - public ApexMultifileAnalysis(ApexLanguageProperties properties) { + ApexMultifileAnalysis(ApexLanguageProperties properties) { String rootDir = properties.getProperty(ApexLanguageProperties.MULTIFILE_DIRECTORY); LOG.debug("MultiFile Analysis created for {}", rootDir); diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/multifile/InternalApiBridge.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/multifile/InternalApiBridge.java new file mode 100644 index 0000000000..3a3d2643af --- /dev/null +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/multifile/InternalApiBridge.java @@ -0,0 +1,22 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.apex.multifile; + +import net.sourceforge.pmd.annotation.InternalApi; +import net.sourceforge.pmd.lang.apex.ApexLanguageProperties; + +/** + * @apiNote Internal API + */ +@InternalApi +public final class InternalApiBridge { + private InternalApiBridge() { + // utility class + } + + public static ApexMultifileAnalysis createApexMultiFileAnalysis(ApexLanguageProperties properties) { + return new ApexMultifileAnalysis(properties); + } +} diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/AbstractApexUnitTestRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/bestpractices/AbstractApexUnitTestRule.java similarity index 80% rename from pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/AbstractApexUnitTestRule.java rename to pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/bestpractices/AbstractApexUnitTestRule.java index 8ccfdb9bb5..ac909e502f 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/AbstractApexUnitTestRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/bestpractices/AbstractApexUnitTestRule.java @@ -2,22 +2,19 @@ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ -package net.sourceforge.pmd.lang.apex.rule; +package net.sourceforge.pmd.lang.apex.rule.bestpractices; -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.apex.ast.ASTModifierNode; import net.sourceforge.pmd.lang.apex.ast.ASTUserClass; import net.sourceforge.pmd.lang.apex.ast.ApexNode; +import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule; /** * Do special checks for apex unit test classes and methods * * @author a.subramanian - * @deprecated Internal API */ -@Deprecated -@InternalApi -public abstract class AbstractApexUnitTestRule extends AbstractApexRule { +abstract class AbstractApexUnitTestRule extends AbstractApexRule { /** * Don't bother visiting this class if it's not a class with @isTest and diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/bestpractices/ApexAssertionsShouldIncludeMessageRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/bestpractices/ApexAssertionsShouldIncludeMessageRule.java index 45cd38a986..bed4a82a8f 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/bestpractices/ApexAssertionsShouldIncludeMessageRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/bestpractices/ApexAssertionsShouldIncludeMessageRule.java @@ -5,7 +5,6 @@ package net.sourceforge.pmd.lang.apex.rule.bestpractices; import net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression; -import net.sourceforge.pmd.lang.apex.rule.AbstractApexUnitTestRule; public class ApexAssertionsShouldIncludeMessageRule extends AbstractApexUnitTestRule { diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/bestpractices/ApexUnitTestClassShouldHaveAssertsRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/bestpractices/ApexUnitTestClassShouldHaveAssertsRule.java index 2288e90b3b..7b95fc17e2 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/bestpractices/ApexUnitTestClassShouldHaveAssertsRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/bestpractices/ApexUnitTestClassShouldHaveAssertsRule.java @@ -21,7 +21,6 @@ import net.sourceforge.pmd.lang.apex.ast.ASTMethod; import net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression; import net.sourceforge.pmd.lang.apex.ast.ASTStatement; import net.sourceforge.pmd.lang.apex.ast.ApexNode; -import net.sourceforge.pmd.lang.apex.rule.AbstractApexUnitTestRule; import net.sourceforge.pmd.properties.PropertyDescriptor; /** diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/bestpractices/ApexUnitTestClassShouldHaveRunAsRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/bestpractices/ApexUnitTestClassShouldHaveRunAsRule.java index 10b74c8321..2f2bfd1a51 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/bestpractices/ApexUnitTestClassShouldHaveRunAsRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/bestpractices/ApexUnitTestClassShouldHaveRunAsRule.java @@ -9,7 +9,6 @@ import java.util.List; import net.sourceforge.pmd.lang.apex.ast.ASTMethod; import net.sourceforge.pmd.lang.apex.ast.ASTRunAsBlockStatement; import net.sourceforge.pmd.lang.apex.ast.ApexNode; -import net.sourceforge.pmd.lang.apex.rule.AbstractApexUnitTestRule; /** * Apex unit tests should have System.runAs methods in them diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/bestpractices/ApexUnitTestShouldNotUseSeeAllDataTrueRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/bestpractices/ApexUnitTestShouldNotUseSeeAllDataTrueRule.java index 9078ece17e..3c7f13edc9 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/bestpractices/ApexUnitTestShouldNotUseSeeAllDataTrueRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/bestpractices/ApexUnitTestShouldNotUseSeeAllDataTrueRule.java @@ -9,7 +9,6 @@ import net.sourceforge.pmd.lang.apex.ast.ASTMethod; import net.sourceforge.pmd.lang.apex.ast.ASTModifierNode; import net.sourceforge.pmd.lang.apex.ast.ASTUserClass; import net.sourceforge.pmd.lang.apex.ast.ApexNode; -import net.sourceforge.pmd.lang.apex.rule.AbstractApexUnitTestRule; /** *

diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/design/AbstractNcssCountRule.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/design/AbstractNcssCountRule.java index ac5afe214f..f7df09a027 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/design/AbstractNcssCountRule.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/design/AbstractNcssCountRule.java @@ -4,7 +4,6 @@ package net.sourceforge.pmd.lang.apex.rule.design; -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.apex.ast.ASTBreakStatement; import net.sourceforge.pmd.lang.apex.ast.ASTContinueStatement; import net.sourceforge.pmd.lang.apex.ast.ASTDoLoopStatement; @@ -33,11 +32,8 @@ import net.sourceforge.pmd.lang.ast.Node; * JavaNCSS rules. * * @author ported from Java original of Jason Bennett - * @deprecated Internal API */ -@Deprecated -@InternalApi -public abstract class AbstractNcssCountRule> extends AbstractCounterCheckRule { +abstract class AbstractNcssCountRule> extends AbstractCounterCheckRule { /** 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 acf9e98fa0..de284ef750 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 @@ -8,7 +8,6 @@ import java.util.Arrays; import java.util.List; import java.util.Locale; -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.apex.ast.ASTDmlDeleteStatement; import net.sourceforge.pmd.lang.apex.ast.ASTDmlInsertStatement; import net.sourceforge.pmd.lang.apex.ast.ASTDmlMergeStatement; @@ -36,7 +35,6 @@ import net.sourceforge.pmd.lang.apex.ast.ApexNode; * @author sergey.gorbaty * */ -@InternalApi public final class Helper { public static final String ANY_METHOD = "*"; private static final String DATABASE_CLASS_NAME = "Database";