[java] Fix compile errors

This commit is contained in:
Andreas Dangel
2020-04-04 18:54:49 +02:00
parent 78974f450d
commit ef1c50707b
5 changed files with 8 additions and 21 deletions

View File

@ -294,7 +294,7 @@ class JavaParserImpl {
private boolean inSwitchExprBlock = false;
private boolean isYieldStart() {
return inSwitchExprBlock && isJava13PreviewOr14()
return inSwitchExprBlock
&& isKeyword("yield")
&& mayStartExprAfterYield(2);
}

View File

@ -87,12 +87,6 @@ public class ASTCompilationUnit extends AbstractJavaTypeNode implements RootNode
return classTypeResolver;
}
@Override
public ASTCompilationUnit getRoot() {
return this;
}
@InternalApi
@Deprecated
public void setClassTypeResolver(ClassTypeResolver classTypeResolver) {

View File

@ -44,14 +44,6 @@ public abstract class AbstractJavaNode extends AbstractJjtreeNode<JavaNode> impl
}
@Override
public ASTCompilationUnit getRoot() {
if (root == null) {
root = getParent().getRoot();
}
return root;
}
@Override
public Scope getScope() {
if (scope == null) {

View File

@ -46,7 +46,6 @@ public interface JavaNode extends ScopedNode, TextAvailableNode {
@Deprecated
Object childrenAccept(JavaParserVisitor visitor, Object data);
ASTCompilationUnit getRoot();
/**
* Calls back the visitor's visit method corresponding to the runtime type of this Node.

View File

@ -8,6 +8,7 @@ package net.sourceforge.pmd.lang.java.ast;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertThat;
import java.util.ArrayList;
import java.util.List;
import org.junit.Assert;
@ -94,15 +95,16 @@ public class Java14Test {
private void checkYieldStatements(JavaParsingHelper parser) {
ASTCompilationUnit compilationUnit = parser.parseResource("YieldStatements.java");
List<JavaNode> stmts = compilationUnit.<JavaNode>findDescendantsOfType(ASTBlockStatement.class);
List<ASTBlockStatement> blockStmts = compilationUnit.findDescendantsOfType(ASTBlockStatement.class);
List<JavaNode> stmts = new ArrayList<>();
// fetch the interesting node, on the java-grammar branch this is not needed
for (int i = 0; i < stmts.size(); i++) {
JavaNode child = stmts.get(i).getChild(0);
for (int i = 0; i < blockStmts.size(); i++) {
JavaNode child = blockStmts.get(i).getChild(0);
if (child instanceof ASTStatement) {
stmts.set(i, child.getChild(0));
stmts.add(child.getChild(0));
} else {
stmts.set(i, child);
stmts.add(child);
}
}