forked from phoedos/pmd
[apex] ASTBlockStatement - verify curlyBrace
This commit is contained in:
@@ -7,7 +7,6 @@ package net.sourceforge.pmd.lang.apex.ast;
|
||||
import net.sourceforge.pmd.lang.document.TextDocument;
|
||||
|
||||
import com.google.summit.ast.Node;
|
||||
import com.google.summit.ast.SourceLocation;
|
||||
|
||||
public final class ASTBlockStatement extends AbstractApexNode.Single<Node> {
|
||||
private boolean curlyBrace;
|
||||
@@ -33,12 +32,9 @@ public final class ASTBlockStatement extends AbstractApexNode.Single<Node> {
|
||||
return;
|
||||
}
|
||||
|
||||
// check, whether the this block statement really begins with a curly brace
|
||||
// check, whether this block statement really begins with a curly brace
|
||||
// unfortunately, for-loop and if-statements always contain a block statement,
|
||||
// regardless whether curly braces where present or not.
|
||||
// TODO: Revisit this, because it is Jorje-specific.
|
||||
SourceLocation loc = node.getSourceLocation();
|
||||
String sourceRegion = loc.extractFrom(sourceCode.getText().toString());
|
||||
this.curlyBrace = sourceRegion.charAt(0) == '{';
|
||||
this.curlyBrace = sourceCode.getText().slice(getTextRegion()).charAt(0) == '{';
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.apex.ast;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class ASTBlockStatementTest extends ApexParserTestBase {
|
||||
@Test
|
||||
void noCurlyBraces() {
|
||||
ASTBlockStatement blockStatement = parse("class Foo { { if (true) methodCall(); } }")
|
||||
.descendants(ASTIfBlockStatement.class)
|
||||
.firstChild(ASTBlockStatement.class)
|
||||
.first();
|
||||
assertFalse(blockStatement.hasCurlyBrace());
|
||||
}
|
||||
|
||||
@Test
|
||||
void withCurlyBraces() {
|
||||
ASTBlockStatement blockStatement = parse("class Foo { { if (true) { methodCall(); } } }")
|
||||
.descendants(ASTIfBlockStatement.class)
|
||||
.firstChild(ASTBlockStatement.class)
|
||||
.first();
|
||||
assertTrue(blockStatement.hasCurlyBrace());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user