Skip to content

Commit b3f9685

Browse files
Simplify code dealing with '_' named variables (eclipse-jdt#4207)
1 parent 0ada239 commit b3f9685

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ private VariableBinding resolveTypeFor(VariableBinding variable) {
957957
return null;
958958
}
959959
if (componentDeclaration.isUnnamed(this.scope)) {
960-
this.scope.problemReporter().illegalUseOfUnderscoreAsAnIdentifier(componentDeclaration.sourceStart, componentDeclaration.sourceEnd, this.scope.compilerOptions().sourceLevel > ClassFileConstants.JDK1_8, true);
960+
this.scope.problemReporter().illegalUseOfUnderscoreAsAnIdentifier(componentDeclaration.sourceStart, componentDeclaration.sourceEnd, true, true);
961961
componentDeclaration.setBinding(null);
962962
return null;
963963
}

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/Parser.java

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8258,13 +8258,8 @@ protected void consumeLambdaHeader() {
82588258
if (argument.isReceiver()) {
82598259
problemReporter().illegalThis(argument);
82608260
}
8261-
if (this.parsingJava8Plus && !JavaFeature.UNNAMMED_PATTERNS_AND_VARS.isSupported(this.options) && argument.name.length == 1 && argument.name[0] == '_') {
8262-
if (this.parsingJava22Plus) {
8263-
problemReporter().validateJavaFeatureSupport(JavaFeature.UNNAMMED_PATTERNS_AND_VARS, argument.sourceStart, argument.sourceEnd);
8264-
} else {
8265-
problemReporter().illegalUseOfUnderscoreAsAnIdentifier(argument.sourceStart, argument.sourceEnd, true, false); // true == lambdaParameter
8266-
}
8267-
}
8261+
if (this.parsingJava8Plus && !JavaFeature.UNNAMMED_PATTERNS_AND_VARS.isSupported(this.options) && argument.name.length == 1 && argument.name[0] == '_')
8262+
problemReporter().illegalUseOfUnderscoreAsAnIdentifier(argument.sourceStart, argument.sourceEnd, true, false); // true == lambdaParameter
82688263
}
82698264
LambdaExpression lexp = (LambdaExpression) this.astStack[this.astPtr];
82708265
lexp.setArguments(arguments);
@@ -12451,13 +12446,8 @@ protected void pushIdentifier(char [] identifier, long position) {
1245112446
stackLength);
1245212447
}
1245312448
this.identifierLengthStack[this.identifierLengthPtr] = 1;
12454-
if (this.parsingJava8Plus && !JavaFeature.UNNAMMED_PATTERNS_AND_VARS.isSupported(this.options) && identifier.length == 1 && identifier[0] == '_' && !this.processingLambdaParameterList) {
12455-
if (this.parsingJava22Plus) {
12456-
problemReporter().validateJavaFeatureSupport(JavaFeature.UNNAMMED_PATTERNS_AND_VARS, (int) (position >>> 32), (int) position);
12457-
} else {
12458-
problemReporter().illegalUseOfUnderscoreAsAnIdentifier((int) (position >>> 32), (int) position, this.parsingJava9Plus, false);
12459-
}
12460-
}
12449+
if (this.parsingJava8Plus && !JavaFeature.UNNAMMED_PATTERNS_AND_VARS.isSupported(this.options) && identifier.length == 1 && identifier[0] == '_' && !this.processingLambdaParameterList)
12450+
problemReporter().illegalUseOfUnderscoreAsAnIdentifier((int) (position >>> 32), (int) position, this.parsingJava9Plus, false);
1246112451
}
1246212452
protected void pushIdentifier() {
1246312453
/*push the consumeToken on the identifier stack.

0 commit comments

Comments
 (0)