[fixes #2752] Save problem handler state for postponed error handling

This commit is contained in:
Rawi01 committed 2021-02-17 09:41:08 +01:00
1 parent ed4ced1a3b
commit 0106746e60
5 files changed
+48

No files matched your search

@@ -55,6 +55,7 @@ import org.eclipse.jdt.internal.compiler.ast.SingleNameReference;
import org.eclipse.jdt.internal.compiler.ast.SuperReference;
import org.eclipse.jdt.internal.compiler.ast.ThisReference;
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
import org.eclipse.jdt.internal.compiler.impl.ReferenceContext;
import org.eclipse.jdt.internal.compiler.lookup.Binding;
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
@@ -143,14 +144,17 @@ public class PatchExtensionMethod {
private final ProblemReporter problemReporter;
private ASTNode location;
private MethodBinding method;
private ReferenceContext referenceContext;
PostponedNonStaticAccessToStaticMethodError(ProblemReporter problemReporter, ASTNode location, MethodBinding method) {
this.problemReporter = problemReporter;
this.location = location;
this.method = method;
this.referenceContext = problemReporter.referenceContext;
}
public void fire() {
problemReporter.referenceContext = this.referenceContext;
problemReporter.nonStaticAccessToStaticMethod(location, method);
}
}
+2
View File
@@ -83,6 +83,8 @@ public class RunTestsViaEcj extends AbstractRunTests {
warnings.put(CompilerOptions.OPTION_ReportUnusedLabel, "ignore");
warnings.put(CompilerOptions.OPTION_ReportUnusedImport, "ignore");
warnings.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, "ignore");
warnings.put(CompilerOptions.OPTION_ReportIndirectStaticAccess, "warning");
warnings.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, "warning");
int ecjVersion = Eclipse.getEcjCompilerVersion();
warnings.put(CompilerOptions.OPTION_Source, (ecjVersion < 9 ? "1." : "") + ecjVersion);
options.set(warnings);
@@ -0,0 +1,22 @@
class ExtensionMethodNonStaticAccess {
ExtensionMethodNonStaticAccess() {
super();
}
public void method() {
Derived derived = new Derived();
derived.staticMethod();
}
}
class Base {
Base() {
super();
}
static String staticMethod() {
return "";
}
}
class Derived extends Base {
Derived() {
super();
}
}
@@ -0,0 +1,18 @@
//issue #2752: this test triggers an indirect static access and a non static access warning for the same method call
//platform ecj,eclipse
class ExtensionMethodNonStaticAccess {
public void method(){
Derived derived = new Derived();
derived.staticMethod();
}
}
class Base {
static String staticMethod() {
return "";
}
}
class Derived extends Base {
}
@@ -0,0 +1,2 @@
6 The static method staticMethod() from the type Base should be accessed directly
6 The static method staticMethod() from the type Base should be accessed in a static way