Skip to content

Commit

Permalink
Merge branch 'nested-record-builder' of https://github.com/Rawi01/lombok
Browse files Browse the repository at this point in the history
 into Rawi01-nested-record-builder
  • Loading branch information
rzwitserloot committed Jan 11, 2024
2 parents 55f3a02 + 27cd3e5 commit 9191f4b
Show file tree
Hide file tree
Showing 14 changed files with 226 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/core/lombok/eclipse/EclipseNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ private Integer getModifiers() {
if (node instanceof TypeDeclaration) {
TypeDeclaration t = (TypeDeclaration) node;
int f = t.modifiers;
if (((ClassFileConstants.AccInterface | ClassFileConstants.AccEnum) & f) != 0) return true;
if (((ClassFileConstants.AccInterface | ClassFileConstants.AccEnum | Eclipse.AccRecord) & f) != 0) return true;

EclipseNode directUp = directUp();
if (directUp == null || directUp.getKind() == Kind.COMPILATION_UNIT) return true;
Expand Down
2 changes: 1 addition & 1 deletion src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ public static TypeReference generateParameterizedTypeReference(EclipseNode paren
return new ParameterizedQualifiedTypeReference(tn, rr, 0, ps);
}

private static final int MODIFIERS_INDICATING_STATIC = ClassFileConstants.AccInterface | ClassFileConstants.AccStatic | ClassFileConstants.AccEnum;
private static final int MODIFIERS_INDICATING_STATIC = ClassFileConstants.AccInterface | ClassFileConstants.AccStatic | ClassFileConstants.AccEnum | Eclipse.AccRecord;

/**
* This class will add type params to fully qualified chain of type references for inner types, such as {@code GrandParent.Parent.Child}; this is needed only as long as the chain does not involve static.
Expand Down
2 changes: 1 addition & 1 deletion src/core/lombok/javac/JavacNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ private JCModifiers getModifiers() {
if (node instanceof JCClassDecl) {
JCClassDecl t = (JCClassDecl) node;
long f = t.mods.flags;
if (((Flags.INTERFACE | Flags.ENUM) & f) != 0) return true;
if (((Flags.INTERFACE | Flags.ENUM | Javac.RECORD) & f) != 0) return true;
JavacNode directUp = directUp();
if (directUp == null || directUp.getKind() == Kind.COMPILATION_UNIT) return true;
if (!(directUp.get() instanceof JCClassDecl)) return false;
Expand Down
6 changes: 3 additions & 3 deletions src/core/lombok/javac/handlers/JavacHandlerUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -2033,13 +2033,13 @@ public static JCExpression removeTypeUseAnnotations(JCExpression from) {

public static JCExpression namePlusTypeParamsToTypeReference(JavacTreeMaker maker, JavacNode type, List<JCTypeParameter> params) {
JCClassDecl td = (JCClassDecl) type.get();
boolean instance = (td.mods.flags & Flags.STATIC) == 0;
boolean instance = !type.isStatic();
return namePlusTypeParamsToTypeReference(maker, type.up(), td.name, instance, params, List.<JCAnnotation>nil());
}

public static JCExpression namePlusTypeParamsToTypeReference(JavacTreeMaker maker, JavacNode type, List<JCTypeParameter> params, List<JCAnnotation> annotations) {
JCClassDecl td = (JCClassDecl) type.get();
boolean instance = (td.mods.flags & Flags.STATIC) == 0;
boolean instance = !type.isStatic();
return namePlusTypeParamsToTypeReference(maker, type.up(), td.name, instance, params, annotations);
}

Expand All @@ -2051,7 +2051,7 @@ public static JCExpression namePlusTypeParamsToTypeReference(JavacTreeMaker make
JCExpression r = null;
if (parentType != null && parentType.getKind() == Kind.TYPE && !parentType.getName().isEmpty()) {
JCClassDecl td = (JCClassDecl) parentType.get();
boolean outerInstance = instance && ((td.mods.flags & Flags.STATIC) == 0);
boolean outerInstance = instance && !parentType.isStatic();
List<JCTypeParameter> outerParams = instance ? td.typarams : List.<JCTypeParameter>nil();
r = namePlusTypeParamsToTypeReference(maker, parentType.up(), td.name, outerInstance, outerParams, List.<JCAnnotation>nil());
}
Expand Down
49 changes: 49 additions & 0 deletions test/transform/resource/after-delombok/BuilderOnNestedClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
public class BuilderOnNestedClass<T> {
private T t;


public static class Nested {
private String a;

@java.lang.SuppressWarnings("all")
Nested(final String a) {
this.a = a;
}


@java.lang.SuppressWarnings("all")
public static class NestedBuilder {
@java.lang.SuppressWarnings("all")
private String a;

@java.lang.SuppressWarnings("all")
NestedBuilder() {
}

/**
* @return {@code this}.
*/
@java.lang.SuppressWarnings("all")
public BuilderOnNestedClass.Nested.NestedBuilder a(final String a) {
this.a = a;
return this;
}

@java.lang.SuppressWarnings("all")
public BuilderOnNestedClass.Nested build() {
return new BuilderOnNestedClass.Nested(this.a);
}

@java.lang.Override
@java.lang.SuppressWarnings("all")
public java.lang.String toString() {
return "BuilderOnNestedClass.Nested.NestedBuilder(a=" + this.a + ")";
}
}

@java.lang.SuppressWarnings("all")
public static BuilderOnNestedClass.Nested.NestedBuilder builder() {
return new BuilderOnNestedClass.Nested.NestedBuilder();
}
}
}
41 changes: 41 additions & 0 deletions test/transform/resource/after-delombok/BuilderOnNestedRecord.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// version 14:
public record BuilderOnNestedRecord<T>(T t) {

public record Nested(String a) {

@java.lang.SuppressWarnings("all")
public static class NestedBuilder {
@java.lang.SuppressWarnings("all")
private String a;

@java.lang.SuppressWarnings("all")
NestedBuilder() {
}

/**
* @return {@code this}.
*/
@java.lang.SuppressWarnings("all")
public BuilderOnNestedRecord.Nested.NestedBuilder a(final String a) {
this.a = a;
return this;
}

@java.lang.SuppressWarnings("all")
public BuilderOnNestedRecord.Nested build() {
return new BuilderOnNestedRecord.Nested(this.a);
}

@java.lang.Override
@java.lang.SuppressWarnings("all")
public java.lang.String toString() {
return "BuilderOnNestedRecord.Nested.NestedBuilder(a=" + this.a + ")";
}
}

@java.lang.SuppressWarnings("all")
public static BuilderOnNestedRecord.Nested.NestedBuilder builder() {
return new BuilderOnNestedRecord.Nested.NestedBuilder();
}
}
}
21 changes: 21 additions & 0 deletions test/transform/resource/after-delombok/WithOnNestedRecord.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// version 14:
public record WithOnNestedRecord<T>() {

public record Nested(String a, String b) {
/**
* @return a clone of this object, except with this updated property (returns {@code this} if an identical value is passed).
*/
@java.lang.SuppressWarnings("all")
public WithOnNestedRecord.Nested withA(final String a) {
return this.a == a ? this : new WithOnNestedRecord.Nested(a, this.b);
}

/**
* @return a clone of this object, except with this updated property (returns {@code this} if an identical value is passed).
*/
@java.lang.SuppressWarnings("all")
public WithOnNestedRecord.Nested withB(final String b) {
return this.b == b ? this : new WithOnNestedRecord.Nested(this.a, b);
}
}
}
35 changes: 35 additions & 0 deletions test/transform/resource/after-ecj/BuilderOnNestedClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
public class BuilderOnNestedClass<T> {
public static @lombok.Builder class Nested {
public static @java.lang.SuppressWarnings("all") class NestedBuilder {
private @java.lang.SuppressWarnings("all") String a;
@java.lang.SuppressWarnings("all") NestedBuilder() {
super();
}
/**
* @return {@code this}.
*/
public @java.lang.SuppressWarnings("all") BuilderOnNestedClass.Nested.NestedBuilder a(final String a) {
this.a = a;
return this;
}
public @java.lang.SuppressWarnings("all") BuilderOnNestedClass.Nested build() {
return new BuilderOnNestedClass.Nested(this.a);
}
public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
return (("BuilderOnNestedClass.Nested.NestedBuilder(a=" + this.a) + ")");
}
}
private String a;
@java.lang.SuppressWarnings("all") Nested(final String a) {
super();
this.a = a;
}
public static @java.lang.SuppressWarnings("all") BuilderOnNestedClass.Nested.NestedBuilder builder() {
return new BuilderOnNestedClass.Nested.NestedBuilder();
}
}
private T t;
public BuilderOnNestedClass() {
super();
}
}
30 changes: 30 additions & 0 deletions test/transform/resource/after-ecj/BuilderOnNestedRecord.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
public record BuilderOnNestedRecord(T t)<T> {
public @lombok.Builder record Nested(String a) {
public static @java.lang.SuppressWarnings("all") class NestedBuilder {
private @java.lang.SuppressWarnings("all") String a;
@java.lang.SuppressWarnings("all") NestedBuilder() {
super();
}
/**
* @return {@code this}.
*/
public @java.lang.SuppressWarnings("all") BuilderOnNestedRecord.Nested.NestedBuilder a(final String a) {
this.a = a;
return this;
}
public @java.lang.SuppressWarnings("all") BuilderOnNestedRecord.Nested build() {
return new BuilderOnNestedRecord.Nested(this.a);
}
public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
return (("BuilderOnNestedRecord.Nested.NestedBuilder(a=" + this.a) + ")");
}
}
/* Implicit */ private final String a;

public static @java.lang.SuppressWarnings("all") BuilderOnNestedRecord.Nested.NestedBuilder builder() {
return new BuilderOnNestedRecord.Nested.NestedBuilder();
}
}
/* Implicit */ private final T t;

}
20 changes: 20 additions & 0 deletions test/transform/resource/after-ecj/WithOnNestedRecord.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import lombok.With;
public record WithOnNestedRecord()<T> {
public @With record Nested(String a, String b) {
/* Implicit */ private final String a;
/* Implicit */ private final String b;

/**
* @return a clone of this object, except with this updated property (returns {@code this} if an identical value is passed).
*/
public @java.lang.SuppressWarnings("all") WithOnNestedRecord.Nested withA(final String a) {
return ((this.a == a) ? this : new WithOnNestedRecord.Nested(a, this.b));
}
/**
* @return a clone of this object, except with this updated property (returns {@code this} if an identical value is passed).
*/
public @java.lang.SuppressWarnings("all") WithOnNestedRecord.Nested withB(final String b) {
return ((this.b == b) ? this : new WithOnNestedRecord.Nested(this.a, b));
}
}
}
8 changes: 8 additions & 0 deletions test/transform/resource/before/BuilderOnNestedClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
public class BuilderOnNestedClass<T> {
private T t;

@lombok.Builder
public static class Nested {
private String a;
}
}
7 changes: 7 additions & 0 deletions test/transform/resource/before/BuilderOnNestedRecord.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// version 14:
public record BuilderOnNestedRecord<T>(T t) {
@lombok.Builder
public record Nested(String a) {

}
}
Empty file.
9 changes: 9 additions & 0 deletions test/transform/resource/before/WithOnNestedRecord.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// version 14:
import lombok.With;

public record WithOnNestedRecord<T>() {
@With
public record Nested(String a, String b) {

}
}

0 comments on commit 9191f4b

Please sign in to comment.