This repository has been archived by the owner on Nov 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 634
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a43ab9
commit 35ff127
Showing
12 changed files
with
353 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import lombok.*; | ||
|
||
@ToString | ||
@EqualsAndHashCode | ||
@AllArgsConstructor | ||
public final class LombokBasics { | ||
@Getter @Setter | ||
// should not be marked as unused | ||
private int age = <warning descr="Variable 'age' initializer '10' is redundant">10</warning>; | ||
|
||
void test(LombokBasics other) { | ||
setAge(20); // setter should be resolved | ||
System.out.println(getAge()); // getter should be resolved | ||
System.out.println(this.toString()); // toString is defined | ||
if (this <warning descr="Object values are compared using '==', not 'equals()'">==</warning> other) {} // equals is implicitly defined | ||
} | ||
|
||
public static void main(String[] args) { | ||
new LombokBasics(10).test(new LombokBasics(12)); | ||
} | ||
} | ||
@AllArgsConstructor | ||
class FinalCheck { | ||
@Getter | ||
private int <warning descr="Field 'a' may be 'final'">a</warning>; | ||
@Setter | ||
private int <warning descr="Private field 'b' is assigned but never accessed">b</warning>; | ||
@Getter @Setter | ||
private int c; | ||
} | ||
final class Foo { | ||
@Getter | ||
String bar; | ||
|
||
public void <warning descr="Method 'test()' is never used">test</warning>() { | ||
bar = null; | ||
System.out.println(getBar().trim()); | ||
} | ||
} | ||
class <warning descr="Class 'Outer' is never used">Outer</warning> { | ||
void <warning descr="Method 'foo()' is never used">foo</warning>() { | ||
@EqualsAndHashCode | ||
class <warning descr="Local class 'Inner' is never used">Inner</warning> { | ||
int x; | ||
} | ||
} | ||
} | ||
class IntellijInspectionNPEDemo { | ||
|
||
@Builder | ||
public static class SomeDataClass { | ||
public static class <warning descr="Class 'SomeDataClassBuilder' is never used">SomeDataClassBuilder</warning> { | ||
private void <warning descr="Private method 'buildWithJSON()' is never used">buildWithJSON</warning>() { | ||
this.jsonObject = "test"; | ||
} | ||
} | ||
|
||
public final String jsonObject; | ||
} | ||
|
||
} | ||
class <warning descr="Class 'InitializerInVar' is never used">InitializerInVar</warning> { | ||
public void <warning descr="Method 'foo()' is never used">foo</warning>() { | ||
var x = 1; // expect no "not used initializer" warning | ||
try { x = 3; } catch (NullPointerException e) { x = 1; } | ||
System.out.println(x); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
import lombok.experimental.ExtensionMethod; | ||
@ExtensionMethod({java.util.Arrays.class}) | ||
class ArrayExample { | ||
void m(int[] array) { | ||
array.sort(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
import lombok.experimental.ExtensionMethod; | ||
import java.util.List; | ||
@ExtensionMethod({Ex.class}) | ||
class Assignability { | ||
void m1(List<String> l) { | ||
l.print(); | ||
} | ||
|
||
void m2(List<? extends String> l) { | ||
l.print(); | ||
} | ||
|
||
void m3(List<? super String> l) { | ||
l.<error descr="Cannot resolve method 'print' in 'List'">print</error>(); | ||
} | ||
|
||
void m4(List<Object> l) { | ||
l.<error descr="Cannot resolve method 'print' in 'List'">print</error>(); | ||
} | ||
|
||
void m5(List l) { | ||
l.print(); | ||
} | ||
|
||
<T> void m6(List<T> l) { | ||
l.<error descr="Cannot resolve method 'print' in 'List'">print</error>(); | ||
} | ||
|
||
} | ||
|
||
class Ex { | ||
public static void print(List<? extends String> list) { | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
testData/highlighting/extensionMethods/ConflictingOwnMethod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
import lombok.experimental.ExtensionMethod; | ||
@ExtensionMethod({Ex.class}) | ||
class ConflictingOwnMethod { | ||
void m(Foo f) { | ||
f.or(f); | ||
} | ||
} | ||
|
||
class Foo { | ||
public void or(Foo foo) {} | ||
} | ||
|
||
class Ex { | ||
public static <T> T or(T t1, T t2) { | ||
return t1; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
testData/highlighting/extensionMethods/ExtensionMethodAutoboxing.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import lombok.experimental.ExtensionMethod; | ||
|
||
@ExtensionMethod({ExtensionMethodAutoboxing.Extensions.class}) | ||
class ExtensionMethodAutoboxing { | ||
public void test() { | ||
Long l1 = 1l; | ||
long l2 = 1l; | ||
Integer i1 = 1; | ||
int i2 = 1; | ||
|
||
String string = "test"; | ||
string.boxing(l1, i1); | ||
string.boxing(l1, i2); | ||
string.boxing(l2, i1); | ||
string.boxing(l2, i2); | ||
} | ||
|
||
static class Extensions { | ||
public static String boxing(String string, Long a, int b) { | ||
return string + " " + a + " " + b; | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
testData/highlighting/extensionMethods/ExtensionMethodFunctional.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// version 8: | ||
import java.util.function.Function; | ||
import java.util.function.Consumer; | ||
|
||
import lombok.experimental.ExtensionMethod; | ||
|
||
@ExtensionMethod(ExtensionMethodFunctional.Extensions.class) | ||
class ExtensionMethodFunctional { | ||
public void test() { | ||
String test = "test"; | ||
test = test.map(s -> s.reverse()); | ||
|
||
test.consume(s -> System.out.println("1: " + s), s -> System.out.println("2: " + s)); | ||
test.consume(System.out::println, System.out::println); | ||
} | ||
|
||
static class Extensions { | ||
public static <T, R> R map(T value, Function<T, R> mapper) { | ||
return mapper.apply(value); | ||
} | ||
|
||
public static String reverse(String string) { | ||
return new StringBuilder(string).reverse().toString(); | ||
} | ||
|
||
@SafeVarargs | ||
public static <T> void consume(T o, Consumer<T>... consumer) { | ||
for (int i = 0; i < consumer.length; i++) { | ||
consumer[i].accept(o); | ||
} | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
testData/highlighting/extensionMethods/ExtensionMethodNames.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package a; | ||
|
||
import lombok.experimental.ExtensionMethod; | ||
|
||
@ExtensionMethod(Extensions.class) | ||
class ExtensionMethodNames { | ||
|
||
public void instanceCalls() { | ||
(new Test()).ext(); | ||
|
||
Test t = new Test(); | ||
t.ext(); | ||
|
||
Test Test = new Test(); | ||
Test.ext(); | ||
} | ||
|
||
public void staticCalls() { | ||
Test.ext(); | ||
a.Test.ext(); | ||
} | ||
} | ||
|
||
class Extensions { | ||
public static void ext(Test t) { | ||
} | ||
} | ||
|
||
class Test { | ||
public static void ext() { | ||
|
||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
testData/highlighting/extensionMethods/ExtensionMethodPlain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import lombok.experimental.ExtensionMethod; | ||
|
||
@ExtensionMethod({java.util.Arrays.class, ExtensionMethodPlain.Extensions.class}) | ||
class ExtensionMethodPlain { | ||
public String test() { | ||
int[] intArray = {5, 3, 8, 2}; | ||
intArray.sort(); | ||
|
||
String iAmNull = null; | ||
return iAmNull.or("hELlO, WORlD!".toTitleCase()); | ||
} | ||
|
||
static class Extensions { | ||
public static <T> T or(T obj, T ifNull) { | ||
return obj != null ? obj : ifNull; | ||
} | ||
|
||
public static String toTitleCase(String in) { | ||
if (in.isEmpty()) return in; | ||
return "" + Character.toTitleCase(in.charAt(0)) + in.substring(1).toLowerCase(); | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
testData/highlighting/extensionMethods/ExtensionMethodSuppress.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import lombok.experimental.ExtensionMethod; | ||
|
||
@ExtensionMethod(Extensions.class) | ||
class ExtensionMethodSuppress { | ||
public void test() { | ||
Test.staticMethod(); | ||
|
||
Test test = new Test(); | ||
test.instanceMethod(); | ||
test.staticMethod(); | ||
} | ||
} | ||
|
||
@ExtensionMethod(value = Extensions.class, suppressBaseMethods = false) | ||
class ExtensionMethodKeep { | ||
public void test() { | ||
Test.staticMethod(); | ||
|
||
Test test = new Test(); | ||
test.instanceMethod(); | ||
test.staticMethod(); | ||
} | ||
} | ||
|
||
class Test { | ||
public static void staticMethod() { | ||
|
||
} | ||
|
||
public void instanceMethod() { | ||
|
||
} | ||
} | ||
|
||
class Extensions { | ||
public static void staticMethod(Test test) { | ||
|
||
} | ||
|
||
public static void instanceMethod(Test test) { | ||
|
||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
testData/highlighting/extensionMethods/ExtensionMethodVarargs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// version 8: | ||
import lombok.experimental.ExtensionMethod; | ||
|
||
@ExtensionMethod(ExtensionMethodVarargs.Extensions.class) | ||
class ExtensionMethodVarargs { | ||
public void test() { | ||
Long l1 = 1l; | ||
long l2 = 1l; | ||
Integer i1 = 1; | ||
int i2 = 1; | ||
|
||
"%d %d %d %d".format(l1, l2, i1, i2); | ||
"%d".format(l1); | ||
"".format(new Integer[]{1,2}); | ||
"".format(new Integer[]{1,2}, new Integer[]{1,2}); | ||
} | ||
|
||
static class Extensions { | ||
public static String format(String string, Object... params) { | ||
return String.format(string, params); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
testData/highlighting/extensionMethods/NestedExtensions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
import lombok.experimental.ExtensionMethod; | ||
@ExtensionMethod({Ex.class}) | ||
class NestedExtensions { | ||
void m(String s) { | ||
s.or(s.or(s.or(s.or("finally")))); | ||
} | ||
} | ||
|
||
class NoExtensions { | ||
void m(String s) { | ||
s.<error descr="Cannot resolve method 'or' in 'String'">or</error>("finally"); | ||
} | ||
} | ||
|
||
class Ex { | ||
public static <T> T or(T t1, T t2) { | ||
return t1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import lombok.experimental.ExtensionMethod; | ||
|
||
@ExtensionMethod({Extensions.class, java.util.Arrays.class}) | ||
public class ExtensionMethodDfa { | ||
public String test() { | ||
String iAmNull = null; | ||
return iAmNull.or("hELlO, WORlD!".toTitleCase()); | ||
} | ||
|
||
public void testArrays() { | ||
String[] arr = null; | ||
String str = null; | ||
<warning descr="Passing 'null' argument to parameter annotated as @NotNull">arr</warning>.fill(str); | ||
} | ||
} | ||
class Extensions { | ||
public static <T> T or(T obj, T ifNull) { | ||
return obj != null ? obj : ifNull; | ||
} | ||
|
||
public static String toTitleCase(String in) { | ||
if (in.isEmpty()) return in; | ||
return "" + Character.toTitleCase(in.charAt(0)) + | ||
in.substring(1).toLowerCase(); | ||
} | ||
} |