Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Consolidate @InternalApi classes #4809

Merged
merged 38 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
906baf9
[core] Internalize AnalysisCache and related types
adangel Jan 26, 2024
3a5ff11
[core] Rename MessageReporter to PmdReporter as public API
adangel Jan 26, 2024
daef0cd
[core] Move n.s.pmd.util.internal.ResourceLoader
adangel Jan 27, 2024
db0392c
[core] n.s.pmd.cpd.Tokens#Tokens() is now package private
adangel Jan 27, 2024
217f0f4
[core] PropertyTypeId and PropertyDescriptor#getTypeId
adangel Jan 27, 2024
4f8d094
[core] FileCollector - factories stay internal, other methods are now…
adangel Jan 27, 2024
932c2e3
[core] XPath Attribute#replacementIfDeprecated stays Internal API
adangel Jan 27, 2024
a0a289f
[core] RuleTargetSelector#isRuleChain removed
adangel Jan 27, 2024
bc31401
[core] LanguageProcessor.AnalysisTask#withFiles now internal
adangel Jan 28, 2024
8b8b11d
[core] AbstractAccumulatingRenderer#renderFileReport(Report) is final
adangel Jan 28, 2024
589d144
[core] Report - ctor and addRuleViolation, addConfigError, addError a…
adangel Jan 28, 2024
627fef1
[core] RuleContext - remove getRule(), create()
adangel Jan 28, 2024
e3cf1c6
[core] RuleContext - addViolationNoSuppress()
adangel Jan 28, 2024
2f47edf
[ant] Cleanup InternalApi methods
adangel Jan 30, 2024
7ec2bc4
[apex] Cleanup InternalApi methods
adangel Jan 30, 2024
35db84a
[java] Cleanup InternalApi methods
adangel Feb 1, 2024
3ff3f5b
[jsp] Cleanup InternalApi methods
adangel Feb 1, 2024
1997984
[modelica] Cleanup InternalApi methods
adangel Feb 1, 2024
8285d70
[plsql] Cleanup InternalApi methods
adangel Feb 1, 2024
d1c3212
[scala] Cleanup InternalApi methods
adangel Feb 1, 2024
5e9ba14
[visualforce] Cleanup InternalApi methods
adangel Feb 1, 2024
4978e66
Fix javadoc generation - exclude also sub-packages of internal
adangel Feb 1, 2024
d2ae17a
[doc] Mark ADR 3 accepted
adangel Feb 1, 2024
7c34085
[doc] Fix javadoc links in release notes
adangel Feb 1, 2024
83879dc
[core] Hide internal API methods in LanguageProcessor.AnalysisTask
adangel Feb 1, 2024
fae522a
[core] Unify javadoc for InternalApiBridge classes
adangel Feb 1, 2024
7cd94eb
[core] Cleanup javadoc regarding InternalApi
adangel Feb 1, 2024
7ca9934
[doc] Update release notes
adangel Feb 1, 2024
bc5be45
Merge branch 'master' into issue-4348-internal-api
adangel Feb 9, 2024
72edaee
[core] Internalize ParametricRuleViolation
adangel Feb 9, 2024
7c5bf74
[core] Consolidate internal api in n.s.p.lang.rule
adangel Feb 10, 2024
2cc9ae9
[core] Consolidate internal api in LexException
adangel Feb 10, 2024
3a635da
[core] Consolidate internal api in PMDConfiguration
adangel Feb 10, 2024
5e92b59
[core] Consolidate internal api in FileCollector
adangel Feb 10, 2024
68d4561
[core] Consolidate internal api in XPath Attribute
adangel Feb 10, 2024
5705847
[core] Consolidate internal api in properties
adangel Feb 10, 2024
dc4d195
[doc] Fix javadoc for moved classes
adangel Feb 10, 2024
b081836
[ant] Add javadoc, internalize ReportException
adangel Feb 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions docs/pages/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,55 @@ in the Migration Guide.

#### API Changes

**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.

* 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
* 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.
* 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**

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:
Expand Down Expand Up @@ -181,6 +230,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.
Expand Down
39 changes: 3 additions & 36 deletions pmd-ant/src/main/java/net/sourceforge/pmd/ant/Formatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
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;
Expand All @@ -37,7 +35,6 @@
import net.sourceforge.pmd.reporting.GlobalAnalysisListener;
import net.sourceforge.pmd.reporting.ListenerInitializer;

@InternalApi
public class Formatter {
adangel marked this conversation as resolved.
Show resolved Hide resolved

private File toFile;
Expand Down Expand Up @@ -68,15 +65,7 @@ public void addConfiguredParam(Parameter parameter) {
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();

Expand Down Expand Up @@ -122,25 +111,7 @@ public void start(String baseDir) {
}
}

@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;
}

Expand Down Expand Up @@ -248,12 +219,8 @@ private static String getNativeConsoleEncoding() {
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();

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
14 changes: 0 additions & 14 deletions pmd-ant/src/main/java/net/sourceforge/pmd/ant/PMDTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,10 +14,8 @@
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;

/**
Expand Down Expand Up @@ -299,15 +296,4 @@ public void addRelativizePathsWith(Path relativizePathsWith) {
public List<Path> getRelativizePathsWith() {
return relativizePathsWith;
}

@InternalApi
public List<java.nio.file.Path> getRelativizeRoots() {
List<java.nio.file.Path> paths = new ArrayList<>();
for (Path path : getRelativizePathsWith()) {
for (Resource resource : path) {
paths.add(Paths.get(resource.toString()));
}
}
return paths;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,6 +17,7 @@
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;
Expand All @@ -26,6 +28,7 @@
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;
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -97,6 +100,17 @@ public PMDTaskImpl(PMDTask task) {
project = task.getProject();
}

private static List<java.nio.file.Path> getRelativizeRoots(PMDTask pmdTask) {
List<java.nio.file.Path> paths = new ArrayList<>();
for (Path path : pmdTask.getRelativizePathsWith()) {
for (Resource resource : path) {
paths.add(Paths.get(resource.toString()));
}
}
return paths;
}


private void doTask() {
setupClassLoader();

Expand Down Expand Up @@ -161,7 +175,7 @@ private List<String> expandRuleSetPaths(List<String> ruleSetPaths) {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

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
Expand All @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ void closeNode(TextDocument document) {

@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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

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;
Expand Down Expand Up @@ -89,10 +88,7 @@ protected void setRegion(TextRegion region) {
this.region = region;
}

@Deprecated
@InternalApi
@Override
public T getNode() {
T getNode() {
return node;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

/**
* Root interface implemented by all Apex nodes. Apex nodes wrap a tree
* obtained from an external parser (Jorje). The underlying AST node is
* available with {@link #getNode()}.
* obtained from an external parser (Jorje).
*
* @param <T> Type of the underlying Jorje node
*/
Expand All @@ -33,16 +32,6 @@ default Object jjtAccept(ApexParserVisitor visitor, Object data) {
}


/**
* 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();


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,7 +13,6 @@
import apex.jorje.data.Locations;
import apex.jorje.semantic.ast.compilation.Compilation;

@InternalApi
public final class ApexParser implements Parser {

public ApexParser() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ private void closeTree(AbstractApexNode<?> node) {
}
}

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
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;

Expand Down Expand Up @@ -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);

Expand Down
Loading