Skip to content

Commit

Permalink
[fixes #3559[fixes #3497] Treat nested records as static
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawi01 committed Dec 17, 2023
1 parent 0089374 commit fb09a99
Show file tree
Hide file tree
Showing 14 changed files with 229 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 class 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;

}
23 changes: 23 additions & 0 deletions test/transform/resource/after-ecj/WithOnNestedRecord.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import lombok.With;
public class 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));
}
}
public WithOnNestedRecord() {
super();
}
}
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 class WithOnNestedRecord<T> {
@With
public record Nested(String a, String b) {

}
}

0 comments on commit fb09a99

Please sign in to comment.