diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTBreakStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTBreakStatement.java index 2e5c6a83277..0c43d4600a8 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTBreakStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTBreakStatement.java @@ -4,14 +4,11 @@ package net.sourceforge.pmd.lang.apex.ast; -import com.google.summit.ast.Node; -import net.sourceforge.pmd.annotation.InternalApi; +import com.google.summit.ast.statement.BreakStatement; -public class ASTBreakStatement extends AbstractApexNode.Single { +public class ASTBreakStatement extends AbstractApexNode.Single { - @Deprecated - @InternalApi - public ASTBreakStatement(Node breakStatement) { + ASTBreakStatement(BreakStatement breakStatement) { super(breakStatement); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTCatchBlockStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTCatchBlockStatement.java index e992fb585e9..1613258945f 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTCatchBlockStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTCatchBlockStatement.java @@ -4,15 +4,12 @@ package net.sourceforge.pmd.lang.apex.ast; -import com.google.summit.ast.Node; -import net.sourceforge.pmd.annotation.InternalApi; +import com.google.summit.ast.statement.TryStatement; -public class ASTCatchBlockStatement extends AbstractApexCommentContainerNode { +public class ASTCatchBlockStatement extends AbstractApexCommentContainerNode { - @Deprecated - @InternalApi - public ASTCatchBlockStatement(Node catchBlockStatement) { - super(catchBlockStatement); + ASTCatchBlockStatement(TryStatement.CatchBlock catchBlock) { + super(catchBlock); } @Override @@ -21,20 +18,14 @@ public Object jjtAccept(ApexParserVisitor visitor, Object data) { } public String getExceptionType() { - // return String.valueOf(node.getTypeRef()); - // TODO(b/239648780) - return null; + return node.getExceptionVariable().getType().asCodeString(); } public String getVariableName() { - // if (node.getVariable() != null) { - // return node.getVariable().getName(); - // } - // TODO(b/239648780) - return null; + return node.getExceptionVariable().getId().getString(); } public ASTBlockStatement getBody() { - return (ASTBlockStatement) getChild(0); + return getFirstChildOfType(ASTBlockStatement.class); } } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTConstructorPreambleStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTConstructorPreambleStatement.java index 419d57d0411..978af4b7908 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTConstructorPreambleStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTConstructorPreambleStatement.java @@ -5,13 +5,10 @@ package net.sourceforge.pmd.lang.apex.ast; import com.google.summit.ast.Node; -import net.sourceforge.pmd.annotation.InternalApi; public class ASTConstructorPreambleStatement extends AbstractApexNode.Single { - @Deprecated - @InternalApi - public ASTConstructorPreambleStatement(Node constructorPreambleStatement) { + ASTConstructorPreambleStatement(Node constructorPreambleStatement) { super(constructorPreambleStatement); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTContinueStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTContinueStatement.java index 51e1666b0e4..89923e48b34 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTContinueStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTContinueStatement.java @@ -4,14 +4,11 @@ package net.sourceforge.pmd.lang.apex.ast; -import com.google.summit.ast.Node; -import net.sourceforge.pmd.annotation.InternalApi; +import com.google.summit.ast.statement.ContinueStatement; -public class ASTContinueStatement extends AbstractApexNode.Single { +public class ASTContinueStatement extends AbstractApexNode.Single { - @Deprecated - @InternalApi - public ASTContinueStatement(Node continueStatement) { + ASTContinueStatement(ContinueStatement continueStatement) { super(continueStatement); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlDeleteStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlDeleteStatement.java index 9820d9b2395..49884a2b446 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlDeleteStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlDeleteStatement.java @@ -5,13 +5,10 @@ package net.sourceforge.pmd.lang.apex.ast; import com.google.summit.ast.Node; -import net.sourceforge.pmd.annotation.InternalApi; public class ASTDmlDeleteStatement extends AbstractApexNode.Single { - @Deprecated - @InternalApi - public ASTDmlDeleteStatement(Node dmlDeleteStatement) { + ASTDmlDeleteStatement(Node dmlDeleteStatement) { super(dmlDeleteStatement); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlInsertStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlInsertStatement.java index ae22d8cd222..89f5b96290a 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlInsertStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlInsertStatement.java @@ -5,13 +5,10 @@ package net.sourceforge.pmd.lang.apex.ast; import com.google.summit.ast.Node; -import net.sourceforge.pmd.annotation.InternalApi; public class ASTDmlInsertStatement extends AbstractApexNode.Single { - @Deprecated - @InternalApi - public ASTDmlInsertStatement(Node dmlInsertStatement) { + ASTDmlInsertStatement(Node dmlInsertStatement) { super(dmlInsertStatement); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlMergeStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlMergeStatement.java index 0b8e817770e..5cace71f90e 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlMergeStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlMergeStatement.java @@ -5,13 +5,10 @@ package net.sourceforge.pmd.lang.apex.ast; import com.google.summit.ast.Node; -import net.sourceforge.pmd.annotation.InternalApi; public class ASTDmlMergeStatement extends AbstractApexNode.Single { - @Deprecated - @InternalApi - public ASTDmlMergeStatement(Node dmlMergeStatement) { + ASTDmlMergeStatement(Node dmlMergeStatement) { super(dmlMergeStatement); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlUndeleteStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlUndeleteStatement.java index 12c25da5e38..ad85bf0f8e1 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlUndeleteStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlUndeleteStatement.java @@ -5,13 +5,10 @@ package net.sourceforge.pmd.lang.apex.ast; import com.google.summit.ast.Node; -import net.sourceforge.pmd.annotation.InternalApi; public class ASTDmlUndeleteStatement extends AbstractApexNode.Single { - @Deprecated - @InternalApi - public ASTDmlUndeleteStatement(Node dmlUndeleteStatement) { + ASTDmlUndeleteStatement(Node dmlUndeleteStatement) { super(dmlUndeleteStatement); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlUpdateStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlUpdateStatement.java index 31b593b93fa..8225db5bdfd 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlUpdateStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlUpdateStatement.java @@ -5,13 +5,10 @@ package net.sourceforge.pmd.lang.apex.ast; import com.google.summit.ast.Node; -import net.sourceforge.pmd.annotation.InternalApi; public class ASTDmlUpdateStatement extends AbstractApexNode.Single { - @Deprecated - @InternalApi - public ASTDmlUpdateStatement(Node dmlUpdateStatement) { + ASTDmlUpdateStatement(Node dmlUpdateStatement) { super(dmlUpdateStatement); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlUpsertStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlUpsertStatement.java index 34733c5b381..5ac86887456 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlUpsertStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDmlUpsertStatement.java @@ -5,13 +5,10 @@ package net.sourceforge.pmd.lang.apex.ast; import com.google.summit.ast.Node; -import net.sourceforge.pmd.annotation.InternalApi; public class ASTDmlUpsertStatement extends AbstractApexNode.Single { - @Deprecated - @InternalApi - public ASTDmlUpsertStatement(Node dmlUpsertStatement) { + ASTDmlUpsertStatement(Node dmlUpsertStatement) { super(dmlUpsertStatement); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDoLoopStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDoLoopStatement.java index ee961cfd1ed..1df5d48a659 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDoLoopStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTDoLoopStatement.java @@ -4,15 +4,12 @@ package net.sourceforge.pmd.lang.apex.ast; -import com.google.summit.ast.Node; -import net.sourceforge.pmd.annotation.InternalApi; +import com.google.summit.ast.statement.DoWhileLoopStatement; -public class ASTDoLoopStatement extends AbstractApexNode.Single { +public class ASTDoLoopStatement extends AbstractApexNode.Single { - @Deprecated - @InternalApi - public ASTDoLoopStatement(Node doLoopStatement) { - super(doLoopStatement); + ASTDoLoopStatement(DoWhileLoopStatement doWhileLoopStatement) { + super(doWhileLoopStatement); } @Override diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTElseWhenBlock.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTElseWhenBlock.java index 62882df6068..3969bb783f9 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTElseWhenBlock.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTElseWhenBlock.java @@ -4,16 +4,14 @@ package net.sourceforge.pmd.lang.apex.ast; -import com.google.summit.ast.Node; +import com.google.summit.ast.statement.SwitchStatement; -public final class ASTElseWhenBlock extends AbstractApexNode.Single { +public final class ASTElseWhenBlock extends AbstractApexNode.Single { - - ASTElseWhenBlock(Node node) { - super(node); + ASTElseWhenBlock(SwitchStatement.WhenElse whenElse) { + super(whenElse); } - @Override public Object jjtAccept(ApexParserVisitor visitor, Object data) { return visitor.visit(this, data); diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTExpressionStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTExpressionStatement.java index f39444cee56..54c48ff8698 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTExpressionStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTExpressionStatement.java @@ -4,42 +4,16 @@ package net.sourceforge.pmd.lang.apex.ast; -import com.google.summit.ast.statement.ExpressionStatement; +import com.google.summit.ast.expression.Expression; -public class ASTExpressionStatement extends AbstractApexNode.Single { +public class ASTExpressionStatement extends AbstractApexNode.Single { - ASTExpressionStatement(ExpressionStatement expressionStatement) { - super(expressionStatement); + ASTExpressionStatement(Expression expression) { + super(expression); } @Override public Object jjtAccept(ApexParserVisitor visitor, Object data) { return visitor.visit(this, data); } - - /* - private int beginColumnDiff = -1; - - @Override - public int getBeginColumn() { - if (beginColumnDiff > -1) { - return super.getBeginColumn() - beginColumnDiff; - } - - if (getNumChildren() > 0 && getChild(0) instanceof ASTMethodCallExpression) { - ASTMethodCallExpression methodCallExpression = (ASTMethodCallExpression) getChild(0); - - int fullLength = methodCallExpression.getFullMethodName().length(); - int nameLength = methodCallExpression.getMethodName().length(); - if (fullLength > nameLength) { - beginColumnDiff = fullLength - nameLength; - } else { - beginColumnDiff = 0; - } - } - - return super.getBeginColumn() - beginColumnDiff; - } - */ - // TODO(b/239648780) } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTForEachStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTForEachStatement.java index ed9719b117e..bad89efbb3d 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTForEachStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTForEachStatement.java @@ -4,15 +4,12 @@ package net.sourceforge.pmd.lang.apex.ast; -import com.google.summit.ast.Node; -import net.sourceforge.pmd.annotation.InternalApi; +import com.google.summit.ast.statement.EnhancedForLoopStatement; -public class ASTForEachStatement extends AbstractApexNode.Single { +public class ASTForEachStatement extends AbstractApexNode.Single { - @Deprecated - @InternalApi - public ASTForEachStatement(Node forEachStatement) { - super(forEachStatement); + ASTForEachStatement(EnhancedForLoopStatement enhancedForLoopStatement) { + super(enhancedForLoopStatement); } @Override diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTForLoopStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTForLoopStatement.java index 8c149170ebd..62f838de48b 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTForLoopStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTForLoopStatement.java @@ -4,14 +4,11 @@ package net.sourceforge.pmd.lang.apex.ast; -import com.google.summit.ast.Node; -import net.sourceforge.pmd.annotation.InternalApi; +import com.google.summit.ast.statement.ForLoopStatement; -public class ASTForLoopStatement extends AbstractApexNode.Single { +public class ASTForLoopStatement extends AbstractApexNode.Single { - @Deprecated - @InternalApi - public ASTForLoopStatement(Node forLoopStatement) { + ASTForLoopStatement(ForLoopStatement forLoopStatement) { super(forLoopStatement); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTIfBlockStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTIfBlockStatement.java index a6f43c72397..cba32de1e62 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTIfBlockStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTIfBlockStatement.java @@ -4,15 +4,12 @@ package net.sourceforge.pmd.lang.apex.ast; -import com.google.summit.ast.Node; -import net.sourceforge.pmd.annotation.InternalApi; +import com.google.summit.ast.statement.IfStatement; -public class ASTIfBlockStatement extends AbstractApexNode.Single { +public class ASTIfBlockStatement extends AbstractApexNode.Single { - @Deprecated - @InternalApi - public ASTIfBlockStatement(Node ifBlockStatement) { - super(ifBlockStatement); + ASTIfBlockStatement(IfStatement ifStatement) { + super(ifStatement); } @Override diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTIfElseBlockStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTIfElseBlockStatement.java index c6575516fb1..cc6a1d3b5c3 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTIfElseBlockStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTIfElseBlockStatement.java @@ -4,15 +4,15 @@ package net.sourceforge.pmd.lang.apex.ast; -import com.google.summit.ast.Node; -import net.sourceforge.pmd.annotation.InternalApi; +import com.google.summit.ast.statement.IfStatement; -public class ASTIfElseBlockStatement extends AbstractApexNode.Single { +public class ASTIfElseBlockStatement extends AbstractApexNode.Single { - @Deprecated - @InternalApi - public ASTIfElseBlockStatement(Node ifElseBlockStatement) { - super(ifElseBlockStatement); + private final boolean hasElseStatement; + + ASTIfElseBlockStatement(IfStatement ifStatement, boolean hasElseStatement) { + super(ifStatement); + this.hasElseStatement = hasElseStatement; } @Override @@ -21,8 +21,6 @@ public Object jjtAccept(ApexParserVisitor visitor, Object data) { } public boolean hasElseStatement() { - // return node.hasElseStatement(); - // TODO(b/239648780) - return false; + return hasElseStatement; } } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTMapEntryNode.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTMapEntryNode.java index eb73b4f5614..61e53352e29 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTMapEntryNode.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTMapEntryNode.java @@ -10,10 +10,10 @@ public class ASTMapEntryNode extends AbstractApexNode.Many { - private final Expression key; - private final Expression value; + private final Expression key; + private final Expression value; - ASTMapEntryNode(Expression key, Expression value) { + ASTMapEntryNode(Expression key, Expression value) { super(Arrays.asList(key, value)); this.key = key; this.value = value; diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTMethodBlockStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTMethodBlockStatement.java index 63f7622ec33..b305f42d79f 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTMethodBlockStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTMethodBlockStatement.java @@ -5,13 +5,10 @@ package net.sourceforge.pmd.lang.apex.ast; import com.google.summit.ast.Node; -import net.sourceforge.pmd.annotation.InternalApi; public class ASTMethodBlockStatement extends AbstractApexNode.Single { - @Deprecated - @InternalApi - public ASTMethodBlockStatement(Node node) { + ASTMethodBlockStatement(Node node) { super(node); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTMultiStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTMultiStatement.java index 86b03ddf39d..5040c1536df 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTMultiStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTMultiStatement.java @@ -5,13 +5,10 @@ package net.sourceforge.pmd.lang.apex.ast; import com.google.summit.ast.Node; -import net.sourceforge.pmd.annotation.InternalApi; public class ASTMultiStatement extends AbstractApexNode.Single { - @Deprecated - @InternalApi - public ASTMultiStatement(Node node) { + ASTMultiStatement(Node node) { super(node); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTReturnStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTReturnStatement.java index f3ab4eaf72d..a07fcb5e257 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTReturnStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTReturnStatement.java @@ -4,14 +4,11 @@ package net.sourceforge.pmd.lang.apex.ast; -import com.google.summit.ast.Node; -import net.sourceforge.pmd.annotation.InternalApi; +import com.google.summit.ast.statement.ReturnStatement; -public class ASTReturnStatement extends AbstractApexNode.Single { +public class ASTReturnStatement extends AbstractApexNode.Single { - @Deprecated - @InternalApi - public ASTReturnStatement(Node returnStatement) { + ASTReturnStatement(ReturnStatement returnStatement) { super(returnStatement); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTRunAsBlockStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTRunAsBlockStatement.java index b74bba13fac..eb2303fb8e0 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTRunAsBlockStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTRunAsBlockStatement.java @@ -4,15 +4,12 @@ package net.sourceforge.pmd.lang.apex.ast; -import com.google.summit.ast.Node; -import net.sourceforge.pmd.annotation.InternalApi; +import com.google.summit.ast.statement.RunAsStatement; -public class ASTRunAsBlockStatement extends AbstractApexNode.Single { +public class ASTRunAsBlockStatement extends AbstractApexNode.Single { - @Deprecated - @InternalApi - public ASTRunAsBlockStatement(Node runAsBlockStatement) { - super(runAsBlockStatement); + ASTRunAsBlockStatement(RunAsStatement runAsStatement) { + super(runAsStatement); } @Override diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTStatement.java index ea10783207e..dabe152196b 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTStatement.java @@ -5,13 +5,10 @@ package net.sourceforge.pmd.lang.apex.ast; import com.google.summit.ast.Node; -import net.sourceforge.pmd.annotation.InternalApi; public class ASTStatement extends AbstractApexNode.Single { - @Deprecated - @InternalApi - public ASTStatement(Node statement) { + ASTStatement(Node statement) { super(statement); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTSwitchStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTSwitchStatement.java index 1b8b6297302..ee7e7ccf613 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTSwitchStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTSwitchStatement.java @@ -4,16 +4,14 @@ package net.sourceforge.pmd.lang.apex.ast; -import com.google.summit.ast.Node; +import com.google.summit.ast.statement.SwitchStatement; -public final class ASTSwitchStatement extends AbstractApexNode.Single { +public final class ASTSwitchStatement extends AbstractApexNode.Single { - - ASTSwitchStatement(Node node) { - super(node); + ASTSwitchStatement(SwitchStatement switchStatement) { + super(switchStatement); } - @Override public Object jjtAccept(ApexParserVisitor visitor, Object data) { return visitor.visit(this, data); diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTThrowStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTThrowStatement.java index 615e1ec1004..99d1a7d1669 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTThrowStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTThrowStatement.java @@ -4,14 +4,11 @@ package net.sourceforge.pmd.lang.apex.ast; -import com.google.summit.ast.Node; -import net.sourceforge.pmd.annotation.InternalApi; +import com.google.summit.ast.statement.ThrowStatement; -public class ASTThrowStatement extends AbstractApexNode.Single { +public class ASTThrowStatement extends AbstractApexNode.Single { - @Deprecated - @InternalApi - public ASTThrowStatement(Node throwStatement) { + ASTThrowStatement(ThrowStatement throwStatement) { super(throwStatement); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTTryCatchFinallyBlockStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTTryCatchFinallyBlockStatement.java index a99c067f7df..087fe02cf44 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTTryCatchFinallyBlockStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTTryCatchFinallyBlockStatement.java @@ -4,17 +4,14 @@ package net.sourceforge.pmd.lang.apex.ast; -import com.google.summit.ast.Node; import java.util.List; -import net.sourceforge.pmd.annotation.InternalApi; +import com.google.summit.ast.statement.TryStatement; -public class ASTTryCatchFinallyBlockStatement extends AbstractApexNode.Single { +public class ASTTryCatchFinallyBlockStatement extends AbstractApexNode.Single { - @Deprecated - @InternalApi - public ASTTryCatchFinallyBlockStatement(Node tryCatchFinallyBlockStatement) { - super(tryCatchFinallyBlockStatement); + ASTTryCatchFinallyBlockStatement(TryStatement tryStatement) { + super(tryStatement); } @Override diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTTypeWhenBlock.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTTypeWhenBlock.java index e18f6b41d44..3fee5c32a4d 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTTypeWhenBlock.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTTypeWhenBlock.java @@ -4,29 +4,20 @@ package net.sourceforge.pmd.lang.apex.ast; -import com.google.summit.ast.Node; -import org.apache.commons.lang3.reflect.FieldUtils; +import com.google.summit.ast.statement.SwitchStatement; -public final class ASTTypeWhenBlock extends AbstractApexNode.Single { +public final class ASTTypeWhenBlock extends AbstractApexNode.Single { - - ASTTypeWhenBlock(Node node) { - super(node); + ASTTypeWhenBlock(SwitchStatement.WhenType whenType) { + super(whenType); } public String getType() { - // return String.valueOf(node.getTypeRef()); - // TODO(b/239648780) - return null; + return node.getType().asCodeString(); } public String getName() { - // unfortunately the name is not exposed... - try { - return String.valueOf(FieldUtils.readDeclaredField(node, "name", true)); - } catch (IllegalArgumentException | ReflectiveOperationException e) { - return null; - } + return node.getVariableDeclaration().getId().getString(); } @Override diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTValueWhenBlock.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTValueWhenBlock.java index 740ebaad9d1..c50c854c3e2 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTValueWhenBlock.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTValueWhenBlock.java @@ -4,17 +4,14 @@ package net.sourceforge.pmd.lang.apex.ast; +import com.google.summit.ast.statement.SwitchStatement; -import com.google.summit.ast.Node; +public final class ASTValueWhenBlock extends AbstractApexNode.Single { -public final class ASTValueWhenBlock extends AbstractApexNode.Single { - - - ASTValueWhenBlock(Node node) { - super(node); + ASTValueWhenBlock(SwitchStatement.WhenValue whenValue) { + super(whenValue); } - @Override public Object jjtAccept(ApexParserVisitor visitor, Object data) { return visitor.visit(this, data); diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTVariableDeclaration.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTVariableDeclaration.java index 23ff7c7e960..98996077a51 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTVariableDeclaration.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTVariableDeclaration.java @@ -4,15 +4,16 @@ package net.sourceforge.pmd.lang.apex.ast; -import com.google.summit.ast.Node; import net.sourceforge.pmd.Rule; import net.sourceforge.pmd.annotation.InternalApi; -public class ASTVariableDeclaration extends AbstractApexNode.Single implements CanSuppressWarnings { +import com.google.summit.ast.declaration.VariableDeclaration; + +public class ASTVariableDeclaration extends AbstractApexNode.Single implements CanSuppressWarnings { @Deprecated @InternalApi - public ASTVariableDeclaration(Node variableDeclaration) { + public ASTVariableDeclaration(VariableDeclaration variableDeclaration) { super(variableDeclaration); } @@ -23,13 +24,7 @@ public Object jjtAccept(ApexParserVisitor visitor, Object data) { @Override public String getImage() { - /* - if (node.getLocalInfo() != null) { - return node.getLocalInfo().getName(); - } - */ - // TODO(b/239648780) - return null; + return node.getId().getString(); } @Override @@ -47,12 +42,6 @@ public boolean hasSuppressWarningsAnnotationFor(Rule rule) { } public String getType() { - /* - if (node.getLocalInfo() != null) { - return node.getLocalInfo().getType().getApexName(); - } - */ - // TODO(b/239648780) - return null; + return node.getType().asCodeString(); } } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTVariableDeclarationStatements.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTVariableDeclarationStatements.java index f10e09abeff..0adf680101c 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTVariableDeclarationStatements.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTVariableDeclarationStatements.java @@ -4,15 +4,18 @@ package net.sourceforge.pmd.lang.apex.ast; -import com.google.summit.ast.Node; +import java.util.List; + import net.sourceforge.pmd.annotation.InternalApi; -public class ASTVariableDeclarationStatements extends AbstractApexNode.Single { +import com.google.summit.ast.declaration.VariableDeclaration; + +public class ASTVariableDeclarationStatements extends AbstractApexNode.Many { @Deprecated @InternalApi - public ASTVariableDeclarationStatements(Node variableDeclarationStatements) { - super(variableDeclarationStatements); + public ASTVariableDeclarationStatements(List variableDeclarations) { + super(variableDeclarations); } @Override diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTWhileLoopStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTWhileLoopStatement.java index 79034849815..a020a06738e 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTWhileLoopStatement.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTWhileLoopStatement.java @@ -4,14 +4,11 @@ package net.sourceforge.pmd.lang.apex.ast; -import com.google.summit.ast.Node; -import net.sourceforge.pmd.annotation.InternalApi; +import com.google.summit.ast.statement.WhileLoopStatement; -public class ASTWhileLoopStatement extends AbstractApexNode.Single { +public class ASTWhileLoopStatement extends AbstractApexNode.Single { - @Deprecated - @InternalApi - public ASTWhileLoopStatement(Node whileLoopStatement) { + ASTWhileLoopStatement(WhileLoopStatement whileLoopStatement) { super(whileLoopStatement); } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexTreeBuilder.kt b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexTreeBuilder.kt index d232815b765..3cbfb17f4e7 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexTreeBuilder.kt +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexTreeBuilder.kt @@ -22,6 +22,7 @@ import com.google.summit.ast.declaration.MethodDeclaration import com.google.summit.ast.declaration.PropertyDeclaration import com.google.summit.ast.declaration.TriggerDeclaration import com.google.summit.ast.declaration.TypeDeclaration +import com.google.summit.ast.declaration.VariableDeclaration import com.google.summit.ast.expression.ArrayExpression import com.google.summit.ast.expression.AssignExpression import com.google.summit.ast.expression.BinaryExpression @@ -44,8 +45,23 @@ import com.google.summit.ast.initializer.ValuesInitializer import com.google.summit.ast.modifier.KeywordModifier import com.google.summit.ast.modifier.KeywordModifier.Keyword import com.google.summit.ast.modifier.Modifier +import com.google.summit.ast.statement.BreakStatement import com.google.summit.ast.statement.CompoundStatement +import com.google.summit.ast.statement.ContinueStatement +import com.google.summit.ast.statement.DmlStatement +import com.google.summit.ast.statement.DoWhileLoopStatement +import com.google.summit.ast.statement.EnhancedForLoopStatement import com.google.summit.ast.statement.ExpressionStatement +import com.google.summit.ast.statement.ForLoopStatement +import com.google.summit.ast.statement.IfStatement +import com.google.summit.ast.statement.ReturnStatement +import com.google.summit.ast.statement.RunAsStatement +import com.google.summit.ast.statement.Statement +import com.google.summit.ast.statement.SwitchStatement +import com.google.summit.ast.statement.ThrowStatement +import com.google.summit.ast.statement.TryStatement +import com.google.summit.ast.statement.VariableDeclarationStatement +import com.google.summit.ast.statement.WhileLoopStatement @Deprecated("internal") @InternalApi @@ -93,7 +109,7 @@ class ApexTreeBuilder(val sourceCode: String, val parserOptions: ApexParserOptio is FieldDeclaration -> ASTFieldDeclaration(node).apply { buildChildren(node, parent = this) } is CompoundStatement -> ASTBlockStatement(node).apply { buildChildren(node, parent = this) } is ExpressionStatement -> - ASTExpressionStatement(node).apply { buildChildren(node, parent = this) } + ASTExpressionStatement(node.expression).apply { buildChildren(node, parent = this) } is AssignExpression -> ASTAssignmentExpression(node).apply { buildChildren(node, parent = this) } is ArrayExpression -> buildArrayExpression(node) @@ -117,6 +133,25 @@ class ApexTreeBuilder(val sourceCode: String, val parserOptions: ApexParserOptio is ValuesInitializer -> buildValuesInitializer(node) is MapInitializer -> buildMapInitializer(node) is SizedArrayInitializer -> buildSizedArrayInitializer(node) + is DmlStatement -> buildDmlStatement(node) + is IfStatement -> buildIfStatement(node) + is VariableDeclarationStatement -> buildVariableDeclarations(node.variableDeclarations) + is VariableDeclaration -> buildVariableDeclaration(node) + is EnhancedForLoopStatement -> buildEnhancedForLoopStatement(node) + is DoWhileLoopStatement -> buildDoWhileLoopStatement(node) + is WhileLoopStatement -> buildWhileLoopStatement(node) + is ForLoopStatement -> buildForLoopStatement(node) + is SwitchStatement -> ASTSwitchStatement(node).apply { buildChildren(node, parent = this) } + is SwitchStatement.When -> buildSwitchWhen(node) + is ReturnStatement -> ASTReturnStatement(node).apply { buildChildren(node, parent = this) } + is RunAsStatement -> ASTRunAsBlockStatement(node).apply { buildChildren(node, parent = this) } + is ThrowStatement -> ASTThrowStatement(node).apply { buildChildren(node, parent = this) } + is TryStatement -> buildTryStatement(node) + is TryStatement.CatchBlock -> + ASTCatchBlockStatement(node).apply { buildChildren(node, parent = this) } + is BreakStatement -> ASTBreakStatement(node).apply { buildChildren(node, parent = this) } + is ContinueStatement -> + ASTContinueStatement(node).apply { buildChildren(node, parent = this) } is Identifier, is KeywordModifier, is TypeRef -> null @@ -349,7 +384,7 @@ class ApexTreeBuilder(val sourceCode: String, val parserOptions: ApexParserOptio components: List, receiver: Node?, referenceType: ReferenceType, - isSafe: Boolean + isSafe: Boolean = false ) = if (receiver == null && components.isEmpty()) { ASTEmptyReferenceExpression() @@ -424,8 +459,184 @@ class ApexTreeBuilder(val sourceCode: String, val parserOptions: ApexParserOptio private fun buildSizedArrayInitializer(node: SizedArrayInitializer) = ASTNewListInitExpression(node).apply { buildChildren(node, parent = this) } + /** Builds an [ApexNode] wrapper for the [DmlStatement]. */ + private fun buildDmlStatement(node: DmlStatement) = + when (node) { + is DmlStatement.Insert -> ASTDmlInsertStatement(node) + is DmlStatement.Update -> ASTDmlUpdateStatement(node) + is DmlStatement.Delete -> ASTDmlDeleteStatement(node) + is DmlStatement.Undelete -> ASTDmlUndeleteStatement(node) + is DmlStatement.Upsert -> ASTDmlUpsertStatement(node) + is DmlStatement.Merge -> ASTDmlMergeStatement(node) + }.apply { buildChildren(node, parent = this) } + + /** Wraps the body of a control statement with an [ASTBlockStatement] if it isn't already one. */ + private fun wrapBody(body: Statement, parent: ApexNode<*>) = + when (body) { + is CompoundStatement -> build(body, parent) as ASTBlockStatement + else -> ASTBlockStatement(body).apply { buildAndSetParent(body, parent = this) } + } + + /** Builds an [ASTIfElseBlockStatement] wrapper for the [IfStatement]. */ + private fun buildIfStatement(node: IfStatement): ASTIfElseBlockStatement { + val (ifBlocks, elseBlock) = flattenIfStatement(node) + + /** Builds an [ASTIfBlockStatement] wrapper for the [if block][IfStatement]. */ + fun buildIfBlock(ifBlock: IfStatement) = + ASTIfBlockStatement(ifBlock).apply { + buildCondition(ifBlock.condition).also { it.setParent(this) } + wrapBody(ifBlock.thenStatement, parent = this).also { it.setParent(this) } + } + + return ASTIfElseBlockStatement(node, elseBlock != null).apply { + ifBlocks.forEach { ifBlock -> buildIfBlock(ifBlock).also { it.setParent(this) } } + if (elseBlock != null) { + wrapBody(elseBlock, parent = this).also { it.setParent(this) } + } + } + } + + /** Result of [flattenIfStatement]. */ + private data class FlatIfStatement(val ifBlocks: List, val elseBlock: Statement?) + + /** Flattens an [IfStatement] into a list of [IfStatement]s. */ + private fun flattenIfStatement( + node: Statement?, + ifBlocks: List = emptyList() + ): FlatIfStatement = + when (node) { + is IfStatement -> + // Extract node and continue flattening + flattenIfStatement(node = node.elseStatement, ifBlocks = ifBlocks + node) + else -> + // Can't flatten + FlatIfStatement(ifBlocks, elseBlock = node) + } + + /** Builds an [ASTVariableDeclarationStatements] for the [VariableDeclaration] list. */ + private fun buildVariableDeclarations(declarations: List) = + ASTVariableDeclarationStatements(declarations).apply { + if (declarations.isNotEmpty()) { + // Modifiers are duplicated between all declarations - use any + buildModifiers(declarations.first().modifiers).also { it.setParent(this) } + } + declarations.forEach { buildAndSetParent(it, parent = this) } + } + + /** Builds an [ASTVariableDeclaration] wrapper for the [VariableDeclaration]. */ + private fun buildVariableDeclaration(node: VariableDeclaration) = + ASTVariableDeclaration(node).apply { + // Exclude modifiers - built in ASTVariableDeclarationStatements + buildChildren(node, parent = this, exclude = { it in node.modifiers }) + + ASTVariableExpression(node.id) + .apply { + buildReferenceExpression(components = emptyList(), receiver = null, ReferenceType.NONE) + .also { it.setParent(this) } + } + .also { it.setParent(this) } + } + + /** Builds an [ASTForEachStatement] wrapper for the [EnhancedForLoopStatement]. */ + private fun buildEnhancedForLoopStatement(node: EnhancedForLoopStatement) = + ASTForEachStatement(node).apply { + buildVariableDeclarations(listOf(node.elementDeclaration)).also { it.setParent(this) } + + ASTVariableExpression(node.elementDeclaration.id) + .apply { + buildReferenceExpression(components = emptyList(), receiver = null, ReferenceType.NONE) + .also { it.setParent(this) } + } + .also { it.setParent(this) } + + wrapBody(node.body, parent = this).also { it.setParent(this) } + + buildChildren( + node, + parent = this, + exclude = { it == node.elementDeclaration || it == node.body } + ) + } + + /** Builds an [ASTDoLoopStatement] wrapper for the [DoWhileLoopStatement]. */ + private fun buildDoWhileLoopStatement(node: DoWhileLoopStatement) = + ASTDoLoopStatement(node).apply { + buildCondition(node.condition).also { it.setParent(this) } + wrapBody(node.body, parent = this).also { it.setParent(this) } + buildChildren(node, parent = this, exclude = { it == node.condition || it == node.body }) + } + + /** Builds an [ASTWhileLoopStatement] wrapper for the [WhileLoopStatement]. */ + private fun buildWhileLoopStatement(node: WhileLoopStatement) = + ASTWhileLoopStatement(node).apply { + buildCondition(node.condition).also { it.setParent(this) } + wrapBody(node.body, parent = this).also { it.setParent(this) } + buildChildren(node, parent = this, exclude = { it == node.condition || it == node.body }) + } + + /** Builds an [ASTForEachStatement] wrapper for the [ForLoopStatement]. */ + private fun buildForLoopStatement(node: ForLoopStatement) = + ASTForLoopStatement(node).apply { + fun buildInitialization(expr: Expression) = + ASTExpressionStatement(expr).apply { buildAndSetParent(expr, parent = this) } + + if (node.declarations.isNotEmpty()) { + buildVariableDeclarations(node.declarations).also { it.setParent(this) } + } + if (node.condition != null) { + buildCondition(node.condition!!).also { it.setParent(this) } + } + node.initializations.forEach { expr -> buildInitialization(expr).also { it.setParent(this) } } + + wrapBody(node.body, parent = this).also { it.setParent(this) } + + buildChildren( + node, + parent = this, + exclude = { + it in node.declarations || + it == node.condition || + it in node.initializations || + it == node.body + } + ) + } + + /** + * Builds an [ASTValueWhenBlock], [ASTTypeWhenBlock], or [ASTElseWhenBlock] wrapper for the + * [SwitchStatement.When]. + */ + private fun buildSwitchWhen(node: SwitchStatement.When) = + when (node) { + is SwitchStatement.WhenValue -> + ASTValueWhenBlock(node).apply { + node.values.forEach { value -> + when (value) { + is LiteralExpression, + is UnaryExpression /* negative */ -> + ASTLiteralCase(value).apply { buildAndSetParent(value, parent = this) } + is VariableExpression -> ASTIdentifierCase(value) + else -> throw ParseException("Invalid when value type") + }.also { it.setParent(this) } + } + + buildChildren(node, parent = this, exclude = { it in node.values }) + } + is SwitchStatement.WhenType -> + ASTTypeWhenBlock(node).apply { buildChildren(node, parent = this) } + is SwitchStatement.WhenElse -> + ASTElseWhenBlock(node).apply { buildChildren(node, parent = this) } + } + + /** Builds an [ASTTryCatchFinallyBlockStatement] wrapper for the [TryStatement]. */ + private fun buildTryStatement(node: TryStatement) = + ASTTryCatchFinallyBlockStatement(node).apply { + buildAndSetParent(node.body, parent = this) + buildChildren(node, parent = this, exclude = { it == node.body }) + } + /** Builds an [ASTStandardCondition] wrapper for the [condition]. */ - private fun buildCondition(condition: Node?) = + private fun buildCondition(condition: Node) = ASTStandardCondition(condition).apply { buildAndSetParent(condition, this) } /** Builds an [ASTModifierNode] wrapper for the list of [Modifier]s. */