aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2021-03-04 22:15:03 +0100
committerGitHub <noreply@github.com>2021-03-04 22:15:03 +0100
commite959e8882c11349fb87cea3a134de263249d7b21 (patch)
tree1d7789d3197d5afcfae6a4c4152384668232917f
parentbb36d95226f9432120bb12db8e22363107969c56 (diff)
parent0106746e60263d8cc3fbd189cca7b2e09c3d5c06 (diff)
downloadlombok-e959e8882c11349fb87cea3a134de263249d7b21.tar.gz
lombok-e959e8882c11349fb87cea3a134de263249d7b21.tar.bz2
lombok-e959e8882c11349fb87cea3a134de263249d7b21.zip
Merge pull request #2754 from Rawi01/npe-nonStaticAccess
Save problem handler state for postponed error handling
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java4
-rw-r--r--test/core/src/lombok/RunTestsViaEcj.java2
-rw-r--r--test/transform/resource/after-ecj/ExtensionMethodNonStaticAccess.java22
-rw-r--r--test/transform/resource/before/ExtensionMethodNonStaticAccess.java18
-rw-r--r--test/transform/resource/messages-ecj/ExtensionMethodNonStaticAccess.java.messages2
5 files changed, 48 insertions, 0 deletions
diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java b/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java
index 1f2f67ec..2e540b5e 100644
--- a/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java
+++ b/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java
@@ -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);
}
}
diff --git a/test/core/src/lombok/RunTestsViaEcj.java b/test/core/src/lombok/RunTestsViaEcj.java
index 1d840a21..454a8aef 100644
--- a/test/core/src/lombok/RunTestsViaEcj.java
+++ b/test/core/src/lombok/RunTestsViaEcj.java
@@ -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);
diff --git a/test/transform/resource/after-ecj/ExtensionMethodNonStaticAccess.java b/test/transform/resource/after-ecj/ExtensionMethodNonStaticAccess.java
new file mode 100644
index 00000000..c930a329
--- /dev/null
+++ b/test/transform/resource/after-ecj/ExtensionMethodNonStaticAccess.java
@@ -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();
+ }
+}
diff --git a/test/transform/resource/before/ExtensionMethodNonStaticAccess.java b/test/transform/resource/before/ExtensionMethodNonStaticAccess.java
new file mode 100644
index 00000000..0d317c35
--- /dev/null
+++ b/test/transform/resource/before/ExtensionMethodNonStaticAccess.java
@@ -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 {
+
+} \ No newline at end of file
diff --git a/test/transform/resource/messages-ecj/ExtensionMethodNonStaticAccess.java.messages b/test/transform/resource/messages-ecj/ExtensionMethodNonStaticAccess.java.messages
new file mode 100644
index 00000000..3f5f3988
--- /dev/null
+++ b/test/transform/resource/messages-ecj/ExtensionMethodNonStaticAccess.java.messages
@@ -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 \ No newline at end of file