From 19f9bdde5f33575a61a5d88979840016be6e375d Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 2 Feb 2024 14:41:45 +0100 Subject: [PATCH] [core] Remove deprecated classes/methods CpdLanguageProperties#DEFAULT_SKIP_BLOCKS_PATTERN BaseAntlrNode#joinTextToken Node#getNthParent Node#getFirstChildOfType --- docs/pages/release_notes.md | 7 ++++ .../java/net/sourceforge/pmd/ant/CPDTask.java | 3 +- .../pmd/cli/commands/internal/CpdCommand.java | 4 +-- .../sourceforge/pmd/cpd/CPDConfiguration.java | 3 +- .../sourceforge/pmd/cpd/CPDConfiguration.java | 3 +- .../pmd/cpd/CpdLanguageProperties.java | 4 --- .../CpdLanguagePropertiesDefaults.java | 18 ++++++++++ .../sourceforge/pmd/internal/LogMessages.java | 5 --- .../net/sourceforge/pmd/lang/ast/Node.java | 34 ------------------- .../sourceforge/pmd/lang/ast/NodeStream.java | 4 +-- .../pmd/lang/ast/impl/GenericNode.java | 5 --- .../lang/ast/impl/antlr4/BaseAntlrNode.java | 13 ------- .../pmd/lang/ast/internal/NodeStreamTest.java | 8 ++--- .../pmd/lang/cpp/CppLanguageModule.java | 3 +- .../pmd/lang/java/ast/ASTClassType.java | 2 +- .../pmd/lang/java/ast/ASTVariableId.java | 8 ++--- .../bestpractices/UnusedAssignmentRule.java | 2 +- ...oidBranchingStatementAsLastInLoopRule.java | 2 +- .../lang/java/types/ast/LazyTypeResolver.java | 2 +- .../plsql/rule/codestyle/CodeFormatRule.java | 4 +-- 20 files changed, 50 insertions(+), 84 deletions(-) create mode 100644 pmd-core/src/main/java/net/sourceforge/pmd/cpd/internal/CpdLanguagePropertiesDefaults.java diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index fca52bee88..42c59cf01e 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -180,6 +180,13 @@ The following previously deprecated rules have been finally removed: The following previously deprecated classes have been removed: +* pmd-core + * {%jdoc !!core::cpd.CpdLanguageProperties %}. The field `DEFAULT_SKIP_BLOCKS_PATTERN` has been removed. + * {%jdoc !!core::lang.ast.impl.antlr4.BaseAntlrNode %} - method `joinTokenText()` has been removed. + * {%jdoc !!core::lang.ast.Node %} - many methods have been removed: + * `getNthParent(int)` - Use {%jdoc core::lang.ast.Node#ancestors() %} instead, e.g. `node.ancestors().get(n-1)` + * `getFirstParentOfType(Class)` - Use {%jdoc core::lang.ast.Node#ancestors(java.lang.Class) %} instead, e.g. `node.ancestors(parentType).first()` + * {%jdoc !!core::lang.ast.impl.GenericNode %} - getNthParent(int) * pmd-apex * {%jdoc apex::lang.apex.ast.ApexNode %} and {% jdoc apex::lang.apex.ast.ASTApexFile %} * `#getApexVersion()`: In PMD 6, this method has been deprecated but was defined in the class `ApexRootNode`. diff --git a/pmd-ant/src/main/java/net/sourceforge/pmd/ant/CPDTask.java b/pmd-ant/src/main/java/net/sourceforge/pmd/ant/CPDTask.java index 85abfdc0ad..607186cb8a 100644 --- a/pmd-ant/src/main/java/net/sourceforge/pmd/ant/CPDTask.java +++ b/pmd-ant/src/main/java/net/sourceforge/pmd/ant/CPDTask.java @@ -28,7 +28,6 @@ import net.sourceforge.pmd.cpd.CPDReport; import net.sourceforge.pmd.cpd.CPDReportRenderer; import net.sourceforge.pmd.cpd.CSVRenderer; import net.sourceforge.pmd.cpd.CpdAnalysis; -import net.sourceforge.pmd.cpd.CpdLanguageProperties; import net.sourceforge.pmd.cpd.SimpleRenderer; import net.sourceforge.pmd.cpd.XMLRenderer; import net.sourceforge.pmd.lang.Language; @@ -79,7 +78,7 @@ public class CPDTask extends Task { private boolean skipLexicalErrors; private boolean skipDuplicateFiles; private boolean skipBlocks = true; - private String skipBlocksPattern = CpdLanguageProperties.DEFAULT_SKIP_BLOCKS_PATTERN; + private String skipBlocksPattern; private File outputFile; private String encoding = System.getProperty("file.encoding"); private List filesets = new ArrayList<>(); diff --git a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/CpdCommand.java b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/CpdCommand.java index 2e71305cef..f15328047b 100644 --- a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/CpdCommand.java +++ b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/CpdCommand.java @@ -17,7 +17,7 @@ import net.sourceforge.pmd.cli.commands.typesupport.internal.CpdLanguageTypeSupp import net.sourceforge.pmd.cli.internal.CliExitCode; import net.sourceforge.pmd.cpd.CPDConfiguration; import net.sourceforge.pmd.cpd.CpdAnalysis; -import net.sourceforge.pmd.cpd.CpdLanguageProperties; +import net.sourceforge.pmd.cpd.internal.CpdLanguagePropertiesDefaults; import net.sourceforge.pmd.internal.LogMessages; import net.sourceforge.pmd.lang.Language; import net.sourceforge.pmd.util.StringUtil; @@ -78,7 +78,7 @@ public class CpdCommand extends AbstractAnalysisPmdSubcommand @Option(names = "--skip-blocks-pattern", description = "Pattern to find the blocks to skip. Start and End pattern separated by |.", - defaultValue = CpdLanguageProperties.DEFAULT_SKIP_BLOCKS_PATTERN) + defaultValue = CpdLanguagePropertiesDefaults.DEFAULT_SKIP_BLOCKS_PATTERN) private String skipBlocksPattern; @Option(names = "--exclude", arity = "1..*", description = "Files to be excluded from the analysis") diff --git a/pmd-compat6/src/main/java/net/sourceforge/pmd/cpd/CPDConfiguration.java b/pmd-compat6/src/main/java/net/sourceforge/pmd/cpd/CPDConfiguration.java index a747e69b2c..c33dd2e3bf 100644 --- a/pmd-compat6/src/main/java/net/sourceforge/pmd/cpd/CPDConfiguration.java +++ b/pmd-compat6/src/main/java/net/sourceforge/pmd/cpd/CPDConfiguration.java @@ -29,6 +29,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.slf4j.LoggerFactory; import net.sourceforge.pmd.AbstractConfiguration; +import net.sourceforge.pmd.cpd.internal.CpdLanguagePropertiesDefaults; import net.sourceforge.pmd.internal.util.FileFinder; import net.sourceforge.pmd.internal.util.FileUtil; import net.sourceforge.pmd.lang.LanguageRegistry; @@ -83,7 +84,7 @@ public class CPDConfiguration extends AbstractConfiguration { private boolean noSkipBlocks = false; - private String skipBlocksPattern = CpdLanguageProperties.DEFAULT_SKIP_BLOCKS_PATTERN; + private String skipBlocksPattern = CpdLanguagePropertiesDefaults.DEFAULT_SKIP_BLOCKS_PATTERN; private boolean help; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CPDConfiguration.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CPDConfiguration.java index 75352ad4db..cfff92b0ca 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CPDConfiguration.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CPDConfiguration.java @@ -19,6 +19,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.slf4j.LoggerFactory; import net.sourceforge.pmd.AbstractConfiguration; +import net.sourceforge.pmd.cpd.internal.CpdLanguagePropertiesDefaults; import net.sourceforge.pmd.lang.LanguageRegistry; import net.sourceforge.pmd.util.log.internal.SimpleMessageReporter; @@ -68,7 +69,7 @@ public class CPDConfiguration extends AbstractConfiguration { private boolean noSkipBlocks = false; - private String skipBlocksPattern = CpdLanguageProperties.DEFAULT_SKIP_BLOCKS_PATTERN; + private String skipBlocksPattern = CpdLanguagePropertiesDefaults.DEFAULT_SKIP_BLOCKS_PATTERN; private boolean help; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CpdLanguageProperties.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CpdLanguageProperties.java index b0dfe68ec2..3561653edf 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CpdLanguageProperties.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CpdLanguageProperties.java @@ -47,8 +47,4 @@ public final class CpdLanguageProperties { .defaultValue(false) .desc("Ignore metadata such as Java annotations or C# attributes.") .build(); - - @Deprecated - // TODO what to do with this? - public static final String DEFAULT_SKIP_BLOCKS_PATTERN = "#if 0|#endif"; } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/internal/CpdLanguagePropertiesDefaults.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/internal/CpdLanguagePropertiesDefaults.java new file mode 100644 index 0000000000..a21cd25091 --- /dev/null +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/internal/CpdLanguagePropertiesDefaults.java @@ -0,0 +1,18 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.cpd.internal; + +public final class CpdLanguagePropertiesDefaults { + private CpdLanguagePropertiesDefaults() {} + + /** + * Default value for the option "cpdSkipBlocksPattern", which is only supported by the + * CppLanguageModule. + * + *

It is already needed in the CLI impl, that's why it needs to be in pmd-core, and not + * in pmd-cpp. + */ + public static final String DEFAULT_SKIP_BLOCKS_PATTERN = "#if 0|#endif"; +} diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/internal/LogMessages.java b/pmd-core/src/main/java/net/sourceforge/pmd/internal/LogMessages.java index b4911afbea..bdabfdbc6e 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/internal/LogMessages.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/internal/LogMessages.java @@ -22,9 +22,4 @@ public final class LogMessages { + "If you do so, please include a stack-trace, the code sample\n" + " causing the issue, and details about your run configuration."; } - - @Deprecated - public static String runWithHelpFlagMessage() { - return "Run with --help for command line help."; - } } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/Node.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/Node.java index 866748fd3b..778775faf7 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/Node.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/Node.java @@ -174,40 +174,6 @@ public interface Node extends Reportable { return false; } - /** - * Returns the n-th parent or null if there are less than {@code n} ancestors. - * - *

{@code
-     *    getNthParent(1) == jjtGetParent
-     * }
- * - * @param n how many ancestors to iterate over. - * @return the n-th parent or null. - * @throws IllegalArgumentException if {@code n} is negative or zero. - * - * @deprecated Use node stream methods: {@code node.ancestors().get(n-1)} - */ - @Deprecated - @DeprecatedUntil700 - default Node getNthParent(int n) { - return ancestors().get(n - 1); - } - - /** - * Traverses up the tree to find the first parent instance of type parentType or one of its subclasses. - * - * @param parentType Class literal of the type you want to find - * @param The type you want to find - * @return Node of type parentType. Returns null if none found. - * - * @deprecated Use node stream methods: {@code node.ancestors(parentType).first()} - */ - @Deprecated - @DeprecatedUntil700 - default T getFirstParentOfType(Class parentType) { - return this.ancestors(parentType).first(); - } - /** * Traverses up the tree to find all of the parent instances of type parentType or one of its subclasses. The nodes * are ordered deepest-first. diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/NodeStream.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/NodeStream.java index c576aa9792..9a9e315462 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/NodeStream.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/NodeStream.java @@ -67,11 +67,11 @@ import net.sourceforge.pmd.lang.ast.internal.StreamImpl; *