[apex] Remove deprecated classes/methods

This commit is contained in:
Andreas Dangel
2024-02-02 12:34:50 +01:00
parent 2695eb250b
commit 7494260ffc
17 changed files with 37 additions and 255 deletions

View File

@ -189,6 +189,26 @@ The following previously deprecated classes have been removed:
If the current version is needed, then `Node.getTextDocument().getLanguageVersion()` can be used. This
is the version that has been selected via CLI `--use-version` parameter.
* {%jdoc !!apex::lang.apex.ast.ApexNode %}
* method `jjtAccept()` has been removed.
Use {%jdoc core::lang.ast.Node#acceptVisitor(core::lang.ast.AstVisitor,P) %} instead.
* method `getNode()` has been removed. The underlying node is only available in AST nodes, but not in rule implementations.
* {%jdoc !!apex::lang.apex.ast.AbstractApexNode %} - method `getNode()` is now package private.
AST nodes still have access to the underlying Jorje node via the protected property `node`.
* `net.sourceforge.pmd.lang.apex.ast.ApexParserVisitor`
Use {%jdoc apex::lang.apex.ast.ApexVisitor %} or {%jdoc apex::lang.apex.ast.ApexVisitorBase %} instead.
* `net.sourceforge.pmd.lang.apex.ast.ApexParserVisitorAdapter`
* {%jdoc !!apex::lang.apex.ast.ASTAssignmentExpression %} - method `getOperator()` removed.
Use {%jdoc apex::lang.apex.ast.ASTAssignmentExpression#getOp() %} instead.
* {%jdoc !!apex::lang.apex.ast.ASTBinaryExpression %} - method `getOperator()` removed.
Use {%jdoc apex::lang.apex.ast.ASTBinaryExpression#getOp() %} instead.
* {%jdoc !!apex::lang.apex.ast.ASTBooleanExpression %} - method `getOperator()` removed.
Use {%jdoc apex::lang.apex.ast.ASTBooleanExpression#getOp() %} instead.
* {%jdoc !!apex::lang.apex.ast.ASTPostfixExpression %} - method `getOperator()` removed.
Use {%jdoc apex::lang.apex.ast.ASTPostfixExpression#getOp() %} instead.
* {%jdoc !!apex::lang.apex.ast.ASTPrefixExpression %} - method `getOperator()` removed.
Use {%jdoc apex::lang.apex.ast.ASTPrefixExpression#getOp() %} instead.
* `net.sourceforge.pmd.lang.apex.rule.security.Helper` removed. This was actually internal API.
* pmd-javascript
* {%jdoc javascript::lang.ecmascript.ast.AbstractEcmascriptNode %} - method `getNode()` has been removed.
AST nodes still have access to the underlying Rhino node via the protected property `node`.

View File

@ -4,7 +4,6 @@
package net.sourceforge.pmd.lang.apex.ast;
import apex.jorje.data.ast.AssignmentOp;
import apex.jorje.semantic.ast.expression.AssignmentExpression;
public final class ASTAssignmentExpression extends AbstractApexNode<AssignmentExpression> {
@ -19,14 +18,6 @@ public final class ASTAssignmentExpression extends AbstractApexNode<AssignmentEx
return visitor.visit(this, data);
}
/**
* @deprecated Use {@link #getOp()} instead.
*/
@Deprecated
public AssignmentOp getOperator() {
return node.getOp();
}
public AssignmentOperator getOp() {
return AssignmentOperator.valueOf(node.getOp());
}

View File

@ -4,7 +4,6 @@
package net.sourceforge.pmd.lang.apex.ast;
import apex.jorje.data.ast.BinaryOp;
import apex.jorje.semantic.ast.expression.BinaryExpression;
public final class ASTBinaryExpression extends AbstractApexNode<BinaryExpression> {
@ -19,13 +18,6 @@ public final class ASTBinaryExpression extends AbstractApexNode<BinaryExpression
return visitor.visit(this, data);
}
/**
* @deprecated Use {@link #getOp()} instead.
*/
@Deprecated
public BinaryOp getOperator() {
return node.getOp();
}
public BinaryOperator getOp() {
return BinaryOperator.valueOf(node.getOp());

View File

@ -42,6 +42,6 @@ public final class ASTBlockStatement extends AbstractApexNode<BlockStatement> {
@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());
}
}

View File

@ -4,7 +4,6 @@
package net.sourceforge.pmd.lang.apex.ast;
import apex.jorje.data.ast.BooleanOp;
import apex.jorje.semantic.ast.expression.BooleanExpression;
@ -14,21 +13,11 @@ public final class ASTBooleanExpression extends AbstractApexNode<BooleanExpressi
super(booleanExpression);
}
@Override
protected <P, R> R acceptApexVisitor(ApexVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
/**
* @deprecated Use {@link #getOp()} instead.
*/
@Deprecated
public BooleanOp getOperator() {
return this.node.getOp();
}
public BooleanOperator getOp() {
return BooleanOperator.valueOf(this.node.getOp());
}

View File

@ -4,7 +4,6 @@
package net.sourceforge.pmd.lang.apex.ast;
import apex.jorje.data.ast.PostfixOp;
import apex.jorje.semantic.ast.expression.PostfixExpression;
@ -14,21 +13,11 @@ public final class ASTPostfixExpression extends AbstractApexNode<PostfixExpressi
super(postfixExpression);
}
@Override
protected <P, R> R acceptApexVisitor(ApexVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
/**
* @deprecated Use {@link #getOp()} instead.
*/
@Deprecated
public PostfixOp getOperator() {
return node.getOp();
}
public PostfixOperator getOp() {
return PostfixOperator.valueOf(node.getOp());
}

View File

@ -4,7 +4,6 @@
package net.sourceforge.pmd.lang.apex.ast;
import apex.jorje.data.ast.PrefixOp;
import apex.jorje.semantic.ast.expression.PrefixExpression;
public final class ASTPrefixExpression extends AbstractApexNode<PrefixExpression> {
@ -13,20 +12,11 @@ public final class ASTPrefixExpression extends AbstractApexNode<PrefixExpression
super(prefixExpression);
}
@Override
protected <P, R> R acceptApexVisitor(ApexVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
/**
* @deprecated Use {@link #getOp()} instead.
*/
@Deprecated
public PrefixOp getOperator() {
return node.getOp();
}
public PrefixOperator getOp() {
return PrefixOperator.valueOf(node.getOp());
}

View File

@ -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<T extends AstNode> extends AbstractNode<Abstract
this.region = region;
}
@Deprecated
@InternalApi
@Override
public T getNode() {
T getNode() {
return node;
}

View File

@ -6,43 +6,17 @@ package net.sourceforge.pmd.lang.apex.ast;
import org.checkerframework.checker.nullness.qual.NonNull;
import net.sourceforge.pmd.annotation.DeprecatedUntil700;
import net.sourceforge.pmd.lang.ast.AstVisitor;
import net.sourceforge.pmd.lang.ast.impl.GenericNode;
import apex.jorje.semantic.ast.AstNode;
/**
* 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
*/
public interface ApexNode<T extends AstNode> extends GenericNode<ApexNode<?>> {
/**
* Accept the visitor.
*
* @deprecated Use {@link #acceptVisitor(AstVisitor, Object)}
*/
@Deprecated
@DeprecatedUntil700
default Object jjtAccept(ApexParserVisitor visitor, Object data) {
return acceptVisitor(visitor, 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();

View File

@ -1,32 +0,0 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.apex.ast;
import net.sourceforge.pmd.annotation.DeprecatedUntil700;
import net.sourceforge.pmd.lang.ast.Node;
@DeprecatedUntil700
@Deprecated
public interface ApexParserVisitor extends ApexVisitor<Object, Object> {
@Override
default Object visitNode(Node node, Object param) {
for (Node child : node.children()) {
child.acceptVisitor(this, param);
}
return param;
}
@Deprecated
default Object visit(ApexNode<?> node, Object data) {
return visitNode(node, data);
}
@Override
default Object visitApexNode(ApexNode<?> node, Object data) {
return visit(node, data); // calls the overload above for compatibility
}
}

View File

@ -1,13 +0,0 @@
/*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.apex.ast;
import net.sourceforge.pmd.annotation.DeprecatedUntil700;
@Deprecated
@DeprecatedUntil700
public class ApexParserVisitorAdapter extends ApexVisitorBase<Object, Object> implements ApexParserVisitor {
}

View File

@ -329,7 +329,7 @@ final class ApexTreeBuilder extends AstVisitor<AdditionalPassScope> {
}
private boolean containsComments(ASTCommentContainer<?> commentContainer) {
Location loc = commentContainer.getNode().getLoc();
Location loc = ((AbstractApexCommentContainerNode<?>) commentContainer).getNode().getLoc();
if (!Locations.isReal(loc)) {
// Synthetic nodes don't have a location and can't have comments
return false;

View File

@ -10,7 +10,7 @@ import net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression;
import net.sourceforge.pmd.lang.apex.ast.ASTUserClass;
import net.sourceforge.pmd.lang.apex.ast.ASTVariableDeclaration;
import net.sourceforge.pmd.lang.apex.ast.ApexNode;
import net.sourceforge.pmd.lang.apex.ast.ApexParserVisitorAdapter;
import net.sourceforge.pmd.lang.apex.ast.ApexVisitorBase;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.rule.xpath.Attribute;
import net.sourceforge.pmd.util.designerbindings.DesignerBindings.DefaultDesignerBindings;
@ -46,12 +46,12 @@ public class ApexDesignerBindings extends DefaultDesignerBindings {
}
private static final class MainAttrVisitor extends ApexParserVisitorAdapter {
private static final class MainAttrVisitor extends ApexVisitorBase<Object, Object> {
private static final MainAttrVisitor INSTANCE = new MainAttrVisitor();
@Override
public Object visit(ApexNode<?> node, Object data) {
public Object visitApexNode(ApexNode<?> node, Object data) {
return null; // don't recurse
}

View File

@ -5,15 +5,20 @@
package net.sourceforge.pmd.lang.apex.rule;
import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.lang.apex.ast.ApexParserVisitor;
import net.sourceforge.pmd.lang.apex.ast.ApexVisitor;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.rule.AbstractRule;
public abstract class AbstractApexRule extends AbstractRule
implements ApexParserVisitor {
public abstract class AbstractApexRule extends AbstractRule implements ApexVisitor<Object, Object> {
@Override
public void apply(Node target, RuleContext ctx) {
target.acceptVisitor(this, ctx);
}
@Override
public Object visitNode(Node node, Object param) {
node.children().forEach(n -> n.acceptVisitor(this, param));
return param;
}
}

View File

@ -62,7 +62,7 @@ public abstract class AbstractCounterCheckRule<T extends ApexNode<?>> extends Ab
@Override
public Object visit(ApexNode<?> node, Object data) {
public Object visitApexNode(ApexNode<?> node, Object data) {
@SuppressWarnings("unchecked")
T t = (T) node;
// since we only visit this node, it's ok

View File

@ -1,119 +0,0 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.apex.rule.security;
import java.util.List;
import net.sourceforge.pmd.lang.apex.ast.ASTField;
import net.sourceforge.pmd.lang.apex.ast.ASTFieldDeclaration;
import net.sourceforge.pmd.lang.apex.ast.ASTMethodCallExpression;
import net.sourceforge.pmd.lang.apex.ast.ASTNewKeyValueObjectExpression;
import net.sourceforge.pmd.lang.apex.ast.ASTParameter;
import net.sourceforge.pmd.lang.apex.ast.ASTReferenceExpression;
import net.sourceforge.pmd.lang.apex.ast.ASTSoqlExpression;
import net.sourceforge.pmd.lang.apex.ast.ASTSoslExpression;
import net.sourceforge.pmd.lang.apex.ast.ASTUserClass;
import net.sourceforge.pmd.lang.apex.ast.ASTVariableDeclaration;
import net.sourceforge.pmd.lang.apex.ast.ASTVariableExpression;
import net.sourceforge.pmd.lang.apex.ast.ApexNode;
import apex.jorje.semantic.ast.member.Parameter;
/**
* Helper methods
*
* @author sergey.gorbaty
*
* @deprecated Use {@link net.sourceforge.pmd.lang.apex.rule.internal.Helper} instead.
*/
@Deprecated
public final class Helper {
static final String ANY_METHOD = "*";
private Helper() {
throw new AssertionError("Can't instantiate helper classes");
}
static boolean isTestMethodOrClass(final ApexNode<?> node) {
return net.sourceforge.pmd.lang.apex.rule.internal.Helper.isTestMethodOrClass(node);
}
static boolean foundAnySOQLorSOSL(final ApexNode<?> node) {
final List<ASTSoqlExpression> dmlSoqlExpression = node.findDescendantsOfType(ASTSoqlExpression.class);
final List<ASTSoslExpression> dmlSoslExpression = node.findDescendantsOfType(ASTSoslExpression.class);
return !dmlSoqlExpression.isEmpty() || !dmlSoslExpression.isEmpty();
}
/**
* Finds DML operations in a given node descendants' path
*
* @param node
*
* @return true if found DML operations in node descendants
*/
static boolean foundAnyDML(final ApexNode<?> node) {
return net.sourceforge.pmd.lang.apex.rule.internal.Helper.foundAnyDML(node);
}
static boolean isMethodName(final ASTMethodCallExpression methodNode, final String className,
final String methodName) {
final ASTReferenceExpression reference = methodNode.getFirstChildOfType(ASTReferenceExpression.class);
return reference != null && reference.getNames().size() == 1
&& reference.getNames().get(0).equalsIgnoreCase(className)
&& (ANY_METHOD.equals(methodName) || isMethodName(methodNode, methodName));
}
static boolean isMethodName(final ASTMethodCallExpression m, final String methodName) {
return m.getMethodName().equalsIgnoreCase(methodName);
}
static boolean isMethodCallChain(final ASTMethodCallExpression methodNode, final String... methodNames) {
return net.sourceforge.pmd.lang.apex.rule.internal.Helper.isMethodCallChain(methodNode, methodNames);
}
static String getFQVariableName(final ASTVariableExpression variable) {
return net.sourceforge.pmd.lang.apex.rule.internal.Helper.getFQVariableName(variable);
}
static String getFQVariableName(final ASTVariableDeclaration variable) {
return net.sourceforge.pmd.lang.apex.rule.internal.Helper.getFQVariableName(variable);
}
static String getFQVariableName(final ASTField variable) {
return net.sourceforge.pmd.lang.apex.rule.internal.Helper.getFQVariableName(variable);
}
static String getVariableType(final ASTField variable) {
StringBuilder sb = new StringBuilder().append(variable.getDefiningType()).append(":")
.append(variable.getName());
return sb.toString();
}
static String getFQVariableName(final ASTFieldDeclaration variable) {
return net.sourceforge.pmd.lang.apex.rule.internal.Helper.getFQVariableName(variable);
}
static String getFQVariableName(final ASTNewKeyValueObjectExpression variable) {
return net.sourceforge.pmd.lang.apex.rule.internal.Helper.getFQVariableName(variable);
}
static boolean isSystemLevelClass(ASTUserClass node) {
return net.sourceforge.pmd.lang.apex.rule.internal.Helper.isSystemLevelClass(node);
}
@Deprecated
public static String getFQVariableName(Parameter p) {
StringBuilder sb = new StringBuilder();
sb.append(p.getDefiningType()).append(":").append(p.getName().getValue());
return sb.toString();
}
static String getFQVariableName(ASTParameter p) {
return net.sourceforge.pmd.lang.apex.rule.internal.Helper.getFQVariableName(p);
}
}

View File

@ -34,7 +34,7 @@ class ApexXPathRuleTest extends ApexParserTestBase {
@Test
void testBooleanExpressions() {
Report report = apex.executeRuleOnResource(makeXPath("//BooleanExpression[@Operator='&&']"),
Report report = apex.executeRuleOnResource(makeXPath("//BooleanExpression[@Op='&&']"),
"BooleanExpressions.cls");
assertSize(report, 1);
}