mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 04:16:19 +00:00
Merge pull request #3789 from Rawi01/utility-class-nested
Remove outer type reference when marking class as static
This commit is contained in:
7 files changed
+69
-15
No files matched your search
@@ -183,3 +183,32 @@ jobs:
|
||||
|
||||
- name: Compile in container
|
||||
run: docker run --entrypoint="" -v $(pwd)/lombok.jar:/workspace/lombok.jar $IMAGE_NAME /bin/bash -c "cd classpath; ${{ matrix.tool.cmd }}"
|
||||
|
||||
manual-tests:
|
||||
runs-on: ubuntu-24.04
|
||||
needs: build
|
||||
strategy:
|
||||
matrix:
|
||||
jdk: [8, 11, 17, 21, 23]
|
||||
dir: [compileTests]
|
||||
fail-fast: false
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up JDK ${{ matrix.jdk }}
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: ${{ matrix.jdk }}
|
||||
distribution: 'zulu'
|
||||
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: lombok.jar
|
||||
path: dist
|
||||
|
||||
- name: Run tests
|
||||
working-directory: ./test/manual/${{ matrix.dir }}/
|
||||
run: ./runTests.sh
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2015-2021 The Project Lombok Authors.
|
||||
* Copyright (C) 2015-2024 The Project Lombok Authors.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -107,7 +107,7 @@ public class HandleUtilityClass extends JavacAnnotationHandler<UtilityClass> {
|
||||
if ((typeDecl.mods.flags & (Flags.INTERFACE | Flags.ANNOTATION)) != 0) markStatic = false;
|
||||
}
|
||||
|
||||
if (markStatic) classDecl.mods.flags |= Flags.STATIC;
|
||||
if (markStatic) markClassAsStatic(classDecl);
|
||||
|
||||
for (JavacNode element : typeNode.down()) {
|
||||
if (element.getKind() == Kind.FIELD) {
|
||||
@@ -125,21 +125,23 @@ public class HandleUtilityClass extends JavacAnnotationHandler<UtilityClass> {
|
||||
|
||||
methodDecl.mods.flags |= Flags.STATIC;
|
||||
} else if (element.getKind() == Kind.TYPE) {
|
||||
JCClassDecl innerClassDecl = (JCClassDecl) element.get();
|
||||
innerClassDecl.mods.flags |= Flags.STATIC;
|
||||
ClassSymbol innerClassSymbol = innerClassDecl.sym;
|
||||
if (innerClassSymbol != null) {
|
||||
if (innerClassSymbol.type instanceof ClassType) {
|
||||
((ClassType) innerClassSymbol.type).setEnclosingType(Type.noType);
|
||||
}
|
||||
innerClassSymbol.erasure_field = null;
|
||||
}
|
||||
markClassAsStatic((JCClassDecl) element.get());
|
||||
}
|
||||
}
|
||||
|
||||
if (makeConstructor) createPrivateDefaultConstructor(typeNode);
|
||||
}
|
||||
|
||||
private void markClassAsStatic(JCClassDecl classDecl) {
|
||||
classDecl.mods.flags |= Flags.STATIC; // maybe Flags.NOOUTERTHIS too?
|
||||
ClassSymbol innerClassSymbol = classDecl.sym;
|
||||
if (innerClassSymbol != null && innerClassSymbol.type instanceof ClassType) {
|
||||
ClassType classType = (ClassType) innerClassSymbol.type;
|
||||
classType.setEnclosingType(Type.noType);
|
||||
innerClassSymbol.erasure_field = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void createPrivateDefaultConstructor(JavacNode typeNode) {
|
||||
JavacTreeMaker maker = typeNode.getTreeMaker();
|
||||
JCModifiers mods = maker.Modifiers(Flags.PRIVATE, List.<JCAnnotation>nil());
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
/out
|
||||
Executable
+20
@@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
echo 'This will compile a selection of files in test/transform/resource/before. If the compilation works without error, lombok is working as designed.'
|
||||
|
||||
mkdir -p out/
|
||||
|
||||
# list of files to iterate over
|
||||
FILES="UtilityClassInner.java"
|
||||
BASE_PATH="../../../test/transform/resource/before"
|
||||
LOMBOK_JAR="../../../dist/lombok.jar"
|
||||
|
||||
# compile all files in list
|
||||
for f in $FILES
|
||||
do
|
||||
|
||||
echo "Compiling $f"
|
||||
javac -processorpath $LOMBOK_JAR -cp $LOMBOK_JAR -d out/ $BASE_PATH/$f
|
||||
done
|
||||
|
||||
rm -rf out/
|
||||
@@ -1,5 +1,6 @@
|
||||
@java.lang.SuppressWarnings("serial")
|
||||
class UtilityClassInner {
|
||||
static final class UtilClass {
|
||||
static final class UtilClass implements java.io.Serializable {
|
||||
@java.lang.SuppressWarnings("all")
|
||||
@lombok.Generated
|
||||
private UtilClass() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class UtilityClassInner {
|
||||
static final @lombok.experimental.UtilityClass class UtilClass {
|
||||
@java.lang.SuppressWarnings("serial") class UtilityClassInner {
|
||||
static final @lombok.experimental.UtilityClass class UtilClass implements java.io.Serializable {
|
||||
private @java.lang.SuppressWarnings("all") @lombok.Generated UtilClass() {
|
||||
super();
|
||||
throw new java.lang.UnsupportedOperationException("This is a utility class and cannot be instantiated");
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
@java.lang.SuppressWarnings("serial")
|
||||
class UtilityClassInner {
|
||||
@lombok.experimental.UtilityClass
|
||||
class UtilClass {}
|
||||
class UtilClass implements java.io.Serializable {}
|
||||
}
|
||||
Reference in new issue
Block a user