Skip to content

Commit

Permalink
[apex] Update summit-ast and apex-parser
Browse files Browse the repository at this point in the history
Fixes pmd#4922
  • Loading branch information
adangel committed Apr 26, 2024
1 parent 11b8fa2 commit ed2ac0e
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 8 deletions.
2 changes: 2 additions & 0 deletions docs/pages/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ This is a {{ site.pmd.release_type }} release.
### 🚀 New and noteworthy

### 🐛 Fixed Issues
* apex
* [#4922](https://github.com/pmd/pmd/issues/4922): \[apex] TYPEOF in sub-query throws error

### 🚨 API Changes

Expand Down
2 changes: 1 addition & 1 deletion pmd-apex/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
<dependency>
<groupId>com.google.summit</groupId>
<artifactId>summit-ast</artifactId>
<version>2.2.0</version>
<version>2.2.1-SNAPSHOT</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import net.sourceforge.pmd.lang.document.TextDocument;
import net.sourceforge.pmd.lang.document.TextRegion;

import com.nawforce.apexparser.ApexLexer;
import io.github.apexdevtools.apexparser.ApexLexer;

@InternalApi
final class ApexCommentBuilder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ class ApexTreeBuilder(private val task: ParserTask, private val proc: ApexLangua
// 2. Add the expected ASTModifier child node
buildModifiers(emptyList()).also { it.setParent(invokeMethod) }
// 3. Elide the body CompoundStatement->ASTBlockStatement
buildChildren(node.body, parent = invokeMethod as AbstractApexNode)
node.body.forEach { buildChildren(it, parent = invokeMethod as AbstractApexNode) }
} else {
buildChildren(node, parent = this, exclude = { it in node.modifiers })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import net.sourceforge.pmd.cpd.TokenFactory;
import net.sourceforge.pmd.lang.document.TextDocument;

import com.nawforce.apexparser.ApexLexer;
import io.github.apexdevtools.apexparser.ApexLexer;

public class ApexCpdLexer implements CpdLexer {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
import org.antlr.v4.runtime.Token;
import org.junit.jupiter.api.Test;

import com.nawforce.apexparser.ApexLexer;
import com.nawforce.apexparser.ApexParser;

import io.github.apexdevtools.apexparser.ApexLexer;
import io.github.apexdevtools.apexparser.ApexParser;

/**
* This is an exploration test for {@link ApexLexer}.
Expand Down Expand Up @@ -46,7 +45,7 @@ void testLexer() {
void testParser() {
CharStream in = CharStreams.fromString(CODE);
ApexLexer lexer = new ApexLexer(in);
ApexParser parser = new com.nawforce.apexparser.ApexParser(new CommonTokenStream(lexer));
ApexParser parser = new ApexParser(new CommonTokenStream(lexer));
ApexParser.CompilationUnitContext compilationUnit = parser.compilationUnit();
assertNotNull(compilationUnit);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,12 @@ void innerClassLocations() {
void nullCoalescingOperator() {
doTest("NullCoalescingOperator");
}

/**
* @see <a href="https://github.com/pmd/pmd/issues/4922">[apex] TYPEOF in sub-query throws error #4922</a>
*/
@Test
void typeOfSubQuery() {
doTest("TypeofTest");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
public class TypeofTest {
static void test() {
Case c = [
SELECT
Id,
Subject,
Description,
TYPEOF Owner
WHEN Group THEN Name
WHEN User THEN Name
END,
(
SELECT
Id,
Subject,
Description,
TYPEOF Owner
WHEN Group THEN Name
WHEN User THEN Name
END
FROM Cases
)
FROM Case
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
+- ApexFile[@DefiningType = "TypeofTest", @RealLoc = true]
+- UserClass[@DefiningType = "TypeofTest", @Image = "TypeofTest", @RealLoc = true, @SimpleName = "TypeofTest", @SuperClassName = ""]
+- ModifierNode[@Abstract = false, @DefiningType = "TypeofTest", @DeprecatedTestMethod = false, @Final = false, @Global = false, @InheritedSharing = false, @Modifiers = 1, @Override = false, @Private = false, @Protected = false, @Public = true, @RealLoc = true, @Static = false, @Test = false, @TestOrTestSetup = false, @Transient = false, @Virtual = false, @WebService = false, @WithSharing = false, @WithoutSharing = false]
+- Method[@Arity = 0, @CanonicalName = "test", @Constructor = false, @DefiningType = "TypeofTest", @Image = "test", @RealLoc = true, @ReturnType = "void", @StaticInitializer = false]
+- ModifierNode[@Abstract = false, @DefiningType = "TypeofTest", @DeprecatedTestMethod = false, @Final = false, @Global = false, @InheritedSharing = false, @Modifiers = 8, @Override = false, @Private = false, @Protected = false, @Public = false, @RealLoc = true, @Static = true, @Test = false, @TestOrTestSetup = false, @Transient = false, @Virtual = false, @WebService = false, @WithSharing = false, @WithoutSharing = false]
+- BlockStatement[@CurlyBrace = true, @DefiningType = "TypeofTest", @RealLoc = true]
+- VariableDeclarationStatements[@DefiningType = "TypeofTest", @RealLoc = true]
+- ModifierNode[@Abstract = false, @DefiningType = "TypeofTest", @DeprecatedTestMethod = false, @Final = false, @Global = false, @InheritedSharing = false, @Modifiers = 0, @Override = false, @Private = false, @Protected = false, @Public = false, @RealLoc = false, @Static = false, @Test = false, @TestOrTestSetup = false, @Transient = false, @Virtual = false, @WebService = false, @WithSharing = false, @WithoutSharing = false]
+- VariableDeclaration[@DefiningType = "TypeofTest", @Image = "c", @RealLoc = true, @Type = "Case"]
+- SoqlExpression[@CanonicalQuery = "SELECT\n\t\t\t\tId,\n\t\t\t\tSubject,\n\t\t\t\tDescription,\n\t\t\t\tTYPEOF Owner\n\t\t\t\t\tWHEN Group THEN Name\n\t\t\t\t\tWHEN User THEN Name\n\t\t\t\tEND,\n\t\t\t\t(\n\t\t\t\t\tSELECT\n\t\t\t\t\t\tId,\n\t\t\t\t\t\tSubject,\n\t\t\t\t\t\tDescription,\n\t\t\t\t\t\tTYPEOF Owner\n\t\t\t\t\t\t\tWHEN Group THEN Name\n\t\t\t\t\t\t\tWHEN User THEN Name\n\t\t\t\t\t\tEND\n\t\t\t\t\tFROM Cases\n\t\t\t\t)\n\t\t\tFROM Case", @DefiningType = "TypeofTest", @Query = "SELECT\n\t\t\t\tId,\n\t\t\t\tSubject,\n\t\t\t\tDescription,\n\t\t\t\tTYPEOF Owner\n\t\t\t\t\tWHEN Group THEN Name\n\t\t\t\t\tWHEN User THEN Name\n\t\t\t\tEND,\n\t\t\t\t(\n\t\t\t\t\tSELECT\n\t\t\t\t\t\tId,\n\t\t\t\t\t\tSubject,\n\t\t\t\t\t\tDescription,\n\t\t\t\t\t\tTYPEOF Owner\n\t\t\t\t\t\t\tWHEN Group THEN Name\n\t\t\t\t\t\t\tWHEN User THEN Name\n\t\t\t\t\t\tEND\n\t\t\t\t\tFROM Cases\n\t\t\t\t)\n\t\t\tFROM Case", @RealLoc = true]
+- VariableExpression[@DefiningType = "TypeofTest", @Image = "c", @RealLoc = true]
+- EmptyReferenceExpression[@DefiningType = null, @RealLoc = false]

0 comments on commit ed2ac0e

Please sign in to comment.