Skip to content

Commit

Permalink
Merge pull request #3312 from Rawi01/extensionmethod-nonstatic
Browse files Browse the repository at this point in the history
Ignore non-static/non-public extension methods
  • Loading branch information
rzwitserloot authored Jan 12, 2023
2 parents b69ff85 + 4feabb4 commit 8bb4dc5
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/core/lombok/javac/handlers/HandleExtensionMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ public Extension getExtension(final JavacNode typeNode, final ClassType extensio
if (tsym != null) for (Symbol member : tsym.getEnclosedElements()) {
if (member.getKind() != ElementKind.METHOD) continue;
MethodSymbol method = (MethodSymbol) member;
if ((method.flags() & (STATIC | PUBLIC)) == 0) continue;
if ((method.flags() & STATIC) == 0) continue;
if ((method.flags() & PUBLIC) == 0) continue;
if (method.params().isEmpty()) continue;
extensionMethods.add(method);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class ExtensionMethodNonStatic {
public void test() {
String s = "test";
s.startsWith("");
}

static class Extensions {
public boolean startsWith(String s, String prefix) {
return s.startsWith(prefix);
}
}
}
18 changes: 18 additions & 0 deletions test/transform/resource/after-ecj/ExtensionMethodNonStatic.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import lombok.experimental.ExtensionMethod;
@ExtensionMethod({ExtensionMethodNonStatic.Extensions.class}) class ExtensionMethodNonStatic {
static class Extensions {
Extensions() {
super();
}
public boolean startsWith(String s, String prefix) {
return s.startsWith(prefix);
}
}
ExtensionMethodNonStatic() {
super();
}
public void test() {
String s = "test";
s.startsWith("");
}
}
15 changes: 15 additions & 0 deletions test/transform/resource/before/ExtensionMethodNonStatic.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import lombok.experimental.ExtensionMethod;

@ExtensionMethod({ExtensionMethodNonStatic.Extensions.class})
class ExtensionMethodNonStatic {
public void test() {
String s = "test";
s.startsWith("");
}

static class Extensions {
public boolean startsWith(String s, String prefix) {
return s.startsWith(prefix);
}
}
}

0 comments on commit 8bb4dc5

Please sign in to comment.