Skip to content

Commit

Permalink
[fixes projectlombok#3097] Update inner class type when creating a st…
Browse files Browse the repository at this point in the history
…atic class
  • Loading branch information
Rawi01 committed Jan 29, 2022
1 parent 36db052 commit 7af7526
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/core/lombok/javac/handlers/HandleUtilityClass.java
Expand Up @@ -25,6 +25,9 @@
import static lombok.javac.handlers.JavacHandlerUtil.*;

import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.code.Symbol.ClassSymbol;
import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.code.Type.ClassType;
import com.sun.tools.javac.tree.JCTree.JCAnnotation;
import com.sun.tools.javac.tree.JCTree.JCBlock;
import com.sun.tools.javac.tree.JCTree.JCClassDecl;
Expand Down Expand Up @@ -124,6 +127,10 @@ private void changeModifiersAndGenerateConstructor(JavacNode typeNode, JavacNode
} else if (element.getKind() == Kind.TYPE) {
JCClassDecl innerClassDecl = (JCClassDecl) element.get();
innerClassDecl.mods.flags |= Flags.STATIC;
ClassSymbol innerClassSymbol = innerClassDecl.sym;
if (innerClassSymbol != null && innerClassSymbol.type instanceof ClassType) {
((ClassType) innerClassSymbol.type).setEnclosingType(Type.noType);
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions test/transform/resource/after-delombok/UtilityClass.java
Expand Up @@ -2,10 +2,15 @@ final class UtilityClass {
private static long someField = System.currentTimeMillis();
static void someMethod() {
System.out.println();
new InnerClass();
new InnerStaticClass();
}
protected static class InnerClass {
private String innerInnerMember;
}
protected static class InnerStaticClass {
private String innerInnerMember;
}
@java.lang.SuppressWarnings("all")
private UtilityClass() {
throw new java.lang.UnsupportedOperationException("This is a utility class and cannot be instantiated");
Expand Down
8 changes: 8 additions & 0 deletions test/transform/resource/after-ecj/UtilityClass.java
Expand Up @@ -5,11 +5,19 @@ protected InnerClass() {
super();
}
}
protected static class InnerStaticClass {
private String innerInnerMember;
protected InnerStaticClass() {
super();
}
}
private static long someField = System.currentTimeMillis();
<clinit>() {
}
static void someMethod() {
System.out.println();
new InnerClass();
new InnerStaticClass();
}
private @java.lang.SuppressWarnings("all") UtilityClass() {
super();
Expand Down
6 changes: 6 additions & 0 deletions test/transform/resource/before/UtilityClass.java
Expand Up @@ -4,11 +4,17 @@ class UtilityClass {

void someMethod() {
System.out.println();
new InnerClass();
new InnerStaticClass();
}

protected class InnerClass {
private String innerInnerMember;
}

protected static class InnerStaticClass {
private String innerInnerMember;
}
}

class UtilityInner {
Expand Down

0 comments on commit 7af7526

Please sign in to comment.