mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-13 20:15:09 +00:00
Merge pull request #3312 from Rawi01/extensionmethod-nonstatic
Ignore non-static/non-public extension methods
This commit is contained in:
4 files changed
+47
-1
No files matched your search
@@ -117,7 +117,8 @@ public class HandleExtensionMethod extends JavacAnnotationHandler<ExtensionMetho
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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("");
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user