From 83879dc420103585397bd08e830e1571d6019878 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 1 Feb 2024 11:39:33 +0100 Subject: [PATCH] [core] Hide internal API methods in LanguageProcessor.AnalysisTask Refs #4348 --- docs/pages/release_notes.md | 10 ++---- .../java/net/sourceforge/pmd/PmdAnalysis.java | 3 +- .../pmd/lang/InternalApiBridge.java | 36 +++++++++++++++++++ .../pmd/lang/LanguageProcessor.java | 7 ++-- .../pmd/lang/impl/BatchLanguageProcessor.java | 3 +- .../lang/impl/AbstractPMDProcessorTest.java | 3 +- 6 files changed, 47 insertions(+), 15 deletions(-) create mode 100644 pmd-core/src/main/java/net/sourceforge/pmd/lang/InternalApiBridge.java diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 5750813165..ee893f27f6 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -172,6 +172,9 @@ package or made (package) private and are _not accessible_ anymore. * `net.sourceforge.pmd.util.ResourceLoader` (moved to internal) * {%jdoc !!core::cpd.Tokens %} * Constructor is now package private. + * {%jdoc !!core::lang.LanguageProcessor.AnalysisTask %} + * Constructor is now package private. + * Method `withFiles(java.util.List)` is now package private. Note: it was not previously marked with @InternalApi. * {%jdoc !!core::lang.rule.RuleTargetSelector %} * Method `isRuleChain()` has been removed. * {%jdoc !!core::renderers.AbstractAccumulatingRenderer %} @@ -224,13 +227,6 @@ package or made (package) private and are _not accessible_ anymore. * {%jdoc !!scala::ScalaLanguageModule %} * Method `dialectOf(LanguageVersion)` has been removed. -**Newly internal classes, interfaces and methods** - -The following classes/methods are for now considered being internal API. Its usage should -be avoided. - -* {%jdoc !!core::lang.LanguageProcessor.AnalysisTask#withFiles(java.util.List) %} - **Removed classes and methods (previously deprecated)** The following previously deprecated classes have been removed: diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/PmdAnalysis.java b/pmd-core/src/main/java/net/sourceforge/pmd/PmdAnalysis.java index bc49d48f49..a8094ecd59 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/PmdAnalysis.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/PmdAnalysis.java @@ -31,6 +31,7 @@ import net.sourceforge.pmd.internal.LogMessages; import net.sourceforge.pmd.internal.util.ClasspathClassLoader; import net.sourceforge.pmd.internal.util.FileCollectionUtil; import net.sourceforge.pmd.internal.util.IOUtil; +import net.sourceforge.pmd.lang.InternalApiBridge; import net.sourceforge.pmd.lang.JvmLanguagePropertyBundle; import net.sourceforge.pmd.lang.Language; import net.sourceforge.pmd.lang.LanguageProcessor.AnalysisTask; @@ -416,7 +417,7 @@ public final class PmdAnalysis implements AutoCloseable { // Note the analysis task is shared: all processors see // the same file list, which may contain files for other // languages. - AnalysisTask analysisTask = new AnalysisTask( + AnalysisTask analysisTask = InternalApiBridge.createAnalysisTask( rulesets, textFiles, listener, diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/InternalApiBridge.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/InternalApiBridge.java new file mode 100644 index 0000000000..fe139d6d9e --- /dev/null +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/InternalApiBridge.java @@ -0,0 +1,36 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang; + +import java.util.List; + +import net.sourceforge.pmd.RuleSets; +import net.sourceforge.pmd.annotation.InternalApi; +import net.sourceforge.pmd.cache.internal.AnalysisCache; +import net.sourceforge.pmd.lang.document.TextFile; +import net.sourceforge.pmd.reporting.GlobalAnalysisListener; +import net.sourceforge.pmd.util.log.PmdReporter; + +/** + * Internal API. + */ +@InternalApi +public final class InternalApiBridge { + private InternalApiBridge() {} + + public static LanguageProcessor.AnalysisTask createAnalysisTask(RuleSets rulesets, + List files, + GlobalAnalysisListener listener, + int threadCount, + AnalysisCache analysisCache, + PmdReporter messageReporter, + LanguageProcessorRegistry lpRegistry) { + return new LanguageProcessor.AnalysisTask(rulesets, files, listener, threadCount, analysisCache, messageReporter, lpRegistry); + } + + public static LanguageProcessor.AnalysisTask taskWithFiles(LanguageProcessor.AnalysisTask originalTask, List newFiles) { + return originalTask.withFiles(newFiles); + } +} diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageProcessor.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageProcessor.java index dfad31fb67..269f0be8c3 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageProcessor.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageProcessor.java @@ -10,7 +10,6 @@ import java.util.List; import org.checkerframework.checker.nullness.qual.NonNull; import net.sourceforge.pmd.RuleSets; -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.cache.internal.AnalysisCache; import net.sourceforge.pmd.lang.document.TextFile; import net.sourceforge.pmd.reporting.GlobalAnalysisListener; @@ -75,8 +74,7 @@ public interface LanguageProcessor extends AutoCloseable { * * @apiNote Internal API */ - @InternalApi - public AnalysisTask(RuleSets rulesets, + AnalysisTask(RuleSets rulesets, List files, GlobalAnalysisListener listener, int threadCount, @@ -125,8 +123,7 @@ public interface LanguageProcessor extends AutoCloseable { * * @apiNote Internal API */ - @InternalApi - public AnalysisTask withFiles(List newFiles) { + AnalysisTask withFiles(List newFiles) { return new AnalysisTask( rulesets, newFiles, diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/impl/BatchLanguageProcessor.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/impl/BatchLanguageProcessor.java index 2c6d93b910..7287752711 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/impl/BatchLanguageProcessor.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/impl/BatchLanguageProcessor.java @@ -9,6 +9,7 @@ import java.util.List; import org.checkerframework.checker.nullness.qual.NonNull; +import net.sourceforge.pmd.lang.InternalApiBridge; import net.sourceforge.pmd.lang.LanguageProcessor; import net.sourceforge.pmd.lang.LanguagePropertyBundle; import net.sourceforge.pmd.lang.LanguageVersion; @@ -60,7 +61,7 @@ public abstract class BatchLanguageProcessor

i // The given analysis task has all files to analyse, not only the ones for this language. List files = new ArrayList<>(task.getFiles()); files.removeIf(it -> !it.getLanguageVersion().getLanguage().equals(getLanguage())); - AnalysisTask newTask = task.withFiles(files); + AnalysisTask newTask = InternalApiBridge.taskWithFiles(task, files); task.getRulesets().initializeRules(task.getLpRegistry(), task.getMessageReporter()); diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/lang/impl/AbstractPMDProcessorTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/lang/impl/AbstractPMDProcessorTest.java index 060515d596..10b9841522 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/lang/impl/AbstractPMDProcessorTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/lang/impl/AbstractPMDProcessorTest.java @@ -20,6 +20,7 @@ import net.sourceforge.pmd.RuleContext; import net.sourceforge.pmd.RuleSet; import net.sourceforge.pmd.RuleViolation; import net.sourceforge.pmd.lang.DummyLanguageModule; +import net.sourceforge.pmd.lang.InternalApiBridge; import net.sourceforge.pmd.lang.LanguageProcessor; import net.sourceforge.pmd.lang.LanguageVersion; import net.sourceforge.pmd.lang.ast.Node; @@ -47,7 +48,7 @@ abstract class AbstractPMDProcessorTest { } private LanguageProcessor.AnalysisTask createTask(int threads) { - return new LanguageProcessor.AnalysisTask(null, null, null, threads, null, null, null); + return InternalApiBridge.createAnalysisTask(null, null, null, threads, null, null, null); } @Test