Fix bugs
This commit is contained in:
@ -2213,7 +2213,7 @@ void BlockStatement() #void:
|
||||
| LOOKAHEAD({ isAssertStart() }) AssertStatement()
|
||||
| LOOKAHEAD({ isYieldStart() }) YieldStatement()
|
||||
| LOOKAHEAD({ getToken(2).kind == COLON }) LabeledStatement()
|
||||
| LOOKAHEAD(ClassOrInterfaceType() <IDENTIFIER>) LocalVariableDeclaration() ";" { fixLastToken(); }
|
||||
| LOOKAHEAD(ReferenceType() <IDENTIFIER>) LocalVariableDeclaration() ";" { fixLastToken(); }
|
||||
| LOOKAHEAD({true}) ExpressionStatement()
|
||||
)
|
||||
| LOOKAHEAD(1, LocalTypeStartNoIdent()) ModifierList() LocalTypeDecl()
|
||||
|
@ -224,6 +224,16 @@ public interface ASTAnyTypeDeclaration
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this is a regular class declaration (not an enum,
|
||||
* not a record, not an interface or annotation). Note that eg
|
||||
* {@link JClassSymbol#isClass()} counts records and enums in, just
|
||||
* like {@link #isInterface()} counts annotations in.
|
||||
*/
|
||||
default boolean isRegularClass() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/** Returns true if this is an {@linkplain ASTAnnotationTypeDeclaration annotation type declaration}. */
|
||||
default boolean isAnnotation() {
|
||||
|
@ -49,6 +49,11 @@ public final class ASTClassOrInterfaceDeclaration extends AbstractAnyTypeDeclara
|
||||
return this.isInterface;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRegularClass() {
|
||||
return !isInterface;
|
||||
}
|
||||
|
||||
void setInterface() {
|
||||
this.isInterface = true;
|
||||
}
|
||||
|
@ -26,6 +26,8 @@ public final class ASTLocalClassStatement extends AbstractStatement {
|
||||
super(JavaParserImplTreeConstants.JJTLOCALCLASSSTATEMENT);
|
||||
assert tdecl != null;
|
||||
addChild((AbstractJavaNode) tdecl, 0);
|
||||
setFirstToken(tdecl.getFirstToken());
|
||||
setLastToken(tdecl.getLastToken());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -24,6 +24,7 @@ public final class ASTLocalVariableDeclaration extends AbstractJavaNode
|
||||
implements Iterable<ASTVariableDeclaratorId>,
|
||||
ASTStatement,
|
||||
FinalizableNode,
|
||||
LeftRecursiveNode, // ModifierList is parsed separately in BlockStatement
|
||||
InternalInterfaces.MultiVariableIdOwner {
|
||||
|
||||
ASTLocalVariableDeclaration(int id) {
|
||||
|
@ -124,6 +124,7 @@ public class LanguageLevelChecker<T> {
|
||||
RECORD_DECLARATIONS(14, 15, false),
|
||||
TYPE_TEST_PATTERNS_IN_INSTANCEOF(14, 15, false),
|
||||
SEALED_CLASSES(15, 15, false),
|
||||
STATIC_LOCAL_TYPE_DECLARATIONS(15, 15, false), // part of the sealed classes JEP
|
||||
|
||||
; // SUPPRESS CHECKSTYLE enum trailing semi is awesome
|
||||
|
||||
@ -478,8 +479,8 @@ public class LanguageLevelChecker<T> {
|
||||
public Void visit(ASTAnyTypeDeclaration node, T data) {
|
||||
if (node.getModifiers().hasAnyExplicitly(JModifier.SEALED, JModifier.NON_SEALED)) {
|
||||
check(node, PreviewFeature.SEALED_CLASSES, data);
|
||||
} else if (node.isLocal() && node.isInterface() || node.isEnum()) {
|
||||
check(node, PreviewFeature.SEALED_CLASSES, data);
|
||||
} else if (node.isLocal() && !node.isRegularClass()) {
|
||||
check(node, PreviewFeature.STATIC_LOCAL_TYPE_DECLARATIONS, data);
|
||||
}
|
||||
|
||||
String simpleName = node.getSimpleName();
|
||||
|
@ -24,7 +24,7 @@ public class JavaQualifiedNameTest {
|
||||
|
||||
|
||||
private <T extends Node> List<T> getNodes(Class<T> target, String code) {
|
||||
return JavaParsingHelper.WITH_PROCESSING.getNodes(target, code);
|
||||
return JavaParsingHelper.WITH_PROCESSING.withDefaultVersion("15-preview").getNodes(target, code);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user