forked from phoedos/pmd
[core] Remove deprecated classes/methods
CpdLanguageProperties#DEFAULT_SKIP_BLOCKS_PATTERN BaseAntlrNode#joinTextToken Node#getNthParent Node#getFirstChildOfType
This commit is contained in:
@ -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`.
|
||||
|
@ -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<FileSet> filesets = new ArrayList<>();
|
||||
|
@ -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<CPDConfiguration>
|
||||
|
||||
@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")
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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";
|
||||
}
|
||||
|
@ -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.
|
||||
*
|
||||
* <p>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";
|
||||
}
|
@ -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.";
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
*
|
||||
* <pre>{@code
|
||||
* getNthParent(1) == jjtGetParent
|
||||
* }</pre>
|
||||
*
|
||||
* @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 <T> 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 extends Node> T getFirstParentOfType(Class<? extends T> parentType) {
|
||||
return this.<T>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.
|
||||
|
@ -67,11 +67,11 @@ import net.sourceforge.pmd.lang.ast.internal.StreamImpl;
|
||||
* <ul>
|
||||
* <li><tt>node.{@link Node#getFirstChildOfType(Class) getFirstChildOfType(t)} === node.{@link Node#children(Class) children(t)}.{@link #first()}</tt></li>
|
||||
* <li><tt>node.{@link Node#getFirstDescendantOfType(Class) getFirstDescendantOfType(t)} === node.{@link Node#descendants(Class) descendants(t)}.{@link #first()}</tt></li>
|
||||
* <li><tt>node.{@link Node#getFirstParentOfType(Class) getFirstParentOfType(t)} === node.{@link Node#ancestors(Class) ancestors(t)}.{@link #first()}</tt></li>
|
||||
* <li>Traverse up the tree to find the first parent instance of type parentType or one of its subclasses: <tt>node.{@link Node#ancestors(Class) ancestors(t)}.{@link #first()}</tt></li>
|
||||
* <li><tt>node.{@link Node#findChildrenOfType(Class) findChildrenOfType(t)} === node.{@link Node#descendants(Class) children(t)}.{@link #toList()}</tt></li>
|
||||
* <li><tt>node.{@link Node#findDescendantsOfType(Class) findDescendantsOfType(t)} === node.{@link Node#descendants(Class) descendants(t)}.{@link #toList()}</tt></li>
|
||||
* <li><tt>node.{@link Node#getParentsOfType(Class) getParentsOfType(t)} === node.{@link Node#descendants(Class) ancestors(t)}.{@link #toList()}</tt></li>
|
||||
* <li><tt>node.{@link Node#getNthParent(int) getNthParent(n)} === node.{@link Node#ancestors() ancestors()}.{@link #get(int) get(n - 1)}</tt></li>
|
||||
* <li>Get the n-th parent or null if there are less than {@code n} ancestors: <tt>node.{@link Node#ancestors() ancestors()}.{@link #get(int) get(n - 1)}</tt></li>
|
||||
* <li><tt>node.{@link Node#hasDescendantOfType(Class) hasDescendantOfType(t)} === node.{@link Node#descendants(Class) descendants(t)}.{@link #nonEmpty()}</tt></li>
|
||||
* <li><tt>node.getFirstParentOfAnyType(c1, c2) === node.{@link Node#ancestors() ancestors()}.{@link #firstNonNull(Function) firstNonNull}({@link #asInstanceOf(Class, Class[]) asInstanceOf(c1, c2)})</tt></li>
|
||||
* <li><tt>node.hasDescendantOfAnyType(c1, c2) === node.{@link Node#descendants() descendants()}.{@link #map(Function) map}({@link #asInstanceOf(Class, Class[]) asInstanceOf(c1, c2)}).{@link #nonEmpty()}</tt></li>
|
||||
|
@ -54,11 +54,6 @@ public interface GenericNode<N extends GenericNode<N>> extends Node {
|
||||
return StreamImpl.singleton((N) this);
|
||||
}
|
||||
|
||||
@Override
|
||||
default N getNthParent(int n) {
|
||||
return (N) Node.super.getNthParent(n);
|
||||
}
|
||||
|
||||
@Override
|
||||
default NodeStream<N> children() {
|
||||
return (NodeStream<N>) Node.super.children();
|
||||
|
@ -48,19 +48,6 @@ public abstract class BaseAntlrNode<A extends AntlrToPmdParseTreeAdapter<N>, N e
|
||||
// protected
|
||||
}
|
||||
|
||||
/**
|
||||
* Recurses over the text of all terminal descendants to build the
|
||||
* text of this node (without spaces). This is extremely inefficient
|
||||
* and should not be used to write rules. The antlr impl doesn't even
|
||||
* use a single stringbuilder.
|
||||
*
|
||||
* @deprecated Some rules depend on it and have not been rewritten
|
||||
*/
|
||||
@Deprecated
|
||||
public String joinTokenText() {
|
||||
return asAntlrNode().getText();
|
||||
}
|
||||
|
||||
// these are an implementation detail, meant as a crutch while some
|
||||
// rules depend on it
|
||||
// Should be made protected
|
||||
|
@ -137,10 +137,10 @@ class NodeStreamTest {
|
||||
assertThat(pathsOf(node.ancestors()), contains("01", "0", ""));
|
||||
assertThat(pathsOf(node.ancestorsOrSelf()), contains("010", "01", "0", ""));
|
||||
|
||||
assertEquals("01", node.getNthParent(1).getImage());
|
||||
assertEquals("0", node.getNthParent(2).getImage());
|
||||
assertEquals("", node.getNthParent(3).getImage());
|
||||
assertNull(node.getNthParent(4));
|
||||
assertEquals("01", node.ancestors().get(0).getImage());
|
||||
assertEquals("0", node.ancestors().get(1).getImage());
|
||||
assertEquals("", node.ancestors().get(2).getImage());
|
||||
assertNull(node.ancestors().get(3));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -6,6 +6,7 @@ package net.sourceforge.pmd.lang.cpp;
|
||||
|
||||
import net.sourceforge.pmd.cpd.CpdLanguageProperties;
|
||||
import net.sourceforge.pmd.cpd.Tokenizer;
|
||||
import net.sourceforge.pmd.cpd.internal.CpdLanguagePropertiesDefaults;
|
||||
import net.sourceforge.pmd.lang.LanguagePropertyBundle;
|
||||
import net.sourceforge.pmd.lang.LanguageRegistry;
|
||||
import net.sourceforge.pmd.lang.cpp.cpd.CPPTokenizer;
|
||||
@ -21,7 +22,7 @@ public class CppLanguageModule extends CpdOnlyLanguageModuleBase {
|
||||
|
||||
public static final PropertyDescriptor<String> CPD_SKIP_BLOCKS =
|
||||
PropertyFactory.stringProperty("cpdSkipBlocksPattern")
|
||||
.defaultValue(CpdLanguageProperties.DEFAULT_SKIP_BLOCKS_PATTERN)
|
||||
.defaultValue(CpdLanguagePropertiesDefaults.DEFAULT_SKIP_BLOCKS_PATTERN)
|
||||
.desc("Specifies a start and end delimiter for CPD to completely ignore. "
|
||||
+ "The delimiters are separated by a pipe |. The default skips code "
|
||||
+ " that is conditionally compiled out. Set this property to empty to disable this.")
|
||||
|
@ -180,7 +180,7 @@ public final class ASTClassType extends AbstractJavaTypeNode implements ASTRefer
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean isReferenceToClassSameCompilationUnit() {
|
||||
ASTCompilationUnit root = getFirstParentOfType(ASTCompilationUnit.class);
|
||||
ASTCompilationUnit root = ancestors(ASTCompilationUnit.class).first();
|
||||
for (ASTClassDeclaration c : root.findDescendantsOfType(ASTClassDeclaration.class, true)) {
|
||||
if (c.hasImageEqualTo(getImage())) {
|
||||
return true;
|
||||
|
@ -169,7 +169,7 @@ public final class ASTVariableId extends AbstractTypedSymbolDeclarator<JVariable
|
||||
* a regular {@link ASTLocalVariableDeclaration}.
|
||||
*/
|
||||
public boolean isLocalVariable() {
|
||||
return getNthParent(2) instanceof ASTLocalVariableDeclaration
|
||||
return ancestors().get(1) instanceof ASTLocalVariableDeclaration
|
||||
&& !isResourceDeclaration()
|
||||
&& !isForeachVariable();
|
||||
}
|
||||
@ -180,7 +180,7 @@ public final class ASTVariableId extends AbstractTypedSymbolDeclarator<JVariable
|
||||
*/
|
||||
public boolean isForeachVariable() {
|
||||
// Foreach/LocalVarDecl/VarDeclarator/VarDeclId
|
||||
return getNthParent(3) instanceof ASTForeachStatement;
|
||||
return ancestors().get(2) instanceof ASTForeachStatement;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -189,7 +189,7 @@ public final class ASTVariableId extends AbstractTypedSymbolDeclarator<JVariable
|
||||
*/
|
||||
public boolean isForLoopVariable() {
|
||||
// For/ForInit/LocalVarDecl/VarDeclarator/VarDeclId
|
||||
return getNthParent(3) instanceof ASTForInit;
|
||||
return ancestors().get(2) instanceof ASTForInit;
|
||||
}
|
||||
|
||||
|
||||
@ -210,7 +210,7 @@ public final class ASTVariableId extends AbstractTypedSymbolDeclarator<JVariable
|
||||
* if you want that).
|
||||
*/
|
||||
public boolean isField() {
|
||||
return getNthParent(2) instanceof ASTFieldDeclaration;
|
||||
return ancestors().get(1) instanceof ASTFieldDeclaration;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -168,7 +168,7 @@ public class UnusedAssignmentRule extends AbstractJavaRulechainRule {
|
||||
return "resource";
|
||||
} else if (id.isExceptionBlockParameter()) {
|
||||
return "exception parameter";
|
||||
} else if (id.getNthParent(3) instanceof ASTForeachStatement) {
|
||||
} else if (id.ancestors().get(2) instanceof ASTForeachStatement) {
|
||||
return "loop variable";
|
||||
} else if (id.isFormalParameter()) {
|
||||
return "parameter";
|
||||
|
@ -79,7 +79,7 @@ public class AvoidBranchingStatementAsLastInLoopRule extends AbstractJavaRulecha
|
||||
if (parent instanceof ASTFinallyClause) {
|
||||
// get the parent of the block, in which the try statement is: ForStatement/Block/TryStatement/Finally
|
||||
// e.g. a ForStatement
|
||||
parent = ((ASTFinallyClause) parent).getNthParent(3);
|
||||
parent = ((ASTFinallyClause) parent).ancestors().get(2);
|
||||
}
|
||||
}
|
||||
if (parent instanceof ASTForStatement || parent instanceof ASTForeachStatement) {
|
||||
|
@ -212,7 +212,7 @@ public final class LazyTypeResolver extends JavaVisitorBase<TypingContext, @NonN
|
||||
|
||||
} else if (isTypeInferred && node.isLambdaParameter()) {
|
||||
ASTLambdaParameter param = (ASTLambdaParameter) node.getParent();
|
||||
ASTLambdaExpression lambda = (ASTLambdaExpression) node.getNthParent(3);
|
||||
ASTLambdaExpression lambda = (ASTLambdaExpression) node.ancestors().get(2);
|
||||
JTypeMirror contextualResult = ctx.apply(node.getSymbol());
|
||||
if (contextualResult != null) {
|
||||
return contextualResult;
|
||||
|
@ -179,7 +179,7 @@ public class CodeFormatRule extends AbstractPLSQLRule {
|
||||
|
||||
@Override
|
||||
public Object visit(ASTDeclarativeSection node, Object data) {
|
||||
int variableIndentation = node.getNthParent(2).getBeginColumn() + 2 * indentation;
|
||||
int variableIndentation = node.ancestors().get(1).getBeginColumn() + 2 * indentation;
|
||||
int line = node.getBeginLine();
|
||||
|
||||
List<ASTVariableOrConstantDeclarator> variables = node
|
||||
@ -254,7 +254,7 @@ public class CodeFormatRule extends AbstractPLSQLRule {
|
||||
}
|
||||
|
||||
// closing parenthesis should be on a new line
|
||||
Node primaryExpression = node.getNthParent(3);
|
||||
Node primaryExpression = node.ancestors().get(2);
|
||||
if (primaryExpression.getEndLine() != node.getEndLine() + 1) {
|
||||
asCtx(data).addViolationWithMessage(primaryExpression, "Closing parenthesis should be on a new line.");
|
||||
}
|
||||
|
Reference in New Issue
Block a user