From 72bb311aba2e2ae848d7a70351f6619def84ceaa Mon Sep 17 00:00:00 2001 From: Aaron Hurst Date: Sun, 16 Oct 2022 21:27:50 +0000 Subject: [PATCH 01/15] Make AST node constructors package-private. Change-Id: Iafdf7b08b0f8f456b981c797209735a1c27e0b33 --- .../net/sourceforge/pmd/lang/apex/ast/ASTMapEntryNode.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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; From bd8e47edd1013d80b784b093edcfd391e144a6d4 Mon Sep 17 00:00:00 2001 From: Edward Klimoshenko Date: Fri, 19 Aug 2022 09:40:03 +0000 Subject: [PATCH 02/15] Build `if` statements Change-Id: I4db2d2dfd028ae820c73f9fcb5fff4fa5e6c3ece --- .../lang/apex/ast/ASTIfBlockStatement.java | 9 +-- .../apex/ast/ASTIfElseBlockStatement.java | 16 ++--- .../pmd/lang/apex/ast/ApexTreeBuilder.kt | 58 +++++++++++++++++++ 3 files changed, 72 insertions(+), 11 deletions(-) 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..ef70958fc67 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,16 @@ package net.sourceforge.pmd.lang.apex.ast; -import com.google.summit.ast.Node; import net.sourceforge.pmd.annotation.InternalApi; -public class ASTIfBlockStatement extends AbstractApexNode.Single { +import com.google.summit.ast.statement.IfStatement; + +public class ASTIfBlockStatement extends AbstractApexNode.Single { @Deprecated @InternalApi - public ASTIfBlockStatement(Node ifBlockStatement) { - super(ifBlockStatement); + public 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..d8c76ac5836 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,19 @@ package net.sourceforge.pmd.lang.apex.ast; -import com.google.summit.ast.Node; import net.sourceforge.pmd.annotation.InternalApi; -public class ASTIfElseBlockStatement extends AbstractApexNode.Single { +import com.google.summit.ast.statement.IfStatement; + +public class ASTIfElseBlockStatement extends AbstractApexNode.Single { + + private final boolean hasElseStatement; @Deprecated @InternalApi - public ASTIfElseBlockStatement(Node ifElseBlockStatement) { - super(ifElseBlockStatement); + public ASTIfElseBlockStatement(IfStatement ifStatement, boolean hasElseStatement) { + super(ifStatement); + this.hasElseStatement = hasElseStatement; } @Override @@ -21,8 +25,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/ApexTreeBuilder.kt b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexTreeBuilder.kt index d232815b765..bacbf48a21a 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 @@ -46,6 +46,8 @@ import com.google.summit.ast.modifier.KeywordModifier.Keyword import com.google.summit.ast.modifier.Modifier import com.google.summit.ast.statement.CompoundStatement import com.google.summit.ast.statement.ExpressionStatement +import com.google.summit.ast.statement.IfStatement +import com.google.summit.ast.statement.Statement @Deprecated("internal") @InternalApi @@ -117,6 +119,8 @@ 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 Identifier, is KeywordModifier, is TypeRef -> null @@ -424,6 +428,60 @@ 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 [ASTStandardCondition] wrapper for the [condition]. */ private fun buildCondition(condition: Node?) = ASTStandardCondition(condition).apply { buildAndSetParent(condition, this) } From f813961ec510181348d4325e6a939dd036d377cf Mon Sep 17 00:00:00 2001 From: Edward Klimoshenko Date: Fri, 19 Aug 2022 10:07:54 +0000 Subject: [PATCH 03/15] Build variable declarations --- .../lang/apex/ast/ASTVariableDeclaration.java | 23 ++++---------- .../ast/ASTVariableDeclarationStatements.java | 11 ++++--- .../pmd/lang/apex/ast/ApexTreeBuilder.kt | 30 ++++++++++++++++++- 3 files changed, 42 insertions(+), 22 deletions(-) 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/ApexTreeBuilder.kt b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexTreeBuilder.kt index bacbf48a21a..0f5c7279d0e 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 @@ -48,6 +49,7 @@ import com.google.summit.ast.statement.CompoundStatement import com.google.summit.ast.statement.ExpressionStatement import com.google.summit.ast.statement.IfStatement import com.google.summit.ast.statement.Statement +import com.google.summit.ast.statement.VariableDeclarationStatement @Deprecated("internal") @InternalApi @@ -121,6 +123,8 @@ class ApexTreeBuilder(val sourceCode: String, val parserOptions: ApexParserOptio is SizedArrayInitializer -> buildSizedArrayInitializer(node) is DmlStatement -> buildDmlStatement(node) is IfStatement -> buildIfStatement(node) + is VariableDeclarationStatement -> buildVariableDeclarations(node.variableDeclarations) + is VariableDeclaration -> buildVariableDeclaration(node) is Identifier, is KeywordModifier, is TypeRef -> null @@ -353,7 +357,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() @@ -482,6 +486,30 @@ class ApexTreeBuilder(val sourceCode: String, val parserOptions: ApexParserOptio 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 [ASTStandardCondition] wrapper for the [condition]. */ private fun buildCondition(condition: Node?) = ASTStandardCondition(condition).apply { buildAndSetParent(condition, this) } From 3321997e0805c6ecb557ae19d7d43db49324841a Mon Sep 17 00:00:00 2001 From: Edward Klimoshenko Date: Sun, 21 Aug 2022 16:01:03 +0000 Subject: [PATCH 04/15] Build for-each loops Change-Id: Ica6c9ad3f0da89b4522dbae6f2cc5d80399ea72a --- .../lang/apex/ast/ASTForEachStatement.java | 9 +++---- .../pmd/lang/apex/ast/ApexTreeBuilder.kt | 24 +++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) 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..0ddcc2839e5 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,16 @@ package net.sourceforge.pmd.lang.apex.ast; -import com.google.summit.ast.Node; import net.sourceforge.pmd.annotation.InternalApi; -public class ASTForEachStatement extends AbstractApexNode.Single { +import com.google.summit.ast.statement.EnhancedForLoopStatement; + +public class ASTForEachStatement extends AbstractApexNode.Single { @Deprecated @InternalApi - public ASTForEachStatement(Node forEachStatement) { - super(forEachStatement); + public ASTForEachStatement(EnhancedForLoopStatement enhancedForLoopStatement) { + super(enhancedForLoopStatement); } @Override 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 0f5c7279d0e..1e21dd09de5 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 @@ -46,6 +46,8 @@ 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.CompoundStatement +import com.google.summit.ast.statement.DmlStatement +import com.google.summit.ast.statement.EnhancedForLoopStatement import com.google.summit.ast.statement.ExpressionStatement import com.google.summit.ast.statement.IfStatement import com.google.summit.ast.statement.Statement @@ -125,6 +127,7 @@ class ApexTreeBuilder(val sourceCode: String, val parserOptions: ApexParserOptio is IfStatement -> buildIfStatement(node) is VariableDeclarationStatement -> buildVariableDeclarations(node.variableDeclarations) is VariableDeclaration -> buildVariableDeclaration(node) + is EnhancedForLoopStatement -> buildEnhancedForLoopStatement(node) is Identifier, is KeywordModifier, is TypeRef -> null @@ -510,6 +513,27 @@ class ApexTreeBuilder(val sourceCode: String, val parserOptions: ApexParserOptio .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 [ASTStandardCondition] wrapper for the [condition]. */ private fun buildCondition(condition: Node?) = ASTStandardCondition(condition).apply { buildAndSetParent(condition, this) } From 6e5fe57a1013ff9cb32991efd4f8ed8f763556e5 Mon Sep 17 00:00:00 2001 From: Edward Klimoshenko Date: Sun, 21 Aug 2022 16:04:44 +0000 Subject: [PATCH 05/15] Build do-while loops --- .../pmd/lang/apex/ast/ASTDoLoopStatement.java | 9 +++++---- .../sourceforge/pmd/lang/apex/ast/ApexTreeBuilder.kt | 10 ++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) 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..5ec5f17a7fc 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,16 @@ package net.sourceforge.pmd.lang.apex.ast; -import com.google.summit.ast.Node; import net.sourceforge.pmd.annotation.InternalApi; -public class ASTDoLoopStatement extends AbstractApexNode.Single { +import com.google.summit.ast.statement.DoWhileLoopStatement; + +public class ASTDoLoopStatement extends AbstractApexNode.Single { @Deprecated @InternalApi - public ASTDoLoopStatement(Node doLoopStatement) { - super(doLoopStatement); + public ASTDoLoopStatement(DoWhileLoopStatement doWhileLoopStatement) { + super(doWhileLoopStatement); } @Override 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 1e21dd09de5..a68a55f6742 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 @@ -47,6 +47,7 @@ import com.google.summit.ast.modifier.KeywordModifier.Keyword import com.google.summit.ast.modifier.Modifier import com.google.summit.ast.statement.CompoundStatement 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.IfStatement @@ -128,6 +129,7 @@ class ApexTreeBuilder(val sourceCode: String, val parserOptions: ApexParserOptio is VariableDeclarationStatement -> buildVariableDeclarations(node.variableDeclarations) is VariableDeclaration -> buildVariableDeclaration(node) is EnhancedForLoopStatement -> buildEnhancedForLoopStatement(node) + is DoWhileLoopStatement -> buildDoWhileLoopStatement(node) is Identifier, is KeywordModifier, is TypeRef -> null @@ -534,6 +536,14 @@ class ApexTreeBuilder(val sourceCode: String, val parserOptions: ApexParserOptio ) } + /** 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 [ASTStandardCondition] wrapper for the [condition]. */ private fun buildCondition(condition: Node?) = ASTStandardCondition(condition).apply { buildAndSetParent(condition, this) } From de2bc8083a97be21b9da4605582c5ea9249dae3e Mon Sep 17 00:00:00 2001 From: Edward Klimoshenko Date: Sun, 21 Aug 2022 16:08:06 +0000 Subject: [PATCH 06/15] Build `while` loops --- .../pmd/lang/apex/ast/ASTWhileLoopStatement.java | 7 ++++--- .../sourceforge/pmd/lang/apex/ast/ApexTreeBuilder.kt | 10 ++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) 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..32191a08b8b 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,15 @@ package net.sourceforge.pmd.lang.apex.ast; -import com.google.summit.ast.Node; import net.sourceforge.pmd.annotation.InternalApi; -public class ASTWhileLoopStatement extends AbstractApexNode.Single { +import com.google.summit.ast.statement.WhileLoopStatement; + +public class ASTWhileLoopStatement extends AbstractApexNode.Single { @Deprecated @InternalApi - public ASTWhileLoopStatement(Node whileLoopStatement) { + public 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 a68a55f6742..0390f04f22e 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 @@ -53,6 +53,7 @@ import com.google.summit.ast.statement.ExpressionStatement import com.google.summit.ast.statement.IfStatement import com.google.summit.ast.statement.Statement import com.google.summit.ast.statement.VariableDeclarationStatement +import com.google.summit.ast.statement.WhileLoopStatement @Deprecated("internal") @InternalApi @@ -130,6 +131,7 @@ class ApexTreeBuilder(val sourceCode: String, val parserOptions: ApexParserOptio is VariableDeclaration -> buildVariableDeclaration(node) is EnhancedForLoopStatement -> buildEnhancedForLoopStatement(node) is DoWhileLoopStatement -> buildDoWhileLoopStatement(node) + is WhileLoopStatement -> buildWhileLoopStatement(node) is Identifier, is KeywordModifier, is TypeRef -> null @@ -544,6 +546,14 @@ class ApexTreeBuilder(val sourceCode: String, val parserOptions: ApexParserOptio 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 [ASTStandardCondition] wrapper for the [condition]. */ private fun buildCondition(condition: Node?) = ASTStandardCondition(condition).apply { buildAndSetParent(condition, this) } From 75690c383b144098731b4fa157735855d8f3c3a2 Mon Sep 17 00:00:00 2001 From: Edward Klimoshenko Date: Fri, 19 Aug 2022 09:49:33 +0000 Subject: [PATCH 07/15] Build `for` loops Change-Id: If1bbe27701e190321f53f19be384be10d2885ec5 --- .../lang/apex/ast/ASTExpressionStatement.java | 34 +++---------------- .../lang/apex/ast/ASTForLoopStatement.java | 7 ++-- .../pmd/lang/apex/ast/ApexTreeBuilder.kt | 34 +++++++++++++++++-- 3 files changed, 40 insertions(+), 35 deletions(-) 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/ASTForLoopStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTForLoopStatement.java index 8c149170ebd..b6e71c9aafe 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,15 @@ package net.sourceforge.pmd.lang.apex.ast; -import com.google.summit.ast.Node; import net.sourceforge.pmd.annotation.InternalApi; -public class ASTForLoopStatement extends AbstractApexNode.Single { +import com.google.summit.ast.statement.ForLoopStatement; + +public class ASTForLoopStatement extends AbstractApexNode.Single { @Deprecated @InternalApi - public ASTForLoopStatement(Node forLoopStatement) { + public ASTForLoopStatement(ForLoopStatement forLoopStatement) { super(forLoopStatement); } 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 0390f04f22e..62567f8fc89 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 @@ -50,6 +50,7 @@ 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.Statement import com.google.summit.ast.statement.VariableDeclarationStatement @@ -101,7 +102,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) @@ -132,6 +133,7 @@ class ApexTreeBuilder(val sourceCode: String, val parserOptions: ApexParserOptio is EnhancedForLoopStatement -> buildEnhancedForLoopStatement(node) is DoWhileLoopStatement -> buildDoWhileLoopStatement(node) is WhileLoopStatement -> buildWhileLoopStatement(node) + is ForLoopStatement -> buildForLoopStatement(node) is Identifier, is KeywordModifier, is TypeRef -> null @@ -554,8 +556,36 @@ class ApexTreeBuilder(val sourceCode: String, val parserOptions: ApexParserOptio 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 [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. */ From cf054a1427fb044c41da68d869df4a9aa72e50ab Mon Sep 17 00:00:00 2001 From: Edward Klimoshenko Date: Sun, 21 Aug 2022 11:31:11 +0000 Subject: [PATCH 08/15] Build `switch` statements --- .../pmd/lang/apex/ast/ASTElseWhenBlock.java | 10 +++---- .../pmd/lang/apex/ast/ASTSwitchStatement.java | 10 +++---- .../pmd/lang/apex/ast/ASTTypeWhenBlock.java | 21 ++++---------- .../pmd/lang/apex/ast/ASTValueWhenBlock.java | 11 +++---- .../pmd/lang/apex/ast/ApexTreeBuilder.kt | 29 +++++++++++++++++++ 5 files changed, 47 insertions(+), 34 deletions(-) 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/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/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/ApexTreeBuilder.kt b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexTreeBuilder.kt index 62567f8fc89..a474ea01416 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 @@ -53,6 +53,7 @@ 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.Statement +import com.google.summit.ast.statement.SwitchStatement import com.google.summit.ast.statement.VariableDeclarationStatement import com.google.summit.ast.statement.WhileLoopStatement @@ -134,6 +135,8 @@ class ApexTreeBuilder(val sourceCode: String, val parserOptions: ApexParserOptio 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 Identifier, is KeywordModifier, is TypeRef -> null @@ -584,6 +587,32 @@ class ApexTreeBuilder(val sourceCode: String, val parserOptions: ApexParserOptio ) } + /** + * 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 [ASTStandardCondition] wrapper for the [condition]. */ private fun buildCondition(condition: Node) = ASTStandardCondition(condition).apply { buildAndSetParent(condition, this) } From d0395462e1f703c46220255f0a524dc9f382285a Mon Sep 17 00:00:00 2001 From: Edward Klimoshenko Date: Sun, 21 Aug 2022 12:19:38 +0000 Subject: [PATCH 09/15] Build `return` statements --- .../sourceforge/pmd/lang/apex/ast/ASTReturnStatement.java | 7 ++++--- .../net/sourceforge/pmd/lang/apex/ast/ApexTreeBuilder.kt | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) 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..9b221957b01 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,15 @@ package net.sourceforge.pmd.lang.apex.ast; -import com.google.summit.ast.Node; import net.sourceforge.pmd.annotation.InternalApi; -public class ASTReturnStatement extends AbstractApexNode.Single { +import com.google.summit.ast.statement.ReturnStatement; + +public class ASTReturnStatement extends AbstractApexNode.Single { @Deprecated @InternalApi - public ASTReturnStatement(Node returnStatement) { + public ASTReturnStatement(ReturnStatement returnStatement) { super(returnStatement); } 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 a474ea01416..6970bebf9a4 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 @@ -52,6 +52,7 @@ 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.Statement import com.google.summit.ast.statement.SwitchStatement import com.google.summit.ast.statement.VariableDeclarationStatement @@ -137,6 +138,7 @@ class ApexTreeBuilder(val sourceCode: String, val parserOptions: ApexParserOptio 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 Identifier, is KeywordModifier, is TypeRef -> null From 91ac5130153e24350c055617d72116c534ca5ec4 Mon Sep 17 00:00:00 2001 From: Edward Klimoshenko Date: Sun, 21 Aug 2022 12:20:39 +0000 Subject: [PATCH 10/15] Build `runAs` statements --- .../pmd/lang/apex/ast/ASTRunAsBlockStatement.java | 9 +++++---- .../net/sourceforge/pmd/lang/apex/ast/ApexTreeBuilder.kt | 2 ++ 2 files changed, 7 insertions(+), 4 deletions(-) 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..836b15b8cd7 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,16 @@ package net.sourceforge.pmd.lang.apex.ast; -import com.google.summit.ast.Node; import net.sourceforge.pmd.annotation.InternalApi; -public class ASTRunAsBlockStatement extends AbstractApexNode.Single { +import com.google.summit.ast.statement.RunAsStatement; + +public class ASTRunAsBlockStatement extends AbstractApexNode.Single { @Deprecated @InternalApi - public ASTRunAsBlockStatement(Node runAsBlockStatement) { - super(runAsBlockStatement); + public ASTRunAsBlockStatement(RunAsStatement runAsStatement) { + super(runAsStatement); } @Override 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 6970bebf9a4..d1de9a13af3 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 @@ -53,6 +53,7 @@ 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.VariableDeclarationStatement @@ -139,6 +140,7 @@ class ApexTreeBuilder(val sourceCode: String, val parserOptions: ApexParserOptio 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 Identifier, is KeywordModifier, is TypeRef -> null From 298b99815cf20dc2e6c3b0f38718eabbafc1dde4 Mon Sep 17 00:00:00 2001 From: Edward Klimoshenko Date: Sun, 21 Aug 2022 12:21:52 +0000 Subject: [PATCH 11/15] Build `throw` statements --- .../sourceforge/pmd/lang/apex/ast/ASTThrowStatement.java | 7 ++++--- .../net/sourceforge/pmd/lang/apex/ast/ApexTreeBuilder.kt | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) 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..8340a9132a8 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,15 @@ package net.sourceforge.pmd.lang.apex.ast; -import com.google.summit.ast.Node; import net.sourceforge.pmd.annotation.InternalApi; -public class ASTThrowStatement extends AbstractApexNode.Single { +import com.google.summit.ast.statement.ThrowStatement; + +public class ASTThrowStatement extends AbstractApexNode.Single { @Deprecated @InternalApi - public ASTThrowStatement(Node throwStatement) { + public ASTThrowStatement(ThrowStatement throwStatement) { super(throwStatement); } 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 d1de9a13af3..5e7efe8b501 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 @@ -56,6 +56,7 @@ 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.VariableDeclarationStatement import com.google.summit.ast.statement.WhileLoopStatement @@ -141,6 +142,7 @@ class ApexTreeBuilder(val sourceCode: String, val parserOptions: ApexParserOptio 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 Identifier, is KeywordModifier, is TypeRef -> null From 3acd9aadfb0b525610d5cc630608a07b8a9299da Mon Sep 17 00:00:00 2001 From: Edward Klimoshenko Date: Sun, 21 Aug 2022 12:23:41 +0000 Subject: [PATCH 12/15] Build `try` statements --- .../lang/apex/ast/ASTCatchBlockStatement.java | 21 +++++++------------ .../ast/ASTTryCatchFinallyBlockStatement.java | 9 ++++---- .../pmd/lang/apex/ast/ApexTreeBuilder.kt | 11 ++++++++++ 3 files changed, 24 insertions(+), 17 deletions(-) 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..0fab46d14eb 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,16 @@ package net.sourceforge.pmd.lang.apex.ast; -import com.google.summit.ast.Node; import net.sourceforge.pmd.annotation.InternalApi; -public class ASTCatchBlockStatement extends AbstractApexCommentContainerNode { +import com.google.summit.ast.statement.TryStatement; + +public class ASTCatchBlockStatement extends AbstractApexCommentContainerNode { @Deprecated @InternalApi - public ASTCatchBlockStatement(Node catchBlockStatement) { - super(catchBlockStatement); + public ASTCatchBlockStatement(TryStatement.CatchBlock catchBlock) { + super(catchBlock); } @Override @@ -21,20 +22,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/ASTTryCatchFinallyBlockStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTTryCatchFinallyBlockStatement.java index a99c067f7df..f63cf748a54 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,18 @@ package net.sourceforge.pmd.lang.apex.ast; -import com.google.summit.ast.Node; import java.util.List; +import com.google.summit.ast.statement.TryStatement; + import net.sourceforge.pmd.annotation.InternalApi; -public class ASTTryCatchFinallyBlockStatement extends AbstractApexNode.Single { +public class ASTTryCatchFinallyBlockStatement extends AbstractApexNode.Single { @Deprecated @InternalApi - public ASTTryCatchFinallyBlockStatement(Node tryCatchFinallyBlockStatement) { - super(tryCatchFinallyBlockStatement); + public ASTTryCatchFinallyBlockStatement(TryStatement tryStatement) { + super(tryStatement); } @Override 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 5e7efe8b501..a66a7d16b29 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 @@ -57,6 +57,7 @@ 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 @@ -143,6 +144,9 @@ class ApexTreeBuilder(val sourceCode: String, val parserOptions: ApexParserOptio 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 Identifier, is KeywordModifier, is TypeRef -> null @@ -619,6 +623,13 @@ class ApexTreeBuilder(val sourceCode: String, val parserOptions: ApexParserOptio 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) = ASTStandardCondition(condition).apply { buildAndSetParent(condition, this) } From 04732d86d69172624312ad9c7242829b7c533aac Mon Sep 17 00:00:00 2001 From: Edward Klimoshenko Date: Sun, 21 Aug 2022 12:25:55 +0000 Subject: [PATCH 13/15] Build `break` statements --- .../sourceforge/pmd/lang/apex/ast/ASTBreakStatement.java | 7 ++++--- .../net/sourceforge/pmd/lang/apex/ast/ApexTreeBuilder.kt | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) 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..ca926a7bbec 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,15 @@ package net.sourceforge.pmd.lang.apex.ast; -import com.google.summit.ast.Node; import net.sourceforge.pmd.annotation.InternalApi; -public class ASTBreakStatement extends AbstractApexNode.Single { +import com.google.summit.ast.statement.BreakStatement; + +public class ASTBreakStatement extends AbstractApexNode.Single { @Deprecated @InternalApi - public ASTBreakStatement(Node breakStatement) { + public ASTBreakStatement(BreakStatement breakStatement) { super(breakStatement); } 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 a66a7d16b29..5d63d95114a 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 @@ -45,6 +45,7 @@ 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.DmlStatement import com.google.summit.ast.statement.DoWhileLoopStatement @@ -147,6 +148,7 @@ class ApexTreeBuilder(val sourceCode: String, val parserOptions: ApexParserOptio is TryStatement -> buildTryStatement(node) is TryStatement.CatchBlock -> ASTCatchBlockStatement(node).apply { buildChildren(node, parent = this) } + is BreakStatement -> ASTBreakStatement(node).apply { buildChildren(node, parent = this) } is Identifier, is KeywordModifier, is TypeRef -> null From a57fd96982ea247d32d64ad9198fc2480bcf1ad3 Mon Sep 17 00:00:00 2001 From: Edward Klimoshenko Date: Sun, 21 Aug 2022 12:26:22 +0000 Subject: [PATCH 14/15] Build `continue` statements --- .../pmd/lang/apex/ast/ASTContinueStatement.java | 7 ++++--- .../net/sourceforge/pmd/lang/apex/ast/ApexTreeBuilder.kt | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) 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..73d7bd5f9ea 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,15 @@ package net.sourceforge.pmd.lang.apex.ast; -import com.google.summit.ast.Node; import net.sourceforge.pmd.annotation.InternalApi; -public class ASTContinueStatement extends AbstractApexNode.Single { +import com.google.summit.ast.statement.ContinueStatement; + +public class ASTContinueStatement extends AbstractApexNode.Single { @Deprecated @InternalApi - public ASTContinueStatement(Node continueStatement) { + public ASTContinueStatement(ContinueStatement continueStatement) { super(continueStatement); } 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 5d63d95114a..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 @@ -47,6 +47,7 @@ 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 @@ -149,6 +150,8 @@ class ApexTreeBuilder(val sourceCode: String, val parserOptions: ApexParserOptio 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 From e4a28b70fd221c13779c43a0399c7a1a19ec2c45 Mon Sep 17 00:00:00 2001 From: Aaron Hurst Date: Sun, 16 Oct 2022 22:27:25 +0000 Subject: [PATCH 15/15] Post-merge fixup. Make new AST constructors package-private. Change-Id: I9b40bb44474894dfa66ef3ee542a2602a9a084ea --- .../sourceforge/pmd/lang/apex/ast/ASTBreakStatement.java | 6 +----- .../pmd/lang/apex/ast/ASTCatchBlockStatement.java | 6 +----- .../pmd/lang/apex/ast/ASTConstructorPreambleStatement.java | 5 +---- .../sourceforge/pmd/lang/apex/ast/ASTContinueStatement.java | 6 +----- .../pmd/lang/apex/ast/ASTDmlDeleteStatement.java | 5 +---- .../pmd/lang/apex/ast/ASTDmlInsertStatement.java | 5 +---- .../sourceforge/pmd/lang/apex/ast/ASTDmlMergeStatement.java | 5 +---- .../pmd/lang/apex/ast/ASTDmlUndeleteStatement.java | 5 +---- .../pmd/lang/apex/ast/ASTDmlUpdateStatement.java | 5 +---- .../pmd/lang/apex/ast/ASTDmlUpsertStatement.java | 5 +---- .../sourceforge/pmd/lang/apex/ast/ASTDoLoopStatement.java | 6 +----- .../sourceforge/pmd/lang/apex/ast/ASTForEachStatement.java | 6 +----- .../sourceforge/pmd/lang/apex/ast/ASTForLoopStatement.java | 6 +----- .../sourceforge/pmd/lang/apex/ast/ASTIfBlockStatement.java | 6 +----- .../pmd/lang/apex/ast/ASTIfElseBlockStatement.java | 6 +----- .../pmd/lang/apex/ast/ASTMethodBlockStatement.java | 5 +---- .../sourceforge/pmd/lang/apex/ast/ASTMultiStatement.java | 5 +---- .../sourceforge/pmd/lang/apex/ast/ASTReturnStatement.java | 6 +----- .../pmd/lang/apex/ast/ASTRunAsBlockStatement.java | 6 +----- .../net/sourceforge/pmd/lang/apex/ast/ASTStatement.java | 5 +---- .../sourceforge/pmd/lang/apex/ast/ASTThrowStatement.java | 6 +----- .../pmd/lang/apex/ast/ASTTryCatchFinallyBlockStatement.java | 6 +----- .../pmd/lang/apex/ast/ASTWhileLoopStatement.java | 6 +----- 23 files changed, 23 insertions(+), 105 deletions(-) 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 ca926a7bbec..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,15 +4,11 @@ package net.sourceforge.pmd.lang.apex.ast; -import net.sourceforge.pmd.annotation.InternalApi; - import com.google.summit.ast.statement.BreakStatement; public class ASTBreakStatement extends AbstractApexNode.Single { - @Deprecated - @InternalApi - public ASTBreakStatement(BreakStatement 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 0fab46d14eb..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,11 @@ package net.sourceforge.pmd.lang.apex.ast; -import net.sourceforge.pmd.annotation.InternalApi; - import com.google.summit.ast.statement.TryStatement; public class ASTCatchBlockStatement extends AbstractApexCommentContainerNode { - @Deprecated - @InternalApi - public ASTCatchBlockStatement(TryStatement.CatchBlock catchBlock) { + ASTCatchBlockStatement(TryStatement.CatchBlock catchBlock) { super(catchBlock); } 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 73d7bd5f9ea..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,15 +4,11 @@ package net.sourceforge.pmd.lang.apex.ast; -import net.sourceforge.pmd.annotation.InternalApi; - import com.google.summit.ast.statement.ContinueStatement; public class ASTContinueStatement extends AbstractApexNode.Single { - @Deprecated - @InternalApi - public ASTContinueStatement(ContinueStatement 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 5ec5f17a7fc..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,11 @@ package net.sourceforge.pmd.lang.apex.ast; -import net.sourceforge.pmd.annotation.InternalApi; - import com.google.summit.ast.statement.DoWhileLoopStatement; public class ASTDoLoopStatement extends AbstractApexNode.Single { - @Deprecated - @InternalApi - public ASTDoLoopStatement(DoWhileLoopStatement doWhileLoopStatement) { + ASTDoLoopStatement(DoWhileLoopStatement doWhileLoopStatement) { super(doWhileLoopStatement); } 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 0ddcc2839e5..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,11 @@ package net.sourceforge.pmd.lang.apex.ast; -import net.sourceforge.pmd.annotation.InternalApi; - import com.google.summit.ast.statement.EnhancedForLoopStatement; public class ASTForEachStatement extends AbstractApexNode.Single { - @Deprecated - @InternalApi - public ASTForEachStatement(EnhancedForLoopStatement enhancedForLoopStatement) { + ASTForEachStatement(EnhancedForLoopStatement enhancedForLoopStatement) { super(enhancedForLoopStatement); } 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 b6e71c9aafe..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,15 +4,11 @@ package net.sourceforge.pmd.lang.apex.ast; -import net.sourceforge.pmd.annotation.InternalApi; - import com.google.summit.ast.statement.ForLoopStatement; public class ASTForLoopStatement extends AbstractApexNode.Single { - @Deprecated - @InternalApi - public ASTForLoopStatement(ForLoopStatement 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 ef70958fc67..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,11 @@ package net.sourceforge.pmd.lang.apex.ast; -import net.sourceforge.pmd.annotation.InternalApi; - import com.google.summit.ast.statement.IfStatement; public class ASTIfBlockStatement extends AbstractApexNode.Single { - @Deprecated - @InternalApi - public ASTIfBlockStatement(IfStatement ifStatement) { + ASTIfBlockStatement(IfStatement ifStatement) { super(ifStatement); } 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 d8c76ac5836..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,17 +4,13 @@ package net.sourceforge.pmd.lang.apex.ast; -import net.sourceforge.pmd.annotation.InternalApi; - import com.google.summit.ast.statement.IfStatement; public class ASTIfElseBlockStatement extends AbstractApexNode.Single { private final boolean hasElseStatement; - @Deprecated - @InternalApi - public ASTIfElseBlockStatement(IfStatement ifStatement, boolean hasElseStatement) { + ASTIfElseBlockStatement(IfStatement ifStatement, boolean hasElseStatement) { super(ifStatement); this.hasElseStatement = hasElseStatement; } 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 9b221957b01..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,15 +4,11 @@ package net.sourceforge.pmd.lang.apex.ast; -import net.sourceforge.pmd.annotation.InternalApi; - import com.google.summit.ast.statement.ReturnStatement; public class ASTReturnStatement extends AbstractApexNode.Single { - @Deprecated - @InternalApi - public ASTReturnStatement(ReturnStatement 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 836b15b8cd7..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,11 @@ package net.sourceforge.pmd.lang.apex.ast; -import net.sourceforge.pmd.annotation.InternalApi; - import com.google.summit.ast.statement.RunAsStatement; public class ASTRunAsBlockStatement extends AbstractApexNode.Single { - @Deprecated - @InternalApi - public ASTRunAsBlockStatement(RunAsStatement runAsStatement) { + ASTRunAsBlockStatement(RunAsStatement runAsStatement) { super(runAsStatement); } 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/ASTThrowStatement.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ASTThrowStatement.java index 8340a9132a8..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,15 +4,11 @@ package net.sourceforge.pmd.lang.apex.ast; -import net.sourceforge.pmd.annotation.InternalApi; - import com.google.summit.ast.statement.ThrowStatement; public class ASTThrowStatement extends AbstractApexNode.Single { - @Deprecated - @InternalApi - public ASTThrowStatement(ThrowStatement 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 f63cf748a54..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 @@ -8,13 +8,9 @@ import com.google.summit.ast.statement.TryStatement; -import net.sourceforge.pmd.annotation.InternalApi; - public class ASTTryCatchFinallyBlockStatement extends AbstractApexNode.Single { - @Deprecated - @InternalApi - public ASTTryCatchFinallyBlockStatement(TryStatement tryStatement) { + ASTTryCatchFinallyBlockStatement(TryStatement tryStatement) { super(tryStatement); } 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 32191a08b8b..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,15 +4,11 @@ package net.sourceforge.pmd.lang.apex.ast; -import net.sourceforge.pmd.annotation.InternalApi; - import com.google.summit.ast.statement.WhileLoopStatement; public class ASTWhileLoopStatement extends AbstractApexNode.Single { - @Deprecated - @InternalApi - public ASTWhileLoopStatement(WhileLoopStatement whileLoopStatement) { + ASTWhileLoopStatement(WhileLoopStatement whileLoopStatement) { super(whileLoopStatement); }