Fix compile errors

This commit is contained in:
Andreas Dangel
2021-07-22 19:31:45 +02:00
parent 7ee9aedca8
commit e4431d4d65
3 changed files with 19 additions and 9 deletions

View File

@ -302,6 +302,10 @@ class JavaParserImpl {
return isRecordTypeSupported();
}
private boolean isSealedClassSupported() {
return jdkVersion == 16 && preview || jdkVersion >= 17;
}
/**
* Keeps track during tree construction, whether we are currently building a switch label.
* A switch label must not contain a LambdaExpression.
@ -2446,16 +2450,11 @@ void SwitchLabel() :
void CaseLabelElement(ASTSwitchLabel label) #void:
{}
{
"default" {label.setDefault(); checkForDefaultCaseLabel();}
"default" {label.setDefault();}
|
LOOKAHEAD(Pattern()) Pattern() {checkForPatternMatchingInSwitch();}
LOOKAHEAD(Pattern()) Pattern()
|
ConditionalExpression() #Expression
{
if ("null".equals(((ASTExpression) jjtree.peekNode()).jjtGetFirstToken().getImage())) {
checkForNullCaseLabel();
}
}
ConditionalExpression()
}
void YieldStatement() :

View File

@ -29,7 +29,9 @@ import net.sourceforge.pmd.lang.java.ast.ASTLambdaExpression;
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTMethodReference;
import net.sourceforge.pmd.lang.java.ast.ASTModuleDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTNullLiteral;
import net.sourceforge.pmd.lang.java.ast.ASTNumericLiteral;
import net.sourceforge.pmd.lang.java.ast.ASTPattern;
import net.sourceforge.pmd.lang.java.ast.ASTReceiverParameter;
import net.sourceforge.pmd.lang.java.ast.ASTRecordDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTResource;
@ -542,6 +544,15 @@ public class LanguageLevelChecker<T> {
if (IteratorUtil.count(node.iterator()) > 1) {
check(node, RegularLanguageFeature.COMPOSITE_CASE_LABEL, data);
}
if (node.isDefault() && "case".equals(node.getFirstToken().getImage())) {
check(node, PreviewFeature.PATTERN_MATCHING_FOR_SWITCH, data);
}
if (node.getFirstChild() instanceof ASTPattern) {
check(node, PreviewFeature.PATTERN_MATCHING_FOR_SWITCH, data);
}
if (node.getFirstChild() instanceof ASTNullLiteral) {
check(node, PreviewFeature.PATTERN_MATCHING_FOR_SWITCH, data);
}
return null;
}

View File

@ -46,7 +46,7 @@ class ASTLiteralTest : ParserTestSpec({
}
}
parserTest("Text block literal", javaVersions = since(J15__PREVIEW)) {
parserTest("Text block literal", javaVersions = since(J15)) {
val delim = "\"\"\""