From ef1c50707b0ff28cea7e0a27481dfb7bb96b74c7 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 4 Apr 2020 18:54:49 +0200 Subject: [PATCH] [java] Fix compile errors --- pmd-java/etc/grammar/Java.jjt | 2 +- .../pmd/lang/java/ast/ASTCompilationUnit.java | 6 ------ .../pmd/lang/java/ast/AbstractJavaNode.java | 8 -------- .../net/sourceforge/pmd/lang/java/ast/JavaNode.java | 1 - .../sourceforge/pmd/lang/java/ast/Java14Test.java | 12 +++++++----- 5 files changed, 8 insertions(+), 21 deletions(-) diff --git a/pmd-java/etc/grammar/Java.jjt b/pmd-java/etc/grammar/Java.jjt index 1efeadd25f..dec7ab1a69 100644 --- a/pmd-java/etc/grammar/Java.jjt +++ b/pmd-java/etc/grammar/Java.jjt @@ -294,7 +294,7 @@ class JavaParserImpl { private boolean inSwitchExprBlock = false; private boolean isYieldStart() { - return inSwitchExprBlock && isJava13PreviewOr14() + return inSwitchExprBlock && isKeyword("yield") && mayStartExprAfterYield(2); } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTCompilationUnit.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTCompilationUnit.java index 76d0084ae6..b463754c52 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTCompilationUnit.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTCompilationUnit.java @@ -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) { diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AbstractJavaNode.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AbstractJavaNode.java index 0cbd49c499..ec3b3cd2ff 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AbstractJavaNode.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AbstractJavaNode.java @@ -44,14 +44,6 @@ public abstract class AbstractJavaNode extends AbstractJjtreeNode impl } - @Override - public ASTCompilationUnit getRoot() { - if (root == null) { - root = getParent().getRoot(); - } - return root; - } - @Override public Scope getScope() { if (scope == null) { diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/JavaNode.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/JavaNode.java index 0fcf5d46a3..b65a1ec9f8 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/JavaNode.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/JavaNode.java @@ -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. diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/Java14Test.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/Java14Test.java index da41bac41e..c9c55642b5 100644 --- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/Java14Test.java +++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/Java14Test.java @@ -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 stmts = compilationUnit.findDescendantsOfType(ASTBlockStatement.class); + List blockStmts = compilationUnit.findDescendantsOfType(ASTBlockStatement.class); + List 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); } }