From 906baf9b50b12dc4d703a2df772778fca1e9f5c9 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 26 Jan 2024 18:41:00 +0100 Subject: [PATCH 01/37] [core] Internalize AnalysisCache and related types Refs #4348 --- docs/pages/release_notes.md | 15 +++++++++++++ pmd-compat6/src/it/pmd-for-java/pom.xml | 1 + .../net/sourceforge/pmd/PMDConfiguration.java | 6 +++--- .../net/sourceforge/pmd/PMDConfiguration.java | 21 ++++++++++++++----- .../java/net/sourceforge/pmd/PmdAnalysis.java | 4 ++-- .../java/net/sourceforge/pmd/RuleSet.java | 2 +- .../{ => internal}/AbstractAnalysisCache.java | 12 +++-------- .../cache/{ => internal}/AnalysisCache.java | 7 +------ .../{ => internal}/AnalysisCacheListener.java | 5 +---- .../cache/{ => internal}/AnalysisResult.java | 6 +----- .../{ => internal}/CachedRuleMapper.java | 9 ++------ .../{ => internal}/CachedRuleViolation.java | 11 +++------- .../cache/{ => internal}/ChecksumAware.java | 8 +------ .../{ => internal}/FileAnalysisCache.java | 7 +------ .../{ => internal}/NoopAnalysisCache.java | 7 +------ .../sourceforge/pmd/cache/package-info.java | 10 ++++----- .../pmd/lang/LanguageProcessor.java | 2 +- .../pmd/lang/impl/PmdRunnable.java | 2 +- .../sourceforge/pmd/PmdConfigurationTest.java | 4 ++-- .../{ => internal}/FileAnalysisCacheTest.java | 2 +- .../reporting/GlobalAnalysisListenerTest.java | 4 ++-- 21 files changed, 63 insertions(+), 82 deletions(-) rename pmd-core/src/main/java/net/sourceforge/pmd/cache/{ => internal}/AbstractAnalysisCache.java (96%) rename pmd-core/src/main/java/net/sourceforge/pmd/cache/{ => internal}/AnalysisCache.java (94%) rename pmd-core/src/main/java/net/sourceforge/pmd/cache/{ => internal}/AnalysisCacheListener.java (91%) rename pmd-core/src/main/java/net/sourceforge/pmd/cache/{ => internal}/AnalysisResult.java (86%) rename pmd-core/src/main/java/net/sourceforge/pmd/cache/{ => internal}/CachedRuleMapper.java (87%) rename pmd-core/src/main/java/net/sourceforge/pmd/cache/{ => internal}/CachedRuleViolation.java (95%) rename pmd-core/src/main/java/net/sourceforge/pmd/cache/{ => internal}/ChecksumAware.java (76%) rename pmd-core/src/main/java/net/sourceforge/pmd/cache/{ => internal}/FileAnalysisCache.java (97%) rename pmd-core/src/main/java/net/sourceforge/pmd/cache/{ => internal}/NoopAnalysisCache.java (87%) rename pmd-core/src/test/java/net/sourceforge/pmd/cache/{ => internal}/FileAnalysisCacheTest.java (99%) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index f00bb65f96..fd6547a97c 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -154,6 +154,21 @@ in the Migration Guide. #### API Changes +**Internalized classes and interfaces** + +The following classes have been marked as @InternalApi before and are now moved into a `internal` package: + +* pmd-core + * {%jdoc core::cache.internal.AbstractAnalysisCache %} (now package private) + * {%jdoc core::cache.internal.AnalysisCache %} + * {%jdoc core::cache.internal.AnalysisCacheListener %} + * {%jdoc core::cache.internal.AnalysisResult %} + * {%jdoc core::cache.internal.CachedRuleMapper %} (now package private) + * {%jdoc core::cache.internal.CachedRuleViolation %} (now package private) + * {%jdoc core::cache.internal.ChecksumAware %} + * {%jdoc core::cache.internal.FileAnalysisCache %} + * {%jdoc core::cache.internal.NoopAnalysisCache %} + **Removed classes and methods (previously deprecated)** The following previously deprecated classes have been removed: diff --git a/pmd-compat6/src/it/pmd-for-java/pom.xml b/pmd-compat6/src/it/pmd-for-java/pom.xml index 55682ec03b..8c9762f110 100644 --- a/pmd-compat6/src/it/pmd-for-java/pom.xml +++ b/pmd-compat6/src/it/pmd-for-java/pom.xml @@ -32,6 +32,7 @@ true true 5 + true /rulesets/java/maven-pmd-plugin-default.xml ${project.basedir}/exception_ruleset.xml diff --git a/pmd-compat6/src/main/java/net/sourceforge/pmd/PMDConfiguration.java b/pmd-compat6/src/main/java/net/sourceforge/pmd/PMDConfiguration.java index 87175d7405..b09a5b9e68 100644 --- a/pmd-compat6/src/main/java/net/sourceforge/pmd/PMDConfiguration.java +++ b/pmd-compat6/src/main/java/net/sourceforge/pmd/PMDConfiguration.java @@ -24,9 +24,9 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.slf4j.LoggerFactory; import net.sourceforge.pmd.annotation.DeprecatedUntil700; -import net.sourceforge.pmd.cache.AnalysisCache; -import net.sourceforge.pmd.cache.FileAnalysisCache; -import net.sourceforge.pmd.cache.NoopAnalysisCache; +import net.sourceforge.pmd.cache.internal.AnalysisCache; +import net.sourceforge.pmd.cache.internal.FileAnalysisCache; +import net.sourceforge.pmd.cache.internal.NoopAnalysisCache; import net.sourceforge.pmd.internal.util.ClasspathClassLoader; import net.sourceforge.pmd.lang.Language; import net.sourceforge.pmd.lang.LanguageRegistry; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java b/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java index b262878dfe..578f16b1e6 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java @@ -21,9 +21,10 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.slf4j.LoggerFactory; import net.sourceforge.pmd.annotation.DeprecatedUntil700; -import net.sourceforge.pmd.cache.AnalysisCache; -import net.sourceforge.pmd.cache.FileAnalysisCache; -import net.sourceforge.pmd.cache.NoopAnalysisCache; +import net.sourceforge.pmd.annotation.InternalApi; +import net.sourceforge.pmd.cache.internal.AnalysisCache; +import net.sourceforge.pmd.cache.internal.FileAnalysisCache; +import net.sourceforge.pmd.cache.internal.NoopAnalysisCache; import net.sourceforge.pmd.internal.util.ClasspathClassLoader; import net.sourceforge.pmd.lang.Language; import net.sourceforge.pmd.lang.LanguageRegistry; @@ -475,7 +476,10 @@ public class PMDConfiguration extends AbstractConfiguration { * Retrieves the currently used analysis cache. Will never be null. * * @return The currently used analysis cache. Never null. + * + * @apiNote This is internal API. */ + @InternalApi public AnalysisCache getAnalysisCache() { // Make sure we are not null if (analysisCache == null || isIgnoreIncrementalAnalysis() && !(analysisCache instanceof NoopAnalysisCache)) { @@ -493,7 +497,10 @@ public class PMDConfiguration extends AbstractConfiguration { * then this method is a noop. * * @param cache The analysis cache to be used. + * + * @apiNote This is internal API. Use {@link #setAnalysisCacheLocation(String)} to configure a cache. */ + @InternalApi public void setAnalysisCache(final AnalysisCache cache) { // the doc says it's a noop if incremental analysis was disabled, // but it's actually the getter that enforces that @@ -502,9 +509,13 @@ public class PMDConfiguration extends AbstractConfiguration { /** * Sets the location of the analysis cache to be used. This will automatically configure - * and appropriate AnalysisCache implementation. + * and appropriate AnalysisCache implementation. Setting a + * value of {@code null} will cause a Noop AnalysisCache to be used. + * If incremental analysis was explicitly disabled ({@link #isIgnoreIncrementalAnalysis()}), + * then this method is a noop. * - * @param cacheLocation The location of the analysis cache to be used. + * @param cacheLocation The location of the analysis cache to be used. Use {@code null} + * to disable the cache. */ public void setAnalysisCacheLocation(final String cacheLocation) { setAnalysisCache(cacheLocation == null 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 6a1b013776..6ef8602b73 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/PmdAnalysis.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/PmdAnalysis.java @@ -25,8 +25,8 @@ import net.sourceforge.pmd.Report.GlobalReportBuilderListener; import net.sourceforge.pmd.benchmark.TimeTracker; import net.sourceforge.pmd.benchmark.TimedOperation; import net.sourceforge.pmd.benchmark.TimedOperationCategory; -import net.sourceforge.pmd.cache.AnalysisCacheListener; -import net.sourceforge.pmd.cache.NoopAnalysisCache; +import net.sourceforge.pmd.cache.internal.AnalysisCacheListener; +import net.sourceforge.pmd.cache.internal.NoopAnalysisCache; import net.sourceforge.pmd.internal.LogMessages; import net.sourceforge.pmd.internal.util.ClasspathClassLoader; import net.sourceforge.pmd.internal.util.FileCollectionUtil; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSet.java b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSet.java index 8d7e370a4d..86416a56f2 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSet.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSet.java @@ -21,7 +21,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import net.sourceforge.pmd.annotation.InternalApi; -import net.sourceforge.pmd.cache.ChecksumAware; +import net.sourceforge.pmd.cache.internal.ChecksumAware; import net.sourceforge.pmd.internal.util.PredicateUtil; import net.sourceforge.pmd.lang.LanguageVersion; import net.sourceforge.pmd.lang.document.FileId; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cache/AbstractAnalysisCache.java b/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/AbstractAnalysisCache.java similarity index 96% rename from pmd-core/src/main/java/net/sourceforge/pmd/cache/AbstractAnalysisCache.java rename to pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/AbstractAnalysisCache.java index 7a8b7a9498..733ddf6581 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cache/AbstractAnalysisCache.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/AbstractAnalysisCache.java @@ -2,7 +2,7 @@ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ -package net.sourceforge.pmd.cache; +package net.sourceforge.pmd.cache.internal; import java.io.File; import java.io.IOException; @@ -29,11 +29,9 @@ import net.sourceforge.pmd.PMDVersion; import net.sourceforge.pmd.Report.ProcessingError; import net.sourceforge.pmd.RuleSets; import net.sourceforge.pmd.RuleViolation; -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.benchmark.TimeTracker; import net.sourceforge.pmd.benchmark.TimedOperation; import net.sourceforge.pmd.benchmark.TimedOperationCategory; -import net.sourceforge.pmd.cache.internal.ClasspathFingerprinter; import net.sourceforge.pmd.internal.util.IOUtil; import net.sourceforge.pmd.lang.document.FileId; import net.sourceforge.pmd.lang.document.TextDocument; @@ -42,12 +40,8 @@ import net.sourceforge.pmd.reporting.FileAnalysisListener; /** * Abstract implementation of the analysis cache. Handles all operations, except for persistence. - * - * @deprecated This is internal API, will be hidden with 7.0.0 */ -@Deprecated -@InternalApi -public abstract class AbstractAnalysisCache implements AnalysisCache { +abstract class AbstractAnalysisCache implements AnalysisCache { protected static final Logger LOG = LoggerFactory.getLogger(AbstractAnalysisCache.class); protected static final ClasspathFingerprinter FINGERPRINTER = new ClasspathFingerprinter(); @@ -62,7 +56,7 @@ public abstract class AbstractAnalysisCache implements AnalysisCache { /** * Creates a new empty cache */ - public AbstractAnalysisCache() { + AbstractAnalysisCache() { pmdVersion = PMDVersion.VERSION; } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cache/AnalysisCache.java b/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/AnalysisCache.java similarity index 94% rename from pmd-core/src/main/java/net/sourceforge/pmd/cache/AnalysisCache.java rename to pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/AnalysisCache.java index 2b7e0e1b5a..8568e449af 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cache/AnalysisCache.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/AnalysisCache.java @@ -2,7 +2,7 @@ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ -package net.sourceforge.pmd.cache; +package net.sourceforge.pmd.cache.internal; import java.io.IOException; import java.util.Collection; @@ -10,7 +10,6 @@ import java.util.List; import net.sourceforge.pmd.RuleSets; import net.sourceforge.pmd.RuleViolation; -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.document.TextDocument; import net.sourceforge.pmd.lang.document.TextFile; import net.sourceforge.pmd.reporting.FileAnalysisListener; @@ -20,11 +19,7 @@ import net.sourceforge.pmd.reporting.GlobalAnalysisListener; * An analysis cache for incremental analysis. * Simultaneously manages the old version of the cache, * and the new, most up-to-date violation cache. - * - * @deprecated This is internal API, will be hidden with 7.0.0 */ -@Deprecated -@InternalApi public interface AnalysisCache { /** diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cache/AnalysisCacheListener.java b/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/AnalysisCacheListener.java similarity index 91% rename from pmd-core/src/main/java/net/sourceforge/pmd/cache/AnalysisCacheListener.java rename to pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/AnalysisCacheListener.java index 702631244c..002ac4a3d9 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cache/AnalysisCacheListener.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/AnalysisCacheListener.java @@ -2,13 +2,12 @@ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ -package net.sourceforge.pmd.cache; +package net.sourceforge.pmd.cache.internal; import java.io.IOException; import java.util.Collection; import net.sourceforge.pmd.RuleSets; -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.document.TextFile; import net.sourceforge.pmd.reporting.FileAnalysisListener; import net.sourceforge.pmd.reporting.GlobalAnalysisListener; @@ -16,8 +15,6 @@ import net.sourceforge.pmd.reporting.GlobalAnalysisListener; /** * Adapter to wrap {@link AnalysisCache} behaviour in a {@link GlobalAnalysisListener}. */ -@Deprecated -@InternalApi public class AnalysisCacheListener implements GlobalAnalysisListener { private final AnalysisCache cache; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cache/AnalysisResult.java b/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/AnalysisResult.java similarity index 86% rename from pmd-core/src/main/java/net/sourceforge/pmd/cache/AnalysisResult.java rename to pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/AnalysisResult.java index 6c87b8e052..e5a44a0c0d 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cache/AnalysisResult.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/AnalysisResult.java @@ -2,21 +2,17 @@ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ -package net.sourceforge.pmd.cache; +package net.sourceforge.pmd.cache.internal; import java.util.ArrayList; import java.util.List; import net.sourceforge.pmd.RuleViolation; -import net.sourceforge.pmd.annotation.InternalApi; /** * The result of a single file analysis. * Includes a checksum of the file and the complete list of violations detected. - * @deprecated This is internal API, will be hidden with 7.0.0 */ -@Deprecated -@InternalApi public class AnalysisResult { private final long fileChecksum; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cache/CachedRuleMapper.java b/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/CachedRuleMapper.java similarity index 87% rename from pmd-core/src/main/java/net/sourceforge/pmd/cache/CachedRuleMapper.java rename to pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/CachedRuleMapper.java index aa1be53825..2e3b270171 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cache/CachedRuleMapper.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/CachedRuleMapper.java @@ -2,23 +2,18 @@ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ -package net.sourceforge.pmd.cache; +package net.sourceforge.pmd.cache.internal; import java.util.HashMap; import java.util.Map; import net.sourceforge.pmd.Rule; import net.sourceforge.pmd.RuleSets; -import net.sourceforge.pmd.annotation.InternalApi; /** * A mapper from rule class names to rule instances for cached rules. - * - * @deprecated This is internal API, will be hidden with 7.0.0 */ -@Deprecated -@InternalApi -public class CachedRuleMapper { +class CachedRuleMapper { private final Map cachedRulesInstances = new HashMap<>(); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cache/CachedRuleViolation.java b/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/CachedRuleViolation.java similarity index 95% rename from pmd-core/src/main/java/net/sourceforge/pmd/cache/CachedRuleViolation.java rename to pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/CachedRuleViolation.java index f53d56492e..18fcde4e0f 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cache/CachedRuleViolation.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/CachedRuleViolation.java @@ -2,7 +2,7 @@ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ -package net.sourceforge.pmd.cache; +package net.sourceforge.pmd.cache.internal; import java.io.DataInputStream; import java.io.DataOutputStream; @@ -16,20 +16,15 @@ import org.checkerframework.checker.nullness.qual.NonNull; import net.sourceforge.pmd.Rule; import net.sourceforge.pmd.RuleViolation; -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.document.FileId; import net.sourceforge.pmd.lang.document.FileLocation; import net.sourceforge.pmd.lang.document.TextRange2d; import net.sourceforge.pmd.util.StringUtil; /** - * A {@link RuleViolation} implementation that is immutable, and therefore cache friendly - * - * @deprecated This is internal API, will be hidden with 7.0.0 + * A {@link RuleViolation} implementation that is immutable, and therefore cache friendly. */ -@Deprecated -@InternalApi -public final class CachedRuleViolation implements RuleViolation { +final class CachedRuleViolation implements RuleViolation { private final CachedRuleMapper mapper; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cache/ChecksumAware.java b/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/ChecksumAware.java similarity index 76% rename from pmd-core/src/main/java/net/sourceforge/pmd/cache/ChecksumAware.java rename to pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/ChecksumAware.java index e3a13abb7d..48e9208243 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cache/ChecksumAware.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/ChecksumAware.java @@ -2,9 +2,7 @@ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ -package net.sourceforge.pmd.cache; - -import net.sourceforge.pmd.annotation.InternalApi; +package net.sourceforge.pmd.cache.internal; /** * Interface defining an object that has a checksum The checksum is a @@ -12,11 +10,7 @@ import net.sourceforge.pmd.annotation.InternalApi; * changed on the object. It differs from a {@code hashCode()} in that a * {@code hashCode()} may not take all fields into account, but a checksum must * do so. - * - * @deprecated This is internal API, will be hidden with 7.0.0 */ -@Deprecated -@InternalApi public interface ChecksumAware { /** * Retrieves the current instance checksum diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cache/FileAnalysisCache.java b/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/FileAnalysisCache.java similarity index 97% rename from pmd-core/src/main/java/net/sourceforge/pmd/cache/FileAnalysisCache.java rename to pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/FileAnalysisCache.java index b1fcc12ed0..de286efb9a 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cache/FileAnalysisCache.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/FileAnalysisCache.java @@ -2,7 +2,7 @@ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ -package net.sourceforge.pmd.cache; +package net.sourceforge.pmd.cache.internal; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; @@ -21,7 +21,6 @@ import java.util.stream.Collectors; import net.sourceforge.pmd.PMDVersion; import net.sourceforge.pmd.RuleSets; import net.sourceforge.pmd.RuleViolation; -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.benchmark.TimeTracker; import net.sourceforge.pmd.benchmark.TimedOperation; import net.sourceforge.pmd.benchmark.TimedOperationCategory; @@ -30,11 +29,7 @@ import net.sourceforge.pmd.lang.document.TextFile; /** * An analysis cache backed by a regular file. - * - * @deprecated This is internal API, will be hidden with 7.0.0 */ -@Deprecated -@InternalApi public class FileAnalysisCache extends AbstractAnalysisCache { private final File cacheFile; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cache/NoopAnalysisCache.java b/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/NoopAnalysisCache.java similarity index 87% rename from pmd-core/src/main/java/net/sourceforge/pmd/cache/NoopAnalysisCache.java rename to pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/NoopAnalysisCache.java index ea8896501d..4e4528340d 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cache/NoopAnalysisCache.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/NoopAnalysisCache.java @@ -2,7 +2,7 @@ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ -package net.sourceforge.pmd.cache; +package net.sourceforge.pmd.cache.internal; import java.util.Collection; import java.util.Collections; @@ -10,18 +10,13 @@ import java.util.List; import net.sourceforge.pmd.RuleSets; import net.sourceforge.pmd.RuleViolation; -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.document.TextDocument; import net.sourceforge.pmd.lang.document.TextFile; import net.sourceforge.pmd.reporting.FileAnalysisListener; /** * A NOOP analysis cache. Easier / safer than null-checking. - * - * @deprecated This is internal API, will be hidden with 7.0.0 */ -@Deprecated -@InternalApi public class NoopAnalysisCache implements AnalysisCache { @Override diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cache/package-info.java b/pmd-core/src/main/java/net/sourceforge/pmd/cache/package-info.java index 136dafd316..73a62782a5 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cache/package-info.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cache/package-info.java @@ -3,11 +3,9 @@ */ /** - * The violation caching system. This is an internal subsystem that will - * be largely hidden with 7.0.0. + * The violation caching system. This is mostly an internal subsystem. + * + *

The only public API entry point is + * {@link net.sourceforge.pmd.PMDConfiguration#setAnalysisCacheLocation(java.lang.String)}. */ -@InternalApi -@Deprecated package net.sourceforge.pmd.cache; - -import net.sourceforge.pmd.annotation.InternalApi; 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 ccdc14248d..cebbcf6fa5 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 @@ -11,7 +11,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import net.sourceforge.pmd.RuleSets; import net.sourceforge.pmd.annotation.InternalApi; -import net.sourceforge.pmd.cache.AnalysisCache; +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.MessageReporter; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/impl/PmdRunnable.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/impl/PmdRunnable.java index 8059d94e2b..0944c73172 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/impl/PmdRunnable.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/impl/PmdRunnable.java @@ -15,7 +15,7 @@ import net.sourceforge.pmd.RuleViolation; import net.sourceforge.pmd.benchmark.TimeTracker; import net.sourceforge.pmd.benchmark.TimedOperation; import net.sourceforge.pmd.benchmark.TimedOperationCategory; -import net.sourceforge.pmd.cache.AnalysisCache; +import net.sourceforge.pmd.cache.internal.AnalysisCache; import net.sourceforge.pmd.internal.SystemProps; import net.sourceforge.pmd.lang.LanguageProcessor; import net.sourceforge.pmd.lang.LanguageProcessor.AnalysisTask; diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/PmdConfigurationTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/PmdConfigurationTest.java index 036a03ee85..6d83eb876d 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/PmdConfigurationTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/PmdConfigurationTest.java @@ -30,8 +30,8 @@ import java.util.Properties; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import net.sourceforge.pmd.cache.FileAnalysisCache; -import net.sourceforge.pmd.cache.NoopAnalysisCache; +import net.sourceforge.pmd.cache.internal.FileAnalysisCache; +import net.sourceforge.pmd.cache.internal.NoopAnalysisCache; import net.sourceforge.pmd.internal.util.ClasspathClassLoader; import net.sourceforge.pmd.renderers.CSVRenderer; import net.sourceforge.pmd.renderers.Renderer; diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/cache/FileAnalysisCacheTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/cache/internal/FileAnalysisCacheTest.java similarity index 99% rename from pmd-core/src/test/java/net/sourceforge/pmd/cache/FileAnalysisCacheTest.java rename to pmd-core/src/test/java/net/sourceforge/pmd/cache/internal/FileAnalysisCacheTest.java index 171219ad1f..b459d8945a 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/cache/FileAnalysisCacheTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/cache/internal/FileAnalysisCacheTest.java @@ -2,7 +2,7 @@ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ -package net.sourceforge.pmd.cache; +package net.sourceforge.pmd.cache.internal; import static com.github.stefanbirkner.systemlambda.SystemLambda.restoreSystemProperties; import static net.sourceforge.pmd.util.CollectionUtil.listOf; diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/reporting/GlobalAnalysisListenerTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/reporting/GlobalAnalysisListenerTest.java index 71e6fedfc9..19d1df8e11 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/reporting/GlobalAnalysisListenerTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/reporting/GlobalAnalysisListenerTest.java @@ -24,8 +24,8 @@ import net.sourceforge.pmd.PmdAnalysis; import net.sourceforge.pmd.Rule; import net.sourceforge.pmd.RuleContext; import net.sourceforge.pmd.RuleSet; -import net.sourceforge.pmd.cache.AnalysisCache; -import net.sourceforge.pmd.cache.NoopAnalysisCache; +import net.sourceforge.pmd.cache.internal.AnalysisCache; +import net.sourceforge.pmd.cache.internal.NoopAnalysisCache; import net.sourceforge.pmd.lang.ast.FileAnalysisException; import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.document.FileId; From 3a5ff11dc25e23d3ba3fb304c4da6775e06dcd9d Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 26 Jan 2024 19:06:08 +0100 Subject: [PATCH 02/37] [core] Rename MessageReporter to PmdReporter as public API PmdReporter is supposed to be used when configuring PMD (see AbstractConfiguration#setReporter), so it can't be internal. Refs #4348 --- docs/pages/release_notes.md | 3 +++ .../pmd/cli/commands/internal/PmdCommand.java | 8 ++++---- .../pmd/cli/internal/PmdRootLogger.java | 8 ++++---- .../sourceforge/pmd/AbstractConfiguration.java | 10 +++++----- .../java/net/sourceforge/pmd/PmdAnalysis.java | 18 +++++++++--------- .../net/sourceforge/pmd/RuleSetFactory.java | 18 +++++++++--------- .../net/sourceforge/pmd/RuleSetLoader.java | 8 ++++---- .../sourceforge/pmd/RuleSetReferenceId.java | 6 +++--- .../java/net/sourceforge/pmd/RuleSets.java | 4 ++-- .../net/sourceforge/pmd/cpd/CpdAnalysis.java | 4 ++-- .../pmd/internal/util/FileCollectionUtil.java | 4 ++-- .../pmd/lang/LanguageProcessor.java | 8 ++++---- .../pmd/lang/LanguageProcessorRegistry.java | 14 +++++++------- .../pmd/lang/ast/SemanticErrorReporter.java | 6 +++--- .../pmd/lang/document/FileCollector.java | 12 ++++++------ .../pmd/lang/impl/MultiThreadProcessor.java | 4 ++-- .../net/sourceforge/pmd/rules/RuleFactory.java | 6 +++--- .../pmd/util/internal/xml/PmdXmlReporter.java | 4 ++-- .../{MessageReporter.java => PmdReporter.java} | 12 ++++-------- .../log/internal/ErrorsAsWarningsReporter.java | 8 +++----- .../util/log/internal/MessageReporterBase.java | 4 ++-- .../pmd/util/log/internal/QuietReporter.java | 6 ++---- .../log/internal/SimpleMessageReporter.java | 6 ++---- .../treeexport/TreeExportConfiguration.java | 8 ++++---- .../sourceforge/pmd/DummyParsingHelper.java | 4 ++-- .../net/sourceforge/pmd/PmdAnalysisTest.java | 4 ++-- .../pmd/RulesetFactoryTestBase.java | 4 ++-- .../sourceforge/pmd/cli/PMDFilelistTest.java | 4 ++-- .../lang/LanguageProcessorRegistryTest.java | 4 ++-- .../lang/ast/SemanticErrorReporterTest.java | 6 +++--- .../lang/impl/AbstractPMDProcessorTest.java | 4 ++-- .../pmd/processor/PmdRunnableTest.java | 6 +++--- .../pmd/lang/java/JavaParsingHelper.java | 4 ++-- .../sourceforge/pmd/lang/vf/VFTestUtils.java | 4 ++-- 34 files changed, 113 insertions(+), 120 deletions(-) rename pmd-core/src/main/java/net/sourceforge/pmd/util/log/{MessageReporter.java => PmdReporter.java} (88%) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index fd6547a97c..c2a5c7f2a0 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -196,6 +196,9 @@ The following previously deprecated classes have been removed: **Renamed classes, interfaces** +* pmd-core + * {%jdoc core::util.log.PmdReporter %} - has been renamed from `net.sourceforge.pmd.util.log.MessageReporter` + * pmd-java * The interface `AccessNode` has been renamed to {% jdoc java::lang.ast.ModifierOwner %}. This is only relevant for Java rules, which use that type directly e.g. through downcasting. diff --git a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/PmdCommand.java b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/PmdCommand.java index 29758b74be..feceb9e886 100644 --- a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/PmdCommand.java +++ b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/PmdCommand.java @@ -38,7 +38,7 @@ import net.sourceforge.pmd.renderers.Renderer; import net.sourceforge.pmd.renderers.RendererFactory; import net.sourceforge.pmd.reporting.ReportStats; import net.sourceforge.pmd.util.StringUtil; -import net.sourceforge.pmd.util.log.MessageReporter; +import net.sourceforge.pmd.util.log.PmdReporter; import net.sourceforge.pmd.util.log.internal.SimpleMessageReporter; import picocli.CommandLine.Command; @@ -311,7 +311,7 @@ public class PmdCommand extends AbstractAnalysisPmdSubcommand TimeTracker.startGlobalTracking(); } - final MessageReporter pmdReporter = configuration.getReporter(); + final PmdReporter pmdReporter = configuration.getReporter(); try { PmdAnalysis pmd = null; @@ -359,14 +359,14 @@ public class PmdCommand extends AbstractAnalysisPmdSubcommand } } - private void printErrorDetected(MessageReporter reporter, int errors) { + private void printErrorDetected(PmdReporter reporter, int errors) { String msg = LogMessages.errorDetectedMessage(errors, "pmd"); // note: using error level here increments the error count of the reporter, // which we don't want. reporter.info(StringUtil.quoteMessageFormat(msg)); } - private void finishBenchmarker(final MessageReporter pmdReporter) { + private void finishBenchmarker(final PmdReporter pmdReporter) { if (benchmark) { final TimingReport timingReport = TimeTracker.stopGlobalTracking(); diff --git a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/internal/PmdRootLogger.java b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/internal/PmdRootLogger.java index c687582a63..54f23ad079 100644 --- a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/internal/PmdRootLogger.java +++ b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/internal/PmdRootLogger.java @@ -13,7 +13,7 @@ import org.slf4j.event.Level; import net.sourceforge.pmd.AbstractConfiguration; import net.sourceforge.pmd.internal.Slf4jSimpleConfiguration; -import net.sourceforge.pmd.util.log.MessageReporter; +import net.sourceforge.pmd.util.log.PmdReporter; import net.sourceforge.pmd.util.log.internal.SimpleMessageReporter; /** @@ -46,7 +46,7 @@ public final class PmdRootLogger { resetLogLevel = true; } - MessageReporter pmdReporter = setupMessageReporter(); + PmdReporter pmdReporter = setupMessageReporter(); conf.setReporter(pmdReporter); return runnable.apply(conf); } finally { @@ -58,14 +58,14 @@ public final class PmdRootLogger { } } - private static @NonNull MessageReporter setupMessageReporter() { + private static @NonNull PmdReporter setupMessageReporter() { // Note: This implementation uses slf4j as the backend. If PMD is integrated into an application // a slf4j implementation binding must be provided to see any loggings (even errors). // In pmd-cli, we use slf4j-simple. // create a top-level reporter // TODO CLI errors should also be reported through this - MessageReporter pmdReporter = new SimpleMessageReporter(log); + PmdReporter pmdReporter = new SimpleMessageReporter(log); // always install java.util.logging to slf4j bridge Slf4jSimpleConfiguration.installJulBridge(); // logging, mostly for testing purposes diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/AbstractConfiguration.java b/pmd-core/src/main/java/net/sourceforge/pmd/AbstractConfiguration.java index c9a73c70ae..5b7e2184e5 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/AbstractConfiguration.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/AbstractConfiguration.java @@ -25,7 +25,7 @@ import net.sourceforge.pmd.lang.LanguageRegistry; import net.sourceforge.pmd.lang.LanguageVersion; import net.sourceforge.pmd.lang.LanguageVersionDiscoverer; import net.sourceforge.pmd.util.AssertionUtil; -import net.sourceforge.pmd.util.log.MessageReporter; +import net.sourceforge.pmd.util.log.PmdReporter; /** * Base configuration class for both PMD and CPD. @@ -39,7 +39,7 @@ public abstract class AbstractConfiguration { private Charset sourceEncoding = Charset.forName(System.getProperty("file.encoding")); private final Map langProperties = new HashMap<>(); private final LanguageRegistry langRegistry; - private MessageReporter reporter; + private PmdReporter reporter; private final LanguageVersionDiscoverer languageVersionDiscoverer; private LanguageVersion forceLanguageVersion; private @NonNull List inputPaths = new ArrayList<>(); @@ -49,7 +49,7 @@ public abstract class AbstractConfiguration { private boolean collectRecursive = true; - protected AbstractConfiguration(LanguageRegistry languageRegistry, MessageReporter messageReporter) { + protected AbstractConfiguration(LanguageRegistry languageRegistry, PmdReporter messageReporter) { this.langRegistry = Objects.requireNonNull(languageRegistry); this.languageVersionDiscoverer = new LanguageVersionDiscoverer(languageRegistry); this.reporter = Objects.requireNonNull(messageReporter); @@ -100,7 +100,7 @@ public abstract class AbstractConfiguration { * Returns the message reporter that is to be used while running * the analysis. */ - public @NonNull MessageReporter getReporter() { + public @NonNull PmdReporter getReporter() { return reporter; } @@ -110,7 +110,7 @@ public abstract class AbstractConfiguration { * * @param reporter A non-null message reporter */ - public void setReporter(@NonNull MessageReporter reporter) { + public void setReporter(@NonNull PmdReporter reporter) { AssertionUtil.requireParamNotNull("reporter", reporter); this.reporter = reporter; } 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 6ef8602b73..bc49d48f49 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/PmdAnalysis.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/PmdAnalysis.java @@ -51,7 +51,7 @@ import net.sourceforge.pmd.reporting.ReportStats; import net.sourceforge.pmd.reporting.ReportStatsListener; import net.sourceforge.pmd.util.AssertionUtil; import net.sourceforge.pmd.util.StringUtil; -import net.sourceforge.pmd.util.log.MessageReporter; +import net.sourceforge.pmd.util.log.PmdReporter; /** * Main programmatic API of PMD. This is not a CLI entry point, see module @@ -122,8 +122,8 @@ import net.sourceforge.pmd.util.log.MessageReporter; *

Customizing message output

* *

The analysis reports messages like meta warnings and errors through a - * {@link MessageReporter} instance. To override how those messages are output, - * you can set it in {@link PMDConfiguration#setReporter(MessageReporter)}. + * {@link PmdReporter} instance. To override how those messages are output, + * you can set it in {@link PMDConfiguration#setReporter(PmdReporter)}. * By default, it forwards messages to SLF4J. * */ @@ -136,7 +136,7 @@ public final class PmdAnalysis implements AutoCloseable { private final List listeners = new ArrayList<>(); private final List ruleSets = new ArrayList<>(); private final PMDConfiguration configuration; - private final MessageReporter reporter; + private final PmdReporter reporter; private final Map langProperties = new HashMap<>(); private boolean closed; @@ -344,7 +344,7 @@ public final class PmdAnalysis implements AutoCloseable { * processed. This does not return a report, as the analysis results * are consumed by {@link GlobalAnalysisListener} instances (of which * Renderers are a special case). Note that this does - * not throw, errors are instead accumulated into a {@link MessageReporter}. + * not throw, errors are instead accumulated into a {@link PmdReporter}. */ public void performAnalysis() { performAnalysisImpl(Collections.emptyList()); @@ -355,7 +355,7 @@ public final class PmdAnalysis implements AutoCloseable { * and finish the registered renderers. All files collected in the * {@linkplain #files() file collector} are processed. Returns the * output report. Note that this does not throw, errors are instead - * accumulated into a {@link MessageReporter}. + * accumulated into a {@link PmdReporter}. */ public Report performAnalysisAndCollectReport() { try (GlobalReportBuilderListener reportBuilder = new GlobalReportBuilderListener()) { @@ -534,7 +534,7 @@ public final class PmdAnalysis implements AutoCloseable { } - public MessageReporter getReporter() { + public PmdReporter getReporter() { return reporter; } @@ -586,7 +586,7 @@ public final class PmdAnalysis implements AutoCloseable { return stats; } - static void printErrorDetected(MessageReporter reporter, int errors) { + static void printErrorDetected(PmdReporter reporter, int errors) { String msg = LogMessages.errorDetectedMessage(errors, "PMD"); // note: using error level here increments the error count of the reporter, // which we don't want. @@ -598,7 +598,7 @@ public final class PmdAnalysis implements AutoCloseable { } private static void encourageToUseIncrementalAnalysis(final PMDConfiguration configuration) { - final MessageReporter reporter = configuration.getReporter(); + final PmdReporter reporter = configuration.getReporter(); if (!configuration.isIgnoreIncrementalAnalysis() && configuration.getAnalysisCache() instanceof NoopAnalysisCache diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java index b78a5c6f5d..1c3e7dc455 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java @@ -54,7 +54,7 @@ import net.sourceforge.pmd.util.StringUtil; import net.sourceforge.pmd.util.internal.xml.PmdXmlReporter; import net.sourceforge.pmd.util.internal.xml.XmlErrorMessages; import net.sourceforge.pmd.util.internal.xml.XmlUtil; -import net.sourceforge.pmd.util.log.MessageReporter; +import net.sourceforge.pmd.util.log.PmdReporter; import com.github.oowekyala.ooxml.DomUtils; import com.github.oowekyala.ooxml.messages.NiceXmlMessageSpec; @@ -81,7 +81,7 @@ final class RuleSetFactory { private final RulePriority minimumPriority; private final boolean warnDeprecated; private final RuleSetFactoryCompatibility compatibilityFilter; - private final MessageReporter reporter; + private final PmdReporter reporter; private final boolean includeDeprecatedRuleReferences; private final Map parsedRulesets = new HashMap<>(); @@ -92,7 +92,7 @@ final class RuleSetFactory { boolean warnDeprecated, RuleSetFactoryCompatibility compatFilter, boolean includeDeprecatedRuleReferences, - MessageReporter reporter) { + PmdReporter reporter) { this.resourceLoader = resourceLoader; this.languageRegistry = Objects.requireNonNull(languageRegistry); this.minimumPriority = minimumPriority; @@ -447,7 +447,7 @@ final class RuleSetFactory { return null; // deleted rule } // only emit a warning if we check for deprecated syntax - MessageReporter subReporter = warnDeprecated ? err.at(xmlPlace) : MessageReporter.quiet(); + PmdReporter subReporter = warnDeprecated ? err.at(xmlPlace) : PmdReporter.quiet(); List references = RuleSetReferenceId.parse(ref, subReporter); if (references.size() > 1 && warnDeprecated) { @@ -677,20 +677,20 @@ final class RuleSetFactory { } private static final class PmdXmlReporterImpl - extends XmlMessageReporterBase + extends XmlMessageReporterBase implements PmdXmlReporter { - private final MessageReporter pmdReporter; + private final PmdReporter pmdReporter; private int errCount; - PmdXmlReporterImpl(MessageReporter pmdReporter, OoxmlFacade ooxml, XmlPositioner positioner) { + PmdXmlReporterImpl(PmdReporter pmdReporter, OoxmlFacade ooxml, XmlPositioner positioner) { super(ooxml, positioner); this.pmdReporter = pmdReporter; } @Override - protected MessageReporter create2ndStage(XmlPosition position, XmlPositioner positioner) { - return new MessageReporter() { + protected PmdReporter create2ndStage(XmlPosition position, XmlPositioner positioner) { + return new PmdReporter() { @Override public boolean isLoggable(Level level) { return pmdReporter.isLoggable(level); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetLoader.java b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetLoader.java index 15987ef0bc..cc7b963a6a 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetLoader.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetLoader.java @@ -26,7 +26,7 @@ import net.sourceforge.pmd.lang.Language; import net.sourceforge.pmd.lang.LanguageRegistry; import net.sourceforge.pmd.util.CollectionUtil; import net.sourceforge.pmd.util.ResourceLoader; -import net.sourceforge.pmd.util.log.MessageReporter; +import net.sourceforge.pmd.util.log.PmdReporter; /** * Configurable object to load rulesets from XML resources. @@ -43,7 +43,7 @@ public final class RuleSetLoader { private boolean warnDeprecated = true; private @NonNull RuleSetFactoryCompatibility compatFilter = RuleSetFactoryCompatibility.DEFAULT; private boolean includeDeprecatedRuleReferences = false; - private @NonNull MessageReporter reporter = MessageReporter.quiet(); + private @NonNull PmdReporter reporter = PmdReporter.quiet(); /** * Create a new RuleSetLoader with a default configuration. @@ -53,7 +53,7 @@ public final class RuleSetLoader { // default } - RuleSetLoader withReporter(@NonNull MessageReporter reporter) { + RuleSetLoader withReporter(@NonNull PmdReporter reporter) { this.reporter = Objects.requireNonNull(reporter); return this; } @@ -153,7 +153,7 @@ public final class RuleSetLoader { ); } - private @Nullable MessageReporter filteredReporter() { + private @Nullable PmdReporter filteredReporter() { return warnDeprecated ? reporter : null; } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java index 7afa4f78b2..c518210629 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java @@ -19,7 +19,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.util.ResourceLoader; -import net.sourceforge.pmd.util.log.MessageReporter; +import net.sourceforge.pmd.util.log.PmdReporter; /** * This class is used to parse a RuleSet reference value. Most commonly used for @@ -147,7 +147,7 @@ public class RuleSetReferenceId { */ RuleSetReferenceId(final String id, final RuleSetReferenceId externalRuleSetReferenceId, - final @Nullable MessageReporter err) { + final @Nullable PmdReporter err) { this.originalRef = id; if (externalRuleSetReferenceId != null && !externalRuleSetReferenceId.isExternal()) { @@ -380,7 +380,7 @@ public class RuleSetReferenceId { } static List parse(String referenceString, - MessageReporter err) { + PmdReporter err) { List references = new ArrayList<>(); if (referenceString != null && referenceString.trim().length() > 0) { diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSets.java b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSets.java index 5a118bca1a..178e424cf1 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSets.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSets.java @@ -21,7 +21,7 @@ import net.sourceforge.pmd.lang.ast.RootNode; import net.sourceforge.pmd.lang.document.TextFile; import net.sourceforge.pmd.lang.rule.internal.RuleApplicator; import net.sourceforge.pmd.reporting.FileAnalysisListener; -import net.sourceforge.pmd.util.log.MessageReporter; +import net.sourceforge.pmd.util.log.PmdReporter; /** * Grouping of Rules per Language in a RuleSet. @@ -64,7 +64,7 @@ public class RuleSets { this.ruleSets = Collections.singletonList(ruleSet); } - public void initializeRules(LanguageProcessorRegistry lpReg, MessageReporter reporter) { + public void initializeRules(LanguageProcessorRegistry lpReg, PmdReporter reporter) { // this is abusing the mutability of RuleSet, will go away eventually. for (RuleSet rset : ruleSets) { for (Iterator iterator = rset.getRules().iterator(); iterator.hasNext();) { diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CpdAnalysis.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CpdAnalysis.java index fc1e131825..52e7309f69 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CpdAnalysis.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CpdAnalysis.java @@ -29,7 +29,7 @@ import net.sourceforge.pmd.lang.document.FileId; import net.sourceforge.pmd.lang.document.TextDocument; import net.sourceforge.pmd.lang.document.TextFile; import net.sourceforge.pmd.properties.PropertyDescriptor; -import net.sourceforge.pmd.util.log.MessageReporter; +import net.sourceforge.pmd.util.log.PmdReporter; /** * Main programmatic API of CPD. This is not a CLI entry point, see module @@ -70,7 +70,7 @@ public final class CpdAnalysis implements AutoCloseable { private static final Logger LOGGER = LoggerFactory.getLogger(CpdAnalysis.class); private final CPDConfiguration configuration; private final FileCollector files; - private final MessageReporter reporter; + private final PmdReporter reporter; private final @Nullable CPDReportRenderer renderer; private @NonNull CPDListener listener = new CPDNullListener(); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/internal/util/FileCollectionUtil.java b/pmd-core/src/main/java/net/sourceforge/pmd/internal/util/FileCollectionUtil.java index 9fb518a9e5..8deb034292 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/internal/util/FileCollectionUtil.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/internal/util/FileCollectionUtil.java @@ -21,7 +21,7 @@ import net.sourceforge.pmd.lang.document.FileId; import net.sourceforge.pmd.util.database.DBMSMetadata; import net.sourceforge.pmd.util.database.DBURI; import net.sourceforge.pmd.util.database.SourceObject; -import net.sourceforge.pmd.util.log.MessageReporter; +import net.sourceforge.pmd.util.log.PmdReporter; import net.sourceforge.pmd.util.log.internal.ErrorsAsWarningsReporter; /** @@ -57,7 +57,7 @@ public final class FileCollectionUtil { // This is to be able to interpret the log (will report 'adding' xxx) LOG.debug("Now collecting files to exclude."); // errors like "excluded file does not exist" are reported as warnings. - MessageReporter mutedLog = new ErrorsAsWarningsReporter(collector.getReporter()); + PmdReporter mutedLog = new ErrorsAsWarningsReporter(collector.getReporter()); try (FileCollector excludeCollector = collector.newCollector(mutedLog)) { if (configuration.getIgnoreFile() != null) { 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 cebbcf6fa5..51f227eecf 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 @@ -14,7 +14,7 @@ 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.MessageReporter; +import net.sourceforge.pmd.util.log.PmdReporter; /** * Stateful object managing the analysis for a given language. @@ -65,7 +65,7 @@ public interface LanguageProcessor extends AutoCloseable { private final GlobalAnalysisListener listener; private final int threadCount; private final AnalysisCache analysisCache; - private final MessageReporter messageReporter; + private final PmdReporter messageReporter; private final LanguageProcessorRegistry lpRegistry; @@ -79,7 +79,7 @@ public interface LanguageProcessor extends AutoCloseable { GlobalAnalysisListener listener, int threadCount, AnalysisCache analysisCache, - MessageReporter messageReporter, + PmdReporter messageReporter, LanguageProcessorRegistry lpRegistry) { this.rulesets = rulesets; this.files = files; @@ -110,7 +110,7 @@ public interface LanguageProcessor extends AutoCloseable { return analysisCache; } - public MessageReporter getMessageReporter() { + public PmdReporter getMessageReporter() { return messageReporter; } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageProcessorRegistry.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageProcessorRegistry.java index 19bc5a02ae..dd11a890e7 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageProcessorRegistry.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageProcessorRegistry.java @@ -23,7 +23,7 @@ import net.sourceforge.pmd.properties.PropertyDescriptor; import net.sourceforge.pmd.properties.PropertySource; import net.sourceforge.pmd.util.CollectionUtil; import net.sourceforge.pmd.util.StringUtil.CaseConvention; -import net.sourceforge.pmd.util.log.MessageReporter; +import net.sourceforge.pmd.util.log.PmdReporter; /** * Stores all currently initialized {@link LanguageProcessor}s during analysis. @@ -116,14 +116,14 @@ public final class LanguageProcessorRegistry implements AutoCloseable { */ public static LanguageProcessorRegistry create(LanguageRegistry registry, Map languageProperties, - MessageReporter messageReporter) { + PmdReporter messageReporter) { return create(registry, languageProperties, messageReporter, System.getenv()); } // overload for testing to allow mocking the system env vars. static LanguageProcessorRegistry create(LanguageRegistry registry, Map languageProperties, - MessageReporter messageReporter, + PmdReporter messageReporter, Map env) { Set processors = new HashSet<>(); for (Language language : registry) { @@ -152,7 +152,7 @@ public final class LanguageProcessorRegistry implements AutoCloseable { // TODO this should be reused when implementing the CLI public static Map derivePropertiesFromStrings( Map stringProperties, - MessageReporter reporter + PmdReporter reporter ) { Map typedProperties = new HashMap<>(); stringProperties.forEach((l, props) -> { @@ -163,7 +163,7 @@ public final class LanguageProcessorRegistry implements AutoCloseable { } - private static void setLanguageProperties(Map languageProperties, MessageReporter messageReporter, Language language, LanguagePropertyBundle properties) { + private static void setLanguageProperties(Map languageProperties, PmdReporter messageReporter, Language language, LanguagePropertyBundle properties) { Properties props = languageProperties.get(language); if (props != null) { props.forEach((k, v) -> { @@ -182,7 +182,7 @@ public final class LanguageProcessorRegistry implements AutoCloseable { private static void trySetPropertyCapture(PropertySource source, PropertyDescriptor propertyDescriptor, String propertyValue, - MessageReporter reporter) { + PmdReporter reporter) { try { T value = propertyDescriptor.serializer().fromString(propertyValue); source.setProperty(propertyDescriptor, value); @@ -194,7 +194,7 @@ public final class LanguageProcessorRegistry implements AutoCloseable { } } - private static void readLanguagePropertiesFromEnv(LanguagePropertyBundle props, MessageReporter reporter, Map env) { + private static void readLanguagePropertiesFromEnv(LanguagePropertyBundle props, PmdReporter reporter, Map env) { for (PropertyDescriptor propertyDescriptor : props.getPropertyDescriptors()) { String envVarName = getEnvironmentVariableName(props.getLanguage(), propertyDescriptor); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporter.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporter.java index 4f421b8075..ae95fe2395 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporter.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporter.java @@ -10,7 +10,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.slf4j.event.Level; import net.sourceforge.pmd.util.StringUtil; -import net.sourceforge.pmd.util.log.MessageReporter; +import net.sourceforge.pmd.util.log.PmdReporter; /** * Reports errors that occur after parsing. This may be used to implement @@ -83,10 +83,10 @@ public interface SemanticErrorReporter { /** - * Forwards to a {@link MessageReporter}, except trace and debug + * Forwards to a {@link PmdReporter}, except trace and debug * messages which are reported on a logger. */ - static SemanticErrorReporter reportToLogger(MessageReporter reporter) { + static SemanticErrorReporter reportToLogger(PmdReporter reporter) { return new SemanticErrorReporter() { private SemanticException exception = null; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/document/FileCollector.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/document/FileCollector.java index 6cc0ff5006..3d0ab591aa 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/document/FileCollector.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/document/FileCollector.java @@ -42,7 +42,7 @@ import net.sourceforge.pmd.lang.Language; import net.sourceforge.pmd.lang.LanguageVersion; import net.sourceforge.pmd.lang.LanguageVersionDiscoverer; import net.sourceforge.pmd.util.AssertionUtil; -import net.sourceforge.pmd.util.log.MessageReporter; +import net.sourceforge.pmd.util.log.PmdReporter; /** * Collects files to analyse before a PMD run. This API allows opening @@ -59,14 +59,14 @@ public final class FileCollector implements AutoCloseable { private final List resourcesToClose = new ArrayList<>(); private Charset charset = StandardCharsets.UTF_8; private final LanguageVersionDiscoverer discoverer; - private final MessageReporter reporter; + private final PmdReporter reporter; private final FileId outerFsPath; private boolean closed; private boolean recursive = true; // construction - private FileCollector(LanguageVersionDiscoverer discoverer, MessageReporter reporter, FileId outerFsPath) { + private FileCollector(LanguageVersionDiscoverer discoverer, PmdReporter reporter, FileId outerFsPath) { this.discoverer = discoverer; this.reporter = reporter; this.outerFsPath = outerFsPath; @@ -82,7 +82,7 @@ public final class FileCollector implements AutoCloseable { * creating a collector yourself. */ @InternalApi - public static FileCollector newCollector(LanguageVersionDiscoverer discoverer, MessageReporter reporter) { + public static FileCollector newCollector(LanguageVersionDiscoverer discoverer, PmdReporter reporter) { return new FileCollector(discoverer, reporter, null); } @@ -90,7 +90,7 @@ public final class FileCollector implements AutoCloseable { * Returns a new collector using the configuration except for the logger. */ @InternalApi - public FileCollector newCollector(MessageReporter logger) { + public FileCollector newCollector(PmdReporter logger) { FileCollector fileCollector = new FileCollector(discoverer, logger, null); fileCollector.charset = this.charset; return fileCollector; @@ -118,7 +118,7 @@ public final class FileCollector implements AutoCloseable { * Returns the reporter for the file collection phase. */ @InternalApi - public MessageReporter getReporter() { + public PmdReporter getReporter() { return reporter; } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/impl/MultiThreadProcessor.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/impl/MultiThreadProcessor.java index cd0e26dc37..db0feb12f4 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/impl/MultiThreadProcessor.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/impl/MultiThreadProcessor.java @@ -15,7 +15,7 @@ import java.util.concurrent.TimeUnit; import net.sourceforge.pmd.RuleSets; import net.sourceforge.pmd.lang.LanguageProcessor.AnalysisTask; import net.sourceforge.pmd.lang.document.TextFile; -import net.sourceforge.pmd.util.log.MessageReporter; +import net.sourceforge.pmd.util.log.PmdReporter; /** @@ -43,7 +43,7 @@ final class MultiThreadProcessor extends AbstractPMDProcessor { RuleSets copy = new RuleSets(task.getRulesets()); // use a noop reporter because the copy should only contain rules that // initialized properly - copy.initializeRules(task.getLpRegistry(), MessageReporter.quiet()); + copy.initializeRules(task.getLpRegistry(), PmdReporter.quiet()); return copy; }); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/rules/RuleFactory.java b/pmd-core/src/main/java/net/sourceforge/pmd/rules/RuleFactory.java index b3a0a2cbde..7b4dd0310d 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/rules/RuleFactory.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/rules/RuleFactory.java @@ -63,7 +63,7 @@ import net.sourceforge.pmd.util.internal.xml.PmdXmlReporter; import net.sourceforge.pmd.util.internal.xml.SchemaConstant; import net.sourceforge.pmd.util.internal.xml.XmlErrorMessages; import net.sourceforge.pmd.util.internal.xml.XmlUtil; -import net.sourceforge.pmd.util.log.MessageReporter; +import net.sourceforge.pmd.util.log.PmdReporter; import com.github.oowekyala.ooxml.DomUtils; import com.github.oowekyala.ooxml.messages.XmlException; @@ -429,7 +429,7 @@ public class RuleFactory { } - private static @Nullable T tryParsePropertyValue(BuilderAndMapper factory, String value, MessageReporter err) { + private static @Nullable T tryParsePropertyValue(BuilderAndMapper factory, String value, PmdReporter err) { try { return factory.getXmlMapper().fromString(value); } catch (IllegalArgumentException e) { @@ -437,7 +437,7 @@ public class RuleFactory { } } - private static Comparable asComparableOrThrow(T object, MessageReporter err) { + private static Comparable asComparableOrThrow(T object, PmdReporter err) { if (object instanceof Comparable) { return (Comparable) object; } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/util/internal/xml/PmdXmlReporter.java b/pmd-core/src/main/java/net/sourceforge/pmd/util/internal/xml/PmdXmlReporter.java index 02464f545a..a0facb0fdb 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/util/internal/xml/PmdXmlReporter.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/util/internal/xml/PmdXmlReporter.java @@ -4,13 +4,13 @@ package net.sourceforge.pmd.util.internal.xml; -import net.sourceforge.pmd.util.log.MessageReporter; +import net.sourceforge.pmd.util.log.PmdReporter; import com.github.oowekyala.ooxml.messages.XmlMessageReporter; /** * @author Clément Fournier */ -public interface PmdXmlReporter extends XmlMessageReporter { +public interface PmdXmlReporter extends XmlMessageReporter { } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/util/log/MessageReporter.java b/pmd-core/src/main/java/net/sourceforge/pmd/util/log/PmdReporter.java similarity index 88% rename from pmd-core/src/main/java/net/sourceforge/pmd/util/log/MessageReporter.java rename to pmd-core/src/main/java/net/sourceforge/pmd/util/log/PmdReporter.java index 9763f6ad01..bfdaab89e6 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/util/log/MessageReporter.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/util/log/PmdReporter.java @@ -9,22 +9,18 @@ import java.text.MessageFormat; import org.checkerframework.checker.nullness.qual.Nullable; import org.slf4j.event.Level; -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.util.log.internal.QuietReporter; /** * Façade to report user-facing messages (info, warning and error). - * Note: messages are formatted using {@link MessageFormat}. * - *

Internal API: this is a transitional API that will be significantly - * changed in PMD 7, with the transition to SLF4J. See https://github.com/pmd/pmd/issues/3816 + *

Note: messages are formatted using {@link MessageFormat}. * - * TODO rename to PmdReporter + *

Note: This interface was called net.sourceforge.pmd.util.log.MessageReporter in PMD 6.

* * @author Clément Fournier */ -@InternalApi -public interface MessageReporter { +public interface PmdReporter { // todo change String to MessageFormat in those arg lists, it's too confusing // where to apply MessageFormat otherwise... @@ -101,7 +97,7 @@ public interface MessageReporter { * Returns a reporter instance that does not output anything, but * still counts errors. */ - static MessageReporter quiet() { + static PmdReporter quiet() { return new QuietReporter(); } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/util/log/internal/ErrorsAsWarningsReporter.java b/pmd-core/src/main/java/net/sourceforge/pmd/util/log/internal/ErrorsAsWarningsReporter.java index 71b201e2cc..9befa9e29f 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/util/log/internal/ErrorsAsWarningsReporter.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/util/log/internal/ErrorsAsWarningsReporter.java @@ -6,20 +6,18 @@ package net.sourceforge.pmd.util.log.internal; import org.slf4j.event.Level; -import net.sourceforge.pmd.annotation.InternalApi; -import net.sourceforge.pmd.util.log.MessageReporter; +import net.sourceforge.pmd.util.log.PmdReporter; /** * Turns errors into warnings reported on another logger. * * @author Clément Fournier */ -@InternalApi public final class ErrorsAsWarningsReporter extends MessageReporterBase { - private final MessageReporter backend; + private final PmdReporter backend; - public ErrorsAsWarningsReporter(MessageReporter backend) { + public ErrorsAsWarningsReporter(PmdReporter backend) { this.backend = backend; } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/util/log/internal/MessageReporterBase.java b/pmd-core/src/main/java/net/sourceforge/pmd/util/log/internal/MessageReporterBase.java index e0929ac7d5..617b150237 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/util/log/internal/MessageReporterBase.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/util/log/internal/MessageReporterBase.java @@ -14,14 +14,14 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.slf4j.event.Level; -import net.sourceforge.pmd.util.log.MessageReporter; +import net.sourceforge.pmd.util.log.PmdReporter; /** * Base implementation. * * @author Clément Fournier */ -public abstract class MessageReporterBase implements MessageReporter { +public abstract class MessageReporterBase implements PmdReporter { private int numErrors; private @Nullable Level minLevel = Level.TRACE; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/util/log/internal/QuietReporter.java b/pmd-core/src/main/java/net/sourceforge/pmd/util/log/internal/QuietReporter.java index ca9cfe55a9..b60bba7b46 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/util/log/internal/QuietReporter.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/util/log/internal/QuietReporter.java @@ -6,16 +6,14 @@ package net.sourceforge.pmd.util.log.internal; import org.slf4j.event.Level; -import net.sourceforge.pmd.annotation.InternalApi; -import net.sourceforge.pmd.util.log.MessageReporter; +import net.sourceforge.pmd.util.log.PmdReporter; /** * A logger that ignores all messages. * * @author Clément Fournier */ -@InternalApi -public class QuietReporter extends MessageReporterBase implements MessageReporter { +public class QuietReporter extends MessageReporterBase implements PmdReporter { // note: not singleton because PmdLogger accumulates error count. // note: not final because used as mock in tests. diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/util/log/internal/SimpleMessageReporter.java b/pmd-core/src/main/java/net/sourceforge/pmd/util/log/internal/SimpleMessageReporter.java index f7ce618fa6..fd6189dbe6 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/util/log/internal/SimpleMessageReporter.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/util/log/internal/SimpleMessageReporter.java @@ -7,16 +7,14 @@ package net.sourceforge.pmd.util.log.internal; import org.slf4j.Logger; import org.slf4j.event.Level; -import net.sourceforge.pmd.annotation.InternalApi; -import net.sourceforge.pmd.util.log.MessageReporter; +import net.sourceforge.pmd.util.log.PmdReporter; /** * A {@link Logger} (java.util) based logger impl. * * @author Clément Fournier */ -@InternalApi -public class SimpleMessageReporter extends MessageReporterBase implements MessageReporter { +public class SimpleMessageReporter extends MessageReporterBase implements PmdReporter { private final Logger backend; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/util/treeexport/TreeExportConfiguration.java b/pmd-core/src/main/java/net/sourceforge/pmd/util/treeexport/TreeExportConfiguration.java index b57dbd0e34..2f55cb36d4 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/util/treeexport/TreeExportConfiguration.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/util/treeexport/TreeExportConfiguration.java @@ -14,7 +14,7 @@ import org.slf4j.LoggerFactory; import net.sourceforge.pmd.AbstractConfiguration; import net.sourceforge.pmd.lang.Language; import net.sourceforge.pmd.lang.LanguageRegistry; -import net.sourceforge.pmd.util.log.MessageReporter; +import net.sourceforge.pmd.util.log.PmdReporter; import net.sourceforge.pmd.util.log.internal.SimpleMessageReporter; public class TreeExportConfiguration extends AbstractConfiguration { @@ -28,7 +28,7 @@ public class TreeExportConfiguration extends AbstractConfiguration { private Properties languageProperties = new Properties(); private Path file; private boolean readStdin; - private MessageReporter messageReporter = new SimpleMessageReporter(LOG); + private PmdReporter messageReporter = new SimpleMessageReporter(LOG); public TreeExportConfiguration(LanguageRegistry registry) { super(registry, new SimpleMessageReporter(LoggerFactory.getLogger(TreeExporter.class))); @@ -86,11 +86,11 @@ public class TreeExportConfiguration extends AbstractConfiguration { this.readStdin = readStdin; } - public MessageReporter getMessageReporter() { + public PmdReporter getMessageReporter() { return messageReporter; } - public void setMessageReporter(MessageReporter messageReporter) { + public void setMessageReporter(PmdReporter messageReporter) { this.messageReporter = messageReporter; } diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/DummyParsingHelper.java b/pmd-core/src/test/java/net/sourceforge/pmd/DummyParsingHelper.java index 417de87663..aa0da9ba92 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/DummyParsingHelper.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/DummyParsingHelper.java @@ -21,7 +21,7 @@ import net.sourceforge.pmd.lang.ast.Parser.ParserTask; import net.sourceforge.pmd.lang.ast.SemanticErrorReporter; import net.sourceforge.pmd.lang.document.FileId; import net.sourceforge.pmd.lang.document.TextDocument; -import net.sourceforge.pmd.util.log.MessageReporter; +import net.sourceforge.pmd.util.log.PmdReporter; /** * @author Clément Fournier @@ -61,7 +61,7 @@ public class DummyParsingHelper implements Extension, BeforeEachCallback, AfterE LanguageProcessorRegistry registry = LanguageProcessorRegistry.create( LanguageRegistry.PMD, Collections.emptyMap(), - MessageReporter.quiet() + PmdReporter.quiet() ); dummyProcessor = registry.getProcessor(DummyLanguageModule.getInstance()); } diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/PmdAnalysisTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/PmdAnalysisTest.java index 8095c7a009..1f4e7c14bc 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/PmdAnalysisTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/PmdAnalysisTest.java @@ -33,7 +33,7 @@ import net.sourceforge.pmd.lang.document.SimpleTestTextFile; import net.sourceforge.pmd.lang.rule.AbstractRule; import net.sourceforge.pmd.renderers.Renderer; import net.sourceforge.pmd.reporting.ReportStats; -import net.sourceforge.pmd.util.log.MessageReporter; +import net.sourceforge.pmd.util.log.PmdReporter; /** * @author Clément Fournier @@ -106,7 +106,7 @@ class PmdAnalysisTest { void testRuleFailureDuringInitialization() { PMDConfiguration config = new PMDConfiguration(); config.setThreads(1); - MessageReporter mockReporter = spy(MessageReporter.quiet()); + PmdReporter mockReporter = spy(PmdReporter.quiet()); config.setReporter(mockReporter); try (PmdAnalysis pmd = PmdAnalysis.create(config)) { diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/RulesetFactoryTestBase.java b/pmd-core/src/test/java/net/sourceforge/pmd/RulesetFactoryTestBase.java index f21796ee76..37d8fb7602 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/RulesetFactoryTestBase.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/RulesetFactoryTestBase.java @@ -30,12 +30,12 @@ import org.slf4j.event.Level; import net.sourceforge.pmd.lang.DummyLanguageModule; import net.sourceforge.pmd.util.internal.xml.SchemaConstant; import net.sourceforge.pmd.util.internal.xml.SchemaConstants; -import net.sourceforge.pmd.util.log.MessageReporter; +import net.sourceforge.pmd.util.log.PmdReporter; import net.sourceforge.pmd.util.log.internal.SimpleMessageReporter; public class RulesetFactoryTestBase { - protected MessageReporter mockReporter; + protected PmdReporter mockReporter; @BeforeEach void setup() { diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/cli/PMDFilelistTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/cli/PMDFilelistTest.java index b3693969d1..8e49b3be93 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/cli/PMDFilelistTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/cli/PMDFilelistTest.java @@ -25,14 +25,14 @@ import net.sourceforge.pmd.lang.LanguageRegistry; import net.sourceforge.pmd.lang.LanguageVersionDiscoverer; import net.sourceforge.pmd.lang.document.FileCollector; import net.sourceforge.pmd.lang.document.TextFile; -import net.sourceforge.pmd.util.log.MessageReporter; +import net.sourceforge.pmd.util.log.PmdReporter; class PMDFilelistTest { private static final Path RESOURCES = Paths.get("src/test/resources/net/sourceforge/pmd/cli/"); private @NonNull FileCollector newCollector() { - return FileCollector.newCollector(new LanguageVersionDiscoverer(LanguageRegistry.PMD), MessageReporter.quiet()); + return FileCollector.newCollector(new LanguageVersionDiscoverer(LanguageRegistry.PMD), PmdReporter.quiet()); } @Test diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/lang/LanguageProcessorRegistryTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/lang/LanguageProcessorRegistryTest.java index eb500bbfc6..cb4824a27b 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/lang/LanguageProcessorRegistryTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/lang/LanguageProcessorRegistryTest.java @@ -13,7 +13,7 @@ import org.junit.jupiter.api.Test; import net.sourceforge.pmd.properties.PropertyDescriptor; import net.sourceforge.pmd.properties.PropertyFactory; -import net.sourceforge.pmd.util.log.MessageReporter; +import net.sourceforge.pmd.util.log.PmdReporter; class LanguageProcessorRegistryTest { @Test @@ -28,7 +28,7 @@ class LanguageProcessorRegistryTest { DummyLanguagePropertyBundle bundle = new DummyLanguagePropertyBundle(dummyLanguage); languageProperties.put(dummyLanguage, bundle); - try (LanguageProcessorRegistry ignored = LanguageProcessorRegistry.create(languageRegistry, languageProperties, MessageReporter.quiet(), env)) { + try (LanguageProcessorRegistry ignored = LanguageProcessorRegistry.create(languageRegistry, languageProperties, PmdReporter.quiet(), env)) { assertEquals("theValue", bundle.getRootDirectory()); } } diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporterTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporterTest.java index e5c1b86e71..7769164d37 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporterTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporterTest.java @@ -22,7 +22,7 @@ import org.slf4j.event.Level; import org.slf4j.helpers.NOPLogger; import net.sourceforge.pmd.DummyParsingHelper; -import net.sourceforge.pmd.util.log.MessageReporter; +import net.sourceforge.pmd.util.log.PmdReporter; /** * Reports errors that occur after parsing. This may be used to implement @@ -30,7 +30,7 @@ import net.sourceforge.pmd.util.log.MessageReporter; */ class SemanticErrorReporterTest { - MessageReporter mockReporter; + PmdReporter mockReporter; Logger mockLogger; @RegisterExtension @@ -38,7 +38,7 @@ class SemanticErrorReporterTest { @BeforeEach void setup() { - mockReporter = mock(MessageReporter.class); + mockReporter = mock(PmdReporter.class); when(mockReporter.isLoggable(Level.ERROR)).thenReturn(true); mockLogger = spy(NOPLogger.class); } 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 ca52a03e65..060515d596 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 @@ -28,12 +28,12 @@ import net.sourceforge.pmd.lang.document.TextFile; import net.sourceforge.pmd.lang.rule.AbstractRule; import net.sourceforge.pmd.reporting.FileAnalysisListener; import net.sourceforge.pmd.reporting.GlobalAnalysisListener; -import net.sourceforge.pmd.util.log.MessageReporter; +import net.sourceforge.pmd.util.log.PmdReporter; abstract class AbstractPMDProcessorTest { protected SimpleReportListener reportListener; - protected MessageReporter reporter; + protected PmdReporter reporter; protected abstract int getThreads(); diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/processor/PmdRunnableTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/processor/PmdRunnableTest.java index 93da9002b1..f2d7e24d45 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/processor/PmdRunnableTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/processor/PmdRunnableTest.java @@ -42,7 +42,7 @@ import net.sourceforge.pmd.lang.document.FileId; import net.sourceforge.pmd.lang.impl.SimpleLanguageModuleBase; import net.sourceforge.pmd.lang.rule.AbstractRule; import net.sourceforge.pmd.util.ContextedAssertionError; -import net.sourceforge.pmd.util.log.MessageReporter; +import net.sourceforge.pmd.util.log.PmdReporter; import com.github.stefanbirkner.systemlambda.SystemLambda; @@ -54,7 +54,7 @@ class PmdRunnableTest { private static final String THROWS_ASSERTION_ERROR = "1.9-throws"; private PMDConfiguration configuration; - private MessageReporter reporter; + private PmdReporter reporter; private Rule rule; @@ -63,7 +63,7 @@ class PmdRunnableTest { // reset data rule = spy(new RuleThatThrows()); configuration = new PMDConfiguration(LanguageRegistry.singleton(ThrowingLanguageModule.INSTANCE)); - reporter = mock(MessageReporter.class); + reporter = mock(PmdReporter.class); configuration.setReporter(reporter); // exceptions thrown on a worker thread are not thrown by the main thread, // so this test only makes sense without separate threads diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/JavaParsingHelper.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/JavaParsingHelper.java index 4a16d064d5..0fd2359166 100644 --- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/JavaParsingHelper.java +++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/JavaParsingHelper.java @@ -33,7 +33,7 @@ import net.sourceforge.pmd.lang.java.types.TypeSystem; import net.sourceforge.pmd.lang.java.types.internal.infer.TypeInferenceLogger; import net.sourceforge.pmd.lang.java.types.internal.infer.TypeInferenceLogger.SimpleLogger; import net.sourceforge.pmd.lang.java.types.internal.infer.TypeInferenceLogger.VerboseLogger; -import net.sourceforge.pmd.util.log.MessageReporter; +import net.sourceforge.pmd.util.log.PmdReporter; import net.sourceforge.pmd.util.log.internal.SimpleMessageReporter; import kotlin.Pair; @@ -129,7 +129,7 @@ public class JavaParsingHelper extends BaseParsingHelper Date: Sat, 27 Jan 2024 18:06:23 +0100 Subject: [PATCH 03/37] [core] Move n.s.pmd.util.internal.ResourceLoader Refs #4348 --- docs/pages/release_notes.md | 1 + .../src/main/java/net/sourceforge/pmd/RuleSetFactory.java | 2 +- .../src/main/java/net/sourceforge/pmd/RuleSetLoader.java | 2 +- .../main/java/net/sourceforge/pmd/RuleSetReferenceId.java | 2 +- .../main/java/net/sourceforge/pmd/rules/RuleFactory.java | 2 +- .../pmd/util/{ => internal}/ResourceLoader.java | 7 ++----- .../test/java/net/sourceforge/pmd/RuleSetFactoryTest.java | 2 +- .../java/net/sourceforge/pmd/RuleSetReferenceIdTest.java | 2 +- 8 files changed, 9 insertions(+), 11 deletions(-) rename pmd-core/src/main/java/net/sourceforge/pmd/util/{ => internal}/ResourceLoader.java (96%) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index c2a5c7f2a0..d94d0e0f65 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -168,6 +168,7 @@ The following classes have been marked as @InternalApi before and are no * {%jdoc core::cache.internal.ChecksumAware %} * {%jdoc core::cache.internal.FileAnalysisCache %} * {%jdoc core::cache.internal.NoopAnalysisCache %} + * {%jdoc core::util.internal.ResourceLoader %} **Removed classes and methods (previously deprecated)** diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java index 1c3e7dc455..4d8d954461 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java @@ -49,8 +49,8 @@ import net.sourceforge.pmd.RuleSet.RuleSetBuilder; import net.sourceforge.pmd.lang.LanguageRegistry; import net.sourceforge.pmd.lang.rule.RuleReference; import net.sourceforge.pmd.rules.RuleFactory; -import net.sourceforge.pmd.util.ResourceLoader; import net.sourceforge.pmd.util.StringUtil; +import net.sourceforge.pmd.util.internal.ResourceLoader; import net.sourceforge.pmd.util.internal.xml.PmdXmlReporter; import net.sourceforge.pmd.util.internal.xml.XmlErrorMessages; import net.sourceforge.pmd.util.internal.xml.XmlUtil; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetLoader.java b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetLoader.java index cc7b963a6a..2e9ae672fd 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetLoader.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetLoader.java @@ -25,7 +25,7 @@ import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.Language; import net.sourceforge.pmd.lang.LanguageRegistry; import net.sourceforge.pmd.util.CollectionUtil; -import net.sourceforge.pmd.util.ResourceLoader; +import net.sourceforge.pmd.util.internal.ResourceLoader; import net.sourceforge.pmd.util.log.PmdReporter; /** diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java index c518210629..486f6b71e5 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java @@ -18,7 +18,7 @@ import org.apache.commons.lang3.StringUtils; import org.checkerframework.checker.nullness.qual.Nullable; import net.sourceforge.pmd.annotation.InternalApi; -import net.sourceforge.pmd.util.ResourceLoader; +import net.sourceforge.pmd.util.internal.ResourceLoader; import net.sourceforge.pmd.util.log.PmdReporter; /** diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/rules/RuleFactory.java b/pmd-core/src/main/java/net/sourceforge/pmd/rules/RuleFactory.java index 7b4dd0310d..14c491535d 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/rules/RuleFactory.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/rules/RuleFactory.java @@ -57,8 +57,8 @@ import net.sourceforge.pmd.properties.PropertyDescriptor; import net.sourceforge.pmd.properties.PropertySerializer; import net.sourceforge.pmd.properties.PropertyTypeId; import net.sourceforge.pmd.properties.PropertyTypeId.BuilderAndMapper; -import net.sourceforge.pmd.util.ResourceLoader; import net.sourceforge.pmd.util.StringUtil; +import net.sourceforge.pmd.util.internal.ResourceLoader; import net.sourceforge.pmd.util.internal.xml.PmdXmlReporter; import net.sourceforge.pmd.util.internal.xml.SchemaConstant; import net.sourceforge.pmd.util.internal.xml.XmlErrorMessages; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/util/ResourceLoader.java b/pmd-core/src/main/java/net/sourceforge/pmd/util/internal/ResourceLoader.java similarity index 96% rename from pmd-core/src/main/java/net/sourceforge/pmd/util/ResourceLoader.java rename to pmd-core/src/main/java/net/sourceforge/pmd/util/internal/ResourceLoader.java index d9d4d7e5b0..cd1df7976b 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/util/ResourceLoader.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/util/internal/ResourceLoader.java @@ -2,7 +2,7 @@ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ -package net.sourceforge.pmd.util; +package net.sourceforge.pmd.util.internal; import java.io.File; import java.io.FileNotFoundException; @@ -18,13 +18,10 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import net.sourceforge.pmd.Rule; -import net.sourceforge.pmd.annotation.InternalApi; /** - * @deprecated Is internal API + * @apiNote Internal API */ -@Deprecated -@InternalApi public class ResourceLoader { public static final int TIMEOUT; diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetFactoryTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetFactoryTest.java index 541f88b477..e4378b29ad 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetFactoryTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetFactoryTest.java @@ -28,7 +28,7 @@ import org.mockito.Mockito; import net.sourceforge.pmd.lang.rule.MockRule; import net.sourceforge.pmd.lang.rule.RuleReference; import net.sourceforge.pmd.properties.PropertyDescriptor; -import net.sourceforge.pmd.util.ResourceLoader; +import net.sourceforge.pmd.util.internal.ResourceLoader; import net.sourceforge.pmd.util.internal.xml.SchemaConstants; import com.github.stefanbirkner.systemlambda.SystemLambda; diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetReferenceIdTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetReferenceIdTest.java index 4e271dbbba..b022d90893 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetReferenceIdTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetReferenceIdTest.java @@ -26,7 +26,7 @@ import java.util.List; import org.junit.jupiter.api.Test; import net.sourceforge.pmd.internal.util.IOUtil; -import net.sourceforge.pmd.util.ResourceLoader; +import net.sourceforge.pmd.util.internal.ResourceLoader; import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; import com.github.tomakehurst.wiremock.junit5.WireMockTest; From db0392cba1fe26bffa965a146e78d062e32a6fe9 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 27 Jan 2024 18:39:20 +0100 Subject: [PATCH 04/37] [core] n.s.pmd.cpd.Tokens#Tokens() is now package private Refs #4348 --- docs/pages/release_notes.md | 6 ++++-- .../java/net/sourceforge/pmd/cpd/Tokenizer.java | 6 ++++++ .../main/java/net/sourceforge/pmd/cpd/Tokens.java | 12 +++++------- .../pmd/lang/java/cpd/JavaTokenizerTest.java | 5 +---- .../pmd/cpd/test/CpdTextComparisonTest.kt | 15 ++++++--------- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index d94d0e0f65..7985ac14f4 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -154,9 +154,10 @@ in the Migration Guide. #### API Changes -**Internalized classes and interfaces** +**Internalized classes and interfaces and methods** -The following classes have been marked as @InternalApi before and are now moved into a `internal` package: +The following classes/methods have been marked as @InternalApi before and are now moved into a `internal` +package or made package private and are not accessible anymore. * pmd-core * {%jdoc core::cache.internal.AbstractAnalysisCache %} (now package private) @@ -169,6 +170,7 @@ The following classes have been marked as @InternalApi before and are no * {%jdoc core::cache.internal.FileAnalysisCache %} * {%jdoc core::cache.internal.NoopAnalysisCache %} * {%jdoc core::util.internal.ResourceLoader %} + * {%jdoc core::cpd.Tokens#Tokens() %} (the constructor is now package private) **Removed classes and methods (previously deprecated)** diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/Tokenizer.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/Tokenizer.java index e1bd1e84e2..5c37848c0c 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/Tokenizer.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/Tokenizer.java @@ -27,4 +27,10 @@ public interface Tokenizer { tokenizer.tokenize(textDocument, tf); } } + + static Tokens tokenize(Tokenizer tokenizer, TextDocument textDocument) throws IOException { + Tokens tokens = new Tokens(); + tokenize(tokenizer, textDocument, tokens); + return tokens; + } } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/Tokens.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/Tokens.java index 3f314121e5..f87877f95a 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/Tokens.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/Tokens.java @@ -13,7 +13,6 @@ import java.util.Map.Entry; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.ast.TokenMgrError; import net.sourceforge.pmd.lang.document.FileId; import net.sourceforge.pmd.lang.document.TextDocument; @@ -22,7 +21,6 @@ import net.sourceforge.pmd.lang.document.TextDocument; * Global token collector for CPD. This is populated by lexing all files, * after which the match algorithm proceeds. */ -@InternalApi public class Tokens { // This stores all the token entries recorded during the run. @@ -32,12 +30,12 @@ public class Tokens { private int curImageId = 1; /** - * Create a new instance, is internal. + * Create a new instance. + * + * @apiNote Internal API */ - @InternalApi - @Deprecated // just to get a warning - public Tokens() { // NOPMD: UnnecessaryConstructor - constructor is needed to place the annotations - // constructor is needed to place the annotations + Tokens() { + // constructor is package private } private void add(TokenEntry tokenEntry) { diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/cpd/JavaTokenizerTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/cpd/JavaTokenizerTest.java index 17a873fc1c..fd7e56f9f4 100644 --- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/cpd/JavaTokenizerTest.java +++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/cpd/JavaTokenizerTest.java @@ -13,7 +13,6 @@ import org.junit.jupiter.api.Test; import net.sourceforge.pmd.cpd.CpdLanguageProperties; import net.sourceforge.pmd.cpd.Tokenizer; -import net.sourceforge.pmd.cpd.Tokens; import net.sourceforge.pmd.cpd.test.CpdTextComparisonTest; import net.sourceforge.pmd.cpd.test.LanguagePropertyConfig; import net.sourceforge.pmd.lang.ast.TokenMgrError; @@ -41,12 +40,10 @@ class JavaTokenizerTest extends CpdTextComparisonTest { @Test void testLexExceptionLocation() { Tokenizer tokenizer = newTokenizer(defaultProperties()); - Tokens tokens = new Tokens(); TokenMgrError lexException = assertThrows(TokenMgrError.class, () -> Tokenizer.tokenize(tokenizer, // note: the source deliberately contains an unbalanced quote, unterminated string literal - TextDocument.readOnlyString("class F {\n String s=\"abc\";\"\n}\n", FileId.UNKNOWN, getLanguage().getDefaultVersion()), - tokens) + TextDocument.readOnlyString("class F {\n String s=\"abc\";\"\n}\n", FileId.UNKNOWN, getLanguage().getDefaultVersion())) ); // this shouldn't throw a IllegalArgumentException assertThat(lexException.getMessage(), containsString("at line 3, column 1")); diff --git a/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/cpd/test/CpdTextComparisonTest.kt b/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/cpd/test/CpdTextComparisonTest.kt index 5c1b1f1c12..6b53b3ef60 100644 --- a/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/cpd/test/CpdTextComparisonTest.kt +++ b/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/cpd/test/CpdTextComparisonTest.kt @@ -5,17 +5,17 @@ package net.sourceforge.pmd.cpd.test import io.kotest.assertions.throwables.shouldThrow -import net.sourceforge.pmd.cpd.* -import net.sourceforge.pmd.lang.Language +import net.sourceforge.pmd.cpd.CpdCapableLanguage +import net.sourceforge.pmd.cpd.TokenEntry +import net.sourceforge.pmd.cpd.Tokenizer +import net.sourceforge.pmd.cpd.Tokens import net.sourceforge.pmd.lang.LanguagePropertyBundle import net.sourceforge.pmd.lang.LanguageRegistry import net.sourceforge.pmd.lang.ast.TokenMgrError -import net.sourceforge.pmd.lang.document.TextDocument -import net.sourceforge.pmd.lang.document.TextFile import net.sourceforge.pmd.lang.document.FileId +import net.sourceforge.pmd.lang.document.TextDocument import net.sourceforge.pmd.test.BaseTextComparisonTest import org.apache.commons.lang3.StringUtils -import java.util.* /** * CPD test comparing a dump of a file against a saved baseline. @@ -173,10 +173,7 @@ abstract class CpdTextComparisonTest( FileData(fileName = fileName, fileText = text) fun tokenize(tokenizer: Tokenizer, fileData: FileData): Tokens = - Tokens().also { tokens -> - val source = sourceCodeOf(fileData) - Tokenizer.tokenize(tokenizer, source, tokens) - } + Tokenizer.tokenize(tokenizer, sourceCodeOf(fileData)) private companion object { const val Indent = " " From 217f0f43f8d09a44ef25f469d7d77f71b1554422 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 27 Jan 2024 18:44:01 +0100 Subject: [PATCH 05/37] [core] PropertyTypeId and PropertyDescriptor#getTypeId Both stay Internal API, update javadoc Refs #4348 --- .../sourceforge/pmd/properties/PropertyDescriptor.java | 2 ++ .../net/sourceforge/pmd/properties/PropertyTypeId.java | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyDescriptor.java b/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyDescriptor.java index 5bd40d48fb..a4e2fc708f 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyDescriptor.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyDescriptor.java @@ -104,6 +104,8 @@ public final class PropertyDescriptor { * Returns the type ID which was used to define this property. Returns * null if this property was defined in Java code and not in XML. This * is used to write the property back to XML, when using a {@link RuleSetWriter}. + * + * @apiNote Internal API */ @InternalApi public @Nullable PropertyTypeId getTypeId() { diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyTypeId.java b/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyTypeId.java index 4454f16ee7..972f9204c0 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyTypeId.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyTypeId.java @@ -18,14 +18,14 @@ import net.sourceforge.pmd.annotation.InternalApi; * of the property that should be built. The mapping between the values of this attribute * and the concrete property that is built is encoded in the constants of this enum. * - *

Properties API changes

This class' API is mainly provided to build GUIs for XPath rules + *

This class' API is mainly provided to build GUIs for XPath rules * like the rule designer, so that they have info about the available properties from XML. As such, - * the number of clients are probably low. Nevertheless, a bunch of members have been deprecated to - * warn about probable upcoming API changes with 7.0.0, but the amount of change may be greater. - * See {@link PropertyDescriptor} for more info about property framework changes with 7.0.0. + * the number of clients are probably low. Fow now, this stays as Internal API and might be + * changed. * * @author Clément Fournier * @since 6.0.0 + * @apiNote Internal API */ @InternalApi public enum PropertyTypeId { From 4f8d09460cfbf57c0e2f82663496d9ea6c121177 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 27 Jan 2024 18:56:19 +0100 Subject: [PATCH 06/37] [core] FileCollector - factories stay internal, other methods are now public api Refs #4348 --- .../pmd/lang/document/FileCollector.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/document/FileCollector.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/document/FileCollector.java index 3d0ab591aa..7b7db06c86 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/document/FileCollector.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/document/FileCollector.java @@ -73,12 +73,8 @@ public final class FileCollector implements AutoCloseable { LOG.debug("Created new FileCollector with {}", discoverer); } - public void setRecursive(boolean collectFilesRecursively) { - this.recursive = collectFilesRecursively; - } - /** - * Internal API: please use {@link PmdAnalysis#files()} instead of + * @apiNote Internal API - please use {@link PmdAnalysis#files()} instead of * creating a collector yourself. */ @InternalApi @@ -87,7 +83,10 @@ public final class FileCollector implements AutoCloseable { } /** - * Returns a new collector using the configuration except for the logger. + * Returns a new collector using the same configuration except for the logger. + * + * @apiNote Internal API - please use {@link PmdAnalysis#files()} instead of + * creating a collector yourself. */ @InternalApi public FileCollector newCollector(PmdReporter logger) { @@ -101,9 +100,8 @@ public final class FileCollector implements AutoCloseable { /** * Returns an unmodifiable list of all files that have been collected. * - *

Internal: This might be unstable until PMD 7, but it's internal. + * @throws IllegalStateException if the collector was already closed */ - @InternalApi public List getCollectedFiles() { if (closed) { throw new IllegalStateException("Collector was closed!"); @@ -117,7 +115,6 @@ public final class FileCollector implements AutoCloseable { /** * Returns the reporter for the file collection phase. */ - @InternalApi public PmdReporter getReporter() { return reporter; } @@ -397,6 +394,10 @@ public final class FileCollector implements AutoCloseable { // configuration + public void setRecursive(boolean collectFilesRecursively) { + this.recursive = collectFilesRecursively; + } + /** * Sets the charset to use for subsequent calls to {@link #addFile(Path)} * and other overloads using a {@link Path}. From 932c2e38f8fadfa1b41d80608dde37c67e1c7f4c Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 27 Jan 2024 19:10:20 +0100 Subject: [PATCH 07/37] [core] XPath Attribute#replacementIfDeprecated stays Internal API Refs #4348 --- .../java/net/sourceforge/pmd/lang/rule/xpath/Attribute.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/Attribute.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/Attribute.java index 64857cca51..9ddcb218aa 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/Attribute.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/Attribute.java @@ -99,6 +99,8 @@ public final class Attribute { /** * Returns null for "not deprecated", empty string for "deprecated without replacement", * otherwise name of replacement attribute. + * + * @apiNote Internal API */ @InternalApi public String replacementIfDeprecated() { From a0a289f4ef4b83739f8db241cd560d12c6e9095a Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 27 Jan 2024 19:17:03 +0100 Subject: [PATCH 08/37] [core] RuleTargetSelector#isRuleChain removed Refs #4348 --- docs/pages/release_notes.md | 1 + .../net/sourceforge/pmd/lang/rule/RuleTargetSelector.java | 6 ------ .../net/sourceforge/pmd/lang/java/rule/XPathRuleTest.java | 5 +++-- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 7985ac14f4..fb8bc51d04 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -171,6 +171,7 @@ package or made package private and are not accessible anymore. * {%jdoc core::cache.internal.NoopAnalysisCache %} * {%jdoc core::util.internal.ResourceLoader %} * {%jdoc core::cpd.Tokens#Tokens() %} (the constructor is now package private) + * {%jdoc core::lang.rule.RuleTargetSelector %} - method `isRuleChain()` has been removed. It was internal API before. **Removed classes and methods (previously deprecated)** diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleTargetSelector.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleTargetSelector.java index 7e01c2071e..8c4151942b 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleTargetSelector.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleTargetSelector.java @@ -13,7 +13,6 @@ import java.util.LinkedHashSet; import java.util.Set; import net.sourceforge.pmd.Rule; -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.ast.RootNode; import net.sourceforge.pmd.lang.rule.internal.TargetSelectorInternal; @@ -86,11 +85,6 @@ public abstract class RuleTargetSelector extends TargetSelectorInternal { return ClassRulechainVisits.ROOT_ONLY; } - @InternalApi - public boolean isRuleChain() { - return this != ClassRulechainVisits.ROOT_ONLY; // NOPMD #3205 - } - private static final class StringRulechainVisits extends RuleTargetSelector { private final Set visits; 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 e28317b6d9..fe24f59474 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 @@ -5,7 +5,7 @@ package net.sourceforge.pmd.lang.java.rule; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNotSame; import java.util.HashMap; import java.util.List; @@ -20,6 +20,7 @@ import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.java.JavaParsingHelper; import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit; import net.sourceforge.pmd.lang.java.ast.JavaNode; +import net.sourceforge.pmd.lang.rule.RuleTargetSelector; import net.sourceforge.pmd.lang.rule.XPathRule; import net.sourceforge.pmd.lang.rule.xpath.XPathVersion; import net.sourceforge.pmd.lang.rule.xpath.impl.XPathHandler; @@ -110,7 +111,7 @@ class XPathRuleTest { XPathRule rule = makeXPath(xpath); try (LanguageProcessor proc = JavaParsingHelper.DEFAULT.newProcessor()) { rule.initialize(proc); - assertTrue(rule.getTargetSelector().isRuleChain(), "Not recognized as a rulechain query: " + xpath); + assertNotSame(rule.getTargetSelector(), RuleTargetSelector.forRootOnly(), "Not recognized as a rulechain query: " + xpath); } catch (Exception e) { throw new RuntimeException(e); } From bc31401258f80e4a88d5c4bd15f8d8bcde86ec56 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sun, 28 Jan 2024 18:15:39 +0100 Subject: [PATCH 09/37] [core] LanguageProcessor.AnalysisTask#withFiles now internal Refs #4348 --- docs/pages/release_notes.md | 7 +++++++ .../java/net/sourceforge/pmd/lang/LanguageProcessor.java | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index fb8bc51d04..da2b7ca6ee 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -173,6 +173,13 @@ package or made package private and are not accessible anymore. * {%jdoc core::cpd.Tokens#Tokens() %} (the constructor is now package private) * {%jdoc core::lang.rule.RuleTargetSelector %} - method `isRuleChain()` has been removed. It was internal API before. +**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/lang/LanguageProcessor.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageProcessor.java index 51f227eecf..dfad31fb67 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 @@ -72,6 +72,8 @@ public interface LanguageProcessor extends AutoCloseable { /** * Create a new task. This constructor is internal and will be * called by PMD. + * + * @apiNote Internal API */ @InternalApi public AnalysisTask(RuleSets rulesets, @@ -120,7 +122,10 @@ public interface LanguageProcessor extends AutoCloseable { /** * Produce a new analysis task with just different files. + * + * @apiNote Internal API */ + @InternalApi public AnalysisTask withFiles(List newFiles) { return new AnalysisTask( rulesets, From 8b8b11d5f31e4ef8f8bce7c7bf468548d7e1b723 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sun, 28 Jan 2024 18:30:11 +0100 Subject: [PATCH 10/37] [core] AbstractAccumulatingRenderer#renderFileReport(Report) is final Refs #4348 --- docs/pages/release_notes.md | 6 ++++-- .../renderers/AbstractAccumulatingRenderer.java | 15 +++++++-------- .../renderers/AbstractIncrementingRenderer.java | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index da2b7ca6ee..865daa1592 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -170,15 +170,17 @@ package or made package private and are not accessible anymore. * {%jdoc core::cache.internal.FileAnalysisCache %} * {%jdoc core::cache.internal.NoopAnalysisCache %} * {%jdoc core::util.internal.ResourceLoader %} - * {%jdoc core::cpd.Tokens#Tokens() %} (the constructor is now package private) + * {%jdoc !!core::cpd.Tokens#Tokens() %} (the constructor is now package private) * {%jdoc core::lang.rule.RuleTargetSelector %} - method `isRuleChain()` has been removed. It was internal API before. + * {%jdoc !!core::renderers.AbstractAccumulatingRenderer#renderFileReport(Report) %} - this method is now final + and can't be overridden anymore. **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) %} +* {%jdoc !!core::lang.LanguageProcessor.AnalysisTask#withFiles(java.util.List) %} **Removed classes and methods (previously deprecated)** diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/renderers/AbstractAccumulatingRenderer.java b/pmd-core/src/main/java/net/sourceforge/pmd/renderers/AbstractAccumulatingRenderer.java index 0bf666d9b9..7207f6dea4 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/renderers/AbstractAccumulatingRenderer.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/renderers/AbstractAccumulatingRenderer.java @@ -10,7 +10,6 @@ import java.util.Objects; import net.sourceforge.pmd.Report; import net.sourceforge.pmd.Report.ConfigurationError; import net.sourceforge.pmd.Report.GlobalReportBuilderListener; -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.benchmark.TimeTracker; import net.sourceforge.pmd.benchmark.TimedOperation; import net.sourceforge.pmd.benchmark.TimedOperationCategory; @@ -25,8 +24,8 @@ import net.sourceforge.pmd.reporting.GlobalAnalysisListener; * quite large in some scenarios. Consider using * {@link AbstractIncrementingRenderer} which can use significantly less memory. * - *

Subclasses should only implement the {@link #end()} method to output the - * complete {@link #report}. + *

Subclasses should only implement the {@link #outputReport(Report)} method to output the + * complete {@link Report} in the end. * * @see AbstractIncrementingRenderer */ @@ -54,13 +53,13 @@ public abstract class AbstractAccumulatingRenderer extends AbstractRenderer { /** * {@inheritDoc} - * - * @deprecated This is internal API. Do not override when extending {@link AbstractAccumulatingRenderer}. - * In PMD7 this method will be made final. + * + * @implNote The implementation in this class does nothing. All the reported violations and + * errors are accumulated and can be rendered once with {@link #outputReport(Report)} in the + * end. Subclasses of {@link AbstractAccumulatingRenderer} cannot override this method + * anymore. */ @Override - @InternalApi - @Deprecated public final void renderFileReport(Report report) throws IOException { // do nothing, final because it will never be called by the listener Objects.requireNonNull(report); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/renderers/AbstractIncrementingRenderer.java b/pmd-core/src/main/java/net/sourceforge/pmd/renderers/AbstractIncrementingRenderer.java index 05cdc963bb..f648dac690 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/renderers/AbstractIncrementingRenderer.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/renderers/AbstractIncrementingRenderer.java @@ -21,7 +21,7 @@ import net.sourceforge.pmd.lang.document.TextFile; * delivery of source file reports are reflected in the output of the * {@link Renderer}, so report output can be different between runs. * - * Only processing errors and suppressed violations are accumulated across all + *

Only processing errors and suppressed violations are accumulated across all * files. These are intended to be processed in the {@link #end()} method. */ public abstract class AbstractIncrementingRenderer extends AbstractRenderer { From 589d14418e6e1c76a27055bd269a34f9da5940ae Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sun, 28 Jan 2024 18:44:22 +0100 Subject: [PATCH 11/37] [core] Report - ctor and addRuleViolation, addConfigError, addError are private Refs #4348 --- docs/pages/release_notes.md | 4 ++- .../main/java/net/sourceforge/pmd/Report.java | 31 ++++--------------- 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 865daa1592..f546c3c962 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -157,7 +157,7 @@ in the Migration Guide. **Internalized classes and interfaces and methods** The following classes/methods have been marked as @InternalApi before and are now moved into a `internal` -package or made package private and are not accessible anymore. +package or made (package) private and are not accessible anymore. * pmd-core * {%jdoc core::cache.internal.AbstractAnalysisCache %} (now package private) @@ -174,6 +174,8 @@ package or made package private and are not accessible anymore. * {%jdoc core::lang.rule.RuleTargetSelector %} - method `isRuleChain()` has been removed. It was internal API before. * {%jdoc !!core::renderers.AbstractAccumulatingRenderer#renderFileReport(Report) %} - this method is now final and can't be overridden anymore. + * {%jdoc core::Report %} - the constructor as well as the methods `addRuleViolation`, `addConfigError`, `addError` + are now private and cannot be accessed anymore. **Newly internal classes, interfaces and methods** diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/Report.java b/pmd-core/src/main/java/net/sourceforge/pmd/Report.java index d579ec05d7..d88dd692f3 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/Report.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/Report.java @@ -15,9 +15,7 @@ import java.util.List; import java.util.function.Consumer; import java.util.function.Predicate; -import net.sourceforge.pmd.annotation.DeprecatedUntil700; import net.sourceforge.pmd.annotation.Experimental; -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.document.FileId; import net.sourceforge.pmd.lang.document.TextFile; import net.sourceforge.pmd.renderers.AbstractAccumulatingRenderer; @@ -51,10 +49,8 @@ public final class Report { private final List errors = synchronizedList(new ArrayList<>()); private final List configErrors = synchronizedList(new ArrayList<>()); - @DeprecatedUntil700 - @InternalApi - public Report() { // NOPMD - UnnecessaryConstructor - // TODO: should be package-private, you have to use a listener to build a report. + private Report() { + // constructor is private } /** @@ -181,13 +177,8 @@ public final class Report { * Adds a new rule violation to the report and notify the listeners. * * @param violation the violation to add - * - * @deprecated PMD's way of creating a report is internal and may be changed in pmd 7. */ - @DeprecatedUntil700 - @Deprecated - @InternalApi - public void addRuleViolation(RuleViolation violation) { + private void addRuleViolation(RuleViolation violation) { synchronized (violations) { // note that this binary search is inefficient as we usually // report violations file by file. @@ -207,27 +198,17 @@ public final class Report { * Adds a new configuration error to the report. * * @param error the error to add - * - * @deprecated PMD's way of creating a report is internal and may be changed in pmd 7. */ - @DeprecatedUntil700 - @Deprecated - @InternalApi - public void addConfigError(ConfigurationError error) { + private void addConfigError(ConfigurationError error) { configErrors.add(error); } /** * Adds a new processing error to the report. * - * @param error - * the error to add - * @deprecated PMD's way of creating a report is internal and may be changed in pmd 7. + * @param error the error to add */ - @DeprecatedUntil700 - @Deprecated - @InternalApi - public void addError(ProcessingError error) { + private void addError(ProcessingError error) { errors.add(error); } From 627fef132dfc3cc84ab73c970bd08c0670c058eb Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sun, 28 Jan 2024 19:17:24 +0100 Subject: [PATCH 12/37] [core] RuleContext - remove getRule(), create() Introduce InternalApiBridge to collect all internal API endpoints. Refs #4348 --- docs/pages/release_notes.md | 3 ++ .../sourceforge/pmd/InternalApiBridge.java | 33 +++++++++++++++++++ .../java/net/sourceforge/pmd/RuleContext.java | 24 ++++---------- .../pmd/lang/rule/AbstractRule.java | 3 +- .../lang/rule/internal/RuleApplicator.java | 3 +- .../net/sourceforge/pmd/AbstractRuleTest.java | 2 +- .../net/sourceforge/pmd/ReportTestUtil.java | 2 +- .../renderers/SummaryHTMLRendererTest.java | 3 +- 8 files changed, 51 insertions(+), 22 deletions(-) create mode 100644 pmd-core/src/main/java/net/sourceforge/pmd/InternalApiBridge.java diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index f546c3c962..7276ef1219 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -176,6 +176,9 @@ package or made (package) private and are not accessible anymore. and can't be overridden anymore. * {%jdoc core::Report %} - the constructor as well as the methods `addRuleViolation`, `addConfigError`, `addError` are now private and cannot be accessed anymore. + * {%jdoc core::RuleContext %} + * Method `getRule()` is now package private + * Method `create(FileAnalysisListener listener, Rule rule)` is removed **Newly internal classes, interfaces and methods** diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/InternalApiBridge.java b/pmd-core/src/main/java/net/sourceforge/pmd/InternalApiBridge.java new file mode 100644 index 0000000000..118664ccc4 --- /dev/null +++ b/pmd-core/src/main/java/net/sourceforge/pmd/InternalApiBridge.java @@ -0,0 +1,33 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd; + +import net.sourceforge.pmd.annotation.InternalApi; +import net.sourceforge.pmd.reporting.FileAnalysisListener; + +/** + * Makes package private methods available for other packages. This is only internal. + * + * @apiNote Internal API + */ +@InternalApi +public final class InternalApiBridge { + private InternalApiBridge() { + // utility class + } + + public static Rule getRule(RuleContext ruleContext) { + return ruleContext.getRule(); + } + + /** + * Create a new RuleContext. + * + * The listener must be closed by its creator. + */ + public static RuleContext createRuleContext(FileAnalysisListener listener, Rule rule) { + return new RuleContext(listener, rule); + } +} diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleContext.java b/pmd-core/src/main/java/net/sourceforge/pmd/RuleContext.java index 905d38474f..cdc81d0b30 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleContext.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/RuleContext.java @@ -51,7 +51,10 @@ public final class RuleContext { private final FileAnalysisListener listener; private final Rule rule; - private RuleContext(FileAnalysisListener listener, Rule rule) { + /** + * @apiNote Internal API + */ + RuleContext(FileAnalysisListener listener, Rule rule) { Objects.requireNonNull(listener, "Listener was null"); Objects.requireNonNull(rule, "Rule was null"); this.listener = listener; @@ -59,11 +62,10 @@ public final class RuleContext { } /** - * @deprecated Used in {@link AbstractRule#asCtx(Object)}, when that is gone, will be removed. + * @apiNote Internal API. Used in {@link AbstractRule} in {@code asCtx(Object)}, + * through {@link InternalApiBridge}. */ - @Deprecated - @InternalApi - public Rule getRule() { + Rule getRule() { return rule; } @@ -214,16 +216,4 @@ public final class RuleContext { final PropertyDescriptor propertyDescriptor = rule.getPropertyDescriptor(name); return propertyDescriptor == null ? null : String.valueOf(rule.getProperty(propertyDescriptor)); } - - - /** - * Create a new RuleContext. - * - * The listener must be closed by its creator. - */ - @InternalApi - public static RuleContext create(FileAnalysisListener listener, Rule rule) { - return new RuleContext(listener, rule); - } - } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/AbstractRule.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/AbstractRule.java index fd0573ed7b..697a3fbcb9 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/AbstractRule.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/AbstractRule.java @@ -15,6 +15,7 @@ import java.util.Set; import org.checkerframework.checker.nullness.qual.NonNull; +import net.sourceforge.pmd.InternalApiBridge; import net.sourceforge.pmd.Rule; import net.sourceforge.pmd.RuleContext; import net.sourceforge.pmd.RulePriority; @@ -293,7 +294,7 @@ public abstract class AbstractRule extends AbstractPropertySource implements Rul */ protected final RuleContext asCtx(Object ctx) { if (ctx instanceof RuleContext) { - assert isThisRule(((RuleContext) ctx).getRule()) + assert isThisRule(InternalApiBridge.getRule((RuleContext) ctx)) : "not an appropriate rule context!"; return (RuleContext) ctx; } else { diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/internal/RuleApplicator.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/internal/RuleApplicator.java index 6da5e290d8..65e27670a9 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/internal/RuleApplicator.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/internal/RuleApplicator.java @@ -11,6 +11,7 @@ import org.apache.commons.lang3.exception.ExceptionContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import net.sourceforge.pmd.InternalApiBridge; import net.sourceforge.pmd.Report.ProcessingError; import net.sourceforge.pmd.Rule; import net.sourceforge.pmd.RuleContext; @@ -61,7 +62,7 @@ public class RuleApplicator { continue; // No point in even trying to apply the rule } - RuleContext ctx = RuleContext.create(listener, rule); + RuleContext ctx = InternalApiBridge.createRuleContext(listener, rule); rule.start(ctx); try (TimedOperation rcto = TimeTracker.startOperation(TimedOperationCategory.RULE, rule.getName())) { diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/AbstractRuleTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/AbstractRuleTest.java index bc82f3452c..12a80086f6 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/AbstractRuleTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/AbstractRuleTest.java @@ -124,7 +124,7 @@ class AbstractRuleTest { .withNoPmdComments(Collections.singletonMap(1, "ohio")); FileAnalysisListener listener = mock(FileAnalysisListener.class); - RuleContext ctx = RuleContext.create(listener, new MyRule()); + RuleContext ctx = InternalApiBridge.createRuleContext(listener, new MyRule()); ctx.addViolationWithMessage(n, "message"); verify(listener, never()).onRuleViolation(any()); diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/ReportTestUtil.java b/pmd-core/src/test/java/net/sourceforge/pmd/ReportTestUtil.java index 752d4d580c..eae46913e2 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/ReportTestUtil.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/ReportTestUtil.java @@ -17,7 +17,7 @@ public final class ReportTestUtil { } public static Report getReport(Rule rule, BiConsumer sideEffects) { - return Report.buildReport(listener -> sideEffects.accept(rule, RuleContext.create(listener, rule))); + return Report.buildReport(listener -> sideEffects.accept(rule, InternalApiBridge.createRuleContext(listener, rule))); } public static Report getReportForRuleApply(Rule rule, Node node) { diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/renderers/SummaryHTMLRendererTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/renderers/SummaryHTMLRendererTest.java index 89a60d00ff..1933718c23 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/renderers/SummaryHTMLRendererTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/renderers/SummaryHTMLRendererTest.java @@ -13,6 +13,7 @@ import java.util.function.Consumer; import org.junit.jupiter.api.Test; import net.sourceforge.pmd.FooRule; +import net.sourceforge.pmd.InternalApiBridge; import net.sourceforge.pmd.Report.ConfigurationError; import net.sourceforge.pmd.Report.ProcessingError; import net.sourceforge.pmd.RuleContext; @@ -148,7 +149,7 @@ class SummaryHTMLRendererTest extends AbstractRendererTest { DummyRootNode root = helper.parse("dummy code", getSourceCodeFilename()) .withNoPmdComments(Collections.singletonMap(1, "test")); - RuleContext ruleContext = RuleContext.create(listener, new FooRule()); + RuleContext ruleContext = InternalApiBridge.createRuleContext(listener, new FooRule()); ruleContext.addViolationWithPosition(root, 1, 1, "suppress test"); }; } From e3cf1c65672bcdccd5901c6e894fef12278d387e Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sun, 28 Jan 2024 19:18:38 +0100 Subject: [PATCH 13/37] [core] RuleContext - addViolationNoSuppress() This was not used and not tested. To be readded with #2736 and #2896 Refs #4348 --- .../main/java/net/sourceforge/pmd/RuleContext.java | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleContext.java b/pmd-core/src/main/java/net/sourceforge/pmd/RuleContext.java index cdc81d0b30..b87bf86d9e 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleContext.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/RuleContext.java @@ -16,7 +16,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import net.sourceforge.pmd.Report.SuppressedViolation; -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.LanguageVersionHandler; import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.document.FileLocation; @@ -167,17 +166,6 @@ public final class RuleContext { return suppressed; } - /** - * Force the recording of a violation, ignoring the violation - * suppression mechanism ({@link ViolationSuppressor}). - * - * @param rv A violation - */ - @InternalApi - public void addViolationNoSuppress(RuleViolation rv) { - listener.onRuleViolation(rv); - } - private String makeMessage(@NonNull String message, Object[] args, Map extraVars) { // Escape PMD specific variable message format, specifically the { // in the ${, so MessageFormat doesn't bitch. From 2f47edfd3b11aed0c07a6b981a8b6f98bd6b182a Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Tue, 30 Jan 2024 19:36:46 +0100 Subject: [PATCH 14/37] [ant] Cleanup InternalApi methods Refs #4348 --- docs/pages/release_notes.md | 9 +++++ .../net/sourceforge/pmd/ant/Formatter.java | 39 ++----------------- .../pmd/ant/InternalApiBridge.java | 28 +++++++++++++ .../java/net/sourceforge/pmd/ant/PMDTask.java | 14 ------- .../pmd/ant/internal/PMDTaskImpl.java | 18 ++++++++- 5 files changed, 56 insertions(+), 52 deletions(-) create mode 100644 pmd-ant/src/main/java/net/sourceforge/pmd/ant/InternalApiBridge.java diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 7276ef1219..d001cb929b 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -179,6 +179,15 @@ package or made (package) private and are not accessible anymore. * {%jdoc core::RuleContext %} * Method `getRule()` is now package private * Method `create(FileAnalysisListener listener, Rule rule)` is removed +* pmd-ant + * {%jdoc ant::ant.Formatter %} + * The method `getRenderer()` has been removed. + * The method `start(String)` is private now and not accessible anymore. + * The method `end(Report)` has been removed. + * The method `isNoOutputSupplied()` is now package private and 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. **Newly internal classes, interfaces and methods** diff --git a/pmd-ant/src/main/java/net/sourceforge/pmd/ant/Formatter.java b/pmd-ant/src/main/java/net/sourceforge/pmd/ant/Formatter.java index 199cc2b16b..aed668a2e1 100644 --- a/pmd-ant/src/main/java/net/sourceforge/pmd/ant/Formatter.java +++ b/pmd-ant/src/main/java/net/sourceforge/pmd/ant/Formatter.java @@ -26,8 +26,6 @@ import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.types.Parameter; -import net.sourceforge.pmd.Report; -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.internal.util.IOUtil; import net.sourceforge.pmd.lang.document.TextFile; import net.sourceforge.pmd.renderers.Renderer; @@ -37,7 +35,6 @@ import net.sourceforge.pmd.reporting.FileNameRenderer; import net.sourceforge.pmd.reporting.GlobalAnalysisListener; import net.sourceforge.pmd.reporting.ListenerInitializer; -@InternalApi public class Formatter { private File toFile; @@ -68,15 +65,7 @@ public class Formatter { this.parameters.add(parameter); } - @Deprecated - @InternalApi - public Renderer getRenderer() { - return renderer; - } - - @Deprecated - @InternalApi - public void start(String baseDir) { + private void start(String baseDir) { Properties properties = createProperties(); @@ -122,25 +111,7 @@ public class Formatter { } } - @Deprecated - @InternalApi - public void end(Report errorReport) { - try { - renderer.renderFileReport(errorReport); - renderer.end(); - if (toConsole) { - writer.flush(); - } else { - writer.close(); - } - } catch (IOException ioe) { - throw new BuildException(ioe.getMessage(), ioe); - } - } - - @Deprecated - @InternalApi - public boolean isNoOutputSupplied() { + boolean isNoOutputSupplied() { return toFile == null && !toConsole; } @@ -248,12 +219,8 @@ public class Formatter { return null; } - @Deprecated - @InternalApi - public GlobalAnalysisListener newListener(Project project) throws IOException { + GlobalAnalysisListener newListener(Project project) throws IOException { start(project.getBaseDir().toString()); - Renderer renderer = getRenderer(); - return new GlobalAnalysisListener() { final GlobalAnalysisListener listener = renderer.newListener(); diff --git a/pmd-ant/src/main/java/net/sourceforge/pmd/ant/InternalApiBridge.java b/pmd-ant/src/main/java/net/sourceforge/pmd/ant/InternalApiBridge.java new file mode 100644 index 0000000000..0aa1b05065 --- /dev/null +++ b/pmd-ant/src/main/java/net/sourceforge/pmd/ant/InternalApiBridge.java @@ -0,0 +1,28 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.ant; + +import java.io.IOException; + +import org.apache.tools.ant.Project; + +import net.sourceforge.pmd.annotation.InternalApi; +import net.sourceforge.pmd.reporting.GlobalAnalysisListener; + +/** + * Gives access to package private methods. + * + * @apiNote Internal API + */ +@InternalApi +public final class InternalApiBridge { + private InternalApiBridge() { + // utility class + } + + public static GlobalAnalysisListener newListener(Formatter formatter, Project project) throws IOException { + return formatter.newListener(project); + } +} diff --git a/pmd-ant/src/main/java/net/sourceforge/pmd/ant/PMDTask.java b/pmd-ant/src/main/java/net/sourceforge/pmd/ant/PMDTask.java index db10833ff7..4a562c3289 100644 --- a/pmd-ant/src/main/java/net/sourceforge/pmd/ant/PMDTask.java +++ b/pmd-ant/src/main/java/net/sourceforge/pmd/ant/PMDTask.java @@ -4,7 +4,6 @@ package net.sourceforge.pmd.ant; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; @@ -15,10 +14,8 @@ import org.apache.tools.ant.Task; import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.Reference; -import org.apache.tools.ant.types.Resource; import net.sourceforge.pmd.RulePriority; -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.ant.internal.PMDTaskImpl; /** @@ -299,15 +296,4 @@ public class PMDTask extends Task { public List getRelativizePathsWith() { return relativizePathsWith; } - - @InternalApi - public List getRelativizeRoots() { - List paths = new ArrayList<>(); - for (Path path : getRelativizePathsWith()) { - for (Resource resource : path) { - paths.add(Paths.get(resource.toString())); - } - } - return paths; - } } diff --git a/pmd-ant/src/main/java/net/sourceforge/pmd/ant/internal/PMDTaskImpl.java b/pmd-ant/src/main/java/net/sourceforge/pmd/ant/internal/PMDTaskImpl.java index 3bd399fc64..e800a34454 100644 --- a/pmd-ant/src/main/java/net/sourceforge/pmd/ant/internal/PMDTaskImpl.java +++ b/pmd-ant/src/main/java/net/sourceforge/pmd/ant/internal/PMDTaskImpl.java @@ -5,6 +5,7 @@ package net.sourceforge.pmd.ant.internal; import java.nio.charset.Charset; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -16,6 +17,7 @@ import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Project; import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.types.Resource; import org.checkerframework.checker.nullness.qual.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -26,6 +28,7 @@ import net.sourceforge.pmd.PmdAnalysis; import net.sourceforge.pmd.RulePriority; import net.sourceforge.pmd.RuleSetLoader; import net.sourceforge.pmd.ant.Formatter; +import net.sourceforge.pmd.ant.InternalApiBridge; import net.sourceforge.pmd.ant.PMDTask; import net.sourceforge.pmd.ant.SourceLanguage; import net.sourceforge.pmd.internal.Slf4jSimpleConfiguration; @@ -54,7 +57,7 @@ public class PMDTaskImpl { private Project project; public PMDTaskImpl(PMDTask task) { - configuration.addRelativizeRoots(task.getRelativizeRoots()); + configuration.addRelativizeRoots(getRelativizeRoots(task)); if (task.getSuppressMarker() != null) { configuration.setSuppressMarker(task.getSuppressMarker()); } @@ -97,6 +100,17 @@ public class PMDTaskImpl { project = task.getProject(); } + private static List getRelativizeRoots(PMDTask pmdTask) { + List paths = new ArrayList<>(); + for (Path path : pmdTask.getRelativizePathsWith()) { + for (Resource resource : path) { + paths.add(Paths.get(resource.toString())); + } + } + return paths; + } + + private void doTask() { setupClassLoader(); @@ -161,7 +175,7 @@ public class PMDTaskImpl { renderers.add(reportSizeListener); for (Formatter formatter : formatters) { project.log("Sending a report to " + formatter, Project.MSG_VERBOSE); - renderers.add(formatter.newListener(project)); + renderers.add(InternalApiBridge.newListener(formatter, project)); } return GlobalAnalysisListener.tee(renderers); } catch (Exception e) { From 7ec2bc48654af2b557fd1890c72b532b954ceb06 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Tue, 30 Jan 2024 20:17:59 +0100 Subject: [PATCH 15/37] [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"; From 35db84a0a841e78e0b6cf3da581233bf308a1e02 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 1 Feb 2024 09:33:17 +0100 Subject: [PATCH 16/37] [java] Cleanup InternalApi methods Refs #4348 --- docs/pages/release_notes.md | 5 ++ .../pmd/lang/java/ast/ASTCompilationUnit.java | 2 +- .../lang/java/ast/AbstractJavaTypeNode.java | 2 +- .../lang/java/ast/AstDisambiguationPass.java | 2 +- .../pmd/lang/java/ast/InternalApiBridge.java | 2 +- .../UnusedPrivateMethodRule.java | 2 +- .../codestyle/AtLeastOneConstructorRule.java | 2 +- .../codestyle/UnnecessaryConstructorRule.java | 2 +- .../AbstractIgnoredAnnotationRule.java | 8 +-- .../pmd/lang/java/symbols/JElementSymbol.java | 2 - .../lang/java/types/ArrayMethodSigImpl.java | 5 -- .../lang/java/types/ClassMethodSigImpl.java | 5 -- .../lang/java/types/InternalApiBridge.java | 21 ++++++ .../pmd/lang/java/types/JMethodSig.java | 11 --- .../pmd/lang/java/types/TypeOps.java | 6 +- .../lang/java/types/UnresolvedMethodSig.java | 5 -- .../pmd/lang/java/types/ast/ExprContext.java | 72 ++----------------- .../java/types/ast/InternalApiBridge.java | 37 ++++++++++ .../java/types/ast/internal/InvocCtx.java | 50 +++++++++++++ .../ast/{ => internal}/LazyTypeResolver.java | 3 +- .../ast/{ => internal}/PolyResolution.java | 33 +++++---- .../java/types/ast/internal/RegularCtx.java | 36 ++++++++++ .../types/internal/InternalMethodTypeItf.java | 4 ++ .../types/internal/infer/ExprCheckHelper.java | 5 +- .../java/types/internal/infer/ExprOps.java | 7 +- .../internal/infer/IncorporationAction.java | 4 +- .../lang/java/types/internal/infer/Infer.java | 15 ++-- .../internal/infer/PhaseOverloadSet.java | 8 ++- .../internal/infer/TypeInferenceLogger.java | 6 +- .../internal/infer/ast/MethodInvocMirror.java | 3 +- .../java/types/ast/ConditionalTypeTest.kt | 1 + 31 files changed, 220 insertions(+), 146 deletions(-) rename pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/{ => internal}/AbstractIgnoredAnnotationRule.java (91%) create mode 100644 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/InternalApiBridge.java create mode 100644 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/InternalApiBridge.java create mode 100644 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/internal/InvocCtx.java rename pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/{ => internal}/LazyTypeResolver.java (99%) rename pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/{ => internal}/PolyResolution.java (95%) create mode 100644 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/internal/RegularCtx.java diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 51325edabb..1835c23513 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -195,6 +195,11 @@ package or made (package) private and are 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) +* pmd-java + * {%jdoc java::rule.internal.AbstractIgnoredAnnotationRule %} + * {%jdoc java::types.ast.internal.LazyTypeResolver %} + * {%jdoc java::types.JMethodSig#internalApi() %} has been removed. + * {%jdoc java::types.TypeOps#isSameTypeInInference(java::types.JTypeMirror,java::types.JTypeMirror) %} (now package private) **Newly internal classes, interfaces and methods** diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTCompilationUnit.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTCompilationUnit.java index c13a716375..326076001d 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTCompilationUnit.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTCompilationUnit.java @@ -16,7 +16,7 @@ import net.sourceforge.pmd.lang.ast.RootNode; import net.sourceforge.pmd.lang.ast.impl.GenericNode; import net.sourceforge.pmd.lang.java.symbols.table.JSymbolTable; import net.sourceforge.pmd.lang.java.types.TypeSystem; -import net.sourceforge.pmd.lang.java.types.ast.LazyTypeResolver; +import net.sourceforge.pmd.lang.java.types.ast.internal.LazyTypeResolver; import net.sourceforge.pmd.lang.rule.xpath.NoAttribute; diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AbstractJavaTypeNode.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AbstractJavaTypeNode.java index 36208aef3a..0065625008 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AbstractJavaTypeNode.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AbstractJavaTypeNode.java @@ -8,7 +8,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import net.sourceforge.pmd.lang.java.types.JTypeMirror; import net.sourceforge.pmd.lang.java.types.TypingContext; -import net.sourceforge.pmd.lang.java.types.ast.LazyTypeResolver; +import net.sourceforge.pmd.lang.java.types.ast.internal.LazyTypeResolver; import net.sourceforge.pmd.util.AssertionUtil; /** diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AstDisambiguationPass.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AstDisambiguationPass.java index fbb52bed8d..c586c9ddca 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AstDisambiguationPass.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AstDisambiguationPass.java @@ -25,7 +25,7 @@ import net.sourceforge.pmd.lang.java.types.JClassType; import net.sourceforge.pmd.lang.java.types.JTypeMirror; import net.sourceforge.pmd.lang.java.types.JVariableSig; import net.sourceforge.pmd.lang.java.types.JVariableSig.FieldSig; -import net.sourceforge.pmd.lang.java.types.ast.LazyTypeResolver; +import net.sourceforge.pmd.lang.java.types.ast.internal.LazyTypeResolver; /** * This implements name disambiguation following JLS§6.5.2. diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/InternalApiBridge.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/InternalApiBridge.java index 9d26249e34..f1558ae801 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/InternalApiBridge.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/InternalApiBridge.java @@ -29,7 +29,7 @@ import net.sourceforge.pmd.lang.java.types.OverloadSelectionResult; import net.sourceforge.pmd.lang.java.types.Substitution; import net.sourceforge.pmd.lang.java.types.TypeSystem; import net.sourceforge.pmd.lang.java.types.ast.ExprContext; -import net.sourceforge.pmd.lang.java.types.ast.LazyTypeResolver; +import net.sourceforge.pmd.lang.java.types.ast.internal.LazyTypeResolver; import net.sourceforge.pmd.lang.java.types.internal.infer.Infer; import net.sourceforge.pmd.lang.java.types.internal.infer.TypeInferenceLogger; import net.sourceforge.pmd.util.AssertionUtil; diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UnusedPrivateMethodRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UnusedPrivateMethodRule.java index 915575c192..53a8c42434 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UnusedPrivateMethodRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UnusedPrivateMethodRule.java @@ -25,7 +25,7 @@ import net.sourceforge.pmd.lang.java.ast.JavaNode; import net.sourceforge.pmd.lang.java.ast.MethodUsage; import net.sourceforge.pmd.lang.java.ast.ModifierOwner.Visibility; import net.sourceforge.pmd.lang.java.ast.internal.PrettyPrintingUtil; -import net.sourceforge.pmd.lang.java.rule.AbstractIgnoredAnnotationRule; +import net.sourceforge.pmd.lang.java.rule.internal.AbstractIgnoredAnnotationRule; import net.sourceforge.pmd.lang.java.symbols.JExecutableSymbol; import net.sourceforge.pmd.lang.java.types.TypeTestUtil; import net.sourceforge.pmd.util.CollectionUtil; diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/AtLeastOneConstructorRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/AtLeastOneConstructorRule.java index 02a7312833..2f0aea0edb 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/AtLeastOneConstructorRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/AtLeastOneConstructorRule.java @@ -15,8 +15,8 @@ import net.sourceforge.pmd.lang.java.ast.ASTConstructorDeclaration; import net.sourceforge.pmd.lang.java.ast.ASTTypeDeclaration; import net.sourceforge.pmd.lang.java.ast.JModifier; import net.sourceforge.pmd.lang.java.ast.ModifierOwner; -import net.sourceforge.pmd.lang.java.rule.AbstractIgnoredAnnotationRule; import net.sourceforge.pmd.lang.java.rule.design.UseUtilityClassRule; +import net.sourceforge.pmd.lang.java.rule.internal.AbstractIgnoredAnnotationRule; import net.sourceforge.pmd.lang.rule.RuleTargetSelector; /** diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/UnnecessaryConstructorRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/UnnecessaryConstructorRule.java index 2e78d3c0d5..ee20fbd19c 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/UnnecessaryConstructorRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/UnnecessaryConstructorRule.java @@ -18,7 +18,7 @@ import net.sourceforge.pmd.lang.java.ast.ASTExplicitConstructorInvocation; import net.sourceforge.pmd.lang.java.ast.ASTStatement; import net.sourceforge.pmd.lang.java.ast.ASTTypeDeclaration; import net.sourceforge.pmd.lang.java.ast.ModifierOwner.Visibility; -import net.sourceforge.pmd.lang.java.rule.AbstractIgnoredAnnotationRule; +import net.sourceforge.pmd.lang.java.rule.internal.AbstractIgnoredAnnotationRule; import net.sourceforge.pmd.lang.rule.RuleTargetSelector; /** diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/AbstractIgnoredAnnotationRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/internal/AbstractIgnoredAnnotationRule.java similarity index 91% rename from pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/AbstractIgnoredAnnotationRule.java rename to pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/internal/AbstractIgnoredAnnotationRule.java index 1768da02ab..a753ca45d8 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/AbstractIgnoredAnnotationRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/internal/AbstractIgnoredAnnotationRule.java @@ -2,7 +2,7 @@ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ -package net.sourceforge.pmd.lang.java.rule; +package net.sourceforge.pmd.lang.java.rule.internal; import static net.sourceforge.pmd.properties.PropertyFactory.stringListProperty; @@ -10,15 +10,13 @@ import java.util.Collection; import java.util.Collections; import java.util.List; -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.java.ast.Annotatable; +import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule; import net.sourceforge.pmd.properties.PropertyDescriptor; /** - * @deprecated Internal API + * @apiNote Internal API */ -@Deprecated -@InternalApi public abstract class AbstractIgnoredAnnotationRule extends AbstractJavaRule { private final PropertyDescriptor> ignoredAnnotationsDescriptor diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symbols/JElementSymbol.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symbols/JElementSymbol.java index ccc6dc4cb9..b57cd82c83 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symbols/JElementSymbol.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symbols/JElementSymbol.java @@ -9,7 +9,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import net.sourceforge.pmd.annotation.Experimental; -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration; import net.sourceforge.pmd.lang.java.ast.JavaNode; import net.sourceforge.pmd.lang.java.types.JTypeMirror; @@ -27,7 +26,6 @@ import net.sourceforge.pmd.lang.java.types.TypeSystem; * @since 7.0.0 */ @Experimental -@InternalApi public interface JElementSymbol { /** diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ArrayMethodSigImpl.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ArrayMethodSigImpl.java index 872225dddf..b4cb635213 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ArrayMethodSigImpl.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ArrayMethodSigImpl.java @@ -82,11 +82,6 @@ class ArrayMethodSigImpl implements JMethodSig, InternalMethodTypeItf { return emptyList(); } - @Override - public InternalMethodTypeItf internalApi() { - return this; - } - @Override public JMethodSig withReturnType(JTypeMirror returnType) { if (!returnType.equals(owner)) { diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ClassMethodSigImpl.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ClassMethodSigImpl.java index d4ec340adb..33c6b9d2c7 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ClassMethodSigImpl.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ClassMethodSigImpl.java @@ -141,11 +141,6 @@ class ClassMethodSigImpl implements JMethodSig, InternalMethodTypeItf { return thrown; } - @Override - public InternalMethodTypeItf internalApi() { - return this; - } - @Override public JMethodSig withReturnType(JTypeMirror returnType) { // share formals & thrown to avoid recomputing diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/InternalApiBridge.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/InternalApiBridge.java new file mode 100644 index 0000000000..e7bd326423 --- /dev/null +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/InternalApiBridge.java @@ -0,0 +1,21 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.java.types; + +import net.sourceforge.pmd.annotation.InternalApi; + +/** + * @apiNote Internal API + */ +@InternalApi +public final class InternalApiBridge { + private InternalApiBridge() { + // internal api + } + + public static boolean isSameTypeInInference(JTypeMirror t, JTypeMirror s) { + return TypeOps.isSameTypeInInference(t, s); + } +} diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/JMethodSig.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/JMethodSig.java index 9476189d8b..d21012f9f9 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/JMethodSig.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/JMethodSig.java @@ -10,11 +10,9 @@ import java.util.function.Function; import org.checkerframework.checker.nullness.qual.NonNull; -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.java.symbols.JConstructorSymbol; import net.sourceforge.pmd.lang.java.symbols.JExecutableSymbol; import net.sourceforge.pmd.lang.java.symbols.JMethodSymbol; -import net.sourceforge.pmd.lang.java.types.internal.InternalMethodTypeItf; /** * Represents the signature of methods and constructors. An instance of @@ -172,13 +170,4 @@ public interface JMethodSig extends JTypeVisitable { default T acceptVisitor(JTypeVisitor visitor, P p) { return visitor.visitMethodType(this, p); } - - - /** - * Internal API, should not be used outside of the type inference - * implementation. - */ - @InternalApi - InternalMethodTypeItf internalApi(); - } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/TypeOps.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/TypeOps.java index 5339bcb280..54725ad9f8 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/TypeOps.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/TypeOps.java @@ -28,7 +28,6 @@ import java.util.stream.Collectors; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.java.symbols.JClassSymbol; import net.sourceforge.pmd.lang.java.symbols.JConstructorSymbol; import net.sourceforge.pmd.lang.java.symbols.JExecutableSymbol; @@ -94,9 +93,10 @@ public final class TypeOps { /** * Return true if t and s are the same type. This may perform side effects * on inference variables. Annotations are ignored. + * + * @apiNote Internal API */ - @InternalApi - public static boolean isSameTypeInInference(JTypeMirror t, JTypeMirror s) { + static boolean isSameTypeInInference(JTypeMirror t, JTypeMirror s) { return isSameType(t, s, true, false); } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/UnresolvedMethodSig.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/UnresolvedMethodSig.java index 1ff6368eef..bc2994f977 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/UnresolvedMethodSig.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/UnresolvedMethodSig.java @@ -108,11 +108,6 @@ final class UnresolvedMethodSig implements JMethodSig, InternalMethodTypeItf { return this; } - @Override - public InternalMethodTypeItf internalApi() { - return this; - } - @Override public String toString() { return getName(); diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/ExprContext.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/ExprContext.java index aa80538da1..763c2eecae 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/ExprContext.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/ExprContext.java @@ -15,8 +15,9 @@ import org.checkerframework.checker.nullness.qual.Nullable; import net.sourceforge.pmd.annotation.Experimental; import net.sourceforge.pmd.lang.java.ast.InvocationNode; import net.sourceforge.pmd.lang.java.types.JTypeMirror; -import net.sourceforge.pmd.lang.java.types.OverloadSelectionResult; import net.sourceforge.pmd.lang.java.types.TypeConversion; +import net.sourceforge.pmd.lang.java.types.ast.internal.InvocCtx; +import net.sourceforge.pmd.lang.java.types.ast.internal.RegularCtx; import net.sourceforge.pmd.util.AssertionUtil; /** @@ -30,9 +31,9 @@ public abstract class ExprContext { // note: most members of this class are quite low-level and should // stay package-private for exclusive use by PolyResolution. - final ExprContextKind kind; + protected final ExprContextKind kind; - private ExprContext(ExprContextKind kind) { + protected ExprContext(ExprContextKind kind) { this.kind = kind; } @@ -86,7 +87,7 @@ public abstract class ExprContext { } public @Nullable InvocationNode getInvocNodeIfInvocContext() { - return this instanceof InvocCtx ? ((InvocCtx) this).node : null; + return this instanceof InvocCtx ? ((InvocCtx) this).getNode() : null; } public @NonNull ExprContext getToplevelCtx() { @@ -107,15 +108,6 @@ public abstract class ExprContext { return getTargetType(); } - static ExprContext newOtherContext(@NonNull JTypeMirror targetType, ExprContextKind kind) { - AssertionUtil.requireParamNotNull("target type", targetType); - return new RegularCtx(targetType, kind); - } - - static ExprContext newInvocContext(InvocationNode invocNode, int argumentIndex) { - return new InvocCtx(argumentIndex, invocNode); - } - /** * Returns an {@link ExprContext} instance which represents a * missing context. Use {@link #isMissing()} instead of testing @@ -129,38 +121,6 @@ public abstract class ExprContext { return getKind() == kind; } - private static final class InvocCtx extends ExprContext { - - final int arg; - final InvocationNode node; - - InvocCtx(int arg, InvocationNode node) { - super(INVOCATION); - this.arg = arg; - this.node = node; - } - - @Override - public @Nullable JTypeMirror getTargetType() { - // this triggers type resolution of the enclosing expr. - OverloadSelectionResult overload = node.getOverloadSelectionInfo(); - if (overload.isFailed()) { - return null; - } - return overload.ithFormalParam(arg); - } - - @Override - public boolean isMissing() { - return false; - } - - @Override - public String toString() { - return "InvocCtx{arg=" + arg + ", node=" + node + '}'; - } - } - /** * Kind of context. */ @@ -231,26 +191,4 @@ public abstract class ExprContext { BOOLEAN, } - static final class RegularCtx extends ExprContext { - - private static final RegularCtx NO_CTX = new RegularCtx(null, MISSING); - - final @Nullable JTypeMirror targetType; - - RegularCtx(@Nullable JTypeMirror targetType, ExprContextKind kind) { - super(kind); - assert kind != INVOCATION; - this.targetType = targetType; - } - - @Override - public @Nullable JTypeMirror getTargetType() { - return targetType; - } - - @Override - public String toString() { - return "RegularCtx{kind=" + kind + ", targetType=" + targetType + '}'; - } - } } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/InternalApiBridge.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/InternalApiBridge.java new file mode 100644 index 0000000000..201fb2ee05 --- /dev/null +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/InternalApiBridge.java @@ -0,0 +1,37 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.java.types.ast; + +import org.checkerframework.checker.nullness.qual.NonNull; + +import net.sourceforge.pmd.annotation.InternalApi; +import net.sourceforge.pmd.lang.java.ast.InvocationNode; +import net.sourceforge.pmd.lang.java.types.JTypeMirror; +import net.sourceforge.pmd.lang.java.types.ast.internal.InvocCtx; +import net.sourceforge.pmd.lang.java.types.ast.internal.RegularCtx; +import net.sourceforge.pmd.util.AssertionUtil; + +/** + * @apiNote Internal API + */ +@InternalApi +public final class InternalApiBridge { + private InternalApiBridge() { + // utility + } + + public static boolean canGiveContextToPoly(ExprContext exprContext, boolean lambdaOrMethodRef) { + return exprContext.canGiveContextToPoly(lambdaOrMethodRef); + } + + public static ExprContext newOtherContext(@NonNull JTypeMirror targetType, ExprContext.ExprContextKind kind) { + AssertionUtil.requireParamNotNull("target type", targetType); + return new RegularCtx(targetType, kind); + } + + public static ExprContext newInvocContext(InvocationNode invocNode, int argumentIndex) { + return new InvocCtx(argumentIndex, invocNode); + } +} diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/internal/InvocCtx.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/internal/InvocCtx.java new file mode 100644 index 0000000000..b6dcc88eb4 --- /dev/null +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/internal/InvocCtx.java @@ -0,0 +1,50 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.java.types.ast.internal; + +import static net.sourceforge.pmd.lang.java.types.ast.ExprContext.ExprContextKind.INVOCATION; + +import org.checkerframework.checker.nullness.qual.Nullable; + +import net.sourceforge.pmd.lang.java.ast.InvocationNode; +import net.sourceforge.pmd.lang.java.types.JTypeMirror; +import net.sourceforge.pmd.lang.java.types.OverloadSelectionResult; +import net.sourceforge.pmd.lang.java.types.ast.ExprContext; + +public final class InvocCtx extends ExprContext { + + private final int arg; + private final InvocationNode node; + + public InvocCtx(int arg, InvocationNode node) { + super(INVOCATION); + this.arg = arg; + this.node = node; + } + + @Override + public @Nullable JTypeMirror getTargetType() { + // this triggers type resolution of the enclosing expr. + OverloadSelectionResult overload = node.getOverloadSelectionInfo(); + if (overload.isFailed()) { + return null; + } + return overload.ithFormalParam(arg); + } + + @Override + public boolean isMissing() { + return false; + } + + public InvocationNode getNode() { + return node; + } + + @Override + public String toString() { + return "InvocCtx{arg=" + arg + ", node=" + node + '}'; + } +} diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/LazyTypeResolver.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/internal/LazyTypeResolver.java similarity index 99% rename from pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/LazyTypeResolver.java rename to pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/internal/LazyTypeResolver.java index 95a6a98ab3..ede18f4b91 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/LazyTypeResolver.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/internal/LazyTypeResolver.java @@ -3,7 +3,7 @@ */ -package net.sourceforge.pmd.lang.java.types.ast; +package net.sourceforge.pmd.lang.java.types.ast.internal; import static net.sourceforge.pmd.lang.java.ast.BinaryOp.ADD; import static net.sourceforge.pmd.lang.java.types.TypeConversion.binaryNumericPromotion; @@ -84,6 +84,7 @@ import net.sourceforge.pmd.lang.java.types.TypeOps; import net.sourceforge.pmd.lang.java.types.TypeSystem; import net.sourceforge.pmd.lang.java.types.TypesFromReflection; import net.sourceforge.pmd.lang.java.types.TypingContext; +import net.sourceforge.pmd.lang.java.types.ast.ExprContext; import net.sourceforge.pmd.lang.java.types.ast.ExprContext.ExprContextKind; import net.sourceforge.pmd.lang.java.types.internal.infer.Infer; import net.sourceforge.pmd.lang.java.types.internal.infer.TypeInferenceLogger; diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/PolyResolution.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/internal/PolyResolution.java similarity index 95% rename from pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/PolyResolution.java rename to pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/internal/PolyResolution.java index 6cfa041f2d..9782ddc462 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/PolyResolution.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/internal/PolyResolution.java @@ -3,11 +3,14 @@ */ -package net.sourceforge.pmd.lang.java.types.ast; +package net.sourceforge.pmd.lang.java.types.ast.internal; import static java.util.Arrays.asList; import static net.sourceforge.pmd.lang.java.types.TypeConversion.isConvertibleUsingBoxing; +import static net.sourceforge.pmd.lang.java.types.ast.InternalApiBridge.canGiveContextToPoly; +import static net.sourceforge.pmd.lang.java.types.ast.InternalApiBridge.newInvocContext; +import static net.sourceforge.pmd.lang.java.types.ast.InternalApiBridge.newOtherContext; import static net.sourceforge.pmd.util.AssertionUtil.shouldNotReachHere; import static net.sourceforge.pmd.util.CollectionUtil.all; import static net.sourceforge.pmd.util.CollectionUtil.map; @@ -61,8 +64,8 @@ import net.sourceforge.pmd.lang.java.types.TypeOps; import net.sourceforge.pmd.lang.java.types.TypeSystem; import net.sourceforge.pmd.lang.java.types.TypeTestUtil; import net.sourceforge.pmd.lang.java.types.TypesFromReflection; +import net.sourceforge.pmd.lang.java.types.ast.ExprContext; import net.sourceforge.pmd.lang.java.types.ast.ExprContext.ExprContextKind; -import net.sourceforge.pmd.lang.java.types.ast.ExprContext.RegularCtx; import net.sourceforge.pmd.lang.java.types.internal.infer.ExprMirror.BranchingMirror; import net.sourceforge.pmd.lang.java.types.internal.infer.ExprMirror.FunctionalExprMirror; import net.sourceforge.pmd.lang.java.types.internal.infer.ExprMirror.InvocationMirror; @@ -75,7 +78,7 @@ import net.sourceforge.pmd.util.AssertionUtil; /** * Routines to handle context around poly expressions. */ -final class PolyResolution { +public final class PolyResolution { private final Infer infer; private final TypeSystem ts; @@ -163,7 +166,7 @@ final class PolyResolution { JTypeMirror standalone = branchingMirror.getStandaloneType(); if (standalone != null) { return standalone; - } else if (!ctx.canGiveContextToPoly(false)) { + } else if (!canGiveContextToPoly(ctx, false)) { // null standalone, force resolution anyway, because there is no context // this is more general than ExprMirror#getStandaloneType, it's not a bug @@ -431,7 +434,7 @@ final class PolyResolution { final InvocationNode papi = (InvocationNode) papa.getParent(); if (papi instanceof ASTExplicitConstructorInvocation || papi instanceof ASTEnumConstant) { - return ExprContext.newInvocContext(papi, node.getIndexInParent()); + return newInvocContext(papi, node.getIndexInParent()); } else { if (isPreJava8()) { // in java < 8 invocation contexts don't provide a target type @@ -441,10 +444,10 @@ final class PolyResolution { // Constructor or method call, maybe there's another context around // We want to fetch the outermost invocation node, but not further ExprContext outerCtx = contextOf(papi, /*onlyInvoc:*/true, internalUse); - return outerCtx.canGiveContextToPoly(false) + return canGiveContextToPoly(outerCtx, false) ? outerCtx // otherwise we're done, this is the outermost context - : ExprContext.newInvocContext(papi, node.getIndexInParent()); + : newInvocContext(papi, node.getIndexInParent()); } } else if (doesCascadesContext(papa, node, internalUse)) { // switch/conditional @@ -614,7 +617,7 @@ final class PolyResolution { // test only - static JTypeMirror computeStandaloneConditionalType(TypeSystem ts, JTypeMirror t2, JTypeMirror t3) { + public static JTypeMirror computeStandaloneConditionalType(TypeSystem ts, JTypeMirror t2, JTypeMirror t3) { return computeStandaloneConditionalType(ts, asList(t2, t3)); } @@ -667,35 +670,35 @@ final class PolyResolution { // invalid syntax return ExprContext.getMissingInstance(); } - return ExprContext.newOtherContext(targetType, ExprContextKind.ASSIGNMENT); + return newOtherContext(targetType, ExprContextKind.ASSIGNMENT); } static ExprContext newNonPolyContext(JTypeMirror targetType) { - return ExprContext.newOtherContext(targetType, ExprContextKind.BOOLEAN); + return newOtherContext(targetType, ExprContextKind.BOOLEAN); } static ExprContext newStringCtx(TypeSystem ts) { JClassType stringType = (JClassType) TypesFromReflection.fromReflect(String.class, ts); - return ExprContext.newOtherContext(stringType, ExprContextKind.STRING); + return newOtherContext(stringType, ExprContextKind.STRING); } static ExprContext newNumericContext(JTypeMirror targetType) { if (targetType.isPrimitive()) { assert targetType.isNumeric() : "Not a numeric type - " + targetType; - return ExprContext.newOtherContext(targetType, ExprContextKind.NUMERIC); + return newOtherContext(targetType, ExprContextKind.NUMERIC); } return ExprContext.getMissingInstance(); // error } static ExprContext newCastCtx(JTypeMirror targetType) { - return ExprContext.newOtherContext(targetType, ExprContextKind.CAST); + return newOtherContext(targetType, ExprContextKind.CAST); } static ExprContext newSuperCtorCtx(JTypeMirror superclassType) { - return ExprContext.newOtherContext(superclassType, ExprContextKind.ASSIGNMENT); + return newOtherContext(superclassType, ExprContextKind.ASSIGNMENT); } static ExprContext newStandaloneTernaryCtx(JTypeMirror ternaryType) { - return ExprContext.newOtherContext(ternaryType, ExprContextKind.TERNARY); + return newOtherContext(ternaryType, ExprContextKind.TERNARY); } } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/internal/RegularCtx.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/internal/RegularCtx.java new file mode 100644 index 0000000000..6952760fde --- /dev/null +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/internal/RegularCtx.java @@ -0,0 +1,36 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.java.types.ast.internal; + +import static net.sourceforge.pmd.lang.java.types.ast.ExprContext.ExprContextKind.INVOCATION; +import static net.sourceforge.pmd.lang.java.types.ast.ExprContext.ExprContextKind.MISSING; + +import org.checkerframework.checker.nullness.qual.Nullable; + +import net.sourceforge.pmd.lang.java.types.JTypeMirror; +import net.sourceforge.pmd.lang.java.types.ast.ExprContext; + +public final class RegularCtx extends ExprContext { + + public static final RegularCtx NO_CTX = new RegularCtx(null, MISSING); + + final @Nullable JTypeMirror targetType; + + public RegularCtx(@Nullable JTypeMirror targetType, ExprContextKind kind) { + super(kind); + assert kind != INVOCATION; + this.targetType = targetType; + } + + @Override + public @Nullable JTypeMirror getTargetType() { + return targetType; + } + + @Override + public String toString() { + return "RegularCtx{kind=" + kind + ", targetType=" + targetType + '}'; + } +} diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/InternalMethodTypeItf.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/InternalMethodTypeItf.java index e9792aa1a0..4b14a54385 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/InternalMethodTypeItf.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/InternalMethodTypeItf.java @@ -20,6 +20,10 @@ import net.sourceforge.pmd.lang.java.types.SubstVar; */ public interface InternalMethodTypeItf { + static InternalMethodTypeItf cast(JMethodSig methodSig) { + return (InternalMethodTypeItf) methodSig; + } + /** * Returns a new method type with the given return type and all the * same characteristics as this one. diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/infer/ExprCheckHelper.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/infer/ExprCheckHelper.java index 4433e430a2..148a542403 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/infer/ExprCheckHelper.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/infer/ExprCheckHelper.java @@ -10,6 +10,7 @@ import static net.sourceforge.pmd.lang.java.types.TypeOps.asClassType; import static net.sourceforge.pmd.lang.java.types.TypeOps.findFunctionalInterfaceMethod; import static net.sourceforge.pmd.lang.java.types.TypeOps.mentionsAny; import static net.sourceforge.pmd.lang.java.types.TypeOps.nonWildcardParameterization; +import static net.sourceforge.pmd.lang.java.types.internal.InternalMethodTypeItf.cast; import static net.sourceforge.pmd.lang.java.types.internal.infer.ExprOps.methodRefAsInvocation; import static net.sourceforge.pmd.lang.java.types.internal.infer.InferenceVar.BoundKind.EQ; import static net.sourceforge.pmd.lang.java.types.internal.infer.InferenceVar.BoundKind.LOWER; @@ -434,7 +435,7 @@ final class ExprCheckHelper { infCtx.freeVarsIn(groundTargetType), solved -> { mref.setInferredType(solved.ground(groundTargetType)); - mref.setFunctionalMethod(solved.ground(functionalMethod).internalApi().withOwner(solved.ground(functionalMethod.getDeclaringType()))); + mref.setFunctionalMethod(cast(solved.ground(functionalMethod)).withOwner(solved.ground(functionalMethod.getDeclaringType()))); mref.setCompileTimeDecl(solved.ground(ctDecl)); } ); @@ -483,7 +484,7 @@ final class ExprCheckHelper { solved -> { JClassType solvedGround = solved.ground(groundTargetType); lambda.setInferredType(solvedGround); - lambda.setFunctionalMethod(solved.ground(groundFun).internalApi().withOwner(solved.ground(groundFun.getDeclaringType()))); + lambda.setFunctionalMethod(cast(solved.ground(groundFun)).withOwner(solved.ground(groundFun.getDeclaringType()))); } ); } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/infer/ExprOps.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/infer/ExprOps.java index 4847007b1c..8ea1cee3da 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/infer/ExprOps.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/infer/ExprOps.java @@ -5,6 +5,7 @@ package net.sourceforge.pmd.lang.java.types.internal.infer; import static net.sourceforge.pmd.lang.java.types.TypeConversion.capture; +import static net.sourceforge.pmd.lang.java.types.internal.InternalMethodTypeItf.cast; import static net.sourceforge.pmd.util.CollectionUtil.listOf; import java.lang.reflect.Modifier; @@ -246,7 +247,7 @@ final class ExprOps { // of the original owner, ie the erased method is the // same as the generic method. JClassType lhsClass = (JClassType) candidate.getDeclaringType(); - JMethodSig unerased = candidate.internalApi().withOwner(lhsClass.getGenericTypeDeclaration()).internalApi().originalMethod(); + JMethodSig unerased = cast(cast(candidate).withOwner(lhsClass.getGenericTypeDeclaration())).originalMethod(); if (TypeOps.mentionsAny(unerased, lhsClass.getFormalTypeParams())) { return null; } @@ -536,7 +537,7 @@ final class ExprOps { static JMethodSig adaptGetClass(JMethodSig sig, Supplier replacementReturnType) { TypeSystem ts = sig.getTypeSystem(); if ("getClass".equals(sig.getName()) && sig.getDeclaringType().equals(ts.OBJECT)) { - return sig.internalApi().withReturnType(getClassReturn(replacementReturnType.get(), ts)).internalApi().markAsAdapted(); + return cast(cast(sig).withReturnType(getClassReturn(replacementReturnType.get(), ts))).markAsAdapted(); } return sig; } @@ -546,7 +547,7 @@ final class ExprOps { } static boolean isContextDependent(JMethodSig m) { - m = m.internalApi().adaptedMethod(); + m = cast(m).adaptedMethod(); return m.isGeneric() && TypeOps.mentionsAny(m.getReturnType(), m.getTypeParameters()); } } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/infer/IncorporationAction.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/infer/IncorporationAction.java index e4cc4e5f7e..1224569c13 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/infer/IncorporationAction.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/infer/IncorporationAction.java @@ -5,11 +5,11 @@ package net.sourceforge.pmd.lang.java.types.internal.infer; import static net.sourceforge.pmd.lang.java.types.TypeOps.isConvertible; -import static net.sourceforge.pmd.lang.java.types.TypeOps.isSameTypeInInference; import java.util.ArrayList; import java.util.Set; +import net.sourceforge.pmd.lang.java.types.InternalApiBridge; import net.sourceforge.pmd.lang.java.types.JTypeMirror; import net.sourceforge.pmd.lang.java.types.TypeOps.Convertibility; import net.sourceforge.pmd.lang.java.types.internal.infer.InferenceVar.BoundKind; @@ -99,7 +99,7 @@ abstract class IncorporationAction { */ boolean checkBound(boolean eq, JTypeMirror t, JTypeMirror s, InferenceContext ctx) { // eq bounds are so rare we shouldn't care if they're cached - return eq ? isSameTypeInInference(t, s) + return eq ? InternalApiBridge.isSameTypeInInference(t, s) : checkSubtype(t, s, ctx); } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/infer/Infer.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/infer/Infer.java index 712647a2ce..377f022037 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/infer/Infer.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/infer/Infer.java @@ -8,6 +8,7 @@ import static net.sourceforge.pmd.lang.java.types.TypeConversion.capture; import static net.sourceforge.pmd.lang.java.types.TypeConversion.isWilcardParameterized; import static net.sourceforge.pmd.lang.java.types.TypeOps.asList; import static net.sourceforge.pmd.lang.java.types.TypeOps.subst; +import static net.sourceforge.pmd.lang.java.types.internal.InternalMethodTypeItf.cast; import static net.sourceforge.pmd.lang.java.types.internal.infer.ExprOps.isPertinentToApplicability; import static net.sourceforge.pmd.lang.java.types.internal.infer.MethodResolutionPhase.INVOC_LOOSE; import static net.sourceforge.pmd.util.CollectionUtil.listOf; @@ -196,7 +197,7 @@ public final class Infer { } // ok we failed, we can still use some info from the ctdecl - JMethodSig fallback = deleteTypeParams(ctdecl.getMethodType().internalApi().adaptedMethod()); + JMethodSig fallback = deleteTypeParams(cast(ctdecl.getMethodType()).adaptedMethod()); LOG.fallbackInvocation(fallback, site); return ctdecl.withMethod(fallback, true); @@ -326,7 +327,7 @@ public final class Infer { return logInference(site, ctdecl.getResolvePhase().asInvoc(), - ctdecl.getMethodType().internalApi().adaptedMethod()); + cast(ctdecl.getMethodType()).adaptedMethod()); } // this is skipped when running without assertions @@ -420,9 +421,9 @@ public final class Infer { if (!rtype.isInterface()) { // this is for anonymous class ctors // an interface cannot declare a constructor - result = result.internalApi().withOwner(rtype); + result = cast(result).withOwner(rtype); } - return result.internalApi().withTypeParams(null); + return cast(result).withTypeParams(null); } return result; @@ -459,7 +460,7 @@ public final class Infer { } // replace the return type so that anonymous class ctors return the supertype - JMethodSig adaptedSig = cons.internalApi().withReturnType(newType).internalApi().markAsAdapted(); + JMethodSig adaptedSig = cast(cast(cons).withReturnType(newType)).markAsAdapted(); List newTypeFormals = newType.getFormalTypeParams(); if (newTypeFormals.isEmpty()) { @@ -482,7 +483,7 @@ public final class Infer { // type parameters are not part of the adapted signature, so that when we reset // the signature for invocation inference, we don't duplicate new type parameters - return adaptedSig.internalApi().withTypeParams(tparams).internalApi().markAsAdapted(); + return cast(cast(adaptedSig).withTypeParams(tparams)).markAsAdapted(); } } @@ -610,7 +611,7 @@ public final class Infer { LOG.startReturnChecks(); JTypeMirror actualResType = addReturnConstraints(infCtx, m, site); // b3 LOG.endReturnChecks(); - m = m.internalApi().withReturnType(actualResType); + m = cast(m).withReturnType(actualResType); return m; } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/infer/PhaseOverloadSet.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/infer/PhaseOverloadSet.java index 86604eac85..5a2763f062 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/infer/PhaseOverloadSet.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/infer/PhaseOverloadSet.java @@ -5,6 +5,7 @@ package net.sourceforge.pmd.lang.java.types.internal.infer; import static net.sourceforge.pmd.lang.java.types.TypeOps.areOverrideEquivalent; +import static net.sourceforge.pmd.lang.java.types.internal.InternalMethodTypeItf.cast; import static net.sourceforge.pmd.lang.java.types.internal.infer.ExprMirror.TypeSpecies.getSpecies; import static net.sourceforge.pmd.util.OptionalBool.NO; import static net.sourceforge.pmd.util.OptionalBool.UNKNOWN; @@ -15,6 +16,7 @@ import java.util.List; import org.checkerframework.checker.nullness.qual.NonNull; +import net.sourceforge.pmd.lang.java.types.InternalApiBridge; import net.sourceforge.pmd.lang.java.types.JMethodSig; import net.sourceforge.pmd.lang.java.types.JTypeMirror; import net.sourceforge.pmd.lang.java.types.JTypeVar; @@ -90,8 +92,8 @@ final class PhaseOverloadSet extends OverloadSet { @Override protected OptionalBool shouldTakePrecedence(MethodCtDecl m1, MethodCtDecl m2) { - return isMoreSpecific(m1.getMethodType().internalApi().adaptedMethod(), - m2.getMethodType().internalApi().adaptedMethod()); + return isMoreSpecific(cast(m1.getMethodType()).adaptedMethod(), + cast(m2.getMethodType()).adaptedMethod()); } @@ -252,7 +254,7 @@ final class PhaseOverloadSet extends OverloadSet { if (TypeOps.mentionsAny(x, sfun.getTypeParameters()) && !ctx.isGround(y)) { return false; } else { - TypeOps.isSameTypeInInference(x, y.subst(tToS)); // adds an equality constraint + InternalApiBridge.isSameTypeInInference(x, y.subst(tToS)); // adds an equality constraint } } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/infer/TypeInferenceLogger.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/infer/TypeInferenceLogger.java index 8c29c626cb..855cd7ebac 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/infer/TypeInferenceLogger.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/infer/TypeInferenceLogger.java @@ -5,6 +5,8 @@ package net.sourceforge.pmd.lang.java.types.internal.infer; +import static net.sourceforge.pmd.lang.java.types.internal.InternalMethodTypeItf.cast; + import java.io.PrintStream; import java.util.ArrayDeque; import java.util.Deque; @@ -281,11 +283,11 @@ public interface TypeInferenceLogger { printExpr(site.getExpr()); startSection("[WARNING] Ambiguity error: all methods are maximally specific"); for (MethodCtDecl m : methods) { - println(color(m.getMethodType().internalApi().originalMethod(), ANSI_RED)); + println(color(cast(m.getMethodType()).originalMethod(), ANSI_RED)); } if (selected != null) { - endSection("Will select " + color(selected.getMethodType().internalApi().originalMethod(), ANSI_BLUE)); + endSection("Will select " + color(cast(selected.getMethodType()).originalMethod(), ANSI_BLUE)); } else { endSection(""); // no fallback? } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/infer/ast/MethodInvocMirror.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/infer/ast/MethodInvocMirror.java index 4fc9952363..f42f61f1bd 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/infer/ast/MethodInvocMirror.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/internal/infer/ast/MethodInvocMirror.java @@ -19,6 +19,7 @@ import net.sourceforge.pmd.lang.java.types.JMethodSig; import net.sourceforge.pmd.lang.java.types.JTypeMirror; import net.sourceforge.pmd.lang.java.types.TypeConversion; import net.sourceforge.pmd.lang.java.types.TypeOps; +import net.sourceforge.pmd.lang.java.types.internal.InternalMethodTypeItf; import net.sourceforge.pmd.lang.java.types.internal.infer.ExprMirror; import net.sourceforge.pmd.lang.java.types.internal.infer.ExprMirror.InvocationMirror; import net.sourceforge.pmd.lang.java.types.internal.infer.ast.JavaExprMirrors.MirrorMaker; @@ -37,7 +38,7 @@ class MethodInvocMirror extends BaseInvocMirror implements Invoca } private static boolean isContextDependent(JMethodSig m) { - m = m.internalApi().adaptedMethod(); + m = InternalMethodTypeItf.cast(m).adaptedMethod(); return m.isGeneric() && TypeOps.mentionsAny(m.getReturnType(), m.getTypeParameters()); } diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/ast/ConditionalTypeTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/ast/ConditionalTypeTest.kt index 5eb74a6d63..81789a3d15 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/ast/ConditionalTypeTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/ast/ConditionalTypeTest.kt @@ -9,6 +9,7 @@ import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.shouldBe import io.kotest.property.checkAll import net.sourceforge.pmd.lang.java.types.* +import net.sourceforge.pmd.lang.java.types.ast.internal.PolyResolution /** * @author Clément Fournier From 3ff3f5b4d14a0fb35ae62fa37eb6700ae0ffc4f7 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 1 Feb 2024 10:08:16 +0100 Subject: [PATCH 17/37] [jsp] Cleanup InternalApi methods Refs #4348 --- docs/pages/release_notes.md | 2 ++ .../pmd/lang/jsp/ast/InternalApiBridge.java | 22 +++++++++++++++++++ .../pmd/lang/jsp/ast/JspParser.java | 8 +------ .../pmd/lang/jsp/ast/OpenTagRegister.java | 3 --- .../pmd/lang/jsp/cpd/JSPTokenizer.java | 4 ++-- 5 files changed, 27 insertions(+), 12 deletions(-) create mode 100644 pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/ast/InternalApiBridge.java diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 1835c23513..22b8af37f0 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -200,6 +200,8 @@ package or made (package) private and are not accessible anymore. * {%jdoc java::types.ast.internal.LazyTypeResolver %} * {%jdoc java::types.JMethodSig#internalApi() %} has been removed. * {%jdoc java::types.TypeOps#isSameTypeInInference(java::types.JTypeMirror,java::types.JTypeMirror) %} (now package private) +* pmd-jsp + * {%jdoc jsp::ast.JspParser#getTokenBehavior() %} has been removed. **Newly internal classes, interfaces and methods** diff --git a/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/ast/InternalApiBridge.java b/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/ast/InternalApiBridge.java new file mode 100644 index 0000000000..abd8e3db3a --- /dev/null +++ b/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/ast/InternalApiBridge.java @@ -0,0 +1,22 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.jsp.ast; + +import net.sourceforge.pmd.annotation.InternalApi; +import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccTokenDocument; + +/** + * @apiNote Internal API + */ +@InternalApi +public final class InternalApiBridge { + private InternalApiBridge() { + // internal + } + + public static JavaccTokenDocument.TokenDocumentBehavior getJspTokenBehavior() { + return JspParser.TOKEN_BEHAVIOR; + } +} diff --git a/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/ast/JspParser.java b/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/ast/JspParser.java index f508b21bc5..8aea39f5a2 100644 --- a/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/ast/JspParser.java +++ b/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/ast/JspParser.java @@ -4,7 +4,6 @@ package net.sourceforge.pmd.lang.jsp.ast; -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.ast.ParseException; import net.sourceforge.pmd.lang.ast.impl.javacc.CharStream; import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccTokenDocument.TokenDocumentBehavior; @@ -15,7 +14,7 @@ import net.sourceforge.pmd.lang.ast.impl.javacc.JjtreeParserAdapter; */ public final class JspParser extends JjtreeParserAdapter { - private static final TokenDocumentBehavior TOKEN_BEHAVIOR = new TokenDocumentBehavior(JspTokenKinds.TOKEN_NAMES); + static final TokenDocumentBehavior TOKEN_BEHAVIOR = new TokenDocumentBehavior(JspTokenKinds.TOKEN_NAMES); @Override protected TokenDocumentBehavior tokenBehavior() { @@ -26,9 +25,4 @@ public final class JspParser extends JjtreeParserAdapter { protected ASTCompilationUnit parseImpl(CharStream cs, ParserTask task) throws ParseException { return new JspParserImpl(cs).CompilationUnit().makeTaskInfo(task); } - - @InternalApi - public static TokenDocumentBehavior getTokenBehavior() { - return TOKEN_BEHAVIOR; - } } diff --git a/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/ast/OpenTagRegister.java b/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/ast/OpenTagRegister.java index df00733685..ef9db4d4f9 100644 --- a/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/ast/OpenTagRegister.java +++ b/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/ast/OpenTagRegister.java @@ -9,8 +9,6 @@ import java.util.List; import org.apache.commons.lang3.StringUtils; -import net.sourceforge.pmd.annotation.InternalApi; - /** * Utility class to keep track of unclosed tags. The mechanism is rather simple. * If a end tag (</x>) is encountered, it will iterate through the open @@ -21,7 +19,6 @@ import net.sourceforge.pmd.annotation.InternalApi; * @author Victor Bucutea * */ -@InternalApi class OpenTagRegister { private List tagList = new ArrayList<>(); diff --git a/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/cpd/JSPTokenizer.java b/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/cpd/JSPTokenizer.java index 1a6b8044ab..6ff273f3c7 100644 --- a/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/cpd/JSPTokenizer.java +++ b/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/cpd/JSPTokenizer.java @@ -9,14 +9,14 @@ import net.sourceforge.pmd.lang.TokenManager; import net.sourceforge.pmd.lang.ast.impl.javacc.CharStream; import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken; import net.sourceforge.pmd.lang.document.TextDocument; -import net.sourceforge.pmd.lang.jsp.ast.JspParser; +import net.sourceforge.pmd.lang.jsp.ast.InternalApiBridge; import net.sourceforge.pmd.lang.jsp.ast.JspTokenKinds; public class JSPTokenizer extends JavaCCTokenizer { @Override protected TokenManager makeLexerImpl(TextDocument doc) { - return JspTokenKinds.newTokenManager(CharStream.create(doc, JspParser.getTokenBehavior())); + return JspTokenKinds.newTokenManager(CharStream.create(doc, InternalApiBridge.getJspTokenBehavior())); } } From 199798456938e472046a0e16f727182107714e97 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 1 Feb 2024 10:29:09 +0100 Subject: [PATCH 18/37] [modelica] Cleanup InternalApi methods Refs #4348 --- docs/pages/release_notes.md | 7 +++++++ .../modelica/ast/ASTComponentReference.java | 2 +- .../ASTMultipleDefinitionImportClause.java | 10 ++++----- .../pmd/lang/modelica/ast/ASTName.java | 2 +- .../modelica/ast/ASTRenamingImportClause.java | 4 ++-- .../ast/ASTSimpleShortClassSpecifier.java | 4 ++-- .../ast/ASTSingleDefinitionImportClause.java | 4 ++-- .../ast/ASTUnqualifiedImportClause.java | 10 ++++----- .../AbstractModelicaClassSpecifierNode.java | 6 +++--- .../ast/AbstractModelicaImportClause.java | 6 +++--- ...icaNodeApi.java => InternalApiBridge.java} | 8 +++---- .../pmd/lang/modelica/ast/ModelicaParser.java | 4 ++-- .../resolver/AbstractModelicaDeclaration.java | 3 +++ .../resolver/AbstractModelicaScope.java | 4 ++++ ...esolverApi.java => InternalApiBridge.java} | 16 ++++++++++++-- .../resolver/ModelicaClassDeclaration.java | 11 ++++++---- .../modelica/resolver/ModelicaClassScope.java | 5 ++++- .../ModelicaComponentDeclaration.java | 3 +++ .../lang/modelica/resolver/ModelicaScope.java | 2 ++ .../resolver/ModelicaSourceFileScope.java | 2 ++ .../resolver/ModelicaSymbolFacade.java | 21 ------------------- .../pmd/lang/modelica/resolver/RootScope.java | 3 +++ .../resolver/ScopeAndDeclarationFinder.java | 4 ++-- .../resolver/SubcomponentResolver.java | 2 ++ .../{ => internal}/ResolutionContext.java | 12 ++++++----- .../{ => internal}/ResolutionState.java | 6 ++++-- .../resolver/{ => internal}/Watchdog.java | 2 +- .../resolver/ModelicaResolverTest.java | 1 + 28 files changed, 96 insertions(+), 68 deletions(-) rename pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/{InternalModelicaNodeApi.java => InternalApiBridge.java} (83%) rename pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/{InternalModelicaResolverApi.java => InternalApiBridge.java} (64%) delete mode 100644 pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/ModelicaSymbolFacade.java rename pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/{ => internal}/ResolutionContext.java (90%) rename pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/{ => internal}/ResolutionState.java (81%) rename pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/{ => internal}/Watchdog.java (91%) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 22b8af37f0..e116575359 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -202,6 +202,13 @@ package or made (package) private and are not accessible anymore. * {%jdoc java::types.TypeOps#isSameTypeInInference(java::types.JTypeMirror,java::types.JTypeMirror) %} (now package private) * pmd-jsp * {%jdoc jsp::ast.JspParser#getTokenBehavior() %} has been removed. +* pmd-modelica + * {%jdoc modelica::ast.InternalApiBridge %} renamed from InternalModelicaNodeApi. + * {%jdoc modelica::resolver.InternalApiBridge %} renamed from InternalModelicaResolverApi. + * {%jdoc modelica::resolver.ModelicaSymbolFacade %} has been removed. + * {%jdoc modelica::resolver.internal.ResolutionContext %} + * {%jdoc modelica::resolver.internal.ResolutionState %} (note: not previously marked as internal api) + * {%jdoc modelica::resolver.internal.Watchdog %} (note: not previously marked as internal api) **Newly internal classes, interfaces and methods** diff --git a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ASTComponentReference.java b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ASTComponentReference.java index 7e5a4c5570..e42c09e051 100644 --- a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ASTComponentReference.java +++ b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ASTComponentReference.java @@ -6,8 +6,8 @@ package net.sourceforge.pmd.lang.modelica.ast; import net.sourceforge.pmd.lang.modelica.resolver.CompositeName; import net.sourceforge.pmd.lang.modelica.resolver.ResolutionResult; -import net.sourceforge.pmd.lang.modelica.resolver.ResolutionState; import net.sourceforge.pmd.lang.modelica.resolver.ResolvableEntity; +import net.sourceforge.pmd.lang.modelica.resolver.internal.ResolutionState; public final class ASTComponentReference extends AbstractModelicaNode implements ResolvableModelicaNode { private String[] nameComponentsWithoutSubscripts; diff --git a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ASTMultipleDefinitionImportClause.java b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ASTMultipleDefinitionImportClause.java index 2977e7d8ee..bac35a1314 100644 --- a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ASTMultipleDefinitionImportClause.java +++ b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ASTMultipleDefinitionImportClause.java @@ -8,13 +8,13 @@ import java.util.HashSet; import java.util.Set; import net.sourceforge.pmd.lang.modelica.resolver.CompositeName; -import net.sourceforge.pmd.lang.modelica.resolver.InternalModelicaResolverApi; +import net.sourceforge.pmd.lang.modelica.resolver.InternalApiBridge; import net.sourceforge.pmd.lang.modelica.resolver.ModelicaDeclaration; import net.sourceforge.pmd.lang.modelica.resolver.ModelicaScope; -import net.sourceforge.pmd.lang.modelica.resolver.ResolutionContext; import net.sourceforge.pmd.lang.modelica.resolver.ResolutionResult; -import net.sourceforge.pmd.lang.modelica.resolver.ResolutionState; -import net.sourceforge.pmd.lang.modelica.resolver.Watchdog; +import net.sourceforge.pmd.lang.modelica.resolver.internal.ResolutionContext; +import net.sourceforge.pmd.lang.modelica.resolver.internal.ResolutionState; +import net.sourceforge.pmd.lang.modelica.resolver.internal.Watchdog; public final class ASTMultipleDefinitionImportClause extends AbstractModelicaImportClause { private ASTName importFrom; @@ -48,7 +48,7 @@ public final class ASTMultipleDefinitionImportClause extends AbstractModelicaImp @Override protected void fetchImportedClassesFromSource(ResolutionContext result, ModelicaDeclaration source, String simpleName) throws Watchdog.CountdownException { if (importedNames.contains(simpleName)) { - InternalModelicaResolverApi.resolveFurtherNameComponents(source, result, CompositeName.create(simpleName)); + InternalApiBridge.resolveFurtherNameComponents(source, result, CompositeName.create(simpleName)); } } diff --git a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ASTName.java b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ASTName.java index 634b991a58..e4fd15d9ff 100644 --- a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ASTName.java +++ b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ASTName.java @@ -6,8 +6,8 @@ package net.sourceforge.pmd.lang.modelica.ast; import net.sourceforge.pmd.lang.modelica.resolver.CompositeName; import net.sourceforge.pmd.lang.modelica.resolver.ResolutionResult; -import net.sourceforge.pmd.lang.modelica.resolver.ResolutionState; import net.sourceforge.pmd.lang.modelica.resolver.ResolvableEntity; +import net.sourceforge.pmd.lang.modelica.resolver.internal.ResolutionState; public final class ASTName extends AbstractModelicaNode implements ResolvableModelicaNode { private String[] nameComponents; diff --git a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ASTRenamingImportClause.java b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ASTRenamingImportClause.java index 33787c76da..62661644ef 100644 --- a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ASTRenamingImportClause.java +++ b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ASTRenamingImportClause.java @@ -6,9 +6,9 @@ package net.sourceforge.pmd.lang.modelica.ast; import net.sourceforge.pmd.lang.modelica.resolver.ModelicaDeclaration; import net.sourceforge.pmd.lang.modelica.resolver.ModelicaScope; -import net.sourceforge.pmd.lang.modelica.resolver.ResolutionContext; import net.sourceforge.pmd.lang.modelica.resolver.ResolutionResult; -import net.sourceforge.pmd.lang.modelica.resolver.ResolutionState; +import net.sourceforge.pmd.lang.modelica.resolver.internal.ResolutionContext; +import net.sourceforge.pmd.lang.modelica.resolver.internal.ResolutionState; public final class ASTRenamingImportClause extends AbstractModelicaImportClause { private ASTName importWhat; diff --git a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ASTSimpleShortClassSpecifier.java b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ASTSimpleShortClassSpecifier.java index bc7e0a9518..8ad0381623 100644 --- a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ASTSimpleShortClassSpecifier.java +++ b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ASTSimpleShortClassSpecifier.java @@ -4,7 +4,7 @@ package net.sourceforge.pmd.lang.modelica.ast; -import net.sourceforge.pmd.lang.modelica.resolver.InternalModelicaResolverApi; +import net.sourceforge.pmd.lang.modelica.resolver.InternalApiBridge; import net.sourceforge.pmd.lang.modelica.resolver.ModelicaClassType; public final class ASTSimpleShortClassSpecifier extends AbstractModelicaClassSpecifierNode { @@ -20,7 +20,7 @@ public final class ASTSimpleShortClassSpecifier extends AbstractModelicaClassSpe @Override public void populateExtendsAndImports(ModelicaClassType classTypeDeclaration) { super.populateExtendsAndImports(classTypeDeclaration); - InternalModelicaResolverApi.addExtendToClass( + InternalApiBridge.addExtendToClass( classTypeDeclaration, Visibility.UNSPEC, firstChild(ASTName.class).getCompositeName() diff --git a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ASTSingleDefinitionImportClause.java b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ASTSingleDefinitionImportClause.java index c1ce260b3f..97dcd0d39a 100644 --- a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ASTSingleDefinitionImportClause.java +++ b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ASTSingleDefinitionImportClause.java @@ -6,9 +6,9 @@ package net.sourceforge.pmd.lang.modelica.ast; import net.sourceforge.pmd.lang.modelica.resolver.ModelicaDeclaration; import net.sourceforge.pmd.lang.modelica.resolver.ModelicaScope; -import net.sourceforge.pmd.lang.modelica.resolver.ResolutionContext; import net.sourceforge.pmd.lang.modelica.resolver.ResolutionResult; -import net.sourceforge.pmd.lang.modelica.resolver.ResolutionState; +import net.sourceforge.pmd.lang.modelica.resolver.internal.ResolutionContext; +import net.sourceforge.pmd.lang.modelica.resolver.internal.ResolutionState; public class ASTSingleDefinitionImportClause extends AbstractModelicaImportClause { private ASTName importWhat; diff --git a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ASTUnqualifiedImportClause.java b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ASTUnqualifiedImportClause.java index 82b176adc9..ad4b685b8c 100644 --- a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ASTUnqualifiedImportClause.java +++ b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ASTUnqualifiedImportClause.java @@ -5,13 +5,13 @@ package net.sourceforge.pmd.lang.modelica.ast; import net.sourceforge.pmd.lang.modelica.resolver.CompositeName; -import net.sourceforge.pmd.lang.modelica.resolver.InternalModelicaResolverApi; +import net.sourceforge.pmd.lang.modelica.resolver.InternalApiBridge; import net.sourceforge.pmd.lang.modelica.resolver.ModelicaDeclaration; import net.sourceforge.pmd.lang.modelica.resolver.ModelicaScope; -import net.sourceforge.pmd.lang.modelica.resolver.ResolutionContext; import net.sourceforge.pmd.lang.modelica.resolver.ResolutionResult; -import net.sourceforge.pmd.lang.modelica.resolver.ResolutionState; -import net.sourceforge.pmd.lang.modelica.resolver.Watchdog; +import net.sourceforge.pmd.lang.modelica.resolver.internal.ResolutionContext; +import net.sourceforge.pmd.lang.modelica.resolver.internal.ResolutionState; +import net.sourceforge.pmd.lang.modelica.resolver.internal.Watchdog; public final class ASTUnqualifiedImportClause extends AbstractModelicaImportClause { private ASTName importFromWhere; @@ -40,7 +40,7 @@ public final class ASTUnqualifiedImportClause extends AbstractModelicaImportClau @Override protected void fetchImportedClassesFromSource(ResolutionContext result, ModelicaDeclaration source, String simpleName) throws Watchdog.CountdownException { result.watchdogTick(); - InternalModelicaResolverApi.resolveFurtherNameComponents(source, result, CompositeName.create(simpleName)); + InternalApiBridge.resolveFurtherNameComponents(source, result, CompositeName.create(simpleName)); } @Override diff --git a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/AbstractModelicaClassSpecifierNode.java b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/AbstractModelicaClassSpecifierNode.java index 7209f531d0..bf623e75d9 100644 --- a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/AbstractModelicaClassSpecifierNode.java +++ b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/AbstractModelicaClassSpecifierNode.java @@ -4,7 +4,7 @@ package net.sourceforge.pmd.lang.modelica.ast; -import net.sourceforge.pmd.lang.modelica.resolver.InternalModelicaResolverApi; +import net.sourceforge.pmd.lang.modelica.resolver.InternalApiBridge; import net.sourceforge.pmd.lang.modelica.resolver.ModelicaClassType; /** @@ -34,14 +34,14 @@ abstract class AbstractModelicaClassSpecifierNode extends AbstractModelicaNode i for (int i = 0; i < listNode.getNumChildren(); ++i) { AbstractModelicaNode child = (AbstractModelicaNode) listNode.getChild(i); if (child instanceof ASTExtendsClause) { - InternalModelicaResolverApi.addExtendToClass( + InternalApiBridge.addExtendToClass( classTypeDeclaration, listNode.getVisibility(), child.firstChild(ASTName.class).getCompositeName() ); } if (child instanceof ASTImportClause) { - InternalModelicaResolverApi.addImportToClass( + InternalApiBridge.addImportToClass( classTypeDeclaration, listNode.getVisibility(), child.firstChild(ModelicaImportClause.class) diff --git a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/AbstractModelicaImportClause.java b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/AbstractModelicaImportClause.java index 98e6c79999..98608a1ad0 100644 --- a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/AbstractModelicaImportClause.java +++ b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/AbstractModelicaImportClause.java @@ -6,10 +6,10 @@ package net.sourceforge.pmd.lang.modelica.ast; import net.sourceforge.pmd.lang.modelica.resolver.ModelicaDeclaration; import net.sourceforge.pmd.lang.modelica.resolver.ModelicaScope; -import net.sourceforge.pmd.lang.modelica.resolver.ResolutionContext; import net.sourceforge.pmd.lang.modelica.resolver.ResolutionResult; -import net.sourceforge.pmd.lang.modelica.resolver.ResolutionState; -import net.sourceforge.pmd.lang.modelica.resolver.Watchdog; +import net.sourceforge.pmd.lang.modelica.resolver.internal.ResolutionContext; +import net.sourceforge.pmd.lang.modelica.resolver.internal.ResolutionState; +import net.sourceforge.pmd.lang.modelica.resolver.internal.Watchdog; /** * Common internal machinery for various import clauses to describe themselves to resolver. diff --git a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/InternalModelicaNodeApi.java b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/InternalApiBridge.java similarity index 83% rename from pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/InternalModelicaNodeApi.java rename to pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/InternalApiBridge.java index e3aa208da8..a7b5aa41b5 100644 --- a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/InternalModelicaNodeApi.java +++ b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/InternalApiBridge.java @@ -7,12 +7,12 @@ package net.sourceforge.pmd.lang.modelica.ast; import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.modelica.resolver.ModelicaClassType; import net.sourceforge.pmd.lang.modelica.resolver.ModelicaScope; -import net.sourceforge.pmd.lang.modelica.resolver.ResolutionContext; -import net.sourceforge.pmd.lang.modelica.resolver.Watchdog; +import net.sourceforge.pmd.lang.modelica.resolver.internal.ResolutionContext; +import net.sourceforge.pmd.lang.modelica.resolver.internal.Watchdog; @InternalApi -public final class InternalModelicaNodeApi { - private InternalModelicaNodeApi() {} +public final class InternalApiBridge { + private InternalApiBridge() {} public static void setNodeOwnScope(ModelicaNode node, ModelicaScope scope) { ((AbstractModelicaNode) node).setOwnScope(scope); diff --git a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ModelicaParser.java b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ModelicaParser.java index 6e1ac343aa..7329a4614d 100644 --- a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ModelicaParser.java +++ b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/ModelicaParser.java @@ -9,7 +9,7 @@ import net.sourceforge.pmd.lang.ast.ParseException; import net.sourceforge.pmd.lang.ast.impl.javacc.CharStream; import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccTokenDocument.TokenDocumentBehavior; import net.sourceforge.pmd.lang.ast.impl.javacc.JjtreeParserAdapter; -import net.sourceforge.pmd.lang.modelica.resolver.ModelicaSymbolFacade; +import net.sourceforge.pmd.lang.modelica.resolver.InternalApiBridge; public class ModelicaParser extends JjtreeParserAdapter { @@ -24,7 +24,7 @@ public class ModelicaParser extends JjtreeParserAdapter { @Override protected ASTStoredDefinition parseImpl(CharStream cs, ParserTask task) throws ParseException { ASTStoredDefinition root = new ModelicaParserImpl(cs).StoredDefinition().makeTaskInfo(task); - TimeTracker.bench("Modelica symbols", () -> ModelicaSymbolFacade.process(root)); + TimeTracker.bench("Modelica symbols", () -> InternalApiBridge.ModelicaSymbolFacade.process(root)); return root; } diff --git a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/AbstractModelicaDeclaration.java b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/AbstractModelicaDeclaration.java index 41e9246190..bc03e13ed1 100644 --- a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/AbstractModelicaDeclaration.java +++ b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/AbstractModelicaDeclaration.java @@ -4,6 +4,9 @@ package net.sourceforge.pmd.lang.modelica.resolver; +import net.sourceforge.pmd.lang.modelica.resolver.internal.ResolutionContext; +import net.sourceforge.pmd.lang.modelica.resolver.internal.Watchdog; + /** * Internal base class for Modelica declarations, see ${@link ModelicaDeclaration} for public API. */ diff --git a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/AbstractModelicaScope.java b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/AbstractModelicaScope.java index 8d3366bee6..04556dc870 100644 --- a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/AbstractModelicaScope.java +++ b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/AbstractModelicaScope.java @@ -10,6 +10,10 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import net.sourceforge.pmd.lang.modelica.resolver.internal.ResolutionContext; +import net.sourceforge.pmd.lang.modelica.resolver.internal.ResolutionState; +import net.sourceforge.pmd.lang.modelica.resolver.internal.Watchdog; + /** * Internal base class for Modelica lexical scopes, see {@link ModelicaScope} for the public API. */ diff --git a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/InternalModelicaResolverApi.java b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/InternalApiBridge.java similarity index 64% rename from pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/InternalModelicaResolverApi.java rename to pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/InternalApiBridge.java index 71ef053e35..5bf71e8346 100644 --- a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/InternalModelicaResolverApi.java +++ b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/InternalApiBridge.java @@ -5,12 +5,15 @@ package net.sourceforge.pmd.lang.modelica.resolver; import net.sourceforge.pmd.annotation.InternalApi; +import net.sourceforge.pmd.lang.modelica.ast.ASTStoredDefinition; import net.sourceforge.pmd.lang.modelica.ast.ModelicaImportClause; import net.sourceforge.pmd.lang.modelica.ast.Visibility; +import net.sourceforge.pmd.lang.modelica.resolver.internal.ResolutionContext; +import net.sourceforge.pmd.lang.modelica.resolver.internal.Watchdog; @InternalApi -public final class InternalModelicaResolverApi { - private InternalModelicaResolverApi() {} +public final class InternalApiBridge { + private InternalApiBridge() {} public static void addImportToClass(ModelicaClassType classTypeDeclaration, Visibility visibility, ModelicaImportClause clause) { ((ModelicaClassDeclaration) classTypeDeclaration).addImport(visibility, clause); @@ -23,4 +26,13 @@ public final class InternalModelicaResolverApi { public static void resolveFurtherNameComponents(ModelicaDeclaration declaration, ResolutionContext result, CompositeName name) throws Watchdog.CountdownException { ((AbstractModelicaDeclaration) declaration).resolveFurtherNameComponents(result, name); } + + public static final class ModelicaSymbolFacade { + private ModelicaSymbolFacade() {} + + public static void process(ASTStoredDefinition node) { + ScopeAndDeclarationFinder sc = new ScopeAndDeclarationFinder(); + node.acceptVisitor(sc, null); + } + } } diff --git a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/ModelicaClassDeclaration.java b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/ModelicaClassDeclaration.java index 962c67f0e5..900b2f487f 100644 --- a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/ModelicaClassDeclaration.java +++ b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/ModelicaClassDeclaration.java @@ -8,10 +8,13 @@ import java.util.ArrayList; import java.util.List; import net.sourceforge.pmd.lang.modelica.ast.ASTClassDefinition; -import net.sourceforge.pmd.lang.modelica.ast.InternalModelicaNodeApi; +import net.sourceforge.pmd.lang.modelica.ast.InternalApiBridge; import net.sourceforge.pmd.lang.modelica.ast.ModelicaClassSpecifierNode; import net.sourceforge.pmd.lang.modelica.ast.ModelicaImportClause; import net.sourceforge.pmd.lang.modelica.ast.Visibility; +import net.sourceforge.pmd.lang.modelica.resolver.internal.ResolutionContext; +import net.sourceforge.pmd.lang.modelica.resolver.internal.ResolutionState; +import net.sourceforge.pmd.lang.modelica.resolver.internal.Watchdog; /** * Internal representation of a declared Modelica class, see {@link ModelicaClassType} for public API. @@ -32,7 +35,7 @@ class ModelicaClassDeclaration extends AbstractModelicaDeclaration implements Mo specialization = node.getSpecialization(); ModelicaClassSpecifierNode classNode = node.getClassSpecifier(); simpleName = classNode.getSimpleClassName(); - InternalModelicaNodeApi.populateExtendsAndImports(classNode, this); + InternalApiBridge.populateExtendsAndImports(classNode, this); } /** @@ -99,8 +102,8 @@ class ModelicaClassDeclaration extends AbstractModelicaDeclaration implements Mo ResolutionContext result = state.createContext(); for (final ModelicaImportClause importClause: imports) { ResolutionContext subResult = state.createContext(); - if (InternalModelicaNodeApi.isQualifiedImport(importClause) == qualified) { - InternalModelicaNodeApi.resolveImportedSimpleName(importClause, subResult, firstName); + if (InternalApiBridge.isQualifiedImport(importClause) == qualified) { + InternalApiBridge.resolveImportedSimpleName(importClause, subResult, firstName); } result.accumulate(subResult.getDeclaration()); } diff --git a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/ModelicaClassScope.java b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/ModelicaClassScope.java index 6957a627cf..4231baa91b 100644 --- a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/ModelicaClassScope.java +++ b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/ModelicaClassScope.java @@ -4,6 +4,9 @@ package net.sourceforge.pmd.lang.modelica.resolver; +import net.sourceforge.pmd.lang.modelica.resolver.internal.ResolutionContext; +import net.sourceforge.pmd.lang.modelica.resolver.internal.Watchdog; + /** * A lexical scope corresponding to a Modelica class. */ @@ -21,7 +24,7 @@ public final class ModelicaClassScope extends AbstractModelicaScope { @Override public void resolveLexically(ResolutionContext result, CompositeName name) throws Watchdog.CountdownException { - InternalModelicaResolverApi.resolveFurtherNameComponents(classDeclaration, result, name); + InternalApiBridge.resolveFurtherNameComponents(classDeclaration, result, name); if (classDeclaration.isEncapsulated()) { getRoot().resolveBuiltin(result, name); } else { diff --git a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/ModelicaComponentDeclaration.java b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/ModelicaComponentDeclaration.java index fa35627614..ed9919048b 100644 --- a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/ModelicaComponentDeclaration.java +++ b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/ModelicaComponentDeclaration.java @@ -19,6 +19,9 @@ import net.sourceforge.pmd.lang.modelica.ast.ASTSimpleName; import net.sourceforge.pmd.lang.modelica.ast.ASTStreamClause; import net.sourceforge.pmd.lang.modelica.ast.ASTTypePrefix; import net.sourceforge.pmd.lang.modelica.ast.ASTTypeSpecifier; +import net.sourceforge.pmd.lang.modelica.resolver.internal.ResolutionContext; +import net.sourceforge.pmd.lang.modelica.resolver.internal.ResolutionState; +import net.sourceforge.pmd.lang.modelica.resolver.internal.Watchdog; public class ModelicaComponentDeclaration extends AbstractModelicaDeclaration implements ModelicaDeclaration { public enum ComponentKind { diff --git a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/ModelicaScope.java b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/ModelicaScope.java index db633846d9..0b12d1597b 100644 --- a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/ModelicaScope.java +++ b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/ModelicaScope.java @@ -6,6 +6,8 @@ package net.sourceforge.pmd.lang.modelica.resolver; import java.util.List; +import net.sourceforge.pmd.lang.modelica.resolver.internal.ResolutionState; + /** * A lexical scope of Modelica code. * That is, a component declaration does not have one, it is its type that does (but these may be resolved to multiple diff --git a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/ModelicaSourceFileScope.java b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/ModelicaSourceFileScope.java index 48bbc27158..3172f43b26 100644 --- a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/ModelicaSourceFileScope.java +++ b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/ModelicaSourceFileScope.java @@ -5,6 +5,8 @@ package net.sourceforge.pmd.lang.modelica.resolver; import net.sourceforge.pmd.lang.modelica.ast.ASTStoredDefinition; +import net.sourceforge.pmd.lang.modelica.resolver.internal.ResolutionContext; +import net.sourceforge.pmd.lang.modelica.resolver.internal.Watchdog; /** * A scope corresponding to some specific Modelica source code file. diff --git a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/ModelicaSymbolFacade.java b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/ModelicaSymbolFacade.java deleted file mode 100644 index 6786d3193f..0000000000 --- a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/ModelicaSymbolFacade.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - -package net.sourceforge.pmd.lang.modelica.resolver; - -import net.sourceforge.pmd.annotation.InternalApi; -import net.sourceforge.pmd.lang.modelica.ast.ASTStoredDefinition; - -@InternalApi -public final class ModelicaSymbolFacade { - - private ModelicaSymbolFacade() { - // util class - } - - public static void process(ASTStoredDefinition node) { - ScopeAndDeclarationFinder sc = new ScopeAndDeclarationFinder(); - node.acceptVisitor(sc, null); - } -} diff --git a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/RootScope.java b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/RootScope.java index 6d1b399d5e..2652db5c12 100644 --- a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/RootScope.java +++ b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/RootScope.java @@ -7,6 +7,9 @@ package net.sourceforge.pmd.lang.modelica.resolver; import java.util.ArrayList; import java.util.List; +import net.sourceforge.pmd.lang.modelica.resolver.internal.ResolutionContext; +import net.sourceforge.pmd.lang.modelica.resolver.internal.Watchdog; + /** * A pseudo lexical scope corresponding to "unnamed enclosing class" for top-level entities. * See "5.2 Enclosing Classes" from MLS 3.4. diff --git a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/ScopeAndDeclarationFinder.java b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/ScopeAndDeclarationFinder.java index a36d8d4dbe..e552296e1f 100644 --- a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/ScopeAndDeclarationFinder.java +++ b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/ScopeAndDeclarationFinder.java @@ -10,7 +10,7 @@ import java.util.Deque; import net.sourceforge.pmd.lang.modelica.ast.ASTClassDefinition; import net.sourceforge.pmd.lang.modelica.ast.ASTComponentDeclaration; import net.sourceforge.pmd.lang.modelica.ast.ASTStoredDefinition; -import net.sourceforge.pmd.lang.modelica.ast.InternalModelicaNodeApi; +import net.sourceforge.pmd.lang.modelica.ast.InternalApiBridge; import net.sourceforge.pmd.lang.modelica.ast.ModelicaNode; import net.sourceforge.pmd.lang.modelica.ast.ModelicaVisitorBase; @@ -25,7 +25,7 @@ class ScopeAndDeclarationFinder extends ModelicaVisitorBase { AbstractModelicaScope prevTop = scopes.peek(); ownScope.setParent(prevTop); scopes.push(ownScope); - InternalModelicaNodeApi.setNodeOwnScope(node, ownScope); + InternalApiBridge.setNodeOwnScope(node, ownScope); } private void createClassDeclaration(ASTClassDefinition node) { diff --git a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/SubcomponentResolver.java b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/SubcomponentResolver.java index 983be6cdc5..7584c83431 100644 --- a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/SubcomponentResolver.java +++ b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/SubcomponentResolver.java @@ -4,6 +4,8 @@ package net.sourceforge.pmd.lang.modelica.resolver; +import net.sourceforge.pmd.lang.modelica.resolver.internal.ResolutionState; + /** * This interface represents something that, being looked up by some prefix of composite name, * may resolve further name parts. Lexically, this is represented by a dot-notation. diff --git a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/ResolutionContext.java b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/internal/ResolutionContext.java similarity index 90% rename from pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/ResolutionContext.java rename to pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/internal/ResolutionContext.java index 15547b0efb..40c60274fd 100644 --- a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/ResolutionContext.java +++ b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/internal/ResolutionContext.java @@ -2,15 +2,17 @@ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ -package net.sourceforge.pmd.lang.modelica.resolver; +package net.sourceforge.pmd.lang.modelica.resolver.internal; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import net.sourceforge.pmd.annotation.InternalApi; +import net.sourceforge.pmd.lang.modelica.resolver.ModelicaDeclaration; +import net.sourceforge.pmd.lang.modelica.resolver.ModelicaType; +import net.sourceforge.pmd.lang.modelica.resolver.ResolutionResult; +import net.sourceforge.pmd.lang.modelica.resolver.ResolvableEntity; -@InternalApi public class ResolutionContext { private final ResolutionState state; private final List bestCandidates = new ArrayList<>(); @@ -43,7 +45,7 @@ public class ResolutionContext { * * Usually, this method is called after catching `Watchdog.CountdownException`. */ - void markTtlExceeded() { + public void markTtlExceeded() { ttlExceeded = true; } @@ -60,7 +62,7 @@ public class ResolutionContext { } } - void accumulate(ResolutionResult result) { + public void accumulate(ResolutionResult result) { bestCandidates.addAll(result.getBestCandidates()); hiddenCandidates.addAll(result.getHiddenCandidates()); } diff --git a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/ResolutionState.java b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/internal/ResolutionState.java similarity index 81% rename from pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/ResolutionState.java rename to pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/internal/ResolutionState.java index 2b01ec1e8c..3c78958906 100644 --- a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/ResolutionState.java +++ b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/internal/ResolutionState.java @@ -2,7 +2,9 @@ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ -package net.sourceforge.pmd.lang.modelica.resolver; +package net.sourceforge.pmd.lang.modelica.resolver.internal; + +import net.sourceforge.pmd.lang.modelica.resolver.ModelicaComponentDeclaration; public final class ResolutionState { private final Watchdog watchdog; @@ -21,7 +23,7 @@ public final class ResolutionState { return new ResolutionState(false); } - void tick() throws Watchdog.CountdownException { + public void tick() throws Watchdog.CountdownException { watchdog.decrement(); } diff --git a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/Watchdog.java b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/internal/Watchdog.java similarity index 91% rename from pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/Watchdog.java rename to pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/internal/Watchdog.java index 2373efb4b7..d0ab889ebd 100644 --- a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/Watchdog.java +++ b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/internal/Watchdog.java @@ -2,7 +2,7 @@ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ -package net.sourceforge.pmd.lang.modelica.resolver; +package net.sourceforge.pmd.lang.modelica.resolver.internal; /** * A watchdog counter initialized with some value. Throws an exception after the specified {@link #decrement} calls. diff --git a/pmd-modelica/src/test/java/net/sourceforge/pmd/lang/modelica/resolver/ModelicaResolverTest.java b/pmd-modelica/src/test/java/net/sourceforge/pmd/lang/modelica/resolver/ModelicaResolverTest.java index 2bcac7b22f..438cd5f62b 100644 --- a/pmd-modelica/src/test/java/net/sourceforge/pmd/lang/modelica/resolver/ModelicaResolverTest.java +++ b/pmd-modelica/src/test/java/net/sourceforge/pmd/lang/modelica/resolver/ModelicaResolverTest.java @@ -20,6 +20,7 @@ import net.sourceforge.pmd.lang.modelica.ast.ASTStoredDefinition; import net.sourceforge.pmd.lang.modelica.ast.ModelicaClassSpecifierNode; import net.sourceforge.pmd.lang.modelica.ast.ModelicaNode; import net.sourceforge.pmd.lang.modelica.ast.ModelicaVisitorBase; +import net.sourceforge.pmd.lang.modelica.resolver.internal.ResolutionState; class ModelicaResolverTest { From 8285d70fe5c6f55f9355ddf9891f945ff02dff95 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 1 Feb 2024 10:31:48 +0100 Subject: [PATCH 19/37] [plsql] Cleanup InternalApi methods Refs #4348 --- docs/pages/release_notes.md | 2 ++ .../pmd/lang/plsql/ast/AbstractSelectStatement.java | 3 --- .../sourceforge/pmd/lang/plsql/ast/InternalApiBridge.java | 2 +- .../pmd/lang/plsql/rule/design/AbstractNcssCountRule.java | 7 ++----- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index e116575359..61a8a06c5f 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -209,6 +209,8 @@ package or made (package) private and are not accessible anymore. * {%jdoc modelica::resolver.internal.ResolutionContext %} * {%jdoc modelica::resolver.internal.ResolutionState %} (note: not previously marked as internal api) * {%jdoc modelica::resolver.internal.Watchdog %} (note: not previously marked as internal api) +* pmd-plsql + * {%jdoc plsql::rule.design.AbstractNcssCountRule (now package private) **Newly internal classes, interfaces and methods** diff --git a/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/ast/AbstractSelectStatement.java b/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/ast/AbstractSelectStatement.java index 7db652b4a4..afcbc7d1cf 100644 --- a/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/ast/AbstractSelectStatement.java +++ b/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/ast/AbstractSelectStatement.java @@ -4,9 +4,6 @@ package net.sourceforge.pmd.lang.plsql.ast; -import net.sourceforge.pmd.annotation.InternalApi; - -@InternalApi abstract class AbstractSelectStatement extends AbstractPLSQLNode { private boolean distinct; diff --git a/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/ast/InternalApiBridge.java b/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/ast/InternalApiBridge.java index 91387c7722..c9ef5160b7 100644 --- a/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/ast/InternalApiBridge.java +++ b/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/ast/InternalApiBridge.java @@ -13,7 +13,7 @@ import net.sourceforge.pmd.lang.symboltable.Scope; * Acts as a bridge between outer parts (e.g. symbol table) and the restricted * access internal API of this package. * - *

Note: This is internal API. + * @apiNote This is internal API. */ @InternalApi public final class InternalApiBridge { diff --git a/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/rule/design/AbstractNcssCountRule.java b/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/rule/design/AbstractNcssCountRule.java index dc3a5eecc3..5829732c94 100644 --- a/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/rule/design/AbstractNcssCountRule.java +++ b/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/rule/design/AbstractNcssCountRule.java @@ -4,7 +4,6 @@ package net.sourceforge.pmd.lang.plsql.rule.design; -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.plsql.ast.ASTCaseStatement; import net.sourceforge.pmd.lang.plsql.ast.ASTCaseWhenClause; @@ -31,11 +30,9 @@ import net.sourceforge.pmd.lang.plsql.ast.PLSQLParserVisitorAdapter; * Abstract superclass for NCSS counting methods. Analogous to and cribbed from * the Java version of the rule. * - * @deprecated Internal API + * @apiNote Internal API */ -@Deprecated -@InternalApi -public abstract class AbstractNcssCountRule extends AbstractCounterCheckRule { +abstract class AbstractNcssCountRule extends AbstractCounterCheckRule { /** From d1c3212ea7937ac839bf6999e5138a01e1dc8442 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 1 Feb 2024 10:37:11 +0100 Subject: [PATCH 20/37] [scala] Cleanup InternalApi methods Refs #4348 --- docs/pages/release_notes.md | 3 +++ .../sourceforge/pmd/cpd/ScalaTokenizer.java | 4 +-- .../pmd/lang/scala/ScalaLanguageModule.java | 18 ------------- .../pmd/lang/scala/ast/ScalaParser.java | 4 +-- .../pmd/lang/scala/internal/ScalaDialect.java | 26 +++++++++++++++++++ 5 files changed, 33 insertions(+), 22 deletions(-) create mode 100644 pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/lang/scala/internal/ScalaDialect.java diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 61a8a06c5f..79c096e2b8 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -211,6 +211,9 @@ package or made (package) private and are not accessible anymore. * {%jdoc modelica::resolver.internal.Watchdog %} (note: not previously marked as internal api) * pmd-plsql * {%jdoc plsql::rule.design.AbstractNcssCountRule (now package private) +* pmd-scala + * {%jdoc scala::ScalaLanguageModule %} + * The method `dialectOf(LanguageVersion)` has been removed **Newly internal classes, interfaces and methods** diff --git a/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/cpd/ScalaTokenizer.java b/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/cpd/ScalaTokenizer.java index d2be64ec60..15f183107f 100644 --- a/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/cpd/ScalaTokenizer.java +++ b/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/cpd/ScalaTokenizer.java @@ -11,7 +11,7 @@ import net.sourceforge.pmd.lang.LanguagePropertyBundle; import net.sourceforge.pmd.lang.LanguageVersion; import net.sourceforge.pmd.lang.TokenManager; import net.sourceforge.pmd.lang.document.TextDocument; -import net.sourceforge.pmd.lang.scala.ScalaLanguageModule; +import net.sourceforge.pmd.lang.scala.internal.ScalaDialect; import scala.collection.Iterator; import scala.meta.Dialect; @@ -33,7 +33,7 @@ public class ScalaTokenizer implements Tokenizer { */ public ScalaTokenizer(LanguagePropertyBundle bundle) { LanguageVersion langVer = bundle.getLanguageVersion(); - dialect = ScalaLanguageModule.dialectOf(langVer); + dialect = ScalaDialect.dialectOf(langVer); } @Override diff --git a/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/lang/scala/ScalaLanguageModule.java b/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/lang/scala/ScalaLanguageModule.java index 0488df2644..2bbd79daf5 100644 --- a/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/lang/scala/ScalaLanguageModule.java +++ b/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/lang/scala/ScalaLanguageModule.java @@ -4,18 +4,12 @@ package net.sourceforge.pmd.lang.scala; -import org.checkerframework.checker.nullness.qual.NonNull; - -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.cpd.ScalaTokenizer; import net.sourceforge.pmd.cpd.Tokenizer; import net.sourceforge.pmd.lang.LanguagePropertyBundle; import net.sourceforge.pmd.lang.LanguageRegistry; -import net.sourceforge.pmd.lang.LanguageVersion; import net.sourceforge.pmd.lang.impl.SimpleLanguageModuleBase; -import scala.meta.Dialect; - /** * Language Module for Scala. */ @@ -39,18 +33,6 @@ public class ScalaLanguageModule extends SimpleLanguageModuleBase { return (ScalaLanguageModule) LanguageRegistry.PMD.getLanguageById(ID); } - @InternalApi - public static @NonNull Dialect dialectOf(LanguageVersion v) { - switch (v.getVersion()) { - case "2.10": return scala.meta.dialects.package$.MODULE$.Scala210(); - case "2.11": return scala.meta.dialects.package$.MODULE$.Scala211(); - case "2.12": return scala.meta.dialects.package$.MODULE$.Scala212(); - case "2.13": return scala.meta.dialects.package$.MODULE$.Scala213(); - default: - throw new IllegalArgumentException(v.getVersion()); - } - } - @Override public Tokenizer createCpdTokenizer(LanguagePropertyBundle bundle) { return new ScalaTokenizer(bundle); diff --git a/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/lang/scala/ast/ScalaParser.java b/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/lang/scala/ast/ScalaParser.java index e4aa37fdf2..d309b34dae 100644 --- a/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/lang/scala/ast/ScalaParser.java +++ b/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/lang/scala/ast/ScalaParser.java @@ -6,7 +6,7 @@ package net.sourceforge.pmd.lang.scala.ast; import net.sourceforge.pmd.lang.ast.ParseException; import net.sourceforge.pmd.lang.ast.Parser; -import net.sourceforge.pmd.lang.scala.ScalaLanguageModule; +import net.sourceforge.pmd.lang.scala.internal.ScalaDialect; import scala.meta.Dialect; import scala.meta.Source; @@ -23,7 +23,7 @@ public final class ScalaParser implements Parser { @Override public ASTSource parse(ParserTask task) throws ParseException { Input.VirtualFile virtualFile = new Input.VirtualFile(task.getFileId().getAbsolutePath(), task.getSourceText()); - Dialect dialect = ScalaLanguageModule.dialectOf(task.getLanguageVersion()); + Dialect dialect = ScalaDialect.dialectOf(task.getLanguageVersion()); Source src = new ScalametaParser(virtualFile, dialect).parseSource(); ASTSource root = (ASTSource) new ScalaTreeBuilder().build(src); root.addTaskInfo(task); diff --git a/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/lang/scala/internal/ScalaDialect.java b/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/lang/scala/internal/ScalaDialect.java new file mode 100644 index 0000000000..dbb126824b --- /dev/null +++ b/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/lang/scala/internal/ScalaDialect.java @@ -0,0 +1,26 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.scala.internal; + +import org.checkerframework.checker.nullness.qual.NonNull; + +import net.sourceforge.pmd.lang.LanguageVersion; + +import scala.meta.Dialect; + +public final class ScalaDialect { + private ScalaDialect() {} + + public static @NonNull Dialect dialectOf(LanguageVersion v) { + switch (v.getVersion()) { + case "2.10": return scala.meta.dialects.package$.MODULE$.Scala210(); + case "2.11": return scala.meta.dialects.package$.MODULE$.Scala211(); + case "2.12": return scala.meta.dialects.package$.MODULE$.Scala212(); + case "2.13": return scala.meta.dialects.package$.MODULE$.Scala213(); + default: + throw new IllegalArgumentException(v.getVersion()); + } + } +} From 5e9ba1468136593ad6d52c2506e4c2a64d908fae Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 1 Feb 2024 10:39:18 +0100 Subject: [PATCH 21/37] [visualforce] Cleanup InternalApi methods Refs #4348 --- .../vf/ast/{VfAstInternals.java => InternalApiBridge.java} | 4 ++-- .../java/net/sourceforge/pmd/lang/vf/ast/OpenTagRegister.java | 3 --- .../sourceforge/pmd/lang/vf/ast/VfExpressionTypeVisitor.java | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) rename pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/{VfAstInternals.java => InternalApiBridge.java} (86%) diff --git a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/VfAstInternals.java b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/InternalApiBridge.java similarity index 86% rename from pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/VfAstInternals.java rename to pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/InternalApiBridge.java index e45aae08a2..5c43ff9dba 100644 --- a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/VfAstInternals.java +++ b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/InternalApiBridge.java @@ -11,9 +11,9 @@ import net.sourceforge.pmd.lang.vf.DataType; * This is internal API, and can be changed at any time. */ @InternalApi -public final class VfAstInternals { +public final class InternalApiBridge { - private VfAstInternals() { + private InternalApiBridge() { // utility class } diff --git a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/OpenTagRegister.java b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/OpenTagRegister.java index ece54ac717..efc1c33bd7 100644 --- a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/OpenTagRegister.java +++ b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/OpenTagRegister.java @@ -9,8 +9,6 @@ import java.util.List; import org.apache.commons.lang3.StringUtils; -import net.sourceforge.pmd.annotation.InternalApi; - /** * Utility class to keep track of unclosed tags. The mechanism is rather simple. * If a end tag (</x>) is encountered, it will iterate through the open @@ -21,7 +19,6 @@ import net.sourceforge.pmd.annotation.InternalApi; * @author Victor Bucutea * */ -@InternalApi class OpenTagRegister { private List tagList = new ArrayList<>(); diff --git a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/VfExpressionTypeVisitor.java b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/VfExpressionTypeVisitor.java index e4f4dc7573..0177ebce33 100644 --- a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/VfExpressionTypeVisitor.java +++ b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/VfExpressionTypeVisitor.java @@ -145,7 +145,7 @@ class VfExpressionTypeVisitor extends VfVisitorBase { } if (type != null) { - VfAstInternals.setDataType(entry.getKey(), type); + InternalApiBridge.setDataType(entry.getKey(), type); } else { LOG.debug("Unable to determine type for: {}", name); } From 4978e66500bc52a640f3cb306b980f68a38d4840 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 1 Feb 2024 10:47:15 +0100 Subject: [PATCH 22/37] Fix javadoc generation - exclude also sub-packages of internal --- pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c991979b5c..f83177dcd8 100644 --- a/pom.xml +++ b/pom.xml @@ -341,7 +341,8 @@ true none - *.internal + + *.internal,*.internal.*,*.internal.*.* false From d2ae17a47469535dad82250ba86dc1f92cf8e2f8 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 1 Feb 2024 10:54:45 +0100 Subject: [PATCH 23/37] [doc] Mark ADR 3 accepted Refs #4756 --- docs/pages/pmd/projectdocs/decisions/adr-1.md | 2 +- docs/pages/pmd/projectdocs/decisions/adr-2.md | 2 +- docs/pages/pmd/projectdocs/decisions/adr-3.md | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/pages/pmd/projectdocs/decisions/adr-1.md b/docs/pages/pmd/projectdocs/decisions/adr-1.md index 94b624e42c..9daf3643de 100644 --- a/docs/pages/pmd/projectdocs/decisions/adr-1.md +++ b/docs/pages/pmd/projectdocs/decisions/adr-1.md @@ -63,7 +63,7 @@ However, this also adds additional tasks, and it takes time to write down and do ## Change History -2022-09-30: Status changed to "Accepted". +2022-09-30: Status changed to "Accepted". ([#4072](https://github.com/pmd/pmd/pull/4072)) 2022-09-06: Added section "Change History" to the template. Added "Last updated" to "Status" section. diff --git a/docs/pages/pmd/projectdocs/decisions/adr-2.md b/docs/pages/pmd/projectdocs/decisions/adr-2.md index 2af164fde2..1e5edf6689 100644 --- a/docs/pages/pmd/projectdocs/decisions/adr-2.md +++ b/docs/pages/pmd/projectdocs/decisions/adr-2.md @@ -66,6 +66,6 @@ Maintaining a polyglot code base with multiple languages is likely to be more ch ## Change History -2022-09-30: Changed status to "Accepted". +2022-09-30: Changed status to "Accepted". ([#4072](https://github.com/pmd/pmd/pull/4072)) 2022-07-28: Proposed initial version. diff --git a/docs/pages/pmd/projectdocs/decisions/adr-3.md b/docs/pages/pmd/projectdocs/decisions/adr-3.md index 99edafd621..70d08d5651 100644 --- a/docs/pages/pmd/projectdocs/decisions/adr-3.md +++ b/docs/pages/pmd/projectdocs/decisions/adr-3.md @@ -5,8 +5,8 @@ permalink: pmd_projectdocs_decisions_adr_3.html sidebaractiveurl: /pmd_projectdocs_decisions.html adr: true # Proposed / Accepted / Deprecated / Superseded -adr_status: "Proposed" -last_updated: December 2023 +adr_status: "Accepted" +last_updated: February 2024 --- @@ -184,4 +184,6 @@ Non-concrete AST classes (like base classes or common interfaces) should follow ## Change History +2024-02-01: Changed status to "Accepted". ([#4756](https://github.com/pmd/pmd/pull/4756)) + 2023-12-01: Proposed initial version. From 7c34085b17e7ba548d57a6f223af6af9f30d5aa2 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 1 Feb 2024 11:32:44 +0100 Subject: [PATCH 24/37] [doc] Fix javadoc links in release notes --- docs/pages/release_notes.md | 105 +++++++++++++++++++----------------- 1 file changed, 57 insertions(+), 48 deletions(-) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 79c096e2b8..5750813165 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -157,63 +157,72 @@ in the Migration Guide. **Internalized classes and interfaces and methods** The following classes/methods have been marked as @InternalApi before and are now moved into a `internal` -package or made (package) private and are not accessible anymore. +package or made (package) private and are _not accessible_ anymore. * pmd-core - * {%jdoc core::cache.internal.AbstractAnalysisCache %} (now package private) - * {%jdoc core::cache.internal.AnalysisCache %} - * {%jdoc core::cache.internal.AnalysisCacheListener %} - * {%jdoc core::cache.internal.AnalysisResult %} - * {%jdoc core::cache.internal.CachedRuleMapper %} (now package private) - * {%jdoc core::cache.internal.CachedRuleViolation %} (now package private) - * {%jdoc core::cache.internal.ChecksumAware %} - * {%jdoc core::cache.internal.FileAnalysisCache %} - * {%jdoc core::cache.internal.NoopAnalysisCache %} - * {%jdoc core::util.internal.ResourceLoader %} - * {%jdoc !!core::cpd.Tokens#Tokens() %} (the constructor is now package private) - * {%jdoc core::lang.rule.RuleTargetSelector %} - method `isRuleChain()` has been removed. It was internal API before. - * {%jdoc !!core::renderers.AbstractAccumulatingRenderer#renderFileReport(Report) %} - this method is now final - and can't be overridden anymore. - * {%jdoc core::Report %} - the constructor as well as the methods `addRuleViolation`, `addConfigError`, `addError` - are now private and cannot be accessed anymore. - * {%jdoc core::RuleContext %} - * Method `getRule()` is now package private - * Method `create(FileAnalysisListener listener, Rule rule)` is removed + * `net.sourceforge.pmd.cache.AbstractAnalysisCache` (moved to internal, now package private) + * `net.sourceforge.pmd.cache.AnalysisCache` (moved to internal) + * `net.sourceforge.pmd.cache.AnalysisCacheListener` (moved to internal) + * `net.sourceforge.pmd.cache.AnalysisResult` (moved to internal) + * `net.sourceforge.pmd.cache.CachedRuleMapper` (moved to internal, now package private) + * `net.sourceforge.pmd.cache.CachedRuleViolation` (moved to internal, now package private) + * `net.sourceforge.pmd.cache.ChecksumAware` (moved to internal) + * `net.sourceforge.pmd.cache.FileAnalysisCache` (moved to internal) + * `net.sourceforge.pmd.cache.NoopAnalysisCache` (moved to internal) + * `net.sourceforge.pmd.util.ResourceLoader` (moved to internal) + * {%jdoc !!core::cpd.Tokens %} + * Constructor is now package private. + * {%jdoc !!core::lang.rule.RuleTargetSelector %} + * Method `isRuleChain()` has been removed. + * {%jdoc !!core::renderers.AbstractAccumulatingRenderer %} + * {%jdoc core::renderers.AbstractAccumulatingRenderer#renderFileReport(core::Report) %} - this method is now final + and can't be overridden anymore. + * {%jdoc !!core::Report %} + * Constructor as well as the methods `addRuleViolation`, `addConfigError`, `addError` are now private. + * {%jdoc !!core::RuleContext %} + * Method `getRule()` is now package private. + * Method `create(FileAnalysisListener listener, Rule rule)` has been removed. * pmd-ant - * {%jdoc ant::ant.Formatter %} - * The method `getRenderer()` has been removed. - * The method `start(String)` is private now and not accessible anymore. - * The method `end(Report)` has been removed. - * The method `isNoOutputSupplied()` is now package private and 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. + * {%jdoc !!ant::ant.Formatter %} + * Method `getRenderer()` has been removed. + * Method `start(String)` is private now. + * Method `end(Report)` has been removed. + * Method `isNoOutputSupplied()` is now package private. + * Method `newListener(Project)` is now package private. + * {%jdoc !!ant::ant.PMDTask %} + * 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) + * {%jdoc !!apex::ast.ApexNode %} + * Method `getNode()` has been removed. It was only deprecated before and not marked with @InternalApi. + However, it gave access to the wrapped Jorje node and was thus internal API. + * {%jdoc !!apex::ast.AbstractApexNode %} + * Method `getNode()` is now package private. + * {%jdoc !!apex::multifile.ApexMultifileAnalysis %} + * Constructor is now package private. + * `net.sourceforge.pmd.lang.apex.rule.design.AbstractNcssCountRule` (now package private) + * `net.sourceforge.pmd.lang.apex.rule.AbstractApexUnitTestRule` (moved to package `net.sourceforge.pmd.apex.rule.bestpractices`, now package private) * pmd-java - * {%jdoc java::rule.internal.AbstractIgnoredAnnotationRule %} - * {%jdoc java::types.ast.internal.LazyTypeResolver %} - * {%jdoc java::types.JMethodSig#internalApi() %} has been removed. - * {%jdoc java::types.TypeOps#isSameTypeInInference(java::types.JTypeMirror,java::types.JTypeMirror) %} (now package private) + * `net.sourceforge.pmd.lang.java.rule.AbstractIgnoredAnnotationRule` (moved to internal) + * `net.sourceforge.pmd.lang.java.types.ast.LazyTypeResolver` (moved to internal) + * {%jdoc !!java::types.JMethodSig %} + * Method `internalApi()` has been removed. + * {%jdoc !!java::types.TypeOps %} + * Method `isSameTypeInInference(JTypeMirror,JTypeMirror)` is now package private. * pmd-jsp - * {%jdoc jsp::ast.JspParser#getTokenBehavior() %} has been removed. + * {%jdoc !!jsp::ast.JspParser %} + * Method `getTokenBehavior()` has been removed. * pmd-modelica - * {%jdoc modelica::ast.InternalApiBridge %} renamed from InternalModelicaNodeApi. - * {%jdoc modelica::resolver.InternalApiBridge %} renamed from InternalModelicaResolverApi. - * {%jdoc modelica::resolver.ModelicaSymbolFacade %} has been removed. - * {%jdoc modelica::resolver.internal.ResolutionContext %} - * {%jdoc modelica::resolver.internal.ResolutionState %} (note: not previously marked as internal api) - * {%jdoc modelica::resolver.internal.Watchdog %} (note: not previously marked as internal api) + * {%jdoc !!modelica::ast.InternalApiBridge %} renamed from `InternalModelicaNodeApi`. + * {%jdoc !!modelica::resolver.InternalApiBridge %} renamed from `InternalModelicaResolverApi`. + * `net.sourceforge.pmd.lang.modelica.resolver.ModelicaSymbolFacade` has been removed. + * `net.sourceforge.pmd.lang.modelica.resolver.ResolutionContext` (moved to internal) + * `net.sourceforge.pmd.lang.modelica.resolver.ResolutionState` (moved to internal). Note: it was not previously marked with @InternalApi. + * `net.sourceforge.pmd.lang.modelica.resolver.Watchdog` (moved to internal). Note: it was not previously marked with @InternalApi. * pmd-plsql - * {%jdoc plsql::rule.design.AbstractNcssCountRule (now package private) + * `net.sourceforge.pmd.lang.plsql.rule.design.AbstractNcssCountRule` is now package private. * pmd-scala - * {%jdoc scala::ScalaLanguageModule %} - * The method `dialectOf(LanguageVersion)` has been removed + * {%jdoc !!scala::ScalaLanguageModule %} + * Method `dialectOf(LanguageVersion)` has been removed. **Newly internal classes, interfaces and methods** From 83879dc420103585397bd08e830e1571d6019878 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 1 Feb 2024 11:39:33 +0100 Subject: [PATCH 25/37] [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 From fae522a002497b598d288cfceb66e28bf0d88632 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 1 Feb 2024 12:09:12 +0100 Subject: [PATCH 26/37] [core] Unify javadoc for InternalApiBridge classes Refs #4348 --- .../sourceforge/pmd/ant/InternalApiBridge.java | 12 ++++++++---- .../lang/apex/multifile/InternalApiBridge.java | 12 +++++++++--- .../net/sourceforge/pmd/InternalApiBridge.java | 12 ++++++++---- .../sourceforge/pmd/lang/InternalApiBridge.java | 8 ++++++++ .../pmd/lang/java/ast/InternalApiBridge.java | 11 +++++------ .../pmd/lang/java/types/InternalApiBridge.java | 12 +++++++++--- .../lang/java/types/ast/InternalApiBridge.java | 12 +++++++++--- .../pmd/lang/jsp/ast/InternalApiBridge.java | 12 +++++++++--- .../lang/modelica/ast/InternalApiBridge.java | 11 +++++++++++ .../modelica/resolver/InternalApiBridge.java | 11 +++++++++++ .../pmd/lang/plsql/ast/InternalApiBridge.java | 17 ++++++++++------- .../pmd/lang/vf/ast/InternalApiBridge.java | 15 ++++++++++----- 12 files changed, 107 insertions(+), 38 deletions(-) diff --git a/pmd-ant/src/main/java/net/sourceforge/pmd/ant/InternalApiBridge.java b/pmd-ant/src/main/java/net/sourceforge/pmd/ant/InternalApiBridge.java index 0aa1b05065..604e9c3997 100644 --- a/pmd-ant/src/main/java/net/sourceforge/pmd/ant/InternalApiBridge.java +++ b/pmd-ant/src/main/java/net/sourceforge/pmd/ant/InternalApiBridge.java @@ -12,15 +12,19 @@ import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.reporting.GlobalAnalysisListener; /** - * Gives access to package private methods. + * Internal API. + * + *

Acts as a bridge between outer parts of PMD and the restricted access + * internal API of this package. + * + *

None of this is published API, and compatibility can be broken anytime! + * Use this only at your own risk. * * @apiNote Internal API */ @InternalApi public final class InternalApiBridge { - private InternalApiBridge() { - // utility class - } + private InternalApiBridge() {} public static GlobalAnalysisListener newListener(Formatter formatter, Project project) throws IOException { return formatter.newListener(project); 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 index 3a3d2643af..beba36c4f7 100644 --- 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 @@ -8,13 +8,19 @@ import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.apex.ApexLanguageProperties; /** + * Internal API. + * + *

Acts as a bridge between outer parts of PMD and the restricted access + * internal API of this package. + * + *

None of this is published API, and compatibility can be broken anytime! + * Use this only at your own risk. + * * @apiNote Internal API */ @InternalApi public final class InternalApiBridge { - private InternalApiBridge() { - // utility class - } + private InternalApiBridge() {} public static ApexMultifileAnalysis createApexMultiFileAnalysis(ApexLanguageProperties properties) { return new ApexMultifileAnalysis(properties); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/InternalApiBridge.java b/pmd-core/src/main/java/net/sourceforge/pmd/InternalApiBridge.java index 118664ccc4..60be0d4447 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/InternalApiBridge.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/InternalApiBridge.java @@ -8,15 +8,19 @@ import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.reporting.FileAnalysisListener; /** - * Makes package private methods available for other packages. This is only internal. + * Internal API. + * + *

Acts as a bridge between outer parts of PMD and the restricted access + * internal API of this package. + * + *

None of this is published API, and compatibility can be broken anytime! + * Use this only at your own risk. * * @apiNote Internal API */ @InternalApi public final class InternalApiBridge { - private InternalApiBridge() { - // utility class - } + private InternalApiBridge() {} public static Rule getRule(RuleContext ruleContext) { return ruleContext.getRule(); 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 index fe139d6d9e..7a7618e264 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/InternalApiBridge.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/InternalApiBridge.java @@ -15,6 +15,14 @@ import net.sourceforge.pmd.util.log.PmdReporter; /** * Internal API. + * + *

Acts as a bridge between outer parts of PMD and the restricted access + * internal API of this package. + * + *

None of this is published API, and compatibility can be broken anytime! + * Use this only at your own risk. + * + * @apiNote Internal API */ @InternalApi public final class InternalApiBridge { diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/InternalApiBridge.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/InternalApiBridge.java index f1558ae801..f4bd52c36b 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/InternalApiBridge.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/InternalApiBridge.java @@ -35,7 +35,9 @@ import net.sourceforge.pmd.lang.java.types.internal.infer.TypeInferenceLogger; import net.sourceforge.pmd.util.AssertionUtil; /** - * Acts as a bridge between outer parts of PMD and the restricted access + * Internal API. + * + *

Acts as a bridge between outer parts of PMD and the restricted access * internal API of this package. * *

None of this is published API, and compatibility can be broken anytime! @@ -43,14 +45,11 @@ import net.sourceforge.pmd.util.AssertionUtil; * * @author Clément Fournier * @since 7.0.0 + * @apiNote Internal API */ @InternalApi public final class InternalApiBridge { - - - private InternalApiBridge() { - - } + private InternalApiBridge() {} @Deprecated public static ASTVariableId newVarId(String image) { diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/InternalApiBridge.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/InternalApiBridge.java index e7bd326423..c5c19bcf50 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/InternalApiBridge.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/InternalApiBridge.java @@ -7,13 +7,19 @@ package net.sourceforge.pmd.lang.java.types; import net.sourceforge.pmd.annotation.InternalApi; /** + * Internal API. + * + *

Acts as a bridge between outer parts of PMD and the restricted access + * internal API of this package. + * + *

None of this is published API, and compatibility can be broken anytime! + * Use this only at your own risk. + * * @apiNote Internal API */ @InternalApi public final class InternalApiBridge { - private InternalApiBridge() { - // internal api - } + private InternalApiBridge() {} public static boolean isSameTypeInInference(JTypeMirror t, JTypeMirror s) { return TypeOps.isSameTypeInInference(t, s); diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/InternalApiBridge.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/InternalApiBridge.java index 201fb2ee05..5b28467a0e 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/InternalApiBridge.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/InternalApiBridge.java @@ -14,13 +14,19 @@ import net.sourceforge.pmd.lang.java.types.ast.internal.RegularCtx; import net.sourceforge.pmd.util.AssertionUtil; /** + * Internal API. + * + *

Acts as a bridge between outer parts of PMD and the restricted access + * internal API of this package. + * + *

None of this is published API, and compatibility can be broken anytime! + * Use this only at your own risk. + * * @apiNote Internal API */ @InternalApi public final class InternalApiBridge { - private InternalApiBridge() { - // utility - } + private InternalApiBridge() {} public static boolean canGiveContextToPoly(ExprContext exprContext, boolean lambdaOrMethodRef) { return exprContext.canGiveContextToPoly(lambdaOrMethodRef); diff --git a/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/ast/InternalApiBridge.java b/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/ast/InternalApiBridge.java index abd8e3db3a..ec6966ef08 100644 --- a/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/ast/InternalApiBridge.java +++ b/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/ast/InternalApiBridge.java @@ -8,13 +8,19 @@ import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccTokenDocument; /** + * Internal API. + * + *

Acts as a bridge between outer parts of PMD and the restricted access + * internal API of this package. + * + *

None of this is published API, and compatibility can be broken anytime! + * Use this only at your own risk. + * * @apiNote Internal API */ @InternalApi public final class InternalApiBridge { - private InternalApiBridge() { - // internal - } + private InternalApiBridge() {} public static JavaccTokenDocument.TokenDocumentBehavior getJspTokenBehavior() { return JspParser.TOKEN_BEHAVIOR; diff --git a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/InternalApiBridge.java b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/InternalApiBridge.java index a7b5aa41b5..475f5d046c 100644 --- a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/InternalApiBridge.java +++ b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/ast/InternalApiBridge.java @@ -10,6 +10,17 @@ import net.sourceforge.pmd.lang.modelica.resolver.ModelicaScope; import net.sourceforge.pmd.lang.modelica.resolver.internal.ResolutionContext; import net.sourceforge.pmd.lang.modelica.resolver.internal.Watchdog; +/** + * Internal API. + * + *

Acts as a bridge between outer parts of PMD and the restricted access + * internal API of this package. + * + *

None of this is published API, and compatibility can be broken anytime! + * Use this only at your own risk. + * + * @apiNote Internal API + */ @InternalApi public final class InternalApiBridge { private InternalApiBridge() {} diff --git a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/InternalApiBridge.java b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/InternalApiBridge.java index 5bf71e8346..0ae2528490 100644 --- a/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/InternalApiBridge.java +++ b/pmd-modelica/src/main/java/net/sourceforge/pmd/lang/modelica/resolver/InternalApiBridge.java @@ -11,6 +11,17 @@ import net.sourceforge.pmd.lang.modelica.ast.Visibility; import net.sourceforge.pmd.lang.modelica.resolver.internal.ResolutionContext; import net.sourceforge.pmd.lang.modelica.resolver.internal.Watchdog; +/** + * Internal API. + * + *

Acts as a bridge between outer parts of PMD and the restricted access + * internal API of this package. + * + *

None of this is published API, and compatibility can be broken anytime! + * Use this only at your own risk. + * + * @apiNote Internal API + */ @InternalApi public final class InternalApiBridge { private InternalApiBridge() {} diff --git a/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/ast/InternalApiBridge.java b/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/ast/InternalApiBridge.java index c9ef5160b7..bb63f354e4 100644 --- a/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/ast/InternalApiBridge.java +++ b/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/ast/InternalApiBridge.java @@ -10,17 +10,20 @@ import net.sourceforge.pmd.lang.symboltable.NameDeclaration; import net.sourceforge.pmd.lang.symboltable.Scope; /** - * Acts as a bridge between outer parts (e.g. symbol table) and the restricted - * access internal API of this package. - * - * @apiNote This is internal API. + * Internal API. + * + *

Acts as a bridge between outer parts of PMD and the restricted access + * internal API of this package. + * + *

None of this is published API, and compatibility can be broken anytime! + * Use this only at your own risk. + * + * @apiNote Internal API */ @InternalApi public final class InternalApiBridge { - private InternalApiBridge() { - - } + private InternalApiBridge() {} public static void setScope(PLSQLNode node, Scope decl) { ((AbstractPLSQLNode) node).setScope(decl); diff --git a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/InternalApiBridge.java b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/InternalApiBridge.java index 5c43ff9dba..4f14298af3 100644 --- a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/InternalApiBridge.java +++ b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/InternalApiBridge.java @@ -8,14 +8,19 @@ import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.vf.DataType; /** - * This is internal API, and can be changed at any time. + * Internal API. + * + *

Acts as a bridge between outer parts of PMD and the restricted access + * internal API of this package. + * + *

None of this is published API, and compatibility can be broken anytime! + * Use this only at your own risk. + * + * @apiNote Internal API */ @InternalApi public final class InternalApiBridge { - - private InternalApiBridge() { - // utility class - } + private InternalApiBridge() {} public static void setDataType(VfTypedNode node, DataType dataType) { ((AbstractVFDataNode) node).setDataType(dataType); From 7cd94ebb7df74a3f358361898f42ea09bfdac8ae Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 1 Feb 2024 12:17:06 +0100 Subject: [PATCH 27/37] [core] Cleanup javadoc regarding InternalApi Refs #4348 --- .../java/net/sourceforge/pmd/annotation/InternalApi.java | 5 ----- .../net/sourceforge/pmd/lang/java/ast/package-info.java | 7 +++---- .../pmd/lang/java/types/ast/internal/LazyTypeResolver.java | 2 -- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/annotation/InternalApi.java b/pmd-core/src/main/java/net/sourceforge/pmd/annotation/InternalApi.java index d66749a932..c74c3bd421 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/annotation/InternalApi.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/annotation/InternalApi.java @@ -14,13 +14,8 @@ import java.lang.annotation.Documented; *

Such members may be removed, renamed, moved, or otherwise broken at any time and should not be * relied upon outside the main PMD codebase. * - *

Members and types tagged with this annotation will remain - * supported until 7.0.0, after which some will be moved to internal - * packages, or will see their visibility reduced. - * * @since 6.7.0 */ -// NOTE: use @Deprecated with this annotation to raise a compiler warning until 7.0.0 @Documented public @interface InternalApi { } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/package-info.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/package-info.java index 65135ee393..406b6fdfe0 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/package-info.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/package-info.java @@ -7,11 +7,10 @@ * *

Note: from 6.16.0 on, the following usages have been deprecated: *

    - *
  • Manual instantiation of nodes. Constructors of node classes are - * deprecated and marked {@link net.sourceforge.pmd.annotation.InternalApi}. + *
  • Manual instantiation of nodes. * Nodes should only be obtained from the parser, which for rules, * means that never need to instantiate node themselves. Those - * constructors will be made package private with 7.0.0. + * constructors have been made package private with 7.0.0. *
  • Subclassing of base node classes, or usage of their type. * Version 7.0.0 will bring a new set of abstractions that will * be public API, but the base classes are and will stay internal. @@ -21,7 +20,7 @@ * interfaces in this package, to refer to nodes generically. *
  • *
  • Setters found in any node class or interface. Rules should consider - * the AST immutable. We will make those setters package private + * the AST immutable. Those setters have been made package private * with 7.0.0. *
  • *
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/internal/LazyTypeResolver.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/internal/LazyTypeResolver.java index ede18f4b91..44e30ad624 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/internal/LazyTypeResolver.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/internal/LazyTypeResolver.java @@ -14,7 +14,6 @@ import static net.sourceforge.pmd.util.CollectionUtil.listOf; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.ast.SemanticErrorReporter; import net.sourceforge.pmd.lang.java.ast.ASTAmbiguousName; import net.sourceforge.pmd.lang.java.ast.ASTAnnotation; @@ -93,7 +92,6 @@ import net.sourceforge.pmd.lang.java.types.internal.infer.TypeInferenceLogger; * Resolves types of expressions. This is used as the implementation of * {@link TypeNode#getTypeMirror(TypingContext)} and is INTERNAL. */ -@InternalApi public final class LazyTypeResolver extends JavaVisitorBase { private final TypeSystem ts; From 7ca993429ae7f97325ac8e52e9ade7f33d1fc7d1 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 1 Feb 2024 12:17:49 +0100 Subject: [PATCH 28/37] [doc] Update release notes Fixes #4348 --- 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 ee893f27f6..807c351f3b 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -105,6 +105,7 @@ in the Migration Guide. * [#4723](https://github.com/pmd/pmd/issues/4723): \[cli] Launch fails for "bash pmd" * core * [#1027](https://github.com/pmd/pmd/issues/1027): \[core] Apply the new PropertyDescriptor<Pattern> type where applicable + * [#4348](https://github.com/pmd/pmd/issues/4348): \[core] Consolidate @InternalApi classes * [#4674](https://github.com/pmd/pmd/issues/4674): \[core] WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass * [#4694](https://github.com/pmd/pmd/pull/4694): \[core] Fix line/col numbers in TokenMgrError * [#4717](https://github.com/pmd/pmd/issues/4717): \[core] XSLTRenderer doesn't close report file @@ -684,6 +685,7 @@ See also [Detailed Release Notes for PMD 7]({{ baseurl }}pmd_release_notes_pmd7. * [#4301](https://github.com/pmd/pmd/issues/4301): \[core] Remove deprecated property concrete classes * [#4302](https://github.com/pmd/pmd/issues/4302): \[core] Migrate Property Framework API to Java 8 * [#4323](https://github.com/pmd/pmd/issues/4323): \[core] Refactor CPD integration + * [#4348](https://github.com/pmd/pmd/issues/4348): \[core] Consolidate @InternalApi classes * [#4353](https://github.com/pmd/pmd/pull/4353): \[core] Micro optimizations for Node API * [#4365](https://github.com/pmd/pmd/pull/4365): \[core] Improve benchmarking * [#4397](https://github.com/pmd/pmd/pull/4397): \[core] Refactor CPD From 72edaee08a9be64aa6ae2a881d909dafe6ca2a97 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 9 Feb 2024 21:58:49 +0100 Subject: [PATCH 29/37] [core] Internalize ParametricRuleViolation --- docs/pages/release_notes.md | 3 ++- .../pmd/reporting/InternalApiBridge.java | 7 +++++ .../reporting/ParametricRuleViolation.java | 25 +++--------------- .../net/sourceforge/pmd/AbstractRuleTest.java | 26 ++++++++++--------- .../cache/internal/FileAnalysisCacheTest.java | 6 +++-- .../pmd/renderers/AbstractRendererTest.java | 8 ++++-- .../renderers/CodeClimateRendererTest.java | 3 +-- .../pmd/renderers/XMLRendererTest.java | 3 +-- .../pmd/renderers/XSLTRendererTest.java | 3 +-- .../pmd/renderers/YAHTMLRendererTest.java | 4 +-- .../sourceforge/pmd/reporting/ReportTest.java | 3 ++- 11 files changed, 44 insertions(+), 47 deletions(-) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index ce54c5e3a5..b0b392968a 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -265,7 +265,6 @@ in the migration guide for details. * {%jdoc core::reporting.RuleContext %} * {%jdoc core::reporting.RuleViolation %} * {%jdoc core::reporting.ViolationSuppressor %} - * {%jdoc core::reporting.ParametricRuleViolation %} (moved from `net.sourcceforge.pmd.lang.rule`) * {%jdoc core::lang.rule.xpath.XPathRule %} has been moved into subpackage {% jdoc_package core::lang.rule.xpath %}. **Internalized classes and interfaces and methods** @@ -305,6 +304,8 @@ package or made (package) private and are _not accessible_ anymore. * `net.sourceforge.pmd.RuleSetReference` * `net.sourceforge.pmd.RuleSetReferenceId` * `net.sourceforge.pmd.RuleSets` + * `net.sourceforge.pmd.lang.rule.ParametricRuleViolation` is now package private and moved to `net.sourceforge.pmd.reporting.ParametricRuleViolation`. + The only public API is {%jdoc core::reporting.RuleViolation %}. * pmd-ant * {%jdoc !!ant::ant.Formatter %} * Method `getRenderer()` has been removed. diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/reporting/InternalApiBridge.java b/pmd-core/src/main/java/net/sourceforge/pmd/reporting/InternalApiBridge.java index ff6bb2b7fb..6da2166b68 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/reporting/InternalApiBridge.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/reporting/InternalApiBridge.java @@ -4,7 +4,10 @@ package net.sourceforge.pmd.reporting; +import java.util.Map; + import net.sourceforge.pmd.annotation.InternalApi; +import net.sourceforge.pmd.lang.document.FileLocation; import net.sourceforge.pmd.lang.rule.Rule; /** @@ -34,4 +37,8 @@ public final class InternalApiBridge { public static RuleContext createRuleContext(FileAnalysisListener listener, Rule rule) { return new RuleContext(listener, rule); } + + public static ParametricRuleViolation createRuleViolation(Rule theRule, FileLocation location, String message, Map additionalInfo) { + return new ParametricRuleViolation(theRule, location, message, additionalInfo); + } } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/reporting/ParametricRuleViolation.java b/pmd-core/src/main/java/net/sourceforge/pmd/reporting/ParametricRuleViolation.java index 61ac4cf9f2..5ca33eeadb 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/reporting/ParametricRuleViolation.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/reporting/ParametricRuleViolation.java @@ -7,17 +7,14 @@ package net.sourceforge.pmd.reporting; import java.util.Collections; import java.util.Map; -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.document.FileLocation; import net.sourceforge.pmd.lang.rule.Rule; import net.sourceforge.pmd.util.AssertionUtil; /** - * @deprecated This is internal. Clients should exclusively use {@link RuleViolation}. + * @apiNote This is internal API. Clients should exclusively use {@link RuleViolation}. */ -@Deprecated -@InternalApi -public class ParametricRuleViolation implements RuleViolation { +class ParametricRuleViolation implements RuleViolation { protected final Rule rule; protected final String description; @@ -25,25 +22,11 @@ public class ParametricRuleViolation implements RuleViolation { private final Map additionalInfo; - // todo add factory methods on the interface and hide the class. - - /** - * @deprecated Update tests that use this not to call the ctor directly. - */ - @Deprecated - public ParametricRuleViolation(Rule theRule, Reportable node, String message) { + ParametricRuleViolation(Rule theRule, Reportable node, String message) { this(theRule, node.getReportLocation(), message, Collections.emptyMap()); } - public ParametricRuleViolation(Rule theRule, FileLocation location, String message) { - this(theRule, location, message, Collections.emptyMap()); - } - - public ParametricRuleViolation(Rule theRule, Reportable node, String message, Map additionalInfo) { - this(theRule, node.getReportLocation(), message, additionalInfo); - } - - public ParametricRuleViolation(Rule theRule, FileLocation location, String message, Map additionalInfo) { + ParametricRuleViolation(Rule theRule, FileLocation location, String message, Map additionalInfo) { this.rule = AssertionUtil.requireParamNotNull("rule", theRule); this.description = AssertionUtil.requireParamNotNull("message", message); this.location = location; diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/AbstractRuleTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/AbstractRuleTest.java index 3022599e2b..6d7f64ca81 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/AbstractRuleTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/AbstractRuleTest.java @@ -30,7 +30,6 @@ import net.sourceforge.pmd.properties.PropertyDescriptor; import net.sourceforge.pmd.properties.PropertyFactory; import net.sourceforge.pmd.reporting.FileAnalysisListener; import net.sourceforge.pmd.reporting.InternalApiBridge; -import net.sourceforge.pmd.reporting.ParametricRuleViolation; import net.sourceforge.pmd.reporting.RuleContext; import net.sourceforge.pmd.reporting.RuleViolation; @@ -86,23 +85,26 @@ class AbstractRuleTest { r.setRuleSetName("foo"); DummyRootNode s = helper.parse("abc()", FileId.fromPathLikeString("abc")); - RuleViolation rv = new ParametricRuleViolation(r, s, r.getMessage()); - assertEquals(1, rv.getBeginLine(), "Line number mismatch!"); - assertEquals("abc", rv.getFileId().getOriginalPath(), "Filename mismatch!"); - assertEquals(r, rv.getRule(), "Rule object mismatch!"); - assertEquals("my rule msg", rv.getDescription(), "Rule msg mismatch!"); - assertEquals("foo", rv.getRule().getRuleSetName(), "RuleSet name mismatch!"); + InternalApiBridge.createRuleContext((rv) -> { + assertEquals(1, rv.getBeginLine(), "Line number mismatch!"); + assertEquals("abc", rv.getFileId().getOriginalPath(), "Filename mismatch!"); + assertEquals(r, rv.getRule(), "Rule object mismatch!"); + assertEquals("my rule msg", rv.getDescription(), "Rule msg mismatch!"); + assertEquals("foo", rv.getRule().getRuleSetName(), "RuleSet name mismatch!"); + }, r).addViolation(s); } @Test void testCreateRV2() { MyRule r = new MyRule(); DummyRootNode s = helper.parse("abc()", FileId.fromPathLikeString("filename")); - RuleViolation rv = new ParametricRuleViolation(r, s, "specificdescription"); - assertEquals(1, rv.getBeginLine(), "Line number mismatch!"); - assertEquals("filename", rv.getFileId().getOriginalPath(), "Filename mismatch!"); - assertEquals(r, rv.getRule(), "Rule object mismatch!"); - assertEquals("specificdescription", rv.getDescription(), "Rule description mismatch!"); + + InternalApiBridge.createRuleContext((rv) -> { + assertEquals(1, rv.getBeginLine(), "Line number mismatch!"); + assertEquals("filename", rv.getFileId().getOriginalPath(), "Filename mismatch!"); + assertEquals(r, rv.getRule(), "Rule object mismatch!"); + assertEquals("specificdescription", rv.getDescription(), "Rule description mismatch!"); + }, r).addViolationWithMessage(s, "specificdescription"); } @Test diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/cache/internal/FileAnalysisCacheTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/cache/internal/FileAnalysisCacheTest.java index a29104586f..2f11170415 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/cache/internal/FileAnalysisCacheTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/cache/internal/FileAnalysisCacheTest.java @@ -47,7 +47,7 @@ import net.sourceforge.pmd.lang.document.TextRange2d; import net.sourceforge.pmd.lang.rule.Rule; import net.sourceforge.pmd.lang.rule.internal.RuleSets; import net.sourceforge.pmd.reporting.FileAnalysisListener; -import net.sourceforge.pmd.reporting.ParametricRuleViolation; +import net.sourceforge.pmd.reporting.InternalApiBridge; import net.sourceforge.pmd.reporting.RuleViolation; class FileAnalysisCacheTest { @@ -170,7 +170,9 @@ class FileAnalysisCacheTest { try (TextDocument doc0 = TextDocument.create(mockFile)) { cache.isUpToDate(doc0); try (FileAnalysisListener listener = cache.startFileAnalysis(doc0)) { - listener.onRuleViolation(new ParametricRuleViolation(rule, FileLocation.range(doc0.getFileId(), textLocation), "message")); + listener.onRuleViolation(InternalApiBridge.createRuleViolation(rule, + FileLocation.range(doc0.getFileId(), textLocation), "message", + Collections.emptyMap())); } } finally { cache.persist(); diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/renderers/AbstractRendererTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/renderers/AbstractRendererTest.java index c488b7e267..8911071160 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/renderers/AbstractRendererTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/renderers/AbstractRendererTest.java @@ -34,7 +34,7 @@ import net.sourceforge.pmd.lang.rule.Rule; import net.sourceforge.pmd.lang.rule.RulePriority; import net.sourceforge.pmd.reporting.FileAnalysisListener; import net.sourceforge.pmd.reporting.GlobalAnalysisListener; -import net.sourceforge.pmd.reporting.ParametricRuleViolation; +import net.sourceforge.pmd.reporting.InternalApiBridge; import net.sourceforge.pmd.reporting.Report; import net.sourceforge.pmd.reporting.Report.ConfigurationError; import net.sourceforge.pmd.reporting.Report.ProcessingError; @@ -107,7 +107,11 @@ abstract class AbstractRendererTest { protected RuleViolation newRuleViolation(int beginLine, int beginColumn, int endLine, int endColumn, Rule rule) { FileLocation loc = createLocation(beginLine, beginColumn, endLine, endColumn); - return new ParametricRuleViolation(rule, loc, "blah", Collections.emptyMap()); + return newRuleViolation(rule, loc, "blah"); + } + + protected RuleViolation newRuleViolation(Rule rule, FileLocation location, String message) { + return InternalApiBridge.createRuleViolation(rule, location, message, Collections.emptyMap()); } /** 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 bc3d7ab4bf..2370b1fc04 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 @@ -11,7 +11,6 @@ import org.junit.jupiter.api.Test; import net.sourceforge.pmd.lang.document.FileLocation; import net.sourceforge.pmd.lang.rule.xpath.XPathRule; import net.sourceforge.pmd.lang.rule.xpath.XPathVersion; -import net.sourceforge.pmd.reporting.ParametricRuleViolation; class CodeClimateRendererTest extends AbstractRendererTest { @@ -91,7 +90,7 @@ class CodeClimateRendererTest extends AbstractRendererTest { theRule.setDescription("Description with Unicode Character U+2013: – ."); theRule.setName("Foo"); - String rendered = renderReport(getRenderer(), it -> it.onRuleViolation(new ParametricRuleViolation(theRule, node, "blah"))); + String rendered = renderReport(getRenderer(), it -> it.onRuleViolation(newRuleViolation(theRule, node, "blah"))); // Output should be the exact same as for non xpath rules assertEquals(filter(getExpected()), filter(rendered)); diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/renderers/XMLRendererTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/renderers/XMLRendererTest.java index 126c72c8f1..a74589fbdf 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/renderers/XMLRendererTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/renderers/XMLRendererTest.java @@ -29,7 +29,6 @@ import net.sourceforge.pmd.internal.util.IOUtil; import net.sourceforge.pmd.lang.document.FileId; import net.sourceforge.pmd.lang.document.FileLocation; import net.sourceforge.pmd.lang.document.TextRange2d; -import net.sourceforge.pmd.reporting.ParametricRuleViolation; import net.sourceforge.pmd.reporting.Report; import net.sourceforge.pmd.reporting.Report.ConfigurationError; import net.sourceforge.pmd.reporting.Report.ProcessingError; @@ -94,7 +93,7 @@ class XMLRendererTest extends AbstractRendererTest { private RuleViolation createRuleViolation(String description) { FileLocation loc = FileLocation.range(FileId.fromPathLikeString(getSourceCodeFilename()), TextRange2d.range2d(1, 1, 1, 1)); - return new ParametricRuleViolation(new FooRule(), loc, description); + return newRuleViolation(new FooRule(), loc, description); } private void verifyXmlEscaping(Renderer renderer, String shouldContain, Charset charset) throws Exception { diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/renderers/XSLTRendererTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/renderers/XSLTRendererTest.java index c1499d542b..48ad1aac3d 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/renderers/XSLTRendererTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/renderers/XSLTRendererTest.java @@ -12,7 +12,6 @@ import net.sourceforge.pmd.FooRule; import net.sourceforge.pmd.lang.document.FileId; import net.sourceforge.pmd.lang.document.FileLocation; import net.sourceforge.pmd.lang.document.TextRange2d; -import net.sourceforge.pmd.reporting.ParametricRuleViolation; import net.sourceforge.pmd.reporting.Report; import net.sourceforge.pmd.reporting.RuleViolation; @@ -59,7 +58,7 @@ class XSLTRendererTest extends AbstractRendererTest { void testDefaultStylesheet() throws Exception { XSLTRenderer renderer = new XSLTRenderer(); FileLocation loc = FileLocation.range(FileId.UNKNOWN, TextRange2d.range2d(1, 1, 1, 2)); - RuleViolation rv = new ParametricRuleViolation(new FooRule(), loc, "violation message"); + RuleViolation rv = newRuleViolation(new FooRule(), loc, "violation message"); String result = renderReport(renderer, it -> it.onRuleViolation(rv)); assertTrue(result.contains("violation message")); } diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/renderers/YAHTMLRendererTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/renderers/YAHTMLRendererTest.java index c853555d6d..09c618807f 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/renderers/YAHTMLRendererTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/renderers/YAHTMLRendererTest.java @@ -23,7 +23,7 @@ import net.sourceforge.pmd.FooRule; import net.sourceforge.pmd.internal.util.IOUtil; import net.sourceforge.pmd.lang.document.FileLocation; import net.sourceforge.pmd.lang.rule.Rule; -import net.sourceforge.pmd.reporting.ParametricRuleViolation; +import net.sourceforge.pmd.reporting.InternalApiBridge; import net.sourceforge.pmd.reporting.Report.ConfigurationError; import net.sourceforge.pmd.reporting.Report.ProcessingError; import net.sourceforge.pmd.reporting.RuleViolation; @@ -46,7 +46,7 @@ class YAHTMLRendererTest extends AbstractRendererTest { FileLocation loc = createLocation(beginLine, beginColumn, endLine, endColumn); Map additionalInfo = CollectionUtil.mapOf(RuleViolation.PACKAGE_NAME, packageNameArg, RuleViolation.CLASS_NAME, classNameArg); - return new ParametricRuleViolation(new FooRule(), loc, "blah", additionalInfo); + return InternalApiBridge.createRuleViolation(new FooRule(), loc, "blah", additionalInfo); } @Override diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/reporting/ReportTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/reporting/ReportTest.java index b866d58870..e20d291259 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/reporting/ReportTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/reporting/ReportTest.java @@ -10,6 +10,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.StringWriter; +import java.util.Collections; import java.util.function.Consumer; import org.checkerframework.checker.nullness.qual.NonNull; @@ -106,7 +107,7 @@ class ReportTest { } public static @NonNull RuleViolation violation(Rule rule, FileLocation loc1, String rule1) { - return new ParametricRuleViolation(rule, loc1, rule1); + return new ParametricRuleViolation(rule, loc1, rule1, Collections.emptyMap()); } From 7c5bf74402a827e3bb9449bcb88a01f14105876e Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 10 Feb 2024 09:31:55 +0100 Subject: [PATCH 30/37] [core] Consolidate internal api in n.s.p.lang.rule RuleSet#applies RuleSetLoader#loadRuleSetsWithoutException RuleSetLoadException ctors --- docs/pages/release_notes.md | 8 ++++ .../pmd/ant/internal/PMDTaskImpl.java | 4 +- .../java/net/sourceforge/pmd/PmdAnalysis.java | 4 +- .../java/net/sourceforge/pmd/RuleSets.java | 5 ++- .../pmd/lang/rule/RuleSetLoadException.java | 36 ++++++++++++++++ .../java/net/sourceforge/pmd/PmdAnalysis.java | 6 ++- .../pmd/lang/rule/InternalApiBridge.java | 39 +++++++++++++++++ .../sourceforge/pmd/lang/rule/RuleSet.java | 42 ++++--------------- .../pmd/lang/rule/RuleSetLoadException.java | 15 +++---- .../pmd/lang/rule/RuleSetLoader.java | 6 +-- .../lang/rule/internal/RuleApplicator.java | 5 ++- .../pmd/lang/rule/internal/RuleSets.java | 5 ++- .../pmd/lang/rule/RuleSetTest.java | 14 ++++--- 13 files changed, 127 insertions(+), 62 deletions(-) create mode 100644 pmd-compat6/src/main/java/net/sourceforge/pmd/lang/rule/RuleSetLoadException.java create mode 100644 pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/InternalApiBridge.java diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index b0b392968a..ace594edfe 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -306,6 +306,14 @@ package or made (package) private and are _not accessible_ anymore. * `net.sourceforge.pmd.RuleSets` * `net.sourceforge.pmd.lang.rule.ParametricRuleViolation` is now package private and moved to `net.sourceforge.pmd.reporting.ParametricRuleViolation`. The only public API is {%jdoc core::reporting.RuleViolation %}. + * {%jdoc !!core::lang.rule.RuleSet %} + * Method `applies(Rule,LanguageVersion)` is now package private. + * Method `applies(TextFile)` has been removed. + * Method `applies(FileId)` is now package private. + * {%jdoc !!core::lang.rule.RuleSetLoader %} + * Method `loadRuleSetsWithoutException(java.util.List)` is now package private. + * {%jdoc !!core::lang.rule.RuleSetLoadException %} + * All constructors are package private now. * pmd-ant * {%jdoc !!ant::ant.Formatter %} * Method `getRenderer()` has been removed. diff --git a/pmd-ant/src/main/java/net/sourceforge/pmd/ant/internal/PMDTaskImpl.java b/pmd-ant/src/main/java/net/sourceforge/pmd/ant/internal/PMDTaskImpl.java index e35a8ff962..a4be75fb15 100644 --- a/pmd-ant/src/main/java/net/sourceforge/pmd/ant/internal/PMDTaskImpl.java +++ b/pmd-ant/src/main/java/net/sourceforge/pmd/ant/internal/PMDTaskImpl.java @@ -4,6 +4,8 @@ package net.sourceforge.pmd.ant.internal; +import static net.sourceforge.pmd.lang.rule.InternalApiBridge.loadRuleSetsWithoutException; + import java.nio.charset.Charset; import java.nio.file.Paths; import java.util.ArrayList; @@ -125,7 +127,7 @@ public class PMDTaskImpl { try (PmdAnalysis pmd = PmdAnalysis.create(configuration)) { RuleSetLoader rulesetLoader = pmd.newRuleSetLoader().loadResourcesWith(setupResourceLoader()); - pmd.addRuleSets(rulesetLoader.loadRuleSetsWithoutException(ruleSetPaths)); + pmd.addRuleSets(loadRuleSetsWithoutException(rulesetLoader, ruleSetPaths)); for (FileSet fileset : filesets) { DirectoryScanner ds = fileset.getDirectoryScanner(project); diff --git a/pmd-compat6/src/main/java/net/sourceforge/pmd/PmdAnalysis.java b/pmd-compat6/src/main/java/net/sourceforge/pmd/PmdAnalysis.java index de0b41595e..3a84752c39 100644 --- a/pmd-compat6/src/main/java/net/sourceforge/pmd/PmdAnalysis.java +++ b/pmd-compat6/src/main/java/net/sourceforge/pmd/PmdAnalysis.java @@ -193,7 +193,7 @@ public final class PmdAnalysis implements AutoCloseable { if (!config.getRuleSetPaths().isEmpty()) { final net.sourceforge.pmd.lang.rule.RuleSetLoader ruleSetLoader = pmd.newRuleSetLoader(); - final List ruleSets = ruleSetLoader.loadRuleSetsWithoutException(config.getRuleSetPaths()); + final List ruleSets = net.sourceforge.pmd.lang.rule.InternalApiBridge.loadRuleSetsWithoutException(ruleSetLoader, config.getRuleSetPaths()); pmd.addRuleSets(ruleSets); } @@ -490,7 +490,7 @@ public final class PmdAnalysis implements AutoCloseable { Objects.requireNonNull(ruleLanguage, "Rule has no language " + rule); if (!languages.contains(ruleLanguage)) { LanguageVersion version = discoverer.getDefaultLanguageVersion(ruleLanguage); - if (RuleSet.applies((net.sourceforge.pmd.lang.rule.Rule) rule, version)) { + if (net.sourceforge.pmd.lang.rule.InternalApiBridge.ruleSetApplies((net.sourceforge.pmd.lang.rule.Rule) rule, version)) { configuration.checkLanguageIsRegistered(ruleLanguage); languages.add(ruleLanguage); if (!quiet) { diff --git a/pmd-compat6/src/main/java/net/sourceforge/pmd/RuleSets.java b/pmd-compat6/src/main/java/net/sourceforge/pmd/RuleSets.java index 601dffd5a1..7ee5ec4daa 100644 --- a/pmd-compat6/src/main/java/net/sourceforge/pmd/RuleSets.java +++ b/pmd-compat6/src/main/java/net/sourceforge/pmd/RuleSets.java @@ -22,6 +22,7 @@ import net.sourceforge.pmd.benchmark.TimedOperationCategory; import net.sourceforge.pmd.lang.LanguageProcessorRegistry; import net.sourceforge.pmd.lang.ast.RootNode; import net.sourceforge.pmd.lang.document.TextFile; +import net.sourceforge.pmd.lang.rule.InternalApiBridge; import net.sourceforge.pmd.lang.rule.Rule; import net.sourceforge.pmd.lang.rule.RuleSet; import net.sourceforge.pmd.lang.rule.internal.RuleApplicator; @@ -126,7 +127,7 @@ public class RuleSets { */ public boolean applies(TextFile file) { for (RuleSet ruleSet : ruleSets) { - if (ruleSet.applies(file)) { + if (InternalApiBridge.ruleSetApplies(ruleSet, file.getFileId())) { return true; } } @@ -155,7 +156,7 @@ public class RuleSets { } for (RuleSet ruleSet : ruleSets) { - if (ruleSet.applies(root.getTextDocument().getFileId())) { + if (InternalApiBridge.ruleSetApplies(ruleSet, root.getTextDocument().getFileId())) { ruleApplicator.apply(ruleSet.getRules(), listener); } } diff --git a/pmd-compat6/src/main/java/net/sourceforge/pmd/lang/rule/RuleSetLoadException.java b/pmd-compat6/src/main/java/net/sourceforge/pmd/lang/rule/RuleSetLoadException.java new file mode 100644 index 0000000000..5cc43b7131 --- /dev/null +++ b/pmd-compat6/src/main/java/net/sourceforge/pmd/lang/rule/RuleSetLoadException.java @@ -0,0 +1,36 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +// Copied from 7.0.0-SNAPSHOT +// Changes: constructors are public again + +package net.sourceforge.pmd.lang.rule; + +import org.checkerframework.checker.nullness.qual.NonNull; + +import net.sourceforge.pmd.lang.rule.internal.RuleSetReferenceId; + +/** + * An exception that is thrown when something wrong occurs while + * {@linkplain RuleSetLoader loading rulesets}. This may be because the + * XML is not well-formed, does not respect the ruleset schema, is + * not a valid ruleset or is otherwise unparsable. + */ +public class RuleSetLoadException extends RuntimeException { + + /** + * @apiNote Internal API. + */ + public RuleSetLoadException(RuleSetReferenceId rsetId, @NonNull Throwable cause) { + super("Cannot load ruleset " + rsetId + ": " + cause.getMessage(), cause); + } + + /** + * @apiNote Internal API. + */ + public RuleSetLoadException(RuleSetReferenceId rsetId, String message) { + super("Cannot load ruleset " + rsetId + ": " + message); + } + +} 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 e3a211cefa..b894b46c39 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/PmdAnalysis.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/PmdAnalysis.java @@ -4,6 +4,8 @@ package net.sourceforge.pmd; +import static net.sourceforge.pmd.lang.rule.InternalApiBridge.loadRuleSetsWithoutException; +import static net.sourceforge.pmd.lang.rule.InternalApiBridge.ruleSetApplies; import static net.sourceforge.pmd.util.CollectionUtil.listOf; import java.nio.file.Path; @@ -193,7 +195,7 @@ public final class PmdAnalysis implements AutoCloseable { if (!config.getRuleSetPaths().isEmpty()) { final RuleSetLoader ruleSetLoader = pmd.newRuleSetLoader(); - final List ruleSets = ruleSetLoader.loadRuleSetsWithoutException(config.getRuleSetPaths()); + final List ruleSets = loadRuleSetsWithoutException(ruleSetLoader, config.getRuleSetPaths()); pmd.addRuleSets(ruleSets); } @@ -490,7 +492,7 @@ public final class PmdAnalysis implements AutoCloseable { Objects.requireNonNull(ruleLanguage, "Rule has no language " + rule); if (!languages.contains(ruleLanguage)) { LanguageVersion version = discoverer.getDefaultLanguageVersion(ruleLanguage); - if (RuleSet.applies(rule, version)) { + if (ruleSetApplies(rule, version)) { configuration.checkLanguageIsRegistered(ruleLanguage); languages.add(ruleLanguage); if (!quiet) { diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/InternalApiBridge.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/InternalApiBridge.java new file mode 100644 index 0000000000..b532eef955 --- /dev/null +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/InternalApiBridge.java @@ -0,0 +1,39 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.rule; + +import java.util.List; + +import net.sourceforge.pmd.annotation.InternalApi; +import net.sourceforge.pmd.lang.LanguageVersion; +import net.sourceforge.pmd.lang.document.FileId; + +/** + * Internal API. + * + *

Acts as a bridge between outer parts of PMD and the restricted access + * internal API of this package. + * + *

None of this is published API, and compatibility can be broken anytime! + * Use this only at your own risk. + * + * @apiNote Internal API + */ +@InternalApi +public final class InternalApiBridge { + private InternalApiBridge() {} + + public static boolean ruleSetApplies(Rule rule, LanguageVersion languageVersion) { + return RuleSet.applies(rule, languageVersion); + } + + public static boolean ruleSetApplies(RuleSet ruleSet, FileId fileId) { + return ruleSet.applies(fileId); + } + + public static List loadRuleSetsWithoutException(RuleSetLoader ruleSetLoader, List rulesetPaths) { + return ruleSetLoader.loadRuleSetsWithoutException(rulesetPaths); + } +} diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleSet.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleSet.java index 47cd37243c..c4a5d5b60a 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleSet.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleSet.java @@ -20,12 +20,10 @@ import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.cache.internal.ChecksumAware; import net.sourceforge.pmd.internal.util.PredicateUtil; import net.sourceforge.pmd.lang.LanguageVersion; import net.sourceforge.pmd.lang.document.FileId; -import net.sourceforge.pmd.lang.document.TextFile; import net.sourceforge.pmd.lang.rule.internal.RuleSetReference; import net.sourceforge.pmd.lang.rule.xpath.XPathRule; @@ -607,30 +605,13 @@ public class RuleSet implements ChecksumAware { * * @return true if the file should be checked, * false otherwise + * + * @apiNote Internal API. */ - // TODO get rid of this overload - @InternalApi - public boolean applies(FileId qualFileName) { + boolean applies(FileId qualFileName) { return filter.test(qualFileName.getAbsolutePath()); } - /** - * Check if a given source file should be checked by rules in this RuleSet. - * A file should not be checked if there is an exclude pattern - * which matches the file, unless there is an include pattern - * which also matches the file. In other words, include - * patterns override exclude patterns. - * - * @param file a text file - * - * @return true if the file should be checked, - * false otherwise - */ - @InternalApi - public boolean applies(TextFile file) { - return applies(file.getFileId()); - } - /** * Does the given Rule apply to the given LanguageVersion? If so, the * Language must be the same and be between the minimum and maximums @@ -644,12 +625,9 @@ public class RuleSet implements ChecksumAware { * @return true if the given rule matches the given language, * which means, that the rule would be executed. * - * @deprecated This is internal API, removed in PMD 7. You should - * not use a ruleset directly. + * @apiNote This is internal API. */ - @Deprecated - @InternalApi - public static boolean applies(Rule rule, LanguageVersion languageVersion) { + static boolean applies(Rule rule, LanguageVersion languageVersion) { final LanguageVersion min = rule.getMinimumLanguageVersion(); final LanguageVersion max = rule.getMaximumLanguageVersion(); assert rule.getLanguage() != null : "Rule has no language " + rule; @@ -715,17 +693,13 @@ public class RuleSet implements ChecksumAware { /** * Remove and collect any misconfigured rules. - * TODO remove this method. This mutates rulesets for nothing. Whether - * a rule is dysfunctional or not should be checked when it is initialized. * * @param collector * the removed rules will be added to this collection - * - * @deprecated This is internal API, removed in PMD 7. You should - * not use a ruleset directly. */ - @Deprecated - @InternalApi + // TODO remove this method. This mutates rulesets for nothing. Whether a rule + // is dysfunctional or not should be checked when it is initialized. + // See also https://github.com/pmd/pmd/issues/3868 and https://github.com/pmd/pmd/issues/3901 public void removeDysfunctionalRules(Collection collector) { Iterator iter = rules.iterator(); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleSetLoadException.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleSetLoadException.java index c87ba35118..ca53380384 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleSetLoadException.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleSetLoadException.java @@ -6,7 +6,6 @@ package net.sourceforge.pmd.lang.rule; import org.checkerframework.checker.nullness.qual.NonNull; -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.rule.internal.RuleSetReferenceId; /** @@ -17,15 +16,17 @@ import net.sourceforge.pmd.lang.rule.internal.RuleSetReferenceId; */ public class RuleSetLoadException extends RuntimeException { - /** Constructors are internal. */ - @InternalApi - public RuleSetLoadException(RuleSetReferenceId rsetId, @NonNull Throwable cause) { + /** + * @apiNote Internal API. + */ + RuleSetLoadException(RuleSetReferenceId rsetId, @NonNull Throwable cause) { super("Cannot load ruleset " + rsetId + ": " + cause.getMessage(), cause); } - /** Constructors are internal. */ - @InternalApi - public RuleSetLoadException(RuleSetReferenceId rsetId, String message) { + /** + * @apiNote Internal API. + */ + RuleSetLoadException(RuleSetReferenceId rsetId, String message) { super("Cannot load ruleset " + rsetId + ": " + message); } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleSetLoader.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleSetLoader.java index 0fa046c824..e1bb83cdc2 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleSetLoader.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleSetLoader.java @@ -21,7 +21,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import net.sourceforge.pmd.PMDConfiguration; -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.Language; import net.sourceforge.pmd.lang.LanguageRegistry; import net.sourceforge.pmd.lang.rule.internal.RuleSetReferenceId; @@ -195,11 +194,10 @@ public final class RuleSetLoader { * Loads a list of rulesets, if any has an error, report it on the contextual * error reporter instead of aborting, and continue loading the rest. * - *

Internal API: might be published later, or maybe in PMD 7 this + * @apiNote Internal API: might be published later, or maybe this * will be the default behaviour of every method of this class. */ - @InternalApi - public List loadRuleSetsWithoutException(List rulesetPaths) { + List loadRuleSetsWithoutException(List rulesetPaths) { List ruleSets = new ArrayList<>(rulesetPaths.size()); boolean anyRules = false; boolean error = false; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/internal/RuleApplicator.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/internal/RuleApplicator.java index e61d28ebff..52e5378369 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/internal/RuleApplicator.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/internal/RuleApplicator.java @@ -4,6 +4,8 @@ package net.sourceforge.pmd.lang.rule.internal; +import static net.sourceforge.pmd.lang.rule.InternalApiBridge.ruleSetApplies; + import java.util.Collection; import java.util.Iterator; @@ -19,7 +21,6 @@ import net.sourceforge.pmd.lang.LanguageVersion; import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.ast.RootNode; import net.sourceforge.pmd.lang.rule.Rule; -import net.sourceforge.pmd.lang.rule.RuleSet; import net.sourceforge.pmd.reporting.FileAnalysisListener; import net.sourceforge.pmd.reporting.InternalApiBridge; import net.sourceforge.pmd.reporting.Report.ProcessingError; @@ -58,7 +59,7 @@ public class RuleApplicator { private void applyOnIndex(TreeIndex idx, Collection rules, FileAnalysisListener listener) { for (Rule rule : rules) { - if (!RuleSet.applies(rule, currentLangVer)) { + if (!ruleSetApplies(rule, currentLangVer)) { continue; // No point in even trying to apply the rule } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/internal/RuleSets.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/internal/RuleSets.java index 7d05afd410..829b06116e 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/internal/RuleSets.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/internal/RuleSets.java @@ -18,6 +18,7 @@ import net.sourceforge.pmd.benchmark.TimedOperationCategory; import net.sourceforge.pmd.lang.LanguageProcessorRegistry; import net.sourceforge.pmd.lang.ast.RootNode; import net.sourceforge.pmd.lang.document.TextFile; +import net.sourceforge.pmd.lang.rule.InternalApiBridge; import net.sourceforge.pmd.lang.rule.Rule; import net.sourceforge.pmd.lang.rule.RuleSet; import net.sourceforge.pmd.reporting.FileAnalysisListener; @@ -121,7 +122,7 @@ public class RuleSets { */ public boolean applies(TextFile file) { for (RuleSet ruleSet : ruleSets) { - if (ruleSet.applies(file)) { + if (InternalApiBridge.ruleSetApplies(ruleSet, file.getFileId())) { return true; } } @@ -150,7 +151,7 @@ public class RuleSets { } for (RuleSet ruleSet : ruleSets) { - if (ruleSet.applies(root.getTextDocument().getFileId())) { + if (InternalApiBridge.ruleSetApplies(ruleSet, root.getTextDocument().getFileId())) { ruleApplicator.apply(ruleSet.getRules(), listener); } } diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/RuleSetTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/RuleSetTest.java index 470b6c4c64..32387b4a73 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/RuleSetTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/RuleSetTest.java @@ -45,6 +45,7 @@ import net.sourceforge.pmd.FooRule; import net.sourceforge.pmd.lang.ast.DummyNode.DummyRootNode; import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.ast.RootNode; +import net.sourceforge.pmd.lang.document.FileId; import net.sourceforge.pmd.lang.document.TextFile; import net.sourceforge.pmd.lang.rule.RuleSet.RuleSetBuilder; import net.sourceforge.pmd.lang.rule.internal.RuleSets; @@ -389,27 +390,28 @@ class RuleSetTest { @Test void testIncludeExcludeApplies() { - TextFile file = TextFile.forPath(Paths.get("C:\\myworkspace\\project\\some\\random\\package\\RandomClass.java"), Charset.defaultCharset(), dummyVersion()); + FileId fileId = TextFile.forPath(Paths.get("C:\\myworkspace\\project\\some\\random\\package\\RandomClass.java"), Charset.defaultCharset(), dummyVersion()) + .getFileId(); RuleSet ruleSet = createRuleSetBuilder("ruleset").build(); - assertTrue(ruleSet.applies(file), "No patterns"); + assertTrue(ruleSet.applies(fileId), "No patterns"); ruleSet = createRuleSetBuilder("ruleset") .withFileExclusions(Pattern.compile("nomatch")) .build(); - assertTrue(ruleSet.applies(file), "Non-matching exclude"); + assertTrue(ruleSet.applies(fileId), "Non-matching exclude"); ruleSet = createRuleSetBuilder("ruleset") .withFileExclusions(Pattern.compile("nomatch"), Pattern.compile(".*/package/.*")) .build(); - assertFalse(ruleSet.applies(file), "Matching exclude"); + assertFalse(ruleSet.applies(fileId), "Matching exclude"); ruleSet = createRuleSetBuilder("ruleset") .withFileExclusions(Pattern.compile("nomatch")) .withFileExclusions(Pattern.compile(".*/package/.*")) .withFileInclusions(Pattern.compile(".*/randomX/.*")) .build(); - assertFalse(ruleSet.applies(file), "Non-matching include"); + assertFalse(ruleSet.applies(fileId), "Non-matching include"); ruleSet = createRuleSetBuilder("ruleset") .withFileExclusions(Pattern.compile("nomatch")) @@ -417,7 +419,7 @@ class RuleSetTest { .withFileInclusions(Pattern.compile(".*/randomX/.*")) .withFileInclusions(Pattern.compile(".*/random/.*")) .build(); - assertTrue(ruleSet.applies(file), "Matching include"); + assertTrue(ruleSet.applies(fileId), "Matching include"); } @Test From 2cc9ae9d7e731b0bed00dd80eaf1407e8bde9d82 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 10 Feb 2024 10:05:34 +0100 Subject: [PATCH 31/37] [core] Consolidate internal api in LexException --- docs/pages/release_notes.md | 2 ++ javacc-wrapper.xml | 2 +- .../pmd/lang/ast/InternalApiBridge.java | 27 +++++++++++++++++++ .../pmd/lang/ast/LexException.java | 6 ++--- 4 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/InternalApiBridge.java diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index ace594edfe..58e00a9029 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -314,6 +314,8 @@ package or made (package) private and are _not accessible_ anymore. * Method `loadRuleSetsWithoutException(java.util.List)` is now package private. * {%jdoc !!core::lang.rule.RuleSetLoadException %} * All constructors are package private now. + * {%jdoc !!core::lang.ast.LexException %} - the constructor `LexException(boolean, String, int, int, String, char)` is now package private. + It is only used by JavaCC-generated token managers. * pmd-ant * {%jdoc !!ant::ant.Formatter %} * Method `getRenderer()` has been removed. diff --git a/javacc-wrapper.xml b/javacc-wrapper.xml index ece4307099..306c0601be 100644 --- a/javacc-wrapper.xml +++ b/javacc-wrapper.xml @@ -283,7 +283,7 @@ - + diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/InternalApiBridge.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/InternalApiBridge.java new file mode 100644 index 0000000000..460ae0dd37 --- /dev/null +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/InternalApiBridge.java @@ -0,0 +1,27 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.ast; + +import net.sourceforge.pmd.annotation.InternalApi; + +/** + * Internal API. + * + *

Acts as a bridge between outer parts of PMD and the restricted access + * internal API of this package. + * + *

None of this is published API, and compatibility can be broken anytime! + * Use this only at your own risk. + * + * @apiNote Internal API + */ +@InternalApi +public final class InternalApiBridge { + private InternalApiBridge() {} + + public static LexException newLexException(boolean eofSeen, String lexStateName, int errorLine, int errorColumn, String errorAfter, char curChar) { + return new LexException(eofSeen, lexStateName, errorLine, errorColumn, errorAfter, curChar); + } +} diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/LexException.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/LexException.java index 3aea6b656d..6331d798c9 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/LexException.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/LexException.java @@ -9,7 +9,6 @@ import static java.lang.Math.max; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.document.FileId; import net.sourceforge.pmd.lang.document.FileLocation; import net.sourceforge.pmd.util.StringUtil; @@ -44,9 +43,10 @@ public final class LexException extends FileAnalysisException { /** * Constructor called by JavaCC. + * + * @apiNote Internal API. */ - @InternalApi - public LexException(boolean eofSeen, String lexStateName, int errorLine, int errorColumn, String errorAfter, char curChar) { + LexException(boolean eofSeen, String lexStateName, int errorLine, int errorColumn, String errorAfter, char curChar) { super(makeReason(eofSeen, lexStateName, errorAfter, curChar)); line = max(errorLine, 1); column = max(errorColumn, 1); From 3a635da9c2a641f393eaef789fa875d597ff954b Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 10 Feb 2024 10:38:26 +0100 Subject: [PATCH 32/37] [core] Consolidate internal api in PMDConfiguration PMDConfiguration#setAnalysisCache PMDConfiguration#getAnalysisCache --- docs/pages/release_notes.md | 3 ++ .../net/sourceforge/pmd/PMDConfiguration.java | 8 ++---- .../pmd/InternalApiBridgeForTestsOnly.java | 28 +++++++++++++++++++ .../reporting/GlobalAnalysisListenerTest.java | 9 +++--- 4 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 pmd-core/src/test/java/net/sourceforge/pmd/InternalApiBridgeForTestsOnly.java diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 58e00a9029..3d8af2c21e 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -316,6 +316,9 @@ package or made (package) private and are _not accessible_ anymore. * All constructors are package private now. * {%jdoc !!core::lang.ast.LexException %} - the constructor `LexException(boolean, String, int, int, String, char)` is now package private. It is only used by JavaCC-generated token managers. + * {%jdoc !!core::PMDConfiguration %} + * Method `setAnalysisCache(AnalysisCache)` is now package private. Use {%jdoc core::PMDConfiguration#setAnalysisCacheLocation(java.lang.String) %} instead. + * Method `getAnalysisCache()` is now package private. * pmd-ant * {%jdoc !!ant::ant.Formatter %} * Method `getRenderer()` has been removed. diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java b/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java index b11df3bd2c..8e86465158 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java @@ -21,13 +21,13 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.slf4j.LoggerFactory; import net.sourceforge.pmd.annotation.DeprecatedUntil700; -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.cache.internal.AnalysisCache; import net.sourceforge.pmd.cache.internal.FileAnalysisCache; import net.sourceforge.pmd.cache.internal.NoopAnalysisCache; import net.sourceforge.pmd.internal.util.ClasspathClassLoader; import net.sourceforge.pmd.lang.Language; import net.sourceforge.pmd.lang.LanguageRegistry; +import net.sourceforge.pmd.lang.LanguageVersion; import net.sourceforge.pmd.lang.rule.RulePriority; import net.sourceforge.pmd.lang.rule.RuleSetLoader; import net.sourceforge.pmd.renderers.Renderer; @@ -455,8 +455,7 @@ public class PMDConfiguration extends AbstractConfiguration { * * @apiNote This is internal API. */ - @InternalApi - public AnalysisCache getAnalysisCache() { + AnalysisCache getAnalysisCache() { // Make sure we are not null if (analysisCache == null || isIgnoreIncrementalAnalysis() && !(analysisCache instanceof NoopAnalysisCache)) { // sets a noop cache @@ -476,8 +475,7 @@ public class PMDConfiguration extends AbstractConfiguration { * * @apiNote This is internal API. Use {@link #setAnalysisCacheLocation(String)} to configure a cache. */ - @InternalApi - public void setAnalysisCache(final AnalysisCache cache) { + void setAnalysisCache(final AnalysisCache cache) { // the doc says it's a noop if incremental analysis was disabled, // but it's actually the getter that enforces that this.analysisCache = cache == null ? new NoopAnalysisCache() : cache; diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/InternalApiBridgeForTestsOnly.java b/pmd-core/src/test/java/net/sourceforge/pmd/InternalApiBridgeForTestsOnly.java new file mode 100644 index 0000000000..f12d571d01 --- /dev/null +++ b/pmd-core/src/test/java/net/sourceforge/pmd/InternalApiBridgeForTestsOnly.java @@ -0,0 +1,28 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd; + +import net.sourceforge.pmd.annotation.InternalApi; +import net.sourceforge.pmd.cache.internal.AnalysisCache; + +/** + * Internal API. + * + *

Acts as a bridge between outer parts of PMD and the restricted access + * internal API of this package. + * + *

None of this is published API, and compatibility can be broken anytime! + * Use this only at your own risk. + * + * @apiNote Internal API + */ +@InternalApi +public final class InternalApiBridgeForTestsOnly { + private InternalApiBridgeForTestsOnly() {} + + public static void setAnalysisCache(PMDConfiguration pmdConfiguration, AnalysisCache cache) { + pmdConfiguration.setAnalysisCache(cache); + } +} diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/reporting/GlobalAnalysisListenerTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/reporting/GlobalAnalysisListenerTest.java index 2f95e79331..1b07770bec 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/reporting/GlobalAnalysisListenerTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/reporting/GlobalAnalysisListenerTest.java @@ -19,6 +19,7 @@ import org.junit.jupiter.api.Test; import org.mockito.Mockito; import net.sourceforge.pmd.FooRule; +import net.sourceforge.pmd.InternalApiBridgeForTestsOnly; import net.sourceforge.pmd.PMDConfiguration; import net.sourceforge.pmd.PmdAnalysis; import net.sourceforge.pmd.cache.internal.AnalysisCache; @@ -71,7 +72,7 @@ class GlobalAnalysisListenerTest { PMDConfiguration config = newConfig(); AnalysisCache mockCache = spy(NoopAnalysisCache.class); - config.setAnalysisCache(mockCache); + InternalApiBridgeForTestsOnly.setAnalysisCache(config, mockCache); MyFooRule rule = new MyFooRule(); runPmd(config, GlobalAnalysisListener.noop(), rule); @@ -86,7 +87,7 @@ class GlobalAnalysisListenerTest { PMDConfiguration config = newConfig(); AnalysisCache mockCache = spy(NoopAnalysisCache.class); - config.setAnalysisCache(mockCache); + InternalApiBridgeForTestsOnly.setAnalysisCache(config, mockCache); BrokenRule rule = new BrokenRule(); // the broken rule throws runPmd(config, GlobalAnalysisListener.noop(), rule); @@ -102,7 +103,7 @@ class GlobalAnalysisListenerTest { PMDConfiguration config = newConfig(); AnalysisCache mockCache = spy(NoopAnalysisCache.class); - config.setAnalysisCache(mockCache); + InternalApiBridgeForTestsOnly.setAnalysisCache(config, mockCache); BrokenRule rule = new BrokenRule(); // the broken rule throws // now the exception should be propagated @@ -122,7 +123,7 @@ class GlobalAnalysisListenerTest { @NonNull private PMDConfiguration newConfig() { PMDConfiguration config = new PMDConfiguration(); - config.setAnalysisCache(new NoopAnalysisCache()); + config.setAnalysisCacheLocation(null); config.setIgnoreIncrementalAnalysis(true); config.setThreads(0); // no multithreading for this test return config; From 5e92b5907e82c553f3d5a1ef05f96305dc15c8a5 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 10 Feb 2024 10:47:07 +0100 Subject: [PATCH 33/37] [core] Consolidate internal api in FileCollector FileCollector#newCollector --- docs/pages/release_notes.md | 4 +++ .../java/net/sourceforge/pmd/PmdAnalysis.java | 2 +- .../java/net/sourceforge/pmd/PmdAnalysis.java | 3 +- .../net/sourceforge/pmd/cpd/CpdAnalysis.java | 3 +- .../java/net/sourceforge/pmd/cpd/GUI.java | 3 +- .../pmd/internal/util/FileCollectionUtil.java | 3 +- .../pmd/lang/document/FileCollector.java | 7 ++-- .../pmd/lang/document/InternalApiBridge.java | 33 +++++++++++++++++++ .../sourceforge/pmd/cli/PMDFilelistTest.java | 3 +- 9 files changed, 50 insertions(+), 11 deletions(-) create mode 100644 pmd-core/src/main/java/net/sourceforge/pmd/lang/document/InternalApiBridge.java diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 3d8af2c21e..369b867bb9 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -319,6 +319,10 @@ package or made (package) private and are _not accessible_ anymore. * {%jdoc !!core::PMDConfiguration %} * Method `setAnalysisCache(AnalysisCache)` is now package private. Use {%jdoc core::PMDConfiguration#setAnalysisCacheLocation(java.lang.String) %} instead. * Method `getAnalysisCache()` is now package private. + * {%jdoc !!core::lang.document.FileCollector %} + * Method `newCollector(LanguageVersionDiscoverer, PmdReporter)` is now package private. + * Method `newCollector(PmdReporter)` is now package private. + * In order to create a FileCollector, use {%jdoc core::PmdAnalysis#files() %} instead. * pmd-ant * {%jdoc !!ant::ant.Formatter %} * Method `getRenderer()` has been removed. diff --git a/pmd-compat6/src/main/java/net/sourceforge/pmd/PmdAnalysis.java b/pmd-compat6/src/main/java/net/sourceforge/pmd/PmdAnalysis.java index 3a84752c39..a5580cdefb 100644 --- a/pmd-compat6/src/main/java/net/sourceforge/pmd/PmdAnalysis.java +++ b/pmd-compat6/src/main/java/net/sourceforge/pmd/PmdAnalysis.java @@ -157,7 +157,7 @@ public final class PmdAnalysis implements AutoCloseable { private PmdAnalysis(PMDConfiguration config) { this.configuration = config; this.reporter = config.getReporter(); - this.collector = FileCollector.newCollector( + this.collector = net.sourceforge.pmd.lang.document.InternalApiBridge.newCollector( config.getLanguageVersionDiscoverer(), reporter ); 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 b894b46c39..84d96909c5 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/PmdAnalysis.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/PmdAnalysis.java @@ -4,6 +4,7 @@ package net.sourceforge.pmd; +import static net.sourceforge.pmd.lang.document.InternalApiBridge.newCollector; import static net.sourceforge.pmd.lang.rule.InternalApiBridge.loadRuleSetsWithoutException; import static net.sourceforge.pmd.lang.rule.InternalApiBridge.ruleSetApplies; import static net.sourceforge.pmd.util.CollectionUtil.listOf; @@ -159,7 +160,7 @@ public final class PmdAnalysis implements AutoCloseable { private PmdAnalysis(PMDConfiguration config) { this.configuration = config; this.reporter = config.getReporter(); - this.collector = FileCollector.newCollector( + this.collector = newCollector( config.getLanguageVersionDiscoverer(), reporter ); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CpdAnalysis.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CpdAnalysis.java index 3f54d51ff9..1faecd371e 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CpdAnalysis.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CpdAnalysis.java @@ -26,6 +26,7 @@ import net.sourceforge.pmd.lang.ast.FileAnalysisException; import net.sourceforge.pmd.lang.ast.LexException; import net.sourceforge.pmd.lang.document.FileCollector; import net.sourceforge.pmd.lang.document.FileId; +import net.sourceforge.pmd.lang.document.InternalApiBridge; import net.sourceforge.pmd.lang.document.TextDocument; import net.sourceforge.pmd.lang.document.TextFile; import net.sourceforge.pmd.properties.PropertyDescriptor; @@ -78,7 +79,7 @@ public final class CpdAnalysis implements AutoCloseable { private CpdAnalysis(CPDConfiguration config) { this.configuration = config; this.reporter = config.getReporter(); - this.files = FileCollector.newCollector( + this.files = InternalApiBridge.newCollector( config.getLanguageVersionDiscoverer(), reporter ); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/GUI.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/GUI.java index 54e98722b2..9231711559 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/GUI.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/GUI.java @@ -70,6 +70,7 @@ import net.sourceforge.pmd.lang.LanguagePropertyBundle; import net.sourceforge.pmd.lang.LanguageRegistry; import net.sourceforge.pmd.lang.document.FileCollector; import net.sourceforge.pmd.lang.document.FileId; +import net.sourceforge.pmd.lang.document.InternalApiBridge; import net.sourceforge.pmd.lang.impl.CpdOnlyLanguageModuleBase; import net.sourceforge.pmd.util.CollectionUtil; @@ -714,7 +715,7 @@ public class GUI implements CPDListener { // the created sourceManager will be closed when exiting or when a new analysis is started, // see #closeSourceManager(). @SuppressWarnings("PMD.CloseResource") - FileCollector fileCollector = FileCollector.newCollector(config.getLanguageVersionDiscoverer(), config.getReporter()); + FileCollector fileCollector = InternalApiBridge.newCollector(config.getLanguageVersionDiscoverer(), config.getReporter()); fileCollector.addFileOrDirectory(dirPath, recurse); sourceManager = new SourceManager(fileCollector.getCollectedFiles()); } catch (Exception e) { diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/internal/util/FileCollectionUtil.java b/pmd-core/src/main/java/net/sourceforge/pmd/internal/util/FileCollectionUtil.java index 8deb034292..09ac693b50 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/internal/util/FileCollectionUtil.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/internal/util/FileCollectionUtil.java @@ -18,6 +18,7 @@ import org.slf4j.LoggerFactory; import net.sourceforge.pmd.AbstractConfiguration; import net.sourceforge.pmd.lang.document.FileCollector; import net.sourceforge.pmd.lang.document.FileId; +import net.sourceforge.pmd.lang.document.InternalApiBridge; import net.sourceforge.pmd.util.database.DBMSMetadata; import net.sourceforge.pmd.util.database.DBURI; import net.sourceforge.pmd.util.database.SourceObject; @@ -58,7 +59,7 @@ public final class FileCollectionUtil { LOG.debug("Now collecting files to exclude."); // errors like "excluded file does not exist" are reported as warnings. PmdReporter mutedLog = new ErrorsAsWarningsReporter(collector.getReporter()); - try (FileCollector excludeCollector = collector.newCollector(mutedLog)) { + try (FileCollector excludeCollector = InternalApiBridge.newCollector(collector, mutedLog)) { if (configuration.getIgnoreFile() != null) { // todo better reporting of *where* exactly the path is diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/document/FileCollector.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/document/FileCollector.java index 7b7db06c86..9c66a666c3 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/document/FileCollector.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/document/FileCollector.java @@ -36,7 +36,6 @@ import org.slf4j.LoggerFactory; import net.sourceforge.pmd.PmdAnalysis; import net.sourceforge.pmd.annotation.Experimental; -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.internal.util.IOUtil; import net.sourceforge.pmd.lang.Language; import net.sourceforge.pmd.lang.LanguageVersion; @@ -77,8 +76,7 @@ public final class FileCollector implements AutoCloseable { * @apiNote Internal API - please use {@link PmdAnalysis#files()} instead of * creating a collector yourself. */ - @InternalApi - public static FileCollector newCollector(LanguageVersionDiscoverer discoverer, PmdReporter reporter) { + static FileCollector newCollector(LanguageVersionDiscoverer discoverer, PmdReporter reporter) { return new FileCollector(discoverer, reporter, null); } @@ -88,8 +86,7 @@ public final class FileCollector implements AutoCloseable { * @apiNote Internal API - please use {@link PmdAnalysis#files()} instead of * creating a collector yourself. */ - @InternalApi - public FileCollector newCollector(PmdReporter logger) { + FileCollector newCollector(PmdReporter logger) { FileCollector fileCollector = new FileCollector(discoverer, logger, null); fileCollector.charset = this.charset; return fileCollector; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/document/InternalApiBridge.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/document/InternalApiBridge.java new file mode 100644 index 0000000000..7c60233179 --- /dev/null +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/document/InternalApiBridge.java @@ -0,0 +1,33 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.document; + +import net.sourceforge.pmd.annotation.InternalApi; +import net.sourceforge.pmd.lang.LanguageVersionDiscoverer; +import net.sourceforge.pmd.util.log.PmdReporter; + +/** + * Internal API. + * + *

Acts as a bridge between outer parts of PMD and the restricted access + * internal API of this package. + * + *

None of this is published API, and compatibility can be broken anytime! + * Use this only at your own risk. + * + * @apiNote Internal API + */ +@InternalApi +public final class InternalApiBridge { + private InternalApiBridge() {} + + public static FileCollector newCollector(LanguageVersionDiscoverer discoverer, PmdReporter reporter) { + return FileCollector.newCollector(discoverer, reporter); + } + + public static FileCollector newCollector(FileCollector collector, PmdReporter reporter) { + return collector.newCollector(reporter); + } +} diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/cli/PMDFilelistTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/cli/PMDFilelistTest.java index 8e49b3be93..19b6b7eed1 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/cli/PMDFilelistTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/cli/PMDFilelistTest.java @@ -24,6 +24,7 @@ import net.sourceforge.pmd.internal.util.IOUtil; import net.sourceforge.pmd.lang.LanguageRegistry; import net.sourceforge.pmd.lang.LanguageVersionDiscoverer; import net.sourceforge.pmd.lang.document.FileCollector; +import net.sourceforge.pmd.lang.document.InternalApiBridge; import net.sourceforge.pmd.lang.document.TextFile; import net.sourceforge.pmd.util.log.PmdReporter; @@ -32,7 +33,7 @@ class PMDFilelistTest { private static final Path RESOURCES = Paths.get("src/test/resources/net/sourceforge/pmd/cli/"); private @NonNull FileCollector newCollector() { - return FileCollector.newCollector(new LanguageVersionDiscoverer(LanguageRegistry.PMD), PmdReporter.quiet()); + return InternalApiBridge.newCollector(new LanguageVersionDiscoverer(LanguageRegistry.PMD), PmdReporter.quiet()); } @Test From 68d4561544053b2ce4125025f5722c07a64a0bb7 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 10 Feb 2024 10:51:19 +0100 Subject: [PATCH 34/37] [core] Consolidate internal api in XPath Attribute Attribute#replacementIfDeprecated --- docs/pages/release_notes.md | 2 ++ .../pmd/lang/rule/xpath/Attribute.java | 4 +-- .../lang/rule/xpath/InternalApiBridge.java | 27 +++++++++++++++++++ .../xpath/internal/DeprecatedAttrLogger.java | 5 ++-- 4 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/InternalApiBridge.java diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 369b867bb9..5c3267e567 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -323,6 +323,8 @@ package or made (package) private and are _not accessible_ anymore. * Method `newCollector(LanguageVersionDiscoverer, PmdReporter)` is now package private. * Method `newCollector(PmdReporter)` is now package private. * In order to create a FileCollector, use {%jdoc core::PmdAnalysis#files() %} instead. + * {%jdoc !!core::lang.rule.xpath.Attribute %} + * Method `replacementIfDeprecated()` is now package private. * pmd-ant * {%jdoc !!ant::ant.Formatter %} * Method `getRenderer()` has been removed. diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/Attribute.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/Attribute.java index 9ddcb218aa..3b032e558f 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/Attribute.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/Attribute.java @@ -15,7 +15,6 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.ast.Node; /** @@ -102,8 +101,7 @@ public final class Attribute { * * @apiNote Internal API */ - @InternalApi - public String replacementIfDeprecated() { + String replacementIfDeprecated() { if (method == null) { return null; } else { diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/InternalApiBridge.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/InternalApiBridge.java new file mode 100644 index 0000000000..bad7bf8168 --- /dev/null +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/InternalApiBridge.java @@ -0,0 +1,27 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.rule.xpath; + +import net.sourceforge.pmd.annotation.InternalApi; + +/** + * Internal API. + * + *

Acts as a bridge between outer parts of PMD and the restricted access + * internal API of this package. + * + *

None of this is published API, and compatibility can be broken anytime! + * Use this only at your own risk. + * + * @apiNote Internal API + */ +@InternalApi +public final class InternalApiBridge { + private InternalApiBridge() {} + + public static String replacementIfDeprecated(Attribute attribute) { + return attribute.replacementIfDeprecated(); + } +} diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/internal/DeprecatedAttrLogger.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/internal/DeprecatedAttrLogger.java index 1190e0235e..96199993b9 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/internal/DeprecatedAttrLogger.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/xpath/internal/DeprecatedAttrLogger.java @@ -12,6 +12,7 @@ import org.slf4j.LoggerFactory; import net.sourceforge.pmd.lang.rule.Rule; import net.sourceforge.pmd.lang.rule.xpath.Attribute; +import net.sourceforge.pmd.lang.rule.xpath.InternalApiBridge; import net.sourceforge.pmd.lang.rule.xpath.XPathRule; /** @@ -84,7 +85,7 @@ public abstract class DeprecatedAttrLogger { @Override public void recordUsageOf(Attribute attribute) { - String replacement = attribute.replacementIfDeprecated(); + String replacement = InternalApiBridge.replacementIfDeprecated(attribute); if (replacement != null) { String name = getLoggableAttributeName(attribute); Boolean b = deprecated.putIfAbsent(name, Boolean.TRUE); @@ -116,7 +117,7 @@ public abstract class DeprecatedAttrLogger { private static final class AdhocLoggerImpl extends DeprecatedAttrLogger { @Override public void recordUsageOf(Attribute attribute) { - String replacement = attribute.replacementIfDeprecated(); + String replacement = InternalApiBridge.replacementIfDeprecated(attribute); if (replacement != null) { String name = getLoggableAttributeName(attribute); // this message needs to be kept in sync with PMDCoverageTest / BinaryDistributionIT From 5705847594f5b24579b30ce161ece5bddab3ff0d Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 10 Feb 2024 11:08:02 +0100 Subject: [PATCH 35/37] [core] Consolidate internal api in properties PropertyTypeId - moved to internal PropertyDescriptor#getTypeId --- docs/pages/release_notes.md | 2 + docs/pages/release_notes_old.md | 4 +- docs/pages/release_notes_pmd7.md | 6 +-- .../pmd/lang/rule/RuleFactory.java | 4 +- .../pmd/lang/rule/RuleSetWriter.java | 5 ++- .../pmd/properties/ConstraintDecorator.java | 1 + .../pmd/properties/InternalApiBridge.java | 41 +++++++++++++++++++ .../pmd/properties/PropertyBuilder.java | 2 + .../pmd/properties/PropertyDescriptor.java | 6 +-- .../pmd/properties/PropertyFactory.java | 3 +- .../{ => internal}/PropertyParsingUtil.java | 8 +++- .../{ => internal}/PropertyTypeId.java | 12 ++++-- .../{ => internal}/ValueSyntax.java | 6 ++- .../properties/PropertyDescriptorTest.java | 2 + .../pmd/properties/PropertySyntaxTest.java | 1 + 15 files changed, 82 insertions(+), 21 deletions(-) create mode 100644 pmd-core/src/main/java/net/sourceforge/pmd/properties/InternalApiBridge.java rename pmd-core/src/main/java/net/sourceforge/pmd/properties/{ => internal}/PropertyParsingUtil.java (95%) rename pmd-core/src/main/java/net/sourceforge/pmd/properties/{ => internal}/PropertyTypeId.java (90%) rename pmd-core/src/main/java/net/sourceforge/pmd/properties/{ => internal}/ValueSyntax.java (92%) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 5c3267e567..c03cdc0c10 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -325,6 +325,8 @@ package or made (package) private and are _not accessible_ anymore. * In order to create a FileCollector, use {%jdoc core::PmdAnalysis#files() %} instead. * {%jdoc !!core::lang.rule.xpath.Attribute %} * Method `replacementIfDeprecated()` is now package private. + * `net.sourceforge.pmd.properties.PropertyTypeId` - moved in subpackage `internal`. + * {%jdoc !!core::properties.PropertyDescriptor %} - method `getTypeId()` is now package private. * pmd-ant * {%jdoc !!ant::ant.Formatter %} * Method `getRenderer()` has been removed. diff --git a/docs/pages/release_notes_old.md b/docs/pages/release_notes_old.md index 478e5781c5..91d377b154 100644 --- a/docs/pages/release_notes_old.md +++ b/docs/pages/release_notes_old.md @@ -225,8 +225,8 @@ The following previously deprecated methods have been removed: * pmd-core * `net.sourceforge.pmd.properties.PropertyBuilder.GenericCollectionPropertyBuilder#delim(char)` * `net.sourceforge.pmd.properties.PropertySource#setProperty(...)` - * `net.sourceforge.pmd.properties.PropertyTypeId#factoryFor(...)` - * `net.sourceforge.pmd.properties.PropertyTypeId#typeIdFor(...)` + * `net.sourceforge.pmd.properties.internal.PropertyTypeId#factoryFor(...)` + * `net.sourceforge.pmd.properties.internal.PropertyTypeId#typeIdFor(...)` * `net.sourceforge.pmd.properties.PropertyDescriptor`: removed methods errorFor, type, isMultiValue, uiOrder, compareTo, isDefinedExternally, valueFrom, asDelimitedString diff --git a/docs/pages/release_notes_pmd7.md b/docs/pages/release_notes_pmd7.md index cf71d941ff..432368536d 100644 --- a/docs/pages/release_notes_pmd7.md +++ b/docs/pages/release_notes_pmd7.md @@ -815,8 +815,8 @@ The following previously deprecated methods have been removed: * pmd-core * `net.sourceforge.pmd.properties.PropertyBuilder.GenericCollectionPropertyBuilder#delim(char)` * `net.sourceforge.pmd.properties.PropertySource#setProperty(...)` - * `net.sourceforge.pmd.properties.PropertyTypeId#factoryFor(...)` - * `net.sourceforge.pmd.properties.PropertyTypeId#typeIdFor(...)` + * `net.sourceforge.pmd.properties.internal.PropertyTypeId#factoryFor(...)` + * `net.sourceforge.pmd.properties.internal.PropertyTypeId#typeIdFor(...)` * `net.sourceforge.pmd.properties.PropertyDescriptor`: removed methods errorFor, type, isMultiValue, uiOrder, compareTo, isDefinedExternally, valueFrom, asDelimitedString @@ -899,7 +899,7 @@ The following classes have been removed: ##### Internal APIs * {% jdoc core::cpd.Tokens %} -* {% jdoc core::net.sourceforge.pmd.properties.PropertyTypeId %} +* {% jdoc core::net.sourceforge.pmd.properties.internal.PropertyTypeId %} ##### Deprecated API diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleFactory.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleFactory.java index 23a4448936..59fd687c22 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleFactory.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleFactory.java @@ -51,8 +51,8 @@ import net.sourceforge.pmd.properties.PropertyBuilder; import net.sourceforge.pmd.properties.PropertyConstraint; import net.sourceforge.pmd.properties.PropertyDescriptor; import net.sourceforge.pmd.properties.PropertySerializer; -import net.sourceforge.pmd.properties.PropertyTypeId; -import net.sourceforge.pmd.properties.PropertyTypeId.BuilderAndMapper; +import net.sourceforge.pmd.properties.internal.PropertyTypeId; +import net.sourceforge.pmd.properties.internal.PropertyTypeId.BuilderAndMapper; import net.sourceforge.pmd.util.StringUtil; import net.sourceforge.pmd.util.internal.ResourceLoader; import net.sourceforge.pmd.util.internal.xml.PmdXmlReporter; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleSetWriter.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleSetWriter.java index 66fedc4333..6c96e08ea2 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleSetWriter.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleSetWriter.java @@ -35,11 +35,12 @@ import net.sourceforge.pmd.internal.util.IOUtil; import net.sourceforge.pmd.lang.Language; import net.sourceforge.pmd.lang.LanguageVersion; import net.sourceforge.pmd.lang.rule.internal.RuleSetReference; +import net.sourceforge.pmd.properties.InternalApiBridge; import net.sourceforge.pmd.properties.PropertyConstraint; import net.sourceforge.pmd.properties.PropertyDescriptor; import net.sourceforge.pmd.properties.PropertySerializer; import net.sourceforge.pmd.properties.PropertySource; -import net.sourceforge.pmd.properties.PropertyTypeId; +import net.sourceforge.pmd.properties.internal.PropertyTypeId; import net.sourceforge.pmd.util.internal.xml.SchemaConstants; /** @@ -269,7 +270,7 @@ public class RuleSetWriter { for (PropertyDescriptor descriptor : defined) { // For each provided PropertyDescriptor - PropertyTypeId typeId = descriptor.getTypeId(); + PropertyTypeId typeId = InternalApiBridge.getTypeId(descriptor); if (typeId == null // not defined externally && !overridden.contains(descriptor)) { diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/properties/ConstraintDecorator.java b/pmd-core/src/main/java/net/sourceforge/pmd/properties/ConstraintDecorator.java index 7c42c30d0f..802c20ef61 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/properties/ConstraintDecorator.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/properties/ConstraintDecorator.java @@ -8,6 +8,7 @@ import java.util.List; import org.checkerframework.checker.nullness.qual.NonNull; +import net.sourceforge.pmd.properties.internal.PropertyParsingUtil; import net.sourceforge.pmd.util.CollectionUtil; /** diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/properties/InternalApiBridge.java b/pmd-core/src/main/java/net/sourceforge/pmd/properties/InternalApiBridge.java new file mode 100644 index 0000000000..b9647e6554 --- /dev/null +++ b/pmd-core/src/main/java/net/sourceforge/pmd/properties/InternalApiBridge.java @@ -0,0 +1,41 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.properties; + +import org.checkerframework.checker.nullness.qual.Nullable; + +import net.sourceforge.pmd.annotation.InternalApi; +import net.sourceforge.pmd.properties.internal.PropertyTypeId; + +/** + * Internal API. + * + *

Acts as a bridge between outer parts of PMD and the restricted access + * internal API of this package. + * + *

None of this is published API, and compatibility can be broken anytime! + * Use this only at your own risk. + * + * @apiNote Internal API + */ +@InternalApi +public final class InternalApiBridge { + private InternalApiBridge() {} + + public static > B withTypeId(PropertyBuilder builder, PropertyTypeId typeId) { + return builder.typeId(typeId); + } + + public static @Nullable PropertyTypeId getTypeId(PropertyDescriptor propertyDescriptor) { + return propertyDescriptor.getTypeId(); + } + + public abstract static class InternalPropertySerializer extends PropertySerializer { + // make the default constructor available + protected InternalPropertySerializer() { + super(); + } + } +} diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyBuilder.java b/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyBuilder.java index 9d6f8711f4..6c251dd887 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyBuilder.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyBuilder.java @@ -18,6 +18,8 @@ import org.apache.commons.lang3.StringUtils; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; +import net.sourceforge.pmd.properties.internal.PropertyParsingUtil; +import net.sourceforge.pmd.properties.internal.PropertyTypeId; import net.sourceforge.pmd.util.AssertionUtil; import net.sourceforge.pmd.util.CollectionUtil; import net.sourceforge.pmd.util.IteratorUtil; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyDescriptor.java b/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyDescriptor.java index b9100c8f4c..e640284f72 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyDescriptor.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyDescriptor.java @@ -8,8 +8,9 @@ import java.util.Objects; import org.checkerframework.checker.nullness.qual.Nullable; -import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.rule.RuleSetWriter; +import net.sourceforge.pmd.properties.internal.PropertyParsingUtil; +import net.sourceforge.pmd.properties.internal.PropertyTypeId; /** @@ -107,8 +108,7 @@ public final class PropertyDescriptor { * * @apiNote Internal API */ - @InternalApi - public @Nullable PropertyTypeId getTypeId() { + @Nullable PropertyTypeId getTypeId() { return typeId; } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyFactory.java b/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyFactory.java index 8085355b06..0d9d662fc5 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyFactory.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyFactory.java @@ -5,7 +5,7 @@ package net.sourceforge.pmd.properties; import static java.util.Arrays.asList; -import static net.sourceforge.pmd.properties.PropertyParsingUtil.enumerationParser; +import static net.sourceforge.pmd.properties.internal.PropertyParsingUtil.enumerationParser; import java.util.Arrays; import java.util.List; @@ -19,6 +19,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import net.sourceforge.pmd.properties.PropertyBuilder.GenericCollectionPropertyBuilder; import net.sourceforge.pmd.properties.PropertyBuilder.GenericPropertyBuilder; import net.sourceforge.pmd.properties.PropertyBuilder.RegexPropertyBuilder; +import net.sourceforge.pmd.properties.internal.PropertyParsingUtil; import net.sourceforge.pmd.util.CollectionUtil; //@formatter:off diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyParsingUtil.java b/pmd-core/src/main/java/net/sourceforge/pmd/properties/internal/PropertyParsingUtil.java similarity index 95% rename from pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyParsingUtil.java rename to pmd-core/src/main/java/net/sourceforge/pmd/properties/internal/PropertyParsingUtil.java index 3a18dbded8..7966886f59 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyParsingUtil.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/properties/internal/PropertyParsingUtil.java @@ -2,7 +2,7 @@ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ -package net.sourceforge.pmd.properties; +package net.sourceforge.pmd.properties.internal; import java.util.ArrayList; @@ -15,13 +15,17 @@ import java.util.regex.Pattern; import java.util.stream.Collector; import java.util.stream.Collectors; +import net.sourceforge.pmd.properties.ConstraintViolatedException; +import net.sourceforge.pmd.properties.PropertyConstraint; +import net.sourceforge.pmd.properties.PropertyFactory; +import net.sourceforge.pmd.properties.PropertySerializer; import net.sourceforge.pmd.util.IteratorUtil; import net.sourceforge.pmd.util.internal.xml.XmlUtil; /** * This is internal API and shouldn't be used directly by clients. */ -final class PropertyParsingUtil { +public final class PropertyParsingUtil { public static final ValueSyntax STRING = ValueSyntax.withDefaultToString(String::trim); public static final ValueSyntax CHARACTER = diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyTypeId.java b/pmd-core/src/main/java/net/sourceforge/pmd/properties/internal/PropertyTypeId.java similarity index 90% rename from pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyTypeId.java rename to pmd-core/src/main/java/net/sourceforge/pmd/properties/internal/PropertyTypeId.java index 972f9204c0..0b6f6f2184 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/properties/PropertyTypeId.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/properties/internal/PropertyTypeId.java @@ -2,14 +2,17 @@ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ -package net.sourceforge.pmd.properties; +package net.sourceforge.pmd.properties.internal; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.function.Function; -import net.sourceforge.pmd.annotation.InternalApi; +import net.sourceforge.pmd.properties.InternalApiBridge; +import net.sourceforge.pmd.properties.PropertyBuilder; +import net.sourceforge.pmd.properties.PropertyFactory; +import net.sourceforge.pmd.properties.PropertySerializer; /** @@ -27,7 +30,6 @@ import net.sourceforge.pmd.annotation.InternalApi; * @since 6.0.0 * @apiNote Internal API */ -@InternalApi public enum PropertyTypeId { // These are exclusively used for XPath rules. It would make more sense to model the supported // property types around XML Schema Datatypes (XSD) 1.0 or 1.1 instead of Java datatypes (save for @@ -100,7 +102,9 @@ public enum PropertyTypeId { @Override public PropertyBuilder newBuilder(String name) { - return factory.apply(name).typeId(PropertyTypeId.this).availableInXPath(true); + PropertyBuilder builder = factory.apply(name); + builder = InternalApiBridge.withTypeId(builder, PropertyTypeId.this); + return builder.availableInXPath(true); } }; } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/properties/ValueSyntax.java b/pmd-core/src/main/java/net/sourceforge/pmd/properties/internal/ValueSyntax.java similarity index 92% rename from pmd-core/src/main/java/net/sourceforge/pmd/properties/ValueSyntax.java rename to pmd-core/src/main/java/net/sourceforge/pmd/properties/internal/ValueSyntax.java index 5192e458d8..61f37251dd 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/properties/ValueSyntax.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/properties/internal/ValueSyntax.java @@ -2,7 +2,7 @@ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ -package net.sourceforge.pmd.properties; +package net.sourceforge.pmd.properties.internal; import static net.sourceforge.pmd.util.CollectionUtil.listOf; @@ -14,6 +14,8 @@ import java.util.function.Function; import org.checkerframework.checker.nullness.qual.NonNull; import net.sourceforge.pmd.internal.util.PredicateUtil; +import net.sourceforge.pmd.properties.InternalApiBridge; +import net.sourceforge.pmd.properties.PropertyConstraint; /** * Serialize to and from a simple string. Examples: @@ -27,7 +29,7 @@ import net.sourceforge.pmd.internal.util.PredicateUtil; *

This class is special because it enables compatibility with the
  * pre 7.0.0 XML syntax.
  */
-class ValueSyntax extends PropertySerializer {
+class ValueSyntax extends InternalApiBridge.InternalPropertySerializer {
 
     private final Function toString;
     private final Function<@NonNull String, ? extends T> fromString;
diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/properties/PropertyDescriptorTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/properties/PropertyDescriptorTest.java
index a8ff1dbafa..89a8788ef2 100644
--- a/pmd-core/src/test/java/net/sourceforge/pmd/properties/PropertyDescriptorTest.java
+++ b/pmd-core/src/test/java/net/sourceforge/pmd/properties/PropertyDescriptorTest.java
@@ -27,6 +27,8 @@ import org.hamcrest.Matchers;
 import org.hamcrest.core.SubstringMatcher;
 import org.junit.jupiter.api.Test;
 
+import net.sourceforge.pmd.properties.internal.PropertyParsingUtil;
+
 
 /**
  * @author Clément Fournier
diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/properties/PropertySyntaxTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/properties/PropertySyntaxTest.java
index a0ce4f10fd..387490202c 100644
--- a/pmd-core/src/test/java/net/sourceforge/pmd/properties/PropertySyntaxTest.java
+++ b/pmd-core/src/test/java/net/sourceforge/pmd/properties/PropertySyntaxTest.java
@@ -15,6 +15,7 @@ import org.junit.jupiter.api.Test;
 
 import net.sourceforge.pmd.lang.rule.Rule;
 import net.sourceforge.pmd.lang.rule.RulesetFactoryTestBase;
+import net.sourceforge.pmd.properties.internal.PropertyParsingUtil;
 import net.sourceforge.pmd.util.internal.xml.XmlErrorMessages;
 
 /**

From dc4d195d77f4be0be26939d9f41457cfb71ac4d9 Mon Sep 17 00:00:00 2001
From: Andreas Dangel 
Date: Sat, 10 Feb 2024 11:13:14 +0100
Subject: [PATCH 36/37] [doc] Fix javadoc for moved classes

---
 docs/pages/release_notes.md | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md
index c03cdc0c10..611fec52a1 100644
--- a/docs/pages/release_notes.md
+++ b/docs/pages/release_notes.md
@@ -291,11 +291,11 @@ package or made (package) private and are _not accessible_ anymore.
   * {%jdoc !!core::lang.rule.RuleTargetSelector %}
     * Method `isRuleChain()` has been removed.
   * {%jdoc !!core::renderers.AbstractAccumulatingRenderer %}
-    * {%jdoc core::renderers.AbstractAccumulatingRenderer#renderFileReport(core::Report) %} - this method is now final
+    * {%jdoc core::renderers.AbstractAccumulatingRenderer#renderFileReport(core::reporting.Report) %} - this method is now final
       and can't be overridden anymore.
-  * {%jdoc !!core::Report %}
+  * {%jdoc !!core::reporting.Report %}
     * Constructor as well as the methods `addRuleViolation`, `addConfigError`, `addError` are now private.
-  * {%jdoc !!core::RuleContext %}
+  * {%jdoc !!core::reporting.RuleContext %}
     * Method `getRule()` is now package private.
     * Method `create(FileAnalysisListener listener, Rule rule)` has been removed.
   * `net.sourceforge.pmd.rules.RuleFactory`: moved into subpackage `lang.rule` and made package private.

From b0818362e759861066680b647a3b00e660fc07ae Mon Sep 17 00:00:00 2001
From: Andreas Dangel 
Date: Sat, 10 Feb 2024 11:56:22 +0100
Subject: [PATCH 37/37] [ant] Add javadoc, internalize ReportException

---
 docs/pages/release_notes.md                       |  1 +
 .../java/net/sourceforge/pmd/ant/Formatter.java   | 15 +++++++++++++++
 .../net/sourceforge/pmd/ant/ReportException.java  |  5 +++--
 .../net/sourceforge/pmd/ant/RuleSetWrapper.java   | 15 +++++++++++++++
 .../net/sourceforge/pmd/ant/SourceLanguage.java   | 14 +++++++++++++-
 5 files changed, 47 insertions(+), 3 deletions(-)

diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md
index 611fec52a1..5a966084d7 100644
--- a/docs/pages/release_notes.md
+++ b/docs/pages/release_notes.md
@@ -336,6 +336,7 @@ package or made (package) private and are _not accessible_ anymore.
     * Method `newListener(Project)` is now package private.
   * {%jdoc !!ant::ant.PMDTask %}
     * Method `getRelativizeRoots()` has been removed.
+  * `net.sourceforge.pmd.ant.ReportException` is now package private. Note: It was not marked with @InternalApi before.
 * pmd-apex
   * {%jdoc !!apex::ast.ApexNode %}
     * Method `getNode()` has been removed. It was only deprecated before and not marked with @InternalApi.
diff --git a/pmd-ant/src/main/java/net/sourceforge/pmd/ant/Formatter.java b/pmd-ant/src/main/java/net/sourceforge/pmd/ant/Formatter.java
index aed668a2e1..cd36777ca9 100644
--- a/pmd-ant/src/main/java/net/sourceforge/pmd/ant/Formatter.java
+++ b/pmd-ant/src/main/java/net/sourceforge/pmd/ant/Formatter.java
@@ -35,6 +35,21 @@ import net.sourceforge.pmd.reporting.FileNameRenderer;
 import net.sourceforge.pmd.reporting.GlobalAnalysisListener;
 import net.sourceforge.pmd.reporting.ListenerInitializer;
 
+/**
+ * Part of PMD Ant task configuration. Setters of this class are interpreted by Ant as properties
+ * settable in the XML. This is therefore published API.
+ *
+ * 

This class is used to configure a specific {@link Renderer} for outputting the violations. This is called + * a formatter in PMD Ant task configuration and might look like this: + * + *

{@code
+ * 
+ *   
+ * 
+ * }
+ * + * @see PMDTask#addFormatter(Formatter) + */ public class Formatter { private File toFile; diff --git a/pmd-ant/src/main/java/net/sourceforge/pmd/ant/ReportException.java b/pmd-ant/src/main/java/net/sourceforge/pmd/ant/ReportException.java index 258dcfae86..d4737e9928 100644 --- a/pmd-ant/src/main/java/net/sourceforge/pmd/ant/ReportException.java +++ b/pmd-ant/src/main/java/net/sourceforge/pmd/ant/ReportException.java @@ -6,11 +6,12 @@ package net.sourceforge.pmd.ant; /** * @author Philippe T'Seyen + * @apiNote Internal API */ -public class ReportException extends RuntimeException { +class ReportException extends RuntimeException { private static final long serialVersionUID = 6043174086675858209L; - public ReportException(Throwable cause) { + ReportException(Throwable cause) { super(cause); } } diff --git a/pmd-ant/src/main/java/net/sourceforge/pmd/ant/RuleSetWrapper.java b/pmd-ant/src/main/java/net/sourceforge/pmd/ant/RuleSetWrapper.java index 8943e0f772..031ba15b21 100644 --- a/pmd-ant/src/main/java/net/sourceforge/pmd/ant/RuleSetWrapper.java +++ b/pmd-ant/src/main/java/net/sourceforge/pmd/ant/RuleSetWrapper.java @@ -4,6 +4,21 @@ package net.sourceforge.pmd.ant; +/** + * Part of PMD Ant task configuration. Setters of this class are interpreted by Ant as properties + * settable in the XML. This is therefore published API. + * + *

This class is used to configure {@link net.sourceforge.pmd.lang.rule.RuleSet} as nested XML tags. + * It might look like this: + * + *

{@code
+ * 
+ *   rulesets/java/quickstart.xml
+ * 
+ * }
+ * + * @see PMDTask#addRuleset(RuleSetWrapper) + */ public class RuleSetWrapper { private String file; diff --git a/pmd-ant/src/main/java/net/sourceforge/pmd/ant/SourceLanguage.java b/pmd-ant/src/main/java/net/sourceforge/pmd/ant/SourceLanguage.java index 75310e3f0f..c1c81aa12a 100644 --- a/pmd-ant/src/main/java/net/sourceforge/pmd/ant/SourceLanguage.java +++ b/pmd-ant/src/main/java/net/sourceforge/pmd/ant/SourceLanguage.java @@ -7,7 +7,19 @@ package net.sourceforge.pmd.ant; import net.sourceforge.pmd.lang.Language; /** - * Stores LanguageVersion terse name value. + * Part of PMD Ant task configuration. Setters of this class are interpreted by Ant as properties + * settable in the XML. This is therefore published API. + * + *

This class is used to configure the language and version to use. + * It might look like this: + * + *

{@code
+ * 
+ *   
+ * 
+ * }
+ * + * @see PMDTask#addConfiguredSourceLanguage(SourceLanguage) */ public class SourceLanguage {