diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ComplianceDiagnoseTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ComplianceDiagnoseTest.java index 181e73a3dab..14130911bd6 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ComplianceDiagnoseTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ComplianceDiagnoseTest.java @@ -3234,6 +3234,9 @@ public void testBug399781() { }; String usLevel = this.complianceLevel < ClassFileConstants.JDK9 ? "WARNING" : "ERROR"; String errorMessage = this.complianceLevel < ClassFileConstants.JDK9 ? "\'_\' should not be used as an identifier, since it is a reserved keyword from source level 1.8 on\n" : "\'_\' is a keyword from source level 9 onwards, cannot be used as identifier\n"; + if (this.complianceLevel >= ClassFileConstants.JDK21) { + errorMessage = "Unnamed Patterns and Variables is a preview feature and disabled by default. Use --enable-preview to enable\n"; + } String expectedProblemLog = "----------\n" + "1. " + usLevel +" in X.java (at line 2)\n" + diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java index 16ccdcb9b8d..4c200b27c80 100644 --- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java +++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java @@ -4232,6 +4232,7 @@ && isIndirectlyInsideFieldInitialization()) { // enum initializers indeed need m case TokenNamesuper: // e.g. super[.]fred() this.invocationType = SUPER_RECEIVER; break; + case TokenNameUNDERSCORE: case TokenNameIdentifier: // e.g. bar[.]fred() if (topKnownElementKind(COMPLETION_OR_ASSIST_PARSER) != K_BETWEEN_NEW_AND_LEFT_BRACKET) { if (this.identifierPtr != prevIdentifierPtr) { // if identifier has been consumed, e.g. this.x[.]fred() @@ -4246,6 +4247,7 @@ && isIndirectlyInsideFieldInitialization()) { // enum initializers indeed need m case TokenNameCOLON_COLON: this.inReferenceExpression = true; break; + case TokenNameUNDERSCORE: case TokenNameIdentifier: if (this.inReferenceExpression) break; @@ -4317,6 +4319,7 @@ && isInsideSwitch() && checkYieldKeyword()) { this.qualifier = this.expressionPtr; // remenber the last expression so that arguments are correctly computed } switch (previous) { + case TokenNameUNDERSCORE: case TokenNameIdentifier: // e.g. fred[(]) or foo.fred[(]) if (topKnownElementKind(COMPLETION_OR_ASSIST_PARSER) == K_SELECTOR) { int info = 0; @@ -4436,6 +4439,7 @@ && isInsideSwitch() && checkYieldKeyword()) { pushOnElementStack(K_BETWEEN_LEFT_AND_RIGHT_BRACKET); } else { switch (previous) { + case TokenNameUNDERSCORE: case TokenNameIdentifier: case TokenNameboolean: case TokenNamebyte: