-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[apex] Improve AST for try-catch-finally statements
- Loading branch information
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...src/test/java/net/sourceforge/pmd/lang/apex/ast/ASTTryCatchFinallyBlockStatementTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html | ||
*/ | ||
|
||
package net.sourceforge.pmd.lang.apex.ast; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import apex.jorje.semantic.ast.compilation.Compilation; | ||
|
||
public class ASTTryCatchFinallyBlockStatementTest extends ApexParserTestBase { | ||
|
||
@Test | ||
public void testTryFinally() { | ||
ApexNode<Compilation> node = parse("class Foo { void bar() { try { methodCall(); } finally { methodCall(); } } }"); | ||
ASTTryCatchFinallyBlockStatement statement = node.getFirstDescendantOfType(ASTTryCatchFinallyBlockStatement.class); | ||
Assert.assertNotNull(statement.getTryBlock()); | ||
Assert.assertEquals(0, statement.getTryBlock().getIndexInParent()); | ||
Assert.assertNotNull(statement.getFinallyBlock()); | ||
Assert.assertEquals(1, statement.getFinallyBlock().getIndexInParent()); | ||
Assert.assertEquals(0, statement.getCatchClauses().size()); | ||
} | ||
|
||
@Test | ||
public void testTryCatch() { | ||
ApexNode<Compilation> node = parse("class Foo { void bar() { try { methodCall(); } catch (Exception e) { methodCall(); } } }"); | ||
ASTTryCatchFinallyBlockStatement statement = node.getFirstDescendantOfType(ASTTryCatchFinallyBlockStatement.class); | ||
Assert.assertNotNull(statement.getTryBlock()); | ||
Assert.assertEquals(0, statement.getTryBlock().getIndexInParent()); | ||
Assert.assertNull(statement.getFinallyBlock()); | ||
Assert.assertEquals(1, statement.getCatchClauses().size()); | ||
Assert.assertNotNull(statement.getCatchClauses().get(0).getBody()); | ||
Assert.assertEquals(1, statement.getCatchClauses().get(0).getIndexInParent()); | ||
} | ||
|
||
@Test | ||
public void testTryCatchFinally() { | ||
ApexNode<Compilation> node = parse("class Foo { void bar() { try { methodCall(); } catch (Exception e) { methodCall(); } finally { } } }"); | ||
ASTTryCatchFinallyBlockStatement statement = node.getFirstDescendantOfType(ASTTryCatchFinallyBlockStatement.class); | ||
Assert.assertNotNull(statement.getTryBlock()); | ||
Assert.assertEquals(0, statement.getTryBlock().getIndexInParent()); | ||
Assert.assertNotNull(statement.getFinallyBlock()); | ||
Assert.assertEquals(2, statement.getFinallyBlock().getIndexInParent()); | ||
Assert.assertEquals(1, statement.getCatchClauses().size()); | ||
Assert.assertNotNull(statement.getCatchClauses().get(0).getBody()); | ||
Assert.assertEquals(1, statement.getCatchClauses().get(0).getIndexInParent()); | ||
} | ||
} |