Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NON-NLS tag ignored for specific method references targeting a string literal #3044

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private ReferenceExpression copy() {
char [] source = new char [this.sourceEnd+1];
System.arraycopy(this.text, 0, source, this.sourceStart, this.sourceEnd - this.sourceStart + 1);
parser.scanner = this.scanner;
ReferenceExpression copy = (ReferenceExpression) parser.parseExpression(source, this.sourceStart, this.sourceEnd - this.sourceStart + 1,
ReferenceExpression copy = (ReferenceExpression) parser.parseReferenceExpression(source, this.sourceStart, this.sourceEnd - this.sourceStart + 1,
this.enclosingScope.referenceCompilationUnit(), false /* record line separators */);
copy.original = this;
copy.sourceStart = this.sourceStart;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ protected int actFromTokenOrSynthetic(int previousAct) {
private boolean tolerateDefaultClassMethods = false;
private boolean processingLambdaParameterList = false;
private boolean expectTypeAnnotation = false;
private boolean reparsingLambdaExpression = false;
private boolean reparsingFunctionalExpression = false;

private Map<TypeDeclaration, Integer[]> recordNestedMethodLevels;
private Map<Integer, Boolean> recordPatternSwitches;
Expand Down Expand Up @@ -9406,7 +9406,7 @@ private void consumeTextBlock() {
private TextBlock createTextBlock(char[] allchars, int start, int end) {
TextBlock textBlock;
if (this.recordStringLiterals &&
!this.reparsingLambdaExpression &&
!this.reparsingFunctionalExpression &&
this.checkExternalizeStrings &&
this.lastPosistion < this.scanner.currentPosition &&
!this.statementRecoveryActivated) {
Expand Down Expand Up @@ -9873,7 +9873,7 @@ protected void consumeToken(int type) {
case TokenNameStringLiteral :
StringLiteral stringLiteral;
if (this.recordStringLiterals &&
!this.reparsingLambdaExpression &&
!this.reparsingFunctionalExpression &&
this.checkExternalizeStrings &&
this.lastPosistion < this.scanner.currentPosition &&
!this.statementRecoveryActivated) {
Expand Down Expand Up @@ -13133,7 +13133,7 @@ public boolean visit(TypeDeclaration memberTypeDeclaration, ClassScope scope) {

public Expression parseLambdaExpression(char[] source, int offset, int length, CompilationUnitDeclaration unit, boolean recordLineSeparators) {
this.haltOnSyntaxError = true; // unexposed/unshared object, no threading concerns.
this.reparsingLambdaExpression = true;
this.reparsingFunctionalExpression = true;
return parseExpression(source, offset, length, unit, recordLineSeparators);
}

Expand All @@ -13160,6 +13160,10 @@ public char[][] parsePackageDeclaration(char[] source, CompilationResult result)
return this.compilationUnit.currentPackage == null ? null : this.compilationUnit.currentPackage.getImportName();

}
public Expression parseReferenceExpression(char[] source, int offset, int length, CompilationUnitDeclaration unit, boolean recordLineSeparators) {
this.reparsingFunctionalExpression = true;
return parseExpression(source, offset, length, unit, recordLineSeparators);
}
public Expression parseExpression(char[] source, int offset, int length, CompilationUnitDeclaration unit, boolean recordLineSeparators) {

initialize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,39 @@ public void test007() {
true,
customOptions);
}
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/3025
// NON-NLS tag ignored for specific method references targeting a string literal
public void testIssue3025() {
Map customOptions = getCompilerOptions();
customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.ERROR);
this.runNegativeTest(
new String[] {
"X.java",
"""
import java.util.List;
import java.util.function.Predicate;

public class X {
public static void main(String[] args) {
List<String> list = List.<String>of();
list.removeIf("."::equals); //$NON-NLS-1$
list.removeIf(e -> "..".equals(e)); //$NON-NLS-1$
list.removeIf((Predicate<String>) "..."::equals); //$NON-NLS-1$
System.out.println("....");
}
}
""",
},
"----------\n" +
"1. ERROR in X.java (at line 10)\n" +
" System.out.println(\"....\");\n" +
" ^^^^^^\n" +
"Non-externalized string literal; it should be followed by //$NON-NLS-<n>$\n" +
"----------\n",
null,
true,
customOptions);
}
public static Class testClass() {
return ExternalizeStringLiteralsTest_1_5.class;
}
Expand Down
Loading