Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial support Lombok for java 8 (mostly done) #4855

Merged
merged 29 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
761c2ea
Support Lombok for java 8
jevanlingen Jan 7, 2025
7cb644f
Support Lombok for java 8
jevanlingen Jan 7, 2025
69984ba
Support Lombok for java 8
jevanlingen Jan 7, 2025
12986eb
Add rewrite-java-lombok to classpath
jevanlingen Jan 7, 2025
e284bf5
Improve message
jevanlingen Jan 7, 2025
80e9ead
Remove `TimedTodo` to be more like the other java parsers
jevanlingen Jan 7, 2025
7a9fb18
cleanup
jevanlingen Jan 7, 2025
1531ca4
Add JavaCompiler `delegate` fix
jevanlingen Jan 7, 2025
b15c51d
Support Lomboks `var` and `val` for Java 8
jevanlingen Jan 7, 2025
b7fbd6e
Cleanup
jevanlingen Jan 7, 2025
da9de0c
Cleanup
jevanlingen Jan 7, 2025
71a2e13
Cleanup of `isLombokGenerated` methods
jevanlingen Jan 8, 2025
6a8c5c6
Cleanup of `isLombokGenerated` methods
jevanlingen Jan 8, 2025
1959b5c
Cleanup of `isLombokGenerated` methods
jevanlingen Jan 8, 2025
a21fbbd
Cleanup of `isLombokGenerated` methods
jevanlingen Jan 8, 2025
5dc7963
Cleanup of `isLombokGenerated` methods
jevanlingen Jan 8, 2025
baf98bb
Cleanup
jevanlingen Jan 8, 2025
fcb70a3
Merge branch 'main' into lombok-java-8
jevanlingen Jan 8, 2025
1b6173e
Improve `onConstructor` and `onConstructorNoArgs` args
jevanlingen Jan 8, 2025
ddde9b0
Fix missing `onConstructor_` check
jevanlingen Jan 9, 2025
6b3d764
Cleanup
jevanlingen Jan 9, 2025
75f636b
Apply suggestions from code review
jevanlingen Jan 9, 2025
05fda97
Merge branch 'main' into lombok-java-8
jevanlingen Jan 9, 2025
3bc94df
Improve tests
jevanlingen Jan 9, 2025
b5deb67
Merge branch 'main' into lombok-java-8
jevanlingen Jan 9, 2025
e0c917d
Merge branch 'main' into lombok-java-8
jevanlingen Jan 9, 2025
b59aecc
Rename JavacAnnotationHandler with no action to XNoOpHandler
jevanlingen Jan 10, 2025
fb52094
Rename JavacAnnotationHandler with no action to XNoOpHandler
jevanlingen Jan 10, 2025
3f2f60b
Improve lomboks `ExampleException` test
jevanlingen Jan 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import com.sun.source.tree.*;
import com.sun.source.util.TreePathScanner;
import com.sun.tools.javac.code.Attribute;
import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.tree.DCTree;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.sun.source.doctree.DocCommentTree;
import com.sun.source.tree.*;
import com.sun.source.util.TreePathScanner;
import com.sun.tools.javac.code.Attribute;
import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.tree.DocCommentTable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.sun.source.doctree.DocCommentTree;
import com.sun.source.tree.*;
import com.sun.source.util.TreePathScanner;
import com.sun.tools.javac.code.Attribute;
import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.tree.DocCommentTable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
*/
package org.openrewrite.java;

import com.sun.org.apache.xalan.internal.xsltc.compiler.sym;
import com.sun.source.tree.*;
import com.sun.source.util.TreePathScanner;
import com.sun.tools.javac.code.Attribute;
import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.tree.DCTree;
Expand Down Expand Up @@ -55,7 +53,8 @@
import java.util.stream.Collectors;

import static java.lang.Math.max;
import static java.util.Collections.*;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static java.util.stream.Collectors.toList;
import static java.util.stream.StreamSupport.stream;
import static org.openrewrite.Tree.randomId;
Expand Down
126 changes: 116 additions & 10 deletions rewrite-java-tck/src/main/java/org/openrewrite/java/tree/LombokTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.openrewrite.java.JavaParser;
import org.openrewrite.java.search.FindMissingTypes;
import org.openrewrite.java.MinimumJava11;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;
import org.openrewrite.test.TypeValidation;
Expand Down Expand Up @@ -245,6 +245,12 @@ public class ConstructorExample<T> {
public static class NoArgsExample {
@NonNull private String field;
}

public void test() {
ConstructorExample<?> x = ConstructorExample.of("desc");
ConstructorExample<?> y = new ConstructorExample<>("1L");
ConstructorExample.NoArgsExample z = new ConstructorExample.NoArgsExample();
}
}
"""
)
Expand Down Expand Up @@ -710,6 +716,7 @@ public void both(String s) {
}

@Test
@MinimumJava11
void jacksonized() {
rewriteRun(
spec -> spec.parser(JavaParser.fromJavaVersion().classpath("jackson-annotations", "lombok")),
Expand Down Expand Up @@ -746,18 +753,15 @@ public class ExampleException extends Exception {
}

@Test
@MinimumJava11
void onConstructor() {
rewriteRun(
java(
"""
public @interface Inject {}
public @interface Id {}
public @interface Column {
String name();
}
public @interface Max {
long value();
}
public @interface Column { String name(); }
public @interface Max { long value(); }
"""
),
java(
Expand All @@ -766,10 +770,10 @@ void onConstructor() {
import lombok.Getter;
import lombok.Setter;

@AllArgsConstructor(onConstructor_=@Inject) //JDK8
@AllArgsConstructor(onConstructor_=@Inject)
public class OnXExample {
@Getter(onMethod_={@Id, @Column(name="unique-id")}) //JDK8
@Setter(onParam_=@Max(10000)) //JDK8
@Getter(onMethod_={@Id, @Column(name="unique-id")})
@Setter(onParam_=@Max(10000))
private long unid;

public void test() {
Expand All @@ -784,6 +788,7 @@ public void test() {
}

@Test
@MinimumJava11
void onConstructorNoArgs() {
rewriteRun(
java(
Expand Down Expand Up @@ -821,6 +826,107 @@ public void test() {
@SuppressWarnings("MismatchedReadAndWriteOfArray")
@Nested
class LessSupported {
/*
java 8 cannot figure out all type checking:
- When the @AllArgsConstructorHandler, @NoArgsConstructorHandler and @NoArgsConstructorHandler annotations are
used with the `onConstructor_` param, Lombok does not call the JavacAnnotationHandlers.
- The @Jacksonized annotation does somehow turns into `ClassDeclaration->CompilationUni` error
*/

@Test
// TODO: Find solution and remove this test
void jacksonizedForJava8() {
rewriteRun(
spec -> spec
.parser(JavaParser.fromJavaVersion().classpath("jackson-annotations", "lombok"))
.typeValidationOptions(TypeValidation.none()),
jevanlingen marked this conversation as resolved.
Show resolved Hide resolved
java(
"""
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Builder;
import lombok.extern.jackson.Jacksonized;

@Jacksonized
@Builder
@JsonIgnoreProperties(ignoreUnknown = true)
public class JacksonExample {
private List<String> strings;
}
"""
)
);
}

@Test
// TODO: Find solution and remove this test
void onConstructorForJava8() {
rewriteRun(
spec -> spec.typeValidationOptions(TypeValidation.none()),
java(
"""
public @interface Inject {}
public @interface Id {}
public @interface Column { String name(); }
public @interface Max { long value(); }
"""
),
java(
"""
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

@AllArgsConstructor(onConstructor_=@Inject)
public class OnXExample {
@Getter(onMethod_={@Id, @Column(name="unique-id")})
@Setter(onParam_=@Max(10000))
private long unid;

public void test() {
OnXExample x = new OnXExample(1L);
x.setUnid(2L);
System.out.println(x.getUnid());
}
}
"""
)
);
}

@Test
// TODO: Find solution and remove this test
void onConstructorNoArgsForJava8() {
rewriteRun(
spec -> spec.typeValidationOptions(TypeValidation.none()),
java(
"""
public @interface Inject {}
"""
),
java(
"""
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;

import javax.inject.Inject;

@NoArgsConstructor(onConstructor_ = @Inject)
@RequiredArgsConstructor(onConstructor_ = @Inject)
public class OnXExample {
@NonNull private Long unid;

public void test() {
new OnXExample();
new OnXExample(1L);
}
}
"""
)
);
}


@Test
void extensionMethod() {
rewriteRun(
Expand Down
Loading