diff options
433 files changed, 9329 insertions, 5496 deletions
@@ -23,3 +23,4 @@ /out /website/lombokSupporters /pom.xml +/jvm.locations @@ -6,6 +6,7 @@ Andre Brait <andrebrait@gmail.com> Bulgakov Alexander <buls@yandex.ru> Caleb Brinkman <floralvikings@gmail.com> Christian Nüssgens <christian@nuessgens.com> +Christian Schlichtherle <christian-schlichtherle@users.noreply.github.com> Christian Sterzl <christian.sterzl@gmail.com> DaveLaw <project.lombok@apconsult.de> Dave Brosius <dbrosius@mebigfatguy.com> @@ -24,6 +25,7 @@ Maarten Mulders <mthmulders@users.noreply.github.com> Mark Haynes <markhaynes.work@gmail.com> Mart Hagenaars <marthagenaars@gmail.com> Mateusz Matela <mateusz.matela@gmail.com> +Michael Dardis <git@md-5.net> Michael Ernst <mernst@alum.mit.edu> Michiel Verheul <cheelio@gmail.com> Pascal Bihler <pascal@qfs.de> @@ -48,4 +50,4 @@ Till Brychcy <till.brychcy@mercateo.com> Victor Williams Stafusa da Silva <victorwssilva@gmail.com> Yun Zhi Lin <yun@yunspace.com> -By adding your name to this list, you grant full and irrevocable copyright and patent indemnity to Project Lombok and all use of Project Lombok, and you certify that you have the right to do so for all commits you add to Project Lombok. +By adding your name to this list, you grant full and irrevocable copyright and patent indemnity to Project Lombok and all use of Project Lombok in relation to all commits you add to Project Lombok, and you certify that you have the right to do so. diff --git a/buildScripts/compile.ant.xml b/buildScripts/compile.ant.xml index bc1d3e8d..23a8a63c 100644 --- a/buildScripts/compile.ant.xml +++ b/buildScripts/compile.ant.xml @@ -1,5 +1,5 @@ <!-- - Copyright (C) 2020 The Project Lombok Authors. + Copyright (C) 2020-2021 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 @@ -50,7 +50,7 @@ This buildfile is part of projectlombok.org. It takes care of compiling and buil <echo level="info">Lombok version: ${lombok.version} (${lombok.fullversion})</echo> </target> - <property name="packing.basedirs" value="build/lombok-transplants,build/lombok-utils,build/lombok-utils6,build/lombok-main,build/lombok-main8,build/lombok-meta,build/lombok-deps" /> + <property name="packing.basedirs" value="build/lombok-transplants,build/lombok-utils,build/lombok-utils6,build/lombok-main,build/lombok-main8,build/lombok-deps" /> <loadresource property="packing.basedirs.colon"> <propertyresource name="packing.basedirs" /> <filterchain><tokenfilter> @@ -62,21 +62,31 @@ This buildfile is part of projectlombok.org. It takes care of compiling and buil <pathelement path="${packing.basedirs.colon}" /> </path> - <target name="compile" depends="version, deps, -setup.build" description="Compiles the code"> + <target name="create.spiProcessor" depends="version, -setup.build" description="Compiles the services file generating processor"> + <ivy:compile destdir="build/spiProcessor" source="1.8" target="1.8" ecj="true"> + <src path="src/spiProcessor" /> + <classpath location="build/spiProcessor" /> + </ivy:compile> + <mkdir dir="build/spiProcessor/META-INF/services" /> + <echo file="build/spiProcessor/META-INF/services/javax.annotation.processing.Processor">lombok.spi.SpiProcessor</echo> + <jar destfile="dist/spiProcessor.jar"> + <fileset dir="build/spiProcessor" /> + </jar> + </target> + + <target name="compile" depends="version, deps, -setup.build, create.spiProcessor" description="Compiles the code"> <!-- 1. Compile stubs. 2. Compile transplants. 3. Compile lombok-utils. - 4. Compile lombok. - 5. Run SPI processor. - 6. Create other manifest entries. --> + 4. Compile lombok. --> <!-- ant includes the destination dir on the classpath (and there are good reasons to do this), but that also means the bleeding edge lombok from the previous build is run (as lombok is an annotation processor), which means if there are bugs in it, you can't compile anymore until you 'ant clean'. That's very undesirable. so we kill the processor, which stops lombok from running. We re-create the file at the end of this target. --> - <delete file="build/lombok-meta/META-INF/services/javax.annotation.processing.Processor" quiet="true" /> + <delete file="build/lombok-main/META-INF/services/javax.annotation.processing.Processor" quiet="true" /> <!-- first, compile stubs. Lombok needs to produce class files that run in a wide variety of JDK, javac, and ecj/eclipse versions. @@ -162,7 +172,8 @@ This buildfile is part of projectlombok.org. It takes care of compiling and buil <classpath refid="cp.build" /> <classpath refid="cp.eclipse-oxygen" /> <classpath refid="cp.javac6" /> - <classpath path="build/lombok-utils:build/lombok-utils6:build/lombok-main" /> + <classpath path="build/lombok-utils:build/lombok-utils6:build/lombok-main:dist/spiProcessor.jar" /> + <annotationProcessor jar="dist/spiProcessor.jar" processor="lombok.spi.SpiProcessor" /> </ivy:compile> <!-- This is really part of the eclipse agent, but references lombok, so that had to be compiled first --> @@ -183,7 +194,7 @@ This buildfile is part of projectlombok.org. It takes care of compiling and buil <bootclasspath location="build/stubs" /> <src path="src/core8" /> <classpath refid="cp.javac8" /> - <classpath path="build/lombok-main:build/lombok-main8" /> + <classpath path="build/lombok-main:build/lombok-main8:build" /> </ivy:compile> <!-- @@ -195,37 +206,11 @@ This buildfile is part of projectlombok.org. It takes care of compiling and buil <classpath refid="cp.build" /> </ivy:compile> - <!-- Run the SPI processor to create the services files listing all lombok handlers --> - <delete dir="build/lombok-proc-result" quiet="true" /> - <ivy:compile destdir="build/lombok-proc-result" release="9" nowarn="true"> - <classpath location="build/stubs" /> - <compilerarg value="-proc:only" /> - <compilerarg value="-processor" /> - <compilerarg value="org.mangosdk.spi.processor.SpiProcessor" /> - <src path="src/core" /> - <src path="src/installer" /> - <src path="src/eclipseAgent" /> - <src path="src/delombok" /> - <classpath refid="cp.build" /> - <classpath refid="cp.javac6" /> - <classpath refid="cp.eclipse-oxygen" /> - <classpath path="build/lombok-utils:build/lombok-utils6:build/lombok-main" /> - </ivy:compile> - - <mkdir dir="build/lombok-meta" /> - - <copy todir="build/lombok-meta"> - <fileset dir="build/lombok-proc-result"> - <include name="META-INF/services/*" /> - </fileset> - </copy> - - <mkdir dir="build/lombok-meta/META-INF" /> - <mkdir dir="build/lombok-meta/META-INF/services" /> - <echo file="build/lombok-meta/META-INF/services/javax.annotation.processing.Processor">lombok.launch.AnnotationProcessorHider$AnnotationProcessor + <mkdir dir="build/lombok-main/META-INF/services" /> + <echo file="build/lombok-main/META-INF/services/javax.annotation.processing.Processor">lombok.launch.AnnotationProcessorHider$AnnotationProcessor lombok.launch.AnnotationProcessorHider$ClaimingProcessor</echo> - <mkdir dir="build/lombok-meta/META-INF/gradle" /> - <echo file="build/lombok-meta/META-INF/gradle/incremental.annotation.processors">lombok.launch.AnnotationProcessorHider$AnnotationProcessor,isolating + <mkdir dir="build/lombok-main/META-INF/gradle" /> + <echo file="build/lombok-main/META-INF/gradle/incremental.annotation.processors">lombok.launch.AnnotationProcessorHider$AnnotationProcessor,isolating lombok.launch.AnnotationProcessorHider$ClaimingProcessor,isolating</echo> </target> @@ -272,7 +257,6 @@ lombok.launch.AnnotationProcessorHider$ClaimingProcessor,isolating</echo> </patternset> <fileset dir="build/lombok-main"><patternset refid="packing.entrypoints" /></fileset> - <fileset dir="build/lombok-meta"><patternset refid="packing.entrypoints" /></fileset> <!-- now include everything else but renamed for the shadowloader system, to make these classes invisible to other projects. --> <patternset id="packing.shadowed"> diff --git a/buildScripts/create-eclipse-project.ant.xml b/buildScripts/create-eclipse-project.ant.xml index 383ebd8b..a9b1a5dc 100644 --- a/buildScripts/create-eclipse-project.ant.xml +++ b/buildScripts/create-eclipse-project.ant.xml @@ -1,5 +1,5 @@ <!-- - Copyright (C) 2010-2020 The Project Lombok Authors. + Copyright (C) 2010-2021 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 @@ -24,10 +24,11 @@ This buildfile is part of projectlombok.org. It creates the infrastructure needed to develop lombok on eclipse. </description> - <target name="eclipse" depends="eclipse.projectfiles, eclipse.testtarget.default" description="Downloads dependencies, create eclipse project files, as well as debug/run test targets. Open this directory as project in eclipse (via import... existing projects)" /> + <target name="eclipse" depends="create.spiProcessor, eclipse.projectfiles, eclipse.testtarget.default" description="Downloads dependencies, create eclipse project files, as well as debug/run test targets. Open this directory as project in eclipse (via import... existing projects)" /> <target name="eclipse.projectfiles" depends="deps"> <ivy:eclipsegen source="1.6" srcout="bin/main"> + <srcdir dir="src/spiProcessor" /> <srcdir dir="src/core" /> <srcdir dir="src/core8" /> <srcdir dir="src/launch" /> @@ -52,7 +53,7 @@ This buildfile is part of projectlombok.org. It creates the infrastructure neede <settings> <url url="https://projectlombok.org/downloads/lombok.eclipse.settings" /> </settings> - <apt location="lib/build/projectlombok.org-spi.jar" /> + <apt location="dist/spiProcessor.jar" /> </ivy:eclipsegen> </target> diff --git a/buildScripts/create-intellij-project.ant.xml b/buildScripts/create-intellij-project.ant.xml index 865e8971..33c1e449 100644 --- a/buildScripts/create-intellij-project.ant.xml +++ b/buildScripts/create-intellij-project.ant.xml @@ -1,5 +1,5 @@ <!-- - Copyright (C) 2010-2020 The Project Lombok Authors. + Copyright (C) 2010-2021 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 @@ -24,15 +24,22 @@ This buildfile is part of projectlombok.org. It creates the infrastructure needed to develop lombok on intellij. </description> - <target name="intellij" depends="deps" description="Creates intellij project files and downloads all dependencies. Open this directory as a project in IntelliJ after running this target"> + <target name="intellij" depends="create.spiProcessor, deps" description="Creates intellij project files and downloads all dependencies. Open this directory as a project in IntelliJ after running this target"> <echo> ** WARNING ** The core lombok contributors all use eclipse to develop lombok. This script will attempt to set up your lombok directory up as intellij project; whether can be used in a modern intellij is currently unknown. Please do continue, but be aware that trying to work on lombok from intellij may run into problems. If you want to adopt 'work on lombok via intellij' as a task, we're open to it!</echo> <echo>NOT IMPLEMENTED: The project should optimally be configured as a java1.6, using the rt.jar in lib/openjdk6_rt.jar as boot basis, to ensure lombok remains 1.6 compatible.</echo> <echo>NOT IMPLEMENTED: Ability to run tests targeted at a specific jvm/javac/ecj/eclipse release; the relevant entrypoint test classes are lombok.RunBaseAndJavacTests and lombok.RunEclipseTests - you can run the eclipse tests even on intellij; an eclipse installation is not required.</echo> + <echo>NOT SURE: The annotation processor system that automatically generates the services files has been changed. This AP is now internal to the project, + the source files for it are in `src/spiProcessor`, and a build of this is now in `dist/spiProcessor.jar` - you may have to manually add it, though I'm not + sure if you actually need it - the files generated by this processor are relevant only when running lombok itself, and if intellij accomplishes this by + invoking ant, all will be well.</echo> <input>Press return to continue</input> <ivy:intellijgen> - <conf name="build" sources="contrib" /> - <conf name="test" sources="contrib" /> + <conf name="build" sources="sources" /> + <conf name="javac6" sources="sources" /> + <conf name="test" sources="sources" /> + <conf name="buildTools" sources="sources" /> <module name="lombok" depends="build, test"> + <srcdir dir="src/spiProcessor" /> <srcdir dir="src/core" /> <srcdir dir="src/core8" /> <srcdir dir="src/launch" /> diff --git a/buildScripts/ivy-repo/org.projectlombok-lombok.patcher-0.38.xml b/buildScripts/ivy-repo/org.projectlombok-lombok.patcher-0.38.xml deleted file mode 100644 index 1ca9c743..00000000 --- a/buildScripts/ivy-repo/org.projectlombok-lombok.patcher-0.38.xml +++ /dev/null @@ -1,14 +0,0 @@ -<ivy-module version="2.0"> - <info organisation="org.projectlombok" module="lombok.patcher" revision="0.38" publication="20201008193000"> - <license name="MIT License" url="https://www.opensource.org/licenses/mit-license.php" /> - <ivyauthor name="rzwitserloot" url="https://github.com/rzwitserloot" /> - <ivyauthor name="rspilker" url="https://github.com/rspilker" /> - <description homepage="https://projectlombok.org/" /> - </info> - <configurations> - <conf name="default" /> - </configurations> - <publications> - <artifact conf="default" url="https://projectlombok.org/downloads/lombok.patcher-0.38.jar" /> - </publications> -</ivy-module> diff --git a/buildScripts/ivy-repo/org.projectlombok-lombok.patcher-0.36.xml b/buildScripts/ivy-repo/org.projectlombok-lombok.patcher-0.42.xml index b75b111d..c64d09df 100644 --- a/buildScripts/ivy-repo/org.projectlombok-lombok.patcher-0.36.xml +++ b/buildScripts/ivy-repo/org.projectlombok-lombok.patcher-0.42.xml @@ -1,5 +1,5 @@ <ivy-module version="2.0"> - <info organisation="org.projectlombok" module="lombok.patcher" revision="0.36" publication="20191210010000"> + <info organisation="org.projectlombok" module="lombok.patcher" revision="0.42" publication="20210322113600"> <license name="MIT License" url="https://www.opensource.org/licenses/mit-license.php" /> <ivyauthor name="rzwitserloot" url="https://github.com/rzwitserloot" /> <ivyauthor name="rspilker" url="https://github.com/rspilker" /> @@ -9,6 +9,6 @@ <conf name="default" /> </configurations> <publications> - <artifact conf="default" url="https://projectlombok.org/downloads/lombok.patcher-0.36.jar" /> + <artifact conf="default" url="https://projectlombok.org/downloads/lombok.patcher-0.42.jar" /> </publications> </ivy-module> diff --git a/buildScripts/ivy.xml b/buildScripts/ivy.xml index 5dded177..0da5c3fc 100644 --- a/buildScripts/ivy.xml +++ b/buildScripts/ivy.xml @@ -28,6 +28,7 @@ <conf name="ecj8" /> <conf name="ecj11" /> <conf name="ecj14" /> + <conf name="ecj16" /> <conf name="eclipse-oxygen" /> <conf name="eclipse-202006" /> @@ -36,10 +37,10 @@ </configurations> <dependencies> - <dependency org="org.projectlombok" name="lombok.patcher" rev="0.40" conf="build,stripe->default" /> + <dependency org="org.projectlombok" name="lombok.patcher" rev="0.42" conf="build,stripe->default" /> <dependency org="zwitserloot.com" name="cmdreader" rev="1.2" conf="build,stripe->runtime" /> - <dependency org="projectlombok.org" name="spi" rev="0.2.7" conf="build" /> <dependency org="org.apache.ant" name="ant" rev="1.10.5" conf="build->default" /> + <dependency org="org.apache.ant" name="ant-junit" rev="1.10.5" conf="build->default" /> <!-- test deps --> <dependency org="junit" name="junit" rev="4.8.2" conf="test->default; sources" /> @@ -52,6 +53,9 @@ <dependency org="com.google.flogger" name="flogger" rev="0.2" conf="test->default; sources" /> <dependency org="com.google.guava" name="guava" rev="18.0" conf="test->default; sources" /> <dependency org="com.google.code.findbugs" name="findbugs" rev="3.0.1" conf="test->master" /> + <dependency org="org.springframework" name="spring-core" rev="5.3.4" conf="test->master" /> + <dependency org="com.fasterxml.jackson.core" name="jackson-databind" rev="2.10.0" conf="test->master" /> + <dependency org="com.fasterxml.jackson.core" name="jackson-annotations" rev="2.10.0" conf="test->master" /> <!-- build tooling --> <dependency org="com.hierynomus" name="sshj" rev="0.26.0" conf="buildtools->default" /> @@ -73,6 +77,7 @@ <!-- ecjs --> + <dependency org="org.eclipse.jdt" name="ecj" rev="3.25.0" conf="ecj16->master" /> <dependency org="org.eclipse.jdt" name="ecj" rev="3.22.0.v20200530-2032" conf="ecj14->master" /> <dependency org="org.eclipse.jdt" name="ecj" rev="3.16.0" conf="ecj11->master" /> <!-- until oct 2016, ecj was released under org 'org.eclipse.jdt.core.compiler', and the versioning followed eclipse's versions. --> diff --git a/buildScripts/setup.ant.xml b/buildScripts/setup.ant.xml index e71f8143..2a9104eb 100644 --- a/buildScripts/setup.ant.xml +++ b/buildScripts/setup.ant.xml @@ -1,5 +1,5 @@ <!-- - Copyright (C) 2020 The Project Lombok Authors. + Copyright (C) 2020-2021 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 @@ -25,7 +25,7 @@ This buildfile is part of projectlombok.org. It sets up the build itself. </description> <!-- increment this number to force a clean of the 'build' dir --> - <property name="build.version" value="2020-12-04_001" /> + <property name="build.version" value="2021-03-18_001" /> <property name="pattern.jdk11plus" value="^(\d\d\d+|1[1-9]|[2-9]\d)(\..*)?$" /> <property name="ivy.retrieve.pattern" value="lib/[conf]/[organisation]-[artifact].[ext]" /> @@ -140,7 +140,7 @@ This buildfile is part of projectlombok.org. It sets up the build itself. <target name="-ipp.load" depends="-ipp.download"> <taskdef classpath="lib/ivyplusplus.jar" resource="com/zwitserloot/ivyplusplus/antlib.xml" uri="antlib:com.zwitserloot.ivyplusplus" /> - <ivy:ensureippversion version="1.38" property="ivyplusplus.minimumAvailable" /> + <ivy:ensureippversion version="1.40" property="ivyplusplus.minimumAvailable" /> </target> <target name="-ipp.redownload" unless="ivyplusplus.minimumAvailable"> diff --git a/buildScripts/tests.ant.xml b/buildScripts/tests.ant.xml index 41bfa391..9d9e9541 100644 --- a/buildScripts/tests.ant.xml +++ b/buildScripts/tests.ant.xml @@ -1,5 +1,5 @@ <!-- - Copyright (C) 2020 The Project Lombok Authors. + Copyright (C) 2020-2021 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 @@ -24,6 +24,14 @@ This buildfile is part of projectlombok.org. It takes care of compiling and running tests. </description> + <target name="test.formatter.compile" depends="deps"> + <mkdir dir="build/ant" /> + <ivy:compile ecj="true" srcdir="src/ant" includes="**/SimpleTestFormatter.java" destdir="build/ant" source="1.6" target="1.6"> + <classpath refid="cp.build" /> + <classpath refid="cp.test" /> + </ivy:compile> + </target> + <target name="test.compile" depends="deps, compile" description="compiles the tests" unless="skip.tests"> <mkdir dir="build/tests" /> <ivy:compile destdir="build/teststubs" source="1.6" target="1.6" ecj="true" nowarn="true"> @@ -33,6 +41,7 @@ This buildfile is part of projectlombok.org. It takes care of compiling and runn <bootclasspath path="${jdk6-rt.loc}" /> <classpath refid="cp.test" /> <classpath refid="cp.eclipse-oxygen" /> + <classpath refid="cp.javac6" /> <classpath refid="packing.basedirs.path" /> <classpath path="build/tests" /> <src path="test/core/src" /> @@ -46,7 +55,7 @@ This buildfile is part of projectlombok.org. It takes care of compiling and runn </ivy:compile> </target> - <target name="test.ecj11" depends="deps, dist" description="Runs a few ecj-specific tests" unless="skip.tests"> + <target name="test.ecj11.call" depends="deps, dist" description="Runs a few ecj-specific tests" unless="skip.tests"> <java jar="lib/ecj11/org.eclipse.jdt-ecj.jar" fork="true" failonerror="true"> <jvmarg value="-javaagent:dist/lombok.jar=ecj" /> <arg line="-source 1.6 -target 1.6 -cp dist/lombok.jar test/ecj/SimpleTest.java" /> @@ -54,54 +63,42 @@ This buildfile is part of projectlombok.org. It takes care of compiling and runn <echo>run ecj11 with a test file to confirm agent injection works: OK</echo> </target> - <property name="test.addopens.raw"> - --add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED - --add-opens jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED - --add-opens jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED - --add-opens jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED - --add-opens jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED - --add-opens jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED - --add-opens jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED - --add-opens jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED - </property> <property name="test.limitmodules">--limit-modules java.base,jdk.unsupported</property> - <loadresource property="test.addopens"> - <propertyresource name="test.addopens.raw" /> - <filterchain><tokenfilter> - <filetokenizer /> - <replaceregex pattern="\s+" replace=" " flags="g" /> - </tokenfilter></filterchain> - </loadresource> - - <target name="test.javac6" depends="test.compile" description="runs the tests on your default VM, using javac6 as underlying compiler"> + <target name="test.javac6" depends="test.formatter.compile, test.compile" description="runs the tests on your default VM, using javac6 as underlying compiler"> <echo>Running TestJavac on JVM${ant.java.version}, with lowest supported javac: 1.6.</echo> <junit haltonfailure="yes" fork="true" forkmode="once"> + <formatter classname="lombok.ant.SimpleTestFormatter" usefile="false" unless="tests.quiet" /> + <classpath location="build/ant" /> <jvmarg value="-Xbootclasspath/a:${jdk6-rt.loc}" /> <jvmarg line="${test.limitmodules}" /> <jvmarg value="-Ddelombok.bootclasspath=${jdk6-rt.loc}" /> - <formatter type="plain" usefile="false" unless="tests.quiet" /> + <jvmarg value="-Dsun.boot.class.path=${jdk6-rt.loc}" /> <classpath refid="cp.test" /> <classpath refid="cp.stripe" /> <classpath refid="cp.javac6" /> <classpath refid="packing.basedirs.path" /> <classpath location="build/tests" /> + <classpath location="build/teststubs" /> <test name="lombok.TestJavac" /> </junit> </target> - <target name="test.javac8" depends="test.compile, deps.jdk8-runtime" description="runs the tests on your default VM, using javac8 as underlying compiler"> + <target name="test.javac8" depends="test.formatter.compile, test.compile, deps.jdk8-runtime" description="runs the tests on your default VM, using javac8 as underlying compiler"> <echo>Running TestJavac on JVM${ant.java.version}, with javac: 1.8.</echo> <junit haltonfailure="yes" fork="true" forkmode="once"> + <formatter classname="lombok.ant.SimpleTestFormatter" usefile="false" unless="tests.quiet" /> <jvmarg value="-Xbootclasspath/a:${jdk8-rt.loc}" /> <jvmarg line="${test.limitmodules}" /> <jvmarg value="-Ddelombok.bootclasspath=${jdk8-rt.loc}" /> - <formatter type="plain" usefile="false" unless="tests.quiet" /> + <jvmarg value="-Dsun.boot.class.path=${jdk8-rt.loc}" /> + <classpath location="build/ant" /> <classpath refid="cp.test" /> <classpath refid="cp.stripe" /> <classpath refid="cp.javac8" /> <classpath refid="packing.basedirs.path" /> <classpath location="build/tests" /> + <classpath location="build/teststubs" /> <test name="lombok.TestJavac" /> </junit> </target> @@ -113,8 +110,8 @@ This buildfile is part of projectlombok.org. It takes care of compiling and runn <echo>Running TestJavac with JVM ${jvm.loc.@{version}}.</echo> <junit haltonfailure="yes" fork="true" forkmode="once" jvm="${jvm.loc.@{version}}/bin/${exe.java}"> - <jvmarg line="${test.addopens}" /> - <formatter type="plain" usefile="false" unless="tests.quiet" /> + <formatter classname="lombok.ant.SimpleTestFormatter" usefile="false" unless="tests.quiet" /> + <classpath location="build/ant" /> <classpath refid="cp.test" /> <classpath refid="cp.stripe" /> <classpath refid="packing.basedirs.path" /> @@ -125,19 +122,25 @@ This buildfile is part of projectlombok.org. It takes care of compiling and runn </sequential> </macrodef> - <target name="test.javac11" depends="test.compile" description="runs the tests on your default VM, using javac11 as underlying compiler"> + <target name="test.javac11" depends="test.formatter.compile, test.compile" description="runs the tests on your default VM, using javac11 as underlying compiler"> <test.javacX version="11" /> </target> - <target name="test.javac14" depends="test.compile" description="runs the tests on your default VM, using javac14 as underlying compiler"> + <!-- For non-LTS versions, feel free to aggressively update these to the current non-LTS openjdk version, and delete them once they roll out of the 6month window. --> + + <target name="test.javac14" depends="test.formatter.compile, test.compile" description="runs the tests on your default VM, using javac14 as underlying compiler"> <test.javacX version="14" /> </target> - <target name="test.javacCurrent" depends="test.compile" description="runs the tests on your default VM, using its javac as underlying compiler"> + <target name="test.javac16" depends="test.formatter.compile, test.compile" description="runs the tests on your default VM, using javac16 as underlying compiler"> + <test.javacX version="16" /> + </target> + + <target name="test.javacCurrent" depends="test.formatter.compile, test.compile" description="runs the tests on your default VM, using its javac as underlying compiler"> <echo>Running TestJavac on JVM${ant.java.version}, with the javac built into your VM distributon.</echo> <junit haltonfailure="yes" fork="true" forkmode="once"> - <jvmarg line="${test.addopens}" /> - <formatter type="plain" usefile="false" unless="tests.quiet" /> + <formatter classname="lombok.ant.SimpleTestFormatter" usefile="false" unless="tests.quiet" /> + <classpath location="build/ant" /> <classpath refid="cp.test" /> <classpath refid="cp.stripe" /> <classpath refid="packing.basedirs.path" /> @@ -152,30 +155,67 @@ This buildfile is part of projectlombok.org. It takes care of compiling and runn <sequential> <echo>Running TestEclipse on eclipse-@{version} on JVM${ant.java.version}.</echo> <junit haltonfailure="yes" fork="true" forkmode="once"> + <formatter classname="lombok.ant.SimpleTestFormatter" usefile="false" unless="tests.quiet" /> <jvmarg value="-Xbootclasspath/a:${jdk8-rt.loc}" /> <jvmarg value="-Ddelombok.bootclasspath=${jdk8-rt.loc}" /> <jvmarg value="-javaagent:dist/lombok.jar" /> - <jvmarg line="${test.addopens}" /> - <formatter type="plain" usefile="false" unless="tests.quiet" /> + <classpath location="build/ant" /> <classpath refid="cp.test" /> <classpath refid="cp.stripe" /> <classpath refid="cp.eclipse-@{version}" /> <classpath refid="packing.basedirs.path" /> <classpath location="build/tests" /> + <classpath location="build/teststubs" /> <test name="lombok.TestEclipse" /> </junit> </sequential> </macrodef> - <target name="test.eclipse-oxygen" depends="test.compile" description="runs the tests on your default VM, testing the oxygen release of eclipse"> + <target name="test.eclipse-oxygen" depends="test.formatter.compile, test.compile" description="runs the tests on your default VM, testing the oxygen release of eclipse"> <test.eclipse-X version="oxygen" /> </target> - <target name="test.eclipse-202006" depends="test.compile" description="runs the tests on your default VM, testing the 2020-03 release of eclipse"> + <target name="test.eclipse-202006" depends="test.formatter.compile, test.compile" description="runs the tests on your default VM, testing the 2020-03 release of eclipse"> <fetchdep.eclipse version="202006" /> <test.eclipse-X version="202006" /> </target> + <macrodef name="test.ecj-X"> + <attribute name="version" /> + <sequential> + <echo>Running TestEclipse on ecj-@{version} on JVM${ant.java.version}.</echo> + <junit haltonfailure="yes" fork="true" forkmode="once"> + <formatter classname="lombok.ant.SimpleTestFormatter" usefile="false" unless="tests.quiet" /> + <jvmarg value="-Xbootclasspath/a:${jdk8-rt.loc}" /> + <jvmarg value="-Ddelombok.bootclasspath=${jdk8-rt.loc}" /> + <jvmarg value="-javaagent:dist/lombok.jar" /> + <classpath location="build/ant" /> + <classpath refid="cp.test" /> + <classpath refid="cp.stripe" /> + <classpath refid="cp.ecj@{version}" /> + <classpath refid="packing.basedirs.path" /> + <classpath location="build/tests" /> + <classpath location="build/teststubs" /> + <test name="lombok.TestEclipse" /> + </junit> + </sequential> + </macrodef> + + <target name="test.ecj11" depends="test.formatter.compile, test.compile" description="runs the tests on your default VM, testing the ecj11 release"> + <fetchdep.ecj version="11" /> + <test.ecj-X version="11" /> + </target> + + <target name="test.ecj14" depends="test.formatter.compile, test.compile" description="runs the tests on your default VM, testing the ecj11 release"> + <fetchdep.ecj version="14" /> + <test.ecj-X version="14" /> + </target> + + <target name="test.ecj16" depends="test.formatter.compile, test.compile" description="runs the tests on your default VM, testing the ecj11 release"> + <fetchdep.ecj version="16" /> + <test.ecj-X version="16" /> + </target> + <target name="test" depends="test.javacCurrent, test.eclipse-202006" description="runs the tests against the default JVM, javac, and eclipse" /> <target name="test.broad" depends="test.javac8, test.javac14, test.eclipse-oxygen, test.eclipse-202006" description="runs the tests against the default JVM, javac, and eclipse" /> </project> diff --git a/buildScripts/vm-finder.ant.xml b/buildScripts/vm-finder.ant.xml index a15d8ed0..2a33b2b8 100644 --- a/buildScripts/vm-finder.ant.xml +++ b/buildScripts/vm-finder.ant.xml @@ -60,7 +60,8 @@ and rerun the build; this build is capable of finding VMs automatically on many <fail unless="find-vm.version">Set property find-vm.version first</fail> <local name="java_home.answer" /> <local name="java_home.result" /> - <exec executable="${exe.java_home}" errorproperty="discard" outputproperty="java_home.answer" failifexecutionfails="false" resultproperty="java_home.result"> + <exec newenvironment="true" executable="${exe.java_home}" errorproperty="discard" outputproperty="java_home.answer" failifexecutionfails="false" resultproperty="java_home.result"> + <env key="floobargle" value="FOO" /> <!-- we do not want JAVA_HOME to be set. This requires newenvironment="true" AND some sort of env value --> <arg value="-v" /> <arg value="${find-vm.version}" /> </exec> diff --git a/buildScripts/website.ant.xml b/buildScripts/website.ant.xml index 63ac2e8d..1fc58fd4 100644 --- a/buildScripts/website.ant.xml +++ b/buildScripts/website.ant.xml @@ -57,7 +57,7 @@ such as applying the templates to produce the website, converting the changelog <echo>Live full versionstring : ${lombok.fullversion.live}</echo> </target> - <target name="changelog.build" depends="version, deps, compile.support" description="Turns the current changelog (doc/changelog.txt) into HTML"> + <target name="changelog.build" depends="version, deps, compile.support" description="Turns the current changelog (doc/changelog.markdown) into HTML"> <mkdir dir="build/website" /> <java classname="lombok.website.WebsiteMaker" failonerror="true"> <classpath> diff --git a/doc/changelog.markdown b/doc/changelog.markdown index 8fd5b293..506f46d7 100644 --- a/doc/changelog.markdown +++ b/doc/changelog.markdown @@ -1,12 +1,19 @@ Lombok Changelog ---------------- -### v1.18.17 "Edgy Guinea Pig" +### v1.18.19 "Edgy Guinea Pig" +* PLATFORM: JDK16 support added. [Issue #2681](https://github.com/mplushnikov/lombok-intellij-plugin/issues/2681). +* PLATFORM: All lombok features updated to act in a sane fashion with JDK16's _record_ feature. In particular, you can annotate record components with `@NonNull` to have lombok add null checks to your compact constructor (which will be created if need be). +* BUGFIX: Trying to use a lambda expression as parameter to an `@ExtensionMethod` did not work. [Issue #2741](https://github.com/rzwitserloot/lombok/issues/2741). (by __@Rawi01__). +* BUGFIX: `@SuperBuilder` with an existing constructor caused issues in eclipse. [Issue #2704](https://github.com/rzwitserloot/lombok/issues/2704). (by [@JanRieke](https://github.com/rzwitserloot/lombok/pull/2770)). +* BUGFIX: Using `@SuperBuilder` with a handwritten builder class caused issues. [Issue #2701](https://github.com/rzwitserloot/lombok/issues/2701). (by [@JanRieke](https://github.com/rzwitserloot/lombok/pull/2772)). +* POTENTIAL BUGFIX: lombok + errorprone could cause `IllegalArgumentException` if using the `MissingSummary` bug pattern. [Issue #2730](https://github.com/rzwitserloot/lombok/issues/2730). + +### v1.18.18 (January 28th, 2021) * BUGFIX: Various tools using ecj under the hood (including intellij) could cause corrupt class files to be generated. [PR #2637](https://github.com/rzwitserloot/lombok/pull/2637), [lombok-intellij-plugin issue #969](https://github.com/mplushnikov/lombok-intellij-plugin/issues/969). -* BUGFIX: Netbeans would not work with 1.18.16 anymore. [Issue #2612](https://github.com/rzwitserloot/lombok/issues/2612) +* BUGFIX: Netbeans would not work with 1.18.16 anymore. [Issue #2612](https://github.com/rzwitserloot/lombok/issues/2612). * BUGFIX: `@ExtensionMethod` support in ecj improved when generics are involved. [Issue #2648](https://github.com/rzwitserloot/lombok/issues/2648), [PR #2658](https://github.com/rzwitserloot/lombok/pull/2658) thanks to __@Rawi01__. * PLATFORM: using `lombok.config` files when compiling with sbt 1.4 now works again. [Issue #2645](https://github.com/rzwitserloot/lombok/issues/2645) -* (potential) BUGFIX: Using lombok with Maven Tycho now works. With assistance from [Rabea Gransberger](https://github.com/rgra). [Issue #285](https://github.com/rzwitserloot/lombok/issues/285) __UPDATE: This doesn't quite work yet, still investigating.__ ### v1.18.16 (October 15th, 2020) * BUGFIX: Version 1.18.14 could not be installed in Eclipse, it would break Eclipse. diff --git a/docker/ant/Dockerfile b/docker/ant/Dockerfile index 57a2faf9..c38c6541 100644 --- a/docker/ant/Dockerfile +++ b/docker/ant/Dockerfile @@ -1,6 +1,6 @@ FROM ubuntu:18.04 as downloader -ARG jdk=13 +ARG jdk=16 ADD provision/jdk/java-${jdk}.sh provision/jdk/java-${jdk}.sh RUN provision/jdk/java-${jdk}.sh @@ -22,7 +22,7 @@ WORKDIR workspace ADD shared/ ./ -ARG jdk=13 +ARG jdk=16 ADD ant/files/jdk-${jdk} ./ COPY --from=downloader /lombok.jar /workspace/classpath/lombok.jar diff --git a/docker/ant/files/jdk-16/classpath/build.xml b/docker/ant/files/jdk-16/classpath/build.xml new file mode 100644 index 00000000..01decd3f --- /dev/null +++ b/docker/ant/files/jdk-16/classpath/build.xml @@ -0,0 +1,35 @@ +<project name="example" default="dist" basedir="."> + <property name="src" location="src/main/java"/> + <property name="build" location="build"/> + <property name="dist" location="dist"/> + <property name="build.sysclasspath" value="ignore"/> + + <target name="init"> + <tstamp/> + <mkdir dir="${build}"/> + </target> + + <target name="compile" depends="init" description="compile the source"> + <javac classpath="lombok.jar" modulepath="lombok.jar" srcdir="${src}" destdir="${build}" fork="true"> + <compilerarg value="-J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED"/> + <compilerarg value="-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED"/> + <compilerarg value="-J--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED"/> + <compilerarg value="-J--add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED"/> + <compilerarg value="-J--add-opens=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED"/> + <compilerarg value="-J--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED"/> + <compilerarg value="-J--add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED"/> + <compilerarg value="-J--add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED"/> + <compilerarg value="-J--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"/> + </javac> + </target> + + <target name="dist" depends="compile" description="generate the distribution"> + <mkdir dir="${dist}/lib"/> + <jar jarfile="${dist}/lib/example-${DSTAMP}.jar" basedir="${build}"/> + </target> + + <target name="clean" description="clean up"> + <delete dir="${build}"/> + <delete dir="${dist}"/> + </target> +</project>
\ No newline at end of file diff --git a/docker/ant/files/jdk-16/modules/build.xml b/docker/ant/files/jdk-16/modules/build.xml new file mode 100644 index 00000000..3f181ed9 --- /dev/null +++ b/docker/ant/files/jdk-16/modules/build.xml @@ -0,0 +1,35 @@ +<project name="example" default="dist" basedir="."> + <property name="src" location="src/main/java"/> + <property name="build" location="build"/> + <property name="dist" location="dist"/> + <property name="build.sysclasspath" value="ignore"/> + + <target name="init"> + <tstamp/> + <mkdir dir="${build}"/> + </target> + + <target name="compile" depends="init" description="compile the source"> + <javac classpath="lombok.jar" srcdir="${src}" destdir="${build}" fork="true"> + <compilerarg value="-J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED"/> + <compilerarg value="-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED"/> + <compilerarg value="-J--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED"/> + <compilerarg value="-J--add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED"/> + <compilerarg value="-J--add-opens=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED"/> + <compilerarg value="-J--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED"/> + <compilerarg value="-J--add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED"/> + <compilerarg value="-J--add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED"/> + <compilerarg value="-J--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"/> + </javac> + </target> + + <target name="dist" depends="compile" description="generate the distribution"> + <mkdir dir="${dist}/lib"/> + <jar jarfile="${dist}/lib/example-${DSTAMP}.jar" basedir="${build}"/> + </target> + + <target name="clean" description="clean up"> + <delete dir="${build}"/> + <delete dir="${dist}"/> + </target> +</project>
\ No newline at end of file diff --git a/docker/ant/readme.md b/docker/ant/readme.md index 7dce84e3..cfe90774 100644 --- a/docker/ant/readme.md +++ b/docker/ant/readme.md @@ -15,21 +15,22 @@ The ant version to be used. Supported values: (To be executed from the `<lombokhome>/docker` directory) ``` -docker build -t lombok-ant-jdk13 -f ant/Dockerfile . +docker build -t lombok-ant-jdk16 -f ant/Dockerfile . -docker build -t lombok-ant-jdk13 --build-arg lombokjar=lombok-1.16.20.jar -f ant/Dockerfile . +docker build -t lombok-ant-jdk16 --build-arg lombokjar=lombok-1.18.20.jar -f ant/Dockerfile . ``` ## Example run commands: ``` -docker run -it lombok-ant-jdk13 +docker run -it lombok-ant-jdk16 -docker run --rm -it -v /<lombokhome>/dist/lombok.jar:/workspace/lombok.jar lombok-ant-jdk13 +docker run --rm -it -v /<lombokhome>/dist/lombok.jar:/workspace/lombok.jar lombok-ant-jdk16 ``` ## Example container commands: ``` +cd classpath ant dist ``` diff --git a/docker/bazel/Dockerfile b/docker/bazel/Dockerfile index edc5e6fd..06149b1e 100644 --- a/docker/bazel/Dockerfile +++ b/docker/bazel/Dockerfile @@ -1,6 +1,6 @@ FROM ubuntu:18.04 as downloader -ARG jdk=13 +ARG jdk=16 ADD provision/jdk/java-${jdk}.sh provision/jdk/java-${jdk}.sh RUN provision/jdk/java-${jdk}.sh @@ -27,7 +27,7 @@ ADD bazel/files/ ./ COPY --from=downloader /lombok.jar /workspace/classpath/lombok.jar COPY --from=downloader /lombok.jar /workspace/modules/lombok.jar -ARG jdk=13 +ARG jdk=16 ENV JDK_VERSION=${jdk} ENV JAVA_HOME=/opt/jdk ENV BAZEL_HOME=/opt/bazel diff --git a/docker/gradle/Dockerfile b/docker/gradle/Dockerfile index 42c4775f..de85ca6f 100644 --- a/docker/gradle/Dockerfile +++ b/docker/gradle/Dockerfile @@ -1,6 +1,6 @@ FROM ubuntu:18.04 as downloader
-ARG jdk=13
+ARG jdk=16
ADD provision/jdk/java-${jdk}.sh provision/jdk/java-${jdk}.sh
RUN provision/jdk/java-${jdk}.sh
@@ -26,7 +26,7 @@ ADD gradle/files/ ./ COPY --from=downloader /lombok.jar /workspace/classpath/lombok.jar
COPY --from=downloader /lombok.jar /workspace/modules/lombok.jar
-ARG jdk=13
+ARG jdk=16
ENV JDK_VERSION=${jdk}
ENV JAVA_HOME=/opt/jdk
ENV GRADLE_HOME=/opt/gradle/gradle
diff --git a/docker/maven/Dockerfile b/docker/maven/Dockerfile index 32ebbe48..7d30dbf3 100644 --- a/docker/maven/Dockerfile +++ b/docker/maven/Dockerfile @@ -1,6 +1,6 @@ FROM ubuntu:18.04 as downloader
-ARG jdk=13
+ARG jdk=16
ADD provision/jdk/java-${jdk}.sh provision/jdk/java-${jdk}.sh
RUN provision/jdk/java-${jdk}.sh
@@ -22,7 +22,7 @@ WORKDIR workspace ADD shared/ ./
-ARG jdk=13
+ARG jdk=16
ADD maven/files/jdk-${jdk} ./
COPY --from=downloader /lombok.jar /workspace/classpath/lombok.jar
diff --git a/docker/provision/jdk/java-16.sh b/docker/provision/jdk/java-16.sh new file mode 100644 index 00000000..339bc11e --- /dev/null +++ b/docker/provision/jdk/java-16.sh @@ -0,0 +1,4 @@ +apt-get update && apt-get install -y wget +wget https://github.com/AdoptOpenJDK/openjdk16-binaries/releases/download/jdk-16%2B36/OpenJDK16-jdk_x64_linux_hotspot_16_36.tar.gz -O jdk.tar.gz +tar -xzf jdk.tar.gz -C /opt/ +mv /opt/jdk-16+36 /opt/jdk
\ No newline at end of file diff --git a/src/ant/lombok/ant/SimpleTestFormatter.java b/src/ant/lombok/ant/SimpleTestFormatter.java new file mode 100644 index 00000000..e137d822 --- /dev/null +++ b/src/ant/lombok/ant/SimpleTestFormatter.java @@ -0,0 +1,87 @@ +package lombok.ant; + +import java.io.OutputStream; +import java.io.PrintStream; +import java.util.Arrays; + +import junit.framework.AssertionFailedError; +import junit.framework.Test; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter; +import org.apache.tools.ant.taskdefs.optional.junit.JUnitTest; + +public class SimpleTestFormatter implements JUnitResultFormatter { + private PrintStream out = System.out; + private Test lastMarked = null; + + @Override + public void addError(Test test, Throwable error) { + lastMarked = test; + logResult(test, "ERR"); + printThrowable(error, false, 2); + } + + private void printThrowable(Throwable throwable, boolean cause, int indent) { + String msg = throwable.getMessage(); + char[] prefixChars = new char[indent]; + Arrays.fill(prefixChars, ' '); + String prefix = new String(prefixChars); + + if (msg == null || msg.isEmpty()) { + out.println(prefix + (cause ? "Caused by " : "") + throwable.getClass()); + } else { + out.println(prefix + (cause ? "Caused by " : "") + throwable.getClass() + ": " + msg); + } + StackTraceElement[] elems = throwable.getStackTrace(); + if (elems != null) for (StackTraceElement elem : elems) { + out.println(prefix + " " + elem); + } + + Throwable c = throwable.getCause(); + if (c != null) printThrowable(c, true, indent + 2); + } + + @Override + public void addFailure(Test test, AssertionFailedError failure) { + lastMarked = test; + logResult(test, "FAIL"); + out.println(failure.getMessage()); + } + + @Override + public void endTest(Test test) { + if (test != lastMarked) logResult(test, "PASS"); + } + + @Override + public void startTest(Test test) { } + + @Override + public void endTestSuite(JUnitTest testSuite) throws BuildException { } + + @Override + public void setOutput(OutputStream out) { + this.out = new PrintStream(out); + } + + @Override + public void setSystemError(String msg) { + if (msg.trim().isEmpty()) return; + out.println(msg); + } + + @Override + public void setSystemOutput(String msg) { + if (msg.trim().isEmpty()) return; + out.println(msg); + } + + @Override + public void startTestSuite(JUnitTest testSuite) throws BuildException { } + + private void logResult(Test test, String result) { + out.println("[" + result + "] " + String.valueOf(test)); + out.flush(); + } +} diff --git a/src/core/lombok/ConfigurationKeys.java b/src/core/lombok/ConfigurationKeys.java index 01a4b576..ba66649b 100644 --- a/src/core/lombok/ConfigurationKeys.java +++ b/src/core/lombok/ConfigurationKeys.java @@ -274,7 +274,7 @@ public class ConfigurationKeys { * * For any class with an {@code @ToString} annotation which extends a class other than {@code java.lang.Object}, should a call to superclass's implementation of {@code toString} be included in the generated method? (Default = skip) */ - public static final ConfigurationKey<CallSuperType> TO_STRING_CALL_SUPER = new ConfigurationKey<CallSuperType>("lombok.toString.callSuper", "When generating toString for classes that extend something (other than Object), either automatically take into account superclass implementation (call), or don't (skip), or warn and don't (warn). (default = warn).") {}; + public static final ConfigurationKey<CallSuperType> TO_STRING_CALL_SUPER = new ConfigurationKey<CallSuperType>("lombok.toString.callSuper", "When generating toString for classes that extend something (other than Object), either automatically take into account superclass implementation (call), or don't (skip), or warn and don't (warn). (default = skip).") {}; /** * lombok configuration: {@code lombok.toString.flagUsage} = {@code WARNING} | {@code ERROR}. diff --git a/src/core/lombok/bytecode/AsmUtil.java b/src/core/lombok/bytecode/AsmUtil.java index 42bf9700..fc2533e5 100644 --- a/src/core/lombok/bytecode/AsmUtil.java +++ b/src/core/lombok/bytecode/AsmUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2014 The Project Lombok Authors. + * Copyright (C) 2010-2021 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 @@ -37,7 +37,7 @@ class AsmUtil { ClassReader reader = new ClassReader(byteCode); ClassWriter writer = new FixedClassWriter(reader, 0); - ClassVisitor visitor = new ClassVisitor(Opcodes.ASM7, writer) { + ClassVisitor visitor = new ClassVisitor(Opcodes.ASM9, writer) { @Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { return new JSRInlinerAdapter(super.visitMethod(access, name, desc, signature, exceptions), access, name, desc, signature, exceptions); } diff --git a/src/core/lombok/bytecode/PoolConstantsApp.java b/src/core/lombok/bytecode/PoolConstantsApp.java index c2120cc0..65b51f17 100644 --- a/src/core/lombok/bytecode/PoolConstantsApp.java +++ b/src/core/lombok/bytecode/PoolConstantsApp.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012 The Project Lombok Authors. + * Copyright (C) 2012-2021 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 @@ -26,8 +26,7 @@ import java.util.ArrayList; import java.util.List; import lombok.core.LombokApp; - -import org.mangosdk.spi.ProviderFor; +import lombok.spi.Provides; import com.zwitserloot.cmdreader.CmdReader; import com.zwitserloot.cmdreader.Description; @@ -36,9 +35,8 @@ import com.zwitserloot.cmdreader.Mandatory; import com.zwitserloot.cmdreader.Sequential; import com.zwitserloot.cmdreader.Shorthand; -@ProviderFor(LombokApp.class) +@Provides public class PoolConstantsApp extends LombokApp { - @Override public String getAppName() { return "Xprintpool"; } diff --git a/src/core/lombok/bytecode/PostCompilerApp.java b/src/core/lombok/bytecode/PostCompilerApp.java index 5f49bd81..7f2237c0 100644 --- a/src/core/lombok/bytecode/PostCompilerApp.java +++ b/src/core/lombok/bytecode/PostCompilerApp.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 The Project Lombok Authors. + * Copyright (C) 2010-2021 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 @@ -33,8 +33,7 @@ import java.util.List; import lombok.core.DiagnosticsReceiver; import lombok.core.LombokApp; import lombok.core.PostCompiler; - -import org.mangosdk.spi.ProviderFor; +import lombok.spi.Provides; import com.zwitserloot.cmdreader.CmdReader; import com.zwitserloot.cmdreader.Description; @@ -43,7 +42,7 @@ import com.zwitserloot.cmdreader.Mandatory; import com.zwitserloot.cmdreader.Sequential; import com.zwitserloot.cmdreader.Shorthand; -@ProviderFor(LombokApp.class) +@Provides public class PostCompilerApp extends LombokApp { @Override public List<String> getAppAliases() { return Arrays.asList("post", "postcompile"); diff --git a/src/core/lombok/bytecode/PreventNullAnalysisRemover.java b/src/core/lombok/bytecode/PreventNullAnalysisRemover.java index 20572e22..8ae7af5b 100644 --- a/src/core/lombok/bytecode/PreventNullAnalysisRemover.java +++ b/src/core/lombok/bytecode/PreventNullAnalysisRemover.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2014 The Project Lombok Authors. + * Copyright (C) 2010-2021 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 @@ -27,15 +27,15 @@ import java.util.concurrent.atomic.AtomicBoolean; import lombok.core.DiagnosticsReceiver; import lombok.core.PostCompilerTransformation; +import lombok.spi.Provides; -import org.mangosdk.spi.ProviderFor; import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Opcodes; -@ProviderFor(PostCompilerTransformation.class) +@Provides public class PreventNullAnalysisRemover implements PostCompilerTransformation { @Override public byte[] applyTransformations(byte[] original, String fileName, DiagnosticsReceiver diagnostics) { @@ -50,7 +50,7 @@ public class PreventNullAnalysisRemover implements PostCompilerTransformation { class PreventNullAnalysisVisitor extends MethodVisitor { PreventNullAnalysisVisitor(MethodVisitor mv) { - super(Opcodes.ASM7, mv); + super(Opcodes.ASM9, mv); } @Override public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) { @@ -68,7 +68,7 @@ public class PreventNullAnalysisRemover implements PostCompilerTransformation { } } - reader.accept(new ClassVisitor(Opcodes.ASM7, writer) { + reader.accept(new ClassVisitor(Opcodes.ASM9, writer) { @Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { return new PreventNullAnalysisVisitor(super.visitMethod(access, name, desc, signature, exceptions)); } diff --git a/src/core/lombok/bytecode/SneakyThrowsRemover.java b/src/core/lombok/bytecode/SneakyThrowsRemover.java index 037cb109..ea1c3cec 100644 --- a/src/core/lombok/bytecode/SneakyThrowsRemover.java +++ b/src/core/lombok/bytecode/SneakyThrowsRemover.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2014 The Project Lombok Authors. + * Copyright (C) 2010-2021 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 @@ -27,8 +27,8 @@ import java.util.concurrent.atomic.AtomicBoolean; import lombok.core.DiagnosticsReceiver; import lombok.core.PostCompilerTransformation; +import lombok.spi.Provides; -import org.mangosdk.spi.ProviderFor; import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.ClassWriter; @@ -37,7 +37,7 @@ import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Opcodes; -@ProviderFor(PostCompilerTransformation.class) +@Provides public class SneakyThrowsRemover implements PostCompilerTransformation { @Override public byte[] applyTransformations(byte[] original, String fileName, final DiagnosticsReceiver diagnostics) { @@ -52,7 +52,7 @@ public class SneakyThrowsRemover implements PostCompilerTransformation { class SneakyThrowsRemoverVisitor extends MethodVisitor { SneakyThrowsRemoverVisitor(MethodVisitor mv) { - super(Opcodes.ASM7, mv); + super(Opcodes.ASM9, mv); } private boolean methodInsnQueued = false; @@ -177,7 +177,7 @@ public class SneakyThrowsRemover implements PostCompilerTransformation { } } - reader.accept(new ClassVisitor(Opcodes.ASM7, writer) { + reader.accept(new ClassVisitor(Opcodes.ASM9, writer) { @Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { return new SneakyThrowsRemoverVisitor(super.visitMethod(access, name, desc, signature, exceptions)); } diff --git a/src/core/lombok/core/AnnotationProcessor.java b/src/core/lombok/core/AnnotationProcessor.java index c9171284..28d16298 100644 --- a/src/core/lombok/core/AnnotationProcessor.java +++ b/src/core/lombok/core/AnnotationProcessor.java @@ -69,7 +69,7 @@ public class AnnotationProcessor extends AbstractProcessor { private final List<String> delayedWarnings = new ArrayList<String>(); /** - * This method is a simplified version of {@link lombok.javac.apt.LombokProcessor.getJavacProcessingEnvironment} + * This method is a simplified version of {@link lombok.javac.apt.LombokProcessor#getJavacProcessingEnvironment} * It simply returns the processing environment, but in case of gradle incremental compilation, * the delegate ProcessingEnvironment of the gradle wrapper is returned. */ @@ -120,7 +120,7 @@ public class AnnotationProcessor extends AbstractProcessor { } /** - * InteliJ >= 2020.3 + * IntelliJ IDEA >= 2020.3 */ private static Object tryGetProxyDelegateToField(Class<?> delegateClass, Object instance) { try { @@ -219,8 +219,12 @@ public class AnnotationProcessor extends AbstractProcessor { if (supported.length() > 0) supported.append(", "); supported.append(proc.getName()); } - procEnv.getMessager().printMessage(Kind.WARNING, String.format("You aren't using a compiler supported by lombok, so lombok will not work and has been disabled.\n" + + if (procEnv.getClass().getName().equals("com.google.turbine.processing.TurbineProcessingEnvironment")) { + procEnv.getMessager().printMessage(Kind.ERROR, String.format("Turbine is not currently supported by lombok.")); + } else { + procEnv.getMessager().printMessage(Kind.WARNING, String.format("You aren't using a compiler supported by lombok, so lombok will not work and has been disabled.\n" + "Your processor is: %s\nLombok supports: %s", procEnv.getClass().getName(), supported)); + } } } @@ -257,6 +261,6 @@ public class AnnotationProcessor extends AbstractProcessor { * We just return the latest version of whatever JDK we run on. Stupid? Yeah, but it's either that or warnings on all versions but 1. Blame Joe. */ @Override public SourceVersion getSupportedSourceVersion() { - return SourceVersion.values()[SourceVersion.values().length - 1]; + return SourceVersion.latest(); } } diff --git a/src/core/lombok/core/LombokNode.java b/src/core/lombok/core/LombokNode.java index abfc66a6..34273a86 100644 --- a/src/core/lombok/core/LombokNode.java +++ b/src/core/lombok/core/LombokNode.java @@ -160,18 +160,16 @@ public abstract class LombokNode<A extends AST<A, L, N>, L extends LombokNode<A, List<L> fields = new ArrayList<L>(); for (L potentialField : type.down()) { if (potentialField.getKind() != Kind.FIELD) continue; - if (fieldContainsAnnotation(potentialField.get(), get())) fields.add(potentialField); + for (L child : potentialField.down()) { + if (child.getKind() != Kind.ANNOTATION) continue; + if (child.get() == get()) fields.add(potentialField); + } } return fields; } /** - * Return {@code true} if the annotation is attached to the field. - */ - protected abstract boolean fieldContainsAnnotation(N field, N annotation); - - /** * Returns the direct parent node in the AST tree of this node. For example, a local variable declaration's * direct parent can be e.g. an If block, but its {@code up()} {@code LombokNode} is the {@code Method} that contains it. */ diff --git a/src/core/lombok/core/Main.java b/src/core/lombok/core/Main.java index 47afaefd..2c9d1dcb 100644 --- a/src/core/lombok/core/Main.java +++ b/src/core/lombok/core/Main.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2018 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -30,7 +30,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; -import org.mangosdk.spi.ProviderFor; +import lombok.spi.Provides; public class Main { private static final Collection<?> HELP_SWITCHES = Collections.unmodifiableList(Arrays.asList( @@ -46,7 +46,7 @@ public class Main { } } - @ProviderFor(LombokApp.class) + @Provides public static class VersionApp extends LombokApp { @Override public String getAppName() { return "version"; @@ -66,7 +66,7 @@ public class Main { } } - @ProviderFor(LombokApp.class) + @Provides public static class LicenseApp extends LombokApp { @Override public String getAppName() { return "license"; diff --git a/src/core/lombok/core/PublicApiCreatorApp.java b/src/core/lombok/core/PublicApiCreatorApp.java index c1430c24..f45808fe 100644 --- a/src/core/lombok/core/PublicApiCreatorApp.java +++ b/src/core/lombok/core/PublicApiCreatorApp.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012 The Project Lombok Authors. + * Copyright (C) 2012-2021 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 @@ -36,10 +36,9 @@ import java.util.zip.ZipEntry; import lombok.Lombok; import lombok.patcher.ClassRootFinder; +import lombok.spi.Provides; -import org.mangosdk.spi.ProviderFor; - -@ProviderFor(LombokApp.class) +@Provides public class PublicApiCreatorApp extends LombokApp { @Override public String getAppName() { return "publicApi"; diff --git a/src/core/lombok/core/Version.java b/src/core/lombok/core/Version.java index 225e02f2..af0941bb 100644 --- a/src/core/lombok/core/Version.java +++ b/src/core/lombok/core/Version.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2020 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -30,7 +30,7 @@ public class Version { // ** CAREFUL ** - this class must always compile with 0 dependencies (it must not refer to any other sources or libraries). // Note: In 'X.Y.Z', if Z is odd, its a snapshot build built from the repository, so many different 0.10.3 versions can exist, for example. // Official builds always end in an even number. (Since 0.10.2). - private static final String VERSION = "1.18.17"; + private static final String VERSION = "1.18.19"; private static final String RELEASE_NAME = "Edgy Guinea Pig"; // private static final String RELEASE_NAME = "Envious Ferret"; diff --git a/src/core/lombok/core/configuration/ConfigurationApp.java b/src/core/lombok/core/configuration/ConfigurationApp.java index 9c225fdb..8d794c8a 100644 --- a/src/core/lombok/core/configuration/ConfigurationApp.java +++ b/src/core/lombok/core/configuration/ConfigurationApp.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014-2020 The Project Lombok Authors. + * Copyright (C) 2014-2021 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 @@ -41,8 +41,6 @@ import java.util.Set; import java.util.TreeMap; import java.util.TreeSet; -import org.mangosdk.spi.ProviderFor; - import com.zwitserloot.cmdreader.CmdReader; import com.zwitserloot.cmdreader.Description; import com.zwitserloot.cmdreader.Excludes; @@ -56,8 +54,9 @@ import com.zwitserloot.cmdreader.Shorthand; import lombok.ConfigurationKeys; import lombok.core.LombokApp; import lombok.core.configuration.ConfigurationParser.Collector; +import lombok.spi.Provides; -@ProviderFor(LombokApp.class) +@Provides public class ConfigurationApp extends LombokApp { private static final URI NO_CONFIG = URI.create(""); diff --git a/src/core/lombok/core/handlers/HandlerUtil.java b/src/core/lombok/core/handlers/HandlerUtil.java index 9fd38720..19cc5a9e 100644 --- a/src/core/lombok/core/handlers/HandlerUtil.java +++ b/src/core/lombok/core/handlers/HandlerUtil.java @@ -325,7 +325,9 @@ public class HandlerUtil { "com.fasterxml.jackson.annotation.JsonTypeInfo", "com.fasterxml.jackson.annotation.JsonView", "com.fasterxml.jackson.databind.annotation.JsonDeserialize", + "com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper", "com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty", + "com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText", })); COPY_TO_BUILDER_SINGULAR_SETTER_ANNOTATIONS = Collections.unmodifiableList(Arrays.asList(new String[] { "com.fasterxml.jackson.annotation.JsonAnySetter", @@ -761,11 +763,20 @@ public class HandlerUtil { private static final Pattern SECTION_FINDER = Pattern.compile("^\\s*\\**\\s*[-*][-*]+\\s*([GS]ETTER|WITH(?:ER)?)\\s*[-*][-*]+\\s*\\**\\s*$", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE); private static final Pattern LINE_BREAK_FINDER = Pattern.compile("(\\r?\\n)?"); - public static String stripLinesWithTagFromJavadoc(String javadoc, String regexpFragment) { + public enum JavadocTag { + PARAM("@param(?:eter)?"), + RETURN("@returns?"); + + private Pattern pattern; + + JavadocTag(String regexpFragment) { + pattern = Pattern.compile("\\s?^[ \\t]*\\**[ \\t]*" + regexpFragment + "(\\S|\\s)*?(?=(\\s^\\s*\\**\\s*@|\\Z))", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE); + } + } + + public static String stripLinesWithTagFromJavadoc(String javadoc, JavadocTag tag) { if (javadoc == null || javadoc.isEmpty()) return javadoc; - Pattern p = Pattern.compile("^\\s*\\**\\s*" + regexpFragment + "\\s*\\**\\s*$", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE); - Matcher m = p.matcher(javadoc); - return m.replaceAll(""); + return tag.pattern.matcher(javadoc).replaceAll(""); } public static String stripSectionsFromJavadoc(String javadoc) { diff --git a/src/core/lombok/core/handlers/SneakyThrowsAndCleanupDependencyInfo.java b/src/core/lombok/core/handlers/SneakyThrowsAndCleanupDependencyInfo.java index 3b6f8974..482c166b 100644 --- a/src/core/lombok/core/handlers/SneakyThrowsAndCleanupDependencyInfo.java +++ b/src/core/lombok/core/handlers/SneakyThrowsAndCleanupDependencyInfo.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2010 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -25,10 +25,9 @@ import java.util.Arrays; import java.util.List; import lombok.core.runtimeDependencies.RuntimeDependencyInfo; +import lombok.spi.Provides; -import org.mangosdk.spi.ProviderFor; - -@ProviderFor(RuntimeDependencyInfo.class) +@Provides public class SneakyThrowsAndCleanupDependencyInfo implements RuntimeDependencyInfo { @Override public List<String> getRuntimeDependencies() { return Arrays.asList( diff --git a/src/core/lombok/core/runtimeDependencies/CreateLombokRuntimeApp.java b/src/core/lombok/core/runtimeDependencies/CreateLombokRuntimeApp.java index 4d5988af..21f097d7 100644 --- a/src/core/lombok/core/runtimeDependencies/CreateLombokRuntimeApp.java +++ b/src/core/lombok/core/runtimeDependencies/CreateLombokRuntimeApp.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2011 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -38,8 +38,7 @@ import java.util.zip.ZipEntry; import lombok.core.LombokApp; import lombok.core.SpiLoadUtil; - -import org.mangosdk.spi.ProviderFor; +import lombok.spi.Provides; import com.zwitserloot.cmdreader.CmdReader; import com.zwitserloot.cmdreader.Description; @@ -48,7 +47,7 @@ import com.zwitserloot.cmdreader.Mandatory; import com.zwitserloot.cmdreader.Requires; import com.zwitserloot.cmdreader.Shorthand; -@ProviderFor(LombokApp.class) +@Provides public class CreateLombokRuntimeApp extends LombokApp { private List<RuntimeDependencyInfo> infoObjects; diff --git a/src/core/lombok/eclipse/EclipseAST.java b/src/core/lombok/eclipse/EclipseAST.java index 73114c6c..0036ec23 100644 --- a/src/core/lombok/eclipse/EclipseAST.java +++ b/src/core/lombok/eclipse/EclipseAST.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2018 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -23,7 +23,6 @@ package lombok.eclipse; import java.io.File; import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URI; import java.util.ArrayList; @@ -31,10 +30,9 @@ import java.util.Collection; import java.util.Collections; import java.util.List; -import lombok.Lombok; import lombok.core.AST; import lombok.core.LombokImmutableList; -import lombok.eclipse.handlers.EclipseHandlerUtil; +import static lombok.eclipse.handlers.EclipseHandlerUtil.*; import lombok.permit.Permit; import org.eclipse.core.resources.ResourcesPlugin; @@ -117,7 +115,7 @@ public class EclipseAST extends AST<EclipseAST, EclipseNode, ASTNode> { try { return EclipseWorkspaceBasedFileResolver.resolve(fileName); } catch (IllegalArgumentException e) { - EclipseHandlerUtil.warning("Finding 'lombok.config' file failed for '" + fileName + "'", e); + warning("Finding 'lombok.config' file failed for '" + fileName + "'", e); // String msg = e.getMessage(); // if (msg != null && msg.startsWith("Path must include project and resource name")) { // // We shouldn't throw an exception at all, but we can't reproduce this so we need help from our users to figure this out. @@ -347,7 +345,7 @@ public class EclipseAST extends AST<EclipseAST, EclipseNode, ASTNode> { case TYPE: return buildType((TypeDeclaration) node); case FIELD: - return buildField((FieldDeclaration) node); + return buildField((FieldDeclaration) node, null); case INITIALIZER: return buildInitializer((Initializer) node); case METHOD: @@ -386,16 +384,18 @@ public class EclipseAST extends AST<EclipseAST, EclipseNode, ASTNode> { private EclipseNode buildType(TypeDeclaration type) { if (setAndGetAsHandled(type)) return null; List<EclipseNode> childNodes = new ArrayList<EclipseNode>(); - childNodes.addAll(buildFields(type.fields)); + childNodes.addAll(buildFields(type.fields, getRecordFieldAnnotations(type))); childNodes.addAll(buildTypes(type.memberTypes)); childNodes.addAll(buildMethods(type.methods)); childNodes.addAll(buildAnnotations(type.annotations, false)); return putInMap(new EclipseNode(this, type, childNodes, Kind.TYPE)); } - private Collection<EclipseNode> buildFields(FieldDeclaration[] children) { + private Collection<EclipseNode> buildFields(FieldDeclaration[] children, Annotation[][] annotations) { List<EclipseNode> childNodes = new ArrayList<EclipseNode>(); - if (children != null) for (FieldDeclaration child : children) addIfNotNull(childNodes, buildField(child)); + if (children != null) for (int i = 0; i < children.length; i++) { + addIfNotNull(childNodes, buildField(children[i], annotations[i])); + } return childNodes; } @@ -405,13 +405,13 @@ public class EclipseAST extends AST<EclipseAST, EclipseNode, ASTNode> { return list; } - private EclipseNode buildField(FieldDeclaration field) { - if (field instanceof Initializer) return buildInitializer((Initializer)field); + private EclipseNode buildField(FieldDeclaration field, Annotation[] annotations) { + if (field instanceof Initializer) return buildInitializer((Initializer) field); if (setAndGetAsHandled(field)) return null; List<EclipseNode> childNodes = new ArrayList<EclipseNode>(); addIfNotNull(childNodes, buildTypeUse(field.type)); addIfNotNull(childNodes, buildStatement(field.initialization)); - childNodes.addAll(buildAnnotations(field.annotations, true)); + childNodes.addAll(buildAnnotations(annotations != null ? annotations : field.annotations, true)); return putInMap(new EclipseNode(this, field, childNodes, Kind.FIELD)); } diff --git a/src/core/lombok/eclipse/EclipseNode.java b/src/core/lombok/eclipse/EclipseNode.java index 12e9ccdb..4f86f0a5 100644 --- a/src/core/lombok/eclipse/EclipseNode.java +++ b/src/core/lombok/eclipse/EclipseNode.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2020 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -143,16 +143,6 @@ public class EclipseNode extends lombok.core.LombokNode<EclipseAST, EclipseNode, } } - @Override protected boolean fieldContainsAnnotation(ASTNode field, ASTNode annotation) { - if (!(field instanceof FieldDeclaration)) return false; - FieldDeclaration f = (FieldDeclaration) field; - if (f.annotations == null) return false; - for (Annotation childAnnotation : f.annotations) { - if (childAnnotation == annotation) return true; - } - return false; - } - /** {@inheritDoc} */ @Override public String getName() { final char[] n; diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java index b58c2996..70d98cc6 100644 --- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java +++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2020 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -337,6 +337,7 @@ public class EclipseHandlerUtil { public static final Field TYPE_REFERENCE__ANNOTATIONS; public static final Class<?> INTERSECTION_BINDING1, INTERSECTION_BINDING2; public static final Field INTERSECTION_BINDING_TYPES1, INTERSECTION_BINDING_TYPES2; + public static final Field TYPE_DECLARATION_RECORD_COMPONENTS; static { STRING_LITERAL__LINE_NUMBER = getField(StringLiteral.class, "lineNumber"); ANNOTATION__MEMBER_VALUE_PAIR_NAME = getField(Annotation.class, "memberValuePairName"); @@ -345,6 +346,7 @@ public class EclipseHandlerUtil { INTERSECTION_BINDING2 = getClass("org.eclipse.jdt.internal.compiler.lookup.IntersectionCastTypeBinding"); INTERSECTION_BINDING_TYPES1 = INTERSECTION_BINDING1 == null ? null : getField(INTERSECTION_BINDING1, "intersectingTypes"); INTERSECTION_BINDING_TYPES2 = INTERSECTION_BINDING2 == null ? null : getField(INTERSECTION_BINDING2, "intersectingTypes"); + TYPE_DECLARATION_RECORD_COMPONENTS = getField(TypeDeclaration.class, "recordComponents"); } public static int reflectInt(Field f, Object o) { @@ -776,13 +778,10 @@ public class EclipseHandlerUtil { } public static boolean hasNonNullAnnotations(EclipseNode node) { - AbstractVariableDeclaration avd = (AbstractVariableDeclaration) node.get(); - if (avd.annotations == null) return false; - for (Annotation annotation : avd.annotations) { - TypeReference typeRef = annotation.type; - if (typeRef != null && typeRef.getTypeName() != null) { - for (String bn : NONNULL_ANNOTATIONS) if (typeMatches(bn, node, typeRef)) return true; - } + for (EclipseNode child : node.down()) { + if (child.getKind() != Kind.ANNOTATION) continue; + Annotation annotation = (Annotation) child.get(); + for (String bn : NONNULL_ANNOTATIONS) if (typeMatches(bn, node, annotation.type)) return true; } return false; } @@ -1877,15 +1876,12 @@ public class EclipseHandlerUtil { public static MemberExistsResult constructorExists(EclipseNode node) { node = upToTypeNode(node); if (node != null && node.get() instanceof TypeDeclaration) { - TypeDeclaration typeDecl = (TypeDeclaration)node.get(); + TypeDeclaration typeDecl = (TypeDeclaration) node.get(); if (typeDecl.methods != null) for (AbstractMethodDeclaration def : typeDecl.methods) { - if (def instanceof ConstructorDeclaration) { - if ((def.bits & ASTNode.IsDefaultConstructor) != 0) continue; - - if (isTolerate(node, def)) continue; - - return getGeneratedBy(def) == null ? MemberExistsResult.EXISTS_BY_USER : MemberExistsResult.EXISTS_BY_LOMBOK; - } + if (!(def instanceof ConstructorDeclaration)) continue; + if ((def.bits & ASTNode.IsDefaultConstructor) != 0) continue; + if (isTolerate(node, def)) continue; + return getGeneratedBy(def) == null ? MemberExistsResult.EXISTS_BY_USER : MemberExistsResult.EXISTS_BY_LOMBOK; } } @@ -2626,6 +2622,73 @@ public class EclipseHandlerUtil { return generateQualifiedTypeRef(source, fromQualifiedName(typeName)); } + /** + * Returns {@code true} if the provided node is an actual class and not some other type declaration (so, not an annotation definition, interface, enum, or record). + */ + public static boolean isClass(EclipseNode typeNode) { + return isTypeAndDoesNotHaveFlags(typeNode, ClassFileConstants.AccInterface | ClassFileConstants.AccEnum | ClassFileConstants.AccAnnotation | AccRecord); + } + + /** + * Returns {@code true} if the provided node is an actual class or enum and not some other type declaration (so, not an annotation definition, interface, or record). + */ + public static boolean isClassOrEnum(EclipseNode typeNode) { + return isTypeAndDoesNotHaveFlags(typeNode, ClassFileConstants.AccInterface | ClassFileConstants.AccAnnotation | AccRecord); + } + + /** + * Returns {@code true} if the provided node is a record declaration (so, not an annotation definition, interface, enum, or plain class). + */ + public static boolean isRecord(EclipseNode typeNode) { + TypeDeclaration typeDecl = null; + if (typeNode.get() instanceof TypeDeclaration) typeDecl = (TypeDeclaration) typeNode.get(); + int modifiers = typeDecl == null ? 0 : typeDecl.modifiers; + return (modifiers & AccRecord) != 0; + } + + /** + * Returns {@code true} If the provided node is a field declaration, and represents a field in a {@code record} declaration. + */ + public static boolean isRecordField(EclipseNode fieldNode) { + return fieldNode.getKind() == Kind.FIELD && (((FieldDeclaration) fieldNode.get()).modifiers & AccRecord) != 0; + } + + /** + * Returns {@code true) if the provided node is a type declaration <em>and</em> is <strong>not</strong> of any kind indicated by the flags (the intent is to pass flags usch as `ClassFileConstants.AccEnum`). + */ + static boolean isTypeAndDoesNotHaveFlags(EclipseNode typeNode, long flags) { + TypeDeclaration typeDecl = null; + if (typeNode.get() instanceof TypeDeclaration) typeDecl = (TypeDeclaration) typeNode.get(); + int modifiers = typeDecl == null ? 0 : typeDecl.modifiers; + return (modifiers & flags) == 0; + } + + public static AbstractVariableDeclaration[] getRecordComponents(TypeDeclaration typeDeclaration) { + if (typeDeclaration == null || (typeDeclaration.modifiers & AccRecord) == 0) return null; + try { + return (AbstractVariableDeclaration[]) TYPE_DECLARATION_RECORD_COMPONENTS.get(typeDeclaration); + } catch (Exception e) { + // This presumably means this isn't a JDK16 - fall through. + } + return null; + } + + public static Annotation[][] getRecordFieldAnnotations(TypeDeclaration typeDeclaration) { + if (typeDeclaration.fields == null) return null; + Annotation[][] annotations = new Annotation[typeDeclaration.fields.length][]; + + AbstractVariableDeclaration[] recordComponents = getRecordComponents(typeDeclaration); + if (recordComponents != null) { + int j = 0; + for (int i = 0; i < typeDeclaration.fields.length; i++) { + if ((typeDeclaration.fields[i].modifiers & AccRecord) != 0) { + annotations[i] = recordComponents[j++].annotations; + } + } + } + return annotations; + } + public static String getDocComment(CompilationUnitDeclaration cud, ASTNode node) { ICompilationUnit compilationUnit = cud.compilationResult.compilationUnit; if (node instanceof FieldDeclaration) { @@ -2688,7 +2751,7 @@ public class EclipseHandlerUtil { String out = getJavadocSection(javadoc, "GETTER"); final boolean sectionBased = out != null; if (!sectionBased) { - out = stripLinesWithTagFromJavadoc(stripSectionsFromJavadoc(javadoc), "@param(?:eter)?\\s+.*"); + out = stripLinesWithTagFromJavadoc(stripSectionsFromJavadoc(javadoc), JavadocTag.PARAM); } return out; } @@ -2718,7 +2781,7 @@ public class EclipseHandlerUtil { String out = getJavadocSection(javadoc, sectionName); final boolean sectionBased = out != null; if (!sectionBased) { - out = stripLinesWithTagFromJavadoc(stripSectionsFromJavadoc(javadoc), "@returns?\\s+.*"); + out = stripLinesWithTagFromJavadoc(stripSectionsFromJavadoc(javadoc), JavadocTag.RETURN); } return shouldReturnThis(node) ? addReturnsThisIfNeeded(out) : out; } diff --git a/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java b/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java index 760f5282..d099cab2 100755 --- a/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java +++ b/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015-2020 The Project Lombok Authors. + * Copyright (C) 2015-2021 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 @@ -451,7 +451,17 @@ public class EclipseSingularsRecipes { statements.add(0, nullCheck); } + protected abstract int getTypeArgumentsCount(); + protected abstract char[][] getEmptyMakerReceiver(String targetFqn); protected abstract char[] getEmptyMakerSelector(String targetFqn); + + public MessageSend getEmptyExpression(String targetFqn, SingularData data, EclipseNode typeNode, ASTNode source) { + MessageSend send = new MessageSend(); + send.receiver = generateQualifiedNameRef(source, getEmptyMakerReceiver(targetFqn)); + send.selector = getEmptyMakerSelector(targetFqn); + send.typeArguments = createTypeArgs(getTypeArgumentsCount(), false, typeNode, data.getTypeArgs()); + return send; + } } } diff --git a/src/core/lombok/eclipse/handlers/HandleAccessors.java b/src/core/lombok/eclipse/handlers/HandleAccessors.java index 864ff50b..6a92dee2 100644 --- a/src/core/lombok/eclipse/handlers/HandleAccessors.java +++ b/src/core/lombok/eclipse/handlers/HandleAccessors.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014 The Project Lombok Authors. + * Copyright (C) 2014-2021 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 @@ -28,11 +28,11 @@ import lombok.core.HandlerPriority; import lombok.eclipse.EclipseAnnotationHandler; import lombok.eclipse.EclipseNode; import lombok.experimental.Accessors; +import lombok.spi.Provides; import org.eclipse.jdt.internal.compiler.ast.Annotation; -import org.mangosdk.spi.ProviderFor; -@ProviderFor(EclipseAnnotationHandler.class) +@Provides @HandlerPriority(65536) public class HandleAccessors extends EclipseAnnotationHandler<Accessors> { @Override public void handle(AnnotationValues<Accessors> annotation, Annotation ast, EclipseNode annotationNode) { diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java index dfb8eab0..c002c4ca 100755 --- a/src/core/lombok/eclipse/handlers/HandleBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2020 The Project Lombok Authors. + * Copyright (C) 2013-2021 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 @@ -74,7 +74,6 @@ import org.eclipse.jdt.internal.compiler.lookup.ClassScope; import org.eclipse.jdt.internal.compiler.lookup.MethodScope; import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; import org.eclipse.jdt.internal.compiler.lookup.TypeIds; -import org.mangosdk.spi.ProviderFor; import lombok.AccessLevel; import lombok.Builder; @@ -98,8 +97,9 @@ import lombok.eclipse.handlers.EclipseSingularsRecipes.EclipseSingularizer; import lombok.eclipse.handlers.EclipseSingularsRecipes.SingularData; import lombok.eclipse.handlers.HandleConstructor.SkipIfConstructorExists; import lombok.experimental.NonFinal; +import lombok.spi.Provides; -@ProviderFor(EclipseAnnotationHandler.class) +@Provides @HandlerPriority(-1024) //-2^10; to ensure we've picked up @FieldDefault's changes (-2048) but @Value hasn't removed itself yet (-512), so that we can error on presence of it on the builder classes. public class HandleBuilder extends EclipseAnnotationHandler<Builder> { private HandleConstructor handleConstructor = new HandleConstructor(); @@ -257,6 +257,8 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> { } @Override public void handle(AnnotationValues<Builder> annotation, Annotation ast, EclipseNode annotationNode) { + final String BUILDER_NODE_NOT_SUPPORTED_ERR = "@Builder is only supported on classes, records, constructors, and methods."; + handleFlagUsage(annotationNode, ConfigurationKeys.BUILDER_FLAG_USAGE, "@Builder"); BuilderJob job = new BuilderJob(); job.sourceNode = annotationNode; @@ -292,6 +294,11 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> { List<EclipseNode> nonFinalNonDefaultedFields = null; if (parent.get() instanceof TypeDeclaration) { + if (!isClass(parent) && !isRecord(parent)) { + annotationNode.addError(BUILDER_NODE_NOT_SUPPORTED_ERR); + return; + } + job.parentType = parent; TypeDeclaration td = (TypeDeclaration) parent.get(); @@ -340,8 +347,12 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> { allFields.add(fieldNode); } - handleConstructor.generateConstructor(parent, AccessLevel.PACKAGE, allFields, false, null, SkipIfConstructorExists.I_AM_BUILDER, - Collections.<Annotation>emptyList(), annotationNode); + if (!isRecord(parent)) { + // Records ship with a canonical constructor that acts as @AllArgsConstructor - just use that one. + + handleConstructor.generateConstructor(parent, AccessLevel.PACKAGE, allFields, false, null, SkipIfConstructorExists.I_AM_BUILDER, + Collections.<Annotation>emptyList(), annotationNode); + } job.typeParams = job.builderTypeParams = td.typeParameters; buildMethodReturnType = job.createBuilderParentTypeReference(); @@ -450,7 +461,7 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> { if (!checkName("builderClassName", job.builderClassName, annotationNode)) return; } } else { - annotationNode.addError("@Builder is only supported on types, constructors, and methods."); + annotationNode.addError(BUILDER_NODE_NOT_SUPPORTED_ERR); return; } diff --git a/src/core/lombok/eclipse/handlers/HandleBuilderDefault.java b/src/core/lombok/eclipse/handlers/HandleBuilderDefault.java index d0c597fd..464a0efd 100644 --- a/src/core/lombok/eclipse/handlers/HandleBuilderDefault.java +++ b/src/core/lombok/eclipse/handlers/HandleBuilderDefault.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2018 The Project Lombok Authors. + * Copyright (C) 2017-2021 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 @@ -23,7 +23,6 @@ package lombok.eclipse.handlers; import static lombok.eclipse.handlers.EclipseHandlerUtil.*; import org.eclipse.jdt.internal.compiler.ast.Annotation; -import org.mangosdk.spi.ProviderFor; import lombok.Builder; import lombok.core.AST.Kind; @@ -32,8 +31,9 @@ import lombok.core.HandlerPriority; import lombok.eclipse.EclipseAnnotationHandler; import lombok.eclipse.EclipseNode; import lombok.experimental.SuperBuilder; +import lombok.spi.Provides; -@ProviderFor(EclipseAnnotationHandler.class) +@Provides @HandlerPriority(-1025) //HandleBuilder's level, minus one. public class HandleBuilderDefault extends EclipseAnnotationHandler<Builder.Default> { @Override public void handle(AnnotationValues<Builder.Default> annotation, Annotation ast, EclipseNode annotationNode) { diff --git a/src/core/lombok/eclipse/handlers/HandleCleanup.java b/src/core/lombok/eclipse/handlers/HandleCleanup.java index dde7cd08..3ce41763 100644 --- a/src/core/lombok/eclipse/handlers/HandleCleanup.java +++ b/src/core/lombok/eclipse/handlers/HandleCleanup.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2014 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -32,6 +32,7 @@ import lombok.core.AnnotationValues; import lombok.core.AST.Kind; import lombok.eclipse.EclipseAnnotationHandler; import lombok.eclipse.EclipseNode; +import lombok.spi.Provides; import org.eclipse.jdt.internal.compiler.ast.ASTNode; import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; @@ -52,12 +53,11 @@ import org.eclipse.jdt.internal.compiler.ast.SingleNameReference; import org.eclipse.jdt.internal.compiler.ast.Statement; import org.eclipse.jdt.internal.compiler.ast.SwitchStatement; import org.eclipse.jdt.internal.compiler.ast.TryStatement; -import org.mangosdk.spi.ProviderFor; /** * Handles the {@code lombok.Cleanup} annotation for eclipse. */ -@ProviderFor(EclipseAnnotationHandler.class) +@Provides public class HandleCleanup extends EclipseAnnotationHandler<Cleanup> { public void handle(AnnotationValues<Cleanup> annotation, Annotation ast, EclipseNode annotationNode) { handleFlagUsage(annotationNode, ConfigurationKeys.CLEANUP_FLAG_USAGE, "@Cleanup"); diff --git a/src/core/lombok/eclipse/handlers/HandleConstructor.java b/src/core/lombok/eclipse/handlers/HandleConstructor.java index 3233a8c6..e69c3267 100755 --- a/src/core/lombok/eclipse/handlers/HandleConstructor.java +++ b/src/core/lombok/eclipse/handlers/HandleConstructor.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2020 The Project Lombok Authors. + * Copyright (C) 2010-2021 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 @@ -44,6 +44,7 @@ import lombok.core.AnnotationValues; import lombok.eclipse.EclipseAnnotationHandler; import lombok.eclipse.EclipseNode; import lombok.eclipse.handlers.EclipseHandlerUtil.MemberExistsResult; +import lombok.spi.Provides; import org.eclipse.jdt.internal.compiler.ast.ASTNode; import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; @@ -79,10 +80,9 @@ import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.ast.TypeReference; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; -import org.mangosdk.spi.ProviderFor; public class HandleConstructor { - @ProviderFor(EclipseAnnotationHandler.class) + @Provides public static class HandleNoArgsConstructor extends EclipseAnnotationHandler<NoArgsConstructor> { private static final String NAME = NoArgsConstructor.class.getSimpleName(); private HandleConstructor handleConstructor = new HandleConstructor(); @@ -105,7 +105,7 @@ public class HandleConstructor { } } - @ProviderFor(EclipseAnnotationHandler.class) + @Provides public static class HandleRequiredArgsConstructor extends EclipseAnnotationHandler<RequiredArgsConstructor> { private static final String NAME = RequiredArgsConstructor.class.getSimpleName(); private HandleConstructor handleConstructor = new HandleConstructor(); @@ -166,7 +166,7 @@ public class HandleConstructor { return fields; } - @ProviderFor(EclipseAnnotationHandler.class) + @Provides public static class HandleAllArgsConstructor extends EclipseAnnotationHandler<AllArgsConstructor> { private static final String NAME = AllArgsConstructor.class.getSimpleName(); @@ -194,12 +194,7 @@ public class HandleConstructor { } static boolean checkLegality(EclipseNode typeNode, EclipseNode errorNode, String name) { - TypeDeclaration typeDecl = null; - if (typeNode.get() instanceof TypeDeclaration) typeDecl = (TypeDeclaration) typeNode.get(); - int modifiers = typeDecl == null ? 0 : typeDecl.modifiers; - boolean notAClass = (modifiers & (ClassFileConstants.AccInterface | ClassFileConstants.AccAnnotation)) != 0; - - if (typeDecl == null || notAClass) { + if (!isClassOrEnum(typeNode)) { errorNode.addError(name + " is only supported on a class or an enum."); return false; } diff --git a/src/core/lombok/eclipse/handlers/HandleData.java b/src/core/lombok/eclipse/handlers/HandleData.java index 4011890d..00e1fd38 100644 --- a/src/core/lombok/eclipse/handlers/HandleData.java +++ b/src/core/lombok/eclipse/handlers/HandleData.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2014 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -22,6 +22,7 @@ package lombok.eclipse.handlers; import static lombok.core.handlers.HandlerUtil.*; +import static lombok.eclipse.handlers.EclipseHandlerUtil.*; import java.util.Collections; @@ -32,16 +33,14 @@ import lombok.core.AnnotationValues; import lombok.eclipse.EclipseAnnotationHandler; import lombok.eclipse.EclipseNode; import lombok.eclipse.handlers.HandleConstructor.SkipIfConstructorExists; +import lombok.spi.Provides; import org.eclipse.jdt.internal.compiler.ast.Annotation; -import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; -import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; -import org.mangosdk.spi.ProviderFor; /** * Handles the {@code lombok.Data} annotation for eclipse. */ -@ProviderFor(EclipseAnnotationHandler.class) +@Provides public class HandleData extends EclipseAnnotationHandler<Data> { private HandleGetter handleGetter = new HandleGetter(); private HandleSetter handleSetter = new HandleSetter(); @@ -55,13 +54,7 @@ public class HandleData extends EclipseAnnotationHandler<Data> { Data ann = annotation.getInstance(); EclipseNode typeNode = annotationNode.up(); - TypeDeclaration typeDecl = null; - if (typeNode.get() instanceof TypeDeclaration) typeDecl = (TypeDeclaration) typeNode.get(); - int modifiers = typeDecl == null ? 0 : typeDecl.modifiers; - boolean notAClass = (modifiers & - (ClassFileConstants.AccInterface | ClassFileConstants.AccAnnotation | ClassFileConstants.AccEnum)) != 0; - - if (typeDecl == null || notAClass) { + if (!isClass(typeNode)) { annotationNode.addError("@Data is only supported on a class."); return; } diff --git a/src/core/lombok/eclipse/handlers/HandleDelegate.java b/src/core/lombok/eclipse/handlers/HandleDelegate.java index 9d352558..0e3eab66 100644 --- a/src/core/lombok/eclipse/handlers/HandleDelegate.java +++ b/src/core/lombok/eclipse/handlers/HandleDelegate.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014 The Project Lombok Authors. + * Copyright (C) 2014-2021 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 @@ -27,14 +27,14 @@ import lombok.core.AnnotationValues; import lombok.eclipse.EclipseAnnotationHandler; import lombok.eclipse.EclipseNode; import lombok.experimental.Delegate; +import lombok.spi.Provides; import org.eclipse.jdt.internal.compiler.ast.Annotation; -import org.mangosdk.spi.ProviderFor; /** * This class just handles basic error cases. The real meat of eclipse '@Delegate' support is in {@code PatchDelegate}. */ -@ProviderFor(EclipseAnnotationHandler.class) +@Provides public class HandleDelegate extends EclipseAnnotationHandler<Delegate> { public void handle(AnnotationValues<Delegate> annotation, Annotation ast, EclipseNode annotationNode) { handleExperimentalFlagUsage(annotationNode, ConfigurationKeys.DELEGATE_FLAG_USAGE, "@Delegate"); diff --git a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java index deb19c00..753c489c 100755 --- a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java +++ b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2020 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -48,6 +48,7 @@ import lombok.eclipse.Eclipse; import lombok.eclipse.EclipseAnnotationHandler; import lombok.eclipse.EclipseNode; import lombok.eclipse.handlers.EclipseHandlerUtil.MemberExistsResult; +import lombok.spi.Provides; import org.eclipse.jdt.internal.compiler.ast.ASTNode; import org.eclipse.jdt.internal.compiler.ast.Annotation; @@ -89,12 +90,11 @@ import org.eclipse.jdt.internal.compiler.ast.Wildcard; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; import org.eclipse.jdt.internal.compiler.lookup.TypeIds; -import org.mangosdk.spi.ProviderFor; /** * Handles the {@code EqualsAndHashCode} annotation for eclipse. */ -@ProviderFor(EclipseAnnotationHandler.class) +@Provides public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndHashCode> { private static final String HASH_CODE_CACHE_NAME = "$hashCodeCache"; @@ -144,18 +144,12 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH public void generateMethods(EclipseNode typeNode, EclipseNode errorNode, List<Included<EclipseNode, EqualsAndHashCode.Include>> members, Boolean callSuper, boolean whineIfExists, boolean cacheHashCode, FieldAccess fieldAccess, List<Annotation> onParam) { - TypeDeclaration typeDecl = null; - - if (typeNode.get() instanceof TypeDeclaration) typeDecl = (TypeDeclaration) typeNode.get(); - int modifiers = typeDecl == null ? 0 : typeDecl.modifiers; - boolean notAClass = (modifiers & - (ClassFileConstants.AccInterface | ClassFileConstants.AccAnnotation | ClassFileConstants.AccEnum)) != 0; - - if (typeDecl == null || notAClass) { + if (!isClass(typeNode)) { errorNode.addError("@EqualsAndHashCode is only supported on a class."); return; } + TypeDeclaration typeDecl = (TypeDeclaration) typeNode.get(); boolean implicitCallSuper = callSuper == null; if (callSuper == null) { @@ -168,30 +162,6 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH boolean isDirectDescendantOfObject = isDirectDescendantOfObject(typeNode); - if (isDirectDescendantOfObject && callSuper) { - errorNode.addError("Generating equals/hashCode with a supercall to java.lang.Object is pointless."); - return; - } - - if (implicitCallSuper && !isDirectDescendantOfObject) { - CallSuperType cst = typeNode.getAst().readConfiguration(ConfigurationKeys.EQUALS_AND_HASH_CODE_CALL_SUPER); - if (cst == null) cst = CallSuperType.WARN; - - switch (cst) { - default: - case WARN: - errorNode.addWarning("Generating equals/hashCode implementation but without a call to superclass, even though this class does not extend java.lang.Object. If this is intentional, add '@EqualsAndHashCode(callSuper=false)' to your type."); - callSuper = false; - break; - case SKIP: - callSuper = false; - break; - case CALL: - callSuper = true; - break; - } - } - boolean isFinal = (typeDecl.modifiers & ClassFileConstants.AccFinal) != 0; boolean needsCanEqual = !isFinal || !isDirectDescendantOfObject; MemberExistsResult equalsExists = methodExists("equals", typeNode, 1); @@ -220,6 +190,30 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH //fallthrough } + if (isDirectDescendantOfObject && callSuper) { + errorNode.addError("Generating equals/hashCode with a supercall to java.lang.Object is pointless."); + return; + } + + if (implicitCallSuper && !isDirectDescendantOfObject) { + CallSuperType cst = typeNode.getAst().readConfiguration(ConfigurationKeys.EQUALS_AND_HASH_CODE_CALL_SUPER); + if (cst == null) cst = CallSuperType.WARN; + + switch (cst) { + default: + case WARN: + errorNode.addWarning("Generating equals/hashCode implementation but without a call to superclass, even though this class does not extend java.lang.Object. If this is intentional, add '@EqualsAndHashCode(callSuper=false)' to your type."); + callSuper = false; + break; + case SKIP: + callSuper = false; + break; + case CALL: + callSuper = true; + break; + } + } + MethodDeclaration equalsMethod = createEquals(typeNode, members, callSuper, errorNode.get(), fieldAccess, needsCanEqual, onParam); equalsMethod.traverse(new SetGeneratedByVisitor(errorNode.get()), ((TypeDeclaration)typeNode.get()).scope); injectMethod(typeNode, equalsMethod); diff --git a/src/core/lombok/eclipse/handlers/HandleExtensionMethod.java b/src/core/lombok/eclipse/handlers/HandleExtensionMethod.java index 8e53d873..5857780c 100644 --- a/src/core/lombok/eclipse/handlers/HandleExtensionMethod.java +++ b/src/core/lombok/eclipse/handlers/HandleExtensionMethod.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2014 The Project Lombok Authors. + * Copyright (C) 2012-2021 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 @@ -28,7 +28,6 @@ import java.util.List; import org.eclipse.jdt.internal.compiler.ast.Annotation; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; -import org.mangosdk.spi.ProviderFor; import lombok.ConfigurationKeys; import lombok.core.AnnotationValues; @@ -36,9 +35,10 @@ import lombok.core.HandlerPriority; import lombok.eclipse.EclipseAnnotationHandler; import lombok.eclipse.EclipseNode; import lombok.experimental.ExtensionMethod; +import lombok.spi.Provides; // This handler just does some additional error checking; the real work is done in the agent. -@ProviderFor(EclipseAnnotationHandler.class) +@Provides @HandlerPriority(66560) // 2^16 + 2^10; we must run AFTER HandleVal which is at 2^16 public class HandleExtensionMethod extends EclipseAnnotationHandler<ExtensionMethod> { @Override public void handle(AnnotationValues<ExtensionMethod> annotation, Annotation ast, EclipseNode annotationNode) { diff --git a/src/core/lombok/eclipse/handlers/HandleFieldDefaults.java b/src/core/lombok/eclipse/handlers/HandleFieldDefaults.java index 702713fe..5900e7ed 100644 --- a/src/core/lombok/eclipse/handlers/HandleFieldDefaults.java +++ b/src/core/lombok/eclipse/handlers/HandleFieldDefaults.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2016 The Project Lombok Authors. + * Copyright (C) 2012-2021 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 @@ -38,6 +38,7 @@ import lombok.eclipse.EclipseNode; import lombok.experimental.FieldDefaults; import lombok.experimental.NonFinal; import lombok.experimental.PackagePrivate; +import lombok.spi.Provides; import org.eclipse.jdt.internal.compiler.ast.ASTNode; import org.eclipse.jdt.internal.compiler.ast.Annotation; @@ -47,12 +48,11 @@ import org.eclipse.jdt.internal.compiler.ast.SingleTypeReference; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.ast.TypeReference; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; -import org.mangosdk.spi.ProviderFor; /** * Handles the {@code lombok.FieldDefaults} annotation for eclipse. */ -@ProviderFor(EclipseASTVisitor.class) +@Provides(EclipseASTVisitor.class) @HandlerPriority(-2048) //-2^11; to ensure @Value picks up on messing with the fields' 'final' state, run earlier. public class HandleFieldDefaults extends EclipseASTAdapter { public boolean generateFieldDefaultsForType(EclipseNode typeNode, EclipseNode pos, AccessLevel level, boolean makeFinal, boolean checkForTypeLevelFieldDefaults) { @@ -63,13 +63,7 @@ public class HandleFieldDefaults extends EclipseASTAdapter { } } - TypeDeclaration typeDecl = null; - if (typeNode.get() instanceof TypeDeclaration) typeDecl = (TypeDeclaration) typeNode.get(); - int modifiers = typeDecl == null ? 0 : typeDecl.modifiers; - boolean notAClass = (modifiers & - (ClassFileConstants.AccInterface | ClassFileConstants.AccAnnotation)) != 0; - - if (typeDecl == null || notAClass) { + if (!isClassOrEnum(typeNode)) { pos.addError("@FieldDefaults is only supported on a class or an enum."); return false; } diff --git a/src/core/lombok/eclipse/handlers/HandleFieldNameConstants.java b/src/core/lombok/eclipse/handlers/HandleFieldNameConstants.java index cee3912c..cc1a5c3f 100644 --- a/src/core/lombok/eclipse/handlers/HandleFieldNameConstants.java +++ b/src/core/lombok/eclipse/handlers/HandleFieldNameConstants.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014-2019 The Project Lombok Authors. + * Copyright (C) 2014-2021 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 @@ -41,7 +41,6 @@ import org.eclipse.jdt.internal.compiler.ast.StringLiteral; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; -import org.mangosdk.spi.ProviderFor; import lombok.AccessLevel; import lombok.ConfigurationKeys; @@ -54,8 +53,9 @@ import lombok.eclipse.EclipseAnnotationHandler; import lombok.eclipse.EclipseNode; import lombok.eclipse.handlers.EclipseHandlerUtil.MemberExistsResult; import lombok.experimental.FieldNameConstants; +import lombok.spi.Provides; -@ProviderFor(EclipseAnnotationHandler.class) +@Provides public class HandleFieldNameConstants extends EclipseAnnotationHandler<FieldNameConstants> { private static final IdentifierName FIELDS = IdentifierName.valueOf("Fields"); diff --git a/src/core/lombok/eclipse/handlers/HandleGetter.java b/src/core/lombok/eclipse/handlers/HandleGetter.java index 4d7d84ce..7f8fdef2 100644 --- a/src/core/lombok/eclipse/handlers/HandleGetter.java +++ b/src/core/lombok/eclipse/handlers/HandleGetter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2020 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -35,6 +35,7 @@ import java.util.Map; import lombok.AccessLevel; import lombok.ConfigurationKeys; import lombok.experimental.Delegate; +import lombok.spi.Provides; import lombok.Getter; import lombok.core.AST.Kind; import lombok.core.AnnotationValues; @@ -73,14 +74,14 @@ import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.ast.TypeReference; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; -import org.mangosdk.spi.ProviderFor; /** * Handles the {@code lombok.Getter} annotation for eclipse. */ -@ProviderFor(EclipseAnnotationHandler.class) +@Provides public class HandleGetter extends EclipseAnnotationHandler<Getter> { private static final Annotation[] EMPTY_ANNOTATIONS_ARRAY = new Annotation[0]; + private static final String GETTER_NODE_NOT_SUPPORTED_ERR = "@Getter is only supported on a class, an enum, or a field."; public boolean generateGetterForType(EclipseNode typeNode, EclipseNode pos, AccessLevel level, boolean checkForTypeLevelGetter, List<Annotation> onMethod) { if (checkForTypeLevelGetter) { @@ -90,14 +91,8 @@ public class HandleGetter extends EclipseAnnotationHandler<Getter> { } } - TypeDeclaration typeDecl = null; - if (typeNode.get() instanceof TypeDeclaration) typeDecl = (TypeDeclaration) typeNode.get(); - int modifiers = typeDecl == null ? 0 : typeDecl.modifiers; - boolean notAClass = (modifiers & - (ClassFileConstants.AccInterface | ClassFileConstants.AccAnnotation)) != 0; - - if (typeDecl == null || notAClass) { - pos.addError("@Getter is only supported on a class, an enum, or a field."); + if (!isClassOrEnum(typeNode)) { + pos.addError(GETTER_NODE_NOT_SUPPORTED_ERR); return false; } @@ -171,8 +166,9 @@ public class HandleGetter extends EclipseAnnotationHandler<Getter> { public void createGetterForField(AccessLevel level, EclipseNode fieldNode, EclipseNode errorNode, ASTNode source, boolean whineIfExists, boolean lazy, List<Annotation> onMethod) { + if (fieldNode.getKind() != Kind.FIELD) { - errorNode.addError("@Getter is only supported on a class or a field."); + errorNode.addError(GETTER_NODE_NOT_SUPPORTED_ERR); return; } diff --git a/src/core/lombok/eclipse/handlers/HandleHelper.java b/src/core/lombok/eclipse/handlers/HandleHelper.java index 36f53813..7977c507 100755 --- a/src/core/lombok/eclipse/handlers/HandleHelper.java +++ b/src/core/lombok/eclipse/handlers/HandleHelper.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015-2016 The Project Lombok Authors. + * Copyright (C) 2015-2021 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 @@ -45,7 +45,6 @@ import org.eclipse.jdt.internal.compiler.ast.ThisReference; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.lookup.BlockScope; -import org.mangosdk.spi.ProviderFor; import lombok.ConfigurationKeys; import lombok.core.AST.Kind; @@ -53,11 +52,12 @@ import lombok.core.AnnotationValues; import lombok.eclipse.EclipseAnnotationHandler; import lombok.eclipse.EclipseNode; import lombok.experimental.Helper; +import lombok.spi.Provides; /** * Handles the {@code lombok.Cleanup} annotation for eclipse. */ -@ProviderFor(EclipseAnnotationHandler.class) +@Provides public class HandleHelper extends EclipseAnnotationHandler<Helper> { private Statement[] getStatementsFromAstNode(ASTNode node) { if (node instanceof Block) return ((Block) node).statements; diff --git a/src/core/lombok/eclipse/handlers/HandleJacksonized.java b/src/core/lombok/eclipse/handlers/HandleJacksonized.java index 90ee7582..466cc338 100644 --- a/src/core/lombok/eclipse/handlers/HandleJacksonized.java +++ b/src/core/lombok/eclipse/handlers/HandleJacksonized.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2020 The Project Lombok Authors. + * Copyright (C) 2013-2021 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 @@ -37,7 +37,6 @@ import org.eclipse.jdt.internal.compiler.ast.StringLiteral; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.ast.TypeReference; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; -import org.mangosdk.spi.ProviderFor; import lombok.Builder; import lombok.ConfigurationKeys; @@ -50,13 +49,15 @@ import lombok.eclipse.EclipseAnnotationHandler; import lombok.eclipse.EclipseNode; import lombok.experimental.SuperBuilder; import lombok.extern.jackson.Jacksonized; +import lombok.spi.Provides; /** * This (ecj) handler deals with {@code @Jacksonized} modifying the (already * generated) {@code @Builder} or {@code @SuperBuilder} to conform to Jackson's * needs for builders. */ -@ProviderFor(EclipseAnnotationHandler.class) @HandlerPriority(-512) // Above Handle(Super)Builder's level (builders must be already generated). +@Provides +@HandlerPriority(-512) // Above Handle(Super)Builder's level (builders must be already generated). public class HandleJacksonized extends EclipseAnnotationHandler<Jacksonized> { private static final char[][] JSON_POJO_BUILDER_ANNOTATION = Eclipse.fromQualifiedName("com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder"); diff --git a/src/core/lombok/eclipse/handlers/HandleLog.java b/src/core/lombok/eclipse/handlers/HandleLog.java index 8297426d..df3989a4 100644 --- a/src/core/lombok/eclipse/handlers/HandleLog.java +++ b/src/core/lombok/eclipse/handlers/HandleLog.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2019 The Project Lombok Authors. + * Copyright (C) 2010-2021 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 @@ -38,7 +38,6 @@ import org.eclipse.jdt.internal.compiler.ast.StringLiteral; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.ast.TypeReference; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; -import org.mangosdk.spi.ProviderFor; import lombok.ConfigurationKeys; import lombok.core.AnnotationValues; @@ -49,10 +48,11 @@ import lombok.core.handlers.LoggingFramework; import lombok.eclipse.EclipseAnnotationHandler; import lombok.eclipse.EclipseNode; import lombok.eclipse.handlers.EclipseHandlerUtil.MemberExistsResult; +import lombok.spi.Provides; public class HandleLog { private static final IdentifierName LOG = IdentifierName.valueOf("log"); - + private HandleLog() { throw new UnsupportedOperationException(); } @@ -82,10 +82,15 @@ public class HandleLog { annotationNode.addWarning("Field '" + logFieldName + "' already exists."); return; } - + + if (isRecord(owner) && !useStatic) { + annotationNode.addError("Logger fields must be static in records."); + return; + } + Object valueGuess = annotation.getValueGuess("topic"); Expression loggerTopic = (Expression) annotation.getActualExpression("topic"); - + if (valueGuess instanceof String && ((String) valueGuess).trim().isEmpty()) loggerTopic = null; if (framework.getDeclaration().getParametersWithTopic() == null && loggerTopic != null) { annotationNode.addError(framework.getAnnotationAsString() + " does not allow a topic."); @@ -203,7 +208,7 @@ public class HandleLog { /** * Handles the {@link lombok.extern.apachecommons.CommonsLog} annotation for Eclipse. */ - @ProviderFor(EclipseAnnotationHandler.class) + @Provides public static class HandleCommonsLog extends EclipseAnnotationHandler<lombok.extern.apachecommons.CommonsLog> { @Override public void handle(AnnotationValues<lombok.extern.apachecommons.CommonsLog> annotation, Annotation source, EclipseNode annotationNode) { handleFlagUsage(annotationNode, ConfigurationKeys.LOG_COMMONS_FLAG_USAGE, "@apachecommons.CommonsLog", ConfigurationKeys.LOG_ANY_FLAG_USAGE, "any @Log"); @@ -214,7 +219,7 @@ public class HandleLog { /** * Handles the {@link lombok.extern.java.Log} annotation for Eclipse. */ - @ProviderFor(EclipseAnnotationHandler.class) + @Provides public static class HandleJulLog extends EclipseAnnotationHandler<lombok.extern.java.Log> { @Override public void handle(AnnotationValues<lombok.extern.java.Log> annotation, Annotation source, EclipseNode annotationNode) { handleFlagUsage(annotationNode, ConfigurationKeys.LOG_JUL_FLAG_USAGE, "@java.Log", ConfigurationKeys.LOG_ANY_FLAG_USAGE, "any @Log"); @@ -225,7 +230,7 @@ public class HandleLog { /** * Handles the {@link lombok.extern.log4j.Log4j} annotation for Eclipse. */ - @ProviderFor(EclipseAnnotationHandler.class) + @Provides public static class HandleLog4jLog extends EclipseAnnotationHandler<lombok.extern.log4j.Log4j> { @Override public void handle(AnnotationValues<lombok.extern.log4j.Log4j> annotation, Annotation source, EclipseNode annotationNode) { handleFlagUsage(annotationNode, ConfigurationKeys.LOG_LOG4J_FLAG_USAGE, "@Log4j", ConfigurationKeys.LOG_ANY_FLAG_USAGE, "any @Log"); @@ -236,7 +241,7 @@ public class HandleLog { /** * Handles the {@link lombok.extern.log4j.Log4j2} annotation for Eclipse. */ - @ProviderFor(EclipseAnnotationHandler.class) + @Provides public static class HandleLog4j2Log extends EclipseAnnotationHandler<lombok.extern.log4j.Log4j2> { @Override public void handle(AnnotationValues<lombok.extern.log4j.Log4j2> annotation, Annotation source, EclipseNode annotationNode) { handleFlagUsage(annotationNode, ConfigurationKeys.LOG_LOG4J2_FLAG_USAGE, "@Log4j2", ConfigurationKeys.LOG_ANY_FLAG_USAGE, "any @Log"); @@ -247,7 +252,7 @@ public class HandleLog { /** * Handles the {@link lombok.extern.slf4j.Slf4j} annotation for Eclipse. */ - @ProviderFor(EclipseAnnotationHandler.class) + @Provides public static class HandleSlf4jLog extends EclipseAnnotationHandler<lombok.extern.slf4j.Slf4j> { @Override public void handle(AnnotationValues<lombok.extern.slf4j.Slf4j> annotation, Annotation source, EclipseNode annotationNode) { handleFlagUsage(annotationNode, ConfigurationKeys.LOG_SLF4J_FLAG_USAGE, "@Slf4j", ConfigurationKeys.LOG_ANY_FLAG_USAGE, "any @Log"); @@ -258,7 +263,7 @@ public class HandleLog { /** * Handles the {@link lombok.extern.slf4j.XSlf4j} annotation for Eclipse. */ - @ProviderFor(EclipseAnnotationHandler.class) + @Provides public static class HandleXSlf4jLog extends EclipseAnnotationHandler<lombok.extern.slf4j.XSlf4j> { @Override public void handle(AnnotationValues<lombok.extern.slf4j.XSlf4j> annotation, Annotation source, EclipseNode annotationNode) { handleFlagUsage(annotationNode, ConfigurationKeys.LOG_XSLF4J_FLAG_USAGE, "@XSlf4j", ConfigurationKeys.LOG_ANY_FLAG_USAGE, "any @Log"); @@ -269,7 +274,7 @@ public class HandleLog { /** * Handles the {@link lombok.extern.jbosslog.JBossLog} annotation for Eclipse. */ - @ProviderFor(EclipseAnnotationHandler.class) + @Provides public static class HandleJBossLog extends EclipseAnnotationHandler<lombok.extern.jbosslog.JBossLog> { @Override public void handle(AnnotationValues<lombok.extern.jbosslog.JBossLog> annotation, Annotation source, EclipseNode annotationNode) { handleFlagUsage(annotationNode, ConfigurationKeys.LOG_JBOSSLOG_FLAG_USAGE, "@JBossLog", ConfigurationKeys.LOG_ANY_FLAG_USAGE, "any @Log"); @@ -280,7 +285,7 @@ public class HandleLog { /** * Handles the {@link lombok.extern.flogger.Flogger} annotation for Eclipse. */ - @ProviderFor(EclipseAnnotationHandler.class) + @Provides public static class HandleFloggerLog extends EclipseAnnotationHandler<lombok.extern.flogger.Flogger> { @Override public void handle(AnnotationValues<lombok.extern.flogger.Flogger> annotation, Annotation source, EclipseNode annotationNode) { handleFlagUsage(annotationNode, ConfigurationKeys.LOG_FLOGGER_FLAG_USAGE, "@Flogger", ConfigurationKeys.LOG_ANY_FLAG_USAGE, "any @Log"); @@ -291,7 +296,7 @@ public class HandleLog { /** * Handles the {@link lombok.CustomLog} annotation for Eclipse. */ - @ProviderFor(EclipseAnnotationHandler.class) + @Provides public static class HandleCustomLog extends EclipseAnnotationHandler<lombok.CustomLog> { @Override public void handle(AnnotationValues<lombok.CustomLog> annotation, Annotation source, EclipseNode annotationNode) { handleFlagUsage(annotationNode, ConfigurationKeys.LOG_CUSTOM_FLAG_USAGE, "@CustomLog", ConfigurationKeys.LOG_ANY_FLAG_USAGE, "any @Log"); diff --git a/src/core/lombok/eclipse/handlers/HandleNonNull.java b/src/core/lombok/eclipse/handlers/HandleNonNull.java index 903d098b..365eef33 100644 --- a/src/core/lombok/eclipse/handlers/HandleNonNull.java +++ b/src/core/lombok/eclipse/handlers/HandleNonNull.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2019 The Project Lombok Authors. + * Copyright (C) 2013-2021 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 @@ -22,10 +22,12 @@ package lombok.eclipse.handlers; import static lombok.core.handlers.HandlerUtil.handleFlagUsage; -import static lombok.eclipse.Eclipse.isPrimitive; +import static lombok.eclipse.Eclipse.*; import static lombok.eclipse.handlers.EclipseHandlerUtil.*; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import org.eclipse.jdt.internal.compiler.ast.ASTNode; import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; @@ -35,31 +37,40 @@ import org.eclipse.jdt.internal.compiler.ast.Argument; import org.eclipse.jdt.internal.compiler.ast.AssertStatement; import org.eclipse.jdt.internal.compiler.ast.Assignment; import org.eclipse.jdt.internal.compiler.ast.Block; +import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; +import org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration; import org.eclipse.jdt.internal.compiler.ast.EqualExpression; +import org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall; import org.eclipse.jdt.internal.compiler.ast.Expression; +import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; +import org.eclipse.jdt.internal.compiler.ast.FieldReference; import org.eclipse.jdt.internal.compiler.ast.IfStatement; import org.eclipse.jdt.internal.compiler.ast.MessageSend; import org.eclipse.jdt.internal.compiler.ast.NullLiteral; +import org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference; import org.eclipse.jdt.internal.compiler.ast.SingleNameReference; +import org.eclipse.jdt.internal.compiler.ast.SingleTypeReference; import org.eclipse.jdt.internal.compiler.ast.Statement; import org.eclipse.jdt.internal.compiler.ast.SynchronizedStatement; +import org.eclipse.jdt.internal.compiler.ast.ThisReference; import org.eclipse.jdt.internal.compiler.ast.ThrowStatement; import org.eclipse.jdt.internal.compiler.ast.TryStatement; +import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.ast.TypeReference; -import org.mangosdk.spi.ProviderFor; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import lombok.ConfigurationKeys; import lombok.NonNull; import lombok.core.AST.Kind; import lombok.core.AnnotationValues; import lombok.core.HandlerPriority; -import lombok.eclipse.DeferUntilPostDiet; +import lombok.eclipse.EcjAugments; import lombok.eclipse.EclipseAST; import lombok.eclipse.EclipseAnnotationHandler; import lombok.eclipse.EclipseNode; +import lombok.spi.Provides; -@DeferUntilPostDiet -@ProviderFor(EclipseAnnotationHandler.class) +@Provides @HandlerPriority(value = 512) // 2^9; onParameter=@__(@NonNull) has to run first. public class HandleNonNull extends EclipseAnnotationHandler<NonNull> { private static final char[] REQUIRE_NON_NULL = "requireNonNull".toCharArray(); @@ -80,10 +91,163 @@ public class HandleNonNull extends EclipseAnnotationHandler<NonNull> { } } + private List<FieldDeclaration> getRecordComponents(EclipseNode typeNode) { + List<FieldDeclaration> list = new ArrayList<FieldDeclaration>(); + + for (EclipseNode child : typeNode.down()) { + if (child.getKind() == Kind.FIELD) { + FieldDeclaration fd = (FieldDeclaration) child.get(); + if ((fd.modifiers & AccRecord) != 0) list.add(fd); + } + } + + return list; + } + + private EclipseNode addCompactConstructorIfNeeded(EclipseNode typeNode, EclipseNode annotationNode) { + // explicit Compact Constructor has bits set: Bit32, IsCanonicalConstructor (10). + // implicit Compact Constructor has bits set: Bit32, IsCanonicalConstructor (10), and IsImplicit (11). + // explicit constructor with long-form shows up as a normal constructor (Bit32 set, that's all), but the + // implicit CC is then also present and will presumably be stripped out in some later phase. + + EclipseNode toRemove = null; + EclipseNode existingCompactConstructor = null; + List<FieldDeclaration> recordComponents = null; + for (EclipseNode child : typeNode.down()) { + if (!(child.get() instanceof ConstructorDeclaration)) continue; + ConstructorDeclaration cd = (ConstructorDeclaration) child.get(); + if ((cd.bits & IsCanonicalConstructor) != 0) { + if ((cd.bits & IsImplicit) != 0) { + toRemove = child; + } else { + existingCompactConstructor = child; + } + } else { + // If this constructor has exact matching types vs. the record components, + // this is the canonical constructor in long form and we should not generate one. + + if (recordComponents == null) recordComponents = getRecordComponents(typeNode); + int argLength = cd.arguments == null ? 0 : cd.arguments.length; + int compLength = recordComponents.size(); + boolean isCanonical = argLength == compLength; + if (isCanonical) top: for (int i = 0; i < argLength; i++) { + TypeReference a = recordComponents.get(i).type; + TypeReference b = cd.arguments[i] == null ? null : cd.arguments[i].type; + // technically this won't match e.g. `java.lang.String` to just `String`; + // to use this feature you'll need to use the same way to write it, which seems + // like a fair requirement. + char[][] ta = getRawTypeName(a); + char[][] tb = getRawTypeName(b); + if (ta == null || tb == null || ta.length != tb.length) { + isCanonical = false; + break top; + } + for (int j = 0; j < ta.length; j++) { + if (!Arrays.equals(ta[j], tb[j])) { + isCanonical = false; + break top; + } + } + } + if (isCanonical) { + return null; + } + } + } + if (existingCompactConstructor != null) return existingCompactConstructor; + int posToInsert = -1; + TypeDeclaration td = (TypeDeclaration) typeNode.get(); + if (toRemove != null) { + int idxToRemove = -1; + for (int i = 0; i < td.methods.length; i++) { + if (td.methods[i] == toRemove.get()) idxToRemove = i; + } + if (idxToRemove != -1) { + System.arraycopy(td.methods, idxToRemove + 1, td.methods, idxToRemove, td.methods.length - idxToRemove - 1); + posToInsert = td.methods.length - 1; + typeNode.removeChild(toRemove); + } + } + if (posToInsert == -1) { + AbstractMethodDeclaration[] na = new AbstractMethodDeclaration[td.methods.length + 1]; + posToInsert = td.methods.length; + System.arraycopy(td.methods, 0, na, 0, posToInsert); + td.methods = na; + } + + ConstructorDeclaration cd = new ConstructorDeclaration(((CompilationUnitDeclaration) typeNode.top().get()).compilationResult); + cd.modifiers = ClassFileConstants.AccPublic; + cd.bits = ASTNode.Bit32 | ECLIPSE_DO_NOT_TOUCH_FLAG | IsCanonicalConstructor; + cd.selector = td.name; + cd.constructorCall = new ExplicitConstructorCall(ExplicitConstructorCall.ImplicitSuper); + if (recordComponents == null) recordComponents = getRecordComponents(typeNode); + cd.arguments = new Argument[recordComponents.size()]; + cd.statements = new Statement[recordComponents.size()]; + cd.bits = IsCanonicalConstructor; + + for (int i = 0; i < cd.arguments.length; i++) { + FieldDeclaration cmp = recordComponents.get(i); + cd.arguments[i] = new Argument(cmp.name, cmp.sourceStart, cmp.type, 0); + cd.arguments[i].bits = ASTNode.IsArgument | ASTNode.IgnoreRawTypeCheck | ASTNode.IsReachable; + FieldReference lhs = new FieldReference(cmp.name, 0); + lhs.receiver = new ThisReference(0, 0); + SingleNameReference rhs = new SingleNameReference(cmp.name, 0); + cd.statements[i] = new Assignment(lhs, rhs, cmp.sourceEnd); + } + + setGeneratedBy(cd, annotationNode.get()); + for (int i = 0; i < cd.arguments.length; i++) { + FieldDeclaration cmp = recordComponents.get(i); + cd.arguments[i].sourceStart = cmp.sourceStart; + cd.arguments[i].sourceEnd = cmp.sourceStart; + cd.arguments[i].declarationSourceEnd = cmp.sourceStart; + cd.arguments[i].declarationEnd = cmp.sourceStart; + } + + td.methods[posToInsert] = cd; + cd.annotations = addSuppressWarningsAll(typeNode, cd, cd.annotations); + cd.annotations = addGenerated(typeNode, cd, cd.annotations); + return typeNode.add(cd, Kind.METHOD); + } + + private static char[][] getRawTypeName(TypeReference a) { + if (a instanceof QualifiedTypeReference) return ((QualifiedTypeReference) a).tokens; + if (a instanceof SingleTypeReference) return new char[][] {((SingleTypeReference) a).token}; + return null; + } + @Override public void handle(AnnotationValues<NonNull> annotation, Annotation ast, EclipseNode annotationNode) { + // Generating new methods is only possible during diet parse but modifying existing methods requires a full parse. + // As we need both for @NonNull we reset the handled flag during diet parse. + + if (!annotationNode.isCompleteParse()) { + if (annotationNode.up().getKind() == Kind.FIELD) { + //Check if this is a record and we need to generate the compact form constructor. + EclipseNode typeNode = annotationNode.up().up(); + if (typeNode.getKind() == Kind.TYPE) { + if (isRecord(typeNode)) { + addCompactConstructorIfNeeded(typeNode, annotationNode); + } + } + } + + EcjAugments.ASTNode_handled.clear(ast); + return; + } + handle0(ast, annotationNode, false); } + private EclipseNode findCompactConstructor(EclipseNode typeNode) { + for (EclipseNode child : typeNode.down()) { + if (!(child.get() instanceof ConstructorDeclaration)) continue; + ConstructorDeclaration cd = (ConstructorDeclaration) child.get(); + if ((cd.bits & IsCanonicalConstructor) != 0 && (cd.bits & IsImplicit) == 0) return child; + } + + return null; + } + private void handle0(Annotation ast, EclipseNode annotationNode, boolean force) { handleFlagUsage(annotationNode, ConfigurationKeys.NON_NULL_FLAG_USAGE, "@NonNull"); @@ -92,13 +256,26 @@ public class HandleNonNull extends EclipseAnnotationHandler<NonNull> { // but in that case those handlers will take care of it. However, we DO check if the annotation is applied to // a primitive, because those handlers trigger on any annotation named @NonNull and we only want the warning // behaviour on _OUR_ 'lombok.NonNull'. + EclipseNode fieldNode = annotationNode.up(); + EclipseNode typeNode = fieldNode.up(); try { if (isPrimitive(((AbstractVariableDeclaration) annotationNode.up().get()).type)) { annotationNode.addWarning("@NonNull is meaningless on a primitive."); + return; } } catch (Exception ignore) {} + if (isRecord(typeNode)) { + // well, these kinda double as parameters (of the compact constructor), so we do some work here. + // NB:Tthe diet parse run already added an explicit compact constructor if we need to take any actions. + EclipseNode compactConstructor = findCompactConstructor(typeNode); + + if (compactConstructor != null) { + addNullCheckIfNeeded((AbstractMethodDeclaration) compactConstructor.get(), (AbstractVariableDeclaration) fieldNode.get(), annotationNode); + } + } + return; } @@ -140,6 +317,11 @@ public class HandleNonNull extends EclipseAnnotationHandler<NonNull> { return; } + addNullCheckIfNeeded(declaration, param, annotationNode); + paramNode.up().rebuild(); + } + + private void addNullCheckIfNeeded(AbstractMethodDeclaration declaration, AbstractVariableDeclaration param, EclipseNode annotationNode) { // Possibly, if 'declaration instanceof ConstructorDeclaration', fetch declaration.constructorCall, search it for any references to our parameter, // and if they exist, create a new method in the class: 'private static <T> T lombok$nullCheck(T expr, String msg) {if (expr == null) throw NPE; return expr;}' and // wrap all references to it in the super/this to a call to this method. @@ -188,7 +370,6 @@ public class HandleNonNull extends EclipseAnnotationHandler<NonNull> { newStatements[skipOver] = nullCheck; declaration.statements = newStatements; } - paramNode.up().rebuild(); } public boolean isNullCheck(Statement stat) { diff --git a/src/core/lombok/eclipse/handlers/HandlePrintAST.java b/src/core/lombok/eclipse/handlers/HandlePrintAST.java index 234e29b8..9cc3e1ae 100644 --- a/src/core/lombok/eclipse/handlers/HandlePrintAST.java +++ b/src/core/lombok/eclipse/handlers/HandlePrintAST.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2014 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -26,7 +26,6 @@ import java.io.FileNotFoundException; import java.io.PrintStream; import org.eclipse.jdt.internal.compiler.ast.Annotation; -import org.mangosdk.spi.ProviderFor; import lombok.Lombok; import lombok.core.AnnotationValues; @@ -36,11 +35,12 @@ import lombok.eclipse.DeferUntilPostDiet; import lombok.eclipse.EclipseASTVisitor; import lombok.eclipse.EclipseAnnotationHandler; import lombok.eclipse.EclipseNode; +import lombok.spi.Provides; /** * Handles the {@code lombok.core.PrintAST} annotation for eclipse. */ -@ProviderFor(EclipseAnnotationHandler.class) +@Provides @DeferUntilPostDiet @HandlerPriority(536870912) // 2^29; this handler is customarily run at the very end. public class HandlePrintAST extends EclipseAnnotationHandler<PrintAST> { diff --git a/src/core/lombok/eclipse/handlers/HandleSetter.java b/src/core/lombok/eclipse/handlers/HandleSetter.java index 83c6eef2..ddae21fb 100644 --- a/src/core/lombok/eclipse/handlers/HandleSetter.java +++ b/src/core/lombok/eclipse/handlers/HandleSetter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2019 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -38,6 +38,7 @@ import lombok.core.configuration.CheckerFrameworkVersion; import lombok.core.AnnotationValues; import lombok.eclipse.EclipseAnnotationHandler; import lombok.eclipse.EclipseNode; +import lombok.spi.Provides; import org.eclipse.jdt.internal.compiler.ast.ASTNode; import org.eclipse.jdt.internal.compiler.ast.Annotation; @@ -56,13 +57,14 @@ import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.ast.TypeReference; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.lookup.TypeIds; -import org.mangosdk.spi.ProviderFor; /** * Handles the {@code lombok.Setter} annotation for eclipse. */ -@ProviderFor(EclipseAnnotationHandler.class) +@Provides public class HandleSetter extends EclipseAnnotationHandler<Setter> { + private static final String SETTER_NODE_NOT_SUPPORTED_ERR = "@Setter is only supported on a class or a field."; + public boolean generateSetterForType(EclipseNode typeNode, EclipseNode pos, AccessLevel level, boolean checkForTypeLevelSetter, List<Annotation> onMethod, List<Annotation> onParam) { if (checkForTypeLevelSetter) { if (hasAnnotation(Setter.class, typeNode)) { @@ -71,14 +73,8 @@ public class HandleSetter extends EclipseAnnotationHandler<Setter> { } } - TypeDeclaration typeDecl = null; - if (typeNode.get() instanceof TypeDeclaration) typeDecl = (TypeDeclaration) typeNode.get(); - int modifiers = typeDecl == null ? 0 : typeDecl.modifiers; - boolean notAClass = (modifiers & - (ClassFileConstants.AccInterface | ClassFileConstants.AccAnnotation | ClassFileConstants.AccEnum)) != 0; - - if (typeDecl == null || notAClass) { - pos.addError("@Setter is only supported on a class or a field."); + if (!isClass(typeNode)) { + pos.addError(SETTER_NODE_NOT_SUPPORTED_ERR); return false; } @@ -148,7 +144,7 @@ public class HandleSetter extends EclipseAnnotationHandler<Setter> { ASTNode source = sourceNode.get(); if (fieldNode.getKind() != Kind.FIELD) { - sourceNode.addError("@Setter is only supported on a class or a field."); + sourceNode.addError(SETTER_NODE_NOT_SUPPORTED_ERR); return; } diff --git a/src/core/lombok/eclipse/handlers/HandleSneakyThrows.java b/src/core/lombok/eclipse/handlers/HandleSneakyThrows.java index 481dbcde..5f0ca3fb 100644 --- a/src/core/lombok/eclipse/handlers/HandleSneakyThrows.java +++ b/src/core/lombok/eclipse/handlers/HandleSneakyThrows.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2014 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -36,6 +36,7 @@ import lombok.core.HandlerPriority; import lombok.eclipse.DeferUntilPostDiet; import lombok.eclipse.EclipseAnnotationHandler; import lombok.eclipse.EclipseNode; +import lombok.spi.Provides; import org.eclipse.jdt.internal.compiler.ast.ASTNode; import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; @@ -56,12 +57,11 @@ import org.eclipse.jdt.internal.compiler.ast.Statement; import org.eclipse.jdt.internal.compiler.ast.ThrowStatement; import org.eclipse.jdt.internal.compiler.ast.TryStatement; import org.eclipse.jdt.internal.compiler.ast.TypeReference; -import org.mangosdk.spi.ProviderFor; /** * Handles the {@code lombok.HandleSneakyThrows} annotation for eclipse. */ -@ProviderFor(EclipseAnnotationHandler.class) +@Provides @DeferUntilPostDiet @HandlerPriority(value = 1024) // 2^10; @NonNull must have run first, so that we wrap around the statements generated by it. public class HandleSneakyThrows extends EclipseAnnotationHandler<SneakyThrows> { diff --git a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java index ad7d3fd6..4d5d2448 100644 --- a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2020 The Project Lombok Authors. + * Copyright (C) 2013-2021 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 @@ -50,6 +50,7 @@ import org.eclipse.jdt.internal.compiler.ast.FalseLiteral; import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; import org.eclipse.jdt.internal.compiler.ast.FieldReference; import org.eclipse.jdt.internal.compiler.ast.IfStatement; +import org.eclipse.jdt.internal.compiler.ast.Initializer; import org.eclipse.jdt.internal.compiler.ast.MessageSend; import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration; import org.eclipse.jdt.internal.compiler.ast.NullLiteral; @@ -74,7 +75,6 @@ import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers; import org.eclipse.jdt.internal.compiler.lookup.MethodScope; import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; import org.eclipse.jdt.internal.compiler.lookup.TypeIds; -import org.mangosdk.spi.ProviderFor; import lombok.AccessLevel; import lombok.Builder; @@ -100,8 +100,9 @@ import lombok.eclipse.handlers.HandleBuilder.BuilderFieldData; import lombok.eclipse.handlers.HandleBuilder.BuilderJob; import lombok.experimental.NonFinal; import lombok.experimental.SuperBuilder; +import lombok.spi.Provides; -@ProviderFor(EclipseAnnotationHandler.class) +@Provides @HandlerPriority(-1024) //-2^10; to ensure we've picked up @FieldDefault's changes (-2048) but @Value hasn't removed itself yet (-512), so that we can error on presence of it on the builder classes. public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> { private static final char[] SELF_METHOD_NAME = "self".toCharArray(); @@ -179,10 +180,11 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> { List<EclipseNode> nonFinalNonDefaultedFields = null; - if (!(parent.get() instanceof TypeDeclaration)) { - annotationNode.addError("@SuperBuilder is only supported on types."); + if (!isClass(parent)) { + annotationNode.addError("@SuperBuilder is only supported on classes."); return; } + job.parentType = parent; TypeDeclaration td = (TypeDeclaration) parent.get(); @@ -608,6 +610,9 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> { } constructor.statements = statements.isEmpty() ? null : statements.toArray(new Statement[0]); + if (job.checkerFramework.generateSideEffectFree()) { + constructor.annotations = new Annotation[] {generateNamedAnnotation(job.source, CheckerFrameworkVersion.NAME__SIDE_EFFECT_FREE)}; + } constructor.traverse(new SetGeneratedByVisitor(job.source), typeDeclaration.scope); @@ -637,6 +642,9 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> { AllocationExpression invoke = new AllocationExpression(); invoke.type = namePlusTypeParamsToTypeReference(job.parentType, job.builderImplClassNameArr, false, job.typeParams, p); out.statements = new Statement[] {new ReturnStatement(invoke, pS, pE)}; + if (job.checkerFramework.generateSideEffectFree()) { + out.annotations = new Annotation[] {generateNamedAnnotation(job.source, CheckerFrameworkVersion.NAME__SIDE_EFFECT_FREE)}; + } createRelevantNonNullAnnotation(job.parentType, out); out.traverse(new SetGeneratedByVisitor(job.source), ((TypeDeclaration) job.parentType.get()).scope); @@ -675,6 +683,9 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> { invokeFillMethod.selector = FILL_VALUES_METHOD_NAME; invokeFillMethod.arguments = new Expression[] {new ThisReference(0, 0)}; out.statements = new Statement[] {new ReturnStatement(invokeFillMethod, pS, pE)}; + if (job.checkerFramework.generateSideEffectFree()) { + out.annotations = new Annotation[] {generateNamedAnnotation(job.source, CheckerFrameworkVersion.NAME__SIDE_EFFECT_FREE)}; + } createRelevantNonNullAnnotation(job.parentType, out); out.traverse(new SetGeneratedByVisitor(job.source), ((TypeDeclaration) job.parentType.get()).scope); @@ -809,9 +820,7 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> { ms.arguments = tgt; } else { Expression ifNull = new EqualExpression(tgt[0], new NullLiteral(0, 0), OperatorIds.EQUAL_EQUAL); - MessageSend emptyCollection = new MessageSend(); - emptyCollection.receiver = generateQualifiedNameRef(source, bfd.singularData.getSingularizer().getEmptyMakerReceiver(bfd.singularData.getTargetFqn())); - emptyCollection.selector = bfd.singularData.getSingularizer().getEmptyMakerSelector(bfd.singularData.getTargetFqn()); + MessageSend emptyCollection = bfd.singularData.getSingularizer().getEmptyExpression(bfd.singularData.getTargetFqn(), bfd.singularData, type, source); ms.arguments = new Expression[] {new ConditionalExpression(ifNull, emptyCollection, tgt[1])}; } ms.receiver = new SingleNameReference(BUILDER_VARIABLE_NAME, 0); @@ -1095,6 +1104,7 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> { // 3. Add used type names. if (td.fields != null) { for (FieldDeclaration field : td.fields) { + if (field instanceof Initializer) continue; char[][] typeName = field.type.getTypeName(); if (typeName.length >= 1) // Add the first token, because only that can collide. usedNames.add(String.valueOf(typeName[0])); @@ -1197,7 +1207,7 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> { if ((def.bits & ASTNode.IsDefaultConstructor) != 0) continue; if (!def.isConstructor()) continue; if (isTolerate(type, def)) continue; - if (def.arguments.length != 1) continue; + if (def.arguments == null || def.arguments.length != 1) continue; // Cannot use typeMatches() here, because the parameter could be fully-qualified, partially-qualified, or not qualified. // A string-compare of the last part should work. If it's a false-positive, users could still @Tolerate it. diff --git a/src/core/lombok/eclipse/handlers/HandleSynchronized.java b/src/core/lombok/eclipse/handlers/HandleSynchronized.java index 08d00d91..18d1e7b7 100644 --- a/src/core/lombok/eclipse/handlers/HandleSynchronized.java +++ b/src/core/lombok/eclipse/handlers/HandleSynchronized.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2020 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -36,6 +36,7 @@ import lombok.eclipse.DeferUntilPostDiet; import lombok.eclipse.EclipseAnnotationHandler; import lombok.eclipse.EclipseNode; import lombok.eclipse.handlers.EclipseHandlerUtil.MemberExistsResult; +import lombok.spi.Provides; import org.eclipse.jdt.internal.compiler.ast.Annotation; import org.eclipse.jdt.internal.compiler.ast.ArrayAllocationExpression; @@ -51,12 +52,11 @@ import org.eclipse.jdt.internal.compiler.ast.SynchronizedStatement; import org.eclipse.jdt.internal.compiler.ast.ThisReference; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; -import org.mangosdk.spi.ProviderFor; /** * Handles the {@code lombok.Synchronized} annotation for eclipse. */ -@ProviderFor(EclipseAnnotationHandler.class) +@Provides @DeferUntilPostDiet @HandlerPriority(value = 1024) // 2^10; @NonNull must have run first, so that we wrap around the statements generated by it. public class HandleSynchronized extends EclipseAnnotationHandler<Synchronized> { @@ -148,6 +148,11 @@ public class HandleSynchronized extends EclipseAnnotationHandler<Synchronized> { return; } + EclipseNode typeNode = upToTypeNode(annotationNode); + if (!isClassOrEnum(typeNode)) { + annotationNode.addError("@Synchronized is legal only on methods in classes and enums."); + return; + } boolean[] isStatic = { method.isStatic() }; char[] lockName = createLockField(annotation, annotationNode, isStatic, true); if (lockName == null) return; @@ -163,7 +168,6 @@ public class HandleSynchronized extends EclipseAnnotationHandler<Synchronized> { Expression lockVariable; if (isStatic[0]) { - EclipseNode typeNode = upToTypeNode(annotationNode); char[][] n = getQualifiedInnerName(typeNode, lockName); long[] ps = new long[n.length]; Arrays.fill(ps, pos); diff --git a/src/core/lombok/eclipse/handlers/HandleToString.java b/src/core/lombok/eclipse/handlers/HandleToString.java index a6bcb24f..72491277 100644 --- a/src/core/lombok/eclipse/handlers/HandleToString.java +++ b/src/core/lombok/eclipse/handlers/HandleToString.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2020 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -50,9 +50,7 @@ import org.eclipse.jdt.internal.compiler.ast.SuperReference; import org.eclipse.jdt.internal.compiler.ast.ThisReference; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.ast.TypeReference; -import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; -import org.mangosdk.spi.ProviderFor; import lombok.AccessLevel; import lombok.ConfigurationKeys; @@ -67,11 +65,12 @@ import lombok.core.handlers.InclusionExclusionUtils.Included; import lombok.eclipse.Eclipse; import lombok.eclipse.EclipseAnnotationHandler; import lombok.eclipse.EclipseNode; +import lombok.spi.Provides; /** * Handles the {@code ToString} annotation for eclipse. */ -@ProviderFor(EclipseAnnotationHandler.class) +@Provides public class HandleToString extends EclipseAnnotationHandler<ToString> { public void handle(AnnotationValues<ToString> annotation, Annotation ast, EclipseNode annotationNode) { handleFlagUsage(annotationNode, ConfigurationKeys.TO_STRING_FLAG_USAGE, "@ToString"); @@ -116,14 +115,7 @@ public class HandleToString extends EclipseAnnotationHandler<ToString> { public void generateToString(EclipseNode typeNode, EclipseNode errorNode, List<Included<EclipseNode, ToString.Include>> members, boolean includeFieldNames, Boolean callSuper, boolean whineIfExists, FieldAccess fieldAccess) { - TypeDeclaration typeDecl = null; - - if (typeNode.get() instanceof TypeDeclaration) typeDecl = (TypeDeclaration) typeNode.get(); - int modifiers = typeDecl == null ? 0 : typeDecl.modifiers; - boolean notAClass = (modifiers & - (ClassFileConstants.AccInterface | ClassFileConstants.AccAnnotation)) != 0; - - if (typeDecl == null || notAClass) { + if (!isClassOrEnum(typeNode)) { errorNode.addError("@ToString is only supported on a class or enum."); return; } diff --git a/src/core/lombok/eclipse/handlers/HandleUtilityClass.java b/src/core/lombok/eclipse/handlers/HandleUtilityClass.java index 2349f839..9a18b20b 100644 --- a/src/core/lombok/eclipse/handlers/HandleUtilityClass.java +++ b/src/core/lombok/eclipse/handlers/HandleUtilityClass.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015-2020 The Project Lombok Authors. + * Copyright (C) 2015-2021 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 @@ -25,8 +25,6 @@ import static lombok.core.handlers.HandlerUtil.*; import static lombok.eclipse.Eclipse.*; import static lombok.eclipse.handlers.EclipseHandlerUtil.*; -import java.util.Arrays; - import org.eclipse.jdt.internal.compiler.ast.ASTNode; import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; import org.eclipse.jdt.internal.compiler.ast.AllocationExpression; @@ -45,7 +43,6 @@ import org.eclipse.jdt.internal.compiler.ast.ThrowStatement; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; -import org.mangosdk.spi.ProviderFor; import lombok.ConfigurationKeys; import lombok.core.AnnotationValues; @@ -54,12 +51,13 @@ import lombok.core.AST.Kind; import lombok.eclipse.EclipseAnnotationHandler; import lombok.eclipse.EclipseNode; import lombok.experimental.UtilityClass; +import lombok.spi.Provides; /** * Handles the {@code lombok.experimental.UtilityClass} annotation for eclipse. */ +@Provides @HandlerPriority(-4096) //-2^12; to ensure @FieldDefaults picks up on the 'static' we set here. -@ProviderFor(EclipseAnnotationHandler.class) public class HandleUtilityClass extends EclipseAnnotationHandler<UtilityClass> { @Override public void handle(AnnotationValues<UtilityClass> annotation, Annotation ast, EclipseNode annotationNode) { handleFlagUsage(annotationNode, ConfigurationKeys.UTILITY_CLASS_FLAG_USAGE, "@UtilityClass"); @@ -70,13 +68,8 @@ public class HandleUtilityClass extends EclipseAnnotationHandler<UtilityClass> { } private static boolean checkLegality(EclipseNode typeNode, EclipseNode errorNode) { - TypeDeclaration typeDecl = null; - if (typeNode.get() instanceof TypeDeclaration) typeDecl = (TypeDeclaration) typeNode.get(); - int modifiers = typeDecl == null ? 0 : typeDecl.modifiers; - boolean notAClass = (modifiers & (ClassFileConstants.AccInterface | ClassFileConstants.AccAnnotation | ClassFileConstants.AccEnum)) != 0; - - if (typeDecl == null || notAClass) { - errorNode.addError("@UtilityClass is only supported on a class (can't be an interface, enum, or annotation)."); + if (!isClass(typeNode)) { + errorNode.addError("@UtilityClass is only supported on a class."); return false; } @@ -158,37 +151,28 @@ public class HandleUtilityClass extends EclipseAnnotationHandler<UtilityClass> { ASTNode source = sourceNode.get(); TypeDeclaration typeDeclaration = ((TypeDeclaration) typeNode.get()); - long p = (long) source.sourceStart << 32 | source.sourceEnd; ConstructorDeclaration constructor = new ConstructorDeclaration(((CompilationUnitDeclaration) typeNode.top().get()).compilationResult); constructor.modifiers = ClassFileConstants.AccPrivate; constructor.selector = typeDeclaration.name; constructor.constructorCall = new ExplicitConstructorCall(ExplicitConstructorCall.ImplicitSuper); - constructor.constructorCall.sourceStart = source.sourceStart; - constructor.constructorCall.sourceEnd = source.sourceEnd; constructor.thrownExceptions = null; constructor.typeParameters = null; constructor.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG; - constructor.bodyStart = constructor.declarationSourceStart = constructor.sourceStart = source.sourceStart; - constructor.bodyEnd = constructor.declarationSourceEnd = constructor.sourceEnd = source.sourceEnd; constructor.arguments = null; - AllocationExpression exception = new AllocationExpression(); - setGeneratedBy(exception, source); long[] ps = new long[JAVA_LANG_UNSUPPORTED_OPERATION_EXCEPTION.length]; - Arrays.fill(ps, p); + AllocationExpression exception = new AllocationExpression(); exception.type = new QualifiedTypeReference(JAVA_LANG_UNSUPPORTED_OPERATION_EXCEPTION, ps); - setGeneratedBy(exception.type, source); exception.arguments = new Expression[] { - new StringLiteral(UNSUPPORTED_MESSAGE, source.sourceStart, source.sourceEnd, 0) + new StringLiteral(UNSUPPORTED_MESSAGE, 0, 0, 0) }; - setGeneratedBy(exception.arguments[0], source); - ThrowStatement throwStatement = new ThrowStatement(exception, source.sourceStart, source.sourceEnd); - setGeneratedBy(throwStatement, source); + ThrowStatement throwStatement = new ThrowStatement(exception, 0, 0); constructor.statements = new Statement[] {throwStatement}; + constructor.traverse(new SetGeneratedByVisitor(source), typeDeclaration.scope); injectMethod(typeNode, constructor); } } diff --git a/src/core/lombok/eclipse/handlers/HandleVal.java b/src/core/lombok/eclipse/handlers/HandleVal.java index 3742ac00..ac53e27e 100644 --- a/src/core/lombok/eclipse/handlers/HandleVal.java +++ b/src/core/lombok/eclipse/handlers/HandleVal.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2018 The Project Lombok Authors. + * Copyright (C) 2010-2021 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 @@ -31,6 +31,7 @@ import lombok.eclipse.DeferUntilPostDiet; import lombok.eclipse.EclipseASTAdapter; import lombok.eclipse.EclipseASTVisitor; import lombok.eclipse.EclipseNode; +import lombok.spi.Provides; import org.eclipse.jdt.internal.compiler.ast.ASTNode; import org.eclipse.jdt.internal.compiler.ast.ArrayInitializer; @@ -39,12 +40,11 @@ import org.eclipse.jdt.internal.compiler.ast.ForeachStatement; import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration; import org.eclipse.jdt.internal.compiler.ast.NullLiteral; import org.eclipse.jdt.internal.compiler.ast.TypeReference; -import org.mangosdk.spi.ProviderFor; /* * This class just handles 3 basic error cases. The real meat of eclipse 'val' support is in {@code PatchVal} and {@code PatchValEclipse}. */ -@ProviderFor(EclipseASTVisitor.class) +@Provides(EclipseASTVisitor.class) @DeferUntilPostDiet @HandlerPriority(65536) // 2^16; resolution needs to work, so if the RHS expression is i.e. a call to a generated getter, we have to run after that getter has been generated. public class HandleVal extends EclipseASTAdapter { diff --git a/src/core/lombok/eclipse/handlers/HandleValue.java b/src/core/lombok/eclipse/handlers/HandleValue.java index 2e0338a8..7a73e5ed 100644 --- a/src/core/lombok/eclipse/handlers/HandleValue.java +++ b/src/core/lombok/eclipse/handlers/HandleValue.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2014 The Project Lombok Authors. + * Copyright (C) 2012-2021 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 @@ -34,17 +34,17 @@ import lombok.eclipse.EclipseAnnotationHandler; import lombok.eclipse.EclipseNode; import lombok.eclipse.handlers.HandleConstructor.SkipIfConstructorExists; import lombok.experimental.NonFinal; +import lombok.spi.Provides; import lombok.Value; import org.eclipse.jdt.internal.compiler.ast.Annotation; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; -import org.mangosdk.spi.ProviderFor; /** * Handles the {@code lombok.Value} annotation for eclipse. */ -@ProviderFor(EclipseAnnotationHandler.class) +@Provides @HandlerPriority(-512) //-2^9; to ensure @EqualsAndHashCode and such pick up on this handler making the class final and messing with the fields' access levels, run earlier. public class HandleValue extends EclipseAnnotationHandler<Value> { private HandleFieldDefaults handleFieldDefaults = new HandleFieldDefaults(); @@ -59,16 +59,11 @@ public class HandleValue extends EclipseAnnotationHandler<Value> { Value ann = annotation.getInstance(); EclipseNode typeNode = annotationNode.up(); - TypeDeclaration typeDecl = null; - if (typeNode.get() instanceof TypeDeclaration) typeDecl = (TypeDeclaration) typeNode.get(); - int modifiers = typeDecl == null ? 0 : typeDecl.modifiers; - boolean notAClass = (modifiers & - (ClassFileConstants.AccInterface | ClassFileConstants.AccAnnotation | ClassFileConstants.AccEnum)) != 0; - - if (typeDecl == null || notAClass) { + if (!isClass(typeNode)) { annotationNode.addError("@Value is only supported on a class."); return; } + TypeDeclaration typeDecl = (TypeDeclaration) typeNode.get(); // Make class final. if (!hasAnnotation(NonFinal.class, typeNode)) { diff --git a/src/core/lombok/eclipse/handlers/HandleWith.java b/src/core/lombok/eclipse/handlers/HandleWith.java index dce193d8..bfad682b 100644 --- a/src/core/lombok/eclipse/handlers/HandleWith.java +++ b/src/core/lombok/eclipse/handlers/HandleWith.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2020 The Project Lombok Authors. + * Copyright (C) 2012-2021 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 @@ -38,6 +38,7 @@ import lombok.core.configuration.CheckerFrameworkVersion; import lombok.core.AnnotationValues; import lombok.eclipse.EclipseAnnotationHandler; import lombok.eclipse.EclipseNode; +import lombok.spi.Provides; import org.eclipse.jdt.internal.compiler.ast.ASTNode; import org.eclipse.jdt.internal.compiler.ast.AllocationExpression; @@ -57,9 +58,8 @@ import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.ast.TypeReference; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers; -import org.mangosdk.spi.ProviderFor; -@ProviderFor(EclipseAnnotationHandler.class) +@Provides public class HandleWith extends EclipseAnnotationHandler<With> { public boolean generateWithForType(EclipseNode typeNode, EclipseNode pos, AccessLevel level, boolean checkForTypeLevelWith) { if (checkForTypeLevelWith) { diff --git a/src/core/lombok/eclipse/handlers/HandleWithBy.java b/src/core/lombok/eclipse/handlers/HandleWithBy.java index f56004f6..a8d13a84 100644 --- a/src/core/lombok/eclipse/handlers/HandleWithBy.java +++ b/src/core/lombok/eclipse/handlers/HandleWithBy.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 The Project Lombok Authors. + * Copyright (C) 2020-2021 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 @@ -51,7 +51,6 @@ import org.eclipse.jdt.internal.compiler.ast.Wildcard; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers; import org.eclipse.jdt.internal.compiler.lookup.TypeIds; -import org.mangosdk.spi.ProviderFor; import lombok.AccessLevel; import lombok.ConfigurationKeys; @@ -63,8 +62,9 @@ import lombok.eclipse.Eclipse; import lombok.eclipse.EclipseAnnotationHandler; import lombok.eclipse.EclipseNode; import lombok.experimental.WithBy; +import lombok.spi.Provides; -@ProviderFor(EclipseAnnotationHandler.class) +@Provides public class HandleWithBy extends EclipseAnnotationHandler<WithBy> { public boolean generateWithByForType(EclipseNode typeNode, EclipseNode pos, AccessLevel level, boolean checkForTypeLevelWithBy) { if (checkForTypeLevelWithBy) { diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaMapSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaMapSingularizer.java index 5956c01b..088a4506 100644 --- a/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaMapSingularizer.java +++ b/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaMapSingularizer.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 The Project Lombok Authors. + * Copyright (C) 2015-2021 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 @@ -21,12 +21,11 @@ */ package lombok.eclipse.handlers.singulars; -import org.mangosdk.spi.ProviderFor; - import lombok.core.LombokImmutableList; import lombok.eclipse.handlers.EclipseSingularsRecipes.EclipseSingularizer; +import lombok.spi.Provides; -@ProviderFor(EclipseSingularizer.class) +@Provides(EclipseSingularizer.class) public class EclipseGuavaMapSingularizer extends EclipseGuavaSingularizer { // TODO cgcc.ImmutableMultimap, cgcc.ImmutableListMultimap, cgcc.ImmutableSetMultimap // TODO cgcc.ImmutableClassToInstanceMap diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSetListSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSetListSingularizer.java index 326a9179..1f3603da 100644 --- a/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSetListSingularizer.java +++ b/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSetListSingularizer.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 The Project Lombok Authors. + * Copyright (C) 2015-2021 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 @@ -21,12 +21,11 @@ */ package lombok.eclipse.handlers.singulars; -import org.mangosdk.spi.ProviderFor; - import lombok.core.LombokImmutableList; import lombok.eclipse.handlers.EclipseSingularsRecipes.EclipseSingularizer; +import lombok.spi.Provides; -@ProviderFor(EclipseSingularizer.class) +@Provides(EclipseSingularizer.class) public class EclipseGuavaSetListSingularizer extends EclipseGuavaSingularizer { // TODO com.google.common.collect.ImmutableRangeSet // TODO com.google.common.collect.ImmutableMultiset and com.google.common.collect.ImmutableSortedMultiset diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSingularizer.java index 395d2e59..7dcf18c9 100755 --- a/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSingularizer.java +++ b/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSingularizer.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015-2020 The Project Lombok Authors. + * Copyright (C) 2015-2021 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 @@ -279,7 +279,7 @@ abstract class EclipseGuavaSingularizer extends EclipseSingularizer { protected abstract String getAddMethodName(); protected abstract String getAddAllTypeName(); - protected int getTypeArgumentsCount() { + @Override protected int getTypeArgumentsCount() { return getArgumentSuffixes().size(); } } diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaTableSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaTableSingularizer.java index 4d25811b..ee92ad5a 100644 --- a/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaTableSingularizer.java +++ b/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaTableSingularizer.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 The Project Lombok Authors. + * Copyright (C) 2015-2021 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 @@ -21,12 +21,11 @@ */ package lombok.eclipse.handlers.singulars; -import org.mangosdk.spi.ProviderFor; - import lombok.core.LombokImmutableList; import lombok.eclipse.handlers.EclipseSingularsRecipes.EclipseSingularizer; +import lombok.spi.Provides; -@ProviderFor(EclipseSingularizer.class) +@Provides(EclipseSingularizer.class) public class EclipseGuavaTableSingularizer extends EclipseGuavaSingularizer { private static final LombokImmutableList<String> SUFFIXES = LombokImmutableList.of("rowKey", "columnKey", "value"); diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSetSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSetSingularizer.java index deab4530..882b7adc 100755 --- a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSetSingularizer.java +++ b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSetSingularizer.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015-2020 The Project Lombok Authors. + * Copyright (C) 2015-2021 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 @@ -156,7 +156,7 @@ abstract class EclipseJavaUtilListSetSingularizer extends EclipseJavaUtilSingula Annotation[] selfReturnAnnotations = generateSelfReturnAnnotations(deprecate, cfv, data.getSource()); Annotation[] copyToSetterAnnotations = copyAnnotations(md, findCopyableToBuilderSingularSetterAnnotations(data.getAnnotation().up())); md.annotations = concat(selfReturnAnnotations, copyToSetterAnnotations, Annotation.class); - + if (returnStatement != null) createRelevantNonNullAnnotation(builderType, md); data.setGeneratedByRecursive(md); HandleNonNull.INSTANCE.fix(injectMethod(builderType, md)); @@ -194,9 +194,13 @@ abstract class EclipseJavaUtilListSetSingularizer extends EclipseJavaUtilSingula Annotation[] selfReturnAnnotations = generateSelfReturnAnnotations(deprecate, cfv, data.getSource()); Annotation[] copyToSetterAnnotations = copyAnnotations(md, findCopyableToSetterAnnotations(data.getAnnotation().up())); md.annotations = concat(selfReturnAnnotations, copyToSetterAnnotations, Annotation.class); - + if (returnStatement != null) createRelevantNonNullAnnotation(builderType, md); data.setGeneratedByRecursive(md); injectMethod(builderType, md); } + + @Override protected int getTypeArgumentsCount() { + return 1; + } } diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSingularizer.java index bf50aef6..0d0f3130 100755 --- a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSingularizer.java +++ b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSingularizer.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015-2019 The Project Lombok Authors. + * Copyright (C) 2015-2021 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 @@ -31,6 +31,7 @@ import lombok.eclipse.Eclipse; import lombok.eclipse.EclipseNode; import lombok.eclipse.handlers.EclipseSingularsRecipes.EclipseSingularizer; import lombok.eclipse.handlers.EclipseSingularsRecipes.SingularData; +import lombok.spi.Provides; import org.eclipse.jdt.internal.compiler.ast.AllocationExpression; import org.eclipse.jdt.internal.compiler.ast.Assignment; @@ -45,10 +46,8 @@ import org.eclipse.jdt.internal.compiler.ast.SingleNameReference; import org.eclipse.jdt.internal.compiler.ast.Statement; import org.eclipse.jdt.internal.compiler.ast.SwitchStatement; import org.eclipse.jdt.internal.compiler.ast.TypeReference; -import org.mangosdk.spi.ProviderFor; - -@ProviderFor(EclipseSingularizer.class) +@Provides(EclipseSingularizer.class) public class EclipseJavaUtilListSingularizer extends EclipseJavaUtilListSetSingularizer { @Override public LombokImmutableList<String> getSupportedTypes() { return LombokImmutableList.of("java.util.List", "java.util.Collection", "java.lang.Iterable"); diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilMapSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilMapSingularizer.java index 1a40369d..a766612f 100755 --- a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilMapSingularizer.java +++ b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilMapSingularizer.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015-2020 The Project Lombok Authors. + * Copyright (C) 2015-2021 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 @@ -50,7 +50,6 @@ import org.eclipse.jdt.internal.compiler.ast.Statement; import org.eclipse.jdt.internal.compiler.ast.ThisReference; import org.eclipse.jdt.internal.compiler.ast.TypeReference; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; -import org.mangosdk.spi.ProviderFor; import lombok.AccessLevel; import lombok.core.LombokImmutableList; @@ -62,8 +61,9 @@ import lombok.eclipse.handlers.EclipseSingularsRecipes.SingularData; import lombok.eclipse.handlers.EclipseSingularsRecipes.StatementMaker; import lombok.eclipse.handlers.EclipseSingularsRecipes.TypeReferenceMaker; import lombok.eclipse.handlers.HandleNonNull; +import lombok.spi.Provides; -@ProviderFor(EclipseSingularizer.class) +@Provides(EclipseSingularizer.class) public class EclipseJavaUtilMapSingularizer extends EclipseJavaUtilSingularizer { @Override public LombokImmutableList<String> getSupportedTypes() { return LombokImmutableList.of("java.util.Map", "java.util.SortedMap", "java.util.NavigableMap"); @@ -349,4 +349,8 @@ public class EclipseJavaUtilMapSingularizer extends EclipseJavaUtilSingularizer statements.addAll(createJavaUtilSimpleCreationAndFillStatements(data, builderType, true, true, false, true, "TreeMap", builderVariable)); } } + + @Override protected int getTypeArgumentsCount() { + return 2; + } } diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilSetSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilSetSingularizer.java index 2076ec7d..a432f3fe 100644 --- a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilSetSingularizer.java +++ b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilSetSingularizer.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015-2019 The Project Lombok Authors. + * Copyright (C) 2015-2021 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 @@ -27,11 +27,11 @@ import lombok.core.LombokImmutableList; import lombok.eclipse.EclipseNode; import lombok.eclipse.handlers.EclipseSingularsRecipes.EclipseSingularizer; import lombok.eclipse.handlers.EclipseSingularsRecipes.SingularData; +import lombok.spi.Provides; import org.eclipse.jdt.internal.compiler.ast.Statement; -import org.mangosdk.spi.ProviderFor; -@ProviderFor(EclipseSingularizer.class) +@Provides(EclipseSingularizer.class) public class EclipseJavaUtilSetSingularizer extends EclipseJavaUtilListSetSingularizer { @Override public LombokImmutableList<String> getSupportedTypes() { return LombokImmutableList.of("java.util.Set", "java.util.SortedSet", "java.util.NavigableSet"); diff --git a/src/core/lombok/javac/CompilerMessageSuppressor.java b/src/core/lombok/javac/CompilerMessageSuppressor.java index 02dc6c26..7d7b81e6 100644 --- a/src/core/lombok/javac/CompilerMessageSuppressor.java +++ b/src/core/lombok/javac/CompilerMessageSuppressor.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2013 The Project Lombok Authors. + * Copyright (C) 2011-2021 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 @@ -226,7 +226,7 @@ public final class CompilerMessageSuppressor { ListBuffer<Object> newDeferredDiagnostics = new ListBuffer<Object>(); for (Object diag_ : deferredDiagnostics) { if (!(diag_ instanceof JCDiagnostic)) { - newDeferredDiagnostics.add(diag_); + newDeferredDiagnostics.append(diag_); continue; } JCDiagnostic diag = (JCDiagnostic) diag_; @@ -234,7 +234,7 @@ public final class CompilerMessageSuppressor { if (here >= startPos && here < endPos && diag.getSource() == sourcefile) { // We eliminate it } else { - newDeferredDiagnostics.add(diag); + newDeferredDiagnostics.append(diag); } } field.set(receiver, newDeferredDiagnostics); diff --git a/src/core/lombok/javac/HandlerLibrary.java b/src/core/lombok/javac/HandlerLibrary.java index 9e7b8fe5..c2bf8512 100644 --- a/src/core/lombok/javac/HandlerLibrary.java +++ b/src/core/lombok/javac/HandlerLibrary.java @@ -65,7 +65,7 @@ public class HandlerLibrary { /** * Creates a new HandlerLibrary that will report any problems or errors to the provided messager. - * You probably want to use {@link #load(Messager)} instead. + * You probably want to use {@link #load(Messager, Trees)} instead. */ public HandlerLibrary(Messager messager) { ConfigurationKeysLoader.LoaderLoader.loadAllConfigurationKeys(); diff --git a/src/core/lombok/javac/JavacAugments.java b/src/core/lombok/javac/JavacAugments.java index bc23131b..e5d1fc43 100644 --- a/src/core/lombok/javac/JavacAugments.java +++ b/src/core/lombok/javac/JavacAugments.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014 The Project Lombok Authors. + * Copyright (C) 2014-2021 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 @@ -24,6 +24,7 @@ package lombok.javac; import lombok.core.FieldAugment; import com.sun.tools.javac.tree.JCTree; +import com.sun.tools.javac.tree.JCTree.JCImport; public final class JavacAugments { private JavacAugments() { @@ -32,4 +33,5 @@ public final class JavacAugments { public static final FieldAugment<JCTree, Boolean> JCTree_handled = FieldAugment.augment(JCTree.class, boolean.class, "lombok$handled"); public static final FieldAugment<JCTree, JCTree> JCTree_generatedNode = FieldAugment.circularSafeAugment(JCTree.class, JCTree.class, "lombok$generatedNode"); + public static final FieldAugment<JCImport, Boolean> JCImport_deletable = FieldAugment.circularSafeAugment(JCImport.class, Boolean.class, "lombok$deletable"); } diff --git a/src/core/lombok/javac/JavacNode.java b/src/core/lombok/javac/JavacNode.java index 3de3f38b..035f7c53 100644 --- a/src/core/lombok/javac/JavacNode.java +++ b/src/core/lombok/javac/JavacNode.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2020 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -186,16 +186,6 @@ public class JavacNode extends lombok.core.LombokNode<JavacAST, JavacNode, JCTre return false; } - @Override protected boolean fieldContainsAnnotation(JCTree field, JCTree annotation) { - if (!(field instanceof JCVariableDecl)) return false; - JCVariableDecl f = (JCVariableDecl) field; - if (f.mods.annotations == null) return false; - for (JCAnnotation childAnnotation : f.mods.annotations) { - if (childAnnotation == annotation) return true; - } - return false; - } - /** * Convenient shortcut to the owning JavacAST object's getTreeMaker method. * diff --git a/src/core/lombok/javac/JavacResolution.java b/src/core/lombok/javac/JavacResolution.java index 63ca69dd..e96079e0 100644 --- a/src/core/lombok/javac/JavacResolution.java +++ b/src/core/lombok/javac/JavacResolution.java @@ -71,6 +71,16 @@ public class JavacResolution { private final Attr attr; private final CompilerMessageSuppressor messageSuppressor; + private static final Method isLocal; + + static { + Method local = Permit.permissiveGetMethod(TypeSymbol.class, "isLocal"); + if (local == null) { + local = Permit.permissiveGetMethod(TypeSymbol.class, "isDirectlyOrIndirectlyLocal"); + } + isLocal = local; + } + public JavacResolution(Context context) { attr = Attr.instance(context); messageSuppressor = new CompilerMessageSuppressor(context); @@ -352,6 +362,15 @@ public class JavacResolution { return a.compareTo(b); } + private static boolean isLocalType(TypeSymbol symbol) { + try { + return (Boolean) Permit.invoke(isLocal, symbol); + } + catch (Exception e) { + return false; + } + } + private static JCExpression typeToJCTree0(Type type, JavacAST ast, boolean allowCompound, boolean allowVoid, boolean allowCapture) throws TypeNotConvertibleException { // NB: There's such a thing as maker.Type(type), but this doesn't work very well; it screws up anonymous classes, captures, and adds an extra prefix dot for some reason too. // -- so we write our own take on that here. @@ -450,7 +469,7 @@ public class JavacResolution { } String qName; - if (symbol.isLocal()) { + if (isLocalType(symbol)) { qName = symbol.getSimpleName().toString(); } else if (symbol.type != null && symbol.type.getEnclosingType() != null && typeTag(symbol.type.getEnclosingType()).equals(typeTag("CLASS"))) { replacement = typeToJCTree0(type.getEnclosingType(), ast, false, false, false); diff --git a/src/core/lombok/javac/apt/InterceptingJavaFileObject.java b/src/core/lombok/javac/apt/InterceptingJavaFileObject.java index 403b5672..75cf0713 100644 --- a/src/core/lombok/javac/apt/InterceptingJavaFileObject.java +++ b/src/core/lombok/javac/apt/InterceptingJavaFileObject.java @@ -26,7 +26,6 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.Reader; import java.io.Writer; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URI; import java.nio.charset.CharsetDecoder; @@ -35,7 +34,6 @@ import javax.lang.model.element.Modifier; import javax.lang.model.element.NestingKind; import javax.tools.JavaFileObject; -import lombok.Lombok; import lombok.core.DiagnosticsReceiver; import lombok.core.PostCompiler; import lombok.permit.Permit; diff --git a/src/core/lombok/javac/apt/LombokProcessor.java b/src/core/lombok/javac/apt/LombokProcessor.java index 485b82a4..6552f15b 100644 --- a/src/core/lombok/javac/apt/LombokProcessor.java +++ b/src/core/lombok/javac/apt/LombokProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2019 The Project Lombok Authors. + * Copyright (C) 2009-2020 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 @@ -63,6 +63,8 @@ import lombok.core.CleanupRegistry; import lombok.core.DiagnosticsReceiver; import lombok.javac.JavacTransformer; import lombok.permit.Permit; +import lombok.permit.dummy.Parent; +import sun.misc.Unsafe; /** * This Annotation Processor is the standard injection mechanism for lombok-enabling the javac compiler. @@ -430,6 +432,7 @@ public class LombokProcessor extends AbstractProcessor { * gradle incremental compilation, the delegate ProcessingEnvironment of the gradle wrapper is returned. */ public JavacProcessingEnvironment getJavacProcessingEnvironment(Object procEnv) { + addOpensForLombok(); if (procEnv instanceof JavacProcessingEnvironment) return (JavacProcessingEnvironment) procEnv; // try to find a "delegate" field in the object, and use this to try to obtain a JavacProcessingEnvironment @@ -446,7 +449,91 @@ public class LombokProcessor extends AbstractProcessor { "Can't get the delegate of the gradle IncrementalProcessingEnvironment. Lombok won't work."); return null; } - + + private static Object getOwnModule() { + try { + Method m = Permit.getMethod(Class.class, "getModule"); + return m.invoke(LombokProcessor.class); + } catch (Exception e) { + return null; + } + } + + private static Object getJdkCompilerModule() { + /* call public api: ModuleLayer.boot().findModule("jdk.compiler").get(); + but use reflection because we don't want this code to crash on jdk1.7 and below. + In that case, none of this stuff was needed in the first place, so we just exit via + the catch block and do nothing. + */ + + try { + Class<?> cModuleLayer = Class.forName("java.lang.ModuleLayer"); + Method mBoot = cModuleLayer.getDeclaredMethod("boot"); + Object bootLayer = mBoot.invoke(null); + Class<?> cOptional = Class.forName("java.util.Optional"); + Method mFindModule = cModuleLayer.getDeclaredMethod("findModule", String.class); + Object oCompilerO = mFindModule.invoke(bootLayer, "jdk.compiler"); + return cOptional.getDeclaredMethod("get").invoke(oCompilerO); + } catch (Exception e) { + return null; + } + } + + /** Useful from jdk9 and up; required from jdk16 and up. This code is supposed to gracefully do nothing on jdk8 and below, as this operation isn't needed there. */ + public static void addOpensForLombok() { + Class<?> cModule; + try { + cModule = Class.forName("java.lang.Module"); + } catch (ClassNotFoundException e) { + return; //jdk8-; this is not needed. + } + + Unsafe unsafe = getUnsafe(); + Object jdkCompilerModule = getJdkCompilerModule(); + Object ownModule = getOwnModule(); + String[] allPkgs = { + "com.sun.tools.javac.code", + "com.sun.tools.javac.comp", + "com.sun.tools.javac.file", + "com.sun.tools.javac.main", + "com.sun.tools.javac.model", + "com.sun.tools.javac.parser", + "com.sun.tools.javac.processing", + "com.sun.tools.javac.tree", + "com.sun.tools.javac.util", + "com.sun.tools.javac.jvm", + }; + + try { + Method m = cModule.getDeclaredMethod("implAddOpens", String.class, cModule); + long firstFieldOffset = getFirstFieldOffset(unsafe); + unsafe.putBooleanVolatile(m, firstFieldOffset, true); + for (String p : allPkgs) m.invoke(jdkCompilerModule, p, ownModule); + } catch (Exception ignore) {} + } + + private static long getFirstFieldOffset(Unsafe unsafe) { + try { + return unsafe.objectFieldOffset(Parent.class.getDeclaredField("first")); + } catch (NoSuchFieldException e) { + // can't happen. + throw new RuntimeException(e); + } catch (SecurityException e) { + // can't happen + throw new RuntimeException(e); + } + } + + private static Unsafe getUnsafe() { + try { + Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe"); + theUnsafe.setAccessible(true); + return (Unsafe) theUnsafe.get(null); + } catch (Exception e) { + return null; + } + } + /** * This class returns the given filer as a JavacFiler. In case the filer is no * JavacFiler (e.g. the Gradle IncrementalFiler), its "delegate" field is used to get the JavacFiler @@ -504,7 +591,7 @@ public class LombokProcessor extends AbstractProcessor { } /** - * InteliJ >= 2020.3 + * IntelliJ IDEA >= 2020.3 */ private Object tryGetProxyDelegateToField(Class<?> delegateClass, Object instance) { try { diff --git a/src/core/lombok/javac/apt/Processor.java b/src/core/lombok/javac/apt/Processor.java index f15bf74c..e0de363d 100644 --- a/src/core/lombok/javac/apt/Processor.java +++ b/src/core/lombok/javac/apt/Processor.java @@ -222,7 +222,7 @@ public class Processor extends AbstractProcessor { * We just return the latest version of whatever JDK we run on. Stupid? Yeah, but it's either that or warnings on all versions but 1. */ @Override public SourceVersion getSupportedSourceVersion() { - return SourceVersion.values()[SourceVersion.values().length - 1]; + return SourceVersion.latest(); } @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { diff --git a/src/core/lombok/javac/handlers/HandleAccessors.java b/src/core/lombok/javac/handlers/HandleAccessors.java index 46fe1cd2..60466d78 100644 --- a/src/core/lombok/javac/handlers/HandleAccessors.java +++ b/src/core/lombok/javac/handlers/HandleAccessors.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2014 The Project Lombok Authors. + * Copyright (C) 2012-2021 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 @@ -24,8 +24,6 @@ package lombok.javac.handlers; import static lombok.core.handlers.HandlerUtil.*; import static lombok.javac.handlers.JavacHandlerUtil.*; -import org.mangosdk.spi.ProviderFor; - import com.sun.tools.javac.tree.JCTree.JCAnnotation; import lombok.ConfigurationKeys; @@ -34,8 +32,9 @@ import lombok.core.HandlerPriority; import lombok.experimental.Accessors; import lombok.javac.JavacAnnotationHandler; import lombok.javac.JavacNode; +import lombok.spi.Provides; -@ProviderFor(JavacAnnotationHandler.class) +@Provides @HandlerPriority(65536) public class HandleAccessors extends JavacAnnotationHandler<Accessors> { @Override public void handle(AnnotationValues<Accessors> annotation, JCAnnotation ast, JavacNode annotationNode) { diff --git a/src/core/lombok/javac/handlers/HandleBuilder.java b/src/core/lombok/javac/handlers/HandleBuilder.java index c10e6071..c23dc14c 100644 --- a/src/core/lombok/javac/handlers/HandleBuilder.java +++ b/src/core/lombok/javac/handlers/HandleBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2020 The Project Lombok Authors. + * Copyright (C) 2013-2021 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 @@ -30,8 +30,6 @@ import java.util.ArrayList; import javax.lang.model.element.Modifier; -import org.mangosdk.spi.ProviderFor; - import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCAnnotation; @@ -81,8 +79,9 @@ import lombok.javac.handlers.JavacHandlerUtil.CopyJavadoc; import lombok.javac.handlers.JavacHandlerUtil.MemberExistsResult; import lombok.javac.handlers.JavacSingularsRecipes.JavacSingularizer; import lombok.javac.handlers.JavacSingularsRecipes.SingularData; +import lombok.spi.Provides; -@ProviderFor(JavacAnnotationHandler.class) +@Provides @HandlerPriority(-1024) //-2^10; to ensure we've picked up @FieldDefault's changes (-2048) but @Value hasn't removed itself yet (-512), so that we can error on presence of it on the builder classes. public class HandleBuilder extends JavacAnnotationHandler<Builder> { private HandleConstructor handleConstructor = new HandleConstructor(); @@ -109,7 +108,6 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { boolean isStatic; List<JCTypeParameter> typeParams; List<JCTypeParameter> builderTypeParams; - JCTree source; JavacNode sourceNode; java.util.List<BuilderFieldData> builderFields; AccessLevel accessInners, accessOuters; @@ -198,10 +196,11 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { } @Override public void handle(AnnotationValues<Builder> annotation, JCAnnotation ast, JavacNode annotationNode) { + final String BUILDER_NODE_NOT_SUPPORTED_ERR = "@Builder is only supported on classes, records, constructors, and methods."; + handleFlagUsage(annotationNode, ConfigurationKeys.BUILDER_FLAG_USAGE, "@Builder"); BuilderJob job = new BuilderJob(); job.sourceNode = annotationNode; - job.source = ast; job.checkerFramework = getCheckerFrameworkVersion(annotationNode); job.isStatic = true; @@ -236,6 +235,11 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { ArrayList<JavacNode> nonFinalNonDefaultedFields = null; if (parent.get() instanceof JCClassDecl) { + if (!isClass(parent) && !isRecord(parent)) { + annotationNode.addError(BUILDER_NODE_NOT_SUPPORTED_ERR); + return; + } + job.parentType = parent; JCClassDecl td = (JCClassDecl) parent.get(); @@ -278,7 +282,7 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { bfd.nameOfSetFlag = parent.toName(bfd.name + SET_PREFIX); bfd.builderFieldName = parent.toName(bfd.name + VALUE_PREFIX); JCMethodDecl md = generateDefaultProvider(bfd.nameOfDefaultProvider, fieldNode, td.typarams); - recursiveSetGeneratedBy(md, ast, annotationNode.getContext()); + recursiveSetGeneratedBy(md, annotationNode); if (md != null) injectMethod(parent, md); } addObtainVia(bfd, fieldNode); @@ -286,7 +290,11 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { allFields.append(fieldNode); } - handleConstructor.generateConstructor(parent, AccessLevel.PACKAGE, List.<JCAnnotation>nil(), allFields.toList(), false, null, SkipIfConstructorExists.I_AM_BUILDER, annotationNode); + if (!isRecord(parent)) { + // Records ship with a canonical constructor that acts as @AllArgsConstructor - just use that one. + + handleConstructor.generateConstructor(parent, AccessLevel.PACKAGE, List.<JCAnnotation>nil(), allFields.toList(), false, null, SkipIfConstructorExists.I_AM_BUILDER, annotationNode); + } buildMethodReturnType = namePlusTypeParamsToTypeReference(parent.getTreeMaker(), parent, td.typarams); job.typeParams = job.builderTypeParams = td.typarams; @@ -321,7 +329,7 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { buildMethodThrownExceptions = jmd.thrown; nameOfBuilderMethod = jmd.name; if (buildMethodReturnType instanceof JCTypeApply) { - buildMethodReturnType = cloneType(job.getTreeMaker(), buildMethodReturnType, ast, annotationNode.getContext()); + buildMethodReturnType = cloneType(job.getTreeMaker(), buildMethodReturnType, annotationNode); } if (job.builderClassName.indexOf('*') > -1) { String replStr = returnTypeToBuilderClassName(annotationNode, td, buildMethodReturnType, job.typeParams); @@ -394,7 +402,7 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { } } } else { - annotationNode.addError("@Builder is only supported on types, constructors, and methods."); + annotationNode.addError(BUILDER_NODE_NOT_SUPPORTED_ERR); return; } @@ -419,7 +427,7 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { job.builderType = findInnerClass(job.parentType, job.builderClassName); if (job.builderType == null) { job.builderType = makeBuilderClass(job); - recursiveSetGeneratedBy(job.builderType.get(), ast, annotationNode.getContext()); + recursiveSetGeneratedBy(job.builderType.get(), annotationNode); } else { JCClassDecl builderTypeDeclaration = (JCClassDecl) job.builderType.get(); if (job.isStatic && !builderTypeDeclaration.getModifiers().getFlags().contains(Modifier.STATIC)) { @@ -467,7 +475,7 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { JavacTreeMaker maker = job.getTreeMaker(); JCVariableDecl uncleanField = maker.VarDef(maker.Modifiers(Flags.PRIVATE), job.builderType.toName(CLEAN_FIELD_NAME), maker.TypeIdent(CTC_BOOLEAN), null); injectFieldAndMarkGenerated(job.builderType, uncleanField); - recursiveSetGeneratedBy(uncleanField, ast, annotationNode.getContext()); + recursiveSetGeneratedBy(uncleanField, annotationNode); } if (constructorExists(job.builderType) == MemberExistsResult.NOT_EXISTS) { @@ -485,8 +493,8 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { if (methodExists == MemberExistsResult.NOT_EXISTS) { JCMethodDecl md = generateBuildMethod(job, nameOfBuilderMethod, buildMethodReturnType, buildMethodThrownExceptions, addCleaning); if (md != null) { + recursiveSetGeneratedBy(md, annotationNode); injectMethod(job.builderType, md); - recursiveSetGeneratedBy(md, ast, annotationNode.getContext()); } } } @@ -499,7 +507,7 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { } } - JCMethodDecl md = HandleToString.createToString(job.builderType, fieldNodes, true, false, FieldAccess.ALWAYS_FIELD, ast); + JCMethodDecl md = HandleToString.createToString(job.builderType, fieldNodes, true, false, FieldAccess.ALWAYS_FIELD, job.sourceNode); if (md != null) injectMethod(job.builderType, md); } @@ -508,7 +516,7 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { if (generateBuilderMethod && methodExists(job.builderMethodName, job.parentType, -1) != MemberExistsResult.NOT_EXISTS) generateBuilderMethod = false; if (generateBuilderMethod) { JCMethodDecl md = generateBuilderMethod(job); - recursiveSetGeneratedBy(md, ast, annotationNode.getContext()); + recursiveSetGeneratedBy(md, annotationNode); if (md != null) injectMethod(job.parentType, md); } @@ -529,7 +537,7 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { } JCMethodDecl md = generateToBuilderMethod(job, tps, annInstance.setterPrefix()); if (md != null) { - recursiveSetGeneratedBy(md, ast, annotationNode.getContext()); + recursiveSetGeneratedBy(md, annotationNode); injectMethod(job.parentType, md); } } @@ -614,10 +622,6 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { private JCMethodDecl generateToBuilderMethod(BuilderJob job, List<JCTypeParameter> typeParameters, String prefix) { // return new ThingieBuilder<A, B>().setA(this.a).setB(this.b); JavacTreeMaker maker = job.getTreeMaker(); - ListBuffer<JCExpression> typeArgs = new ListBuffer<JCExpression>(); - for (JCTypeParameter typeParam : typeParameters) { - typeArgs.append(maker.Ident(typeParam.name)); - } JCExpression call = maker.NewClass(null, List.<JCExpression>nil(), namePlusTypeParamsToTypeReference(maker, job.parentType, job.toName(job.builderClassName), !job.isStatic, job.builderTypeParams), List.<JCExpression>nil(), null); JCExpression invoke = call; @@ -649,7 +653,7 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { // javac appears to cache the type of JCMethodInvocation expressions based on position, meaning, if you have 2 ObtainVia-based method invokes on different types, you get bizarre type mismatch errors. // going via a local variable declaration solves the problem. - JCExpression varType = JavacHandlerUtil.cloneType(maker, bfd.type, job.source, job.getContext()); + JCExpression varType = JavacHandlerUtil.cloneType(maker, bfd.type, job.sourceNode); if (preStatements == null) preStatements = new ListBuffer<JCStatement>(); preStatements.append(maker.VarDef(maker.Modifiers(Flags.FINAL), bfd.name, varType, inv)); } @@ -691,14 +695,14 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { for (BuilderFieldData bfd : job.builderFields) { if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) { - bfd.singularData.getSingularizer().appendCleaningCode(bfd.singularData, job.builderType, job.source, statements); + bfd.singularData.getSingularizer().appendCleaningCode(bfd.singularData, job.builderType, job.sourceNode, statements); } } statements.append(maker.Exec(maker.Assign(maker.Select(maker.Ident(job.toName("this")), job.toName(CLEAN_FIELD_NAME)), maker.Literal(CTC_BOOLEAN, 0)))); JCBlock body = maker.Block(0, statements.toList()); JCMethodDecl method = maker.MethodDef(maker.Modifiers(toJavacModifier(AccessLevel.PRIVATE)), job.toName(CLEAN_METHOD_NAME), maker.Type(Javac.createVoidType(job.builderType.getSymbolTable(), CTC_VOID)), List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null); - recursiveSetGeneratedBy(method, job.source, job.getContext()); + recursiveSetGeneratedBy(method, job.sourceNode); return method; } @@ -740,7 +744,7 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { for (BuilderFieldData bfd : job.builderFields) { if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) { - bfd.singularData.getSingularizer().appendBuildCode(bfd.singularData, job.builderType, job.source, statements, bfd.builderFieldName, "this"); + bfd.singularData.getSingularizer().appendBuildCode(bfd.singularData, job.builderType, job.sourceNode, statements, bfd.builderFieldName, "this"); } } @@ -748,7 +752,7 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { Name thisName = job.toName("this"); for (BuilderFieldData bfd : job.builderFields) { if (bfd.nameOfSetFlag != null) { - statements.append(maker.VarDef(maker.Modifiers(0L), bfd.builderFieldName, cloneType(maker, bfd.type, job.source, job.getContext()), maker.Select(maker.Ident(thisName), bfd.builderFieldName))); + statements.append(maker.VarDef(maker.Modifiers(0L), bfd.builderFieldName, cloneType(maker, bfd.type, job.sourceNode), maker.Select(maker.Ident(thisName), bfd.builderFieldName))); statements.append(maker.If(maker.Unary(CTC_NOT, maker.Select(maker.Ident(thisName), bfd.nameOfSetFlag)), maker.Exec(maker.Assign(maker.Ident(bfd.builderFieldName), maker.Apply(typeParameterNames(maker, ((JCClassDecl) job.parentType.get()).typarams), maker.Select(maker.Ident(((JCClassDecl) job.parentType.get()).name), bfd.nameOfDefaultProvider), List.<JCExpression>nil()))), null)); } if (bfd.nameOfSetFlag != null || (bfd.singularData != null && bfd.singularData.getSingularizer().shadowedDuringBuild())) { @@ -804,19 +808,14 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { JCBlock body = maker.Block(0, List.<JCStatement>of(statement)); int modifiers = Flags.PRIVATE | Flags.STATIC; - return maker.MethodDef(maker.Modifiers(modifiers), methodName, cloneType(maker, field.vartype, field, fieldNode.getContext()), copyTypeParams(fieldNode, params), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null); + return maker.MethodDef(maker.Modifiers(modifiers), methodName, cloneType(maker, field.vartype, fieldNode), copyTypeParams(fieldNode, params), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null); } public JCMethodDecl generateBuilderMethod(BuilderJob job) { //String builderClassName, JavacNode source, JavacNode type, List<JCTypeParameter> typeParams, AccessLevel access) { //builderClassName, annotationNode, tdParent, typeParams, accessForOuters); - - JavacTreeMaker maker = job.getTreeMaker(); - ListBuffer<JCExpression> typeArgs = new ListBuffer<JCExpression>(); - for (JCTypeParameter typeParam : job.typeParams) { - typeArgs.append(maker.Ident(typeParam.name)); - } + JavacTreeMaker maker = job.getTreeMaker(); JCExpression call; if (job.isStatic) { @@ -854,7 +853,11 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { for (int i = len - 1; i >= 0; i--) { BuilderFieldData bfd = job.builderFields.get(i); if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) { - bfd.createdFields.addAll(bfd.singularData.getSingularizer().generateFields(bfd.singularData, job.builderType, job.source)); + java.util.List<JavacNode> generateSingularFields = bfd.singularData.getSingularizer().generateFields(bfd.singularData, job.builderType, job.sourceNode); + for (JavacNode field : generateSingularFields) { + generated.add((JCVariableDecl) field.get()); + } + bfd.createdFields.addAll(generateSingularFields); } else { JavacNode field = null, setFlag = null; for (JavacNode exists : existing) { @@ -865,7 +868,7 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { JavacTreeMaker maker = job.getTreeMaker(); if (field == null) { JCModifiers mods = maker.Modifiers(Flags.PRIVATE); - JCVariableDecl newField = maker.VarDef(mods, bfd.builderFieldName, cloneType(maker, bfd.type, job.source, job.getContext()), null); + JCVariableDecl newField = maker.VarDef(mods, bfd.builderFieldName, cloneType(maker, bfd.type, job.sourceNode), null); field = injectFieldAndMarkGenerated(job.builderType, newField); generated.add(newField); } @@ -878,7 +881,7 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { bfd.createdFields.add(field); } } - for (JCVariableDecl gen : generated) recursiveSetGeneratedBy(gen, job.source, job.getContext()); + for (JCVariableDecl gen : generated) recursiveSetGeneratedBy(gen, job.sourceNode); } public void makePrefixedSetterMethodsForBuilder(BuilderJob job, BuilderFieldData bfd, String prefix) { @@ -915,7 +918,7 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { newMethod = HandleSetter.createSetterWithRecv(toJavacModifier(job.accessInners), deprecate, fieldNode, maker, setterName, bfd.name, bfd.nameOfSetFlag, job.oldChain, job.sourceNode, methodAnns, bfd.annotations, recv); } if (newMethod == null) newMethod = HandleSetter.createSetter(toJavacModifier(job.accessInners), deprecate, fieldNode, maker, setterName, bfd.name, bfd.nameOfSetFlag, job.oldChain, job.sourceNode, methodAnns, bfd.annotations); - recursiveSetGeneratedBy(newMethod, job.source, job.getContext()); + recursiveSetGeneratedBy(newMethod, job.sourceNode); if (job.sourceNode.up().getKind() == Kind.METHOD) { copyJavadocFromParam(bfd.originalFieldNode.up(), newMethod, bfd.name.toString()); } else { @@ -942,6 +945,7 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> { if (job.isStatic) modifiers |= Flags.STATIC; JCModifiers mods = maker.Modifiers(modifiers); JCClassDecl builder = maker.ClassDef(mods, job.getBuilderClassName(), job.copyTypeParams(), null, List.<JCExpression>nil(), List.<JCTree>nil()); + recursiveSetGeneratedBy(builder, job.sourceNode); return injectType(job.parentType, builder); } diff --git a/src/core/lombok/javac/handlers/HandleBuilderDefault.java b/src/core/lombok/javac/handlers/HandleBuilderDefault.java index df5eebc9..8438057a 100644 --- a/src/core/lombok/javac/handlers/HandleBuilderDefault.java +++ b/src/core/lombok/javac/handlers/HandleBuilderDefault.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2018 The Project Lombok Authors. + * Copyright (C) 2017-2021 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 @@ -23,8 +23,6 @@ package lombok.javac.handlers; import static lombok.javac.handlers.JavacHandlerUtil.*; -import org.mangosdk.spi.ProviderFor; - import com.sun.tools.javac.tree.JCTree.JCAnnotation; import com.sun.tools.javac.tree.JCTree.JCFieldAccess; import com.sun.tools.javac.tree.JCTree.JCIdent; @@ -36,8 +34,9 @@ import lombok.core.HandlerPriority; import lombok.experimental.SuperBuilder; import lombok.javac.JavacAnnotationHandler; import lombok.javac.JavacNode; +import lombok.spi.Provides; -@ProviderFor(JavacAnnotationHandler.class) +@Provides @HandlerPriority(-1025) //HandleBuilder's level, minus one. public class HandleBuilderDefault extends JavacAnnotationHandler<Builder.Default> { @Override public void handle(AnnotationValues<Builder.Default> annotation, JCAnnotation ast, JavacNode annotationNode) { @@ -55,6 +54,7 @@ public class HandleBuilderDefault extends JavacAnnotationHandler<Builder.Default JCFieldAccess jfa = (JCFieldAccess) ast.annotationType; if (jfa.selected instanceof JCIdent && ((JCIdent) jfa.selected).name.contentEquals("Builder") && jfa.name.contentEquals("Default")) { JCFieldAccess newJfaSel = annotationNode.getTreeMaker().Select(annotationNode.getTreeMaker().Ident(annotationNode.toName("lombok")), ((JCIdent) jfa.selected).name); + recursiveSetGeneratedBy(newJfaSel, annotationNode); jfa.selected = newJfaSel; } } diff --git a/src/core/lombok/javac/handlers/HandleBuilderDefaultRemove.java b/src/core/lombok/javac/handlers/HandleBuilderDefaultRemove.java index fc0738c3..d7bc28cb 100644 --- a/src/core/lombok/javac/handlers/HandleBuilderDefaultRemove.java +++ b/src/core/lombok/javac/handlers/HandleBuilderDefaultRemove.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 The Project Lombok Authors. + * Copyright (C) 2018-2021 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 @@ -23,8 +23,6 @@ package lombok.javac.handlers; import static lombok.javac.handlers.JavacHandlerUtil.*; -import org.mangosdk.spi.ProviderFor; - import com.sun.tools.javac.tree.JCTree.JCAnnotation; import lombok.Builder; @@ -34,9 +32,10 @@ import lombok.core.AnnotationValues; import lombok.core.HandlerPriority; import lombok.javac.JavacAnnotationHandler; import lombok.javac.JavacNode; +import lombok.spi.Provides; -@ProviderFor(JavacAnnotationHandler.class) -@HandlerPriority(65536) +@Provides +@HandlerPriority(32768) @AlreadyHandledAnnotations public class HandleBuilderDefaultRemove extends JavacAnnotationHandler<Builder.Default> { @Override public void handle(AnnotationValues<Default> annotation, JCAnnotation ast, JavacNode annotationNode) { diff --git a/src/core/lombok/javac/handlers/HandleBuilderRemove.java b/src/core/lombok/javac/handlers/HandleBuilderRemove.java index 6e59b40f..a47ed6b0 100644 --- a/src/core/lombok/javac/handlers/HandleBuilderRemove.java +++ b/src/core/lombok/javac/handlers/HandleBuilderRemove.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 The Project Lombok Authors. + * Copyright (C) 2020-2021 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 @@ -23,8 +23,6 @@ package lombok.javac.handlers; import static lombok.javac.handlers.JavacHandlerUtil.*; -import org.mangosdk.spi.ProviderFor; - import com.sun.tools.javac.tree.JCTree.JCAnnotation; import lombok.Builder; @@ -33,9 +31,10 @@ import lombok.core.AnnotationValues; import lombok.core.HandlerPriority; import lombok.javac.JavacAnnotationHandler; import lombok.javac.JavacNode; +import lombok.spi.Provides; -@ProviderFor(JavacAnnotationHandler.class) -@HandlerPriority(65536) +@Provides +@HandlerPriority(32768) @AlreadyHandledAnnotations public class HandleBuilderRemove extends JavacAnnotationHandler<Builder> { @Override public void handle(AnnotationValues<Builder> annotation, JCAnnotation ast, JavacNode annotationNode) { diff --git a/src/core/lombok/javac/handlers/HandleCleanup.java b/src/core/lombok/javac/handlers/HandleCleanup.java index 4aa61764..785ebf8a 100644 --- a/src/core/lombok/javac/handlers/HandleCleanup.java +++ b/src/core/lombok/javac/handlers/HandleCleanup.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2014 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -32,8 +32,7 @@ import lombok.delombok.LombokOptionsFactory; import lombok.javac.JavacAnnotationHandler; import lombok.javac.JavacNode; import lombok.javac.JavacTreeMaker; - -import org.mangosdk.spi.ProviderFor; +import lombok.spi.Provides; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCAnnotation; @@ -52,7 +51,6 @@ import com.sun.tools.javac.tree.JCTree.JCMethodInvocation; import com.sun.tools.javac.tree.JCTree.JCStatement; import com.sun.tools.javac.tree.JCTree.JCTypeCast; import com.sun.tools.javac.tree.JCTree.JCVariableDecl; -import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.ListBuffer; import com.sun.tools.javac.util.Name; @@ -60,7 +58,7 @@ import com.sun.tools.javac.util.Name; /** * Handles the {@code lombok.Cleanup} annotation for javac. */ -@ProviderFor(JavacAnnotationHandler.class) +@Provides public class HandleCleanup extends JavacAnnotationHandler<Cleanup> { @Override public void handle(AnnotationValues<Cleanup> annotation, JCAnnotation ast, JavacNode annotationNode) { handleFlagUsage(annotationNode, ConfigurationKeys.CLEANUP_FLAG_USAGE, "@Cleanup"); @@ -129,10 +127,9 @@ public class HandleCleanup extends JavacAnnotationHandler<Cleanup> { JCIf ifNotNullCleanup = maker.If(isNull, maker.Block(0, cleanupCall), null); - Context context = annotationNode.getContext(); - JCBlock finalizer = recursiveSetGeneratedBy(maker.Block(0, List.<JCStatement>of(ifNotNullCleanup)), ast, context); + JCBlock finalizer = recursiveSetGeneratedBy(maker.Block(0, List.<JCStatement>of(ifNotNullCleanup)), annotationNode); - newStatements.append(setGeneratedBy(maker.Try(setGeneratedBy(maker.Block(0, tryBlock.toList()), ast, context), List.<JCCatch>nil(), finalizer), ast, context)); + newStatements.append(setGeneratedBy(maker.Try(setGeneratedBy(maker.Block(0, tryBlock.toList()), annotationNode), List.<JCCatch>nil(), finalizer), annotationNode)); if (blockNode instanceof JCBlock) { ((JCBlock)blockNode).stats = newStatements.toList(); diff --git a/src/core/lombok/javac/handlers/HandleConstructor.java b/src/core/lombok/javac/handlers/HandleConstructor.java index f30320dc..9c74ca0e 100644 --- a/src/core/lombok/javac/handlers/HandleConstructor.java +++ b/src/core/lombok/javac/handlers/HandleConstructor.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2019 The Project Lombok Authors. + * Copyright (C) 2010-2021 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 @@ -25,8 +25,6 @@ import static lombok.core.handlers.HandlerUtil.*; import static lombok.javac.Javac.*; import static lombok.javac.handlers.JavacHandlerUtil.*; -import org.mangosdk.spi.ProviderFor; - import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.code.Symbol.ClassSymbol; import com.sun.tools.javac.code.Type; @@ -55,18 +53,17 @@ import lombok.NoArgsConstructor; import lombok.RequiredArgsConstructor; import lombok.core.AST.Kind; import lombok.core.AnnotationValues; -import lombok.core.LombokNode; import lombok.core.configuration.CheckerFrameworkVersion; import lombok.delombok.LombokOptionsFactory; import lombok.javac.Javac; -import lombok.javac.JavacAST; import lombok.javac.JavacAnnotationHandler; import lombok.javac.JavacNode; import lombok.javac.JavacTreeMaker; import lombok.javac.handlers.JavacHandlerUtil.MemberExistsResult; +import lombok.spi.Provides; public class HandleConstructor { - @ProviderFor(JavacAnnotationHandler.class) + @Provides public static class HandleNoArgsConstructor extends JavacAnnotationHandler<NoArgsConstructor> { private static final String NAME = NoArgsConstructor.class.getSimpleName(); private HandleConstructor handleConstructor = new HandleConstructor(); @@ -88,7 +85,7 @@ public class HandleConstructor { } } - @ProviderFor(JavacAnnotationHandler.class) + @Provides public static class HandleRequiredArgsConstructor extends JavacAnnotationHandler<RequiredArgsConstructor> { private static final String NAME = RequiredArgsConstructor.class.getSimpleName(); private HandleConstructor handleConstructor = new HandleConstructor(); @@ -138,7 +135,7 @@ public class HandleConstructor { return fields.toList(); } - @ProviderFor(JavacAnnotationHandler.class) + @Provides public static class HandleAllArgsConstructor extends JavacAnnotationHandler<AllArgsConstructor> { private static final String NAME = AllArgsConstructor.class.getSimpleName(); private HandleConstructor handleConstructor = new HandleConstructor(); @@ -184,12 +181,7 @@ public class HandleConstructor { } public static boolean checkLegality(JavacNode typeNode, JavacNode errorNode, String name) { - JCClassDecl typeDecl = null; - if (typeNode.get() instanceof JCClassDecl) typeDecl = (JCClassDecl) typeNode.get(); - long modifiers = typeDecl == null ? 0 : typeDecl.mods.flags; - boolean notAClass = (modifiers & (Flags.INTERFACE | Flags.ANNOTATION)) != 0; - - if (typeDecl == null || notAClass) { + if (!isClassOrEnum(typeNode)) { errorNode.addError(name + " is only supported on a class or an enum."); return false; } @@ -269,11 +261,11 @@ public class HandleConstructor { generateStaticConstructor(staticConstrRequired, typeNode, staticName, level, allToDefault, fields, source, argTypes_); } - private void generateStaticConstructor(boolean staticConstrRequired, JavacNode typeNode, String staticName, AccessLevel level, boolean allToDefault, List<JavacNode> fields, LombokNode<JavacAST, JavacNode, JCTree> source, List<Type> argTypes_) { + private void generateStaticConstructor(boolean staticConstrRequired, JavacNode typeNode, String staticName, AccessLevel level, boolean allToDefault, List<JavacNode> fields, JavacNode source, List<Type> argTypes_) { if (staticConstrRequired) { ClassSymbol sym = ((JCClassDecl) typeNode.get()).sym; Type returnType = sym == null ? null : sym.type; - JCMethodDecl staticConstr = createStaticConstructor(staticName, level, typeNode, allToDefault ? List.<JavacNode>nil() : fields, source.get()); + JCMethodDecl staticConstr = createStaticConstructor(staticName, level, typeNode, allToDefault ? List.<JavacNode>nil() : fields, source); injectMethod(typeNode, staticConstr, argTypes_, returnType); } } @@ -342,7 +334,7 @@ public class HandleConstructor { Name rawName = field.name; List<JCAnnotation> copyableAnnotations = findCopyableAnnotations(fieldNode); long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, typeNode.getContext()); - JCExpression pType = cloneType(fieldNode.getTreeMaker(), field.vartype, source.get(), source.getContext()); + JCExpression pType = cloneType(fieldNode.getTreeMaker(), field.vartype, source); JCVariableDecl param = maker.VarDef(maker.Modifiers(flags, copyableAnnotations), fieldName, pType, null); params.append(param); if (hasNonNullAnnotations(fieldNode)) { @@ -379,7 +371,7 @@ public class HandleConstructor { if (onConstructor != null) mods.annotations = mods.annotations.appendList(copyAnnotations(onConstructor)); return recursiveSetGeneratedBy(maker.MethodDef(mods, typeNode.toName("<init>"), null, List.<JCTypeParameter>nil(), params.toList(), List.<JCExpression>nil(), - maker.Block(0L, nullChecks.appendList(assigns).toList()), null), source.get(), typeNode.getContext()); + maker.Block(0L, nullChecks.appendList(assigns).toList()), null), source); } /** @@ -450,7 +442,7 @@ public class HandleConstructor { return true; } - public JCMethodDecl createStaticConstructor(String name, AccessLevel level, JavacNode typeNode, List<JavacNode> fields, JCTree source) { + public JCMethodDecl createStaticConstructor(String name, AccessLevel level, JavacNode typeNode, List<JavacNode> fields, JavacNode source) { JavacTreeMaker maker = typeNode.getTreeMaker(); JCClassDecl type = (JCClassDecl) typeNode.get(); @@ -475,7 +467,7 @@ public class HandleConstructor { for (JavacNode fieldNode : fields) { JCVariableDecl field = (JCVariableDecl) fieldNode.get(); Name fieldName = removePrefixFromField(fieldNode); - JCExpression pType = cloneType(maker, field.vartype, source, typeNode.getContext()); + JCExpression pType = cloneType(maker, field.vartype, source); List<JCAnnotation> copyableAnnotations = findCopyableAnnotations(fieldNode); long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, typeNode.getContext()); JCVariableDecl param = maker.VarDef(maker.Modifiers(flags, copyableAnnotations), fieldName, pType, null); @@ -487,6 +479,6 @@ public class HandleConstructor { JCMethodDecl methodDef = maker.MethodDef(mods, typeNode.toName(name), returnType, typeParams.toList(), params.toList(), List.<JCExpression>nil(), body, null); createRelevantNonNullAnnotation(typeNode, methodDef); - return recursiveSetGeneratedBy(methodDef, source, typeNode.getContext()); + return recursiveSetGeneratedBy(methodDef, source); } } diff --git a/src/core/lombok/javac/handlers/HandleData.java b/src/core/lombok/javac/handlers/HandleData.java index 15c9c9e7..06524aa8 100644 --- a/src/core/lombok/javac/handlers/HandleData.java +++ b/src/core/lombok/javac/handlers/HandleData.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2018 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -30,8 +30,7 @@ import lombok.core.AnnotationValues; import lombok.javac.JavacAnnotationHandler; import lombok.javac.JavacNode; import lombok.javac.handlers.HandleConstructor.SkipIfConstructorExists; - -import org.mangosdk.spi.ProviderFor; +import lombok.spi.Provides; import com.sun.tools.javac.tree.JCTree.JCAnnotation; import com.sun.tools.javac.util.List; @@ -39,7 +38,7 @@ import com.sun.tools.javac.util.List; /** * Handles the {@code lombok.Data} annotation for javac. */ -@ProviderFor(JavacAnnotationHandler.class) +@Provides public class HandleData extends JavacAnnotationHandler<Data> { private HandleConstructor handleConstructor = new HandleConstructor(); private HandleGetter handleGetter = new HandleGetter(); @@ -52,9 +51,8 @@ public class HandleData extends JavacAnnotationHandler<Data> { deleteAnnotationIfNeccessary(annotationNode, Data.class); JavacNode typeNode = annotationNode.up(); - boolean notAClass = !isClass(typeNode); - if (notAClass) { + if (!isClass(typeNode)) { annotationNode.addError("@Data is only supported on a class."); return; } diff --git a/src/core/lombok/javac/handlers/HandleDelegate.java b/src/core/lombok/javac/handlers/HandleDelegate.java index ac414fbb..4d72eea3 100644 --- a/src/core/lombok/javac/handlers/HandleDelegate.java +++ b/src/core/lombok/javac/handlers/HandleDelegate.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2014 The Project Lombok Authors. + * Copyright (C) 2010-2021 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 @@ -43,8 +43,6 @@ import javax.lang.model.type.ExecutableType; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; -import org.mangosdk.spi.ProviderFor; - import com.sun.tools.javac.code.Attribute.Compound; import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.code.Symbol; @@ -82,8 +80,9 @@ import lombok.javac.JavacResolution.TypeNotConvertibleException; import lombok.javac.JavacTreeMaker; import lombok.javac.ResolutionResetNeeded; import lombok.permit.Permit; +import lombok.spi.Provides; -@ProviderFor(JavacAnnotationHandler.class) +@Provides @HandlerPriority(HandleDelegate.HANDLE_DELEGATE_PRIORITY) //2^16; to make sure that we also delegate generated methods. @ResolutionResetNeeded public class HandleDelegate extends JavacAnnotationHandler<Delegate> { @@ -349,7 +348,7 @@ public class HandleDelegate extends JavacAnnotationHandler<Delegate> { JCStatement body = useReturn ? maker.Return(delegateCall) : maker.Exec(delegateCall); JCBlock bodyBlock = maker.Block(0, com.sun.tools.javac.util.List.of(body)); - return recursiveSetGeneratedBy(maker.MethodDef(mods, sig.name, returnType, toList(typeParams), toList(params), toList(thrown), bodyBlock, null), annotation.get(), annotation.getContext()); + return recursiveSetGeneratedBy(maker.MethodDef(mods, sig.name, returnType, toList(typeParams), toList(params), toList(thrown), bodyBlock, null), annotation); } public static <T> com.sun.tools.javac.util.List<T> toList(ListBuffer<T> collection) { diff --git a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java index c65fa491..ffe882d8 100644 --- a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java +++ b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2020 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -30,11 +30,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import org.mangosdk.spi.ProviderFor; - import com.sun.tools.javac.code.BoundKind; import com.sun.tools.javac.code.Flags; -import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCAnnotation; import com.sun.tools.javac.tree.JCTree.JCArrayTypeTree; import com.sun.tools.javac.tree.JCTree.JCBinary; @@ -71,11 +68,12 @@ import lombok.javac.JavacAnnotationHandler; import lombok.javac.JavacNode; import lombok.javac.JavacTreeMaker; import lombok.javac.handlers.JavacHandlerUtil.MemberExistsResult; +import lombok.spi.Provides; /** * Handles the {@code lombok.EqualsAndHashCode} annotation for javac. */ -@ProviderFor(JavacAnnotationHandler.class) +@Provides public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHashCode> { private static final String RESULT_NAME = "result"; private static final String PRIME_NAME = "PRIME"; @@ -97,9 +95,9 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas Boolean doNotUseGettersConfiguration = annotationNode.getAst().readConfiguration(ConfigurationKeys.EQUALS_AND_HASH_CODE_DO_NOT_USE_GETTERS); boolean doNotUseGetters = annotation.isExplicit("doNotUseGetters") || doNotUseGettersConfiguration == null ? ann.doNotUseGetters() : doNotUseGettersConfiguration; FieldAccess fieldAccess = doNotUseGetters ? FieldAccess.PREFER_FIELD : FieldAccess.GETTER; - + boolean cacheHashCode = ann.cacheStrategy() == CacheStrategy.LAZY; - + generateMethods(typeNode, annotationNode, members, callSuper, true, cacheHashCode, fieldAccess, onParam); } @@ -120,13 +118,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas public void generateMethods(JavacNode typeNode, JavacNode source, java.util.List<Included<JavacNode, EqualsAndHashCode.Include>> members, Boolean callSuper, boolean whineIfExists, boolean cacheHashCode, FieldAccess fieldAccess, List<JCAnnotation> onParam) { - boolean notAClass = true; - if (typeNode.get() instanceof JCClassDecl) { - long flags = ((JCClassDecl) typeNode.get()).mods.flags; - notAClass = (flags & (Flags.INTERFACE | Flags.ANNOTATION | Flags.ENUM)) != 0; - } - - if (notAClass) { + if (!isClass(typeNode)) { source.addError("@EqualsAndHashCode is only supported on a class."); return; } @@ -142,30 +134,6 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas boolean isDirectDescendantOfObject = isDirectDescendantOfObject(typeNode); - if (isDirectDescendantOfObject && callSuper) { - source.addError("Generating equals/hashCode with a supercall to java.lang.Object is pointless."); - return; - } - - if (implicitCallSuper && !isDirectDescendantOfObject) { - CallSuperType cst = typeNode.getAst().readConfiguration(ConfigurationKeys.EQUALS_AND_HASH_CODE_CALL_SUPER); - if (cst == null) cst = CallSuperType.WARN; - - switch (cst) { - default: - case WARN: - source.addWarning("Generating equals/hashCode implementation but without a call to superclass, even though this class does not extend java.lang.Object. If this is intentional, add '@EqualsAndHashCode(callSuper=false)' to your type."); - callSuper = false; - break; - case SKIP: - callSuper = false; - break; - case CALL: - callSuper = true; - break; - } - } - boolean isFinal = (((JCClassDecl) typeNode.get()).mods.flags & Flags.FINAL) != 0; boolean needsCanEqual = !isFinal || !isDirectDescendantOfObject; MemberExistsResult equalsExists = methodExists("equals", typeNode, 1); @@ -194,12 +162,36 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas //fallthrough } - JCMethodDecl equalsMethod = createEquals(typeNode, members, callSuper, fieldAccess, needsCanEqual, source.get(), onParam); + if (isDirectDescendantOfObject && callSuper) { + source.addError("Generating equals/hashCode with a supercall to java.lang.Object is pointless."); + return; + } + + if (implicitCallSuper && !isDirectDescendantOfObject) { + CallSuperType cst = typeNode.getAst().readConfiguration(ConfigurationKeys.EQUALS_AND_HASH_CODE_CALL_SUPER); + if (cst == null) cst = CallSuperType.WARN; + + switch (cst) { + default: + case WARN: + source.addWarning("Generating equals/hashCode implementation but without a call to superclass, even though this class does not extend java.lang.Object. If this is intentional, add '@EqualsAndHashCode(callSuper=false)' to your type."); + callSuper = false; + break; + case SKIP: + callSuper = false; + break; + case CALL: + callSuper = true; + break; + } + } + + JCMethodDecl equalsMethod = createEquals(typeNode, members, callSuper, fieldAccess, needsCanEqual, source, onParam); injectMethod(typeNode, equalsMethod); if (needsCanEqual && canEqualExists == MemberExistsResult.NOT_EXISTS) { - JCMethodDecl canEqualMethod = createCanEqual(typeNode, source.get(), onParam); + JCMethodDecl canEqualMethod = createCanEqual(typeNode, source, onParam); injectMethod(typeNode, canEqualMethod); } @@ -209,23 +201,23 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas source.addWarning(msg); cacheHashCode = false; } else { - createHashCodeCacheField(typeNode, source.get()); + createHashCodeCacheField(typeNode, source); } } - JCMethodDecl hashCodeMethod = createHashCode(typeNode, members, callSuper, cacheHashCode, fieldAccess, source.get()); + JCMethodDecl hashCodeMethod = createHashCode(typeNode, members, callSuper, cacheHashCode, fieldAccess, source); injectMethod(typeNode, hashCodeMethod); } - private void createHashCodeCacheField(JavacNode typeNode, JCTree source) { + private void createHashCodeCacheField(JavacNode typeNode, JavacNode source) { JavacTreeMaker maker = typeNode.getTreeMaker(); JCModifiers mods = maker.Modifiers(Flags.PRIVATE | Flags.TRANSIENT); JCVariableDecl hashCodeCacheField = maker.VarDef(mods, typeNode.toName(HASH_CODE_CACHE_NAME), maker.TypeIdent(CTC_INT), null); injectFieldAndMarkGenerated(typeNode, hashCodeCacheField); - recursiveSetGeneratedBy(hashCodeCacheField, source, typeNode.getContext()); + recursiveSetGeneratedBy(hashCodeCacheField, source); } - public JCMethodDecl createHashCode(JavacNode typeNode, java.util.List<Included<JavacNode, EqualsAndHashCode.Include>> members, boolean callSuper, boolean cacheHashCode, FieldAccess fieldAccess, JCTree source) { + public JCMethodDecl createHashCode(JavacNode typeNode, java.util.List<Included<JavacNode, EqualsAndHashCode.Include>> members, boolean callSuper, boolean cacheHashCode, FieldAccess fieldAccess, JavacNode source) { JavacTreeMaker maker = typeNode.getTreeMaker(); JCAnnotation overrideAnnotation = maker.Annotation(genJavaLangTypeRef(typeNode, "Override"), List.<JCExpression>nil()); @@ -364,7 +356,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas JCBlock body = maker.Block(0, statements.toList()); return recursiveSetGeneratedBy(maker.MethodDef(mods, typeNode.toName("hashCode"), returnType, - List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null), source, typeNode.getContext()); + List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null), source); } public JCExpressionStatement createResultCalculation(JavacNode typeNode, JCExpression expr) { @@ -426,7 +418,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas return maker.TypeApply(expr, wildcards.toList()); } - public JCMethodDecl createEquals(JavacNode typeNode, java.util.List<Included<JavacNode, EqualsAndHashCode.Include>> members, boolean callSuper, FieldAccess fieldAccess, boolean needsCanEqual, JCTree source, List<JCAnnotation> onParam) { + public JCMethodDecl createEquals(JavacNode typeNode, java.util.List<Included<JavacNode, EqualsAndHashCode.Include>> members, boolean callSuper, FieldAccess fieldAccess, boolean needsCanEqual, JavacNode source, List<JCAnnotation> onParam) { JavacTreeMaker maker = typeNode.getTreeMaker(); Name oName = typeNode.toName("o"); @@ -560,10 +552,10 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas } JCBlock body = maker.Block(0, statements.toList()); - return recursiveSetGeneratedBy(maker.MethodDef(mods, typeNode.toName("equals"), returnType, List.<JCTypeParameter>nil(), params, List.<JCExpression>nil(), body, null), source, typeNode.getContext()); + return recursiveSetGeneratedBy(maker.MethodDef(mods, typeNode.toName("equals"), returnType, List.<JCTypeParameter>nil(), params, List.<JCExpression>nil(), body, null), source); } - public JCMethodDecl createCanEqual(JavacNode typeNode, JCTree source, List<JCAnnotation> onParam) { + public JCMethodDecl createCanEqual(JavacNode typeNode, JavacNode source, List<JCAnnotation> onParam) { /* protected boolean canEqual(final java.lang.Object other) { * return other instanceof Outer.Inner.MyType; * } @@ -588,7 +580,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas JCBlock body = maker.Block(0, List.<JCStatement>of( maker.Return(maker.TypeTest(maker.Ident(otherName), createTypeReference(typeNode, false))))); - return recursiveSetGeneratedBy(maker.MethodDef(mods, canEqualName, returnType, List.<JCTypeParameter>nil(), params, List.<JCExpression>nil(), body, null), source, typeNode.getContext()); + return recursiveSetGeneratedBy(maker.MethodDef(mods, canEqualName, returnType, List.<JCTypeParameter>nil(), params, List.<JCExpression>nil(), body, null), source); } public JCStatement generateCompareFloatOrDouble(JCExpression thisDotField, JCExpression otherDotField, diff --git a/src/core/lombok/javac/handlers/HandleExtensionMethod.java b/src/core/lombok/javac/handlers/HandleExtensionMethod.java index 805a96f8..dd565f72 100644 --- a/src/core/lombok/javac/handlers/HandleExtensionMethod.java +++ b/src/core/lombok/javac/handlers/HandleExtensionMethod.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2014 The Project Lombok Authors. + * Copyright (C) 2012-2021 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 @@ -39,8 +39,7 @@ import lombok.experimental.ExtensionMethod; import lombok.javac.JavacAnnotationHandler; import lombok.javac.JavacNode; import lombok.javac.JavacResolution; - -import org.mangosdk.spi.ProviderFor; +import lombok.spi.Provides; import com.sun.source.tree.MethodInvocationTree; import com.sun.source.util.TreeScanner; @@ -65,7 +64,7 @@ import com.sun.tools.javac.tree.JCTree.JCMethodInvocation; /** * Handles the {@link ExtensionMethod} annotation for javac. */ -@ProviderFor(JavacAnnotationHandler.class) +@Provides @HandlerPriority(66560) // 2^16 + 2^10; we must run AFTER HandleVal which is at 2^16 public class HandleExtensionMethod extends JavacAnnotationHandler<ExtensionMethod> { @Override @@ -152,8 +151,9 @@ public class HandleExtensionMethod extends JavacAnnotationHandler<ExtensionMetho @Override public Void visitMethodInvocation(final MethodInvocationTree tree, final Void p) { + super.visitMethodInvocation(tree, p); handleMethodCall((JCMethodInvocation) tree); - return super.visitMethodInvocation(tree, p); + return null; } private void handleMethodCall(final JCMethodInvocation methodCall) { @@ -202,6 +202,7 @@ public class HandleExtensionMethod extends JavacAnnotationHandler<ExtensionMetho if (!types.isAssignable(receiverType, firstArgType)) continue; methodCall.args = methodCall.args.prepend(receiver); methodCall.meth = chainDotsString(annotationNode, extensionProvider.toString() + "." + methodName); + recursiveSetGeneratedBy(methodCall.meth, methodCallNode); return; } } diff --git a/src/core/lombok/javac/handlers/HandleFieldDefaults.java b/src/core/lombok/javac/handlers/HandleFieldDefaults.java index aa381c0d..ebab67e3 100644 --- a/src/core/lombok/javac/handlers/HandleFieldDefaults.java +++ b/src/core/lombok/javac/handlers/HandleFieldDefaults.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2016 The Project Lombok Authors. + * Copyright (C) 2012-2021 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 @@ -34,8 +34,7 @@ import lombok.experimental.PackagePrivate; import lombok.javac.JavacASTAdapter; import lombok.javac.JavacASTVisitor; import lombok.javac.JavacNode; - -import org.mangosdk.spi.ProviderFor; +import lombok.spi.Provides; import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.tree.JCTree; @@ -46,7 +45,7 @@ import com.sun.tools.javac.tree.JCTree.JCVariableDecl; /** * Handles the {@code lombok.FieldDefaults} annotation for javac. */ -@ProviderFor(JavacASTVisitor.class) +@Provides(JavacASTVisitor.class) @HandlerPriority(-2048) //-2^11; to ensure @Value picks up on messing with the fields' 'final' state, run earlier. public class HandleFieldDefaults extends JavacASTAdapter { public boolean generateFieldDefaultsForType(JavacNode typeNode, JavacNode errorNode, AccessLevel level, boolean makeFinal, boolean checkForTypeLevelFieldDefaults) { @@ -57,12 +56,7 @@ public class HandleFieldDefaults extends JavacASTAdapter { } } - JCClassDecl typeDecl = null; - if (typeNode.get() instanceof JCClassDecl) typeDecl = (JCClassDecl) typeNode.get(); - long modifiers = typeDecl == null ? 0 : typeDecl.mods.flags; - boolean notAClass = (modifiers & (Flags.INTERFACE | Flags.ANNOTATION)) != 0; - - if (typeDecl == null || notAClass) { + if (!isClassOrEnum(typeNode)) { errorNode.addError("@FieldDefaults is only supported on a class or an enum."); return false; } diff --git a/src/core/lombok/javac/handlers/HandleFieldNameConstants.java b/src/core/lombok/javac/handlers/HandleFieldNameConstants.java index ec4015c7..f3c879d5 100644 --- a/src/core/lombok/javac/handlers/HandleFieldNameConstants.java +++ b/src/core/lombok/javac/handlers/HandleFieldNameConstants.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014-2019 The Project Lombok Authors. + * Copyright (C) 2014-2021 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 @@ -36,8 +36,7 @@ import lombok.experimental.FieldNameConstants; import lombok.javac.JavacAnnotationHandler; import lombok.javac.JavacNode; import lombok.javac.JavacTreeMaker; - -import org.mangosdk.spi.ProviderFor; +import lombok.spi.Provides; import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.tree.JCTree; @@ -53,7 +52,7 @@ import com.sun.tools.javac.tree.JCTree.JCVariableDecl; import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.Name; -@ProviderFor(JavacAnnotationHandler.class) +@Provides public class HandleFieldNameConstants extends JavacAnnotationHandler<FieldNameConstants> { private static final IdentifierName FIELDS = IdentifierName.valueOf("Fields"); @@ -78,7 +77,7 @@ public class HandleFieldNameConstants extends JavacAnnotationHandler<FieldNameCo if (qualified.isEmpty()) { errorNode.addWarning("No fields qualify for @FieldNameConstants, therefore this annotation does nothing"); } else { - createInnerTypeFieldNameConstants(typeNode, errorNode, errorNode.get(), level, qualified, asEnum, innerTypeName, uppercase); + createInnerTypeFieldNameConstants(typeNode, errorNode, level, qualified, asEnum, innerTypeName, uppercase); } } @@ -133,7 +132,7 @@ public class HandleFieldNameConstants extends JavacAnnotationHandler<FieldNameCo generateFieldNameConstantsForType(node, annotationNode, level, asEnum, innerTypeName, annotationInstance.onlyExplicitlyIncluded(), uppercase); } - private void createInnerTypeFieldNameConstants(JavacNode typeNode, JavacNode errorNode, JCTree pos, AccessLevel level, java.util.List<JavacNode> fields, boolean asEnum, IdentifierName innerTypeName, boolean uppercase) { + private void createInnerTypeFieldNameConstants(JavacNode typeNode, JavacNode errorNode, AccessLevel level, java.util.List<JavacNode> fields, boolean asEnum, IdentifierName innerTypeName, boolean uppercase) { if (fields.isEmpty()) return; JavacTreeMaker maker = typeNode.getTreeMaker(); @@ -146,7 +145,7 @@ public class HandleFieldNameConstants extends JavacAnnotationHandler<FieldNameCo if (fieldsType == null) { JCClassDecl innerType = maker.ClassDef(mods, fieldsName, List.<JCTypeParameter>nil(), null, List.<JCExpression>nil(), List.<JCTree>nil()); fieldsType = injectType(typeNode, innerType); - recursiveSetGeneratedBy(innerType, pos, typeNode.getContext()); + recursiveSetGeneratedBy(innerType, errorNode); genConstr = true; } else { JCClassDecl builderTypeDeclaration = (JCClassDecl) fieldsType.get(); @@ -166,7 +165,7 @@ public class HandleFieldNameConstants extends JavacAnnotationHandler<FieldNameCo JCModifiers genConstrMods = maker.Modifiers(Flags.GENERATEDCONSTR | (asEnum ? 0L : Flags.PRIVATE)); JCBlock genConstrBody = maker.Block(0L, List.<JCStatement>of(maker.Exec(maker.Apply(List.<JCExpression>nil(), maker.Ident(typeNode.toName("super")), List.<JCExpression>nil())))); JCMethodDecl c = maker.MethodDef(genConstrMods, typeNode.toName("<init>"), null, List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), genConstrBody, null); - recursiveSetGeneratedBy(c, pos, typeNode.getContext()); + recursiveSetGeneratedBy(c, errorNode); injectMethod(fieldsType, c); } @@ -187,9 +186,9 @@ public class HandleFieldNameConstants extends JavacAnnotationHandler<FieldNameCo } JCVariableDecl constantField = maker.VarDef(constantValueMods, fName, returnType, init); injectField(fieldsType, constantField, false, true); - setGeneratedBy(constantField, pos, typeNode.getContext()); + setGeneratedBy(constantField, errorNode); generated.add(constantField); } - for (JCVariableDecl cf : generated) recursiveSetGeneratedBy(cf, pos, typeNode.getContext()); + for (JCVariableDecl cf : generated) recursiveSetGeneratedBy(cf, errorNode); } } diff --git a/src/core/lombok/javac/handlers/HandleGetter.java b/src/core/lombok/javac/handlers/HandleGetter.java index afe2c1b6..8f6de9bb 100644 --- a/src/core/lombok/javac/handlers/HandleGetter.java +++ b/src/core/lombok/javac/handlers/HandleGetter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2020 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -43,8 +43,7 @@ import lombok.javac.JavacAnnotationHandler; import lombok.javac.JavacNode; import lombok.javac.JavacTreeMaker; import lombok.javac.JavacTreeMaker.TypeTag; - -import org.mangosdk.spi.ProviderFor; +import lombok.spi.Provides; import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.code.Type; @@ -52,7 +51,6 @@ import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCAnnotation; import com.sun.tools.javac.tree.JCTree.JCBinary; import com.sun.tools.javac.tree.JCTree.JCBlock; -import com.sun.tools.javac.tree.JCTree.JCClassDecl; import com.sun.tools.javac.tree.JCTree.JCExpression; import com.sun.tools.javac.tree.JCTree.JCExpressionStatement; import com.sun.tools.javac.tree.JCTree.JCIf; @@ -71,8 +69,10 @@ import com.sun.tools.javac.util.Name; /** * Handles the {@code lombok.Getter} annotation for javac. */ -@ProviderFor(JavacAnnotationHandler.class) +@Provides public class HandleGetter extends JavacAnnotationHandler<Getter> { + private static final String GETTER_NODE_NOT_SUPPORTED_ERR = "@Getter is only supported on a class, an enum, or a field."; + public void generateGetterForType(JavacNode typeNode, JavacNode errorNode, AccessLevel level, boolean checkForTypeLevelGetter, List<JCAnnotation> onMethod) { if (checkForTypeLevelGetter) { if (hasAnnotation(Getter.class, typeNode)) { @@ -81,13 +81,8 @@ public class HandleGetter extends JavacAnnotationHandler<Getter> { } } - JCClassDecl typeDecl = null; - if (typeNode.get() instanceof JCClassDecl) typeDecl = (JCClassDecl) typeNode.get(); - long modifiers = typeDecl == null ? 0 : typeDecl.mods.flags; - boolean notAClass = (modifiers & (Flags.INTERFACE | Flags.ANNOTATION)) != 0; - - if (typeDecl == null || notAClass) { - errorNode.addError("@Getter is only supported on a class, an enum, or a field."); + if (!isClassOrEnum(typeNode)) { + errorNode.addError(GETTER_NODE_NOT_SUPPORTED_ERR); return; } @@ -171,7 +166,7 @@ public class HandleGetter extends JavacAnnotationHandler<Getter> { JavacNode fieldNode, JavacNode source, boolean whineIfExists, boolean lazy, List<JCAnnotation> onMethod) { if (fieldNode.getKind() != Kind.FIELD) { - source.addError("@Getter is only supported on a class or a field."); + source.addError(GETTER_NODE_NOT_SUPPORTED_ERR); return; } @@ -219,14 +214,14 @@ public class HandleGetter extends JavacAnnotationHandler<Getter> { long access = toJavacModifier(level) | (fieldDecl.mods.flags & Flags.STATIC); - injectMethod(fieldNode.up(), createGetter(access, fieldNode, fieldNode.getTreeMaker(), source.get(), lazy, onMethod), List.<Type>nil(), getMirrorForFieldType(fieldNode)); + injectMethod(fieldNode.up(), createGetter(access, fieldNode, fieldNode.getTreeMaker(), source, lazy, onMethod), List.<Type>nil(), getMirrorForFieldType(fieldNode)); } - public JCMethodDecl createGetter(long access, JavacNode field, JavacTreeMaker treeMaker, JCTree source, boolean lazy, List<JCAnnotation> onMethod) { + public JCMethodDecl createGetter(long access, JavacNode field, JavacTreeMaker treeMaker, JavacNode source, boolean lazy, List<JCAnnotation> onMethod) { JCVariableDecl fieldNode = (JCVariableDecl) field.get(); // Remember the type; lazy will change it - JCExpression methodType = cloneType(treeMaker, copyType(treeMaker, fieldNode), source, field.getContext()); + JCExpression methodType = cloneType(treeMaker, copyType(treeMaker, fieldNode), source); // Generate the methodName; lazy will change the field type Name methodName = field.toName(toGetterName(field)); @@ -267,9 +262,9 @@ public class HandleGetter extends JavacAnnotationHandler<Getter> { if (isFieldDeprecated(field)) annsOnMethod = annsOnMethod.prepend(treeMaker.Annotation(genJavaLangTypeRef(field, "Deprecated"), List.<JCExpression>nil())); JCMethodDecl decl = recursiveSetGeneratedBy(treeMaker.MethodDef(treeMaker.Modifiers(access, annsOnMethod), methodName, methodType, - methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue), source, field.getContext()); + methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue), source); - if (toClearOfMarkers != null) recursiveSetGeneratedBy(toClearOfMarkers, null, null); + if (toClearOfMarkers != null) recursiveSetGeneratedBy(toClearOfMarkers, null); if (methodArgPos != null) { for (int i = 0; i < methodArgPos.length; i++) { ((JCMethodInvocation) toClearOfMarkers).args.get(i).pos = methodArgPos[i]; @@ -280,10 +275,10 @@ public class HandleGetter extends JavacAnnotationHandler<Getter> { if (addSuppressWarningsUnchecked) { ListBuffer<JCExpression> suppressions = new ListBuffer<JCExpression>(); if (!Boolean.FALSE.equals(field.getAst().readConfiguration(ConfigurationKeys.ADD_SUPPRESSWARNINGS_ANNOTATIONS))) { - suppressions.add(treeMaker.Literal("all")); + suppressions.append(treeMaker.Literal("all")); } - suppressions.add(treeMaker.Literal("unchecked")); - addAnnotation(decl.mods, field, source.pos, source, field.getContext(), "java.lang.SuppressWarnings", treeMaker.NewArray(null, List.<JCExpression>nil(), suppressions.toList())); + suppressions.append(treeMaker.Literal("unchecked")); + addAnnotation(decl.mods, field, source, "java.lang.SuppressWarnings", treeMaker.NewArray(null, List.<JCExpression>nil(), suppressions.toList())); } copyJavadoc(field, decl, CopyJavadoc.GETTER); @@ -334,7 +329,7 @@ public class HandleGetter extends JavacAnnotationHandler<Getter> { TYPE_MAP = Collections.unmodifiableMap(m); } - public List<JCStatement> createLazyGetterBody(JavacTreeMaker maker, JavacNode fieldNode, JCTree source) { + public List<JCStatement> createLazyGetterBody(JavacTreeMaker maker, JavacNode fieldNode, JavacNode source) { /* java.lang.Object value = this.fieldName.get(); if (value == null) { @@ -447,8 +442,8 @@ public class HandleGetter extends JavacAnnotationHandler<Getter> { /* private final java.util.concurrent.atomic.AtomicReference<Object> fieldName = new java.util.concurrent.atomic.AtomicReference<Object>(); */ { field.vartype = recursiveSetGeneratedBy( - maker.TypeApply(chainDotsString(fieldNode, AR), List.<JCExpression>of(genJavaLangTypeRef(fieldNode, "Object"))), source, fieldNode.getContext()); - field.init = recursiveSetGeneratedBy(maker.NewClass(null, NIL_EXPRESSION, copyType(maker, field), NIL_EXPRESSION, null), source, fieldNode.getContext()); + maker.TypeApply(chainDotsString(fieldNode, AR), List.<JCExpression>of(genJavaLangTypeRef(fieldNode, "Object"))), source); + field.init = recursiveSetGeneratedBy(maker.NewClass(null, NIL_EXPRESSION, copyType(maker, field), NIL_EXPRESSION, null), source); } return statements.toList(); diff --git a/src/core/lombok/javac/handlers/HandleHelper.java b/src/core/lombok/javac/handlers/HandleHelper.java index 6f4361c1..35b0c4f2 100755 --- a/src/core/lombok/javac/handlers/HandleHelper.java +++ b/src/core/lombok/javac/handlers/HandleHelper.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015-2016 The Project Lombok Authors. + * Copyright (C) 2015-2021 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 @@ -29,8 +29,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.Iterator; -import org.mangosdk.spi.ProviderFor; - import com.sun.source.tree.MethodInvocationTree; import com.sun.source.tree.TreeVisitor; import com.sun.source.util.TreeScanner; @@ -56,8 +54,9 @@ import lombok.experimental.Helper; import lombok.javac.JavacAnnotationHandler; import lombok.javac.JavacNode; import lombok.javac.JavacTreeMaker; +import lombok.spi.Provides; -@ProviderFor(JavacAnnotationHandler.class) +@Provides public class HandleHelper extends JavacAnnotationHandler<Helper> { private List<JCStatement> getStatementsFromJcNode(JCTree tree) { if (tree instanceof JCBlock) return ((JCBlock) tree).stats; @@ -71,7 +70,7 @@ public class HandleHelper extends JavacAnnotationHandler<Helper> { else throw new IllegalArgumentException("Can't set statements on node type: " + tree.getClass()); } - @Override public void handle(AnnotationValues<Helper> annotation, JCAnnotation ast, JavacNode annotationNode) { + @Override public void handle(AnnotationValues<Helper> annotation, JCAnnotation ast, final JavacNode annotationNode) { handleExperimentalFlagUsage(annotationNode, ConfigurationKeys.HELPER_FLAG_USAGE, "@Helper"); deleteAnnotationIfNeccessary(annotationNode, Helper.class); @@ -120,6 +119,7 @@ public class HandleHelper extends JavacAnnotationHandler<Helper> { JCIdent jci = (JCIdent) jcmi.meth; if (Arrays.binarySearch(knownMethodNames_, jci.name.toString()) < 0) return; jcmi.meth = maker.Select(maker.Ident(helperName), jci.name); + recursiveSetGeneratedBy(jcmi.meth, annotationNode); helperUsed[0] = true; } }; @@ -144,6 +144,7 @@ public class HandleHelper extends JavacAnnotationHandler<Helper> { JCExpression init = maker.NewClass(null, List.<JCExpression>nil(), maker.Ident(annotatedType_.name), List.<JCExpression>nil(), null); JCExpression varType = maker.Ident(annotatedType_.name); JCVariableDecl decl = maker.VarDef(maker.Modifiers(Flags.FINAL), helperName, varType, init); + recursiveSetGeneratedBy(decl, annotationNode); newStatements.append(decl); } setStatementsOfJcNode(containingBlock.get(), newStatements.toList()); diff --git a/src/core/lombok/javac/handlers/HandleJacksonized.java b/src/core/lombok/javac/handlers/HandleJacksonized.java index 0aa02d1b..3ee0eec4 100644 --- a/src/core/lombok/javac/handlers/HandleJacksonized.java +++ b/src/core/lombok/javac/handlers/HandleJacksonized.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 The Project Lombok Authors. + * Copyright (C) 2020-2021 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 @@ -24,8 +24,6 @@ package lombok.javac.handlers; import static lombok.core.handlers.HandlerUtil.handleExperimentalFlagUsage; import static lombok.javac.handlers.JavacHandlerUtil.*; -import org.mangosdk.spi.ProviderFor; - import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCAnnotation; @@ -49,13 +47,14 @@ import lombok.extern.jackson.Jacksonized; import lombok.javac.JavacAnnotationHandler; import lombok.javac.JavacNode; import lombok.javac.JavacTreeMaker; +import lombok.spi.Provides; /** * This (javac) handler deals with {@code @Jacksonized} modifying the (already * generated) {@code @Builder} or {@code @SuperBuilder} to conform to Jackson's * needs for builders. */ -@ProviderFor(JavacAnnotationHandler.class) +@Provides @HandlerPriority(-512) // Above Handle(Super)Builder's level (builders must be already generated). public class HandleJacksonized extends JavacAnnotationHandler<Jacksonized> { @@ -107,7 +106,7 @@ public class HandleJacksonized extends JavacAnnotationHandler<Jacksonized> { JavacTreeMaker maker = annotatedNode.getTreeMaker(); // Now lets find the generated builder class. - String builderClassName = getBuilderClassName(ast, annotationNode, annotatedNode, td, builderAnnotation, maker); + String builderClassName = getBuilderClassName(annotationNode, annotatedNode, td, builderAnnotation, maker); JCClassDecl builderClass = null; for (JCTree member : td.getMembers()) { @@ -132,11 +131,15 @@ public class HandleJacksonized extends JavacAnnotationHandler<Jacksonized> { JCFieldAccess builderClassReference = maker.Select(builderClassExpression, annotatedNode.toName("class")); JCExpression assign = maker.Assign(maker.Ident(annotationNode.toName("builder")), builderClassReference); JCAnnotation annotationJsonDeserialize = maker.Annotation(jsonDeserializeType, List.of(assign)); + recursiveSetGeneratedBy(annotationJsonDeserialize, annotationNode); td.mods.annotations = td.mods.annotations.append(annotationJsonDeserialize); // Copy annotations from the class to the builder class. List<JCAnnotation> copyableAnnotations = findJacksonAnnotationsOnClass(tdNode); List<JCAnnotation> copiedAnnotations = copyAnnotations(copyableAnnotations); + for (JCAnnotation anno : copiedAnnotations) { + recursiveSetGeneratedBy(anno, annotationNode); + } builderClass.mods.annotations = builderClass.mods.annotations.appendList(copiedAnnotations); // Insert @JsonPOJOBuilder on the builder class. @@ -144,6 +147,7 @@ public class HandleJacksonized extends JavacAnnotationHandler<Jacksonized> { JCExpression withPrefixExpr = maker.Assign(maker.Ident(annotationNode.toName("withPrefix")), maker.Literal(setPrefix)); JCExpression buildMethodNameExpr = maker.Assign(maker.Ident(annotationNode.toName("buildMethodName")), maker.Literal(buildMethodName)); JCAnnotation annotationJsonPOJOBuilder = maker.Annotation(jsonPOJOBuilderType, List.of(withPrefixExpr, buildMethodNameExpr)); + recursiveSetGeneratedBy(annotationJsonPOJOBuilder, annotatedNode); builderClass.mods.annotations = builderClass.mods.annotations.append(annotationJsonPOJOBuilder); // @SuperBuilder? Make it package-private! @@ -151,7 +155,7 @@ public class HandleJacksonized extends JavacAnnotationHandler<Jacksonized> { builderClass.mods.flags = builderClass.mods.flags & ~Flags.PRIVATE; } - private String getBuilderClassName(JCAnnotation ast, JavacNode annotationNode, JavacNode annotatedNode, JCClassDecl td, AnnotationValues<Builder> builderAnnotation, JavacTreeMaker maker) { + private String getBuilderClassName(JavacNode annotationNode, JavacNode annotatedNode, JCClassDecl td, AnnotationValues<Builder> builderAnnotation, JavacTreeMaker maker) { String builderClassName = builderAnnotation != null ? builderAnnotation.getInstance().builderClassName() : null; if (builderClassName == null || builderClassName.isEmpty()) { @@ -166,7 +170,7 @@ public class HandleJacksonized extends JavacAnnotationHandler<Jacksonized> { JCExpression returnType = fillParametersFrom.restype; List<JCTypeParameter> typeParams = fillParametersFrom.typarams; if (returnType instanceof JCTypeApply) { - returnType = cloneType(maker, returnType, ast, annotationNode.getContext()); + returnType = cloneType(maker, returnType, annotatedNode); } replacement = HandleBuilder.returnTypeToBuilderClassName(annotationNode, td, returnType, typeParams); } else { diff --git a/src/core/lombok/javac/handlers/HandleLog.java b/src/core/lombok/javac/handlers/HandleLog.java index 3173b3ba..47c4098f 100644 --- a/src/core/lombok/javac/handlers/HandleLog.java +++ b/src/core/lombok/javac/handlers/HandleLog.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2019 The Project Lombok Authors. + * Copyright (C) 2010-2021 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 @@ -31,15 +31,14 @@ import lombok.core.configuration.IdentifierName; import lombok.core.configuration.LogDeclaration; import lombok.core.configuration.LogDeclaration.LogFactoryParameter; import lombok.core.handlers.LoggingFramework; +import lombok.javac.Javac; import lombok.javac.JavacAnnotationHandler; import lombok.javac.JavacNode; import lombok.javac.JavacTreeMaker; import lombok.javac.handlers.JavacHandlerUtil.MemberExistsResult; - -import org.mangosdk.spi.ProviderFor; +import lombok.spi.Provides; import com.sun.tools.javac.code.Flags; -import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCAnnotation; import com.sun.tools.javac.tree.JCTree.JCClassDecl; import com.sun.tools.javac.tree.JCTree.JCExpression; @@ -76,9 +75,14 @@ public class HandleLog { return; } + if (isRecord(typeNode) && !useStatic) { + annotationNode.addError("Logger fields must be static in records."); + return; + } + Object valueGuess = annotation.getValueGuess("topic"); JCExpression loggerTopic = (JCExpression) annotation.getActualExpression("topic"); - + if (valueGuess instanceof String && ((String) valueGuess).trim().isEmpty()) loggerTopic = null; if (framework.getDeclaration().getParametersWithTopic() == null && loggerTopic != null) { annotationNode.addError(framework.getAnnotationAsString() + " does not allow a topic."); @@ -90,7 +94,7 @@ public class HandleLog { } JCFieldAccess loggingType = selfType(typeNode); - createField(framework, typeNode, loggingType, annotationNode.get(), logFieldName.getName(), useStatic, loggerTopic); + createField(framework, typeNode, loggingType, annotationNode, logFieldName.getName(), useStatic, loggerTopic); break; default: annotationNode.addError("@Log is legal only on types."); @@ -104,7 +108,7 @@ public class HandleLog { return maker.Select(maker.Ident(name), typeNode.toName("class")); } - private static boolean createField(LoggingFramework framework, JavacNode typeNode, JCFieldAccess loggingType, JCTree source, String logFieldName, boolean useStatic, JCExpression loggerTopic) { + private static boolean createField(LoggingFramework framework, JavacNode typeNode, JCFieldAccess loggingType, JavacNode source, String logFieldName, boolean useStatic, JCExpression loggerTopic) { JavacTreeMaker maker = typeNode.getTreeMaker(); LogDeclaration logDeclaration = framework.getDeclaration(); @@ -118,9 +122,16 @@ public class HandleLog { JCVariableDecl fieldDecl = recursiveSetGeneratedBy(maker.VarDef( maker.Modifiers(Flags.PRIVATE | Flags.FINAL | (useStatic ? Flags.STATIC : 0)), - typeNode.toName(logFieldName), loggerType, factoryMethodCall), source, typeNode.getContext()); + typeNode.toName(logFieldName), loggerType, factoryMethodCall), source); + + if (isRecord(typeNode) && Javac.getJavaCompilerVersion() < 16) { + // This is a workaround for https://bugs.openjdk.java.net/browse/JDK-8243057 + + injectField(typeNode, fieldDecl); + } else { + injectFieldAndMarkGenerated(typeNode, fieldDecl); + } - injectFieldAndMarkGenerated(typeNode, fieldDecl); return true; } @@ -155,7 +166,7 @@ public class HandleLog { /** * Handles the {@link lombok.extern.apachecommons.CommonsLog} annotation for javac. */ - @ProviderFor(JavacAnnotationHandler.class) + @Provides public static class HandleCommonsLog extends JavacAnnotationHandler<lombok.extern.apachecommons.CommonsLog> { @Override public void handle(AnnotationValues<lombok.extern.apachecommons.CommonsLog> annotation, JCAnnotation ast, JavacNode annotationNode) { handleFlagUsage(annotationNode, ConfigurationKeys.LOG_COMMONS_FLAG_USAGE, "@apachecommons.CommonsLog", ConfigurationKeys.LOG_ANY_FLAG_USAGE, "any @Log"); @@ -166,7 +177,7 @@ public class HandleLog { /** * Handles the {@link lombok.extern.java.Log} annotation for javac. */ - @ProviderFor(JavacAnnotationHandler.class) + @Provides public static class HandleJulLog extends JavacAnnotationHandler<lombok.extern.java.Log> { @Override public void handle(AnnotationValues<lombok.extern.java.Log> annotation, JCAnnotation ast, JavacNode annotationNode) { handleFlagUsage(annotationNode, ConfigurationKeys.LOG_JUL_FLAG_USAGE, "@java.Log", ConfigurationKeys.LOG_ANY_FLAG_USAGE, "any @Log"); @@ -177,7 +188,7 @@ public class HandleLog { /** * Handles the {@link lombok.extern.log4j.Log4j} annotation for javac. */ - @ProviderFor(JavacAnnotationHandler.class) + @Provides public static class HandleLog4jLog extends JavacAnnotationHandler<lombok.extern.log4j.Log4j> { @Override public void handle(AnnotationValues<lombok.extern.log4j.Log4j> annotation, JCAnnotation ast, JavacNode annotationNode) { handleFlagUsage(annotationNode, ConfigurationKeys.LOG_LOG4J_FLAG_USAGE, "@Log4j", ConfigurationKeys.LOG_ANY_FLAG_USAGE, "any @Log"); @@ -188,7 +199,7 @@ public class HandleLog { /** * Handles the {@link lombok.extern.log4j.Log4j2} annotation for javac. */ - @ProviderFor(JavacAnnotationHandler.class) + @Provides public static class HandleLog4j2Log extends JavacAnnotationHandler<lombok.extern.log4j.Log4j2> { @Override public void handle(AnnotationValues<lombok.extern.log4j.Log4j2> annotation, JCAnnotation ast, JavacNode annotationNode) { handleFlagUsage(annotationNode, ConfigurationKeys.LOG_LOG4J2_FLAG_USAGE, "@Log4j2", ConfigurationKeys.LOG_ANY_FLAG_USAGE, "any @Log"); @@ -199,7 +210,7 @@ public class HandleLog { /** * Handles the {@link lombok.extern.slf4j.Slf4j} annotation for javac. */ - @ProviderFor(JavacAnnotationHandler.class) + @Provides public static class HandleSlf4jLog extends JavacAnnotationHandler<lombok.extern.slf4j.Slf4j> { @Override public void handle(AnnotationValues<lombok.extern.slf4j.Slf4j> annotation, JCAnnotation ast, JavacNode annotationNode) { handleFlagUsage(annotationNode, ConfigurationKeys.LOG_SLF4J_FLAG_USAGE, "@Slf4j", ConfigurationKeys.LOG_ANY_FLAG_USAGE, "any @Log"); @@ -210,7 +221,7 @@ public class HandleLog { /** * Handles the {@link lombok.extern.slf4j.XSlf4j} annotation for javac. */ - @ProviderFor(JavacAnnotationHandler.class) + @Provides public static class HandleXSlf4jLog extends JavacAnnotationHandler<lombok.extern.slf4j.XSlf4j> { @Override public void handle(AnnotationValues<lombok.extern.slf4j.XSlf4j> annotation, JCAnnotation ast, JavacNode annotationNode) { handleFlagUsage(annotationNode, ConfigurationKeys.LOG_XSLF4J_FLAG_USAGE, "@XSlf4j", ConfigurationKeys.LOG_ANY_FLAG_USAGE, "any @Log"); @@ -221,7 +232,7 @@ public class HandleLog { /** * Handles the {@link lombok.extern.jbosslog.JBossLog} annotation for javac. */ - @ProviderFor(JavacAnnotationHandler.class) + @Provides public static class HandleJBossLog extends JavacAnnotationHandler<lombok.extern.jbosslog.JBossLog> { @Override public void handle(AnnotationValues<lombok.extern.jbosslog.JBossLog> annotation, JCAnnotation ast, JavacNode annotationNode) { handleFlagUsage(annotationNode, ConfigurationKeys.LOG_JBOSSLOG_FLAG_USAGE, "@JBossLog", ConfigurationKeys.LOG_ANY_FLAG_USAGE, "any @Log"); @@ -232,7 +243,7 @@ public class HandleLog { /** * Handles the {@link lombok.extern.flogger.Flogger} annotation for javac. */ - @ProviderFor(JavacAnnotationHandler.class) + @Provides public static class HandleFloggerLog extends JavacAnnotationHandler<lombok.extern.flogger.Flogger> { @Override public void handle(AnnotationValues<lombok.extern.flogger.Flogger> annotation, JCAnnotation ast, JavacNode annotationNode) { handleFlagUsage(annotationNode, ConfigurationKeys.LOG_FLOGGER_FLAG_USAGE, "@Flogger", ConfigurationKeys.LOG_ANY_FLAG_USAGE, "any @Log"); @@ -243,7 +254,7 @@ public class HandleLog { /** * Handles the {@link lombok.CustomLog} annotation for javac. */ - @ProviderFor(JavacAnnotationHandler.class) + @Provides public static class HandleCustomLog extends JavacAnnotationHandler<lombok.CustomLog> { @Override public void handle(AnnotationValues<lombok.CustomLog> annotation, JCAnnotation ast, JavacNode annotationNode) { handleFlagUsage(annotationNode, ConfigurationKeys.LOG_CUSTOM_FLAG_USAGE, "@CustomLog", ConfigurationKeys.LOG_ANY_FLAG_USAGE, "any @Log"); diff --git a/src/core/lombok/javac/handlers/HandleNonNull.java b/src/core/lombok/javac/handlers/HandleNonNull.java index 079d5b04..786a7659 100644 --- a/src/core/lombok/javac/handlers/HandleNonNull.java +++ b/src/core/lombok/javac/handlers/HandleNonNull.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2019 The Project Lombok Authors. + * Copyright (C) 2013-2021 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 @@ -27,13 +27,16 @@ import static lombok.javac.JavacTreeMaker.TreeTag.treeTag; import static lombok.javac.JavacTreeMaker.TypeTag.typeTag; import static lombok.javac.handlers.JavacHandlerUtil.*; -import org.mangosdk.spi.ProviderFor; +import java.util.ArrayList; +import com.sun.tools.javac.code.Flags; +import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCAnnotation; import com.sun.tools.javac.tree.JCTree.JCAssert; import com.sun.tools.javac.tree.JCTree.JCAssign; import com.sun.tools.javac.tree.JCTree.JCBinary; import com.sun.tools.javac.tree.JCTree.JCBlock; +import com.sun.tools.javac.tree.JCTree.JCClassDecl; import com.sun.tools.javac.tree.JCTree.JCExpression; import com.sun.tools.javac.tree.JCTree.JCExpressionStatement; import com.sun.tools.javac.tree.JCTree.JCFieldAccess; @@ -42,15 +45,19 @@ import com.sun.tools.javac.tree.JCTree.JCIf; import com.sun.tools.javac.tree.JCTree.JCLiteral; import com.sun.tools.javac.tree.JCTree.JCMethodDecl; import com.sun.tools.javac.tree.JCTree.JCMethodInvocation; +import com.sun.tools.javac.tree.JCTree.JCModifiers; import com.sun.tools.javac.tree.JCTree.JCParens; import com.sun.tools.javac.tree.JCTree.JCStatement; import com.sun.tools.javac.tree.JCTree.JCSynchronized; import com.sun.tools.javac.tree.JCTree.JCThrow; import com.sun.tools.javac.tree.JCTree.JCTry; +import com.sun.tools.javac.tree.JCTree.JCTypeParameter; import com.sun.tools.javac.tree.JCTree.JCVariableDecl; import com.sun.tools.javac.util.List; +import com.sun.tools.javac.util.ListBuffer; import com.sun.tools.javac.util.Name; +import lombok.AccessLevel; import lombok.ConfigurationKeys; import lombok.NonNull; import lombok.core.AST.Kind; @@ -58,68 +65,102 @@ import lombok.core.AnnotationValues; import lombok.core.HandlerPriority; import lombok.javac.JavacAnnotationHandler; import lombok.javac.JavacNode; +import lombok.javac.JavacTreeMaker; +import lombok.spi.Provides; -@ProviderFor(JavacAnnotationHandler.class) +@Provides @HandlerPriority(value = 512) // 2^9; onParameter=@__(@NonNull) has to run first. public class HandleNonNull extends JavacAnnotationHandler<NonNull> { - @Override public void handle(AnnotationValues<NonNull> annotation, JCAnnotation ast, JavacNode annotationNode) { - handleFlagUsage(annotationNode, ConfigurationKeys.NON_NULL_FLAG_USAGE, "@NonNull"); + private JCMethodDecl createRecordArgslessConstructor(JavacNode typeNode, JavacNode source) { + JavacTreeMaker maker = typeNode.getTreeMaker(); - if (annotationNode.up().getKind() == Kind.FIELD) { - // This is meaningless unless the field is used to generate a method (@Setter, @RequiredArgsConstructor, etc), - // but in that case those handlers will take care of it. However, we DO check if the annotation is applied to - // a primitive, because those handlers trigger on any annotation named @NonNull and we only want the warning - // behaviour on _OUR_ 'lombok.NonNull'. - - try { - if (isPrimitive(((JCVariableDecl) annotationNode.up().get()).vartype)) { - annotationNode.addWarning("@NonNull is meaningless on a primitive."); + java.util.List<JCVariableDecl> fields = new ArrayList<JCVariableDecl>(); + for (JavacNode child : typeNode.down()) { + if (child.getKind() == Kind.FIELD) { + JCVariableDecl v = (JCVariableDecl) child.get(); + if ((v.mods.flags & RECORD) != 0) { + fields.add(v); } - } catch (Exception ignore) {} - - return; + } } - JCMethodDecl declaration; - JavacNode paramNode; + ListBuffer<JCVariableDecl> params = new ListBuffer<JCVariableDecl>(); - switch (annotationNode.up().getKind()) { - case ARGUMENT: - paramNode = annotationNode.up(); - break; - case TYPE_USE: - JavacNode typeNode = annotationNode.directUp(); - paramNode = typeNode.directUp(); - break; - default: - return; + for (int i = 0; i < fields.size(); i++) { + JCVariableDecl arg = fields.get(i); + JCModifiers mods = maker.Modifiers(GENERATED_MEMBER | Flags.PARAMETER, arg.mods.annotations); + params.append(maker.VarDef(mods, arg.name, arg.vartype, null)); } - if (paramNode.getKind() != Kind.ARGUMENT) return; - try { - declaration = (JCMethodDecl) paramNode.up().get(); - } catch (Exception e) { - return; + JCModifiers mods = maker.Modifiers(toJavacModifier(AccessLevel.PUBLIC) | COMPACT_RECORD_CONSTRUCTOR, List.<JCAnnotation>nil()); + JCBlock body = maker.Block(0L, List.<JCStatement>nil()); + JCMethodDecl constr = maker.MethodDef(mods, typeNode.toName("<init>"), null, List.<JCTypeParameter>nil(), params.toList(), List.<JCExpression>nil(), body, null); + return recursiveSetGeneratedBy(constr, source); + } + + /** + * If the provided typeNode is a record, returns the compact constructor (there should only be one, but if the file is + * not semantically sound there might be more). If the only one in existence is the default auto-generated one, it is removed, + * a new explicit one is created, and that one is returned in a list. + * + * Otherwise, an empty list is returned. + */ + private List<JCMethodDecl> addCompactConstructorIfNeeded(JavacNode typeNode, JavacNode source) { + List<JCMethodDecl> answer = List.nil(); + + if (typeNode == null || !(typeNode.get() instanceof JCClassDecl)) return answer; + + JCClassDecl cDecl = (JCClassDecl) typeNode.get(); + if ((cDecl.mods.flags & RECORD) == 0) return answer; + + ListBuffer<JCTree> newDefs = new ListBuffer<JCTree>(); + boolean generateConstructor = false; + + for (JCTree def : cDecl.defs) { + boolean remove = false; + if (def instanceof JCMethodDecl) { + JCMethodDecl md = (JCMethodDecl) def; + if (md.name.contentEquals("<init>")) { + if ((md.mods.flags & Flags.GENERATEDCONSTR) != 0) { + remove = true; + generateConstructor = true; + } else { + if (!isTolerate(typeNode, md)) { + if ((md.mods.flags & COMPACT_RECORD_CONSTRUCTOR) != 0) { + generateConstructor = false; + answer = answer.prepend(md); + } + } + } + } + } + if (!remove) newDefs.append(def); } - if (declaration.body == null) { - // This used to be a warning, but as @NonNull also has a documentary purpose, better to not warn about this. Since 1.16.7 - return; + if (generateConstructor) { + cDecl.defs = newDefs.toList(); + JCMethodDecl ctr = createRecordArgslessConstructor(typeNode, source); + injectMethod(typeNode, ctr); + answer = answer.prepend(ctr); } + return answer; + } + + private void addNullCheckIfNeeded(JCMethodDecl method, JavacNode paramNode, JavacNode source) { // Possibly, if 'declaration instanceof ConstructorDeclaration', fetch declaration.constructorCall, search it for any references to our parameter, // and if they exist, create a new method in the class: 'private static <T> T lombok$nullCheck(T expr, String msg) {if (expr == null) throw NPE; return expr;}' and // wrap all references to it in the super/this to a call to this method. - JCStatement nullCheck = recursiveSetGeneratedBy(generateNullCheck(annotationNode.getTreeMaker(), paramNode, annotationNode), ast, annotationNode.getContext()); + JCStatement nullCheck = recursiveSetGeneratedBy(generateNullCheck(source.getTreeMaker(), paramNode, source), source); if (nullCheck == null) { // @NonNull applied to a primitive. Kinda pointless. Let's generate a warning. - annotationNode.addWarning("@NonNull is meaningless on a primitive."); + source.addWarning("@NonNull is meaningless on a primitive."); return; } - List<JCStatement> statements = declaration.body.stats; + List<JCStatement> statements = method.body.stats; String expectedName = paramNode.getName(); @@ -158,8 +199,71 @@ public class HandleNonNull extends JavacAnnotationHandler<NonNull> { List<JCStatement> newList = tail.prepend(nullCheck); for (JCStatement stat : head) newList = newList.prepend(stat); - declaration.body.stats = newList; - annotationNode.getAst().setChanged(); + method.body.stats = newList; + source.getAst().setChanged(); + } + + @Override public void handle(AnnotationValues<NonNull> annotation, JCAnnotation ast, JavacNode annotationNode) { + handleFlagUsage(annotationNode, ConfigurationKeys.NON_NULL_FLAG_USAGE, "@NonNull"); + if (annotationNode.up().getKind() == Kind.FIELD) { + // This is meaningless unless the field is used to generate a method (@Setter, @RequiredArgsConstructor, etc), + // but in that case those handlers will take care of it. However, we DO check if the annotation is applied to + // a primitive, because those handlers trigger on any annotation named @NonNull and we only want the warning + // behaviour on _OUR_ 'lombok.NonNull'. + + try { + if (isPrimitive(((JCVariableDecl) annotationNode.up().get()).vartype)) { + annotationNode.addWarning("@NonNull is meaningless on a primitive."); + } + } catch (Exception ignore) {} + + JCVariableDecl fDecl = (JCVariableDecl) annotationNode.up().get(); + if ((fDecl.mods.flags & RECORD) != 0) { + // well, these kinda double as parameters (of the compact constructor), so we do some work here. + + List<JCMethodDecl> compactConstructors = addCompactConstructorIfNeeded(annotationNode.up().up(), annotationNode); + for (JCMethodDecl ctr : compactConstructors) { + addNullCheckIfNeeded(ctr, annotationNode.up(), annotationNode); + } + } + return; + } + + JCMethodDecl declaration; + JavacNode paramNode; + + switch (annotationNode.up().getKind()) { + case ARGUMENT: + paramNode = annotationNode.up(); + break; + case TYPE_USE: + JavacNode typeNode = annotationNode.directUp(); + paramNode = typeNode.directUp(); + break; + default: + return; + } + + if (paramNode.getKind() != Kind.ARGUMENT) return; + try { + declaration = (JCMethodDecl) paramNode.up().get(); + } catch (Exception e) { + return; + } + + if (declaration.body == null) { + // This used to be a warning, but as @NonNull also has a documentary purpose, better to not warn about this. Since 1.16.7 + return; + } + + if ((declaration.mods.flags & (GENERATED_MEMBER | COMPACT_RECORD_CONSTRUCTOR)) != 0) { + // The 'real' annotations are on the `record Foo(@NonNull Obj x)` part and we just see these + // syntax-sugared over. We deal with it on the field declaration variant, as those are always there, + // not dependent on whether you write out the compact constructor or not. + return; + } + + addNullCheckIfNeeded(declaration, paramNode, annotationNode); } public boolean isNullCheck(JCStatement stat) { diff --git a/src/core/lombok/javac/handlers/HandlePrintAST.java b/src/core/lombok/javac/handlers/HandlePrintAST.java index 0826d1d1..647139bc 100644 --- a/src/core/lombok/javac/handlers/HandlePrintAST.java +++ b/src/core/lombok/javac/handlers/HandlePrintAST.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2014 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -25,8 +25,6 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.PrintStream; -import org.mangosdk.spi.ProviderFor; - import com.sun.tools.javac.tree.JCTree.JCAnnotation; import lombok.Lombok; @@ -36,11 +34,12 @@ import lombok.core.PrintAST; import lombok.javac.JavacASTVisitor; import lombok.javac.JavacAnnotationHandler; import lombok.javac.JavacNode; +import lombok.spi.Provides; /** * Handles the {@code lombok.core.PrintAST} annotation for javac. */ -@ProviderFor(JavacAnnotationHandler.class) +@Provides @HandlerPriority(536870912) // 2^29; this handler is customarily run at the very end. public class HandlePrintAST extends JavacAnnotationHandler<PrintAST> { @Override public void handle(AnnotationValues<PrintAST> annotation, JCAnnotation ast, JavacNode annotationNode) { diff --git a/src/core/lombok/javac/handlers/HandleSetter.java b/src/core/lombok/javac/handlers/HandleSetter.java index 5c4c7681..5c34f9f5 100644 --- a/src/core/lombok/javac/handlers/HandleSetter.java +++ b/src/core/lombok/javac/handlers/HandleSetter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2020 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -37,8 +37,7 @@ import lombok.javac.Javac; import lombok.javac.JavacAnnotationHandler; import lombok.javac.JavacNode; import lombok.javac.JavacTreeMaker; - -import org.mangosdk.spi.ProviderFor; +import lombok.spi.Provides; import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.code.Symbol.ClassSymbol; @@ -60,8 +59,10 @@ import com.sun.tools.javac.util.Name; /** * Handles the {@code lombok.Setter} annotation for javac. */ -@ProviderFor(JavacAnnotationHandler.class) +@Provides public class HandleSetter extends JavacAnnotationHandler<Setter> { + private static final String SETTER_NODE_NOT_SUPPORTED_ERR = "@Setter is only supported on a class or a field."; + public void generateSetterForType(JavacNode typeNode, JavacNode errorNode, AccessLevel level, boolean checkForTypeLevelSetter, List<JCAnnotation> onMethod, List<JCAnnotation> onParam) { if (checkForTypeLevelSetter) { if (hasAnnotation(Setter.class, typeNode)) { @@ -70,13 +71,8 @@ public class HandleSetter extends JavacAnnotationHandler<Setter> { } } - JCClassDecl typeDecl = null; - if (typeNode.get() instanceof JCClassDecl) typeDecl = (JCClassDecl) typeNode.get(); - long modifiers = typeDecl == null ? 0 : typeDecl.mods.flags; - boolean notAClass = (modifiers & (Flags.INTERFACE | Flags.ANNOTATION | Flags.ENUM)) != 0; - - if (typeDecl == null || notAClass) { - errorNode.addError("@Setter is only supported on a class or a field."); + if (!isClass(typeNode)) { + errorNode.addError(SETTER_NODE_NOT_SUPPORTED_ERR); return; } @@ -150,7 +146,7 @@ public class HandleSetter extends JavacAnnotationHandler<Setter> { public void createSetterForField(AccessLevel level, JavacNode fieldNode, JavacNode sourceNode, boolean whineIfExists, List<JCAnnotation> onMethod, List<JCAnnotation> onParam) { if (fieldNode.getKind() != Kind.FIELD) { - fieldNode.addError("@Setter is only supported on a class or a field."); + fieldNode.addError(SETTER_NODE_NOT_SUPPORTED_ERR); return; } @@ -220,7 +216,7 @@ public class HandleSetter extends JavacAnnotationHandler<Setter> { List<JCAnnotation> annotations = d.mods.annotations; if (annotations == null) annotations = List.nil(); JCAnnotation anno = treeMaker.Annotation(genTypeRef(source, CheckerFrameworkVersion.NAME__RETURNS_RECEIVER), List.<JCExpression>nil()); - recursiveSetGeneratedBy(anno, source.get(), field.getContext()); + recursiveSetGeneratedBy(anno, source); d.mods.annotations = annotations.prepend(anno); } return d; @@ -239,7 +235,7 @@ public class HandleSetter extends JavacAnnotationHandler<Setter> { List<JCAnnotation> annotations = d.mods.annotations; if (annotations == null) annotations = List.nil(); JCAnnotation anno = treeMaker.Annotation(genTypeRef(source, CheckerFrameworkVersion.NAME__RETURNS_RECEIVER), List.<JCExpression>nil()); - recursiveSetGeneratedBy(anno, source.get(), field.getContext()); + recursiveSetGeneratedBy(anno, source); d.mods.annotations = annotations.prepend(anno); } return d; @@ -265,7 +261,7 @@ public class HandleSetter extends JavacAnnotationHandler<Setter> { List<JCAnnotation> annsOnParam = copyAnnotations(onParam).appendList(copyableAnnotations); long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, field.getContext()); - JCExpression pType = cloneType(treeMaker, fieldDecl.vartype, source.get(), source.getContext()); + JCExpression pType = cloneType(treeMaker, fieldDecl.vartype, source); JCVariableDecl param = treeMaker.VarDef(treeMaker.Modifiers(flags, annsOnParam), paramName, pType, null); if (!hasNonNullAnnotations(field) && !hasNonNullAnnotations(field, onParam)) { @@ -309,7 +305,7 @@ public class HandleSetter extends JavacAnnotationHandler<Setter> { methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue); } if (returnStatement != null) createRelevantNonNullAnnotation(source, methodDef); - JCMethodDecl decl = recursiveSetGeneratedBy(methodDef, source.get(), field.getContext()); + JCMethodDecl decl = recursiveSetGeneratedBy(methodDef, source); copyJavadoc(field, decl, CopyJavadoc.SETTER, returnStatement != null); return decl; } diff --git a/src/core/lombok/javac/handlers/HandleSneakyThrows.java b/src/core/lombok/javac/handlers/HandleSneakyThrows.java index ffe37a4c..3dde75d8 100644 --- a/src/core/lombok/javac/handlers/HandleSneakyThrows.java +++ b/src/core/lombok/javac/handlers/HandleSneakyThrows.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2014 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -35,11 +35,9 @@ import lombok.core.HandlerPriority; import lombok.javac.JavacAnnotationHandler; import lombok.javac.JavacNode; import lombok.javac.JavacTreeMaker; - -import org.mangosdk.spi.ProviderFor; +import lombok.spi.Provides; import com.sun.tools.javac.code.Flags; -import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCAnnotation; import com.sun.tools.javac.tree.JCTree.JCBlock; import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; @@ -48,14 +46,13 @@ import com.sun.tools.javac.tree.JCTree.JCMethodDecl; import com.sun.tools.javac.tree.JCTree.JCStatement; import com.sun.tools.javac.tree.JCTree.JCTry; import com.sun.tools.javac.tree.JCTree.JCVariableDecl; -import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.List; import lombok.javac.Javac; /** * Handles the {@code lombok.SneakyThrows} annotation for javac. */ -@ProviderFor(JavacAnnotationHandler.class) +@Provides @HandlerPriority(value = 1024) // 2^10; @NonNull must have run first, so that we wrap around the statements generated by it. public class HandleSneakyThrows extends JavacAnnotationHandler<SneakyThrows> { @Override public void handle(AnnotationValues<SneakyThrows> annotation, JCAnnotation ast, JavacNode annotationNode) { @@ -107,7 +104,7 @@ public class HandleSneakyThrows extends JavacAnnotationHandler<SneakyThrows> { } for (String exception : exceptions) { - contents = List.of(buildTryCatchBlock(methodNode, contents, exception, annotation.get())); + contents = List.of(buildTryCatchBlock(methodNode, contents, exception, annotation)); } method.body.stats = isConstructorCall ? List.of(constructorCall).appendList(contents) : contents; @@ -122,11 +119,10 @@ public class HandleSneakyThrows extends JavacAnnotationHandler<SneakyThrows> { } } - public JCStatement buildTryCatchBlock(JavacNode node, List<JCStatement> contents, String exception, JCTree source) { + public JCStatement buildTryCatchBlock(JavacNode node, List<JCStatement> contents, String exception, JavacNode source) { JavacTreeMaker maker = node.getTreeMaker(); - Context context = node.getContext(); - JCBlock tryBlock = setGeneratedBy(maker.Block(0, contents), source, context); + JCBlock tryBlock = setGeneratedBy(maker.Block(0, contents), source); JCExpression varType = chainDots(node, exception.split("\\.")); JCVariableDecl catchParam = maker.VarDef(maker.Modifiers(Flags.FINAL | Flags.PARAMETER), node.toName("$ex"), varType, null); @@ -134,7 +130,7 @@ public class HandleSneakyThrows extends JavacAnnotationHandler<SneakyThrows> { JCBlock catchBody = maker.Block(0, List.<JCStatement>of(maker.Throw(maker.Apply( List.<JCExpression>nil(), lombokLombokSneakyThrowNameRef, List.<JCExpression>of(maker.Ident(node.toName("$ex"))))))); - JCTry tryStatement = maker.Try(tryBlock, List.of(recursiveSetGeneratedBy(maker.Catch(catchParam, catchBody), source, context)), null); + JCTry tryStatement = maker.Try(tryBlock, List.of(recursiveSetGeneratedBy(maker.Catch(catchParam, catchBody), source)), null); if (JavacHandlerUtil.inNetbeansEditor(node)) { //set span (start and end position) of the try statement and the main block //this allows NetBeans to dive into the statement correctly: @@ -146,6 +142,6 @@ public class HandleSneakyThrows extends JavacAnnotationHandler<SneakyThrows> { Javac.storeEnd(tryBlock, endPos, top); Javac.storeEnd(tryStatement, endPos, top); } - return setGeneratedBy(tryStatement, source, context); + return setGeneratedBy(tryStatement, source); } } diff --git a/src/core/lombok/javac/handlers/HandleSuperBuilder.java b/src/core/lombok/javac/handlers/HandleSuperBuilder.java index b66df8cd..8974cd68 100644 --- a/src/core/lombok/javac/handlers/HandleSuperBuilder.java +++ b/src/core/lombok/javac/handlers/HandleSuperBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2020 The Project Lombok Authors. + * Copyright (C) 2013-2021 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 @@ -32,8 +32,6 @@ import java.util.HashSet; import javax.lang.model.element.Modifier; -import org.mangosdk.spi.ProviderFor; - import com.sun.tools.javac.code.BoundKind; import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.tree.JCTree; @@ -54,7 +52,6 @@ import com.sun.tools.javac.tree.JCTree.JCTypeApply; import com.sun.tools.javac.tree.JCTree.JCTypeParameter; import com.sun.tools.javac.tree.JCTree.JCVariableDecl; import com.sun.tools.javac.tree.JCTree.JCWildcard; -import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.ListBuffer; import com.sun.tools.javac.util.Name; @@ -85,8 +82,9 @@ import lombok.javac.handlers.JavacSingularsRecipes.ExpressionMaker; import lombok.javac.handlers.JavacSingularsRecipes.JavacSingularizer; import lombok.javac.handlers.JavacSingularsRecipes.SingularData; import lombok.javac.handlers.JavacSingularsRecipes.StatementMaker; +import lombok.spi.Provides; -@ProviderFor(JavacAnnotationHandler.class) +@Provides @HandlerPriority(-1024) //-2^10; to ensure we've picked up @FieldDefault's changes (-2048) but @Value hasn't removed itself yet (-512), so that we can error on presence of it on the builder classes. public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { private static final String SELF_METHOD = "self"; @@ -134,7 +132,6 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { handleExperimentalFlagUsage(annotationNode, ConfigurationKeys.SUPERBUILDER_FLAG_USAGE, "@SuperBuilder"); SuperBuilderJob job = new SuperBuilderJob(); job.sourceNode = annotationNode; - job.source = ast; job.checkerFramework = getCheckerFrameworkVersion(annotationNode); job.isStatic = true; @@ -162,15 +159,15 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { List<JCExpression> superclassTypeParams = List.nil(); boolean addCleaning = false; - if (!(parent.get() instanceof JCClassDecl)) { - annotationNode.addError("@SuperBuilder is only supported on types."); + if (!isClass(parent)) { + annotationNode.addError("@SuperBuilder is only supported on classes."); return; } - // Gather all fields of the class that should be set by the builder. job.parentType = parent; JCClassDecl td = (JCClassDecl) parent.get(); - ListBuffer<JavacNode> allFields = new ListBuffer<JavacNode>(); + + // Gather all fields of the class that should be set by the builder. ArrayList<JavacNode> nonFinalNonDefaultedFields = null; boolean valuePresent = (hasAnnotation(lombok.Value.class, parent) || hasAnnotation("lombok.experimental.Value", parent)); @@ -208,12 +205,11 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { bfd.nameOfSetFlag = parent.toName(bfd.name + SET_PREFIX); bfd.builderFieldName = parent.toName(bfd.name + VALUE_PREFIX); JCMethodDecl md = HandleBuilder.generateDefaultProvider(bfd.nameOfDefaultProvider, fieldNode, td.typarams); - recursiveSetGeneratedBy(md, ast, annotationNode.getContext()); + recursiveSetGeneratedBy(md, annotationNode); if (md != null) injectMethod(parent, md); } addObtainVia(bfd, fieldNode); job.builderFields.add(bfd); - allFields.append(fieldNode); } job.typeParams = job.builderTypeParams = td.typarams; @@ -235,9 +231,9 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { { JCExpression annotatedClass = namePlusTypeParamsToTypeReference(maker, parent, job.typeParams); JCTypeParameter c = maker.TypeParameter(parent.toName(classGenericName), List.<JCExpression>of(annotatedClass)); - ListBuffer<JCExpression> typeParamsForBuilder = getTypeParamExpressions(job.typeParams, maker, job.sourceNode.getContext()); - typeParamsForBuilder.add(maker.Ident(parent.toName(classGenericName))); - typeParamsForBuilder.add(maker.Ident(parent.toName(builderGenericName))); + ListBuffer<JCExpression> typeParamsForBuilder = getTypeParamExpressions(job.typeParams, maker, job.sourceNode); + typeParamsForBuilder.append(maker.Ident(parent.toName(classGenericName))); + typeParamsForBuilder.append(maker.Ident(parent.toName(builderGenericName))); JCTypeApply typeApply = maker.TypeApply(namePlusTypeParamsToTypeReference(maker, parent, job.getBuilderClassName(), false, List.<JCTypeParameter>nil()), typeParamsForBuilder.toList()); JCTypeParameter d = maker.TypeParameter(parent.toName(builderGenericName), List.<JCExpression>of(typeApply)); if (job.typeParams == null || job.typeParams.isEmpty()) { @@ -293,7 +289,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { job.builderAbstractType = findInnerClass(parent, job.builderClassName); if (job.builderAbstractType == null) { job.builderAbstractType = generateBuilderAbstractClass(job, superclassBuilderClass, superclassTypeParams, classGenericName, builderGenericName); - recursiveSetGeneratedBy(job.builderAbstractType.get(), ast, annotationNode.getContext()); + recursiveSetGeneratedBy(job.builderAbstractType.get(), annotationNode); } else { JCClassDecl builderTypeDeclaration = (JCClassDecl) job.builderAbstractType.get(); if (!builderTypeDeclaration.getModifiers().getFlags().contains(Modifier.STATIC) @@ -309,7 +305,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { if (sd == null) continue; JavacSingularizer singularizer = sd.getSingularizer(); if (singularizer == null) continue; - if (singularizer.checkForAlreadyExistingNodesAndGenerateError(job.builderType, sd)) { + if (singularizer.checkForAlreadyExistingNodesAndGenerateError(job.builderAbstractType, sd)) { bfd.singularData = null; } } @@ -317,30 +313,30 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { // Generate the fields in the abstract builder class that hold the values for the instance. job.setBuilderToAbstract(); - generateBuilderFields(job.builderType, job.builderFields, ast); + generateBuilderFields(job.builderType, job.builderFields, annotationNode); if (addCleaning) { JCVariableDecl uncleanField = maker.VarDef(maker.Modifiers(Flags.PRIVATE), job.toName("$lombokUnclean"), maker.TypeIdent(CTC_BOOLEAN), null); - recursiveSetGeneratedBy(uncleanField, ast, annotationNode.getContext()); + recursiveSetGeneratedBy(uncleanField, annotationNode); injectFieldAndMarkGenerated(job.builderType, uncleanField); } if (job.toBuilder) { // Generate $fillValuesFrom() method in the abstract builder. JCMethodDecl fvm = generateFillValuesMethod(job, superclassBuilderClass != null, builderGenericName, classGenericName); - recursiveSetGeneratedBy(fvm, ast, annotationNode.getContext()); + recursiveSetGeneratedBy(fvm, annotationNode); injectMethod(job.builderType, fvm); // Generate $fillValuesFromInstanceIntoBuilder() method in the builder implementation class. JCMethodDecl sfvm = generateStaticFillValuesMethod(job, annInstance.setterPrefix()); - recursiveSetGeneratedBy(sfvm, ast, annotationNode.getContext()); + recursiveSetGeneratedBy(sfvm, annotationNode); injectMethod(job.builderType, sfvm); } // Generate abstract self() and build() methods in the abstract builder. JCMethodDecl asm = generateAbstractSelfMethod(job, superclassBuilderClass != null, builderGenericName); - recursiveSetGeneratedBy(asm, ast, annotationNode.getContext()); + recursiveSetGeneratedBy(asm, annotationNode); injectMethod(job.builderType, asm); JCMethodDecl abm = generateAbstractBuildMethod(job, superclassBuilderClass != null, classGenericName); - recursiveSetGeneratedBy(abm, ast, annotationNode.getContext()); + recursiveSetGeneratedBy(abm, annotationNode); injectMethod(job.builderType, abm); // Create the setter methods in the abstract builder. @@ -357,13 +353,13 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { } // Let toString() call super.toString() if there is a superclass, so that it also shows fields from the superclass' builder. - JCMethodDecl toStringMethod = HandleToString.createToString(job.builderType, fieldNodes, true, superclassBuilderClass != null, FieldAccess.ALWAYS_FIELD, ast); + JCMethodDecl toStringMethod = HandleToString.createToString(job.builderType, fieldNodes, true, superclassBuilderClass != null, FieldAccess.ALWAYS_FIELD, annotationNode); if (toStringMethod != null) injectMethod(job.builderType, toStringMethod); // If clean methods are requested, add them now. if (addCleaning) { - JCMethodDecl md = generateCleanMethod(job.builderFields, job.builderType, ast); - recursiveSetGeneratedBy(md, ast, annotationNode.getContext()); + JCMethodDecl md = generateCleanMethod(job.builderFields, job.builderType, annotationNode); + recursiveSetGeneratedBy(md, annotationNode); injectMethod(job.builderType, md); } @@ -375,7 +371,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { job.builderImplType = findInnerClass(parent, job.builderImplClassName); if (job.builderImplType == null) { job.builderImplType = generateBuilderImplClass(job); - recursiveSetGeneratedBy(job.builderImplType.get(), ast, annotationNode.getContext()); + recursiveSetGeneratedBy(job.builderImplType.get(), annotationNode); } else { JCClassDecl builderImplTypeDeclaration = (JCClassDecl) job.builderImplType.get(); if (!builderImplTypeDeclaration.getModifiers().getFlags().contains(Modifier.STATIC) @@ -393,11 +389,11 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { // Create the self() and build() methods in the BuilderImpl. JCMethodDecl selfMethod = generateSelfMethod(job); - recursiveSetGeneratedBy(selfMethod, ast, annotationNode.getContext()); + recursiveSetGeneratedBy(selfMethod, annotationNode); injectMethod(job.builderType, selfMethod); if (methodExists(job.buildMethodName, job.builderType, -1) == MemberExistsResult.NOT_EXISTS) { JCMethodDecl buildMethod = generateBuildMethod(job, buildMethodThrownExceptions); - recursiveSetGeneratedBy(buildMethod, ast, annotationNode.getContext()); + recursiveSetGeneratedBy(buildMethod, annotationNode); injectMethod(job.builderType, buildMethod); } } @@ -417,7 +413,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { if (generateBuilderMethod) { JCMethodDecl builderMethod = generateBuilderMethod(job); if (builderMethod != null) { - recursiveSetGeneratedBy(builderMethod, ast, annotationNode.getContext()); + recursiveSetGeneratedBy(builderMethod, annotationNode); injectMethod(job.parentType, builderMethod); } } @@ -430,7 +426,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { case NOT_EXISTS: JCMethodDecl md = generateToBuilderMethod(job); if (md != null) { - recursiveSetGeneratedBy(md, ast, annotationNode.getContext()); + recursiveSetGeneratedBy(md, annotationNode); injectMethod(job.parentType, md); } break; @@ -456,32 +452,33 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { // Keep any type params of the annotated class. ListBuffer<JCTypeParameter> allTypeParams = new ListBuffer<JCTypeParameter>(); - allTypeParams.addAll(copyTypeParams(job.sourceNode, job.typeParams)); + allTypeParams.appendList(copyTypeParams(job.sourceNode, job.typeParams)); // Add builder-specific type params required for inheritable builders. // 1. The return type for the build() method, named "C", which extends the annotated class. JCExpression annotatedClass = namePlusTypeParamsToTypeReference(maker, job.parentType, job.typeParams); - allTypeParams.add(maker.TypeParameter(job.toName(classGenericName), List.<JCExpression>of(annotatedClass))); + allTypeParams.append(maker.TypeParameter(job.toName(classGenericName), List.<JCExpression>of(annotatedClass))); // 2. The return type for all setter methods, named "B", which extends this builder class. Name builderClassName = job.toName(job.builderClassName); - ListBuffer<JCExpression> typeParamsForBuilder = getTypeParamExpressions(job.typeParams, maker, job.sourceNode.getContext()); - typeParamsForBuilder.add(maker.Ident(job.toName(classGenericName))); - typeParamsForBuilder.add(maker.Ident(job.toName(builderGenericName))); + ListBuffer<JCExpression> typeParamsForBuilder = getTypeParamExpressions(job.typeParams, maker, job.sourceNode); + typeParamsForBuilder.append(maker.Ident(job.toName(classGenericName))); + typeParamsForBuilder.append(maker.Ident(job.toName(builderGenericName))); JCTypeApply typeApply = maker.TypeApply(namePlusTypeParamsToTypeReference(maker, job.parentType, builderClassName, false, List.<JCTypeParameter>nil()), typeParamsForBuilder.toList()); - allTypeParams.add(maker.TypeParameter(job.toName(builderGenericName), List.<JCExpression>of(typeApply))); + allTypeParams.append(maker.TypeParameter(job.toName(builderGenericName), List.<JCExpression>of(typeApply))); JCExpression extending = null; if (superclassBuilderClass != null) { // If the annotated class extends another class, we want this builder to extend the builder of the superclass. // 1. Add the type parameters of the superclass. - typeParamsForBuilder = getTypeParamExpressions(superclassTypeParams, maker, job.sourceNode.getContext()); + typeParamsForBuilder = getTypeParamExpressions(superclassTypeParams, maker, job.sourceNode); // 2. Add the builder type params <C, B>. - typeParamsForBuilder.add(maker.Ident(job.toName(classGenericName))); - typeParamsForBuilder.add(maker.Ident(job.toName(builderGenericName))); + typeParamsForBuilder.append(maker.Ident(job.toName(classGenericName))); + typeParamsForBuilder.append(maker.Ident(job.toName(builderGenericName))); extending = maker.TypeApply(superclassBuilderClass, typeParamsForBuilder.toList()); } JCClassDecl builder = maker.ClassDef(mods, builderClassName, allTypeParams.toList(), extending, List.<JCExpression>nil(), List.<JCTree>nil()); + recursiveSetGeneratedBy(builder, job.sourceNode); return injectType(job.parentType, builder); } @@ -494,21 +491,20 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { // Extend the abstract builder. JCExpression extending = namePlusTypeParamsToTypeReference(maker, job.parentType, job.toName(job.builderAbstractClassName), false, List.<JCTypeParameter>nil()); - // Add any type params of the annotated class. - ListBuffer<JCTypeParameter> allTypeParams = new ListBuffer<JCTypeParameter>(); - allTypeParams.addAll(copyTypeParams(job.sourceNode, job.typeParams)); + // Add builder-specific type params required for inheritable builders. // 1. The return type for the build() method (named "C" in the abstract builder), which is the annotated class. JCExpression annotatedClass = namePlusTypeParamsToTypeReference(maker, job.parentType, job.typeParams); // 2. The return type for all setter methods (named "B" in the abstract builder), which is this builder class. JCExpression builderImplClassExpression = namePlusTypeParamsToTypeReference(maker, job.parentType, job.toName(job.builderImplClassName), false, job.typeParams); - ListBuffer<JCExpression> typeParamsForBuilder = getTypeParamExpressions(job.typeParams, maker, job.getContext()); - typeParamsForBuilder.add(annotatedClass); - typeParamsForBuilder.add(builderImplClassExpression); + ListBuffer<JCExpression> typeParamsForBuilder = getTypeParamExpressions(job.typeParams, maker, job.sourceNode); + typeParamsForBuilder.append(annotatedClass); + typeParamsForBuilder.append(builderImplClassExpression); extending = maker.TypeApply(extending, typeParamsForBuilder.toList()); JCClassDecl builder = maker.ClassDef(mods, job.toName(job.builderImplClassName), copyTypeParams(job.parentType, job.typeParams), extending, List.<JCExpression>nil(), List.<JCTree>nil()); + recursiveSetGeneratedBy(builder, job.sourceNode); return injectType(job.parentType, builder); } @@ -532,7 +528,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { for (BuilderFieldData bfd : job.builderFields) { JCExpression rhs; if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) { - bfd.singularData.getSingularizer().appendBuildCode(bfd.singularData, bfd.originalFieldNode, bfd.type, statements, bfd.builderFieldName, "b"); + bfd.singularData.getSingularizer().appendBuildCode(bfd.singularData, bfd.originalFieldNode, job.sourceNode, statements, bfd.builderFieldName, "b"); rhs = maker.Ident(bfd.singularData.getPluralName()); } else { rhs = maker.Select(maker.Ident(builderVariableName), bfd.builderFieldName); @@ -558,19 +554,19 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { } } - List<JCAnnotation> annsOnMethod = job.checkerFramework.generateUnique() ? List.of(maker.Annotation(genTypeRef(job.parentType, CheckerFrameworkVersion.NAME__SIDE_EFFECT_FREE), List.<JCExpression>nil())) : List.<JCAnnotation>nil(); + List<JCAnnotation> annsOnMethod = job.checkerFramework.generateSideEffectFree() ? List.of(maker.Annotation(genTypeRef(job.parentType, CheckerFrameworkVersion.NAME__SIDE_EFFECT_FREE), List.<JCExpression>nil())) : List.<JCAnnotation>nil(); JCModifiers mods = maker.Modifiers(toJavacModifier(level), annsOnMethod); // Create a constructor that has just the builder as parameter. ListBuffer<JCVariableDecl> params = new ListBuffer<JCVariableDecl>(); long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, job.getContext()); // First add all generics that are present on the parent type. - ListBuffer<JCExpression> typeParamsForBuilderParameter = getTypeParamExpressions(job.typeParams, maker, job.getContext()); + ListBuffer<JCExpression> typeParamsForBuilderParameter = getTypeParamExpressions(job.typeParams, maker, job.sourceNode); // Now add the <?, ?>. JCWildcard wildcard = maker.Wildcard(maker.TypeBoundKind(BoundKind.UNBOUND), null); - typeParamsForBuilderParameter.add(wildcard); + typeParamsForBuilderParameter.append(wildcard); wildcard = maker.Wildcard(maker.TypeBoundKind(BoundKind.UNBOUND), null); - typeParamsForBuilderParameter.add(wildcard); + typeParamsForBuilderParameter.append(wildcard); JCTypeApply paramType = maker.TypeApply(namePlusTypeParamsToTypeReference(maker, job.parentType, job.getBuilderClassName(), false, List.<JCTypeParameter>nil()), typeParamsForBuilderParameter.toList()); JCVariableDecl param = maker.VarDef(maker.Modifiers(flags), builderVariableName, paramType, null); params.append(param); @@ -585,7 +581,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { JCMethodDecl constr = recursiveSetGeneratedBy(maker.MethodDef(mods, job.toName("<init>"), null, List.<JCTypeParameter>nil(), params.toList(), List.<JCExpression>nil(), - maker.Block(0L, statements.toList()), null), job.source, job.getContext()); + maker.Block(0L, statements.toList()), null), job.sourceNode); injectMethod(job.parentType, constr, null, Javac.createVoidType(job.builderType.getSymbolTable(), CTC_VOID)); } @@ -593,9 +589,6 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { private JCMethodDecl generateBuilderMethod(SuperBuilderJob job) { JavacTreeMaker maker = job.getTreeMaker(); - ListBuffer<JCExpression> typeArgs = new ListBuffer<JCExpression>(); - for (JCTypeParameter typeParam : job.typeParams) typeArgs.append(maker.Ident(typeParam.name)); - JCExpression call = maker.NewClass(null, List.<JCExpression>nil(), namePlusTypeParamsToTypeReference(maker, job.parentType, job.toName(job.builderImplClassName), false, job.typeParams), List.<JCExpression>nil(), null); JCStatement statement = maker.Return(call); @@ -605,14 +598,17 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { // Add any type params of the annotated class to the return type. ListBuffer<JCExpression> typeParameterNames = new ListBuffer<JCExpression>(); - typeParameterNames.addAll(typeParameterNames(maker, job.typeParams)); + typeParameterNames.appendList(typeParameterNames(maker, job.typeParams)); // Now add the <?, ?>. JCWildcard wildcard = maker.Wildcard(maker.TypeBoundKind(BoundKind.UNBOUND), null); - typeParameterNames.add(wildcard); - typeParameterNames.add(wildcard); - JCTypeApply returnType = maker.TypeApply(namePlusTypeParamsToTypeReference(maker, job.parentType, job.toName(job.builderAbstractClassName), false, List.<JCTypeParameter>nil()), typeParameterNames.toList()); - - List<JCAnnotation> annsOnMethod = job.checkerFramework.generateUnique() ? List.of(maker.Annotation(genTypeRef(job.parentType, CheckerFrameworkVersion.NAME__SIDE_EFFECT_FREE), List.<JCExpression>nil())) : List.<JCAnnotation>nil(); + typeParameterNames.append(wildcard); + typeParameterNames.append(wildcard); + // And return type annotations. + List<JCAnnotation> annsOnParamType = List.nil(); + if (job.checkerFramework.generateUnique()) annsOnParamType = List.of(maker.Annotation(genTypeRef(job.parentType, CheckerFrameworkVersion.NAME__UNIQUE), List.<JCExpression>nil())); + JCTypeApply returnType = maker.TypeApply(namePlusTypeParamsToTypeReference(maker, job.parentType, job.toName(job.builderAbstractClassName), false, List.<JCTypeParameter>nil(), annsOnParamType), typeParameterNames.toList()); + + List<JCAnnotation> annsOnMethod = job.checkerFramework.generateSideEffectFree() ? List.of(maker.Annotation(genTypeRef(job.parentType, CheckerFrameworkVersion.NAME__SIDE_EFFECT_FREE), List.<JCExpression>nil())) : List.<JCAnnotation>nil(); JCMethodDecl methodDef = maker.MethodDef(maker.Modifiers(modifiers, annsOnMethod), job.toName(job.builderMethodName), returnType, copyTypeParams(job.sourceNode, job.typeParams), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null); createRelevantNonNullAnnotation(job.parentType, methodDef); return methodDef; @@ -629,9 +625,6 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { private JCMethodDecl generateToBuilderMethod(SuperBuilderJob job) { JavacTreeMaker maker = job.getTreeMaker(); - ListBuffer<JCExpression> typeArgs = new ListBuffer<JCExpression>(); - for (JCTypeParameter typeParam : job.typeParams) typeArgs.append(maker.Ident(typeParam.name)); - JCExpression newClass = maker.NewClass(null, List.<JCExpression>nil(), namePlusTypeParamsToTypeReference(maker, job.parentType, job.toName(job.builderImplClassName), false, job.typeParams), List.<JCExpression>nil(), null); List<JCExpression> methodArgs = List.<JCExpression>of(maker.Ident(job.toName("this"))); JCMethodInvocation invokeFillMethod = maker.Apply(List.<JCExpression>nil(), maker.Select(newClass, job.toName(FILL_VALUES_METHOD_NAME)), methodArgs); @@ -642,14 +635,14 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { // Add any type params of the annotated class to the return type. ListBuffer<JCExpression> typeParameterNames = new ListBuffer<JCExpression>(); - typeParameterNames.addAll(typeParameterNames(maker, job.typeParams)); + typeParameterNames.appendList(typeParameterNames(maker, job.typeParams)); // Now add the <?, ?>. JCWildcard wildcard = maker.Wildcard(maker.TypeBoundKind(BoundKind.UNBOUND), null); - typeParameterNames.add(wildcard); - typeParameterNames.add(wildcard); + typeParameterNames.append(wildcard); + typeParameterNames.append(wildcard); JCTypeApply returnType = maker.TypeApply(namePlusTypeParamsToTypeReference(maker, job.parentType, job.toName(job.builderAbstractClassName), false, List.<JCTypeParameter>nil()), typeParameterNames.toList()); - List<JCAnnotation> annsOnMethod = job.checkerFramework.generateUnique() ? List.of(maker.Annotation(genTypeRef(job.parentType, CheckerFrameworkVersion.NAME__SIDE_EFFECT_FREE), List.<JCExpression>nil())) : List.<JCAnnotation>nil(); + List<JCAnnotation> annsOnMethod = job.checkerFramework.generateSideEffectFree() ? List.of(maker.Annotation(genTypeRef(job.parentType, CheckerFrameworkVersion.NAME__SIDE_EFFECT_FREE), List.<JCExpression>nil())) : List.<JCAnnotation>nil(); JCMethodDecl methodDef = maker.MethodDef(maker.Modifiers(modifiers, annsOnMethod), job.toName(TO_BUILDER_METHOD_NAME), returnType, List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null); createRelevantNonNullAnnotation(job.parentType, methodDef); return methodDef; @@ -727,12 +720,12 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { // 2nd parameter: "FoobarBuilder<?, ?> b" (plus generics on the annotated type) // First add all generics that are present on the parent type. - ListBuffer<JCExpression> typeParamsForBuilderParameter = getTypeParamExpressions(job.typeParams, maker, job.getContext()); + ListBuffer<JCExpression> typeParamsForBuilderParameter = getTypeParamExpressions(job.typeParams, maker, job.sourceNode); // Now add the <?, ?>. JCWildcard wildcard = maker.Wildcard(maker.TypeBoundKind(BoundKind.UNBOUND), null); - typeParamsForBuilderParameter.add(wildcard); + typeParamsForBuilderParameter.append(wildcard); wildcard = maker.Wildcard(maker.TypeBoundKind(BoundKind.UNBOUND), null); - typeParamsForBuilderParameter.add(wildcard); + typeParamsForBuilderParameter.append(wildcard); JCTypeApply builderType = maker.TypeApply(namePlusTypeParamsToTypeReference(maker, job.parentType, job.getBuilderClassName(), false, List.<JCTypeParameter>nil()), typeParamsForBuilderParameter.toList()); JCVariableDecl paramBuilder = maker.VarDef(maker.Modifiers(Flags.PARAMETER | Flags.FINAL), job.toName(BUILDER_VARIABLE_NAME), builderType, null); @@ -740,7 +733,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { // Call the builder's setter methods to fill the values from the instance. for (BuilderFieldData bfd : job.builderFields) { - JCExpressionStatement exec = createSetterCallWithInstanceValue(bfd, job.parentType, maker, setterPrefix); + JCExpressionStatement exec = createSetterCallWithInstanceValue(bfd, job, setterPrefix); body.append(exec); } @@ -749,22 +742,23 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { return maker.MethodDef(modifiers, name, returnType, copyTypeParams(job.builderType, job.typeParams), List.of(paramInstance, paramBuilder), List.<JCExpression>nil(), bodyBlock, null); } - private JCExpressionStatement createSetterCallWithInstanceValue(BuilderFieldData bfd, JavacNode type, JavacTreeMaker maker, String setterPrefix) { + private JCExpressionStatement createSetterCallWithInstanceValue(BuilderFieldData bfd, SuperBuilderJob job, String setterPrefix) { + JavacTreeMaker maker = job.getTreeMaker(); JCExpression[] tgt = new JCExpression[bfd.singularData == null ? 1 : 2]; if (bfd.obtainVia == null || !bfd.obtainVia.field().isEmpty()) { for (int i = 0; i < tgt.length; i++) { - tgt[i] = maker.Select(maker.Ident(type.toName(INSTANCE_VARIABLE_NAME)), bfd.obtainVia == null ? bfd.rawName : type.toName(bfd.obtainVia.field())); + tgt[i] = maker.Select(maker.Ident(job.toName(INSTANCE_VARIABLE_NAME)), bfd.obtainVia == null ? bfd.rawName : job.toName(bfd.obtainVia.field())); } } else { if (bfd.obtainVia.isStatic()) { for (int i = 0; i < tgt.length; i++) { - JCExpression typeRef = namePlusTypeParamsToTypeReference(maker, type, List.<JCTypeParameter>nil()); - JCExpression c = maker.Select(typeRef, type.toName(bfd.obtainVia.method())); - tgt[i] = maker.Apply(List.<JCExpression>nil(), c, List.<JCExpression>of(maker.Ident(type.toName(INSTANCE_VARIABLE_NAME)))); + JCExpression typeRef = namePlusTypeParamsToTypeReference(maker, job.parentType, List.<JCTypeParameter>nil()); + JCExpression c = maker.Select(typeRef, job.toName(bfd.obtainVia.method())); + tgt[i] = maker.Apply(List.<JCExpression>nil(), c, List.<JCExpression>of(maker.Ident(job.toName(INSTANCE_VARIABLE_NAME)))); } } else { for (int i = 0; i < tgt.length; i++) { - JCExpression c = maker.Select(maker.Ident(type.toName(INSTANCE_VARIABLE_NAME)), type.toName(bfd.obtainVia.method())); + JCExpression c = maker.Select(maker.Ident(job.toName(INSTANCE_VARIABLE_NAME)), job.toName(bfd.obtainVia.method())); tgt[i] = maker.Apply(List.<JCExpression>nil(), c, List.<JCExpression>nil()); } } @@ -775,13 +769,12 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { arg = tgt[0]; } else { JCExpression eqNull = maker.Binary(CTC_EQUAL, tgt[0], maker.Literal(CTC_BOT, null)); - String emptyMaker = bfd.singularData.getSingularizer().getEmptyMaker(bfd.singularData.getTargetFqn()); - JCExpression emptyCollection = maker.Apply(List.<JCExpression>nil(), chainDots(type, emptyMaker.split("\\.")), List.<JCExpression>nil()); + JCExpression emptyCollection = bfd.singularData.getSingularizer().getEmptyExpression(bfd.singularData.getTargetFqn(), maker, bfd.singularData, job.parentType, job.sourceNode); arg = maker.Conditional(eqNull, emptyCollection, tgt[1]); } String setterName = HandlerUtil.buildAccessorName(setterPrefix, bfd.name.toString()); - JCMethodInvocation apply = maker.Apply(List.<JCExpression>nil(), maker.Select(maker.Ident(type.toName(BUILDER_VARIABLE_NAME)), type.toName(setterName)), List.of(arg)); + JCMethodInvocation apply = maker.Apply(List.<JCExpression>nil(), maker.Select(maker.Ident(job.toName(BUILDER_VARIABLE_NAME)), job.toName(setterName)), List.of(arg)); JCExpressionStatement exec = maker.Exec(apply); return exec; } @@ -874,7 +867,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { return methodDef; } - private JCMethodDecl generateCleanMethod(java.util.List<BuilderFieldData> builderFields, JavacNode type, JCTree source) { + private JCMethodDecl generateCleanMethod(java.util.List<BuilderFieldData> builderFields, JavacNode type, JavacNode source) { JavacTreeMaker maker = type.getTreeMaker(); ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>(); @@ -889,7 +882,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { return maker.MethodDef(maker.Modifiers(Flags.PUBLIC), type.toName("$lombokClean"), maker.Type(Javac.createVoidType(type.getSymbolTable(), CTC_VOID)), List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null); } - private void generateBuilderFields(JavacNode builderType, java.util.List<BuilderFieldData> builderFields, JCTree source) { + private void generateBuilderFields(JavacNode builderType, java.util.List<BuilderFieldData> builderFields, JavacNode source) { int len = builderFields.size(); java.util.List<JavacNode> existing = new ArrayList<JavacNode>(); for (JavacNode child : builderType.down()) { @@ -901,7 +894,11 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { for (int i = len - 1; i >= 0; i--) { BuilderFieldData bfd = builderFields.get(i); if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) { - bfd.createdFields.addAll(bfd.singularData.getSingularizer().generateFields(bfd.singularData, builderType, source)); + java.util.List<JavacNode> fields = bfd.singularData.getSingularizer().generateFields(bfd.singularData, builderType, source); + for (JavacNode field : fields) { + generated.add((JCVariableDecl) field.get()); + } + bfd.createdFields.addAll(fields); } else { JavacNode field = null, setFlag = null; for (JavacNode exists : existing) { @@ -912,7 +909,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { JavacTreeMaker maker = builderType.getTreeMaker(); if (field == null) { JCModifiers mods = maker.Modifiers(Flags.PRIVATE); - JCVariableDecl newField = maker.VarDef(mods, bfd.builderFieldName, cloneType(maker, bfd.type, source, builderType.getContext()), null); + JCVariableDecl newField = maker.VarDef(mods, bfd.builderFieldName, cloneType(maker, bfd.type, source), null); field = injectFieldAndMarkGenerated(builderType, newField); generated.add(newField); } @@ -925,7 +922,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { bfd.createdFields.add(field); } } - for (JCVariableDecl gen : generated) recursiveSetGeneratedBy(gen, source, builderType.getContext()); + for (JCVariableDecl gen : generated) recursiveSetGeneratedBy(gen, source); } private void generateSetterMethodsForBuilder(final SuperBuilderJob job, BuilderFieldData fieldNode, final String builderGenericName, String setterPrefix) { @@ -943,7 +940,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { generateSimpleSetterMethodForBuilder(job, deprecate, fieldNode.createdFields.get(0), fieldNode.name, fieldNode.nameOfSetFlag, returnTypeMaker.make(), returnStatementMaker.make(), fieldNode.annotations, fieldNode.originalFieldNode, setterPrefix); } else { fieldNode.singularData.getSingularizer().generateMethods(job.checkerFramework, fieldNode.singularData, deprecate, job.builderType, - job.source, true, returnTypeMaker, returnStatementMaker, AccessLevel.PUBLIC); + job.sourceNode, true, returnTypeMaker, returnStatementMaker, AccessLevel.PUBLIC); } } @@ -974,7 +971,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { List<JCAnnotation> annotations = newMethod.mods.annotations; if (annotations == null) annotations = List.nil(); JCAnnotation anno = maker.Annotation(genTypeRef(job.builderType, CheckerFrameworkVersion.NAME__RETURNS_RECEIVER), List.<JCExpression>nil()); - recursiveSetGeneratedBy(anno, job.source, job.getContext()); + recursiveSetGeneratedBy(anno, job.sourceNode); newMethod.mods.annotations = annotations.prepend(anno); } @@ -1084,17 +1081,17 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> { return null; } - private ListBuffer<JCExpression> getTypeParamExpressions(List<? extends JCTree> typeParams, JavacTreeMaker maker, Context context) { + private ListBuffer<JCExpression> getTypeParamExpressions(List<? extends JCTree> typeParams, JavacTreeMaker maker, JavacNode source) { ListBuffer<JCExpression> typeParamsForBuilderParameter = new ListBuffer<JCExpression>(); for (JCTree typeParam : typeParams) { if (typeParam instanceof JCTypeParameter) { - typeParamsForBuilderParameter.add(maker.Ident(((JCTypeParameter)typeParam).getName())); + typeParamsForBuilderParameter.append(maker.Ident(((JCTypeParameter)typeParam).getName())); } else if (typeParam instanceof JCIdent) { - typeParamsForBuilderParameter.add(maker.Ident(((JCIdent)typeParam).getName())); + typeParamsForBuilderParameter.append(maker.Ident(((JCIdent)typeParam).getName())); } else if (typeParam instanceof JCFieldAccess) { - typeParamsForBuilderParameter.add(copySelect(maker, (JCFieldAccess) typeParam)); + typeParamsForBuilderParameter.append(copySelect(maker, (JCFieldAccess) typeParam)); } else if (typeParam instanceof JCTypeApply) { - typeParamsForBuilderParameter.add(cloneType(maker, (JCTypeApply)typeParam, typeParam, context)); + typeParamsForBuilderParameter.append(cloneType(maker, (JCTypeApply)typeParam, source)); } } return typeParamsForBuilderParameter; diff --git a/src/core/lombok/javac/handlers/HandleSuperBuilderRemove.java b/src/core/lombok/javac/handlers/HandleSuperBuilderRemove.java index cca69729..d3db5ef4 100644 --- a/src/core/lombok/javac/handlers/HandleSuperBuilderRemove.java +++ b/src/core/lombok/javac/handlers/HandleSuperBuilderRemove.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 The Project Lombok Authors. + * Copyright (C) 2020-2021 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 @@ -23,8 +23,6 @@ package lombok.javac.handlers; import static lombok.javac.handlers.JavacHandlerUtil.*; -import org.mangosdk.spi.ProviderFor; - import com.sun.tools.javac.tree.JCTree.JCAnnotation; import lombok.core.AlreadyHandledAnnotations; @@ -33,9 +31,10 @@ import lombok.core.HandlerPriority; import lombok.experimental.SuperBuilder; import lombok.javac.JavacAnnotationHandler; import lombok.javac.JavacNode; +import lombok.spi.Provides; -@ProviderFor(JavacAnnotationHandler.class) -@HandlerPriority(65536) +@Provides +@HandlerPriority(32768) @AlreadyHandledAnnotations public class HandleSuperBuilderRemove extends JavacAnnotationHandler<SuperBuilder> { @Override public void handle(AnnotationValues<SuperBuilder> annotation, JCAnnotation ast, JavacNode annotationNode) { diff --git a/src/core/lombok/javac/handlers/HandleSynchronized.java b/src/core/lombok/javac/handlers/HandleSynchronized.java index b6f1e47f..0bf7cbe8 100644 --- a/src/core/lombok/javac/handlers/HandleSynchronized.java +++ b/src/core/lombok/javac/handlers/HandleSynchronized.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2020 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -33,8 +33,7 @@ import lombok.javac.JavacAnnotationHandler; import lombok.javac.JavacNode; import lombok.javac.JavacTreeMaker; import lombok.javac.handlers.JavacHandlerUtil.MemberExistsResult; - -import org.mangosdk.spi.ProviderFor; +import lombok.spi.Provides; import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.tree.JCTree; @@ -46,13 +45,12 @@ import com.sun.tools.javac.tree.JCTree.JCNewArray; import com.sun.tools.javac.tree.JCTree.JCStatement; import com.sun.tools.javac.tree.JCTree.JCTypeParameter; import com.sun.tools.javac.tree.JCTree.JCVariableDecl; -import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.List; /** * Handles the {@code lombok.Synchronized} annotation for javac. */ -@ProviderFor(JavacAnnotationHandler.class) +@Provides @HandlerPriority(value = 1024) // 2^10; @NonNull must have run first, so that we wrap around the statements generated by it. public class HandleSynchronized extends JavacAnnotationHandler<Synchronized> { private static final String INSTANCE_LOCK_NAME = "$lock"; @@ -78,6 +76,12 @@ public class HandleSynchronized extends JavacAnnotationHandler<Synchronized> { return; } + JavacNode typeNode = upToTypeNode(annotationNode); + if (!isClassOrEnum(typeNode)) { + annotationNode.addError("@Synchronized is legal only on methods in classes and enums."); + return; + } + boolean[] isStatic = new boolean[] {(method.mods.flags & Flags.STATIC) != 0}; String lockName = annotation.getInstance().value(); boolean autoMake = false; @@ -87,9 +91,6 @@ public class HandleSynchronized extends JavacAnnotationHandler<Synchronized> { } JavacTreeMaker maker = methodNode.getTreeMaker().at(ast.pos); - Context context = methodNode.getContext(); - - JavacNode typeNode = upToTypeNode(annotationNode); MemberExistsResult exists = MemberExistsResult.NOT_EXISTS; @@ -120,7 +121,7 @@ public class HandleSynchronized extends JavacAnnotationHandler<Synchronized> { List.<JCExpression>of(maker.Literal(CTC_INT, 0)), null); JCVariableDecl fieldDecl = recursiveSetGeneratedBy(maker.VarDef( maker.Modifiers(Flags.PRIVATE | Flags.FINAL | (isStatic[0] ? Flags.STATIC : 0)), - methodNode.toName(lockName), objectType, newObjectArray), ast, context); + methodNode.toName(lockName), objectType, newObjectArray), annotationNode); injectFieldAndMarkGenerated(methodNode.up(), fieldDecl); } @@ -133,8 +134,8 @@ public class HandleSynchronized extends JavacAnnotationHandler<Synchronized> { lockNode = maker.Select(maker.Ident(methodNode.toName("this")), methodNode.toName(lockName)); } - recursiveSetGeneratedBy(lockNode, ast, context); - method.body = setGeneratedBy(maker.Block(0, List.<JCStatement>of(setGeneratedBy(maker.Synchronized(lockNode, method.body), ast, context))), ast, context); + recursiveSetGeneratedBy(lockNode, annotationNode); + method.body = setGeneratedBy(maker.Block(0, List.<JCStatement>of(setGeneratedBy(maker.Synchronized(lockNode, method.body), annotationNode))), annotationNode); methodNode.rebuild(); } diff --git a/src/core/lombok/javac/handlers/HandleToString.java b/src/core/lombok/javac/handlers/HandleToString.java index 0a950f7c..3fc6a4e4 100644 --- a/src/core/lombok/javac/handlers/HandleToString.java +++ b/src/core/lombok/javac/handlers/HandleToString.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2020 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -38,11 +38,9 @@ import lombok.core.handlers.InclusionExclusionUtils.Included; import lombok.javac.JavacAnnotationHandler; import lombok.javac.JavacNode; import lombok.javac.JavacTreeMaker; - -import org.mangosdk.spi.ProviderFor; +import lombok.spi.Provides; import com.sun.tools.javac.code.Flags; -import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCAnnotation; import com.sun.tools.javac.tree.JCTree.JCArrayTypeTree; import com.sun.tools.javac.tree.JCTree.JCBlock; @@ -60,7 +58,7 @@ import com.sun.tools.javac.util.List; /** * Handles the {@code ToString} annotation for javac. */ -@ProviderFor(JavacAnnotationHandler.class) +@Provides public class HandleToString extends JavacAnnotationHandler<ToString> { @Override public void handle(AnnotationValues<ToString> annotation, JCAnnotation ast, JavacNode annotationNode) { handleFlagUsage(annotationNode, ConfigurationKeys.TO_STRING_FLAG_USAGE, "@ToString"); @@ -107,13 +105,7 @@ public class HandleToString extends JavacAnnotationHandler<ToString> { public void generateToString(JavacNode typeNode, JavacNode source, java.util.List<Included<JavacNode, ToString.Include>> members, boolean includeFieldNames, Boolean callSuper, boolean whineIfExists, FieldAccess fieldAccess) { - boolean notAClass = true; - if (typeNode.get() instanceof JCClassDecl) { - long flags = ((JCClassDecl) typeNode.get()).mods.flags; - notAClass = (flags & (Flags.INTERFACE | Flags.ANNOTATION)) != 0; - } - - if (notAClass) { + if (!isClassOrEnum(typeNode)) { source.addError("@ToString is only supported on a class or enum."); return; } @@ -141,7 +133,7 @@ public class HandleToString extends JavacAnnotationHandler<ToString> { } } } - JCMethodDecl method = createToString(typeNode, members, includeFieldNames, callSuper, fieldAccess, source.get()); + JCMethodDecl method = createToString(typeNode, members, includeFieldNames, callSuper, fieldAccess, source); injectMethod(typeNode, method); break; case EXISTS_BY_LOMBOK: @@ -156,7 +148,7 @@ public class HandleToString extends JavacAnnotationHandler<ToString> { } static JCMethodDecl createToString(JavacNode typeNode, Collection<Included<JavacNode, ToString.Include>> members, - boolean includeNames, boolean callSuper, FieldAccess fieldAccess, JCTree source) { + boolean includeNames, boolean callSuper, FieldAccess fieldAccess, JavacNode source) { JavacTreeMaker maker = typeNode.getTreeMaker(); @@ -256,7 +248,7 @@ public class HandleToString extends JavacAnnotationHandler<ToString> { JCMethodDecl methodDef = maker.MethodDef(mods, typeNode.toName("toString"), returnType, List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null); createRelevantNonNullAnnotation(typeNode, methodDef); - return recursiveSetGeneratedBy(methodDef, source, typeNode.getContext()); + return recursiveSetGeneratedBy(methodDef, source); } public static String getTypeName(JavacNode typeNode) { diff --git a/src/core/lombok/javac/handlers/HandleUtilityClass.java b/src/core/lombok/javac/handlers/HandleUtilityClass.java index 5d651689..e006cc47 100644 --- a/src/core/lombok/javac/handlers/HandleUtilityClass.java +++ b/src/core/lombok/javac/handlers/HandleUtilityClass.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015-2020 The Project Lombok Authors. + * Copyright (C) 2015-2021 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 @@ -25,8 +25,6 @@ import static lombok.core.handlers.HandlerUtil.handleExperimentalFlagUsage; import static lombok.javac.Javac.CTC_VOID; import static lombok.javac.handlers.JavacHandlerUtil.*; -import org.mangosdk.spi.ProviderFor; - import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.code.Type; import com.sun.tools.javac.tree.JCTree.JCAnnotation; @@ -50,12 +48,13 @@ import lombok.javac.Javac; import lombok.javac.JavacAnnotationHandler; import lombok.javac.JavacNode; import lombok.javac.JavacTreeMaker; +import lombok.spi.Provides; /** * Handles the {@code @UtilityClass} annotation for javac. */ @HandlerPriority(-4096) //-2^12; to ensure @FieldDefaults picks up on the 'static' we set here. -@ProviderFor(JavacAnnotationHandler.class) +@Provides public class HandleUtilityClass extends JavacAnnotationHandler<UtilityClass> { @Override public void handle(AnnotationValues<UtilityClass> annotation, JCAnnotation ast, JavacNode annotationNode) { handleExperimentalFlagUsage(annotationNode, ConfigurationKeys.UTILITY_CLASS_FLAG_USAGE, "@UtilityClass"); @@ -68,13 +67,8 @@ public class HandleUtilityClass extends JavacAnnotationHandler<UtilityClass> { } private static boolean checkLegality(JavacNode typeNode, JavacNode errorNode) { - JCClassDecl typeDecl = null; - if (typeNode.get() instanceof JCClassDecl) typeDecl = (JCClassDecl) typeNode.get(); - long modifiers = typeDecl == null ? 0 : typeDecl.mods.flags; - boolean notAClass = (modifiers & (Flags.INTERFACE | Flags.ANNOTATION | Flags.ENUM)) != 0; - - if (typeDecl == null || notAClass) { - errorNode.addError("@UtilityClass is only supported on a class (can't be an interface, enum, or annotation)."); + if (!isClass(typeNode)) { + errorNode.addError("@UtilityClass is only supported on a class."); return false; } @@ -146,7 +140,7 @@ public class HandleUtilityClass extends JavacAnnotationHandler<UtilityClass> { Name name = typeNode.toName("<init>"); JCBlock block = maker.Block(0L, createThrowStatement(typeNode, maker)); JCMethodDecl methodDef = maker.MethodDef(mods, name, null, List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), block, null); - JCMethodDecl constructor = recursiveSetGeneratedBy(methodDef, typeNode.get(), typeNode.getContext()); + JCMethodDecl constructor = recursiveSetGeneratedBy(methodDef, typeNode); JavacHandlerUtil.injectMethod(typeNode, constructor, List.<Type>nil(), Javac.createVoidType(typeNode.getSymbolTable(), CTC_VOID)); } diff --git a/src/core/lombok/javac/handlers/HandleVal.java b/src/core/lombok/javac/handlers/HandleVal.java index 23c27bc0..7a524ca3 100644 --- a/src/core/lombok/javac/handlers/HandleVal.java +++ b/src/core/lombok/javac/handlers/HandleVal.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2018 The Project Lombok Authors. + * Copyright (C) 2010-2021 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 @@ -33,8 +33,7 @@ import lombok.javac.JavacASTVisitor; import lombok.javac.JavacNode; import lombok.javac.JavacResolution; import lombok.javac.ResolutionResetNeeded; - -import org.mangosdk.spi.ProviderFor; +import lombok.spi.Provides; import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.code.Symtab; @@ -49,7 +48,7 @@ import com.sun.tools.javac.tree.JCTree.JCNewArray; import com.sun.tools.javac.tree.JCTree.JCVariableDecl; import com.sun.tools.javac.util.List; -@ProviderFor(JavacASTVisitor.class) +@Provides(JavacASTVisitor.class) @HandlerPriority(HANDLE_DELEGATE_PRIORITY + 100) // run slightly after HandleDelegate; resolution needs to work, so if the RHS expression is i.e. a call to a generated getter, we have to run after that getter has been generated. @ResolutionResetNeeded public class HandleVal extends JavacASTAdapter { @@ -63,6 +62,7 @@ public class HandleVal extends JavacASTAdapter { JCTree typeTree = local.vartype; if (typeTree == null) return; String typeTreeToString = typeTree.toString(); + JavacNode typeNode = localNode.getNodeFor(typeTree); if (!(eq(typeTreeToString, "val") || eq(typeTreeToString, "var"))) return; boolean isVal = typeMatches(val.class, localNode, typeTree); @@ -111,7 +111,7 @@ public class HandleVal extends JavacASTAdapter { if (isVal) local.mods.flags |= Flags.FINAL; if (!localNode.shouldDeleteLombokAnnotations()) { - JCAnnotation valAnnotation = recursiveSetGeneratedBy(localNode.getTreeMaker().Annotation(local.vartype, List.<JCExpression>nil()), typeTree, localNode.getContext()); + JCAnnotation valAnnotation = recursiveSetGeneratedBy(localNode.getTreeMaker().Annotation(local.vartype, List.<JCExpression>nil()), typeNode); local.mods.annotations = local.mods.annotations == null ? List.of(valAnnotation) : local.mods.annotations.append(valAnnotation); } @@ -182,7 +182,7 @@ public class HandleVal extends JavacASTAdapter { local.vartype = JavacResolution.createJavaLangObject(localNode.getAst()); throw e; } finally { - recursiveSetGeneratedBy(local.vartype, typeTree, localNode.getContext()); + recursiveSetGeneratedBy(local.vartype, typeNode); } } } diff --git a/src/core/lombok/javac/handlers/HandleValue.java b/src/core/lombok/javac/handlers/HandleValue.java index abc5a5ca..cff29801 100644 --- a/src/core/lombok/javac/handlers/HandleValue.java +++ b/src/core/lombok/javac/handlers/HandleValue.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2018 The Project Lombok Authors. + * Copyright (C) 2012-2021 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 @@ -33,8 +33,7 @@ import lombok.Value; import lombok.javac.JavacAnnotationHandler; import lombok.javac.JavacNode; import lombok.javac.handlers.HandleConstructor.SkipIfConstructorExists; - -import org.mangosdk.spi.ProviderFor; +import lombok.spi.Provides; import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.tree.JCTree.JCAnnotation; @@ -45,7 +44,7 @@ import com.sun.tools.javac.util.List; /** * Handles the {@code lombok.Value} annotation for javac. */ -@ProviderFor(JavacAnnotationHandler.class) +@Provides @HandlerPriority(-512) //-2^9; to ensure @EqualsAndHashCode and such pick up on this handler making the class final and messing with the fields' access levels, run earlier. public class HandleValue extends JavacAnnotationHandler<Value> { private HandleFieldDefaults handleFieldDefaults = new HandleFieldDefaults(); @@ -72,7 +71,6 @@ public class HandleValue extends JavacAnnotationHandler<Value> { JCModifiers jcm = ((JCClassDecl) typeNode.get()).mods; if ((jcm.flags & Flags.FINAL) == 0) { jcm.flags |= Flags.FINAL; - typeNode.rebuild(); } } handleFieldDefaults.generateFieldDefaultsForType(typeNode, annotationNode, AccessLevel.PRIVATE, true, true); diff --git a/src/core/lombok/javac/handlers/HandleWith.java b/src/core/lombok/javac/handlers/HandleWith.java index 4e35a574..f914b4c7 100644 --- a/src/core/lombok/javac/handlers/HandleWith.java +++ b/src/core/lombok/javac/handlers/HandleWith.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2020 The Project Lombok Authors. + * Copyright (C) 2012-2021 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 @@ -37,8 +37,7 @@ import lombok.javac.JavacAnnotationHandler; import lombok.javac.JavacNode; import lombok.javac.JavacTreeMaker; import lombok.javac.handlers.JavacHandlerUtil.CopyJavadoc; - -import org.mangosdk.spi.ProviderFor; +import lombok.spi.Provides; import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.code.Type; @@ -62,7 +61,7 @@ import com.sun.tools.javac.util.Name; /** * Handles the {@code lombok.With} annotation for javac. */ -@ProviderFor(JavacAnnotationHandler.class) +@Provides public class HandleWith extends JavacAnnotationHandler<With> { public void generateWithForType(JavacNode typeNode, JavacNode errorNode, AccessLevel level, boolean checkForTypeLevelWith) { if (checkForTypeLevelWith) { @@ -215,6 +214,7 @@ public class HandleWith extends JavacAnnotationHandler<With> { ClassSymbol sym = ((JCClassDecl) fieldNode.up().get()).sym; Type returnType = sym == null ? null : sym.type; + recursiveSetGeneratedBy(createdWith, source); injectMethod(typeNode, createdWith, List.<Type>of(getMirrorForFieldType(fieldNode)), returnType); } @@ -234,7 +234,7 @@ public class HandleWith extends JavacAnnotationHandler<With> { long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, field.getContext()); List<JCAnnotation> annsOnParam = copyAnnotations(onParam).appendList(copyableAnnotations); - JCExpression pType = cloneType(maker, fieldDecl.vartype, source.get(), source.getContext()); + JCExpression pType = cloneType(maker, fieldDecl.vartype, source); JCVariableDecl param = maker.VarDef(maker.Modifiers(flags, annsOnParam), fieldDecl.name, pType, null); if (!makeAbstract) { @@ -289,7 +289,7 @@ public class HandleWith extends JavacAnnotationHandler<With> { if (makeAbstract) access = access | Flags.ABSTRACT; JCMethodDecl decl = recursiveSetGeneratedBy(maker.MethodDef(maker.Modifiers(access, annsOnMethod), methodName, returnType, - methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue), source.get(), field.getContext()); + methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue), source); copyJavadoc(field, decl, CopyJavadoc.WITH); return decl; } diff --git a/src/core/lombok/javac/handlers/HandleWithBy.java b/src/core/lombok/javac/handlers/HandleWithBy.java index 19673172..f1f953b3 100644 --- a/src/core/lombok/javac/handlers/HandleWithBy.java +++ b/src/core/lombok/javac/handlers/HandleWithBy.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 The Project Lombok Authors. + * Copyright (C) 2020-2021 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 @@ -41,8 +41,7 @@ import lombok.javac.JavacNode; import lombok.javac.JavacTreeMaker; import lombok.javac.JavacTreeMaker.TypeTag; import lombok.javac.handlers.JavacHandlerUtil.CopyJavadoc; - -import org.mangosdk.spi.ProviderFor; +import lombok.spi.Provides; import com.sun.tools.javac.code.BoundKind; import com.sun.tools.javac.code.Flags; @@ -67,7 +66,7 @@ import com.sun.tools.javac.util.Name; /** * Handles the {@code lombok.With} annotation for javac. */ -@ProviderFor(JavacAnnotationHandler.class) +@Provides public class HandleWithBy extends JavacAnnotationHandler<WithBy> { public void generateWithByForType(JavacNode typeNode, JavacNode errorNode, AccessLevel level, boolean checkForTypeLevelWithBy) { if (checkForTypeLevelWithBy) { @@ -126,7 +125,6 @@ public class HandleWithBy extends JavacAnnotationHandler<WithBy> { @Override public void handle(AnnotationValues<WithBy> annotation, JCAnnotation ast, JavacNode annotationNode) { handleExperimentalFlagUsage(annotationNode, ConfigurationKeys.WITHBY_FLAG_USAGE, "@WithBy"); - Collection<JavacNode> fields = annotationNode.upFromAnnotationToFields(); deleteAnnotationIfNeccessary(annotationNode, WithBy.class); deleteImportFromCompilationUnit(annotationNode, "lombok.AccessLevel"); JavacNode node = annotationNode.up(); @@ -138,7 +136,7 @@ public class HandleWithBy extends JavacAnnotationHandler<WithBy> { switch (node.getKind()) { case FIELD: - createWithByForFields(level, fields, annotationNode, true, onMethod); + createWithByForFields(level, annotationNode.upFromAnnotationToFields(), annotationNode, true, onMethod); break; case TYPE: if (!onMethod.isEmpty()) annotationNode.addError("'onMethod' is not supported for @WithBy on a type."); @@ -209,6 +207,7 @@ public class HandleWithBy extends JavacAnnotationHandler<WithBy> { ClassSymbol sym = ((JCClassDecl) fieldNode.up().get()).sym; Type returnType = sym == null ? null : sym.type; + recursiveSetGeneratedBy(createdWithBy, source); injectMethod(typeNode, createdWithBy, List.<Type>of(getMirrorForFieldType(fieldNode)), returnType); } @@ -265,7 +264,7 @@ public class HandleWithBy extends JavacAnnotationHandler<WithBy> { } if (functionalInterfaceName == null) { functionalInterfaceName = NAME_JUF_FUNCTION; - parameterizer = cloneType(maker, fieldDecl.vartype, source.get(), field.getContext()); + parameterizer = cloneType(maker, fieldDecl.vartype, source); } if (functionalInterfaceName == NAME_JUF_INTOP) applyMethodName = "applyAsInt"; if (functionalInterfaceName == NAME_JUF_LONGOP) applyMethodName = "applyAsLong"; @@ -274,7 +273,7 @@ public class HandleWithBy extends JavacAnnotationHandler<WithBy> { JCExpression varType = chainDots(field, functionalInterfaceName); if (parameterizer != null && superExtendsStyle) { JCExpression parameterizer1 = parameterizer; - JCExpression parameterizer2 = cloneType(maker, parameterizer, source.get(), field.getContext()); + JCExpression parameterizer2 = cloneType(maker, parameterizer, source); // TODO: Apply copyable annotations to 'parameterizer' and 'parameterizer2'. JCExpression arg1 = maker.Wildcard(maker.TypeBoundKind(BoundKind.SUPER), parameterizer1); JCExpression arg2 = maker.Wildcard(maker.TypeBoundKind(BoundKind.EXTENDS), parameterizer2); @@ -334,7 +333,7 @@ public class HandleWithBy extends JavacAnnotationHandler<WithBy> { if (makeAbstract) access = access | Flags.ABSTRACT; createRelevantNonNullAnnotation(source, param); JCMethodDecl decl = recursiveSetGeneratedBy(maker.MethodDef(maker.Modifiers(access, annsOnMethod), methodName, returnType, - methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue), source.get(), field.getContext()); + methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue), source); copyJavadoc(field, decl, CopyJavadoc.WITH_BY); createRelevantNonNullAnnotation(source, decl); return decl; diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java index fbde9568..32eae4e9 100644 --- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java +++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2020 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -103,6 +103,7 @@ import lombok.delombok.LombokOptionsFactory; import lombok.experimental.Accessors; import lombok.experimental.Tolerate; import lombok.javac.Javac; +import lombok.javac.JavacAugments; import lombok.javac.JavacNode; import lombok.javac.JavacTreeMaker; import lombok.permit.Permit; @@ -116,17 +117,15 @@ public class JavacHandlerUtil { } private static class MarkingScanner extends TreeScanner { - private final JCTree source; - private final Context context; + private final JavacNode source; - MarkingScanner(JCTree source, Context context) { + MarkingScanner(JavacNode source) { this.source = source; - this.context = context; } @Override public void scan(JCTree tree) { if (tree == null) return; - setGeneratedBy(tree, source, context); + setGeneratedBy(tree, source); super.scan(tree); } } @@ -158,20 +157,31 @@ public class JavacHandlerUtil { return getGeneratedBy(node) != null; } - public static <T extends JCTree> T recursiveSetGeneratedBy(T node, JCTree source, Context context) { + public static <T extends JCTree> T recursiveSetGeneratedBy(T node, JavacNode source) { if (node == null) return null; - setGeneratedBy(node, source, context); - node.accept(new MarkingScanner(source, context)); + setGeneratedBy(node, source); + node.accept(new MarkingScanner(source)); return node; } - public static <T extends JCTree> T setGeneratedBy(T node, JCTree source, Context context) { + public static <T extends JCTree> T setGeneratedBy(T node, JavacNode sourceNode) { if (node == null) return null; - if (source == null) JCTree_generatedNode.clear(node); - else JCTree_generatedNode.set(node, source); - if (source != null && (!inNetbeansEditor(context) || (node instanceof JCVariableDecl && (((JCVariableDecl) node).mods.flags & Flags.PARAMETER) != 0))) node.pos = source.pos; + if (sourceNode == null) { + JCTree_generatedNode.clear(node); + return node; + } + JCTree_generatedNode.set(node, sourceNode.get()); + + if (!inNetbeansEditor(sourceNode.getContext()) || isParameter(node)) { + node.pos = sourceNode.getStartPos(); + storeEnd(node, sourceNode.getEndPosition(), (JCCompilationUnit) sourceNode.top().get()); + } return node; } + + public static boolean isParameter(JCTree node) { + return node instanceof JCVariableDecl && (((JCVariableDecl) node).mods.flags & Flags.PARAMETER) != 0; + } public static boolean hasAnnotation(String type, JavacNode node) { return hasAnnotation(type, node, false); @@ -528,21 +538,18 @@ public class JavacHandlerUtil { public static void deleteImportFromCompilationUnit(JavacNode node, String name) { if (inNetbeansEditor(node)) return; if (!node.shouldDeleteLombokAnnotations()) return; - ListBuffer<JCTree> newDefs = new ListBuffer<JCTree>(); JCCompilationUnit unit = (JCCompilationUnit) node.top().get(); for (JCTree def : unit.defs) { - boolean delete = false; - if (def instanceof JCImport) { - JCImport imp0rt = (JCImport)def; - delete = (!imp0rt.staticImport && imp0rt.qualid.toString().equals(name)); - } - if (!delete) newDefs.append(def); + if (!(def instanceof JCImport)) continue; + JCImport imp0rt = (JCImport) def; + if (imp0rt.staticImport) continue; + if (!imp0rt.qualid.toString().equals(name)) continue; + JavacAugments.JCImport_deletable.set(imp0rt, true); } - unit.defs = newDefs.toList(); } - + private static List<JCAnnotation> filterList(List<JCAnnotation> annotations, JCTree jcTree) { ListBuffer<JCAnnotation> newAnnotations = new ListBuffer<JCAnnotation>(); for (JCAnnotation ann : annotations) { @@ -798,7 +805,7 @@ public class JavacHandlerUtil { node = upToTypeNode(node); if (node != null && node.get() instanceof JCClassDecl) { - for (JCTree def : ((JCClassDecl)node.get()).defs) { + for (JCTree def : ((JCClassDecl) node.get()).defs) { if (def instanceof JCMethodDecl) { JCMethodDecl md = (JCMethodDecl) def; if (md.name.contentEquals("<init>")) { @@ -1035,8 +1042,8 @@ public class JavacHandlerUtil { JCClassDecl type = (JCClassDecl) typeNode.get(); if (addGenerated) { - addSuppressWarningsAll(field.mods, typeNode, field.pos, getGeneratedBy(field), typeNode.getContext()); - addGenerated(field.mods, typeNode, field.pos, getGeneratedBy(field), typeNode.getContext()); + addSuppressWarningsAll(field.mods, typeNode, typeNode.getNodeFor(getGeneratedBy(field)), typeNode.getContext()); + addGenerated(field.mods, typeNode, typeNode.getNodeFor(getGeneratedBy(field)), typeNode.getContext()); } List<JCTree> insertAfter = null; @@ -1229,8 +1236,8 @@ public class JavacHandlerUtil { } } - addSuppressWarningsAll(method.mods, typeNode, method.pos, getGeneratedBy(method), typeNode.getContext()); - addGenerated(method.mods, typeNode, method.pos, getGeneratedBy(method), typeNode.getContext()); + addSuppressWarningsAll(method.mods, typeNode, typeNode.getNodeFor(getGeneratedBy(method)), typeNode.getContext()); + addGenerated(method.mods, typeNode, typeNode.getNodeFor(getGeneratedBy(method)), typeNode.getContext()); type.defs = type.defs.append(method); List<Symbol.VarSymbol> params = null; @@ -1268,7 +1275,7 @@ public class JavacHandlerUtil { typeNode.add(method, Kind.METHOD); } - + private static void fixMethodMirror(Context context, Element typeMirror, long access, Name methodName, List<Type> paramTypes, List<Symbol.VarSymbol> params, Type returnType) { if (typeMirror == null || paramTypes == null || returnType == null) return; ClassSymbol cs = (ClassSymbol) typeMirror; @@ -1291,8 +1298,8 @@ public class JavacHandlerUtil { */ public static JavacNode injectType(JavacNode typeNode, final JCClassDecl type) { JCClassDecl typeDecl = (JCClassDecl) typeNode.get(); - addSuppressWarningsAll(type.mods, typeNode, type.pos, getGeneratedBy(type), typeNode.getContext()); - addGenerated(type.mods, typeNode, type.pos, getGeneratedBy(type), typeNode.getContext()); + addSuppressWarningsAll(type.mods, typeNode, typeNode.getNodeFor(getGeneratedBy(type)), typeNode.getContext()); + addGenerated(type.mods, typeNode, typeNode.getNodeFor(getGeneratedBy(type)), typeNode.getContext()); typeDecl.defs = typeDecl.defs.append(type); return typeNode.add(type, Kind.TYPE); } @@ -1331,7 +1338,7 @@ public class JavacHandlerUtil { } } - public static void addSuppressWarningsAll(JCModifiers mods, JavacNode node, int pos, JCTree source, Context context) { + public static void addSuppressWarningsAll(JCModifiers mods, JavacNode node, JavacNode source, Context context) { if (!LombokOptionsFactory.getDelombokOptions(context).getFormatPreferences().generateSuppressWarnings()) return; boolean addJLSuppress = !Boolean.FALSE.equals(node.getAst().readConfiguration(ConfigurationKeys.ADD_SUPPRESSWARNINGS_ANNOTATIONS)); @@ -1347,27 +1354,27 @@ public class JavacHandlerUtil { } } } - if (addJLSuppress) addAnnotation(mods, node, pos, source, context, "java.lang.SuppressWarnings", node.getTreeMaker().Literal("all")); + if (addJLSuppress) addAnnotation(mods, node, source, "java.lang.SuppressWarnings", node.getTreeMaker().Literal("all")); if (Boolean.TRUE.equals(node.getAst().readConfiguration(ConfigurationKeys.ADD_FINDBUGS_SUPPRESSWARNINGS_ANNOTATIONS))) { JavacTreeMaker maker = node.getTreeMaker(); JCExpression arg = maker.Assign(maker.Ident(node.toName("justification")), maker.Literal("generated code")); - addAnnotation(mods, node, pos, source, context, "edu.umd.cs.findbugs.annotations.SuppressFBWarnings", arg); + addAnnotation(mods, node, source, "edu.umd.cs.findbugs.annotations.SuppressFBWarnings", arg); } } - public static void addGenerated(JCModifiers mods, JavacNode node, int pos, JCTree source, Context context) { + public static void addGenerated(JCModifiers mods, JavacNode node, JavacNode source, Context context) { if (!LombokOptionsFactory.getDelombokOptions(context).getFormatPreferences().generateGenerated()) return; if (HandlerUtil.shouldAddGenerated(node)) { - addAnnotation(mods, node, pos, source, context, "javax.annotation.Generated", node.getTreeMaker().Literal("lombok")); + addAnnotation(mods, node, source, "javax.annotation.Generated", node.getTreeMaker().Literal("lombok")); } if (Boolean.TRUE.equals(node.getAst().readConfiguration(ConfigurationKeys.ADD_LOMBOK_GENERATED_ANNOTATIONS))) { - addAnnotation(mods, node, pos, source, context, "lombok.Generated", null); + addAnnotation(mods, node, source, "lombok.Generated", null); } } - public static void addAnnotation(JCModifiers mods, JavacNode node, int pos, JCTree source, Context context, String annotationTypeFqn, JCExpression arg) { + public static void addAnnotation(JCModifiers mods, JavacNode node, JavacNode source, String annotationTypeFqn, JCExpression arg) { boolean isJavaLangBased; String simpleName; { int idx = annotationTypeFqn.lastIndexOf('.'); @@ -1390,17 +1397,8 @@ public class JavacHandlerUtil { JavacTreeMaker maker = node.getTreeMaker(); JCExpression annType = isJavaLangBased ? genJavaLangTypeRef(node, simpleName) : chainDotsString(node, annotationTypeFqn); - annType.pos = pos; - if (arg != null) { - arg.pos = pos; - if (arg instanceof JCAssign) { - ((JCAssign) arg).lhs.pos = pos; - ((JCAssign) arg).rhs.pos = pos; - } - } List<JCExpression> argList = arg != null ? List.of(arg) : List.<JCExpression>nil(); - JCAnnotation annotation = recursiveSetGeneratedBy(maker.Annotation(annType, argList), source, context); - annotation.pos = pos; + JCAnnotation annotation = recursiveSetGeneratedBy(maker.Annotation(annType, argList), source); mods.annotations = mods.annotations.append(annotation); } @@ -1820,13 +1818,12 @@ public class JavacHandlerUtil { if (params == null || params.isEmpty()) return params; ListBuffer<JCTypeParameter> out = new ListBuffer<JCTypeParameter>(); JavacTreeMaker maker = source.getTreeMaker(); - Context context = source.getContext(); for (JCTypeParameter tp : params) { List<JCExpression> bounds = tp.bounds; if (bounds != null && !bounds.isEmpty()) { ListBuffer<JCExpression> boundsCopy = new ListBuffer<JCExpression>(); for (JCExpression expr : tp.bounds) { - boundsCopy.append(cloneType(maker, expr, source.get(), context)); + boundsCopy.append(cloneType(maker, expr, source)); } bounds = boundsCopy.toList(); } @@ -1925,17 +1922,30 @@ public class JavacHandlerUtil { return out.toList(); } - static boolean isClass(JavacNode typeNode) { - return isClassAndDoesNotHaveFlags(typeNode, Flags.INTERFACE | Flags.ENUM | Flags.ANNOTATION); + /** + * Returns {@code true} if the provided node is an actual class and not some other type declaration (so, not an annotation definition, interface, enum, or record). + */ + public static boolean isClass(JavacNode typeNode) { + return isClassAndDoesNotHaveFlags(typeNode, Flags.INTERFACE | Flags.ENUM | Flags.ANNOTATION | RECORD); } - static boolean isClassOrEnum(JavacNode typeNode) { - return isClassAndDoesNotHaveFlags(typeNode, Flags.INTERFACE | Flags.ANNOTATION); + /** + * Returns {@code true} if the provided node is an actual class or enum and not some other type declaration (so, not an annotation definition, interface, or record). + */ + public static boolean isClassOrEnum(JavacNode typeNode) { + return isClassAndDoesNotHaveFlags(typeNode, Flags.INTERFACE | Flags.ANNOTATION | RECORD); } - public static boolean isClassAndDoesNotHaveFlags(JavacNode typeNode, int flags) { + /** + * Returns {@code true} if the provided node is a record declaration (so, not an annotation definition, interface, enum, or plain class). + */ + public static boolean isRecord(JavacNode typeNode) { + return typeNode.getKind() == Kind.TYPE && (((JCClassDecl) typeNode.get()).mods.flags & RECORD) != 0; + } + + public static boolean isClassAndDoesNotHaveFlags(JavacNode typeNode, long flags) { JCClassDecl typeDecl = null; - if (typeNode.get() instanceof JCClassDecl) typeDecl = (JCClassDecl)typeNode.get(); + if (typeNode.get() instanceof JCClassDecl) typeDecl = (JCClassDecl) typeNode.get(); else return false; long typeDeclflags = typeDecl == null ? 0 : typeDecl.mods.flags; @@ -1949,11 +1959,11 @@ public class JavacHandlerUtil { return node; } - public static List<JCExpression> cloneTypes(JavacTreeMaker maker, List<JCExpression> in, JCTree source, Context context) { + public static List<JCExpression> cloneTypes(JavacTreeMaker maker, List<JCExpression> in, JavacNode source) { if (in.isEmpty()) return List.nil(); - if (in.size() == 1) return List.of(cloneType(maker, in.get(0), source, context)); + if (in.size() == 1) return List.of(cloneType(maker, in.get(0), source)); ListBuffer<JCExpression> lb = new ListBuffer<JCExpression>(); - for (JCExpression expr : in) lb.append(cloneType(maker, expr, source, context)); + for (JCExpression expr : in) lb.append(cloneType(maker, expr, source)); return lb.toList(); } @@ -1967,9 +1977,9 @@ public class JavacHandlerUtil { * the class's own parameter, but as its a static method, the static method's notion of {@code T} is different from the class notion of {@code T}. If you're duplicating * a type used in the class context, you need to use this method. */ - public static JCExpression cloneType(JavacTreeMaker maker, JCExpression in, JCTree source, Context context) { + public static JCExpression cloneType(JavacTreeMaker maker, JCExpression in, JavacNode source) { JCExpression out = cloneType0(maker, in); - if (out != null) recursiveSetGeneratedBy(out, source, context); + if (out != null) recursiveSetGeneratedBy(out, source); return out; } @@ -2044,7 +2054,7 @@ public class JavacHandlerUtil { String out = getJavadocSection(javadoc, "GETTER"); final boolean sectionBased = out != null; if (!sectionBased) { - out = stripLinesWithTagFromJavadoc(stripSectionsFromJavadoc(javadoc), "@param(?:eter)?\\s+.*"); + out = stripLinesWithTagFromJavadoc(stripSectionsFromJavadoc(javadoc), JavadocTag.PARAM); } node.getAst().cleanupTask("javadocfilter-getter", n, new CleanupTask() { @Override public void cleanup() { @@ -2052,7 +2062,7 @@ public class JavacHandlerUtil { if (javadoc == null || javadoc.isEmpty()) return; javadoc = stripSectionsFromJavadoc(javadoc); if (!sectionBased) { - javadoc = stripLinesWithTagFromJavadoc(stripSectionsFromJavadoc(javadoc), "@returns?\\s+.*"); + javadoc = stripLinesWithTagFromJavadoc(stripSectionsFromJavadoc(javadoc), JavadocTag.RETURN); } Javac.setDocComment(cu, n, javadoc); } @@ -2085,7 +2095,7 @@ public class JavacHandlerUtil { String out = getJavadocSection(javadoc, sectionName); final boolean sectionBased = out != null; if (!sectionBased) { - out = stripLinesWithTagFromJavadoc(stripSectionsFromJavadoc(javadoc), "@returns?\\s+.*"); + out = stripLinesWithTagFromJavadoc(stripSectionsFromJavadoc(javadoc), JavadocTag.RETURN); } node.getAst().cleanupTask("javadocfilter-setter", n, new CleanupTask() { @Override public void cleanup() { @@ -2093,7 +2103,7 @@ public class JavacHandlerUtil { if (javadoc == null || javadoc.isEmpty()) return; javadoc = stripSectionsFromJavadoc(javadoc); if (!sectionBased) { - javadoc = stripLinesWithTagFromJavadoc(stripSectionsFromJavadoc(javadoc), "@param(?:eter)?\\s+.*"); + javadoc = stripLinesWithTagFromJavadoc(stripSectionsFromJavadoc(javadoc), JavadocTag.PARAM); } Javac.setDocComment(cu, n, javadoc); } @@ -2170,6 +2180,10 @@ public class JavacHandlerUtil { JCExpression resType = mth.restype; if (resType instanceof JCTypeApply) { JCTypeApply ta = (JCTypeApply) resType; + if (ta.clazz instanceof JCFieldAccess) { + mth.restype = maker.TypeApply(maker.AnnotatedType(List.of(m), ta.clazz), ta.arguments); + return; + } resType = ta.clazz; } diff --git a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java index 2fc9329c..4ca09b82 100644 --- a/src/core/lombok/javac/handlers/JavacSingularsRecipes.java +++ b/src/core/lombok/javac/handlers/JavacSingularsRecipes.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015-2020 The Project Lombok Authors. + * Copyright (C) 2015-2021 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 @@ -43,7 +43,6 @@ import com.sun.tools.javac.tree.JCTree.JCStatement; import com.sun.tools.javac.tree.JCTree.JCTypeParameter; import com.sun.tools.javac.tree.JCTree.JCVariableDecl; import com.sun.tools.javac.tree.JCTree.JCWildcard; -import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.ListBuffer; import com.sun.tools.javac.util.Name; @@ -236,7 +235,7 @@ public class JavacSingularsRecipes { return Arrays.asList(p, s); } - public abstract java.util.List<JavacNode> generateFields(SingularData data, JavacNode builderType, JCTree source); + public abstract java.util.List<JavacNode> generateFields(SingularData data, JavacNode builderType, JavacNode source); /** * Generates the singular, plural, and clear methods for the given {@link SingularData}. @@ -246,7 +245,7 @@ public class JavacSingularsRecipes { */ public void generateMethods(final BuilderJob job, SingularData data, boolean deprecate) { //job.checkerFramework, job.builderType, job.source, job.oldFluent, job.oldChain, job.accessInners - //CheckerFrameworkVersion cfv, final JavacNode builderType, JCTree source, boolean fluent, final boolean chain, AccessLevel access) { + //CheckerFrameworkVersion cfv, final JavacNode builderType, JavacNode source, boolean fluent, final boolean chain, AccessLevel access) { final JavacTreeMaker maker = job.builderType.getTreeMaker(); ExpressionMaker returnTypeMaker = new ExpressionMaker() { @Override public JCExpression make() { @@ -259,23 +258,23 @@ public class JavacSingularsRecipes { return job.oldChain ? maker.Return(maker.Ident(job.builderType.toName("this"))) : null; }}; - generateMethods(job.checkerFramework, data, deprecate, job.builderType, job.source, job.oldFluent, returnTypeMaker, returnStatementMaker, job.accessInners); + generateMethods(job.checkerFramework, data, deprecate, job.builderType, job.sourceNode, job.oldFluent, returnTypeMaker, returnStatementMaker, job.accessInners); } /** * Generates the singular, plural, and clear methods for the given {@link SingularData}. * Uses the given {@code returnTypeMaker} and {@code returnStatementMaker} for the generated methods. */ - public abstract void generateMethods(CheckerFrameworkVersion cfv, SingularData data, boolean deprecate, JavacNode builderType, JCTree source, boolean fluent, ExpressionMaker returnTypeMaker, StatementMaker returnStatementMaker, AccessLevel access); + public abstract void generateMethods(CheckerFrameworkVersion cfv, SingularData data, boolean deprecate, JavacNode builderType, JavacNode source, boolean fluent, ExpressionMaker returnTypeMaker, StatementMaker returnStatementMaker, AccessLevel access); - protected void doGenerateMethods(CheckerFrameworkVersion cfv, SingularData data, boolean deprecate, JavacNode builderType, JCTree source, boolean fluent, ExpressionMaker returnTypeMaker, StatementMaker returnStatementMaker, AccessLevel access) { + protected void doGenerateMethods(CheckerFrameworkVersion cfv, SingularData data, boolean deprecate, JavacNode builderType, JavacNode source, boolean fluent, ExpressionMaker returnTypeMaker, StatementMaker returnStatementMaker, AccessLevel access) { JavacTreeMaker maker = builderType.getTreeMaker(); generateSingularMethod(cfv, deprecate, maker, returnTypeMaker.make(), returnStatementMaker.make(), data, builderType, source, fluent, access); generatePluralMethod(cfv, deprecate, maker, returnTypeMaker.make(), returnStatementMaker.make(), data, builderType, source, fluent, access); generateClearMethod(cfv, deprecate, maker, returnTypeMaker.make(), returnStatementMaker.make(), data, builderType, source, access); } - private void finishAndInjectMethod(CheckerFrameworkVersion cfv, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean deprecate, ListBuffer<JCStatement> statements, Name methodName, List<JCVariableDecl> jcVariableDecls, List<JCAnnotation> methodAnnotations, AccessLevel access, Boolean ignoreNullCollections) { + private void finishAndInjectMethod(CheckerFrameworkVersion cfv, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JavacNode source, boolean deprecate, ListBuffer<JCStatement> statements, Name methodName, List<JCVariableDecl> jcVariableDecls, List<JCAnnotation> methodAnnotations, AccessLevel access, Boolean ignoreNullCollections) { if (returnStatement != null) statements.append(returnStatement); JCBlock body = maker.Block(0, statements.toList()); JCModifiers mods = makeMods(maker, cfv, builderType, deprecate, access, methodAnnotations); @@ -291,15 +290,15 @@ public class JavacSingularsRecipes { } JCMethodDecl method = maker.MethodDef(mods, methodName, returnType, typeParams, jcVariableDecls, thrown, body, null); - recursiveSetGeneratedBy(method, source, builderType.getContext()); if (returnStatement != null) createRelevantNonNullAnnotation(builderType, method); + recursiveSetGeneratedBy(method, source); injectMethod(builderType, method); } - private void generateClearMethod(CheckerFrameworkVersion cfv, boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, AccessLevel access) { + private void generateClearMethod(CheckerFrameworkVersion cfv, boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JavacNode source, AccessLevel access) { JCStatement clearStatement = generateClearStatements(maker, data, builderType); ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>(); - statements.add(clearStatement); + statements.append(clearStatement); Name methodName = builderType.toName(HandlerUtil.buildAccessorName("clear", data.getPluralName().toString())); finishAndInjectMethod(cfv, maker, returnType, returnStatement, data, builderType, source, deprecate, statements, methodName, List.<JCVariableDecl>nil(), List.<JCAnnotation>nil(), access, null); @@ -307,7 +306,7 @@ public class JavacSingularsRecipes { protected abstract JCStatement generateClearStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType); - private void generateSingularMethod(CheckerFrameworkVersion cfv, boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent, AccessLevel access) { + private void generateSingularMethod(CheckerFrameworkVersion cfv, boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JavacNode source, boolean fluent, AccessLevel access) { ListBuffer<JCStatement> statements = generateSingularMethodStatements(maker, data, builderType, source); List<JCVariableDecl> params = generateSingularMethodParameters(maker, data, builderType, source); Name name = data.getSingularName(); @@ -320,7 +319,7 @@ public class JavacSingularsRecipes { finishAndInjectMethod(cfv, maker, returnType, returnStatement, data, builderType, source, deprecate, statements, name, params, methodAnnotations, access, null); } - protected JCVariableDecl generateSingularMethodParameter(int typeIndex, JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source, Name name) { + protected JCVariableDecl generateSingularMethodParameter(int typeIndex, JavacTreeMaker maker, SingularData data, JavacNode builderType, JavacNode source, Name name) { long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext()); JCExpression type = cloneParamType(typeIndex, maker, data.getTypeArgs(), builderType, source); List<JCAnnotation> typeUseAnns = getTypeUseAnnotations(type); @@ -335,11 +334,11 @@ public class JavacSingularsRecipes { return maker.Exec(invokeAdd); } - protected abstract ListBuffer<JCStatement> generateSingularMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source); + protected abstract ListBuffer<JCStatement> generateSingularMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JavacNode source); - protected abstract List<JCVariableDecl> generateSingularMethodParameters(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source); + protected abstract List<JCVariableDecl> generateSingularMethodParameters(JavacTreeMaker maker, SingularData data, JavacNode builderType, JavacNode source); - private void generatePluralMethod(CheckerFrameworkVersion cfv, boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JCTree source, boolean fluent, AccessLevel access) { + private void generatePluralMethod(CheckerFrameworkVersion cfv, boolean deprecate, JavacTreeMaker maker, JCExpression returnType, JCStatement returnStatement, SingularData data, JavacNode builderType, JavacNode source, boolean fluent, AccessLevel access) { ListBuffer<JCStatement> statements = generatePluralMethodStatements(maker, data, builderType, source); Name name = data.getPluralName(); @@ -358,7 +357,7 @@ public class JavacSingularsRecipes { JCExpression incomingIsNotNull = maker.Binary(CTC_NOT_EQUAL, maker.Ident(data.getPluralName()), maker.Literal(CTC_BOT, null)); JCStatement onNotNull = maker.Block(0, statements.toList()); statements = new ListBuffer<JCStatement>(); - statements.add(maker.If(incomingIsNotNull, onNotNull, null)); + statements.append(maker.If(incomingIsNotNull, onNotNull, null)); } else { statements.prepend(JavacHandlerUtil.generateNullCheck(maker, null, data.getPluralName(), builderType, "%s cannot be null")); } @@ -368,7 +367,7 @@ public class JavacSingularsRecipes { finishAndInjectMethod(cfv, maker, returnType, returnStatement, data, builderType, source, deprecate, statements, name, List.of(param), methodAnnotations, access, ignoreNullCollections); } - protected ListBuffer<JCStatement> generatePluralMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { + protected ListBuffer<JCStatement> generatePluralMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JavacNode source) { ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>(); JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), getAddMethodName() + "All"); @@ -380,9 +379,9 @@ public class JavacSingularsRecipes { protected abstract JCExpression getPluralMethodParamType(JavacNode builderType); - protected abstract JCStatement createConstructBuilderVarIfNeeded(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source); + protected abstract JCStatement createConstructBuilderVarIfNeeded(JavacTreeMaker maker, SingularData data, JavacNode builderType, JavacNode source); - public abstract void appendBuildCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer<JCStatement> statements, Name targetVariableName, String builderVariable); + public abstract void appendBuildCode(SingularData data, JavacNode builderType, JavacNode source, ListBuffer<JCStatement> statements, Name targetVariableName, String builderVariable); public boolean shadowedDuringBuild() { return true; @@ -396,7 +395,7 @@ public class JavacSingularsRecipes { } } - public void appendCleaningCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer<JCStatement> statements) { + public void appendCleaningCode(SingularData data, JavacNode builderType, JavacNode source, ListBuffer<JCStatement> statements) { } // -- Utility methods -- @@ -412,16 +411,15 @@ public class JavacSingularsRecipes { * @param typeArgs the list of type args to clone. * @param source The source annotation that is the root cause of this code generation. */ - protected JCExpression addTypeArgs(int count, boolean addExtends, JavacNode node, JCExpression type, List<JCExpression> typeArgs, JCTree source) { + protected JCExpression addTypeArgs(int count, boolean addExtends, JavacNode node, JCExpression type, List<JCExpression> typeArgs, JavacNode source) { JavacTreeMaker maker = node.getTreeMaker(); List<JCExpression> clonedAndFixedTypeArgs = createTypeArgs(count, addExtends, node, typeArgs, source); return maker.TypeApply(type, clonedAndFixedTypeArgs); } - protected List<JCExpression> createTypeArgs(int count, boolean addExtends, JavacNode node, List<JCExpression> typeArgs, JCTree source) { + protected List<JCExpression> createTypeArgs(int count, boolean addExtends, JavacNode node, List<JCExpression> typeArgs, JavacNode source) { JavacTreeMaker maker = node.getTreeMaker(); - Context context = node.getContext(); if (count < 0) throw new IllegalArgumentException("count is negative"); if (count == 0) return List.nil(); @@ -438,17 +436,17 @@ public class JavacSingularsRecipes { } catch (Exception e) { inner = genJavaLangTypeRef(node, "Object"); } - arguments.append(cloneType(maker, inner, source, context)); + arguments.append(cloneType(maker, inner, source)); } else { - arguments.append(cloneType(maker, orig, source, context)); + arguments.append(cloneType(maker, orig, source)); } } else { if (orig.getKind() == Kind.UNBOUNDED_WILDCARD || orig.getKind() == Kind.SUPER_WILDCARD) { arguments.append(maker.Wildcard(maker.TypeBoundKind(BoundKind.UNBOUND), null)); } else if (orig.getKind() == Kind.EXTENDS_WILDCARD) { - arguments.append(cloneType(maker, orig, source, context)); + arguments.append(cloneType(maker, orig, source)); } else { - arguments.append(maker.Wildcard(maker.TypeBoundKind(BoundKind.EXTENDS), cloneType(maker, orig, source, context))); + arguments.append(maker.Wildcard(maker.TypeBoundKind(BoundKind.EXTENDS), cloneType(maker, orig, source))); } } if (--count == 0) break; @@ -471,7 +469,7 @@ public class JavacSingularsRecipes { JCExpression fn = maker.Select(maker.Select(maker.Ident(thisName), name), builderType.toName("size")); JCExpression sizeInvoke = maker.Apply(List.<JCExpression>nil(), fn, List.<JCExpression>nil()); if (nullGuard) { - JCExpression isNull = maker.Binary(CTC_EQUAL, maker.Select(maker.Ident(thisName), name), maker.Literal(CTC_BOT, 0)); + JCExpression isNull = maker.Binary(CTC_EQUAL, maker.Select(maker.Ident(thisName), name), maker.Literal(CTC_BOT, null)); JCExpression out = maker.Conditional(isNull, maker.Literal(CTC_INT, 0), sizeInvoke); if (parens) return maker.Parens(out); return out; @@ -479,7 +477,7 @@ public class JavacSingularsRecipes { return sizeInvoke; } - protected JCExpression cloneParamType(int index, JavacTreeMaker maker, List<JCExpression> typeArgs, JavacNode builderType, JCTree source) { + protected JCExpression cloneParamType(int index, JavacTreeMaker maker, List<JCExpression> typeArgs, JavacNode builderType, JavacNode source) { if (typeArgs == null || typeArgs.size() <= index) { return genJavaLangTypeRef(builderType, "Object"); } else { @@ -488,12 +486,12 @@ public class JavacSingularsRecipes { return genJavaLangTypeRef(builderType, "Object"); } else if (originalType.getKind() == Kind.EXTENDS_WILDCARD) { try { - return cloneType(maker, (JCExpression) ((JCWildcard) originalType).inner, source, builderType.getContext()); + return cloneType(maker, (JCExpression) ((JCWildcard) originalType).inner, source); } catch (Exception e) { return genJavaLangTypeRef(builderType, "Object"); } } else { - return cloneType(maker, originalType, source, builderType.getContext()); + return cloneType(maker, originalType, source); } } } @@ -503,5 +501,11 @@ public class JavacSingularsRecipes { protected abstract int getTypeArgumentsCount(); protected abstract String getEmptyMaker(String target); + + public JCExpression getEmptyExpression(String target, JavacTreeMaker maker, SingularData data, JavacNode builderType, JavacNode source) { + String emptyMaker = getEmptyMaker(target); + List<JCExpression> typeArgs = createTypeArgs(getTypeArgumentsCount(), false, builderType, data.getTypeArgs(), source); + return maker.Apply(typeArgs, chainDots(builderType, emptyMaker.split("\\.")), List.<JCExpression>nil()); + } } } diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaMapSingularizer.java index e0621cf7..84840799 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaMapSingularizer.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 The Project Lombok Authors. + * Copyright (C) 2015-2021 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 @@ -23,10 +23,9 @@ package lombok.javac.handlers.singulars; import lombok.core.LombokImmutableList; import lombok.javac.handlers.JavacSingularsRecipes.JavacSingularizer; +import lombok.spi.Provides; -import org.mangosdk.spi.ProviderFor; - -@ProviderFor(JavacSingularizer.class) +@Provides(JavacSingularizer.class) public class JavacGuavaMapSingularizer extends JavacGuavaSingularizer { // TODO cgcc.ImmutableMultimap, cgcc.ImmutableListMultimap, cgcc.ImmutableSetMultimap // TODO cgcc.ImmutableClassToInstanceMap diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSetListSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSetListSingularizer.java index 5c7fcab5..44d6d15b 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSetListSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSetListSingularizer.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 The Project Lombok Authors. + * Copyright (C) 2015-2021 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 @@ -21,12 +21,11 @@ */ package lombok.javac.handlers.singulars; -import org.mangosdk.spi.ProviderFor; - import lombok.core.LombokImmutableList; import lombok.javac.handlers.JavacSingularsRecipes.JavacSingularizer; +import lombok.spi.Provides; -@ProviderFor(JavacSingularizer.class) +@Provides(JavacSingularizer.class) public class JavacGuavaSetListSingularizer extends JavacGuavaSingularizer { // TODO com.google.common.collect.ImmutableRangeSet // TODO com.google.common.collect.ImmutableMultiset and com.google.common.collect.ImmutableSortedMultiset diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java index dadf881d..ce5aad5e 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaSingularizer.java @@ -39,7 +39,6 @@ import lombok.javac.handlers.JavacSingularsRecipes.SingularData; import lombok.javac.handlers.JavacSingularsRecipes.StatementMaker; import com.sun.tools.javac.code.Flags; -import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCExpression; import com.sun.tools.javac.tree.JCTree.JCStatement; import com.sun.tools.javac.tree.JCTree.JCVariableDecl; @@ -62,7 +61,7 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { return "builder"; } - @Override public java.util.List<JavacNode> generateFields(SingularData data, JavacNode builderType, JCTree source) { + @Override public java.util.List<JavacNode> generateFields(SingularData data, JavacNode builderType, JavacNode source) { JavacTreeMaker maker = builderType.getTreeMaker(); String simpleTypeName = getSimpleTargetTypeName(data); JCExpression type = JavacHandlerUtil.chainDots(builderType, "com", "google", "common", "collect", simpleTypeName, "Builder"); @@ -72,7 +71,7 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { return Collections.singletonList(injectFieldAndMarkGenerated(builderType, buildField)); } - @Override public void generateMethods(CheckerFrameworkVersion cfv, SingularData data, boolean deprecate, JavacNode builderType, JCTree source, boolean fluent, ExpressionMaker returnTypeMaker, StatementMaker returnStatementMaker, AccessLevel access) { + @Override public void generateMethods(CheckerFrameworkVersion cfv, SingularData data, boolean deprecate, JavacNode builderType, JavacNode source, boolean fluent, ExpressionMaker returnTypeMaker, StatementMaker returnStatementMaker, AccessLevel access) { doGenerateMethods(cfv, data, deprecate, builderType, source, fluent, returnTypeMaker, returnStatementMaker, access); } @@ -83,7 +82,7 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { } @Override - protected List<JCVariableDecl> generateSingularMethodParameters(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { + protected List<JCVariableDecl> generateSingularMethodParameters(JavacTreeMaker maker, SingularData data, JavacNode builderType, JavacNode source) { Name[] names = generateSingularMethodParameterNames(data, builderType); ListBuffer<JCVariableDecl> params = new ListBuffer<JCVariableDecl>(); for (int i = 0; i < names.length; i++) { @@ -93,7 +92,7 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { } @Override - protected ListBuffer<JCStatement> generateSingularMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { + protected ListBuffer<JCStatement> generateSingularMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JavacNode source) { Name[] names = generateSingularMethodParameterNames(data, builderType); JCExpression thisDotFieldDotAdd = chainDots(builderType, "this", data.getPluralName().toString(), getAddMethodName()); @@ -124,7 +123,7 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { return genTypeRef(builderType, getAddAllTypeName()); } - @Override public void appendBuildCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer<JCStatement> statements, Name targetVariableName, String builderVariable) { + @Override public void appendBuildCode(SingularData data, JavacNode builderType, JavacNode source, ListBuffer<JCStatement> statements, Name targetVariableName, String builderVariable) { JavacTreeMaker maker = builderType.getTreeMaker(); List<JCExpression> jceBlank = List.nil(); @@ -156,7 +155,7 @@ abstract class JavacGuavaSingularizer extends JavacSingularizer { } @Override - protected JCStatement createConstructBuilderVarIfNeeded(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { + protected JCStatement createConstructBuilderVarIfNeeded(JavacTreeMaker maker, SingularData data, JavacNode builderType, JavacNode source) { List<JCExpression> jceBlank = List.nil(); JCExpression thisDotField = maker.Select(maker.Ident(builderType.toName("this")), data.getPluralName()); diff --git a/src/core/lombok/javac/handlers/singulars/JavacGuavaTableSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacGuavaTableSingularizer.java index 080266b8..bdc5facc 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacGuavaTableSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacGuavaTableSingularizer.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 The Project Lombok Authors. + * Copyright (C) 2015-2021 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 @@ -21,12 +21,11 @@ */ package lombok.javac.handlers.singulars; -import org.mangosdk.spi.ProviderFor; - import lombok.core.LombokImmutableList; import lombok.javac.handlers.JavacSingularsRecipes.JavacSingularizer; +import lombok.spi.Provides; -@ProviderFor(JavacSingularizer.class) +@Provides(JavacSingularizer.class) public class JavacGuavaTableSingularizer extends JavacGuavaSingularizer { private static final LombokImmutableList<String> SUFFIXES = LombokImmutableList.of("rowKey", "columnKey", "value"); diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java index 634a086d..dfc8c7b0 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSetSingularizer.java @@ -37,7 +37,6 @@ import lombok.javac.handlers.JavacSingularsRecipes.SingularData; import lombok.javac.handlers.JavacSingularsRecipes.StatementMaker; import com.sun.tools.javac.code.Flags; -import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCExpression; import com.sun.tools.javac.tree.JCTree.JCStatement; import com.sun.tools.javac.tree.JCTree.JCVariableDecl; @@ -58,7 +57,7 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize return super.listMethodsToBeGenerated(data, builderType); } - @Override public java.util.List<JavacNode> generateFields(SingularData data, JavacNode builderType, JCTree source) { + @Override public java.util.List<JavacNode> generateFields(SingularData data, JavacNode builderType, JavacNode source) { JavacTreeMaker maker = builderType.getTreeMaker(); JCExpression type = JavacHandlerUtil.chainDots(builderType, "java", "util", "ArrayList"); type = addTypeArgs(1, false, builderType, type, data.getTypeArgs(), source); @@ -67,7 +66,7 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize return Collections.singletonList(injectFieldAndMarkGenerated(builderType, buildField)); } - @Override public void generateMethods(CheckerFrameworkVersion cfv, SingularData data, boolean deprecate, JavacNode builderType, JCTree source, boolean fluent, ExpressionMaker returnTypeMaker, StatementMaker returnStatementMaker, AccessLevel access) { + @Override public void generateMethods(CheckerFrameworkVersion cfv, SingularData data, boolean deprecate, JavacNode builderType, JavacNode source, boolean fluent, ExpressionMaker returnTypeMaker, StatementMaker returnStatementMaker, AccessLevel access) { doGenerateMethods(cfv, data, deprecate, builderType, source, fluent, returnTypeMaker, returnStatementMaker, access); } @@ -84,13 +83,13 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize } @Override - protected ListBuffer<JCStatement> generateSingularMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { + protected ListBuffer<JCStatement> generateSingularMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JavacNode source) { return new ListBuffer<JCStatement>() .append(generateSingularMethodAddStatement(maker, builderType, data.getSingularName(), data.getPluralName().toString())); } @Override - protected List<JCVariableDecl> generateSingularMethodParameters(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { + protected List<JCVariableDecl> generateSingularMethodParameters(JavacTreeMaker maker, SingularData data, JavacNode builderType, JavacNode source) { JCVariableDecl param = generateSingularMethodParameter(0, maker, data, builderType, source, data.getSingularName()); return List.of(param); } @@ -101,7 +100,7 @@ abstract class JavacJavaUtilListSetSingularizer extends JavacJavaUtilSingularize } @Override - protected JCStatement createConstructBuilderVarIfNeeded(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { + protected JCStatement createConstructBuilderVarIfNeeded(JavacTreeMaker maker, SingularData data, JavacNode builderType, JavacNode source) { return createConstructBuilderVarIfNeeded(maker, data, builderType, false, source); } diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSingularizer.java index 1f8bbbe9..10f1ddd1 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilListSingularizer.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 The Project Lombok Authors. + * Copyright (C) 2015-2021 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 @@ -24,15 +24,13 @@ package lombok.javac.handlers.singulars; import static lombok.javac.Javac.*; import static lombok.javac.handlers.JavacHandlerUtil.*; -import org.mangosdk.spi.ProviderFor; - import lombok.core.LombokImmutableList; import lombok.javac.JavacNode; import lombok.javac.JavacTreeMaker; import lombok.javac.handlers.JavacSingularsRecipes.JavacSingularizer; import lombok.javac.handlers.JavacSingularsRecipes.SingularData; +import lombok.spi.Provides; -import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCCase; import com.sun.tools.javac.tree.JCTree.JCExpression; import com.sun.tools.javac.tree.JCTree.JCStatement; @@ -40,7 +38,7 @@ import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.ListBuffer; import com.sun.tools.javac.util.Name; -@ProviderFor(JavacSingularizer.class) +@Provides(JavacSingularizer.class) public class JavacJavaUtilListSingularizer extends JavacJavaUtilListSetSingularizer { @Override public LombokImmutableList<String> getSupportedTypes() { return LombokImmutableList.of("java.util.List", "java.util.Collection", "java.lang.Iterable"); @@ -50,7 +48,7 @@ public class JavacJavaUtilListSingularizer extends JavacJavaUtilListSetSingulari return "java.util.Collections.emptyList"; } - @Override public void appendBuildCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer<JCStatement> statements, Name targetVariableName, String builderVariable) { + @Override public void appendBuildCode(SingularData data, JavacNode builderType, JavacNode source, ListBuffer<JCStatement> statements, Name targetVariableName, String builderVariable) { JavacTreeMaker maker = builderType.getTreeMaker(); List<JCExpression> jceBlank = List.nil(); ListBuffer<JCCase> cases = new ListBuffer<JCCase>(); @@ -94,7 +92,7 @@ public class JavacJavaUtilListSingularizer extends JavacJavaUtilListSetSingulari statements.append(switchStat); } - private List<JCStatement> createListCopy(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source, String builderVariable) { + private List<JCStatement> createListCopy(JavacTreeMaker maker, SingularData data, JavacNode builderType, JavacNode source, String builderVariable) { List<JCExpression> jceBlank = List.nil(); Name thisName = builderType.toName(builderVariable); diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java index 8dc7ecff..b8c931c7 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilMapSingularizer.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015-2019 The Project Lombok Authors. + * Copyright (C) 2015-2021 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 @@ -36,11 +36,9 @@ import lombok.javac.handlers.JavacSingularsRecipes.ExpressionMaker; import lombok.javac.handlers.JavacSingularsRecipes.JavacSingularizer; import lombok.javac.handlers.JavacSingularsRecipes.SingularData; import lombok.javac.handlers.JavacSingularsRecipes.StatementMaker; - -import org.mangosdk.spi.ProviderFor; +import lombok.spi.Provides; import com.sun.tools.javac.code.Flags; -import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCBlock; import com.sun.tools.javac.tree.JCTree.JCExpression; import com.sun.tools.javac.tree.JCTree.JCStatement; @@ -49,7 +47,7 @@ import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.ListBuffer; import com.sun.tools.javac.util.Name; -@ProviderFor(JavacSingularizer.class) +@Provides(JavacSingularizer.class) public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { @Override public LombokImmutableList<String> getSupportedTypes() { return LombokImmutableList.of("java.util.Map", "java.util.SortedMap", "java.util.NavigableMap"); @@ -74,7 +72,7 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { return super.listMethodsToBeGenerated(data, builderType); } - @Override public java.util.List<JavacNode> generateFields(SingularData data, JavacNode builderType, JCTree source) { + @Override public java.util.List<JavacNode> generateFields(SingularData data, JavacNode builderType, JavacNode source) { JavacTreeMaker maker = builderType.getTreeMaker(); JCVariableDecl buildKeyField; { @@ -98,7 +96,7 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { return Arrays.asList(keyFieldNode, valueFieldNode); } - @Override public void generateMethods(CheckerFrameworkVersion cfv, SingularData data, boolean deprecate, JavacNode builderType, JCTree source, boolean fluent, ExpressionMaker returnTypeMaker, StatementMaker returnStatementMaker, AccessLevel access) { + @Override public void generateMethods(CheckerFrameworkVersion cfv, SingularData data, boolean deprecate, JavacNode builderType, JavacNode source, boolean fluent, ExpressionMaker returnTypeMaker, StatementMaker returnStatementMaker, AccessLevel access) { doGenerateMethods(cfv, data, deprecate, builderType, source, fluent, returnTypeMaker, returnStatementMaker, access); } @@ -117,7 +115,7 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { } @Override - protected ListBuffer<JCStatement> generateSingularMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { + protected ListBuffer<JCStatement> generateSingularMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JavacNode source) { Name keyName = builderType.toName(data.getSingularName().toString() + "Key"); Name valueName = builderType.toName(data.getSingularName().toString() + "Value"); @@ -130,7 +128,7 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { } @Override - protected List<JCVariableDecl> generateSingularMethodParameters(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { + protected List<JCVariableDecl> generateSingularMethodParameters(JavacTreeMaker maker, SingularData data, JavacNode builderType, JavacNode source) { Name keyName = builderType.toName(data.getSingularName().toString() + "Key"); Name valueName = builderType.toName(data.getSingularName().toString() + "Value"); JCVariableDecl paramKey = generateSingularMethodParameter(0, maker, data, builderType, source, keyName); @@ -139,7 +137,7 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { } @Override - protected ListBuffer<JCStatement> generatePluralMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { + protected ListBuffer<JCStatement> generatePluralMethodStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, JavacNode source) { List<JCExpression> jceBlank = List.nil(); ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>(); long baseFlags = JavacHandlerUtil.addFinalIfNeeded(0, builderType.getContext()); @@ -164,11 +162,11 @@ public class JavacJavaUtilMapSingularizer extends JavacJavaUtilSingularizer { } @Override - protected JCStatement createConstructBuilderVarIfNeeded(JavacTreeMaker maker, SingularData data, JavacNode builderType, JCTree source) { + protected JCStatement createConstructBuilderVarIfNeeded(JavacTreeMaker maker, SingularData data, JavacNode builderType, JavacNode source) { return createConstructBuilderVarIfNeeded(maker, data, builderType, true, source); } - @Override public void appendBuildCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer<JCStatement> statements, Name targetVariableName, String builderVariable) { + @Override public void appendBuildCode(SingularData data, JavacNode builderType, JavacNode source, ListBuffer<JCStatement> statements, Name targetVariableName, String builderVariable) { JavacTreeMaker maker = builderType.getTreeMaker(); if (data.getTargetFqn().equals("java.util.Map")) { diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilSetSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilSetSingularizer.java index 7c870c0a..6d2e0655 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilSetSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilSetSingularizer.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 The Project Lombok Authors. + * Copyright (C) 2015-2021 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 @@ -21,20 +21,18 @@ */ package lombok.javac.handlers.singulars; -import org.mangosdk.spi.ProviderFor; - import lombok.core.LombokImmutableList; import lombok.javac.JavacNode; import lombok.javac.JavacTreeMaker; import lombok.javac.handlers.JavacSingularsRecipes.JavacSingularizer; import lombok.javac.handlers.JavacSingularsRecipes.SingularData; +import lombok.spi.Provides; -import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCStatement; import com.sun.tools.javac.util.ListBuffer; import com.sun.tools.javac.util.Name; -@ProviderFor(JavacSingularizer.class) +@Provides(JavacSingularizer.class) public class JavacJavaUtilSetSingularizer extends JavacJavaUtilListSetSingularizer { @Override public LombokImmutableList<String> getSupportedTypes() { return LombokImmutableList.of("java.util.Set", "java.util.SortedSet", "java.util.NavigableSet"); @@ -46,7 +44,7 @@ public class JavacJavaUtilSetSingularizer extends JavacJavaUtilListSetSingulariz return "java.util.Collections.emptySet"; } - @Override public void appendBuildCode(SingularData data, JavacNode builderType, JCTree source, ListBuffer<JCStatement> statements, Name targetVariableName, String builderVariable) { + @Override public void appendBuildCode(SingularData data, JavacNode builderType, JavacNode source, ListBuffer<JCStatement> statements, Name targetVariableName, String builderVariable) { JavacTreeMaker maker = builderType.getTreeMaker(); if (data.getTargetFqn().equals("java.util.Set")) { diff --git a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilSingularizer.java b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilSingularizer.java index 5670b5e6..3b6113df 100644 --- a/src/core/lombok/javac/handlers/singulars/JavacJavaUtilSingularizer.java +++ b/src/core/lombok/javac/handlers/singulars/JavacJavaUtilSingularizer.java @@ -24,7 +24,6 @@ package lombok.javac.handlers.singulars; import static lombok.javac.Javac.*; import static lombok.javac.handlers.JavacHandlerUtil.*; -import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCCase; import com.sun.tools.javac.tree.JCTree.JCExpression; import com.sun.tools.javac.tree.JCTree.JCStatement; @@ -38,7 +37,7 @@ import lombok.javac.handlers.JavacSingularsRecipes.JavacSingularizer; import lombok.javac.handlers.JavacSingularsRecipes.SingularData; abstract class JavacJavaUtilSingularizer extends JavacSingularizer { - protected List<JCStatement> createJavaUtilSetMapInitialCapacitySwitchStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, boolean mapMode, String emptyCollectionMethod, String singletonCollectionMethod, String targetType, JCTree source, String builderVariable) { + protected List<JCStatement> createJavaUtilSetMapInitialCapacitySwitchStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, boolean mapMode, String emptyCollectionMethod, String singletonCollectionMethod, String targetType, JavacNode source, String builderVariable) { List<JCExpression> jceBlank = List.nil(); ListBuffer<JCCase> cases = new ListBuffer<JCCase>(); @@ -88,9 +87,9 @@ abstract class JavacJavaUtilSingularizer extends JavacSingularizer { return List.of(varDefStat, switchStat); } - protected JCStatement createConstructBuilderVarIfNeeded(JavacTreeMaker maker, SingularData data, JavacNode builderType, boolean mapMode, JCTree source) { + protected JCStatement createConstructBuilderVarIfNeeded(JavacTreeMaker maker, SingularData data, JavacNode builderType, boolean mapMode, JavacNode source) { List<JCExpression> jceBlank = List.nil(); - + Name v1Name = mapMode ? builderType.toName(data.getPluralName() + "$key") : data.getPluralName(); Name v2Name = mapMode ? builderType.toName(data.getPluralName() + "$value") : null; JCExpression thisDotField = maker.Select(maker.Ident(builderType.toName("this")), v1Name); @@ -117,7 +116,7 @@ abstract class JavacJavaUtilSingularizer extends JavacSingularizer { return maker.If(cond, thenPart, null); } - protected List<JCStatement> createJavaUtilSimpleCreationAndFillStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, boolean mapMode, boolean defineVar, boolean addInitialCapacityArg, boolean nullGuard, String targetType, JCTree source, String builderVariable) { + protected List<JCStatement> createJavaUtilSimpleCreationAndFillStatements(JavacTreeMaker maker, SingularData data, JavacNode builderType, boolean mapMode, boolean defineVar, boolean addInitialCapacityArg, boolean nullGuard, String targetType, JavacNode source, String builderVariable) { List<JCExpression> jceBlank = List.nil(); Name thisName = builderType.toName(builderVariable); diff --git a/src/delombok/lombok/delombok/Delombok.java b/src/delombok/lombok/delombok/Delombok.java index 6b745015..8d39f447 100755 --- a/src/delombok/lombok/delombok/Delombok.java +++ b/src/delombok/lombok/delombok/Delombok.java @@ -43,6 +43,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.IdentityHashMap; import java.util.LinkedHashMap; import java.util.List; @@ -51,6 +52,7 @@ import java.util.Map; import java.util.Set; import java.util.regex.Pattern; +import javax.annotation.processing.AbstractProcessor; import javax.tools.DiagnosticListener; import javax.tools.JavaFileManager; import javax.tools.JavaFileObject; @@ -58,6 +60,7 @@ import javax.tools.JavaFileObject; import lombok.Lombok; import lombok.javac.CommentCatcher; import lombok.javac.Javac; +import lombok.javac.JavacAugments; import lombok.javac.LombokOptions; import lombok.javac.apt.LombokProcessor; import lombok.permit.Permit; @@ -67,8 +70,11 @@ import com.sun.tools.javac.comp.Todo; import com.sun.tools.javac.file.BaseFileManager; import com.sun.tools.javac.main.Arguments; import com.sun.tools.javac.main.JavaCompiler; +import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; +import com.sun.tools.javac.tree.JCTree.JCImport; import com.sun.tools.javac.util.Context; +import com.sun.tools.javac.util.ListBuffer; import com.zwitserloot.cmdreader.CmdReader; import com.zwitserloot.cmdreader.Description; import com.zwitserloot.cmdreader.Excludes; @@ -97,6 +103,7 @@ public class Delombok { private LinkedHashMap<File, File> fileToBase = new LinkedHashMap<File, File>(); private List<File> filesToParse = new ArrayList<File>(); private Map<String, String> formatPrefs = new HashMap<String, String>(); + private List<AbstractProcessor> additionalAnnotationProcessors = new ArrayList<AbstractProcessor>(); /** If null, output to standard out. */ private File output = null; @@ -165,6 +172,10 @@ public class Delombok { private boolean help; } + static { + LombokProcessor.addOpensForLombok(); + } + private static String indentAndWordbreak(String in, int indent, int maxLen) { StringBuilder out = new StringBuilder(); StringBuilder line = new StringBuilder(); @@ -642,6 +653,10 @@ public class Delombok { fileToBase.put(f, base); } + public void addAdditionalAnnotationProcessor(AbstractProcessor processor) { + additionalAnnotationProcessors.add(processor); + } + private static <T> com.sun.tools.javac.util.List<T> toJavacList(List<T> list) { com.sun.tools.javac.util.List<T> out = com.sun.tools.javac.util.List.nil(); ListIterator<T> li = list.listIterator(list.size()); @@ -718,7 +733,9 @@ public class Delombok { List<JCCompilationUnit> roots = new ArrayList<JCCompilationUnit>(); Map<JCCompilationUnit, File> baseMap = new IdentityHashMap<JCCompilationUnit, File>(); - Set<LombokProcessor> processors = Collections.singleton(new lombok.javac.apt.LombokProcessor()); + Set<AbstractProcessor> processors = new HashSet<AbstractProcessor>(); + processors.add(new lombok.javac.apt.LombokProcessor()); + processors.addAll(additionalAnnotationProcessors); if (Javac.getJavaCompilerVersion() >= 9) { JavaFileManager jfm_ = context.get(JavaFileManager.class); @@ -782,6 +799,16 @@ public class Delombok { if (verbose) feedback.printf("File: %s [%s]\n", unit.sourcefile.getName(), "unchanged (skipped)"); continue; } + ListBuffer<JCTree> newDefs = new ListBuffer<JCTree>(); + for (JCTree def : unit.defs) { + if (def instanceof JCImport) { + Boolean b = JavacAugments.JCImport_deletable.get((JCImport) def); + if (b == null || !b.booleanValue()) newDefs.append(def); + } else { + newDefs.append(def); + } + } + unit.defs = newDefs.toList(); if (verbose) feedback.printf("File: %s [%s%s]\n", unit.sourcefile.getName(), result.isChanged() ? "delomboked" : "unchanged", force && !options.isChanged(unit) ? " (forced)" : ""); Writer rawWriter; if (presetWriter != null) rawWriter = createUnicodeEscapeWriter(presetWriter); diff --git a/src/delombok/lombok/delombok/DelombokApp.java b/src/delombok/lombok/delombok/DelombokApp.java index 8467bf77..f5a5fc81 100644 --- a/src/delombok/lombok/delombok/DelombokApp.java +++ b/src/delombok/lombok/delombok/DelombokApp.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -37,10 +37,9 @@ import java.util.jar.JarFile; import lombok.core.LombokApp; import lombok.permit.Permit; +import lombok.spi.Provides; -import org.mangosdk.spi.ProviderFor; - -@ProviderFor(LombokApp.class) +@Provides public class DelombokApp extends LombokApp { @Override public int runApp(List<String> args) throws Exception { try { diff --git a/src/delombok/lombok/delombok/DocCommentIntegrator.java b/src/delombok/lombok/delombok/DocCommentIntegrator.java index bab0abd8..e61968a5 100644 --- a/src/delombok/lombok/delombok/DocCommentIntegrator.java +++ b/src/delombok/lombok/delombok/DocCommentIntegrator.java @@ -89,7 +89,7 @@ public class DocCommentIntegrator { ((Map<JCTree, String>) map_).put(node, docCommentContent); return true; } else if (Javac.instanceOfDocCommentTable(map_)) { - CommentAttacher_8.attach(node, docCommentContent, map_); + CommentAttacher_8.attach(node, docCommentContent, cmt.pos, map_); return true; } @@ -98,7 +98,7 @@ public class DocCommentIntegrator { /* Container for code which will cause class loader exceptions on javac below 8. By being in a separate class, we avoid the problem. */ private static class CommentAttacher_8 { - static void attach(final JCTree node, String docCommentContent, Object map_) { + static void attach(final JCTree node, String docCommentContent, final int pos, Object map_) { final String docCommentContent_ = docCommentContent; ((DocCommentTable) map_).putComment(node, new Comment() { @Override public String getText() { @@ -106,7 +106,7 @@ public class DocCommentIntegrator { } @Override public int getSourcePos(int index) { - return -1; + return pos + index; } @Override public CommentStyle getStyle() { diff --git a/src/delombok/lombok/delombok/PrettyPrinter.java b/src/delombok/lombok/delombok/PrettyPrinter.java index 9f47e5ec..c46a3298 100644 --- a/src/delombok/lombok/delombok/PrettyPrinter.java +++ b/src/delombok/lombok/delombok/PrettyPrinter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016-2020 The Project Lombok Authors. + * Copyright (C) 2016-2021 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 @@ -29,7 +29,6 @@ import static lombok.javac.JavacTreeMaker.TypeTag.typeTag; import java.io.IOException; import java.io.Writer; import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Arrays; import java.util.HashMap; @@ -279,7 +278,6 @@ public class PrettyPrinter extends JCTree.Visitor { aligned = false; } - private void println() { try { out.write(LINE_SEP); @@ -516,10 +514,12 @@ public class PrettyPrinter extends JCTree.Visitor { boolean isInterface = (tree.mods.flags & INTERFACE) != 0; boolean isAnnotationInterface = isInterface && (tree.mods.flags & ANNOTATION) != 0; boolean isEnum = (tree.mods.flags & ENUM) != 0; + boolean isRecord = (tree.mods.flags & RECORD) != 0; if (isAnnotationInterface) print("@interface "); else if (isInterface) print("interface "); else if (isEnum) print("enum "); + else if (isRecord) print("record "); else print("class "); print(tree.name); @@ -542,6 +542,8 @@ public class PrettyPrinter extends JCTree.Visitor { print(tree.implementing, ", "); } + if (isRecord) printRecordConstructor(tree.defs); + println(" {"); indent++; printClassMembers(tree.defs, isEnum, isInterface); @@ -551,6 +553,23 @@ public class PrettyPrinter extends JCTree.Visitor { currentTypeName = prevTypeName; } + private void printRecordConstructor(List<JCTree> members) { + boolean first = true; + print("("); + for (JCTree member : members) { + if (member instanceof JCVariableDecl) { + JCVariableDecl variableDecl = (JCVariableDecl) member; + if ((variableDecl.mods.flags & GENERATED_MEMBER) != 0) { + if (!first) print(", "); + first = false; + printAnnotations(variableDecl.mods.annotations, false); + printVarDef0(variableDecl); + } + } + } + print(")"); + } + private void printClassMembers(List<JCTree> members, boolean isEnum, boolean isInterface) { Class<?> prefType = null; int typeOfPrevEnumMember = isEnum ? 3 : 0; // 1 = normal, 2 = with body, 3 = no enum field yet. @@ -580,6 +599,7 @@ public class PrettyPrinter extends JCTree.Visitor { JCTree init = ((JCVariableDecl) member).init; typeOfPrevEnumMember = init instanceof JCNewClass && ((JCNewClass) init).def != null ? 2 : 1; } else if (member instanceof JCVariableDecl) { + if ((((JCVariableDecl) member).mods.flags & GENERATED_MEMBER) != 0) continue; if (prefType != null && prefType != JCVariableDecl.class) println(); if (isInterface) flagMod = -1L & ~(PUBLIC | STATIC | FINAL); print(member); @@ -792,21 +812,28 @@ public class PrettyPrinter extends JCTree.Visitor { print(tree.name); } - boolean first = true; - print("("); - - JCVariableDecl recvparam = readObject(tree, "recvparam", null); - if (recvparam != null) { - printVarDefInline(recvparam); - first = false; + boolean argsLessConstructor = false; + if (isConstructor && (tree.mods.flags & COMPACT_RECORD_CONSTRUCTOR) != 0) { + argsLessConstructor = true; } - for (JCVariableDecl param : tree.params) { - if (!first) print(", "); - first = false; - printVarDefInline(param); + boolean first = true; + if (!argsLessConstructor) { + print("("); + + JCVariableDecl recvparam = readObject(tree, "recvparam", null); + if (recvparam != null) { + printVarDefInline(recvparam); + first = false; + } + + for (JCVariableDecl param : tree.params) { + if (!first) print(", "); + first = false; + printVarDefInline(param); + } + print(")"); } - print(")"); if (tree.thrown.nonEmpty()) { print(" throws "); @@ -1387,9 +1414,10 @@ public class PrettyPrinter extends JCTree.Visitor { } void printBindingPattern(JCTree tree) { - print((JCExpression) readObject(tree, "vartype", null)); + JCTree var = readObject(tree, "var", tree); + print((JCExpression) readObject(var, "vartype", null)); print(" "); - print((Name) readObject(tree, "name", null)); + print((Name) readObject(var, "name", null)); } @Override public void visitTry(JCTry tree) { diff --git a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java index 488d6eee..ce26c892 100644 --- a/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java +++ b/src/eclipseAgent/lombok/eclipse/agent/EclipsePatcher.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2020 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -697,13 +697,13 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { .decisionMethod(new Hook("lombok.launch.PatchFixesHider$Delegate", "handleDelegateForType", "boolean", "java.lang.Object")) .build()); - sm.addScript(ScriptBuilder.setSymbolDuringMethodCall() + sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.setSymbolDuringMethodCall() .target(new MethodTarget("org.eclipse.jdt.internal.core.SelectionRequestor", "acceptSourceMethod")) .callToWrap(new Hook("org.eclipse.jdt.core.IType", "getMethods", "org.eclipse.jdt.core.IMethod[]")) .symbol("lombok.skipdelegates") .build()); - sm.addScript(ScriptBuilder.addField() + sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.addField() .fieldName("$delegateMethods") .fieldType("Ljava/util/Map;") .setPublic() @@ -711,10 +711,10 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { .targetClass("org.eclipse.jdt.internal.core.CompilationUnit") .build()); - sm.addScript(ScriptBuilder.wrapReturnValue() + sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.wrapReturnValue() .target(new MethodTarget("org.eclipse.jdt.internal.core.SourceTypeElementInfo", "getChildren", "org.eclipse.jdt.core.IJavaElement[]")) .request(StackRequest.RETURN_VALUE, StackRequest.THIS) - .wrapMethod(new Hook("lombok.launch.PatchFixesHider$Delegate", "getChildren", "java.lang.Object[]", "java.lang.Object", "java.lang.Object")) + .wrapMethod(new Hook("lombok.launch.PatchFixesHider$Delegate", "addGeneratedDelegateMethods", "java.lang.Object[]", "java.lang.Object", "java.lang.Object")) .build()); } @@ -772,11 +772,12 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { final String EXPRESSION_SIG = "org.eclipse.jdt.internal.compiler.ast.Expression"; final String BLOCKSCOPE_SIG = "org.eclipse.jdt.internal.compiler.lookup.BlockScope"; final String TYPEBINDING_SIG = "org.eclipse.jdt.internal.compiler.lookup.TypeBinding"; + final String OBJECT_SIG = "java.lang.Object"; sm.addScript(ScriptBuilder.exitEarly() .target(new MethodTarget(LOCALDECLARATION_SIG, "resolve", "void", BLOCKSCOPE_SIG)) .request(StackRequest.THIS, StackRequest.PARAM1) - .decisionMethod(new Hook("lombok.launch.PatchFixesHider$Val", "handleValForLocalDeclaration", "boolean", LOCALDECLARATION_SIG, BLOCKSCOPE_SIG)) + .decisionMethod(new Hook("lombok.launch.PatchFixesHider$Val", "handleValForLocalDeclaration", "boolean", OBJECT_SIG, OBJECT_SIG)) .build()); sm.addScript(ScriptBuilder.replaceMethodCall() @@ -784,18 +785,20 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { .methodToReplace(new Hook(EXPRESSION_SIG, "resolveType", TYPEBINDING_SIG, BLOCKSCOPE_SIG)) .requestExtra(StackRequest.THIS) .replacementMethod(new Hook("lombok.launch.PatchFixesHider$Val", "skipResolveInitializerIfAlreadyCalled2", TYPEBINDING_SIG, EXPRESSION_SIG, BLOCKSCOPE_SIG, LOCALDECLARATION_SIG)) + .transplant() .build()); sm.addScript(ScriptBuilder.replaceMethodCall() .target(new MethodTarget(FOREACHSTATEMENT_SIG, "resolve", "void", BLOCKSCOPE_SIG)) .methodToReplace(new Hook(EXPRESSION_SIG, "resolveType", TYPEBINDING_SIG, BLOCKSCOPE_SIG)) .replacementMethod(new Hook("lombok.launch.PatchFixesHider$Val", "skipResolveInitializerIfAlreadyCalled", TYPEBINDING_SIG, EXPRESSION_SIG, BLOCKSCOPE_SIG)) + .transplant() .build()); sm.addScript(ScriptBuilder.exitEarly() .target(new MethodTarget(FOREACHSTATEMENT_SIG, "resolve", "void", BLOCKSCOPE_SIG)) .request(StackRequest.THIS, StackRequest.PARAM1) - .decisionMethod(new Hook("lombok.launch.PatchFixesHider$Val", "handleValForForEach", "boolean", FOREACHSTATEMENT_SIG, BLOCKSCOPE_SIG)) + .decisionMethod(new Hook("lombok.launch.PatchFixesHider$Val", "handleValForForEach", "boolean", OBJECT_SIG, OBJECT_SIG)) .build()); } @@ -843,33 +846,33 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable { .request(StackRequest.RETURN_VALUE) .request(StackRequest.THIS) .request(StackRequest.PARAM1) - .wrapMethod(new Hook(PATCH_EXTENSIONMETHOD, "resolveType", OBJECT_SIG, OBJECT_SIG, MESSAGE_SEND_SIG, BLOCK_SCOPE_SIG)) + .wrapMethod(new Hook(PATCH_EXTENSIONMETHOD, "resolveType", OBJECT_SIG, OBJECT_SIG, OBJECT_SIG, OBJECT_SIG)) .cast() .build()); sm.addScript(replaceMethodCall() .target(new MethodTarget(MESSAGE_SEND_SIG, "resolveType", TYPE_BINDING_SIG, BLOCK_SCOPE_SIG)) .methodToReplace(new Hook(PROBLEM_REPORTER_SIG, "errorNoMethodFor", "void", MESSAGE_SEND_SIG, TYPE_BINDING_SIG, TYPE_BINDINGS_SIG)) - .replacementMethod(new Hook(PATCH_EXTENSIONMETHOD, "errorNoMethodFor", "void", PROBLEM_REPORTER_SIG, MESSAGE_SEND_SIG, TYPE_BINDING_SIG, TYPE_BINDINGS_SIG)) + .replacementMethod(new Hook(PATCH_EXTENSIONMETHOD, "errorNoMethodFor", "void", OBJECT_SIG, OBJECT_SIG, OBJECT_SIG, OBJECT_SIG)) .build()); sm.addScript(replaceMethodCall() .target(new MethodTarget(MESSAGE_SEND_SIG, "resolveType", TYPE_BINDING_SIG, BLOCK_SCOPE_SIG)) .methodToReplace(new Hook(PROBLEM_REPORTER_SIG, "invalidMethod", "void", MESSAGE_SEND_SIG, METHOD_BINDING_SIG)) - .replacementMethod(new Hook(PATCH_EXTENSIONMETHOD, "invalidMethod", "void", PROBLEM_REPORTER_SIG, MESSAGE_SEND_SIG, METHOD_BINDING_SIG)) + .replacementMethod(new Hook(PATCH_EXTENSIONMETHOD, "invalidMethod", "void", OBJECT_SIG, OBJECT_SIG, OBJECT_SIG)) .build()); // Since eclipse mars; they added a param. sm.addScript(replaceMethodCall() .target(new MethodTarget(MESSAGE_SEND_SIG, "resolveType", TYPE_BINDING_SIG, BLOCK_SCOPE_SIG)) .methodToReplace(new Hook(PROBLEM_REPORTER_SIG, "invalidMethod", "void", MESSAGE_SEND_SIG, METHOD_BINDING_SIG, SCOPE_SIG)) - .replacementMethod(new Hook(PATCH_EXTENSIONMETHOD, "invalidMethod", "void", PROBLEM_REPORTER_SIG, MESSAGE_SEND_SIG, METHOD_BINDING_SIG, SCOPE_SIG)) + .replacementMethod(new Hook(PATCH_EXTENSIONMETHOD, "invalidMethod", "void", OBJECT_SIG, OBJECT_SIG, OBJECT_SIG, OBJECT_SIG)) .build()); sm.addScript(replaceMethodCall() .target(new MethodTarget(MESSAGE_SEND_SIG, "resolveType", TYPE_BINDING_SIG, BLOCK_SCOPE_SIG)) .methodToReplace(new Hook(PROBLEM_REPORTER_SIG, "nonStaticAccessToStaticMethod", "void", AST_NODE, METHOD_BINDING_SIG)) - .replacementMethod(new Hook(PATCH_EXTENSIONMETHOD, "nonStaticAccessToStaticMethod", "void", PROBLEM_REPORTER_SIG, AST_NODE, METHOD_BINDING_SIG, MESSAGE_SEND_SIG)) + .replacementMethod(new Hook(PATCH_EXTENSIONMETHOD, "nonStaticAccessToStaticMethod", "void", OBJECT_SIG, OBJECT_SIG, OBJECT_SIG, OBJECT_SIG)) .requestExtra(StackRequest.THIS) .build()); diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchDelegate.java b/src/eclipseAgent/lombok/eclipse/agent/PatchDelegate.java index 99367a22..d7b17598 100644 --- a/src/eclipseAgent/lombok/eclipse/agent/PatchDelegate.java +++ b/src/eclipseAgent/lombok/eclipse/agent/PatchDelegate.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2020 The Project Lombok Authors. + * Copyright (C) 2010-2021 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 @@ -148,7 +148,9 @@ public class PatchDelegate { CompilationUnitDeclaration cud = scope.compilationUnitScope().referenceContext; if (scope == scope.compilationUnitScope().topLevelTypes[0].scope) { - cleanupDelegateMethods(cud); + if (eclipseAvailable) { + EclipseOnlyMethods.cleanupDelegateMethods(cud); + } } if (!hasDelegateMarkedFieldsOrMethods(scope.referenceContext)) return false; @@ -195,8 +197,8 @@ public class PatchDelegate { } } finally { stack.remove(stack.size() - 1); - if (stack.isEmpty()) { - notifyDelegateMethodsAdded(cud); + if (stack.isEmpty() && eclipseAvailable) { + EclipseOnlyMethods.notifyDelegateMethodsAdded(cud); } } } @@ -204,16 +206,6 @@ public class PatchDelegate { return false; } - public static IJavaElement[] getChildren(IJavaElement[] returnValue, SourceTypeElementInfo javaElement) { - if (Symbols.hasSymbol("lombok.skipdelegates")) return returnValue; - - List<SourceMethod> delegateMethods = getDelegateMethods((SourceType) javaElement.getHandle()); - if (delegateMethods != null) { - return concat(returnValue, delegateMethods.toArray(new IJavaElement[0]), IJavaElement.class); - } - return returnValue; - } - /** * Returns a string containing the signature of a method that appears (erased) at least twice in the list. * If no duplicates are present, {@code null} is returned. @@ -459,11 +451,7 @@ public class PatchDelegate { private static void generateDelegateMethods(EclipseNode typeNode, List<BindingTuple> methods, DelegateReceiver delegateReceiver) { CompilationUnitDeclaration top = (CompilationUnitDeclaration) typeNode.top().get(); - - String qualifiedName = new String(CharOperation.concatWith(getQualifiedInnerName(typeNode.up(), typeNode.getName().toCharArray()), '$')); - SourceType sourceType = getSourceType(top, qualifiedName); - List<SourceMethod> delegateSourceMethods = getDelegateMethods(sourceType); - + List<MethodDeclaration> addedMethods = new ArrayList<MethodDeclaration>(); for (BindingTuple pair : methods) { EclipseNode annNode = typeNode.getAst().get(pair.responsible); MethodDeclaration method = createDelegateMethod(pair.fieldName, typeNode, pair, top.compilationResult, annNode, delegateReceiver); @@ -471,12 +459,12 @@ public class PatchDelegate { SetGeneratedByVisitor visitor = new SetGeneratedByVisitor(annNode.get()); method.traverse(visitor, ((TypeDeclaration)typeNode.get()).scope); injectMethod(typeNode, method); - - if (delegateSourceMethods != null) { - delegateSourceMethods.add(DelegateSourceMethod.forMethodDeclaration(sourceType, method)); - } + addedMethods.add(method); } } + if (eclipseAvailable) { + EclipseOnlyMethods.collectGeneratedDelegateMethods(top, typeNode, addedMethods); + } } public static void checkConflictOfTypeVarNames(BindingTuple binding, EclipseNode typeNode) throws CantMakeDelegates { @@ -722,127 +710,159 @@ public class PatchDelegate { return method; } - private static void cleanupDelegateMethods(CompilationUnitDeclaration cud) { - CompilationUnit compilationUnit = getCompilationUnit(cud); - if (compilationUnit != null) { - EclipseAugments.CompilationUnit_delegateMethods.clear(compilationUnit); + private static boolean eclipseAvailable = true; + static { + try { + CompilationUnit.class.getName(); + } catch (Throwable t) { + eclipseAvailable = false; } } - private static boolean javaModelManagerAvailable = true; - private static void notifyDelegateMethodsAdded(CompilationUnitDeclaration cud) { - CompilationUnit compilationUnit = getCompilationUnit(cud); - if (compilationUnit != null && javaModelManagerAvailable) { - try { - DeltaProcessor deltaProcessor = JavaModelManager.getJavaModelManager().getDeltaProcessor(); - deltaProcessor.fire(new JavaElementDelta(compilationUnit), ElementChangedEvent.POST_CHANGE); - } catch (NoClassDefFoundError e) { - javaModelManagerAvailable = false; - } - } + public static Object[] addGeneratedDelegateMethods(Object[] returnValue, Object javaElement) { + if (Symbols.hasSymbol("lombok.skipdelegates")) return returnValue; + if (!eclipseAvailable) return returnValue; + + return EclipseOnlyMethods.addGeneratedDelegateMethodsToChildren(returnValue, javaElement); } - private static CompilationUnit getCompilationUnit(Object iCompilationUnit) { - if (iCompilationUnit instanceof CompilationUnit) { - CompilationUnit compilationUnit = (CompilationUnit) iCompilationUnit; - return compilationUnit.originalFromClone(); + public static class EclipseOnlyMethods { + private static void cleanupDelegateMethods(CompilationUnitDeclaration cud) { + CompilationUnit compilationUnit = getCompilationUnit(cud); + if (compilationUnit != null) { + EclipseAugments.CompilationUnit_delegateMethods.clear(compilationUnit); + } } - return null; - } - - private static CompilationUnit getCompilationUnit(CompilationUnitDeclaration cud) { - return getCompilationUnit(cud.compilationResult.compilationUnit); - } - - private static final class DelegateSourceMethod extends SourceMethod { - private DelegateSourceMethodInfo sourceMethodInfo; - private static DelegateSourceMethod forMethodDeclaration(JavaElement parent, MethodDeclaration method) { - Argument[] arguments = method.arguments != null ? method.arguments : new Argument[0]; - String[] parameterTypes = new String[arguments.length]; - for (int i = 0; i < arguments.length; i++) { - parameterTypes[i] = Signature.createTypeSignature(CharOperation.concatWith(arguments[i].type.getParameterizedTypeName(), '.'), false); + public static void collectGeneratedDelegateMethods(CompilationUnitDeclaration top, EclipseNode typeNode, List<MethodDeclaration> addedMethods) { + String qualifiedName = new String(CharOperation.concatWith(getQualifiedInnerName(typeNode.up(), typeNode.getName().toCharArray()), '$')); + SourceType sourceType = getSourceType(top, qualifiedName); + List<SourceMethod> generatedMethods = getGeneratedMethods(sourceType); + if (generatedMethods == null) return; + + for (MethodDeclaration md : addedMethods) { + generatedMethods.add(DelegateSourceMethod.forMethodDeclaration(sourceType, md)); } - return new DelegateSourceMethod(parent, new String(method.selector), parameterTypes, method); } - private DelegateSourceMethod(JavaElement parent, String name, String[] parameterTypes, MethodDeclaration md) { - super(parent, name, parameterTypes); - sourceMethodInfo = new DelegateSourceMethodInfo(this, md); + public static Object[] addGeneratedDelegateMethodsToChildren(Object[] returnValue, Object javaElement) { + List<SourceMethod> delegateMethods = getGeneratedMethods((SourceType) ((SourceTypeElementInfo) javaElement).getHandle()); + if (delegateMethods != null) { + return concat((IJavaElement[]) returnValue, delegateMethods.toArray(new IJavaElement[0]), IJavaElement.class); + } + return returnValue; } - @Override public Object getElementInfo() throws JavaModelException { - return sourceMethodInfo; + private static void notifyDelegateMethodsAdded(CompilationUnitDeclaration cud) { + CompilationUnit compilationUnit = getCompilationUnit(cud); + if (compilationUnit != null) { + DeltaProcessor deltaProcessor = JavaModelManager.getJavaModelManager().getDeltaProcessor(); + deltaProcessor.fire(new JavaElementDelta(compilationUnit), ElementChangedEvent.POST_CHANGE); + } } - /** - * Disable refactoring for delegate methods - */ - @Override public boolean isReadOnly() { - return true; + private static CompilationUnit getCompilationUnit(Object iCompilationUnit) { + if (iCompilationUnit instanceof CompilationUnit) { + CompilationUnit compilationUnit = (CompilationUnit) iCompilationUnit; + return compilationUnit.originalFromClone(); + } + return null; } - /** - * This is required to prevent duplicate entries in the outline - */ - @Override public boolean equals(Object o) { - return this == o; + private static CompilationUnit getCompilationUnit(CompilationUnitDeclaration cud) { + return getCompilationUnit(cud.compilationResult.compilationUnit); } - public static final class DelegateSourceMethodInfo extends SourceMethodInfo { - DelegateSourceMethodInfo(DelegateSourceMethod delegateSourceMethod, MethodDeclaration md) { - int pS = md.sourceStart; - int pE = md.sourceEnd; - - Argument[] methodArguments = md.arguments != null ? md.arguments : new Argument[0]; - char[][] argumentNames = new char[methodArguments.length][]; - arguments = new ILocalVariable[methodArguments.length]; - for (int i = 0; i < methodArguments.length; i++) { - Argument argument = methodArguments[i]; - argumentNames[i] = argument.name; - arguments[i] = new LocalVariable(delegateSourceMethod, new String(argument.name), pS, pE, pS, pS, delegateSourceMethod.getParameterTypes()[i], argument.annotations, argument.modifiers, true); + private static final class DelegateSourceMethod extends SourceMethod { + private DelegateSourceMethodInfo sourceMethodInfo; + + private static DelegateSourceMethod forMethodDeclaration(JavaElement parent, MethodDeclaration method) { + Argument[] arguments = method.arguments != null ? method.arguments : new Argument[0]; + String[] parameterTypes = new String[arguments.length]; + for (int i = 0; i < arguments.length; i++) { + parameterTypes[i] = Signature.createTypeSignature(CharOperation.concatWith(arguments[i].type.getParameterizedTypeName(), '.'), false); + } + return new DelegateSourceMethod(parent, new String(method.selector), parameterTypes, method); + } + + private DelegateSourceMethod(JavaElement parent, String name, String[] parameterTypes, MethodDeclaration md) { + super(parent, name, parameterTypes); + sourceMethodInfo = new DelegateSourceMethodInfo(this, md); + } + + @Override public Object getElementInfo() throws JavaModelException { + return sourceMethodInfo; + } + + /** + * Disable refactoring for delegate methods + */ + @Override public boolean isReadOnly() { + return true; + } + + /** + * This is required to prevent duplicate entries in the outline + */ + @Override public boolean equals(Object o) { + return this == o; + } + + public static final class DelegateSourceMethodInfo extends SourceMethodInfo { + DelegateSourceMethodInfo(DelegateSourceMethod delegateSourceMethod, MethodDeclaration md) { + int pS = md.sourceStart; + int pE = md.sourceEnd; + + Argument[] methodArguments = md.arguments != null ? md.arguments : new Argument[0]; + char[][] argumentNames = new char[methodArguments.length][]; + arguments = new ILocalVariable[methodArguments.length]; + for (int i = 0; i < methodArguments.length; i++) { + Argument argument = methodArguments[i]; + argumentNames[i] = argument.name; + arguments[i] = new LocalVariable(delegateSourceMethod, new String(argument.name), pS, pE, pS, pS, delegateSourceMethod.getParameterTypes()[i], argument.annotations, argument.modifiers, true); + } + setArgumentNames(argumentNames); + + setSourceRangeStart(pS); + setSourceRangeEnd(pE); + setNameSourceStart(pS); + setNameSourceEnd(pE); + + setExceptionTypeNames(CharOperation.NO_CHAR_CHAR); + setReturnType(md.returnType == null ? new char[]{'v', 'o','i', 'd'} : CharOperation.concatWith(md.returnType.getParameterizedTypeName(), '.')); + setFlags(md.modifiers); } - setArgumentNames(argumentNames); - - setSourceRangeStart(pS); - setSourceRangeEnd(pE); - setNameSourceStart(pS); - setNameSourceEnd(pE); - - setExceptionTypeNames(CharOperation.NO_CHAR_CHAR); - setReturnType(md.returnType == null ? new char[]{'v', 'o','i', 'd'} : CharOperation.concatWith(md.returnType.getParameterizedTypeName(), '.')); - setFlags(md.modifiers); } } - } - - private static List<SourceMethod> getDelegateMethods(SourceType sourceType) { - if (sourceType != null) { - CompilationUnit compilationUnit = getCompilationUnit(sourceType.getCompilationUnit()); - if (compilationUnit != null) { - ConcurrentMap<String, List<SourceMethod>> map = EclipseAugments.CompilationUnit_delegateMethods.setIfAbsent(compilationUnit, new ConcurrentHashMap<String, List<SourceMethod>>()); - List<SourceMethod> newList = new ArrayList<SourceMethod>(); - List<SourceMethod> oldList = map.putIfAbsent(sourceType.getTypeQualifiedName(), newList); - return oldList != null ? oldList : newList; + + private static List<SourceMethod> getGeneratedMethods(SourceType sourceType) { + if (sourceType != null) { + CompilationUnit compilationUnit = getCompilationUnit(sourceType.getCompilationUnit()); + if (compilationUnit != null) { + ConcurrentMap<String, List<SourceMethod>> map = EclipseAugments.CompilationUnit_delegateMethods.setIfAbsent(compilationUnit, new ConcurrentHashMap<String, List<SourceMethod>>()); + List<SourceMethod> newList = new ArrayList<SourceMethod>(); + List<SourceMethod> oldList = map.putIfAbsent(sourceType.getTypeQualifiedName(), newList); + return oldList != null ? oldList : newList; + } } + return null; } - return null; - } - - private static SourceType getSourceType(CompilationUnitDeclaration cud, String typeName) { - CompilationUnit compilationUnit = getCompilationUnit(cud); - if (compilationUnit != null) { - try { - for (IType type : compilationUnit.getAllTypes()) { - if (type instanceof SourceType && type.getTypeQualifiedName().equals(typeName)) { - return (SourceType) type; + + private static SourceType getSourceType(CompilationUnitDeclaration cud, String typeName) { + CompilationUnit compilationUnit = getCompilationUnit(cud); + if (compilationUnit != null) { + try { + for (IType type : compilationUnit.getAllTypes()) { + if (type instanceof SourceType && type.getTypeQualifiedName().equals(typeName)) { + return (SourceType) type; + } } + } catch (JavaModelException e) { + // Ignore } - } catch (JavaModelException e) { - // Ignore } + return null; } - return null; } private static final class Reflection { diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchDelegatePortal.java b/src/eclipseAgent/lombok/eclipse/agent/PatchDelegatePortal.java index 3d8c86c9..01e4bb18 100644 --- a/src/eclipseAgent/lombok/eclipse/agent/PatchDelegatePortal.java +++ b/src/eclipseAgent/lombok/eclipse/agent/PatchDelegatePortal.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2020 The Project Lombok Authors. + * Copyright (C) 2012-2021 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 @@ -31,34 +31,44 @@ public class PatchDelegatePortal { static final String SOURCE_TYPE_ELEMENT_INFO = "org.eclipse.jdt.internal.core.SourceTypeElementInfo"; public static boolean handleDelegateForType(Object classScope) { - Boolean v = (Boolean) Permit.invokeSneaky(Reflection.problem, Reflection.handleDelegateForType, null, classScope); + Boolean v = (Boolean) Permit.invokeSneaky(Reflection.problemHandleDelegate, Reflection.handleDelegateForType, null, classScope); if (v == null) return false; return v.booleanValue(); } - public static Object[] getChildren(Object returnValue, Object javaElement) { - return (Object[]) Permit.invokeSneaky(Reflection.problem, Reflection.getChildren, null, returnValue, javaElement); + public static Object[] addGeneratedDelegateMethods(Object returnValue, Object javaElement) { + return (Object[]) Permit.invokeSneaky(Reflection.problemAddGeneratedDelegateMethods, Reflection.addGeneratedDelegateMethods, null, returnValue, javaElement); } private static final class Reflection { public static final Method handleDelegateForType; - public static final Method getChildren; - public static final Throwable problem; + public static final Method addGeneratedDelegateMethods; + public static final Throwable problemHandleDelegate; + public static final Throwable problemAddGeneratedDelegateMethods; static { Method m = null, n = null; - Throwable problem_ = null; + Throwable problemHandleDelegate_ = null; + Throwable problemAddGeneratedDelegateMethods_ = null; try { m = Permit.getMethod(PatchDelegate.class, "handleDelegateForType", Class.forName(CLASS_SCOPE)); - n = Permit.getMethod(PatchDelegate.class, "getChildren", Class.forName(I_JAVA_ELEMENT_ARRAY), Class.forName(SOURCE_TYPE_ELEMENT_INFO)); } catch (Throwable t) { // That's problematic, but as long as no local classes are used we don't actually need it. // Better fail on local classes than crash altogether. - problem_ = t; + problemHandleDelegate_ = t; } handleDelegateForType = m; - getChildren = n; - problem = problem_; + problemHandleDelegate = problemHandleDelegate_; + + try { + n = Permit.getMethod(PatchDelegate.class, "addGeneratedDelegateMethods", Object[].class, Object.class); + } catch (Throwable t) { + // That's problematic, but as long as no local classes are used we don't actually need it. + // Better fail on local classes than crash altogether. + problemAddGeneratedDelegateMethods_ = t; + } + addGeneratedDelegateMethods = n; + problemAddGeneratedDelegateMethods = problemAddGeneratedDelegateMethods_; } } } diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java b/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java index 5f229955..2e540b5e 100644 --- a/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java +++ b/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethod.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2020 The Project Lombok Authors. + * Copyright (C) 2012-2021 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 @@ -55,6 +55,7 @@ import org.eclipse.jdt.internal.compiler.ast.SingleNameReference; import org.eclipse.jdt.internal.compiler.ast.SuperReference; import org.eclipse.jdt.internal.compiler.ast.ThisReference; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; +import org.eclipse.jdt.internal.compiler.impl.ReferenceContext; import org.eclipse.jdt.internal.compiler.lookup.Binding; import org.eclipse.jdt.internal.compiler.lookup.BlockScope; import org.eclipse.jdt.internal.compiler.lookup.MethodBinding; @@ -143,14 +144,17 @@ public class PatchExtensionMethod { private final ProblemReporter problemReporter; private ASTNode location; private MethodBinding method; + private ReferenceContext referenceContext; PostponedNonStaticAccessToStaticMethodError(ProblemReporter problemReporter, ASTNode location, MethodBinding method) { this.problemReporter = problemReporter; this.location = location; this.method = method; + this.referenceContext = problemReporter.referenceContext; } public void fire() { + problemReporter.referenceContext = this.referenceContext; problemReporter.nonStaticAccessToStaticMethod(location, method); } } @@ -246,7 +250,7 @@ public class PatchExtensionMethod { MessageSend_postponedErrors.set(messageSend, new PostponedNonStaticAccessToStaticMethodError(problemReporter, location, method)); } - public static Object resolveType(Object resolvedType, MessageSend methodCall, BlockScope scope) { + public static TypeBinding resolveType(TypeBinding resolvedType, MessageSend methodCall, BlockScope scope) { List<Extension> extensions = new ArrayList<Extension>(); TypeDeclaration decl = scope.classScope().referenceContext; diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethodPortal.java b/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethodPortal.java deleted file mode 100644 index 82df71f6..00000000 --- a/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethodPortal.java +++ /dev/null @@ -1,115 +0,0 @@ -package lombok.eclipse.agent; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import lombok.Lombok; - -public class PatchExtensionMethodPortal { - private static final String TYPE_BINDING = "org.eclipse.jdt.internal.compiler.lookup.TypeBinding"; - private static final String TYPE_BINDING_ARRAY = "[Lorg.eclipse.jdt.internal.compiler.lookup.TypeBinding;"; - private static final String MESSAGE_SEND = "org.eclipse.jdt.internal.compiler.ast.MessageSend"; - private static final String BLOCK_SCOPE = "org.eclipse.jdt.internal.compiler.lookup.BlockScope"; - private static final String METHOD_BINDING = "org.eclipse.jdt.internal.compiler.lookup.MethodBinding"; - private static final String PROBLEM_REPORTER = "org.eclipse.jdt.internal.compiler.problem.ProblemReporter"; - - public static Object resolveType(Object resolvedType, Object methodCall, Object scope) { - try { - return Reflection.resolveType.invoke(null, resolvedType, methodCall, scope); - } catch (NoClassDefFoundError e) { - //ignore, we don't have access to the correct ECJ classes, so lombok can't possibly - //do anything useful here. - return resolvedType; - } catch (IllegalAccessException e) { - throw Lombok.sneakyThrow(e); - } catch (InvocationTargetException e) { - throw Lombok.sneakyThrow(e); - } catch (NullPointerException e) { - if (!"false".equals(System.getProperty("lombok.debug.reflection", "false"))) { - e.initCause(Reflection.problem); - throw e; - } - //ignore, we don't have access to the correct ECJ classes, so lombok can't possibly - //do anything useful here. - return resolvedType; - } - } - - public static void errorNoMethodFor(Object problemReporter, Object messageSend, Object recType, Object params) { - try { - Reflection.errorNoMethodFor.invoke(null, problemReporter, messageSend, recType, params); - } catch (NoClassDefFoundError e) { - //ignore, we don't have access to the correct ECJ classes, so lombok can't possibly - //do anything useful here. - } catch (IllegalAccessException e) { - throw Lombok.sneakyThrow(e); - } catch (InvocationTargetException e) { - throw Lombok.sneakyThrow(e.getCause()); - } catch (NullPointerException e) { - if (!"false".equals(System.getProperty("lombok.debug.reflection", "false"))) { - e.initCause(Reflection.problem); - throw e; - } - //ignore, we don't have access to the correct ECJ classes, so lombok can't possibly - //do anything useful here. - } - } - - public static void invalidMethod(Object problemReporter, Object messageSend, Object method) { - try { - Reflection.invalidMethod.invoke(null, problemReporter, messageSend, method); - } catch (NoClassDefFoundError e) { - //ignore, we don't have access to the correct ECJ classes, so lombok can't possibly - //do anything useful here. - } catch (IllegalAccessException e) { - handleReflectionDebug(e); - throw Lombok.sneakyThrow(e); - } catch (InvocationTargetException e) { - handleReflectionDebug(e.getCause()); - throw Lombok.sneakyThrow(e.getCause()); - } catch (NullPointerException e) { - handleReflectionDebug(e); - //ignore, we don't have access to the correct ECJ classes, so lombok can't possibly - //do anything useful here. - } - } - - public static boolean isDebugReflection() { - return !"false".equals(System.getProperty("lombok.debug.reflection", "false")); - } - - public static void handleReflectionDebug(Throwable t) { - if (!isDebugReflection()) return; - - System.err.println("** LOMBOK REFLECTION exception: " + t.getClass() + ": " + (t.getMessage() == null ? "(no message)" : t.getMessage())); - t.printStackTrace(System.err); - if (Reflection.problem != null) { - System.err.println("*** ADDITIONALLY, exception occurred setting up reflection: "); - Reflection.problem.printStackTrace(System.err); - } - } - - private static final class Reflection { - public static final Method resolveType, errorNoMethodFor, invalidMethod; - public static final Throwable problem; - - static { - Method m = null, n = null, o = null; - Throwable problem_ = null; - try { - m = PatchExtensionMethod.class.getMethod("resolveType", Object.class, Class.forName(MESSAGE_SEND), Class.forName(BLOCK_SCOPE)); - n = PatchExtensionMethod.class.getMethod("errorNoMethodFor", Class.forName(PROBLEM_REPORTER), - Class.forName(MESSAGE_SEND), Class.forName(TYPE_BINDING), Class.forName(TYPE_BINDING_ARRAY)); - o = PatchExtensionMethod.class.getMethod("invalidMethod", Class.forName(PROBLEM_REPORTER), Class.forName(MESSAGE_SEND), Class.forName(METHOD_BINDING)); - } catch (Throwable t) { - // That's problematic, but as long as no local classes are used we don't actually need it. - // Better fail on local classes than crash altogether. - problem_ = t; - } - resolveType = m; - errorNoMethodFor = n; - invalidMethod = o; - problem = problem_; - } - } -} diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java b/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java index f22e78a8..774e5b40 100644 --- a/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java +++ b/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2019 The Project Lombok Authors. + * Copyright (C) 2010-2021 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 @@ -68,32 +68,7 @@ public class PatchVal { // This is half of the work for 'val' support - the other half is in PatchValEclipse. This half is enough for ecj. // Creates a copy of the 'initialization' field on a LocalDeclaration if the type of the LocalDeclaration is 'val', because the completion parser will null this out, // which in turn stops us from inferring the intended type for 'val x = 5;'. We look at the copy. - // Also patches local declaration to not call .resolveType() on the initializer expression if we've already done so (calling it twice causes weird errors), - // and patches .resolve() on LocalDeclaration itself to just-in-time replace the 'val' vartype with the right one. - - public static TypeBinding skipResolveInitializerIfAlreadyCalled(Expression expr, BlockScope scope) { - if (expr.resolvedType != null) return expr.resolvedType; - try { - return expr.resolveType(scope); - } catch (NullPointerException e) { - return null; - } catch (ArrayIndexOutOfBoundsException e) { - // This will occur internally due to for example 'val x = mth("X");', where mth takes 2 arguments. - return null; - } - } - - public static TypeBinding skipResolveInitializerIfAlreadyCalled2(Expression expr, BlockScope scope, LocalDeclaration decl) { - if (decl != null && LocalDeclaration.class.equals(decl.getClass()) && expr.resolvedType != null) return expr.resolvedType; - try { - return expr.resolveType(scope); - } catch (NullPointerException e) { - return null; - } catch (ArrayIndexOutOfBoundsException e) { - // This will occur internally due to for example 'val x = mth("X");', where mth takes 2 arguments. - return null; - } - } + // Also patches .resolve() on LocalDeclaration itself to just-in-time replace the 'val' vartype with the right one. public static boolean matches(String key, char[] array) { if (array == null || key.length() != array.length) return false; @@ -145,7 +120,7 @@ public class PatchVal { public static boolean couldBe(ImportReference[] imports, String key, TypeReference ref) { String[] keyParts = key.split("\\."); if (ref instanceof SingleTypeReference) { - char[] token = ((SingleTypeReference)ref).token; + char[] token = ((SingleTypeReference) ref).token; if (!matches(keyParts[keyParts.length - 1], token)) return false; if (imports == null) return true; top: @@ -165,7 +140,7 @@ public class PatchVal { } if (ref instanceof QualifiedTypeReference) { - char[][] tokens = ((QualifiedTypeReference)ref).tokens; + char[][] tokens = ((QualifiedTypeReference) ref).tokens; if (keyParts.length != tokens.length) return false; for(int i = 0; i < tokens.length; ++i) { String part = keyParts[i]; @@ -295,7 +270,6 @@ public class PatchVal { if (val) local.modifiers |= ClassFileConstants.AccFinal; local.annotations = addValAnnotation(local.annotations, local.type, scope); local.type = replacement != null ? replacement : new QualifiedTypeReference(TypeConstants.JAVA_LANG_OBJECT, poss(local.type, 3)); - return false; } diff --git a/src/eclipseAgent/lombok/launch/PatchFixesHider.java b/src/eclipseAgent/lombok/launch/PatchFixesHider.java index e2d266c5..02df3f5f 100755 --- a/src/eclipseAgent/lombok/launch/PatchFixesHider.java +++ b/src/eclipseAgent/lombok/launch/PatchFixesHider.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2019 The Project Lombok Authors. + * Copyright (C) 2010-2021 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 @@ -43,20 +43,14 @@ import org.eclipse.jdt.core.dom.MethodDeclaration; import org.eclipse.jdt.core.dom.SimpleName; import org.eclipse.jdt.core.dom.Type; import org.eclipse.jdt.core.search.SearchMatch; -import org.eclipse.jdt.internal.compiler.ast.ASTNode; import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; import org.eclipse.jdt.internal.compiler.ast.Annotation; import org.eclipse.jdt.internal.compiler.ast.Expression; import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; -import org.eclipse.jdt.internal.compiler.ast.ForeachStatement; import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration; -import org.eclipse.jdt.internal.compiler.ast.MessageSend; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.lookup.BlockScope; -import org.eclipse.jdt.internal.compiler.lookup.MethodBinding; -import org.eclipse.jdt.internal.compiler.lookup.Scope; import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; -import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; import org.eclipse.jdt.internal.core.SourceField; import org.eclipse.jdt.internal.core.dom.rewrite.NodeRewriteEvent; import org.eclipse.jdt.internal.core.dom.rewrite.RewriteEvent; @@ -116,6 +110,15 @@ final class PatchFixesHider { } } + public static Method findMethod(Class<?> type, String name, String... parameterTypes) { + for (Method m : type.getDeclaredMethods()) { + if (name.equals(m.getName()) && sameTypes(m.getParameterTypes(), parameterTypes)) { + return m; + } + } + throw sneakyThrow(new NoSuchMethodException(type.getName() + "::" + name)); + } + public static Method findMethodAnyArgs(Class<?> type, String name) { for (Method m : type.getDeclaredMethods()) if (name.equals(m.getName())) return m; throw sneakyThrow(new NoSuchMethodException(type.getName() + "::" + name)); @@ -141,6 +144,14 @@ final class PatchFixesHider { private static <T extends Throwable> void sneakyThrow0(Throwable t) throws T { throw (T)t; } + + private static boolean sameTypes(Class<?>[] types, String[] typeNames) { + if (types.length != typeNames.length) return false; + for (int i = 0; i < types.length; i++) { + if (!types[i].getName().equals(typeNames[i])) return false; + } + return true; + } } /** Contains patch fixes that are dependent on lombok internals. */ @@ -193,7 +204,6 @@ final class PatchFixesHider { } public static void transform(Object parser, Object ast) throws IOException { - Main.prependClassLoader(parser.getClass().getClassLoader()); init(parser.getClass().getClassLoader()); Util.invokeMethod(TRANSFORM, parser, ast); } @@ -207,20 +217,20 @@ final class PatchFixesHider { /** Contains patch code to support {@code @Delegate} */ public static final class Delegate { private static final Method HANDLE_DELEGATE_FOR_TYPE; - private static final Method GET_CHILDREN; + private static final Method ADD_GENERATED_DELEGATE_METHODS; static { Class<?> shadowed = Util.shadowLoadClass("lombok.eclipse.agent.PatchDelegatePortal"); HANDLE_DELEGATE_FOR_TYPE = Util.findMethod(shadowed, "handleDelegateForType", Object.class); - GET_CHILDREN = Util.findMethod(shadowed, "getChildren", Object.class, Object.class); + ADD_GENERATED_DELEGATE_METHODS = Util.findMethod(shadowed, "addGeneratedDelegateMethods", Object.class, Object.class); } public static boolean handleDelegateForType(Object classScope) { return (Boolean) Util.invokeMethod(HANDLE_DELEGATE_FOR_TYPE, classScope); } - public static Object[] getChildren(Object returnValue, Object javaElement) { - return (Object[]) Util.invokeMethod(GET_CHILDREN, returnValue, javaElement); + public static Object[] addGeneratedDelegateMethods(Object returnValue, Object javaElement) { + return (Object[]) Util.invokeMethod(ADD_GENERATED_DELEGATE_METHODS, returnValue, javaElement); } } @@ -258,38 +268,67 @@ final class PatchFixesHider { /** Contains patch code to support {@code val} (eclipse and ecj) */ public static final class Val { - private static final Method SKIP_RESOLVE_INITIALIZER_IF_ALREADY_CALLED; - private static final Method SKIP_RESOLVE_INITIALIZER_IF_ALREADY_CALLED2; + private static final String BLOCK_SCOPE_SIG = "org.eclipse.jdt.internal.compiler.lookup.BlockScope"; + private static final String LOCAL_DECLARATION_SIG = "org.eclipse.jdt.internal.compiler.ast.LocalDeclaration"; + private static final String FOREACH_STATEMENT_SIG = "org.eclipse.jdt.internal.compiler.ast.ForeachStatement"; + private static final Method HANDLE_VAL_FOR_LOCAL_DECLARATION; private static final Method HANDLE_VAL_FOR_FOR_EACH; static { Class<?> shadowed = Util.shadowLoadClass("lombok.eclipse.agent.PatchVal"); - SKIP_RESOLVE_INITIALIZER_IF_ALREADY_CALLED = Util.findMethod(shadowed, "skipResolveInitializerIfAlreadyCalled", Expression.class, BlockScope.class); - SKIP_RESOLVE_INITIALIZER_IF_ALREADY_CALLED2 = Util.findMethod(shadowed, "skipResolveInitializerIfAlreadyCalled2", Expression.class, BlockScope.class, LocalDeclaration.class); - HANDLE_VAL_FOR_LOCAL_DECLARATION = Util.findMethod(shadowed, "handleValForLocalDeclaration", LocalDeclaration.class, BlockScope.class); - HANDLE_VAL_FOR_FOR_EACH = Util.findMethod(shadowed, "handleValForForEach", ForeachStatement.class, BlockScope.class); + HANDLE_VAL_FOR_LOCAL_DECLARATION = Util.findMethod(shadowed, "handleValForLocalDeclaration", LOCAL_DECLARATION_SIG, BLOCK_SCOPE_SIG); + HANDLE_VAL_FOR_FOR_EACH = Util.findMethod(shadowed, "handleValForForEach", FOREACH_STATEMENT_SIG, BLOCK_SCOPE_SIG); } - public static TypeBinding skipResolveInitializerIfAlreadyCalled(Expression expr, BlockScope scope) { - return (TypeBinding) Util.invokeMethod(SKIP_RESOLVE_INITIALIZER_IF_ALREADY_CALLED, expr, scope); + public static boolean handleValForLocalDeclaration(Object local, Object scope) { + return (Boolean) Util.invokeMethod(HANDLE_VAL_FOR_LOCAL_DECLARATION, local, scope); } - public static TypeBinding skipResolveInitializerIfAlreadyCalled2(Expression expr, BlockScope scope, LocalDeclaration decl) { - return (TypeBinding) Util.invokeMethod(SKIP_RESOLVE_INITIALIZER_IF_ALREADY_CALLED2, expr, scope, decl); + public static boolean handleValForForEach(Object forEach, Object scope) { + return (Boolean) Util.invokeMethod(HANDLE_VAL_FOR_FOR_EACH, forEach, scope); } - public static boolean handleValForLocalDeclaration(LocalDeclaration local, BlockScope scope) { - return (Boolean) Util.invokeMethod(HANDLE_VAL_FOR_LOCAL_DECLARATION, local, scope); + /** + * Patches local declaration to not call .resolveType() on the initializer expression if we've already done so (calling it twice causes weird errors) + * This and the next method must be transplanted so that the return type is loaded in the correct class loader + */ + public static TypeBinding skipResolveInitializerIfAlreadyCalled(Expression expr, BlockScope scope) { + if (expr.resolvedType != null) return expr.resolvedType; + try { + return expr.resolveType(scope); + } catch (NullPointerException e) { + return null; + } catch (ArrayIndexOutOfBoundsException e) { + // This will occur internally due to for example 'val x = mth("X");', where mth takes 2 arguments. + return null; + } } - public static boolean handleValForForEach(ForeachStatement forEach, BlockScope scope) { - return (Boolean) Util.invokeMethod(HANDLE_VAL_FOR_FOR_EACH, forEach, scope); + public static TypeBinding skipResolveInitializerIfAlreadyCalled2(Expression expr, BlockScope scope, LocalDeclaration decl) { + if (decl != null && LocalDeclaration.class.equals(decl.getClass()) && expr.resolvedType != null) return expr.resolvedType; + try { + return expr.resolveType(scope); + } catch (NullPointerException e) { + return null; + } catch (ArrayIndexOutOfBoundsException e) { + // This will occur internally due to for example 'val x = mth("X");', where mth takes 2 arguments. + return null; + } } } /** Contains patch code to support {@code @ExtensionMethod} */ public static final class ExtensionMethod { + private static final String MESSAGE_SEND_SIG = "org.eclipse.jdt.internal.compiler.ast.MessageSend"; + private static final String TYPE_BINDING_SIG = "org.eclipse.jdt.internal.compiler.lookup.TypeBinding"; + private static final String SCOPE_SIG = "org.eclipse.jdt.internal.compiler.lookup.Scope"; + private static final String BLOCK_SCOPE_SIG = "org.eclipse.jdt.internal.compiler.lookup.BlockScope"; + private static final String TYPE_BINDINGS_SIG = "[Lorg.eclipse.jdt.internal.compiler.lookup.TypeBinding;"; + private static final String PROBLEM_REPORTER_SIG = "org.eclipse.jdt.internal.compiler.problem.ProblemReporter"; + private static final String METHOD_BINDING_SIG = "org.eclipse.jdt.internal.compiler.lookup.MethodBinding"; + private static final String AST_NODE_SIG = "org.eclipse.jdt.internal.compiler.ast.ASTNode"; + private static final Method RESOLVE_TYPE; private static final Method ERROR_NO_METHOD_FOR; private static final Method INVALID_METHOD, INVALID_METHOD2; @@ -297,30 +336,30 @@ final class PatchFixesHider { static { Class<?> shadowed = Util.shadowLoadClass("lombok.eclipse.agent.PatchExtensionMethod"); - RESOLVE_TYPE = Util.findMethod(shadowed, "resolveType", Object.class, MessageSend.class, BlockScope.class); - ERROR_NO_METHOD_FOR = Util.findMethod(shadowed, "errorNoMethodFor", ProblemReporter.class, MessageSend.class, TypeBinding.class, TypeBinding[].class); - INVALID_METHOD = Util.findMethod(shadowed, "invalidMethod", ProblemReporter.class, MessageSend.class, MethodBinding.class); - INVALID_METHOD2 = Util.findMethod(shadowed, "invalidMethod", ProblemReporter.class, MessageSend.class, MethodBinding.class, Scope.class); - NON_STATIC_ACCESS_TO_STATIC_METHOD = Util.findMethod(shadowed, "nonStaticAccessToStaticMethod", ProblemReporter.class, ASTNode.class, MethodBinding.class, MessageSend.class); + RESOLVE_TYPE = Util.findMethod(shadowed, "resolveType", TYPE_BINDING_SIG, MESSAGE_SEND_SIG, BLOCK_SCOPE_SIG); + ERROR_NO_METHOD_FOR = Util.findMethod(shadowed, "errorNoMethodFor", PROBLEM_REPORTER_SIG, MESSAGE_SEND_SIG, TYPE_BINDING_SIG, TYPE_BINDINGS_SIG); + INVALID_METHOD = Util.findMethod(shadowed, "invalidMethod", PROBLEM_REPORTER_SIG, MESSAGE_SEND_SIG, METHOD_BINDING_SIG); + INVALID_METHOD2 = Util.findMethod(shadowed, "invalidMethod", PROBLEM_REPORTER_SIG, MESSAGE_SEND_SIG, METHOD_BINDING_SIG, SCOPE_SIG); + NON_STATIC_ACCESS_TO_STATIC_METHOD = Util.findMethod(shadowed, "nonStaticAccessToStaticMethod", PROBLEM_REPORTER_SIG, AST_NODE_SIG, METHOD_BINDING_SIG, MESSAGE_SEND_SIG); } - public static Object resolveType(Object resolvedType, MessageSend methodCall, BlockScope scope) { + public static Object resolveType(Object resolvedType, Object methodCall, Object scope) { return Util.invokeMethod(RESOLVE_TYPE, resolvedType, methodCall, scope); } - public static void errorNoMethodFor(ProblemReporter problemReporter, MessageSend messageSend, TypeBinding recType, TypeBinding[] params) { + public static void errorNoMethodFor(Object problemReporter, Object messageSend, Object recType, Object params) { Util.invokeMethod(ERROR_NO_METHOD_FOR, problemReporter, messageSend, recType, params); } - public static void invalidMethod(ProblemReporter problemReporter, MessageSend messageSend, MethodBinding method) { + public static void invalidMethod(Object problemReporter, Object messageSend, Object method) { Util.invokeMethod(INVALID_METHOD, problemReporter, messageSend, method); } - public static void invalidMethod(ProblemReporter problemReporter, MessageSend messageSend, MethodBinding method, Scope scope) { + public static void invalidMethod(Object problemReporter, Object messageSend, Object method, Object scope) { Util.invokeMethod(INVALID_METHOD2, problemReporter, messageSend, method, scope); } - public static void nonStaticAccessToStaticMethod(ProblemReporter problemReporter, ASTNode location, MethodBinding method, MessageSend messageSend) { + public static void nonStaticAccessToStaticMethod(Object problemReporter, Object location, Object method, Object messageSend) { Util.invokeMethod(NON_STATIC_ACCESS_TO_STATIC_METHOD, problemReporter, location, method, messageSend); } } diff --git a/src/installer/lombok/installer/Installer.java b/src/installer/lombok/installer/Installer.java index 94cc1a45..1ca77065 100644 --- a/src/installer/lombok/installer/Installer.java +++ b/src/installer/lombok/installer/Installer.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2016 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -40,8 +40,7 @@ import lombok.core.SpiLoadUtil; import lombok.core.Version; import lombok.installer.OsUtils.OS; import lombok.patcher.ClassRootFinder; - -import org.mangosdk.spi.ProviderFor; +import lombok.spi.Provides; import com.zwitserloot.cmdreader.CmdReader; import com.zwitserloot.cmdreader.Description; @@ -105,7 +104,7 @@ public class Installer { return a.equals(b); } - @ProviderFor(LombokApp.class) + @Provides public static class GraphicalInstallerApp extends LombokApp { @Override public String getAppName() { return "installer"; @@ -124,7 +123,7 @@ public class Installer { } } - @ProviderFor(LombokApp.class) + @Provides public static class CommandLineInstallerApp extends LombokApp { @Override public String getAppName() { return "install"; @@ -139,7 +138,7 @@ public class Installer { } } - @ProviderFor(LombokApp.class) + @Provides public static class CommandLineUninstallerApp extends LombokApp { @Override public String getAppName() { return "uninstall"; diff --git a/src/installer/lombok/installer/eclipse/AngularIDELocationProvider.java b/src/installer/lombok/installer/eclipse/AngularIDELocationProvider.java index 6d580e13..0f0aac0d 100644 --- a/src/installer/lombok/installer/eclipse/AngularIDELocationProvider.java +++ b/src/installer/lombok/installer/eclipse/AngularIDELocationProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 The Project Lombok Authors. + * Copyright (C) 2018-2021 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 @@ -23,11 +23,10 @@ package lombok.installer.eclipse; import java.util.Collections; -import org.mangosdk.spi.ProviderFor; - import lombok.installer.IdeLocationProvider; +import lombok.spi.Provides; -@ProviderFor(IdeLocationProvider.class) +@Provides(IdeLocationProvider.class) public class AngularIDELocationProvider extends EclipseProductLocationProvider { private static final EclipseProductDescriptor ANGULAR = new StandardProductDescriptor( diff --git a/src/installer/lombok/installer/eclipse/EclipseLocationProvider.java b/src/installer/lombok/installer/eclipse/EclipseLocationProvider.java index fa2ce958..317c95cb 100644 --- a/src/installer/lombok/installer/eclipse/EclipseLocationProvider.java +++ b/src/installer/lombok/installer/eclipse/EclipseLocationProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2016 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -24,10 +24,9 @@ package lombok.installer.eclipse; import java.util.Collections; import lombok.installer.IdeLocationProvider; +import lombok.spi.Provides; -import org.mangosdk.spi.ProviderFor; - -@ProviderFor(IdeLocationProvider.class) +@Provides(IdeLocationProvider.class) public class EclipseLocationProvider extends EclipseProductLocationProvider { private static final EclipseProductDescriptor ECLIPSE = new StandardProductDescriptor( diff --git a/src/installer/lombok/installer/eclipse/JbdsLocationProvider.java b/src/installer/lombok/installer/eclipse/JbdsLocationProvider.java index 635f304a..75805f21 100644 --- a/src/installer/lombok/installer/eclipse/JbdsLocationProvider.java +++ b/src/installer/lombok/installer/eclipse/JbdsLocationProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2016 The Project Lombok Authors. + * Copyright (C) 2013-2021 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 @@ -24,10 +24,9 @@ package lombok.installer.eclipse; import java.util.Collections; import lombok.installer.IdeLocationProvider; +import lombok.spi.Provides; -import org.mangosdk.spi.ProviderFor; - -@ProviderFor(IdeLocationProvider.class) +@Provides(IdeLocationProvider.class) public class JbdsLocationProvider extends EclipseProductLocationProvider { private static final EclipseProductDescriptor JBDS = new StandardProductDescriptor( diff --git a/src/installer/lombok/installer/eclipse/MyEclipseLocationProvider.java b/src/installer/lombok/installer/eclipse/MyEclipseLocationProvider.java index 298cabd6..e923202d 100644 --- a/src/installer/lombok/installer/eclipse/MyEclipseLocationProvider.java +++ b/src/installer/lombok/installer/eclipse/MyEclipseLocationProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 The Project Lombok Authors. + * Copyright (C) 2016-2021 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 @@ -24,10 +24,9 @@ package lombok.installer.eclipse; import java.util.Collections; import lombok.installer.IdeLocationProvider; +import lombok.spi.Provides; -import org.mangosdk.spi.ProviderFor; - -@ProviderFor(IdeLocationProvider.class) +@Provides(IdeLocationProvider.class) public class MyEclipseLocationProvider extends EclipseProductLocationProvider { private static final EclipseProductDescriptor MY_ECLIPSE = new StandardProductDescriptor( diff --git a/src/installer/lombok/installer/eclipse/RhcrLocationProvider.java b/src/installer/lombok/installer/eclipse/RhcrLocationProvider.java index d4f39f3b..0731d5bd 100644 --- a/src/installer/lombok/installer/eclipse/RhcrLocationProvider.java +++ b/src/installer/lombok/installer/eclipse/RhcrLocationProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 The Project Lombok Authors. + * Copyright (C) 2020-2021 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 @@ -24,10 +24,9 @@ package lombok.installer.eclipse; import java.util.Collections; import lombok.installer.IdeLocationProvider; +import lombok.spi.Provides; -import org.mangosdk.spi.ProviderFor; - -@ProviderFor(IdeLocationProvider.class) +@Provides(IdeLocationProvider.class) public class RhcrLocationProvider extends EclipseProductLocationProvider { private static final EclipseProductDescriptor RHCR = new StandardProductDescriptor( "Red Hat CodeReady Studio", diff --git a/src/installer/lombok/installer/eclipse/RhdsLocationProvider.java b/src/installer/lombok/installer/eclipse/RhdsLocationProvider.java index 5e1d303d..030b96bb 100644 --- a/src/installer/lombok/installer/eclipse/RhdsLocationProvider.java +++ b/src/installer/lombok/installer/eclipse/RhdsLocationProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2016 The Project Lombok Authors. + * Copyright (C) 2013-2021 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 @@ -24,10 +24,9 @@ package lombok.installer.eclipse; import java.util.Collections; import lombok.installer.IdeLocationProvider; +import lombok.spi.Provides; -import org.mangosdk.spi.ProviderFor; - -@ProviderFor(IdeLocationProvider.class) +@Provides(IdeLocationProvider.class) public class RhdsLocationProvider extends EclipseProductLocationProvider { private static final EclipseProductDescriptor RHDS = new StandardProductDescriptor( diff --git a/src/installer/lombok/installer/eclipse/STS4LocationProvider.java b/src/installer/lombok/installer/eclipse/STS4LocationProvider.java index 47a07bdd..068ec6e9 100644 --- a/src/installer/lombok/installer/eclipse/STS4LocationProvider.java +++ b/src/installer/lombok/installer/eclipse/STS4LocationProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 The Project Lombok Authors. + * Copyright (C) 2018-2021 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 @@ -25,10 +25,9 @@ import java.util.Arrays; import java.util.Collections; import lombok.installer.IdeLocationProvider; +import lombok.spi.Provides; -import org.mangosdk.spi.ProviderFor; - -@ProviderFor(IdeLocationProvider.class) +@Provides(IdeLocationProvider.class) public class STS4LocationProvider extends EclipseProductLocationProvider { private static final EclipseProductDescriptor STS4 = new StandardProductDescriptor("Spring Tools Suite 4", diff --git a/src/installer/lombok/installer/eclipse/STSLocationProvider.java b/src/installer/lombok/installer/eclipse/STSLocationProvider.java index d2efb956..7c42cf62 100644 --- a/src/installer/lombok/installer/eclipse/STSLocationProvider.java +++ b/src/installer/lombok/installer/eclipse/STSLocationProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2016 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -24,10 +24,9 @@ package lombok.installer.eclipse; import java.util.Collections; import lombok.installer.IdeLocationProvider; +import lombok.spi.Provides; -import org.mangosdk.spi.ProviderFor; - -@ProviderFor(IdeLocationProvider.class) +@Provides(IdeLocationProvider.class) public class STSLocationProvider extends EclipseProductLocationProvider { private static final EclipseProductDescriptor STS = new StandardProductDescriptor("STS", diff --git a/src/launch/lombok/launch/Main.java b/src/launch/lombok/launch/Main.java index ff539704..af65bdf8 100644 --- a/src/launch/lombok/launch/Main.java +++ b/src/launch/lombok/launch/Main.java @@ -36,7 +36,7 @@ class Main { static synchronized void prependClassLoader(ClassLoader loader) { getShadowClassLoader(); - classLoader.prepend(loader); + classLoader.prependParent(loader); } public static void main(String[] args) throws Throwable { diff --git a/src/launch/lombok/launch/ShadowClassLoader.java b/src/launch/lombok/launch/ShadowClassLoader.java index e75c300e..929681ce 100644 --- a/src/launch/lombok/launch/ShadowClassLoader.java +++ b/src/launch/lombok/launch/ShadowClassLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014-2018 The Project Lombok Authors. + * Copyright (C) 2014-2021 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 @@ -38,6 +38,7 @@ import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; +import java.util.IdentityHashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -102,14 +103,12 @@ class ShadowClassLoader extends ClassLoader { private final List<String> parentExclusion = new ArrayList<String>(); private final List<String> highlanders = new ArrayList<String>(); - private final List<ClassLoader> prependedLoaders = new ArrayList<ClassLoader>(); + private final Set<ClassLoader> prependedParentLoaders = Collections.newSetFromMap(new IdentityHashMap<ClassLoader, Boolean>()); - public void prepend(ClassLoader loader) { + public void prependParent(ClassLoader loader) { if (loader == null) return; - for (ClassLoader cl : prependedLoaders) { - if (cl == loader) return; - } - prependedLoaders.add(loader); + if (loader == getParent()) return; + prependedParentLoaders.add(loader); } /** @@ -539,23 +538,25 @@ class ShadowClassLoader extends ClassLoader { } String fileNameOfClass = name.replace(".", "/") + ".class"; - for (ClassLoader pre : prependedLoaders) { - try { - URL res = pre.getResource(fileNameOfClass); - if (res == null) continue; - return urlToDefineClass(name, res, resolve); - } catch (Exception e) { - continue; - } - } - URL res = getResource_(fileNameOfClass, true); if (res == null) { - if (!exclusionListMatch(fileNameOfClass)) try { - return super.loadClass(name, resolve); - } catch (ClassNotFoundException cnfe) { - res = getResource_("secondaryLoading.SCL." + sclSuffix + "/" + name.replace(".", "/") + ".SCL." + sclSuffix, true); - if (res == null) throw cnfe; + if (!exclusionListMatch(fileNameOfClass)) { + try { + // First search in the prepended classloaders, the class might be their already + for (ClassLoader pre : prependedParentLoaders) { + try { + Class<?> loadClass = pre.loadClass(name); + if (loadClass != null) return loadClass; + } catch (Throwable e) { + continue; + } + } + + return super.loadClass(name, resolve); + } catch (ClassNotFoundException cnfe) { + res = getResource_("secondaryLoading.SCL." + sclSuffix + "/" + name.replace(".", "/") + ".SCL." + sclSuffix, true); + if (res == null) throw cnfe; + } } } if (res == null) throw new ClassNotFoundException(name); diff --git a/src/spiProcessor/lombok/spi/Provides.java b/src/spiProcessor/lombok/spi/Provides.java new file mode 100644 index 00000000..de930819 --- /dev/null +++ b/src/spiProcessor/lombok/spi/Provides.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2021 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 + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.spi; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.SOURCE) +public @interface Provides { + Class<?>[] value() default {}; +} diff --git a/src/spiProcessor/lombok/spi/SpiProcessor.java b/src/spiProcessor/lombok/spi/SpiProcessor.java new file mode 100644 index 00000000..4ad27bbe --- /dev/null +++ b/src/spiProcessor/lombok/spi/SpiProcessor.java @@ -0,0 +1,254 @@ +/* + * Copyright (C) 2021 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 + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.spi; + +import java.io.IOException; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Deque; +import java.util.List; +import java.util.Map.Entry; +import java.util.Set; + +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.ProcessingEnvironment; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedAnnotationTypes; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.AnnotationValue; +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.Modifier; +import javax.lang.model.element.Name; +import javax.lang.model.element.TypeElement; +import javax.lang.model.type.DeclaredType; +import javax.lang.model.type.TypeMirror; + +import javax.tools.Diagnostic.Kind; + +@SupportedAnnotationTypes("*") +public class SpiProcessor extends AbstractProcessor { + private SpiProcessorCollector data; + private SpiProcessorPersistence persistence; + + static String getRootPathOfServiceFiles() { + return "META-INF/services/"; + } + + @Override public SourceVersion getSupportedSourceVersion() { + return SourceVersion.latest(); + } + + static String toErrorMsg(Exception e, String pathName) { + StringBuilder sb = new StringBuilder(); + sb.append("Exception applying SPI processor on ").append(pathName).append(": ").append(toStringLong(e)); + return sb.toString(); + } + + private static String toStringLong(Throwable t) { + if (t == null) return "NULL"; + StringBuilder out = new StringBuilder(); + + String msg = t.getMessage(); + out.append(t.getClass().getName()); + if (msg != null) out.append(": ").append(msg); + String indent = " "; + + StackTraceElement[] elems = t.getStackTrace(); + if (elems != null) for (int i = 0; i < elems.length; i++) { + out.append("\n").append(indent).append(elems[i]); + } + Throwable cause = t.getCause(); + while (cause != null) { + indent = indent + " "; + out.append("\n").append(indent).append("Caused by: ").append(cause.getClass().getName()); + msg = cause.getMessage(); + if (msg != null) out.append(": ").append(msg); + elems = cause.getStackTrace(); + indent = indent + " "; + if (elems != null) for (int i = 0; i < elems.length; i++) { + out.append("\n").append(indent).append(elems[i]); + } + cause = cause.getCause(); + } + return out.toString(); + } + + @Override public synchronized void init(ProcessingEnvironment processingEnv) { + super.init(processingEnv); + persistence = new SpiProcessorPersistence("SpiProcessor", processingEnv.getFiler(), processingEnv.getMessager()); + data = new SpiProcessorCollector(processingEnv); + for (String serviceName : persistence.tryFind()) data.getService(serviceName); + data.stripProvidersWithoutSourceFile(); + } + + @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { + removeStaleData(roundEnv); + handleAnnotations(roundEnv); + if (roundEnv.processingOver()) writeData(); + + return false; + } + + private void writeData() { + for (SpiProcessorService service : data.services()) { + try { + persistence.write(service.getName(), service.toProvidersListFormat()); + } + catch (IOException e) { + processingEnv.getMessager().printMessage(Kind.ERROR, e.getMessage()); + } + } + } + + private void removeStaleData(RoundEnvironment roundEnv) { + for (Element e : roundEnv.getRootElements()) { + if (e instanceof TypeElement) { + TypeElement currentClass = (TypeElement) e; + data.removeProvider(createProperQualifiedName(currentClass)); + } + } + } + + private void handleAnnotations(RoundEnvironment roundEnv) { + Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(Provides.class); + for (Element e : elements) handleProvidingElement(e); + } + + private void handleProvidingElement(Element element) { + if (element.getKind() != ElementKind.CLASS) { + report(element, "is not a class definition"); + return; + } + + TypeElement elem = (TypeElement) element; + + Element enclosing = elem.getEnclosingElement(); + if (enclosing != null && enclosing.getKind() == ElementKind.CLASS && !elem.getModifiers().contains(Modifier.STATIC)) { + report(elem, "is a non-static inner class"); + return; + } + + boolean hasConstructors = false; + boolean hasNoArgsConstructor = false; + for (Element child : elem.getEnclosedElements()) { + if (child.getKind() != ElementKind.CONSTRUCTOR) continue; + ExecutableElement ee = (ExecutableElement) child; + hasConstructors = true; + if (ee.getParameters().isEmpty()) { + hasNoArgsConstructor = true; + break; + } + } + + if (hasConstructors && !hasNoArgsConstructor) { + report(elem, "has no no-args constructor"); + return; + } + + List<TypeMirror> spiTypes = new ArrayList<TypeMirror>(); + + for (AnnotationMirror annMirror : element.getAnnotationMirrors()) { + if (!getQualifiedTypeName(annMirror).contentEquals(Provides.class.getName())) continue; + for (Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : annMirror.getElementValues().entrySet()) { + if (!entry.getKey().getSimpleName().contentEquals("value")) continue; + Object list = entry.getValue().getValue(); + if (list instanceof TypeMirror) spiTypes.add((TypeMirror) list); + else if (list instanceof List<?>) { + for (Object tm : (List<?>) list) { + if (tm instanceof AnnotationValue) tm = ((AnnotationValue) tm).getValue(); + if (tm instanceof TypeMirror) { + TypeMirror mirror = (TypeMirror) tm; + mirror = processingEnv.getTypeUtils().erasure(mirror); + spiTypes.add(mirror); + } + } + } + } + } + + TypeMirror superclass = elem.getSuperclass(); + if (spiTypes.isEmpty()) { + List<TypeMirror> qualifying = new ArrayList<TypeMirror>(); + qualifying.addAll(elem.getInterfaces()); + if (superclass != null && !toElement(superclass).getQualifiedName().contentEquals("java.lang.Object")) qualifying.add(superclass); + + if (qualifying.isEmpty()) { + report(elem, "is marked @Provides but implements/extends nothing"); + return; + } + if (qualifying.size() > 1) { + report(elem, "is marked @Provides but implements/extends multiple types; explicitly specify which interface(s) this provides for"); + return; + } + spiTypes.add(qualifying.get(0)); + } else { + Deque<TypeMirror> parentage = new ArrayDeque<TypeMirror>(); + parentage.addAll(elem.getInterfaces()); + parentage.add(superclass); + List<TypeMirror> needed = new ArrayList<TypeMirror>(); + needed.addAll(spiTypes); + while (!parentage.isEmpty() && !spiTypes.isEmpty()) { + TypeMirror parent = parentage.pollFirst(); + if (parent == null) continue; + needed.remove(parent); + parentage.addAll(processingEnv.getTypeUtils().directSupertypes(parent)); + } + if (!needed.isEmpty()) { + report(elem, "is marked as providing " + needed + " but does not implement it"); + return; + } + } + + for (TypeMirror spiType : spiTypes) { + String spiTypeName = createProperQualifiedName(toElement(spiType)); + String createProperQualifiedName = createProperQualifiedName(elem); + data.getService(spiTypeName).addProvider(createProperQualifiedName); + } + } + + private Name getQualifiedTypeName(AnnotationMirror mirror) { + Element elem = mirror.getAnnotationType().asElement(); + if (!(elem instanceof TypeElement)) return null; + return ((TypeElement) elem).getQualifiedName(); + } + + private TypeElement toElement(TypeMirror typeMirror) { + if (typeMirror instanceof DeclaredType) { + Element asElement = ((DeclaredType) typeMirror).asElement(); + if (asElement instanceof TypeElement) return (TypeElement) asElement; + } + return null; + } + + private void report(Element elem, String message) { + /* In eclipse, messages just seem to get ignored, so we throw instead. */ + if (Boolean.TRUE) throw new RuntimeException(elem.getSimpleName() + " " + message); + processingEnv.getMessager().printMessage(Kind.ERROR, elem.getSimpleName() + " " + message, elem); + } + + private String createProperQualifiedName(TypeElement provider) { + return processingEnv.getElementUtils().getBinaryName(provider).toString(); + } +} diff --git a/src/spiProcessor/lombok/spi/SpiProcessorCollector.java b/src/spiProcessor/lombok/spi/SpiProcessorCollector.java new file mode 100644 index 00000000..52e557f6 --- /dev/null +++ b/src/spiProcessor/lombok/spi/SpiProcessorCollector.java @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2021 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 + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.spi; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.annotation.processing.Filer; +import javax.annotation.processing.Messager; +import javax.annotation.processing.ProcessingEnvironment; +import javax.lang.model.util.Elements; +import javax.tools.Diagnostic.Kind; +import javax.tools.FileObject; +import javax.tools.StandardLocation; + +class SpiProcessorCollector { + private final Map<String, SpiProcessorService> services = new HashMap<String, SpiProcessorService>(); + private final List<String> removed = new ArrayList<String>(); + + private final Elements elements; + private final Messager logger; + private final Filer filer; + + SpiProcessorCollector(ProcessingEnvironment processingEnv) { + this.elements = processingEnv.getElementUtils(); + this.logger = processingEnv.getMessager(); + this.filer = processingEnv.getFiler(); + } + + SpiProcessorCollector(Elements elements, Messager logger, Filer filer) { + if (elements == null) throw new NullPointerException("elements"); + if (logger == null) throw new NullPointerException("logger"); + if (filer == null) throw new NullPointerException("filer"); + this.elements = elements; + this.logger = logger; + this.filer = filer; + } + + SpiProcessorService getService(String serviceName) { + if (serviceName == null) throw new NullPointerException("serviceName"); + if (!services.containsKey(serviceName)) { + SpiProcessorService newService = new SpiProcessorService(serviceName); + CharSequence initialData = readInitialData(serviceName); + if (initialData != null) { + newService.addAllFromProvidersNameList(initialData.toString()); + for (String provider : removed) newService.removeProvider(provider); + } + services.put(serviceName, newService); + } + return services.get(serviceName); + } + + Collection<SpiProcessorService> services() { + return Collections.unmodifiableMap(services).values(); + } + + void removeProvider(String provider) { + if (provider == null) throw new NullPointerException("provider"); + removed.add(provider); + for (SpiProcessorService service : services.values()) service.removeProvider(provider); + } + + @Override public String toString() { + return services.values().toString(); + } + + private CharSequence readInitialData(String serviceName) { + String pathName = SpiProcessor.getRootPathOfServiceFiles() + serviceName; + FileObject resource; + + try { + resource = filer.getResource(StandardLocation.CLASS_OUTPUT, "", pathName); + } catch (Exception e) { + logger.printMessage(Kind.ERROR, SpiProcessor.toErrorMsg(e, pathName)); + return null; + } + + return SpiProcessorPersistence.readFilerResource(resource, logger, pathName); + } + + void stripProvidersWithoutSourceFile() { + for (SpiProcessorService s : services.values()) s.stripProvidersWithoutSourceFile(elements); + } +} diff --git a/src/spiProcessor/lombok/spi/SpiProcessorPersistence.java b/src/spiProcessor/lombok/spi/SpiProcessorPersistence.java new file mode 100644 index 00000000..c9bd745f --- /dev/null +++ b/src/spiProcessor/lombok/spi/SpiProcessorPersistence.java @@ -0,0 +1,148 @@ +/* + * Copyright (C) 2021 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 + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.spi; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.Reader; +import java.io.Writer; +import java.net.URI; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.Locale; + +import javax.annotation.processing.Filer; +import javax.annotation.processing.Messager; +import javax.tools.Diagnostic.Kind; +import javax.tools.FileObject; +import javax.tools.StandardLocation; + +class SpiProcessorPersistence { + private final String name; + private final String path; + final Filer filer; + private final Messager logger; + + SpiProcessorPersistence(String name, Filer filer, Messager logger) { + this.name = name; + this.logger = logger; + this.path = SpiProcessor.getRootPathOfServiceFiles(); + this.filer = filer; + } + + static CharSequence readFilerResource(FileObject resource, Messager logger, String pathName) { + try { + // Eclipse can't handle getCharContent, so we must use a reader... + return tryWithReader(resource); + } catch (FileNotFoundException e) { + return null; + } catch (IOException e) { + if ( + e.getClass().getName().equals("org.eclipse.core.internal.resources.ResourceException") && + e.getMessage() != null && + e.getMessage().endsWith("does not exist.")) { + + return null; + } + + logger.printMessage(Kind.ERROR, SpiProcessor.toErrorMsg(e, pathName)); + return null; + } catch (Exception other) { + // otherwise, probably javac: Some versions don't support the `openReader` method. + try { + return resource.getCharContent(true); + } catch (FileNotFoundException e) { + return null; + } catch (IOException e) { + logger.printMessage(Kind.ERROR, SpiProcessor.toErrorMsg(e, pathName)); + return null; + } + } + } + + private static CharSequence tryWithReader(FileObject resource) throws IOException { + StringBuilder sb = new StringBuilder(); + Reader raw = resource.openReader(true); + try { + BufferedReader in = new BufferedReader(raw); + for (String line = in.readLine(); line != null; line = in.readLine()) sb.append(line).append('\n'); + return sb; + } finally { + if (raw != null) raw.close(); + } + } + + Collection<String> tryFind() { + File dir = determineOutputLocation(); + if (dir == null || !dir.isDirectory()) return Collections.emptyList(); + List<String> out = new ArrayList<String>(); + for (File p : dir.listFiles()) { + if (!p.isFile()) continue; + out.add(p.getName()); + } + return out; + } + + private File determineOutputLocation() { + FileObject resource; + try { + resource = filer.createResource(StandardLocation.CLASS_OUTPUT, "META-INF", "locator.tmp"); + } catch (FileNotFoundException e) { + e.printStackTrace(); + // Could happen + return null; + } catch (IOException e) { + e.printStackTrace(); + logger.printMessage(Kind.NOTE, "IOException while determining output location: " + e.getMessage()); + return null; + } catch (IllegalArgumentException e) { + e.printStackTrace(); + // Happens when the path is invalid. For instance absolute or relative to a path + // not part of the class output folder. + // + // Due to a bug in javac for Linux, this also occurs when no output path is specified + // for javac using the -d parameter. + // See http://forums.sun.com/thread.jspa?threadID=5240999&tstart=45 + // and http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6647996 + + return null; + } + + URI uri = resource.toUri(); + return new File(new File(uri).getParentFile(), "services"); + } + + void write(String serviceName, String value) throws IOException { + FileObject output = filer.createResource(StandardLocation.CLASS_OUTPUT, "", path + serviceName); + Writer writer = output.openWriter(); + writer.write("# Generated by " + name + "\n"); + writer.write("# " + new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.US).format(new Date()) + "\n"); + writer.write(value); + writer.close(); + } +} diff --git a/src/spiProcessor/lombok/spi/SpiProcessorService.java b/src/spiProcessor/lombok/spi/SpiProcessorService.java new file mode 100644 index 00000000..be8d5a21 --- /dev/null +++ b/src/spiProcessor/lombok/spi/SpiProcessorService.java @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2021 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 + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.spi; + +import java.util.Iterator; +import java.util.Set; +import java.util.TreeSet; +import java.util.stream.Collectors; + +import javax.lang.model.util.Elements; + +final class SpiProcessorService { + private final String name; + private final Set<String> providers = new TreeSet<String>(); + + SpiProcessorService(String name) { + if (name == null) throw new NullPointerException("name"); + this.name = name; + } + + public String getName() { + return name; + } + + void addProvider(String className) { + if (className == null) throw new NullPointerException("className"); + providers.add(className); + } + + boolean removeProvider(String provider) { + return providers.remove(provider); + } + + String toProvidersListFormat() { + return providers.stream().collect(Collectors.joining("\n")); + } + + void addAllFromProvidersNameList(String in) { + for (String line : in.split("\\n")) { + String[] content = line.split("#", 2); + if (content.length == 0) continue; + String trimmed = content[0].trim(); + String[] elems = trimmed.split("\\s+", 2); + if (elems.length == 0 || elems[0].isEmpty()) continue; + String cn = elems[0]; + addProvider(cn); + } + } + + void stripProvidersWithoutSourceFile(Elements elements) { + Iterator<String> it = providers.iterator(); + while (it.hasNext()) { + if (!sourceExists(elements, it.next())) it.remove(); + } + } + + private boolean sourceExists(Elements elements, String typeName) { + return elements.getTypeElement(typeName) != null; + } + + @Override public String toString() { + return name + " = " + providers; + } +} diff --git a/src/stubs/com/sun/tools/javac/parser/JavaTokenizer.java b/src/stubs/com/sun/tools/javac/parser/JavaTokenizer.java index 7d5bbcb1..cde6b325 100644 --- a/src/stubs/com/sun/tools/javac/parser/JavaTokenizer.java +++ b/src/stubs/com/sun/tools/javac/parser/JavaTokenizer.java @@ -1,11 +1,15 @@ package com.sun.tools.javac.parser; +import java.nio.CharBuffer; + import com.sun.tools.javac.parser.Tokens.Comment; import com.sun.tools.javac.parser.Tokens.Comment.CommentStyle; public class JavaTokenizer { + // used before java 16 protected UnicodeReader reader; + // used before java 16 protected JavaTokenizer(ScannerFactory fac, UnicodeReader reader) { } @@ -16,4 +20,17 @@ public class JavaTokenizer { protected Comment processComment(int pos, int endPos, CommentStyle style) { return null; } + + // used in java 16 + protected JavaTokenizer(ScannerFactory fac, char[] buf, int inputLength) { + } + + // used in java 16 + protected JavaTokenizer(ScannerFactory fac, CharBuffer buf) { + } + + // introduced in java 16 + protected int position() { + return -1; + } } diff --git a/src/utils/lombok/eclipse/Eclipse.java b/src/utils/lombok/eclipse/Eclipse.java index 31979955..8af481b9 100644 --- a/src/utils/lombok/eclipse/Eclipse.java +++ b/src/utils/lombok/eclipse/Eclipse.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2019 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -60,6 +60,13 @@ public class Eclipse { */ public static final int ECLIPSE_DO_NOT_TOUCH_FLAG = ASTNode.Bit24; + /* This section includes flags that are in ecj files too new vs. the deps we compile against. + * Specifically: org.eclipse.jdt.internal.compiler.ast.ASTNode and org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers + */ + public static final int AccRecord = ASTNode.Bit25; // ECM.AccRecord + public static final int IsCanonicalConstructor = ASTNode.Bit10; // ASTNode.IsCanonicalConstructor + public static final int IsImplicit = ASTNode.Bit11; // ASTNode.IsImplicit + private static final Pattern SPLIT_AT_DOT = Pattern.compile("\\."); private Eclipse() { @@ -239,9 +246,14 @@ public class Eclipse { for (Field f : CompilerOptions.class.getDeclaredFields()) { try { - if (f.getName().startsWith("VERSION_1_")) { - ecjCompilerVersionCached = Math.max(ecjCompilerVersionCached, Integer.parseInt(f.getName().substring("VERSION_1_".length()))); - } + String fName = f.getName(); + String versionNumber = null; + if (fName.startsWith("VERSION_1_")) { + versionNumber = fName.substring("VERSION_1_".length()); + } else if (fName.startsWith("VERSION_")) { + versionNumber = fName.substring("VERSION_".length()); + } else continue; + ecjCompilerVersionCached = Math.max(ecjCompilerVersionCached, Integer.parseInt(versionNumber)); } catch (Exception ignore) {} } diff --git a/src/utils/lombok/eclipse/Java14Bits.java b/src/utils/lombok/eclipse/Java14Bits.java new file mode 100644 index 00000000..c7e00c39 --- /dev/null +++ b/src/utils/lombok/eclipse/Java14Bits.java @@ -0,0 +1,11 @@ +package lombok.eclipse; + +import org.eclipse.jdt.internal.compiler.ast.ASTNode; + +public class Java14Bits { + private Java14Bits() { } + + public static final int AccRecord = ASTNode.Bit25; + public static final int IsCanonicalConstructor = ASTNode.Bit10; // record declaration + public static final int IsImplicit = ASTNode.Bit11; // record declaration / generated statements in compact constructor +} diff --git a/src/utils/lombok/javac/Java14Flags.java b/src/utils/lombok/javac/Java14Flags.java new file mode 100644 index 00000000..0d565dca --- /dev/null +++ b/src/utils/lombok/javac/Java14Flags.java @@ -0,0 +1,26 @@ +package lombok.javac; + +public class Java14Flags { + private Java14Flags() { } + + /** + * Flag to indicate that a class is a record. The flag is also used to mark fields that are + * part of the state vector of a record and to mark the canonical constructor + */ + public static final long RECORD = 1L<<61; // ClassSymbols, MethodSymbols and VarSymbols + + /** + * Flag to mark a record constructor as a compact one + */ + public static final long COMPACT_RECORD_CONSTRUCTOR = 1L<<51; // MethodSymbols only + + /** + * Flag to mark a record field that was not initialized in the compact constructor + */ + public static final long UNINITIALIZED_FIELD= 1L<<51; // VarSymbols only + + /** Flag is set for compiler-generated record members, it could be appplied to + * accessors and fields + */ + public static final int GENERATED_MEMBER = 1<<24; // MethodSymbols and VarSymbols +} diff --git a/src/utils/lombok/javac/Javac.java b/src/utils/lombok/javac/Javac.java index 33bd7265..c0bda93c 100644 --- a/src/utils/lombok/javac/Javac.java +++ b/src/utils/lombok/javac/Javac.java @@ -75,6 +75,12 @@ public class Javac { private static final AtomicInteger compilerVersion = new AtomicInteger(-1); + /* This section includes flags that would ordinarily be in Flags, but which are 'too new' (we don't compile against older versions of javac for compatibility). */ + public static final long RECORD = 1L << 61; // ClassSymbols, MethodSymbols, VarSymbols (Marks types as being records, as well as the 'fields' in the compact declaration, and the canonical constructor) + public static final long COMPACT_RECORD_CONSTRUCTOR = 1L << 51; // MethodSymbols (the 'implicit' many-args constructor that records have) + public static final long UNINITIALIZED_FIELD = 1L << 51; // VarSymbols (To identify fields that the compact record constructor won't initialize) + public static final long GENERATED_MEMBER = 1L << 24; // MethodSymbols, VarSymbols (marks methods and the constructor generated in records) + /** * Returns the version of this java compiler, i.e. the JDK that it shipped in. For example, for javac v1.7, this returns {@code 7}. */ @@ -279,6 +285,17 @@ public class Javac { return null; } + /** + * Checks if the javadoc comment associated with {@code tree} has a position set. + * + * Returns true if there is no javadoc comment on the node, or it has position (position isn't -1). + */ + public static boolean validateDocComment(JCCompilationUnit cu, JCTree tree) { + Object dc = getDocComments(cu); + if (!instanceOfDocCommentTable(dc)) return true; + return JavadocOps_8.validateJavadoc(dc, tree); + } + @SuppressWarnings("unchecked") public static void setDocComment(JCCompilationUnit cu, JCTree node, String javadoc) { if (javadoc == null) return; @@ -302,6 +319,12 @@ public class Javac { return javadoc.getText(); } + public static boolean validateJavadoc(Object dc, JCTree node) { + DocCommentTable dct = (DocCommentTable) dc; + Comment javadoc = dct.getComment(node); + return javadoc == null || javadoc.getText() == null || javadoc.getSourcePos(0) >= 0; + } + static void setJavadoc(Object dc, JCTree node, String javadoc) { DocCommentTable dct = (DocCommentTable) dc; Comment newCmt = createJavadocComment(javadoc, node); @@ -315,7 +338,7 @@ public class Javac { } @Override public int getSourcePos(int index) { - return -1; + return field == null ? -1 : field.getStartPosition(); } @Override public CommentStyle getStyle() { diff --git a/src/utils/lombok/javac/java8/CommentCollectingScannerFactory.java b/src/utils/lombok/javac/java8/CommentCollectingScannerFactory.java index cb0d2e12..f29f501b 100644 --- a/src/utils/lombok/javac/java8/CommentCollectingScannerFactory.java +++ b/src/utils/lombok/javac/java8/CommentCollectingScannerFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2019 The Project Lombok Authors. + * Copyright (C) 2011-2021 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 @@ -72,18 +72,31 @@ public class CommentCollectingScannerFactory extends ScannerFactory { super(context); } + @SuppressWarnings("all") @Override public Scanner newScanner(CharSequence input, boolean keepDocComments) { - if (input instanceof CharBuffer) { - CharBuffer buf = (CharBuffer) input; - return new CommentCollectingScanner(this, new CommentCollectingTokenizer(this, buf, findTextBlocks)); + char[] array; + int limit; + if (input instanceof CharBuffer && ((CharBuffer) input).hasArray()) { + CharBuffer cb = (CharBuffer) input; + cb.compact().flip(); + array = cb.array(); + limit = cb.limit(); + } else { + array = input.toString().toCharArray(); + limit = array.length; + } + if (array.length == limit) { + // work around a bug where the last comment in a file falls away in this case. + char[] d = new char[limit + 1]; + System.arraycopy(array, 0, d, 0, limit); + array = d; } - char[] array = input.toString().toCharArray(); - return newScanner(array, array.length, keepDocComments); + return newScanner(array, limit, keepDocComments); } @Override public Scanner newScanner(char[] input, int inputLength, boolean keepDocComments) { - return new CommentCollectingScanner(this, new CommentCollectingTokenizer(this, input, inputLength, findTextBlocks)); + return new CommentCollectingScanner(this, CommentCollectingTokenizer.create(this, input, inputLength, findTextBlocks)); } } diff --git a/src/utils/lombok/javac/java8/CommentCollectingTokenizer.java b/src/utils/lombok/javac/java8/CommentCollectingTokenizer.java index d7b1d569..4a31fc81 100644 --- a/src/utils/lombok/javac/java8/CommentCollectingTokenizer.java +++ b/src/utils/lombok/javac/java8/CommentCollectingTokenizer.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2020 The Project Lombok Authors. + * Copyright (C) 2013-2021 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 @@ -23,36 +23,51 @@ package lombok.javac.java8; import java.nio.CharBuffer; -import lombok.javac.CommentInfo; -import lombok.javac.CommentInfo.EndConnection; -import lombok.javac.CommentInfo.StartConnection; - import com.sun.tools.javac.parser.JavaTokenizer; import com.sun.tools.javac.parser.ScannerFactory; import com.sun.tools.javac.parser.Tokens.Comment; -import com.sun.tools.javac.parser.Tokens.Token; import com.sun.tools.javac.parser.Tokens.Comment.CommentStyle; +import com.sun.tools.javac.parser.Tokens.Token; import com.sun.tools.javac.parser.UnicodeReader; import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.ListBuffer; +import lombok.javac.CommentInfo; +import lombok.javac.CommentInfo.EndConnection; +import lombok.javac.CommentInfo.StartConnection; + class CommentCollectingTokenizer extends JavaTokenizer { + + private static final boolean tokenizerIsUnicodeReader = JavaTokenizer.class.getSuperclass().getSimpleName().equals("UnicodeReader"); + private int prevEndPosition = 0; private final ListBuffer<CommentInfo> comments = new ListBuffer<CommentInfo>(); private final ListBuffer<Integer> textBlockStarts; private int endComment = 0; - CommentCollectingTokenizer(ScannerFactory fac, char[] buf, int inputLength, boolean findTextBlocks) { + static CommentCollectingTokenizer create(ScannerFactory fac, char[] buf, int inputLength, boolean findTextBlocks) { + if (tokenizerIsUnicodeReader) { + return new CommentCollectingTokenizer(fac, buf, inputLength, findTextBlocks, true); + } + return new CommentCollectingTokenizer(fac, buf, inputLength, findTextBlocks); + } + + // pre java 16 + private CommentCollectingTokenizer(ScannerFactory fac, char[] buf, int inputLength, boolean findTextBlocks) { super(fac, new PositionUnicodeReader(fac, buf, inputLength)); textBlockStarts = findTextBlocks ? new ListBuffer<Integer>() : null; } - CommentCollectingTokenizer(ScannerFactory fac, CharBuffer buf, boolean findTextBlocks) { - super(fac, new PositionUnicodeReader(fac, buf)); + // from java 16 + private CommentCollectingTokenizer(ScannerFactory fac, char[] buf, int inputLength, boolean findTextBlocks, boolean java16Signature) { + super(fac, buf, inputLength); textBlockStarts = findTextBlocks ? new ListBuffer<Integer>() : null; } int pos() { + if (tokenizerIsUnicodeReader) { + return position(); + } return ((PositionUnicodeReader) reader).pos(); } @@ -60,8 +75,8 @@ class CommentCollectingTokenizer extends JavaTokenizer { Token token = super.readToken(); prevEndPosition = pos(); if (textBlockStarts != null && (prevEndPosition - token.pos > 5) && token.getClass().getName().endsWith("$StringToken")) { - char[] start = reader.getRawCharacters(token.pos, token.pos + 3); - if (start[0] == '"' && start[1] == '"' && start[2] == '"') textBlockStarts.add(token.pos); + char[] start = reader().getRawCharacters(token.pos, token.pos + 3); + if (start[0] == '"' && start[1] == '"' && start[2] == '"') textBlockStarts.append(token.pos); } return token; } @@ -70,7 +85,7 @@ class CommentCollectingTokenizer extends JavaTokenizer { protected Comment processComment(int pos, int endPos, CommentStyle style) { int prevEndPos = Math.max(prevEndPosition, endComment); endComment = endPos; - String content = new String(reader.getRawCharacters(pos, endPos)); + String content = new String(reader().getRawCharacters(pos, endPos)); StartConnection start = determineStartConnection(prevEndPos, pos); EndConnection end = determineEndConnection(endPos); @@ -85,7 +100,7 @@ class CommentCollectingTokenizer extends JavaTokenizer { for (int i = pos;; i++) { char c; try { - c = reader.getRawCharacters(i, i + 1)[0]; + c = reader().getRawCharacters(i, i + 1)[0]; } catch (IndexOutOfBoundsException e) { c = '\n'; } @@ -104,7 +119,7 @@ class CommentCollectingTokenizer extends JavaTokenizer { if (from == to) { return StartConnection.DIRECT_AFTER_PREVIOUS; } - char[] between = reader.getRawCharacters(from, to); + char[] between = reader().getRawCharacters(from, to); if (isNewLine(between[between.length - 1])) { return StartConnection.START_OF_LINE; } @@ -128,6 +143,13 @@ class CommentCollectingTokenizer extends JavaTokenizer { return textBlockStarts == null ? List.<Integer>nil() : textBlockStarts.toList(); } + private UnicodeReader reader() { + if (tokenizerIsUnicodeReader) { + return (UnicodeReader) (Object) this; + } + return reader; + } + static class PositionUnicodeReader extends UnicodeReader { protected PositionUnicodeReader(ScannerFactory sf, char[] input, int inputLength) { super(sf, input, inputLength); diff --git a/src/utils/lombok/permit/Permit.java b/src/utils/lombok/permit/Permit.java index edcc36b2..2854706e 100644 --- a/src/utils/lombok/permit/Permit.java +++ b/src/utils/lombok/permit/Permit.java @@ -122,6 +122,14 @@ public class Permit { return setAccessible(m); } + public static Method permissiveGetMethod(Class<?> c, String mName, Class<?>... parameterTypes) { + try { + return getMethod(c, mName, parameterTypes); + } catch (Exception ignore) { + return null; + } + } + public static Field getField(Class<?> c, String fName) throws NoSuchFieldException { Field f = null; Class<?> oc = c; diff --git a/src/utils/lombok/permit/dummy/Child.java b/src/utils/lombok/permit/dummy/Child.java new file mode 100644 index 00000000..c189ee37 --- /dev/null +++ b/src/utils/lombok/permit/dummy/Child.java @@ -0,0 +1,9 @@ +package lombok.permit.dummy; + +@SuppressWarnings("all") +public abstract class Child extends Parent { + private transient volatile boolean foo; + private transient volatile Object[] bar; + private transient volatile Object baz; + +} diff --git a/src/utils/lombok/permit/dummy/GrandChild.java b/src/utils/lombok/permit/dummy/GrandChild.java new file mode 100644 index 00000000..ef182aa7 --- /dev/null +++ b/src/utils/lombok/permit/dummy/GrandChild.java @@ -0,0 +1,19 @@ +package lombok.permit.dummy; + +@SuppressWarnings("all") +public final class GrandChild extends Child { + private Class<?> a; + private int b; + private String c; + private Class<?> d; + private Class<?>[] e; + private Class<?>[] f; + private int g; + private transient String h; + private transient Object i; + private byte[] j; + private byte[] k; + private byte[] l; + private volatile Object m; + private Object n; +} diff --git a/src/utils/lombok/permit/dummy/Parent.java b/src/utils/lombok/permit/dummy/Parent.java new file mode 100644 index 00000000..33928aeb --- /dev/null +++ b/src/utils/lombok/permit/dummy/Parent.java @@ -0,0 +1,12 @@ +package lombok.permit.dummy; + +import java.io.OutputStream; + +@SuppressWarnings("all") +public class Parent { + boolean first; + static final Object staticObj = OutputStream.class; + volatile Object second; + private static volatile boolean staticSecond; + private static volatile boolean staticThird; +} diff --git a/src/utils/lombok/permit/dummy/package-info.java b/src/utils/lombok/permit/dummy/package-info.java new file mode 100644 index 00000000..87ca839a --- /dev/null +++ b/src/utils/lombok/permit/dummy/package-info.java @@ -0,0 +1,8 @@ +/** + * This package recreates the type hierarchy of {@code java.lang.reflect.AccessibleObject} and friends (such as {@code java.lang.reflect.Method}); + * its purpose is to allow us to ask {@code sun.misc.internal.Unsafe} about the exact offset of the {@code override} field of {@code AccessibleObject}; + * asking about that field directly doesn't work after jdk14, presumably because the fields of AO are expressly hidden somehow. + * + * NB: It's usually 12, on the vast majority of OS, VM, and architecture combos. + */ +package lombok.permit.dummy; diff --git a/test/bytecode/src/lombok/bytecode/TestClassFileMetaData.java b/test/bytecode/src/lombok/bytecode/TestClassFileMetaData.java index 335455fd..7aef0d51 100644 --- a/test/bytecode/src/lombok/bytecode/TestClassFileMetaData.java +++ b/test/bytecode/src/lombok/bytecode/TestClassFileMetaData.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 The Project Lombok Authors. + * Copyright (C) 2010-2021 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 @@ -56,7 +56,7 @@ public class TestClassFileMetaData { public void testGetClassName() { assertTrue(foo.containsUtf8("Foo")); assertEquals("Foo", foo.getClassName()); - + assertTrue(bar.containsUtf8("Bar")); assertEquals("Bar", bar.getClassName()); @@ -68,15 +68,13 @@ public class TestClassFileMetaData { public void testGetSuperClassName() { assertTrue(foo.containsUtf8("java/lang/Object")); assertEquals("java/lang/Object", foo.getSuperClassName()); - + assertEquals("java/lang/Object", bar.getSuperClassName()); assertEquals("java/lang/Object", baz.getSuperClassName()); assertEquals("java/util/ArrayList", buux.getSuperClassName()); } - - @Test public void testUsesClass() { assertTrue(foo.usesClass("java/lang/System")); @@ -185,6 +183,22 @@ public class TestClassFileMetaData { static byte[] compile(File file) { try { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); + if (compiler == null) { + // The 'auto-find my compiler' code in java6 works because it hard-codes `c.s.t.j.a.JavacTool`, which we put on the classpath. + // On java8, it fails, because it looks for tools.jar, which won't be there. + // on J11+ place it succeeds again, as we run those on the real JDKs. + + // Thus, let's try this, in cae we're on java 8: + + try { + compiler = (JavaCompiler) Class.forName("com.sun.tools.javac.api.JavacTool").getConstructor().newInstance(); + } catch (Exception e) { + compiler = null; + } + } + + if (compiler == null) throw new RuntimeException("No javac tool is available in this distribution. Using an old JRE perhaps?"); + File tempDir = getTempDir(); tempDir.mkdirs(); List<String> options = Arrays.asList("-proc:none", "-d", tempDir.getAbsolutePath()); @@ -199,7 +213,7 @@ public class TestClassFileMetaData { CompilationTask task = compiler.getTask(captureWarnings, null, diagnostics, options, null, Collections.singleton(new ContentBasedJavaFileObject(file.getPath(), readFileAsString(file)))); Boolean taskResult = task.call(); - assertTrue("Compilation task didn't succeed: \n<Warnings and Errors>\n" + compilerErrors.toString() + "\n</Warnings and Errors>", taskResult); + assertTrue("Compilation task didn't succeed: \n<Warnings and Errors>\n" + compilerErrors.toString() + "\n" + captureWarnings.toString() + "\n</Warnings and Errors>", taskResult); return PostCompilerApp.readFile(new File(tempDir, file.getName().replaceAll("\\.java$", ".class"))); } catch (Exception e) { throw Lombok.sneakyThrow(e); diff --git a/test/core/src/lombok/AbstractRunTests.java b/test/core/src/lombok/AbstractRunTests.java index 448f77ab..51ec41c5 100644 --- a/test/core/src/lombok/AbstractRunTests.java +++ b/test/core/src/lombok/AbstractRunTests.java @@ -48,6 +48,7 @@ import lombok.core.configuration.ConfigurationResolver; import lombok.core.configuration.ConfigurationResolverFactory; import lombok.javac.CapturingDiagnosticListener.CompilerMessage; import lombok.transform.TestLombokFilesIdempotent; +import lombok.transform.TestSourceFiles; public abstract class AbstractRunTests { private final File dumpActualFilesHere; @@ -91,7 +92,9 @@ public abstract class AbstractRunTests { } }); - boolean changed = transformCode(messages, writer, file, sourceDirectives_.getSpecifiedEncoding(), sourceDirectives_.getFormatPreferences(), sourceDirectives_.minVersion()); + boolean checkPositions = !(params instanceof TestLombokFilesIdempotent || params instanceof TestSourceFiles) && !sourceDirectives_.isSkipCompareContent(); + + boolean changed = transformCode(messages, writer, file, sourceDirectives_.getSpecifiedEncoding(), sourceDirectives_.getFormatPreferences(), sourceDirectives_.minVersion(), checkPositions); boolean forceUnchanged = sourceDirectives_.forceUnchanged() || sourceDirectives_.isSkipCompareContent(); if (params.expectChanges() && !forceUnchanged && !changed) messages.add(new CompilerMessage(-1, -1, true, "not flagged modified")); if (!params.expectChanges() && changed) messages.add(new CompilerMessage(-1, -1, true, "unexpected modification")); @@ -101,7 +104,7 @@ public abstract class AbstractRunTests { }; } - protected abstract boolean transformCode(Collection<CompilerMessage> messages, StringWriter result, File file, String encoding, Map<String, String> formatPreferences, int minVersion) throws Throwable; + protected abstract boolean transformCode(Collection<CompilerMessage> messages, StringWriter result, File file, String encoding, Map<String, String> formatPreferences, int minVersion, boolean checkPositions) throws Throwable; protected String readFile(File file) throws IOException { BufferedReader reader; diff --git a/test/core/src/lombok/DirectoryRunner.java b/test/core/src/lombok/DirectoryRunner.java index 93b18039..b041c42e 100644 --- a/test/core/src/lombok/DirectoryRunner.java +++ b/test/core/src/lombok/DirectoryRunner.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2020 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -78,6 +78,9 @@ public class DirectoryRunner extends Runner { } public abstract boolean expectChanges(); + public String testNamePrefix() { + return ""; + } } private static final FileFilter JAVA_FILE_FILTER = new FileFilter() { @@ -114,8 +117,7 @@ public class DirectoryRunner extends Runner { Throwable error = null; try { addTests(testClass); - } - catch (Throwable t) { + } catch (Throwable t) { error = t; } this.failure = error; @@ -124,7 +126,7 @@ public class DirectoryRunner extends Runner { private void addTests(Class<?> testClass) throws Exception { for (File file : params.getBeforeDirectory().listFiles(JAVA_FILE_FILTER)) { if (!params.accept(file)) continue; - Description testDescription = Description.createTestDescription(testClass, file.getName()); + Description testDescription = Description.createTestDescription(testClass, this.params.testNamePrefix() + file.getName()); description.addChild(testDescription); tests.put(file.getName(), testDescription); } diff --git a/test/core/src/lombok/LombokTestSource.java b/test/core/src/lombok/LombokTestSource.java index 1498e635..0326dee9 100644 --- a/test/core/src/lombok/LombokTestSource.java +++ b/test/core/src/lombok/LombokTestSource.java @@ -374,4 +374,8 @@ public class LombokTestSource { public int minVersion() { return Math.max(6, versionLowerLimit); } + + public int maxVersion() { + return versionUpperLimit; + } } diff --git a/test/core/src/lombok/RunTestsViaDelombok.java b/test/core/src/lombok/RunTestsViaDelombok.java index ffac8372..46eb54a0 100644 --- a/test/core/src/lombok/RunTestsViaDelombok.java +++ b/test/core/src/lombok/RunTestsViaDelombok.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2014 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -21,24 +21,53 @@ */ package lombok; +import static org.junit.Assert.fail; + import java.io.ByteArrayOutputStream; import java.io.File; import java.io.PrintStream; import java.io.StringWriter; import java.io.UnsupportedEncodingException; +import java.util.ArrayDeque; import java.util.Collection; +import java.util.Collections; +import java.util.Deque; import java.util.Locale; import java.util.Map; +import java.util.Set; + +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.ProcessingEnvironment; +import javax.annotation.processing.RoundEnvironment; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.Element; +import javax.lang.model.element.TypeElement; + +import com.sun.source.util.TreePath; +import com.sun.source.util.Trees; +import com.sun.tools.javac.code.Flags; +import com.sun.tools.javac.tree.JCTree; +import com.sun.tools.javac.tree.TreeScanner; +import com.sun.tools.javac.tree.JCTree.JCAnnotation; +import com.sun.tools.javac.tree.JCTree.JCAssign; +import com.sun.tools.javac.tree.JCTree.JCClassDecl; +import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; +import com.sun.tools.javac.tree.JCTree.JCIdent; +import com.sun.tools.javac.tree.JCTree.JCMethodDecl; +import com.sun.tools.javac.tree.JCTree.JCModifiers; +import com.sun.tools.javac.tree.JCTree.JCVariableDecl; +import com.sun.tools.javac.tree.JCTree.TypeBoundKind; import lombok.delombok.Delombok; import lombok.javac.CapturingDiagnosticListener; +import lombok.javac.Javac; import lombok.javac.CapturingDiagnosticListener.CompilerMessage; public class RunTestsViaDelombok extends AbstractRunTests { private Delombok delombok = new Delombok(); @Override - public boolean transformCode(Collection<CompilerMessage> messages, StringWriter result, final File file, String encoding, Map<String, String> formatPreferences, int version) throws Throwable { + public boolean transformCode(Collection<CompilerMessage> messages, StringWriter result, final File file, String encoding, Map<String, String> formatPreferences, int version, boolean checkPositions) throws Throwable { delombok.setVerbose(true); ChangedChecker cc = new ChangedChecker(); delombok.setFeedback(cc.feedback); @@ -48,6 +77,8 @@ public class RunTestsViaDelombok extends AbstractRunTests { delombok.setDiagnosticsListener(new CapturingDiagnosticListener(file, messages)); + if (checkPositions) delombok.addAdditionalAnnotationProcessor(new ValidatePositionProcessor(version)); + delombok.addFile(file.getAbsoluteFile().getParentFile(), file.getName()); delombok.setSourcepath(file.getAbsoluteFile().getParent()); String bcp = System.getProperty("delombok.bootclasspath"); @@ -63,6 +94,134 @@ public class RunTestsViaDelombok extends AbstractRunTests { } } + public static class ValidatePositionProcessor extends TreeProcessor { + private final int version; + + public ValidatePositionProcessor(int version) { + this.version = version; + } + + private String craftFailMsg(String problematicNode, Deque<JCTree> astContext) { + StringBuilder msg = new StringBuilder(problematicNode).append(" position of node not set: "); + for (JCTree t : astContext) { + msg.append("\n ").append(t.getClass().getSimpleName()); + String asStr = t.toString(); + if (asStr.length() < 80) msg.append(": ").append(asStr); + else if (t instanceof JCClassDecl) msg.append(": ").append(((JCClassDecl) t).name); + else if (t instanceof JCMethodDecl) msg.append(": ").append(((JCMethodDecl) t).name); + else if (t instanceof JCVariableDecl) msg.append(": ").append(((JCVariableDecl) t).name); + } + return msg.append("\n-------").toString(); + } + + @Override void processCompilationUnit(final JCCompilationUnit unit) { + final Deque<JCTree> astContext = new ArrayDeque<JCTree>(); + unit.accept(new TreeScanner() { + @Override public void scan(JCTree tree) { + if (tree == null) return; + if (tree instanceof JCMethodDecl && (((JCMethodDecl) tree).mods.flags & Flags.GENERATEDCONSTR) != 0) return; + astContext.push(tree); + try { + if (tree instanceof JCModifiers) return; + + if (!Javac.validateDocComment(unit, tree)) { + fail("Start position of doc comment (" + Javac.getDocComment(unit, tree) + ") of " + tree + " not set"); + } + + boolean check = true; + if (version < 8 && tree instanceof TypeBoundKind) { + // TypeBoundKind works differently in java6, and as a consequence, + // the position is not set properly. + // Given status of j6/j7, not worth properly testing. + check = false; + } + if (version < 8 && tree instanceof JCIdent) { + // explicit `super()` invocations do not appear to have end pos in j6/7. + if ("super".equals("" + ((JCIdent) tree).name)) check = false; + } + + if (tree instanceof JCVariableDecl && (((JCVariableDecl) tree).mods.flags & Javac.GENERATED_MEMBER) != 0) return; + + if (check && tree.pos == -1) fail(craftFailMsg("Start", astContext)); + + if (check && Javac.getEndPosition(tree, unit) == -1) { + fail(craftFailMsg("End", astContext)); + } + } finally { + try { + super.scan(tree); + } finally { + astContext.pop(); + } + } + } + + @Override public void visitMethodDef(JCMethodDecl tree) { + super.visitMethodDef(tree); + } + + @Override public void visitVarDef(JCVariableDecl tree) { + if ((tree.mods.flags & Flags.ENUM) != 0) return; + super.visitVarDef(tree); + } + + @Override public void visitAnnotation(JCAnnotation tree) { + scan(tree.annotationType); + // Javac parser maps @Annotation("val") to @Annotation(value = "val") but does not add an end position for the new JCIdent... + if (tree.args.length() == 1 && tree.args.head instanceof JCAssign && ((JCIdent)((JCAssign) tree.args.head).lhs).name.toString().equals("value")) { + scan(((JCAssign) tree.args.head).rhs); + } else { + scan(tree.args); + } + } + }); + } + } + + public static abstract class TreeProcessor extends AbstractProcessor { + private Trees trees; + @Override public synchronized void init(ProcessingEnvironment processingEnv) { + super.init(processingEnv); + trees = Trees.instance(processingEnv); + } + + @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { + for (Element element : roundEnv.getRootElements()) { + JCCompilationUnit unit = toUnit(element); + if (unit != null) { + processCompilationUnit(unit); + } + } + return false; + } + + abstract void processCompilationUnit(JCCompilationUnit unit); + + @Override public Set<String> getSupportedAnnotationTypes() { + return Collections.singleton("*"); + } + + @Override public SourceVersion getSupportedSourceVersion() { + return SourceVersion.latest(); + } + + private JCCompilationUnit toUnit(Element element) { + TreePath path = null; + if (trees != null) { + try { + path = trees.getPath(element); + } catch (NullPointerException ignore) { + // Happens if a package-info.java dowsn't conatin a package declaration. + // https://github.com/rzwitserloot/lombok/issues/2184 + // We can safely ignore those, since they do not need any processing + } + } + if (path == null) return null; + + return (JCCompilationUnit) path.getCompilationUnit(); + } + } + static class ChangedChecker { private final ByteArrayOutputStream bytes = new ByteArrayOutputStream(); private final PrintStream feedback; diff --git a/test/core/src/lombok/RunTestsViaEcj.java b/test/core/src/lombok/RunTestsViaEcj.java index 1d840a21..afba8c7f 100644 --- a/test/core/src/lombok/RunTestsViaEcj.java +++ b/test/core/src/lombok/RunTestsViaEcj.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2020 The Project Lombok Authors. + * Copyright (C) 2010-2021 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 @@ -83,6 +83,10 @@ public class RunTestsViaEcj extends AbstractRunTests { warnings.put(CompilerOptions.OPTION_ReportUnusedLabel, "ignore"); warnings.put(CompilerOptions.OPTION_ReportUnusedImport, "ignore"); warnings.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, "ignore"); + warnings.put(CompilerOptions.OPTION_ReportIndirectStaticAccess, "warning"); + warnings.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, "warning"); + warnings.put("org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures", "enabled"); + warnings.put("org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures", "ignore"); int ecjVersion = Eclipse.getEcjCompilerVersion(); warnings.put(CompilerOptions.OPTION_Source, (ecjVersion < 9 ? "1." : "") + ecjVersion); options.set(warnings); @@ -106,8 +110,13 @@ public class RunTestsViaEcj extends AbstractRunTests { }; } + private ICompilationUnit getSourceUnit(File file, String source) { + if (eclipseAvailable()) return new TestCompilationUnitEclipse(file.getName(), source); + return new TestCompilationUnitEcj(file.getName(), source); + } + @Override - public boolean transformCode(Collection<CompilerMessage> messages, StringWriter result, File file, String encoding, Map<String, String> formatPreferences, int minVersion) throws Throwable { + public boolean transformCode(Collection<CompilerMessage> messages, StringWriter result, File file, String encoding, Map<String, String> formatPreferences, int minVersion, boolean checkPositions) throws Throwable { final AtomicReference<CompilationResult> compilationResult_ = new AtomicReference<CompilationResult>(); final AtomicReference<CompilationUnitDeclaration> compilationUnit_ = new AtomicReference<CompilationUnitDeclaration>(); ICompilerRequestor bitbucketRequestor = new ICompilerRequestor() { @@ -120,11 +129,7 @@ public class RunTestsViaEcj extends AbstractRunTests { char[] sourceArray = source.toCharArray(); final ICompilationUnit sourceUnit; try { - if (eclipseAvailable()) { - sourceUnit = new TestCompilationUnitEclipse(file.getName(), source); - } else { - sourceUnit = new TestCompilationUnitEcj(file.getName(), source); - } + sourceUnit = getSourceUnit(file, source); } catch (Throwable t) { t.printStackTrace(); return false; @@ -151,7 +156,12 @@ public class RunTestsViaEcj extends AbstractRunTests { CompilationUnitDeclaration cud = compilationUnit_.get(); if (cud == null) result.append("---- No CompilationUnit provided by ecj ----"); - else result.append(cud.toString()); + else { + String output = cud.toString(); + // starting somewhere around ecj16, the print code is a bit too cavalier with printing modifiers. + output = output.replace("non-sealed @val", "@val"); + result.append(output); + } if (eclipseAvailable()) { EclipseDomConversion.toDomAst(cud, sourceArray); @@ -226,6 +236,7 @@ public class RunTestsViaEcj extends AbstractRunTests { } if (new File("bin/main").exists()) classpath.add("bin/main"); classpath.add("dist/lombok.jar"); + classpath.add("build/teststubs"); if (bootRuntimePath == null || bootRuntimePath.isEmpty()) throw new IllegalStateException("System property delombok.bootclasspath is not set; set it to the rt of java6 or java8"); classpath.add(bootRuntimePath); for (File f : new File("lib/test").listFiles()) { diff --git a/test/stubs/java/lang/Record.java b/test/stubs/java/lang/Record.java new file mode 100644 index 00000000..e985bb45 --- /dev/null +++ b/test/stubs/java/lang/Record.java @@ -0,0 +1,3 @@ +package java.lang; + +public abstract class Record {} diff --git a/test/stubs/java/lang/runtime/ObjectMethods.java b/test/stubs/java/lang/runtime/ObjectMethods.java new file mode 100644 index 00000000..519563ae --- /dev/null +++ b/test/stubs/java/lang/runtime/ObjectMethods.java @@ -0,0 +1,12 @@ +package java.lang.runtime; + +// import java.lang.invoke.MethodHandle; +// import java.lang.invoke.MethodHandles; +// import java.lang.invoke.TypeDescriptor; + +public class ObjectMethods { +// public static Object bootstrap(MethodHandles.Lookup lookup, String methodName, TypeDescriptor type, Class<?> recordClass, String names, MethodHandle... getters) throws Throwable { + public static Object bootstrap(Object lookup, String methodName, Object type, Class<?> recordClass, String names, Object... getters) throws Throwable { + return null; + } +} diff --git a/test/transform/resource/after-delombok/BuilderAccessWithGetter.java b/test/transform/resource/after-delombok/BuilderAccessWithGetter.java new file mode 100644 index 00000000..f36403bf --- /dev/null +++ b/test/transform/resource/after-delombok/BuilderAccessWithGetter.java @@ -0,0 +1,49 @@ +public final class BuilderAccessWithGetter { + private final String string; + + @java.lang.SuppressWarnings("all") + BuilderAccessWithGetter(final String string) { + this.string = string; + } + + + @java.lang.SuppressWarnings("all") + private static class BuilderAccessWithGetterBuilder { + @java.lang.SuppressWarnings("all") + private String string; + + @java.lang.SuppressWarnings("all") + BuilderAccessWithGetterBuilder() { + } + + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + private BuilderAccessWithGetter.BuilderAccessWithGetterBuilder string(final String string) { + this.string = string; + return this; + } + + @java.lang.SuppressWarnings("all") + private BuilderAccessWithGetter build() { + return new BuilderAccessWithGetter(this.string); + } + + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "BuilderAccessWithGetter.BuilderAccessWithGetterBuilder(string=" + this.string + ")"; + } + } + + @java.lang.SuppressWarnings("all") + private static BuilderAccessWithGetter.BuilderAccessWithGetterBuilder builder() { + return new BuilderAccessWithGetter.BuilderAccessWithGetterBuilder(); + } + + @java.lang.SuppressWarnings("all") + public String getString() { + return this.string; + } +} diff --git a/test/transform/resource/after-delombok/BuilderDefaultsWarnings.java b/test/transform/resource/after-delombok/BuilderDefaultsWarnings.java index 2b0a6d3b..c7e37abe 100644 --- a/test/transform/resource/after-delombok/BuilderDefaultsWarnings.java +++ b/test/transform/resource/after-delombok/BuilderDefaultsWarnings.java @@ -1,6 +1,4 @@ //skip-idempotent -import lombok.Builder; -@Builder public class BuilderDefaultsWarnings { long x = System.currentTimeMillis(); final int y = 5; @@ -87,7 +85,6 @@ public class BuilderDefaultsWarnings { } class NoBuilderButHasDefaults { private final long z = 5; - @Builder public NoBuilderButHasDefaults() { } @java.lang.SuppressWarnings("all") diff --git a/test/transform/resource/after-delombok/BuilderJavadoc.java b/test/transform/resource/after-delombok/BuilderJavadoc.java index c99bfe90..f7caa2d6 100644 --- a/test/transform/resource/after-delombok/BuilderJavadoc.java +++ b/test/transform/resource/after-delombok/BuilderJavadoc.java @@ -3,7 +3,6 @@ class BuilderJavadoc<T> { /** * basic gets only a builder setter. * @see #getsetwith - * * @return tag is removed from the setter. */ private final int basic; @@ -92,7 +91,6 @@ class BuilderJavadoc<T> { } /** * getsetwith gets a builder setter, an instance getter and setter, and a wither. - * * @return tag is moved to the getter. */ @java.lang.SuppressWarnings("all") diff --git a/test/transform/resource/after-delombok/BuilderSimpleOnRecord.java b/test/transform/resource/after-delombok/BuilderSimpleOnRecord.java new file mode 100644 index 00000000..acb6f20a --- /dev/null +++ b/test/transform/resource/after-delombok/BuilderSimpleOnRecord.java @@ -0,0 +1,43 @@ +// version 14: +import java.util.List; +public record BuilderSimpleOnRecord<T>(List<T> l, String a) { + @java.lang.SuppressWarnings("all") + protected static class BuilderSimpleOnRecordBuilder<T> { + @java.lang.SuppressWarnings("all") + private List<T> l; + @java.lang.SuppressWarnings("all") + private String a; + @java.lang.SuppressWarnings("all") + BuilderSimpleOnRecordBuilder() { + } + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public BuilderSimpleOnRecord.BuilderSimpleOnRecordBuilder<T> l(final List<T> l) { + this.l = l; + return this; + } + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public BuilderSimpleOnRecord.BuilderSimpleOnRecordBuilder<T> a(final String a) { + this.a = a; + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSimpleOnRecord<T> build() { + return new BuilderSimpleOnRecord<T>(this.l, this.a); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "BuilderSimpleOnRecord.BuilderSimpleOnRecordBuilder(l=" + this.l + ", a=" + this.a + ")"; + } + } + @java.lang.SuppressWarnings("all") + protected static <T> BuilderSimpleOnRecord.BuilderSimpleOnRecordBuilder<T> builder() { + return new BuilderSimpleOnRecord.BuilderSimpleOnRecordBuilder<T>(); + } +} diff --git a/test/transform/resource/after-delombok/BuilderSingularAnnotatedTypes.java b/test/transform/resource/after-delombok/BuilderSingularAnnotatedTypes.java index f6fa22de..7568d812 100644 --- a/test/transform/resource/after-delombok/BuilderSingularAnnotatedTypes.java +++ b/test/transform/resource/after-delombok/BuilderSingularAnnotatedTypes.java @@ -1,3 +1,4 @@ +//version 8: import java.lang.annotation.ElementType; import java.lang.annotation.Target; import java.util.Set; diff --git a/test/transform/resource/after-delombok/BuilderSingularAnnotatedTypesWithSetterPrefix.java b/test/transform/resource/after-delombok/BuilderSingularAnnotatedTypesWithSetterPrefix.java index 6dbbeee4..d58caf4d 100644 --- a/test/transform/resource/after-delombok/BuilderSingularAnnotatedTypesWithSetterPrefix.java +++ b/test/transform/resource/after-delombok/BuilderSingularAnnotatedTypesWithSetterPrefix.java @@ -1,3 +1,4 @@ +//version 8: import java.lang.annotation.ElementType; import java.lang.annotation.Target; import java.util.Set; diff --git a/test/transform/resource/after-delombok/BuilderSingularNoAuto.java b/test/transform/resource/after-delombok/BuilderSingularNoAuto.java index 8c30f926..de86383f 100644 --- a/test/transform/resource/after-delombok/BuilderSingularNoAuto.java +++ b/test/transform/resource/after-delombok/BuilderSingularNoAuto.java @@ -1,6 +1,5 @@ //skip-idempotent import java.util.List; -@lombok.Builder class BuilderSingularNoAuto { private List<String> things; private List<String> widgets; diff --git a/test/transform/resource/after-delombok/BuilderSingularNoAutoWithSetterPrefix.java b/test/transform/resource/after-delombok/BuilderSingularNoAutoWithSetterPrefix.java index 4207cf74..8858f145 100644 --- a/test/transform/resource/after-delombok/BuilderSingularNoAutoWithSetterPrefix.java +++ b/test/transform/resource/after-delombok/BuilderSingularNoAutoWithSetterPrefix.java @@ -1,6 +1,5 @@ //skip-idempotent import java.util.List; -@lombok.Builder(setterPrefix = "with") class BuilderSingularNoAutoWithSetterPrefix { private List<String> things; private List<String> widgets; diff --git a/test/transform/resource/after-delombok/BuilderSingularNullBehavior1.java b/test/transform/resource/after-delombok/BuilderSingularNullBehavior1.java index 32ad0a68..45ff97fa 100644 --- a/test/transform/resource/after-delombok/BuilderSingularNullBehavior1.java +++ b/test/transform/resource/after-delombok/BuilderSingularNullBehavior1.java @@ -1,3 +1,4 @@ +//version 8: import java.util.List; import java.util.Collection; class BuilderSingularNullBehavior1 { diff --git a/test/transform/resource/after-delombok/BuilderSingularNullBehavior2.java b/test/transform/resource/after-delombok/BuilderSingularNullBehavior2.java index e70877bf..5f605de4 100644 --- a/test/transform/resource/after-delombok/BuilderSingularNullBehavior2.java +++ b/test/transform/resource/after-delombok/BuilderSingularNullBehavior2.java @@ -1,3 +1,4 @@ +//version 8: springframework dep is too new to run on j6 import java.util.List; class BuilderSingularNullBehavior2 { private List<String> locations; diff --git a/test/transform/resource/after-delombok/BuilderSingularOnRecord.java b/test/transform/resource/after-delombok/BuilderSingularOnRecord.java new file mode 100644 index 00000000..0aaa12cd --- /dev/null +++ b/test/transform/resource/after-delombok/BuilderSingularOnRecord.java @@ -0,0 +1,123 @@ +// version 14: +import java.util.Collection; +import java.util.List; +public record BuilderSingularOnRecord<T>(List<T> children, Collection<? extends Number> scarves, @SuppressWarnings("all") List rawList) { + @java.lang.SuppressWarnings("all") + public static class BuilderSingularOnRecordBuilder<T> { + @java.lang.SuppressWarnings("all") + private java.util.ArrayList<T> children; + @java.lang.SuppressWarnings("all") + private java.util.ArrayList<Number> scarves; + @java.lang.SuppressWarnings("all") + private java.util.ArrayList<java.lang.Object> rawList; + @java.lang.SuppressWarnings("all") + BuilderSingularOnRecordBuilder() { + } + @java.lang.SuppressWarnings("all") + public BuilderSingularOnRecord.BuilderSingularOnRecordBuilder<T> child(final T child) { + if (this.children == null) this.children = new java.util.ArrayList<T>(); + this.children.add(child); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularOnRecord.BuilderSingularOnRecordBuilder<T> children(final java.util.Collection<? extends T> children) { + if (children == null) { + throw new java.lang.NullPointerException("children cannot be null"); + } + if (this.children == null) this.children = new java.util.ArrayList<T>(); + this.children.addAll(children); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularOnRecord.BuilderSingularOnRecordBuilder<T> clearChildren() { + if (this.children != null) this.children.clear(); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularOnRecord.BuilderSingularOnRecordBuilder<T> scarf(final Number scarf) { + if (this.scarves == null) this.scarves = new java.util.ArrayList<Number>(); + this.scarves.add(scarf); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularOnRecord.BuilderSingularOnRecordBuilder<T> scarves(final java.util.Collection<? extends Number> scarves) { + if (scarves == null) { + throw new java.lang.NullPointerException("scarves cannot be null"); + } + if (this.scarves == null) this.scarves = new java.util.ArrayList<Number>(); + this.scarves.addAll(scarves); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularOnRecord.BuilderSingularOnRecordBuilder<T> clearScarves() { + if (this.scarves != null) this.scarves.clear(); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularOnRecord.BuilderSingularOnRecordBuilder<T> rawList(final java.lang.Object rawList) { + if (this.rawList == null) this.rawList = new java.util.ArrayList<java.lang.Object>(); + this.rawList.add(rawList); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularOnRecord.BuilderSingularOnRecordBuilder<T> rawList(final java.util.Collection<?> rawList) { + if (rawList == null) { + throw new java.lang.NullPointerException("rawList cannot be null"); + } + if (this.rawList == null) this.rawList = new java.util.ArrayList<java.lang.Object>(); + this.rawList.addAll(rawList); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularOnRecord.BuilderSingularOnRecordBuilder<T> clearRawList() { + if (this.rawList != null) this.rawList.clear(); + return this; + } + @java.lang.SuppressWarnings("all") + public BuilderSingularOnRecord<T> build() { + java.util.List<T> children; + switch (this.children == null ? 0 : this.children.size()) { + case 0: + children = java.util.Collections.emptyList(); + break; + case 1: + children = java.util.Collections.singletonList(this.children.get(0)); + break; + default: + children = java.util.Collections.unmodifiableList(new java.util.ArrayList<T>(this.children)); + } + java.util.Collection<Number> scarves; + switch (this.scarves == null ? 0 : this.scarves.size()) { + case 0: + scarves = java.util.Collections.emptyList(); + break; + case 1: + scarves = java.util.Collections.singletonList(this.scarves.get(0)); + break; + default: + scarves = java.util.Collections.unmodifiableList(new java.util.ArrayList<Number>(this.scarves)); + } + java.util.List<java.lang.Object> rawList; + switch (this.rawList == null ? 0 : this.rawList.size()) { + case 0: + rawList = java.util.Collections.emptyList(); + break; + case 1: + rawList = java.util.Collections.singletonList(this.rawList.get(0)); + break; + default: + rawList = java.util.Collections.unmodifiableList(new java.util.ArrayList<java.lang.Object>(this.rawList)); + } + return new BuilderSingularOnRecord<T>(children, scarves, rawList); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "BuilderSingularOnRecord.BuilderSingularOnRecordBuilder(children=" + this.children + ", scarves=" + this.scarves + ", rawList=" + this.rawList + ")"; + } + } + @java.lang.SuppressWarnings("all") + public static <T> BuilderSingularOnRecord.BuilderSingularOnRecordBuilder<T> builder() { + return new BuilderSingularOnRecord.BuilderSingularOnRecordBuilder<T>(); + } +} diff --git a/test/transform/resource/after-delombok/BuilderWithNonNull.java b/test/transform/resource/after-delombok/BuilderWithNonNull.java index c9c37542..00728ea7 100644 --- a/test/transform/resource/after-delombok/BuilderWithNonNull.java +++ b/test/transform/resource/after-delombok/BuilderWithNonNull.java @@ -1,3 +1,4 @@ +//version 8: class BuilderWithNonNull { @lombok.NonNull private final String id; diff --git a/test/transform/resource/after-delombok/BuilderWithNonNullWithSetterPrefix.java b/test/transform/resource/after-delombok/BuilderWithNonNullWithSetterPrefix.java index ec8ed514..f6dfed67 100644 --- a/test/transform/resource/after-delombok/BuilderWithNonNullWithSetterPrefix.java +++ b/test/transform/resource/after-delombok/BuilderWithNonNullWithSetterPrefix.java @@ -1,3 +1,4 @@ +//version 8: class BuilderWithNonNullWithSetterPrefix { @lombok.NonNull private final String id; diff --git a/test/transform/resource/after-delombok/CheckerFrameworkBasic.java b/test/transform/resource/after-delombok/CheckerFrameworkBasic.java index f7f38b29..2beafc4c 100644 --- a/test/transform/resource/after-delombok/CheckerFrameworkBasic.java +++ b/test/transform/resource/after-delombok/CheckerFrameworkBasic.java @@ -1,3 +1,4 @@ +//version 8: class CheckerFrameworkBasic { private final int x; private final int y; diff --git a/test/transform/resource/after-delombok/CheckerFrameworkSuperBuilder.java b/test/transform/resource/after-delombok/CheckerFrameworkSuperBuilder.java index 919a3e33..8dcdaf10 100644 --- a/test/transform/resource/after-delombok/CheckerFrameworkSuperBuilder.java +++ b/test/transform/resource/after-delombok/CheckerFrameworkSuperBuilder.java @@ -1,4 +1,4 @@ -// skip-idempotent +//version 8: import java.util.List; class CheckerFrameworkSuperBuilder { public static class Parent { @@ -128,7 +128,7 @@ class CheckerFrameworkSuperBuilder { } @org.checkerframework.dataflow.qual.SideEffectFree @java.lang.SuppressWarnings("all") - public static CheckerFrameworkSuperBuilder.Parent.ParentBuilder<?, ?> builder() { + public static CheckerFrameworkSuperBuilder.Parent.@org.checkerframework.common.aliasing.qual.Unique ParentBuilder<?, ?> builder() { return new CheckerFrameworkSuperBuilder.Parent.ParentBuilderImpl(); } } @@ -211,7 +211,7 @@ class CheckerFrameworkSuperBuilder { } @org.checkerframework.dataflow.qual.SideEffectFree @java.lang.SuppressWarnings("all") - public static CheckerFrameworkSuperBuilder.ZChild.ZChildBuilder<?, ?> builder() { + public static CheckerFrameworkSuperBuilder.ZChild.@org.checkerframework.common.aliasing.qual.Unique ZChildBuilder<?, ?> builder() { return new CheckerFrameworkSuperBuilder.ZChild.ZChildBuilderImpl(); } } diff --git a/test/transform/resource/after-delombok/ConstructorsOnRecord.java b/test/transform/resource/after-delombok/ConstructorsOnRecord.java new file mode 100644 index 00000000..1861fd22 --- /dev/null +++ b/test/transform/resource/after-delombok/ConstructorsOnRecord.java @@ -0,0 +1,3 @@ +// version 14: +public record ConstructorsOnRecord(String a, String b) { +} diff --git a/test/transform/resource/after-delombok/ConstructorsWithAccessors.java b/test/transform/resource/after-delombok/ConstructorsWithAccessors.java index 3614d682..7097d5a2 100644 --- a/test/transform/resource/after-delombok/ConstructorsWithAccessors.java +++ b/test/transform/resource/after-delombok/ConstructorsWithAccessors.java @@ -1,3 +1,4 @@ +//version 8: class ConstructorsWithAccessors { int plower; int pUpper; diff --git a/test/transform/resource/after-delombok/DataOnLocalClass.java b/test/transform/resource/after-delombok/DataOnLocalClass.java index 80f3ca83..0d863f4f 100644 --- a/test/transform/resource/after-delombok/DataOnLocalClass.java +++ b/test/transform/resource/after-delombok/DataOnLocalClass.java @@ -1,3 +1,4 @@ +//version 8: class DataOnLocalClass1 { public static void main(String[] args) { class Local { diff --git a/test/transform/resource/after-delombok/DataOnRecord.java b/test/transform/resource/after-delombok/DataOnRecord.java new file mode 100644 index 00000000..e24c7fc2 --- /dev/null +++ b/test/transform/resource/after-delombok/DataOnRecord.java @@ -0,0 +1,3 @@ +// version 14: +public record DataOnRecord(String a, String b) { +} diff --git a/test/transform/resource/after-delombok/DataWithOverrideEqualsAndHashCode.java b/test/transform/resource/after-delombok/DataWithOverrideEqualsAndHashCode.java new file mode 100644 index 00000000..7e84dda4 --- /dev/null +++ b/test/transform/resource/after-delombok/DataWithOverrideEqualsAndHashCode.java @@ -0,0 +1,25 @@ +class DataWithOverrideEqualsAndHashCode { + + class Data1 { + } + + class Data2 extends Data1 { + public int hashCode() { + return 42; + } + + public boolean equals(Object other) { + return false; + } + + @java.lang.SuppressWarnings("all") + public Data2() { + } + + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "DataWithOverrideEqualsAndHashCode.Data2()"; + } + } +} diff --git a/test/transform/resource/after-delombok/EqualsAndHashCodeAnnotated.java b/test/transform/resource/after-delombok/EqualsAndHashCodeAnnotated.java index 64b6f4d3..d99fc71c 100644 --- a/test/transform/resource/after-delombok/EqualsAndHashCodeAnnotated.java +++ b/test/transform/resource/after-delombok/EqualsAndHashCodeAnnotated.java @@ -1,3 +1,4 @@ +//version 8: import java.lang.annotation.*; class EqualsAndHashCodeAnnotated { diff --git a/test/transform/resource/after-delombok/EqualsAndHashCodeOnRecord.java b/test/transform/resource/after-delombok/EqualsAndHashCodeOnRecord.java new file mode 100644 index 00000000..c251a584 --- /dev/null +++ b/test/transform/resource/after-delombok/EqualsAndHashCodeOnRecord.java @@ -0,0 +1,3 @@ +// version 14: +public record EqualsAndHashCodeOnRecord(String a, String b) { +} diff --git a/test/transform/resource/after-delombok/ExtensionMethodChain.java b/test/transform/resource/after-delombok/ExtensionMethodChain.java new file mode 100644 index 00000000..77f79dea --- /dev/null +++ b/test/transform/resource/after-delombok/ExtensionMethodChain.java @@ -0,0 +1,15 @@ +import java.util.Arrays; +import java.util.List; + +class ExtensionMethodChain { + public void test() { + ExtensionMethodChain.Extensions.intValue("1").intValue(); + } + + + static class Extensions { + public static Integer intValue(String s) { + return Integer.valueOf(s); + } + } +}
\ No newline at end of file diff --git a/test/transform/resource/after-delombok/ExtensionMethodFunctional.java b/test/transform/resource/after-delombok/ExtensionMethodFunctional.java index fb58eb91..2b82a957 100644 --- a/test/transform/resource/after-delombok/ExtensionMethodFunctional.java +++ b/test/transform/resource/after-delombok/ExtensionMethodFunctional.java @@ -1,3 +1,4 @@ +// version 8: import java.util.function.Consumer; import java.util.function.Function; import java.util.List; @@ -10,7 +11,7 @@ class ExtensionMethodFunctional { test = ExtensionMethodFunctional.Extensions.map(test, s -> ExtensionMethodFunctional.Extensions.reverse(s)); ExtensionMethodFunctional.Extensions.consume(test, s -> System.out.println("1: " + s), s -> System.out.println("2: " + s)); ExtensionMethodFunctional.Extensions.consume(test, System.out::println, System.out::println); - ExtensionMethodFunctional.Extensions.toList(Stream.of("a", "b", "c").map(String::toUpperCase)); + ExtensionMethodFunctional.Extensions.toList1(Stream.of("a", "b", "c").map(String::toUpperCase)); List<Integer> i2 = ExtensionMethodFunctional.Extensions.toList2(Stream.of("a", "b", "c").map(String::toUpperCase)); } @@ -30,7 +31,7 @@ class ExtensionMethodFunctional { } } - public static <T> List<T> toList(Stream<T> stream) { + public static <T> List<T> toList1(Stream<T> stream) { return (List<T>) stream.collect(Collectors.toList()); } diff --git a/test/transform/resource/after-delombok/FieldDefaultsOnRecord.java b/test/transform/resource/after-delombok/FieldDefaultsOnRecord.java new file mode 100644 index 00000000..fd5f0f95 --- /dev/null +++ b/test/transform/resource/after-delombok/FieldDefaultsOnRecord.java @@ -0,0 +1,3 @@ +// version 14: +public record FieldDefaultsOnRecord(String a, String b) { +} diff --git a/test/transform/resource/after-delombok/FieldNameConstantsOnRecord.java b/test/transform/resource/after-delombok/FieldNameConstantsOnRecord.java new file mode 100644 index 00000000..ffaab75e --- /dev/null +++ b/test/transform/resource/after-delombok/FieldNameConstantsOnRecord.java @@ -0,0 +1,9 @@ +// version 14: +public record FieldNameConstantsOnRecord(String iAmADvdPlayer, int $skipMe, int andMe, String butPrintMePlease) { + static double skipMeToo; + @java.lang.SuppressWarnings("all") + static final class Fields { + public static final java.lang.String iAmADvdPlayer = "iAmADvdPlayer"; + public static final java.lang.String butPrintMePlease = "butPrintMePlease"; + } +} diff --git a/test/transform/resource/after-delombok/GetterLazyArguments.java b/test/transform/resource/after-delombok/GetterLazyArguments.java index a8a422c0..604513cd 100644 --- a/test/transform/resource/after-delombok/GetterLazyArguments.java +++ b/test/transform/resource/after-delombok/GetterLazyArguments.java @@ -1,3 +1,4 @@ +// version 8: class GetterLazyArguments { static String fun() { return null; diff --git a/test/transform/resource/after-delombok/GetterOnClass.java b/test/transform/resource/after-delombok/GetterOnClass.java index f0025370..ae845e54 100644 --- a/test/transform/resource/after-delombok/GetterOnClass.java +++ b/test/transform/resource/after-delombok/GetterOnClass.java @@ -1,3 +1,4 @@ +//version 8: class GetterOnClass1 { boolean isNone; boolean isPublic; diff --git a/test/transform/resource/after-delombok/GetterOnRecord.java b/test/transform/resource/after-delombok/GetterOnRecord.java new file mode 100644 index 00000000..6318a6cc --- /dev/null +++ b/test/transform/resource/after-delombok/GetterOnRecord.java @@ -0,0 +1,3 @@ +// version 14: +public record GetterOnRecord(String a, String b) { +} diff --git a/test/transform/resource/after-delombok/JacksonBuilderSingular.java b/test/transform/resource/after-delombok/JacksonBuilderSingular.java index feaa6832..b2bbfa5a 100644 --- a/test/transform/resource/after-delombok/JacksonBuilderSingular.java +++ b/test/transform/resource/after-delombok/JacksonBuilderSingular.java @@ -1,3 +1,4 @@ +//version 8: Jackson deps are at least Java7+. import java.util.List; import java.util.Map; import com.fasterxml.jackson.annotation.JsonAnySetter; diff --git a/test/transform/resource/after-delombok/JacksonJsonProperty.java b/test/transform/resource/after-delombok/JacksonJsonProperty.java index 14e50447..7bb17dfd 100644 --- a/test/transform/resource/after-delombok/JacksonJsonProperty.java +++ b/test/transform/resource/after-delombok/JacksonJsonProperty.java @@ -1,3 +1,4 @@ +//version 8: Jackson deps are at least Java7+. import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonSetter; import com.fasterxml.jackson.annotation.Nulls; diff --git a/test/transform/resource/after-delombok/JacksonizedBuilderComplex.java b/test/transform/resource/after-delombok/JacksonizedBuilderComplex.java index 5abfda63..ed0ca9e7 100644 --- a/test/transform/resource/after-delombok/JacksonizedBuilderComplex.java +++ b/test/transform/resource/after-delombok/JacksonizedBuilderComplex.java @@ -1,3 +1,4 @@ +//version 8: Jackson deps are at least Java7+. //CONF: lombok.builder.className = Test*Name import java.util.List; @com.fasterxml.jackson.databind.annotation.JsonDeserialize(builder = JacksonizedBuilderComplex.TestVoidName.class) diff --git a/test/transform/resource/after-delombok/JacksonizedBuilderSimple.java b/test/transform/resource/after-delombok/JacksonizedBuilderSimple.java index 550163b9..cb8390d2 100644 --- a/test/transform/resource/after-delombok/JacksonizedBuilderSimple.java +++ b/test/transform/resource/after-delombok/JacksonizedBuilderSimple.java @@ -1,3 +1,4 @@ +//version 8: Jackson deps are at least Java7+. import java.util.List; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @JsonIgnoreProperties(ignoreUnknown = true) diff --git a/test/transform/resource/after-delombok/JacksonizedSuperBuilderSimple.java b/test/transform/resource/after-delombok/JacksonizedSuperBuilderSimple.java index a5765934..88a51f41 100644 --- a/test/transform/resource/after-delombok/JacksonizedSuperBuilderSimple.java +++ b/test/transform/resource/after-delombok/JacksonizedSuperBuilderSimple.java @@ -1,58 +1,59 @@ -public class JacksonizedSuperBuilderSimple {
- @com.fasterxml.jackson.annotation.JsonIgnoreProperties(ignoreUnknown = true)
- @com.fasterxml.jackson.databind.annotation.JsonDeserialize(builder = JacksonizedSuperBuilderSimple.Parent.ParentBuilderImpl.class)
- public static class Parent {
- int field1;
- @java.lang.SuppressWarnings("all")
- public static abstract class ParentBuilder<C extends JacksonizedSuperBuilderSimple.Parent, B extends JacksonizedSuperBuilderSimple.Parent.ParentBuilder<C, B>> {
- @java.lang.SuppressWarnings("all")
- private int field1;
- @java.lang.SuppressWarnings("all")
- protected abstract B self();
- @java.lang.SuppressWarnings("all")
- public abstract C build();
- /**
- * @return {@code this}.
- */
- @java.lang.SuppressWarnings("all")
- public B field1(final int field1) {
- this.field1 = field1;
- return self();
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public java.lang.String toString() {
- return "JacksonizedSuperBuilderSimple.Parent.ParentBuilder(field1=" + this.field1 + ")";
- }
- }
- @java.lang.SuppressWarnings("all")
- @com.fasterxml.jackson.annotation.JsonIgnoreProperties(ignoreUnknown = true)
- @com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder(withPrefix = "", buildMethodName = "build")
- static final class ParentBuilderImpl extends JacksonizedSuperBuilderSimple.Parent.ParentBuilder<JacksonizedSuperBuilderSimple.Parent, JacksonizedSuperBuilderSimple.Parent.ParentBuilderImpl> {
- @java.lang.SuppressWarnings("all")
- private ParentBuilderImpl() {
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected JacksonizedSuperBuilderSimple.Parent.ParentBuilderImpl self() {
- return this;
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public JacksonizedSuperBuilderSimple.Parent build() {
- return new JacksonizedSuperBuilderSimple.Parent(this);
- }
- }
- @java.lang.SuppressWarnings("all")
- protected Parent(final JacksonizedSuperBuilderSimple.Parent.ParentBuilder<?, ?> b) {
- this.field1 = b.field1;
- }
- @java.lang.SuppressWarnings("all")
- public static JacksonizedSuperBuilderSimple.Parent.ParentBuilder<?, ?> builder() {
- return new JacksonizedSuperBuilderSimple.Parent.ParentBuilderImpl();
- }
- }
- public static void test() {
- Parent x = Parent.builder().field1(5).build();
- }
-}
+//version 8: Jackson deps are at least Java7+. +public class JacksonizedSuperBuilderSimple { + @com.fasterxml.jackson.annotation.JsonIgnoreProperties(ignoreUnknown = true) + @com.fasterxml.jackson.databind.annotation.JsonDeserialize(builder = JacksonizedSuperBuilderSimple.Parent.ParentBuilderImpl.class) + public static class Parent { + int field1; + @java.lang.SuppressWarnings("all") + public static abstract class ParentBuilder<C extends JacksonizedSuperBuilderSimple.Parent, B extends JacksonizedSuperBuilderSimple.Parent.ParentBuilder<C, B>> { + @java.lang.SuppressWarnings("all") + private int field1; + @java.lang.SuppressWarnings("all") + protected abstract B self(); + @java.lang.SuppressWarnings("all") + public abstract C build(); + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public B field1(final int field1) { + this.field1 = field1; + return self(); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "JacksonizedSuperBuilderSimple.Parent.ParentBuilder(field1=" + this.field1 + ")"; + } + } + @java.lang.SuppressWarnings("all") + @com.fasterxml.jackson.annotation.JsonIgnoreProperties(ignoreUnknown = true) + @com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder(withPrefix = "", buildMethodName = "build") + static final class ParentBuilderImpl extends JacksonizedSuperBuilderSimple.Parent.ParentBuilder<JacksonizedSuperBuilderSimple.Parent, JacksonizedSuperBuilderSimple.Parent.ParentBuilderImpl> { + @java.lang.SuppressWarnings("all") + private ParentBuilderImpl() { + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected JacksonizedSuperBuilderSimple.Parent.ParentBuilderImpl self() { + return this; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public JacksonizedSuperBuilderSimple.Parent build() { + return new JacksonizedSuperBuilderSimple.Parent(this); + } + } + @java.lang.SuppressWarnings("all") + protected Parent(final JacksonizedSuperBuilderSimple.Parent.ParentBuilder<?, ?> b) { + this.field1 = b.field1; + } + @java.lang.SuppressWarnings("all") + public static JacksonizedSuperBuilderSimple.Parent.ParentBuilder<?, ?> builder() { + return new JacksonizedSuperBuilderSimple.Parent.ParentBuilderImpl(); + } + } + public static void test() { + Parent x = Parent.builder().field1(5).build(); + } +} diff --git a/test/transform/resource/after-delombok/JacksonizedSuperBuilderWithJsonDeserialize.java b/test/transform/resource/after-delombok/JacksonizedSuperBuilderWithJsonDeserialize.java index d26b4ee4..1ed38f05 100644 --- a/test/transform/resource/after-delombok/JacksonizedSuperBuilderWithJsonDeserialize.java +++ b/test/transform/resource/after-delombok/JacksonizedSuperBuilderWithJsonDeserialize.java @@ -1,5 +1,4 @@ //skip-idempotent -@lombok.experimental.SuperBuilder @com.fasterxml.jackson.databind.annotation.JsonDeserialize public class JacksonizedSuperBuilderWithJsonDeserialize { int field1; diff --git a/test/transform/resource/after-delombok/JavadocMultiline.java b/test/transform/resource/after-delombok/JavadocMultiline.java new file mode 100644 index 00000000..cc8b1148 --- /dev/null +++ b/test/transform/resource/after-delombok/JavadocMultiline.java @@ -0,0 +1,51 @@ +class JavadocMultiline { + /** + * This is a list of booleans. + */ + private java.util.List<Boolean> booleans; + /** + * This is a list of booleans. + */ + private java.util.List<Boolean> booleans2; + + /** + * This is a list of booleans. + * + * @return A list of booleans to set for this object. This is a Javadoc return that is long + * enough to wrap to multiple lines. + */ + @java.lang.SuppressWarnings("all") + public java.util.List<Boolean> getBooleans() { + return this.booleans; + } + + /** + * This is a list of booleans. + */ + @java.lang.SuppressWarnings("all") + public java.util.List<Boolean> getBooleans2() { + return this.booleans2; + } + + /** + * This is a list of booleans. + * + * @param booleans A list of booleans to set for this object. This is a Javadoc param that is + * long enough to wrap to multiple lines. + */ + @java.lang.SuppressWarnings("all") + public void setBooleans(final java.util.List<Boolean> booleans) { + this.booleans = booleans; + } + + /** + * This is a list of booleans. + * + * @param booleans A list of booleans to set for this object. This is a Javadoc param that is + * long enough to wrap to multiple lines. + */ + @java.lang.SuppressWarnings("all") + public void setBooleans2(final java.util.List<Boolean> booleans2) { + this.booleans2 = booleans2; + } +}
\ No newline at end of file diff --git a/test/transform/resource/after-delombok/LoggerConfigOnRecord.java b/test/transform/resource/after-delombok/LoggerConfigOnRecord.java new file mode 100644 index 00000000..58d3fad0 --- /dev/null +++ b/test/transform/resource/after-delombok/LoggerConfigOnRecord.java @@ -0,0 +1,3 @@ +// version 14: +public record LoggerConfigOnRecord(String a, String b) { +} diff --git a/test/transform/resource/after-delombok/LoggerLog4j2.java b/test/transform/resource/after-delombok/LoggerLog4j2.java index b32c7722..cba516f2 100644 --- a/test/transform/resource/after-delombok/LoggerLog4j2.java +++ b/test/transform/resource/after-delombok/LoggerLog4j2.java @@ -1,3 +1,4 @@ +//version 8: class LoggerLog4j2 { @java.lang.SuppressWarnings("all") private static final org.apache.logging.log4j.Logger log = org.apache.logging.log4j.LogManager.getLogger(LoggerLog4j2.class); diff --git a/test/transform/resource/after-delombok/LoggerSlf4jInvalidTopic.java b/test/transform/resource/after-delombok/LoggerSlf4jInvalidTopic.java deleted file mode 100644 index 86e6ae2c..00000000 --- a/test/transform/resource/after-delombok/LoggerSlf4jInvalidTopic.java +++ /dev/null @@ -1,5 +0,0 @@ -import lombok.extern.slf4j.Slf4j; - -@Slf4j(topic = 42) -class LoggerSlf4jWithIntegerTopic { -}
\ No newline at end of file diff --git a/test/transform/resource/after-delombok/LoggerSlf4jNonStaticOnRecord.java b/test/transform/resource/after-delombok/LoggerSlf4jNonStaticOnRecord.java new file mode 100644 index 00000000..801c9990 --- /dev/null +++ b/test/transform/resource/after-delombok/LoggerSlf4jNonStaticOnRecord.java @@ -0,0 +1,4 @@ +// version 14: +record LoggerSlf4jOnRecord(String a, String b) { + private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LoggerSlf4jOnRecord.class); +} diff --git a/test/transform/resource/after-delombok/LoggerSlf4jOnRecord.java b/test/transform/resource/after-delombok/LoggerSlf4jOnRecord.java new file mode 100644 index 00000000..831ac357 --- /dev/null +++ b/test/transform/resource/after-delombok/LoggerSlf4jOnRecord.java @@ -0,0 +1,5 @@ +// version 16: the SuppressWarnings is not emitted in java14/15 to work around a javac bug. +public record LoggerSlf4jOnRecord(String a, String b) { + @java.lang.SuppressWarnings("all") + private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LoggerSlf4jOnRecord.class); +} diff --git a/test/transform/resource/after-delombok/NonNullExistingConstructorOnRecord.java b/test/transform/resource/after-delombok/NonNullExistingConstructorOnRecord.java new file mode 100644 index 00000000..45364815 --- /dev/null +++ b/test/transform/resource/after-delombok/NonNullExistingConstructorOnRecord.java @@ -0,0 +1,19 @@ +// version 16: +import lombok.NonNull; +public record NonNullExistingConstructorOnRecord(@NonNull String a, @NonNull String b) { + public NonNullExistingConstructorOnRecord(@NonNull String b) { + this("default", b); + if (b == null) { + throw new java.lang.NullPointerException("b is marked non-null but is null"); + } + } + @java.lang.SuppressWarnings("all") + public NonNullExistingConstructorOnRecord { + if (a == null) { + throw new java.lang.NullPointerException("a is marked non-null but is null"); + } + if (b == null) { + throw new java.lang.NullPointerException("b is marked non-null but is null"); + } + } +} diff --git a/test/transform/resource/after-delombok/NonNullOnParameter.java b/test/transform/resource/after-delombok/NonNullOnParameter.java index 4f6df920..95fd13ec 100644 --- a/test/transform/resource/after-delombok/NonNullOnParameter.java +++ b/test/transform/resource/after-delombok/NonNullOnParameter.java @@ -1,3 +1,4 @@ +//version 8: class NonNullOnParameter extends Thread { NonNullOnParameter(@lombok.NonNull String arg) { this(arg, ""); diff --git a/test/transform/resource/after-delombok/NonNullOnParameterAbstract.java b/test/transform/resource/after-delombok/NonNullOnParameterAbstract.java index 88577f25..df496931 100644 --- a/test/transform/resource/after-delombok/NonNullOnParameterAbstract.java +++ b/test/transform/resource/after-delombok/NonNullOnParameterAbstract.java @@ -1,3 +1,4 @@ +//version 8: abstract class NonNullOnParameterAbstract { public void test(@lombok.NonNull String arg) { if (arg == null) { diff --git a/test/transform/resource/after-delombok/NonNullOnRecord.java b/test/transform/resource/after-delombok/NonNullOnRecord.java new file mode 100644 index 00000000..465c30db --- /dev/null +++ b/test/transform/resource/after-delombok/NonNullOnRecord.java @@ -0,0 +1,13 @@ +// version 16: +import lombok.NonNull; +public record NonNullOnRecord(@NonNull String a, @NonNull String b) { + @java.lang.SuppressWarnings("all") + public NonNullOnRecord { + if (a == null) { + throw new java.lang.NullPointerException("a is marked non-null but is null"); + } + if (b == null) { + throw new java.lang.NullPointerException("b is marked non-null but is null"); + } + } +} diff --git a/test/transform/resource/after-delombok/NonNullOnRecord2.java b/test/transform/resource/after-delombok/NonNullOnRecord2.java new file mode 100644 index 00000000..d3021350 --- /dev/null +++ b/test/transform/resource/after-delombok/NonNullOnRecord2.java @@ -0,0 +1,10 @@ +// version 16: +import lombok.NonNull; +record NonNullOnRecord2(@NonNull String a) { + public NonNullOnRecord2 { + if (a == null) { + throw new java.lang.NullPointerException("a is marked non-null but is null"); + } + System.out.println("Hello"); + } +} diff --git a/test/transform/resource/after-delombok/NonNullOnRecord3.java b/test/transform/resource/after-delombok/NonNullOnRecord3.java new file mode 100644 index 00000000..62b385bc --- /dev/null +++ b/test/transform/resource/after-delombok/NonNullOnRecord3.java @@ -0,0 +1,13 @@ +// version 14: +import lombok.NonNull; +public record NonNullOnRecord3(@NonNull String a) { + public NonNullOnRecord3(String a) { + this.a = a; + } + public void method(@NonNull String param) { + if (param == null) { + throw new java.lang.NullPointerException("param is marked non-null but is null"); + } + String asd = "a"; + } +} diff --git a/test/transform/resource/after-delombok/NonNullPlain.java b/test/transform/resource/after-delombok/NonNullPlain.java index 24377237..9fc29042 100644 --- a/test/transform/resource/after-delombok/NonNullPlain.java +++ b/test/transform/resource/after-delombok/NonNullPlain.java @@ -1,3 +1,4 @@ +//version 8: import java.lang.annotation.*; class NonNullPlain { @lombok.NonNull diff --git a/test/transform/resource/after-delombok/NonNullTypeUse.java b/test/transform/resource/after-delombok/NonNullTypeUse.java index 7c438501..b80a6da8 100644 --- a/test/transform/resource/after-delombok/NonNullTypeUse.java +++ b/test/transform/resource/after-delombok/NonNullTypeUse.java @@ -1,3 +1,4 @@ +//version 8: import lombok.NonNull; class NonNullTypeUse { void test1(@NonNull String[][][] args) { diff --git a/test/transform/resource/after-delombok/NonNullWithAlternateException.java b/test/transform/resource/after-delombok/NonNullWithAlternateException.java index 7f30fd1f..e76feca2 100644 --- a/test/transform/resource/after-delombok/NonNullWithAlternateException.java +++ b/test/transform/resource/after-delombok/NonNullWithAlternateException.java @@ -1,3 +1,4 @@ +//version 8: public class NonNullWithAlternateException { @lombok.NonNull private String test; diff --git a/test/transform/resource/after-delombok/NonNullWithAssertion.java b/test/transform/resource/after-delombok/NonNullWithAssertion.java index 15dc0254..318d85b9 100644 --- a/test/transform/resource/after-delombok/NonNullWithAssertion.java +++ b/test/transform/resource/after-delombok/NonNullWithAssertion.java @@ -1,3 +1,4 @@ +//version 8: public class NonNullWithAssertion { @lombok.NonNull private String test; diff --git a/test/transform/resource/after-delombok/NonNullWithGuava.java b/test/transform/resource/after-delombok/NonNullWithGuava.java index b3c13d30..efa5878e 100644 --- a/test/transform/resource/after-delombok/NonNullWithGuava.java +++ b/test/transform/resource/after-delombok/NonNullWithGuava.java @@ -1,3 +1,4 @@ +//version 8: import static com.google.common.base.Preconditions.*; public class NonNullWithGuava { @lombok.NonNull diff --git a/test/transform/resource/after-delombok/NonNullWithJdk.java b/test/transform/resource/after-delombok/NonNullWithJdk.java index d7e2958c..725d90c7 100644 --- a/test/transform/resource/after-delombok/NonNullWithJdk.java +++ b/test/transform/resource/after-delombok/NonNullWithJdk.java @@ -1,4 +1,4 @@ -//version 7: +//version 8: import static java.util.Objects.*; public class NonNullWithJdk { @lombok.NonNull diff --git a/test/transform/resource/after-delombok/NonNullWithSneakyThrows.java b/test/transform/resource/after-delombok/NonNullWithSneakyThrows.java index 44640164..cd7f8092 100644 --- a/test/transform/resource/after-delombok/NonNullWithSneakyThrows.java +++ b/test/transform/resource/after-delombok/NonNullWithSneakyThrows.java @@ -1,3 +1,4 @@ +//version 8: class NonNullWithSneakyThrows { void test(@lombok.NonNull String in) { try { diff --git a/test/transform/resource/after-delombok/NullAnnotatedCheckerFrameworkSuperBuilder.java b/test/transform/resource/after-delombok/NullAnnotatedCheckerFrameworkSuperBuilder.java new file mode 100644 index 00000000..25a76c6d --- /dev/null +++ b/test/transform/resource/after-delombok/NullAnnotatedCheckerFrameworkSuperBuilder.java @@ -0,0 +1,237 @@ +//version 8: +//CONF: lombok.addNullAnnotations = checkerframework +import java.util.List; + +class NullAnnotatedCheckerFrameworkSuperBuilder { + + public static class Parent { + int x; + int y; + int z; + List<String> names; + + @java.lang.SuppressWarnings("all") + private static int $default$x() { + return 5; + } + + + @java.lang.SuppressWarnings("all") + public static abstract class ParentBuilder<C extends NullAnnotatedCheckerFrameworkSuperBuilder.Parent, B extends NullAnnotatedCheckerFrameworkSuperBuilder.Parent.ParentBuilder<C, B>> { + @java.lang.SuppressWarnings("all") + private boolean x$set; + @java.lang.SuppressWarnings("all") + private int x$value; + @java.lang.SuppressWarnings("all") + private int y; + @java.lang.SuppressWarnings("all") + private int z; + @java.lang.SuppressWarnings("all") + private java.util.ArrayList<String> names; + + @java.lang.SuppressWarnings("all") + protected abstract B self(); + + @java.lang.SuppressWarnings("all") + public abstract C build(); + + /** + * @return {@code this}. + */ + @org.checkerframework.checker.nullness.qual.NonNull + @java.lang.SuppressWarnings("all") + public B x(final int x) { + this.x$value = x; + x$set = true; + return self(); + } + + /** + * @return {@code this}. + */ + @org.checkerframework.checker.nullness.qual.NonNull + @java.lang.SuppressWarnings("all") + public B y(final int y) { + this.y = y; + return self(); + } + + /** + * @return {@code this}. + */ + @org.checkerframework.checker.nullness.qual.NonNull + @java.lang.SuppressWarnings("all") + public B z(final int z) { + this.z = z; + return self(); + } + + @org.checkerframework.checker.nullness.qual.NonNull + @java.lang.SuppressWarnings("all") + public B name(final String name) { + if (this.names == null) this.names = new java.util.ArrayList<String>(); + this.names.add(name); + return self(); + } + + @org.checkerframework.checker.nullness.qual.NonNull + @java.lang.SuppressWarnings("all") + public B names(final java.util.@org.checkerframework.checker.nullness.qual.NonNull Collection<? extends String> names) { + if (names == null) { + throw new java.lang.NullPointerException("names cannot be null"); + } + if (this.names == null) this.names = new java.util.ArrayList<String>(); + this.names.addAll(names); + return self(); + } + + @org.checkerframework.checker.nullness.qual.NonNull + @java.lang.SuppressWarnings("all") + public B clearNames() { + if (this.names != null) this.names.clear(); + return self(); + } + + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.@org.checkerframework.checker.nullness.qual.NonNull String toString() { + return "NullAnnotatedCheckerFrameworkSuperBuilder.Parent.ParentBuilder(x$value=" + this.x$value + ", y=" + this.y + ", z=" + this.z + ", names=" + this.names + ")"; + } + } + + + @java.lang.SuppressWarnings("all") + private static final class ParentBuilderImpl extends NullAnnotatedCheckerFrameworkSuperBuilder.Parent.ParentBuilder<NullAnnotatedCheckerFrameworkSuperBuilder.Parent, NullAnnotatedCheckerFrameworkSuperBuilder.Parent.ParentBuilderImpl> { + @java.lang.SuppressWarnings("all") + private ParentBuilderImpl() { + } + + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected NullAnnotatedCheckerFrameworkSuperBuilder.Parent.ParentBuilderImpl self() { + return this; + } + + @java.lang.Override + @java.lang.SuppressWarnings("all") + public NullAnnotatedCheckerFrameworkSuperBuilder.@org.checkerframework.checker.nullness.qual.NonNull Parent build() { + return new NullAnnotatedCheckerFrameworkSuperBuilder.Parent(this); + } + } + + @java.lang.SuppressWarnings("all") + protected Parent(final NullAnnotatedCheckerFrameworkSuperBuilder.Parent.ParentBuilder<?, ?> b) { + if (b.x$set) this.x = b.x$value; + else this.x = NullAnnotatedCheckerFrameworkSuperBuilder.Parent.$default$x(); + this.y = b.y; + this.z = b.z; + java.util.List<String> names; + switch (b.names == null ? 0 : b.names.size()) { + case 0: + names = java.util.Collections.emptyList(); + break; + case 1: + names = java.util.Collections.singletonList(b.names.get(0)); + break; + default: + names = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(b.names)); + } + this.names = names; + } + + @java.lang.SuppressWarnings("all") + public static NullAnnotatedCheckerFrameworkSuperBuilder.Parent.@org.checkerframework.checker.nullness.qual.NonNull ParentBuilder<?, ?> builder() { + return new NullAnnotatedCheckerFrameworkSuperBuilder.Parent.ParentBuilderImpl(); + } + } + + + public static class ZChild extends Parent { + int a; + int b; + + @java.lang.SuppressWarnings("all") + private static int $default$a() { + return 1; + } + + + @java.lang.SuppressWarnings("all") + public static abstract class ZChildBuilder<C extends NullAnnotatedCheckerFrameworkSuperBuilder.ZChild, B extends NullAnnotatedCheckerFrameworkSuperBuilder.ZChild.ZChildBuilder<C, B>> extends Parent.ParentBuilder<C, B> { + @java.lang.SuppressWarnings("all") + private boolean a$set; + @java.lang.SuppressWarnings("all") + private int a$value; + @java.lang.SuppressWarnings("all") + private int b; + + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected abstract B self(); + + @java.lang.Override + @java.lang.SuppressWarnings("all") + public abstract C build(); + + /** + * @return {@code this}. + */ + @org.checkerframework.checker.nullness.qual.NonNull + @java.lang.SuppressWarnings("all") + public B a(final int a) { + this.a$value = a; + a$set = true; + return self(); + } + + /** + * @return {@code this}. + */ + @org.checkerframework.checker.nullness.qual.NonNull + @java.lang.SuppressWarnings("all") + public B b(final int b) { + this.b = b; + return self(); + } + + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.@org.checkerframework.checker.nullness.qual.NonNull String toString() { + return "NullAnnotatedCheckerFrameworkSuperBuilder.ZChild.ZChildBuilder(super=" + super.toString() + ", a$value=" + this.a$value + ", b=" + this.b + ")"; + } + } + + + @java.lang.SuppressWarnings("all") + private static final class ZChildBuilderImpl extends NullAnnotatedCheckerFrameworkSuperBuilder.ZChild.ZChildBuilder<NullAnnotatedCheckerFrameworkSuperBuilder.ZChild, NullAnnotatedCheckerFrameworkSuperBuilder.ZChild.ZChildBuilderImpl> { + @java.lang.SuppressWarnings("all") + private ZChildBuilderImpl() { + } + + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected NullAnnotatedCheckerFrameworkSuperBuilder.ZChild.ZChildBuilderImpl self() { + return this; + } + + @java.lang.Override + @java.lang.SuppressWarnings("all") + public NullAnnotatedCheckerFrameworkSuperBuilder.@org.checkerframework.checker.nullness.qual.NonNull ZChild build() { + return new NullAnnotatedCheckerFrameworkSuperBuilder.ZChild(this); + } + } + + @java.lang.SuppressWarnings("all") + protected ZChild(final NullAnnotatedCheckerFrameworkSuperBuilder.ZChild.ZChildBuilder<?, ?> b) { + super(b); + if (b.a$set) this.a = b.a$value; + else this.a = NullAnnotatedCheckerFrameworkSuperBuilder.ZChild.$default$a(); + this.b = b.b; + } + + @java.lang.SuppressWarnings("all") + public static NullAnnotatedCheckerFrameworkSuperBuilder.ZChild.@org.checkerframework.checker.nullness.qual.NonNull ZChildBuilder<?, ?> builder() { + return new NullAnnotatedCheckerFrameworkSuperBuilder.ZChild.ZChildBuilderImpl(); + } + } +} diff --git a/test/transform/resource/after-delombok/NullLibrary1.java b/test/transform/resource/after-delombok/NullLibrary1.java index e19c535d..e299be3d 100644 --- a/test/transform/resource/after-delombok/NullLibrary1.java +++ b/test/transform/resource/after-delombok/NullLibrary1.java @@ -1,3 +1,4 @@ +//version 8: public class NullLibrary1 { String foo; @java.lang.Override diff --git a/test/transform/resource/after-delombok/NullLibrary2.java b/test/transform/resource/after-delombok/NullLibrary2.java index 5087e4ee..fec143c2 100644 --- a/test/transform/resource/after-delombok/NullLibrary2.java +++ b/test/transform/resource/after-delombok/NullLibrary2.java @@ -1,3 +1,4 @@ +//version 8: springframework dep is too new to run on j6 public class NullLibrary2 { String foo; @java.lang.Override diff --git a/test/transform/resource/after-delombok/SetterOnClass.java b/test/transform/resource/after-delombok/SetterOnClass.java index 24f376cb..d95a280f 100644 --- a/test/transform/resource/after-delombok/SetterOnClass.java +++ b/test/transform/resource/after-delombok/SetterOnClass.java @@ -1,3 +1,4 @@ +//version 8: class SetterOnClass1 { boolean isNone; boolean isPublic; diff --git a/test/transform/resource/after-delombok/SetterOnRecord.java b/test/transform/resource/after-delombok/SetterOnRecord.java new file mode 100644 index 00000000..a6be2d8c --- /dev/null +++ b/test/transform/resource/after-delombok/SetterOnRecord.java @@ -0,0 +1,3 @@ +// version 14: +public record SetterOnRecord(String a, String b) { +} diff --git a/test/transform/resource/after-delombok/StaticConstructor.java b/test/transform/resource/after-delombok/StaticConstructor.java index f9c862d7..4de6dbe5 100644 --- a/test/transform/resource/after-delombok/StaticConstructor.java +++ b/test/transform/resource/after-delombok/StaticConstructor.java @@ -1,3 +1,4 @@ +//version 8: public class StaticConstructor { String name; @java.lang.SuppressWarnings("all") diff --git a/test/transform/resource/after-delombok/SuperBuilderAbstract.java b/test/transform/resource/after-delombok/SuperBuilderAbstract.java index 5fa0b1a0..727c5beb 100644 --- a/test/transform/resource/after-delombok/SuperBuilderAbstract.java +++ b/test/transform/resource/after-delombok/SuperBuilderAbstract.java @@ -1,138 +1,138 @@ -public class SuperBuilderAbstract {
- public static class Parent {
- int parentField;
- @java.lang.SuppressWarnings("all")
- public static abstract class ParentBuilder<C extends SuperBuilderAbstract.Parent, B extends SuperBuilderAbstract.Parent.ParentBuilder<C, B>> {
- @java.lang.SuppressWarnings("all")
- private int parentField;
- @java.lang.SuppressWarnings("all")
- protected abstract B self();
- @java.lang.SuppressWarnings("all")
- public abstract C build();
- /**
- * @return {@code this}.
- */
- @java.lang.SuppressWarnings("all")
- public B parentField(final int parentField) {
- this.parentField = parentField;
- return self();
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public java.lang.String toString() {
- return "SuperBuilderAbstract.Parent.ParentBuilder(parentField=" + this.parentField + ")";
- }
- }
- @java.lang.SuppressWarnings("all")
- private static final class ParentBuilderImpl extends SuperBuilderAbstract.Parent.ParentBuilder<SuperBuilderAbstract.Parent, SuperBuilderAbstract.Parent.ParentBuilderImpl> {
- @java.lang.SuppressWarnings("all")
- private ParentBuilderImpl() {
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected SuperBuilderAbstract.Parent.ParentBuilderImpl self() {
- return this;
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public SuperBuilderAbstract.Parent build() {
- return new SuperBuilderAbstract.Parent(this);
- }
- }
- @java.lang.SuppressWarnings("all")
- protected Parent(final SuperBuilderAbstract.Parent.ParentBuilder<?, ?> b) {
- this.parentField = b.parentField;
- }
- @java.lang.SuppressWarnings("all")
- public static SuperBuilderAbstract.Parent.ParentBuilder<?, ?> builder() {
- return new SuperBuilderAbstract.Parent.ParentBuilderImpl();
- }
- }
- public static abstract class Child extends Parent {
- double childField;
- @java.lang.SuppressWarnings("all")
- public static abstract class ChildBuilder<C extends SuperBuilderAbstract.Child, B extends SuperBuilderAbstract.Child.ChildBuilder<C, B>> extends Parent.ParentBuilder<C, B> {
- @java.lang.SuppressWarnings("all")
- private double childField;
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected abstract B self();
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public abstract C build();
- /**
- * @return {@code this}.
- */
- @java.lang.SuppressWarnings("all")
- public B childField(final double childField) {
- this.childField = childField;
- return self();
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public java.lang.String toString() {
- return "SuperBuilderAbstract.Child.ChildBuilder(super=" + super.toString() + ", childField=" + this.childField + ")";
- }
- }
- @java.lang.SuppressWarnings("all")
- protected Child(final SuperBuilderAbstract.Child.ChildBuilder<?, ?> b) {
- super(b);
- this.childField = b.childField;
- }
- }
- public static class GrandChild extends Child {
- String grandChildField;
- @java.lang.SuppressWarnings("all")
- public static abstract class GrandChildBuilder<C extends SuperBuilderAbstract.GrandChild, B extends SuperBuilderAbstract.GrandChild.GrandChildBuilder<C, B>> extends Child.ChildBuilder<C, B> {
- @java.lang.SuppressWarnings("all")
- private String grandChildField;
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected abstract B self();
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public abstract C build();
- /**
- * @return {@code this}.
- */
- @java.lang.SuppressWarnings("all")
- public B grandChildField(final String grandChildField) {
- this.grandChildField = grandChildField;
- return self();
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public java.lang.String toString() {
- return "SuperBuilderAbstract.GrandChild.GrandChildBuilder(super=" + super.toString() + ", grandChildField=" + this.grandChildField + ")";
- }
- }
- @java.lang.SuppressWarnings("all")
- private static final class GrandChildBuilderImpl extends SuperBuilderAbstract.GrandChild.GrandChildBuilder<SuperBuilderAbstract.GrandChild, SuperBuilderAbstract.GrandChild.GrandChildBuilderImpl> {
- @java.lang.SuppressWarnings("all")
- private GrandChildBuilderImpl() {
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected SuperBuilderAbstract.GrandChild.GrandChildBuilderImpl self() {
- return this;
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public SuperBuilderAbstract.GrandChild build() {
- return new SuperBuilderAbstract.GrandChild(this);
- }
- }
- @java.lang.SuppressWarnings("all")
- protected GrandChild(final SuperBuilderAbstract.GrandChild.GrandChildBuilder<?, ?> b) {
- super(b);
- this.grandChildField = b.grandChildField;
- }
- @java.lang.SuppressWarnings("all")
- public static SuperBuilderAbstract.GrandChild.GrandChildBuilder<?, ?> builder() {
- return new SuperBuilderAbstract.GrandChild.GrandChildBuilderImpl();
- }
- }
- public static void test() {
- GrandChild x = GrandChild.builder().grandChildField("").parentField(5).childField(2.5).build();
- }
-}
+public class SuperBuilderAbstract { + public static class Parent { + int parentField; + @java.lang.SuppressWarnings("all") + public static abstract class ParentBuilder<C extends SuperBuilderAbstract.Parent, B extends SuperBuilderAbstract.Parent.ParentBuilder<C, B>> { + @java.lang.SuppressWarnings("all") + private int parentField; + @java.lang.SuppressWarnings("all") + protected abstract B self(); + @java.lang.SuppressWarnings("all") + public abstract C build(); + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public B parentField(final int parentField) { + this.parentField = parentField; + return self(); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "SuperBuilderAbstract.Parent.ParentBuilder(parentField=" + this.parentField + ")"; + } + } + @java.lang.SuppressWarnings("all") + private static final class ParentBuilderImpl extends SuperBuilderAbstract.Parent.ParentBuilder<SuperBuilderAbstract.Parent, SuperBuilderAbstract.Parent.ParentBuilderImpl> { + @java.lang.SuppressWarnings("all") + private ParentBuilderImpl() { + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected SuperBuilderAbstract.Parent.ParentBuilderImpl self() { + return this; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public SuperBuilderAbstract.Parent build() { + return new SuperBuilderAbstract.Parent(this); + } + } + @java.lang.SuppressWarnings("all") + protected Parent(final SuperBuilderAbstract.Parent.ParentBuilder<?, ?> b) { + this.parentField = b.parentField; + } + @java.lang.SuppressWarnings("all") + public static SuperBuilderAbstract.Parent.ParentBuilder<?, ?> builder() { + return new SuperBuilderAbstract.Parent.ParentBuilderImpl(); + } + } + public static abstract class Child extends Parent { + double childField; + @java.lang.SuppressWarnings("all") + public static abstract class ChildBuilder<C extends SuperBuilderAbstract.Child, B extends SuperBuilderAbstract.Child.ChildBuilder<C, B>> extends Parent.ParentBuilder<C, B> { + @java.lang.SuppressWarnings("all") + private double childField; + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected abstract B self(); + @java.lang.Override + @java.lang.SuppressWarnings("all") + public abstract C build(); + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public B childField(final double childField) { + this.childField = childField; + return self(); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "SuperBuilderAbstract.Child.ChildBuilder(super=" + super.toString() + ", childField=" + this.childField + ")"; + } + } + @java.lang.SuppressWarnings("all") + protected Child(final SuperBuilderAbstract.Child.ChildBuilder<?, ?> b) { + super(b); + this.childField = b.childField; + } + } + public static class GrandChild extends Child { + String grandChildField; + @java.lang.SuppressWarnings("all") + public static abstract class GrandChildBuilder<C extends SuperBuilderAbstract.GrandChild, B extends SuperBuilderAbstract.GrandChild.GrandChildBuilder<C, B>> extends Child.ChildBuilder<C, B> { + @java.lang.SuppressWarnings("all") + private String grandChildField; + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected abstract B self(); + @java.lang.Override + @java.lang.SuppressWarnings("all") + public abstract C build(); + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public B grandChildField(final String grandChildField) { + this.grandChildField = grandChildField; + return self(); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "SuperBuilderAbstract.GrandChild.GrandChildBuilder(super=" + super.toString() + ", grandChildField=" + this.grandChildField + ")"; + } + } + @java.lang.SuppressWarnings("all") + private static final class GrandChildBuilderImpl extends SuperBuilderAbstract.GrandChild.GrandChildBuilder<SuperBuilderAbstract.GrandChild, SuperBuilderAbstract.GrandChild.GrandChildBuilderImpl> { + @java.lang.SuppressWarnings("all") + private GrandChildBuilderImpl() { + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected SuperBuilderAbstract.GrandChild.GrandChildBuilderImpl self() { + return this; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public SuperBuilderAbstract.GrandChild build() { + return new SuperBuilderAbstract.GrandChild(this); + } + } + @java.lang.SuppressWarnings("all") + protected GrandChild(final SuperBuilderAbstract.GrandChild.GrandChildBuilder<?, ?> b) { + super(b); + this.grandChildField = b.grandChildField; + } + @java.lang.SuppressWarnings("all") + public static SuperBuilderAbstract.GrandChild.GrandChildBuilder<?, ?> builder() { + return new SuperBuilderAbstract.GrandChild.GrandChildBuilderImpl(); + } + } + public static void test() { + GrandChild x = GrandChild.builder().grandChildField("").parentField(5).childField(2.5).build(); + } +} diff --git a/test/transform/resource/after-delombok/SuperBuilderAbstractToBuilder.java b/test/transform/resource/after-delombok/SuperBuilderAbstractToBuilder.java index e5c11562..53962c60 100644 --- a/test/transform/resource/after-delombok/SuperBuilderAbstractToBuilder.java +++ b/test/transform/resource/after-delombok/SuperBuilderAbstractToBuilder.java @@ -1,177 +1,177 @@ -public class SuperBuilderAbstractToBuilder {
- public static class Parent {
- int parentField;
- @java.lang.SuppressWarnings("all")
- public static abstract class ParentBuilder<C extends SuperBuilderAbstractToBuilder.Parent, B extends SuperBuilderAbstractToBuilder.Parent.ParentBuilder<C, B>> {
- @java.lang.SuppressWarnings("all")
- private int parentField;
- @java.lang.SuppressWarnings("all")
- protected B $fillValuesFrom(final C instance) {
- SuperBuilderAbstractToBuilder.Parent.ParentBuilder.$fillValuesFromInstanceIntoBuilder(instance, this);
- return self();
- }
- @java.lang.SuppressWarnings("all")
- private static void $fillValuesFromInstanceIntoBuilder(final SuperBuilderAbstractToBuilder.Parent instance, final SuperBuilderAbstractToBuilder.Parent.ParentBuilder<?, ?> b) {
- b.parentField(instance.parentField);
- }
- @java.lang.SuppressWarnings("all")
- protected abstract B self();
- @java.lang.SuppressWarnings("all")
- public abstract C build();
- /**
- * @return {@code this}.
- */
- @java.lang.SuppressWarnings("all")
- public B parentField(final int parentField) {
- this.parentField = parentField;
- return self();
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public java.lang.String toString() {
- return "SuperBuilderAbstractToBuilder.Parent.ParentBuilder(parentField=" + this.parentField + ")";
- }
- }
- @java.lang.SuppressWarnings("all")
- private static final class ParentBuilderImpl extends SuperBuilderAbstractToBuilder.Parent.ParentBuilder<SuperBuilderAbstractToBuilder.Parent, SuperBuilderAbstractToBuilder.Parent.ParentBuilderImpl> {
- @java.lang.SuppressWarnings("all")
- private ParentBuilderImpl() {
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected SuperBuilderAbstractToBuilder.Parent.ParentBuilderImpl self() {
- return this;
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public SuperBuilderAbstractToBuilder.Parent build() {
- return new SuperBuilderAbstractToBuilder.Parent(this);
- }
- }
- @java.lang.SuppressWarnings("all")
- protected Parent(final SuperBuilderAbstractToBuilder.Parent.ParentBuilder<?, ?> b) {
- this.parentField = b.parentField;
- }
- @java.lang.SuppressWarnings("all")
- public static SuperBuilderAbstractToBuilder.Parent.ParentBuilder<?, ?> builder() {
- return new SuperBuilderAbstractToBuilder.Parent.ParentBuilderImpl();
- }
- @java.lang.SuppressWarnings("all")
- public SuperBuilderAbstractToBuilder.Parent.ParentBuilder<?, ?> toBuilder() {
- return new SuperBuilderAbstractToBuilder.Parent.ParentBuilderImpl().$fillValuesFrom(this);
- }
- }
- public static abstract class Child extends Parent {
- double childField;
- @java.lang.SuppressWarnings("all")
- public static abstract class ChildBuilder<C extends SuperBuilderAbstractToBuilder.Child, B extends SuperBuilderAbstractToBuilder.Child.ChildBuilder<C, B>> extends Parent.ParentBuilder<C, B> {
- @java.lang.SuppressWarnings("all")
- private double childField;
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected B $fillValuesFrom(final C instance) {
- super.$fillValuesFrom(instance);
- SuperBuilderAbstractToBuilder.Child.ChildBuilder.$fillValuesFromInstanceIntoBuilder(instance, this);
- return self();
- }
- @java.lang.SuppressWarnings("all")
- private static void $fillValuesFromInstanceIntoBuilder(final SuperBuilderAbstractToBuilder.Child instance, final SuperBuilderAbstractToBuilder.Child.ChildBuilder<?, ?> b) {
- b.childField(instance.childField);
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected abstract B self();
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public abstract C build();
- /**
- * @return {@code this}.
- */
- @java.lang.SuppressWarnings("all")
- public B childField(final double childField) {
- this.childField = childField;
- return self();
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public java.lang.String toString() {
- return "SuperBuilderAbstractToBuilder.Child.ChildBuilder(super=" + super.toString() + ", childField=" + this.childField + ")";
- }
- }
- @java.lang.SuppressWarnings("all")
- protected Child(final SuperBuilderAbstractToBuilder.Child.ChildBuilder<?, ?> b) {
- super(b);
- this.childField = b.childField;
- }
- }
- public static class GrandChild extends Child {
- String grandChildField;
- @java.lang.SuppressWarnings("all")
- public static abstract class GrandChildBuilder<C extends SuperBuilderAbstractToBuilder.GrandChild, B extends SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilder<C, B>> extends Child.ChildBuilder<C, B> {
- @java.lang.SuppressWarnings("all")
- private String grandChildField;
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected B $fillValuesFrom(final C instance) {
- super.$fillValuesFrom(instance);
- SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilder.$fillValuesFromInstanceIntoBuilder(instance, this);
- return self();
- }
- @java.lang.SuppressWarnings("all")
- private static void $fillValuesFromInstanceIntoBuilder(final SuperBuilderAbstractToBuilder.GrandChild instance, final SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilder<?, ?> b) {
- b.grandChildField(instance.grandChildField);
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected abstract B self();
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public abstract C build();
- /**
- * @return {@code this}.
- */
- @java.lang.SuppressWarnings("all")
- public B grandChildField(final String grandChildField) {
- this.grandChildField = grandChildField;
- return self();
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public java.lang.String toString() {
- return "SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilder(super=" + super.toString() + ", grandChildField=" + this.grandChildField + ")";
- }
- }
- @java.lang.SuppressWarnings("all")
- private static final class GrandChildBuilderImpl extends SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilder<SuperBuilderAbstractToBuilder.GrandChild, SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilderImpl> {
- @java.lang.SuppressWarnings("all")
- private GrandChildBuilderImpl() {
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilderImpl self() {
- return this;
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public SuperBuilderAbstractToBuilder.GrandChild build() {
- return new SuperBuilderAbstractToBuilder.GrandChild(this);
- }
- }
- @java.lang.SuppressWarnings("all")
- protected GrandChild(final SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilder<?, ?> b) {
- super(b);
- this.grandChildField = b.grandChildField;
- }
- @java.lang.SuppressWarnings("all")
- public static SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilder<?, ?> builder() {
- return new SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilderImpl();
- }
- @java.lang.SuppressWarnings("all")
- public SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilder<?, ?> toBuilder() {
- return new SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilderImpl().$fillValuesFrom(this);
- }
- }
- public static void test() {
- GrandChild x = GrandChild.builder().grandChildField("").parentField(5).childField(2.5).build().toBuilder().build();
- }
-}
+public class SuperBuilderAbstractToBuilder { + public static class Parent { + int parentField; + @java.lang.SuppressWarnings("all") + public static abstract class ParentBuilder<C extends SuperBuilderAbstractToBuilder.Parent, B extends SuperBuilderAbstractToBuilder.Parent.ParentBuilder<C, B>> { + @java.lang.SuppressWarnings("all") + private int parentField; + @java.lang.SuppressWarnings("all") + protected B $fillValuesFrom(final C instance) { + SuperBuilderAbstractToBuilder.Parent.ParentBuilder.$fillValuesFromInstanceIntoBuilder(instance, this); + return self(); + } + @java.lang.SuppressWarnings("all") + private static void $fillValuesFromInstanceIntoBuilder(final SuperBuilderAbstractToBuilder.Parent instance, final SuperBuilderAbstractToBuilder.Parent.ParentBuilder<?, ?> b) { + b.parentField(instance.parentField); + } + @java.lang.SuppressWarnings("all") + protected abstract B self(); + @java.lang.SuppressWarnings("all") + public abstract C build(); + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public B parentField(final int parentField) { + this.parentField = parentField; + return self(); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "SuperBuilderAbstractToBuilder.Parent.ParentBuilder(parentField=" + this.parentField + ")"; + } + } + @java.lang.SuppressWarnings("all") + private static final class ParentBuilderImpl extends SuperBuilderAbstractToBuilder.Parent.ParentBuilder<SuperBuilderAbstractToBuilder.Parent, SuperBuilderAbstractToBuilder.Parent.ParentBuilderImpl> { + @java.lang.SuppressWarnings("all") + private ParentBuilderImpl() { + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected SuperBuilderAbstractToBuilder.Parent.ParentBuilderImpl self() { + return this; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public SuperBuilderAbstractToBuilder.Parent build() { + return new SuperBuilderAbstractToBuilder.Parent(this); + } + } + @java.lang.SuppressWarnings("all") + protected Parent(final SuperBuilderAbstractToBuilder.Parent.ParentBuilder<?, ?> b) { + this.parentField = b.parentField; + } + @java.lang.SuppressWarnings("all") + public static SuperBuilderAbstractToBuilder.Parent.ParentBuilder<?, ?> builder() { + return new SuperBuilderAbstractToBuilder.Parent.ParentBuilderImpl(); + } + @java.lang.SuppressWarnings("all") + public SuperBuilderAbstractToBuilder.Parent.ParentBuilder<?, ?> toBuilder() { + return new SuperBuilderAbstractToBuilder.Parent.ParentBuilderImpl().$fillValuesFrom(this); + } + } + public static abstract class Child extends Parent { + double childField; + @java.lang.SuppressWarnings("all") + public static abstract class ChildBuilder<C extends SuperBuilderAbstractToBuilder.Child, B extends SuperBuilderAbstractToBuilder.Child.ChildBuilder<C, B>> extends Parent.ParentBuilder<C, B> { + @java.lang.SuppressWarnings("all") + private double childField; + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected B $fillValuesFrom(final C instance) { + super.$fillValuesFrom(instance); + SuperBuilderAbstractToBuilder.Child.ChildBuilder.$fillValuesFromInstanceIntoBuilder(instance, this); + return self(); + } + @java.lang.SuppressWarnings("all") + private static void $fillValuesFromInstanceIntoBuilder(final SuperBuilderAbstractToBuilder.Child instance, final SuperBuilderAbstractToBuilder.Child.ChildBuilder<?, ?> b) { + b.childField(instance.childField); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected abstract B self(); + @java.lang.Override + @java.lang.SuppressWarnings("all") + public abstract C build(); + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public B childField(final double childField) { + this.childField = childField; + return self(); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "SuperBuilderAbstractToBuilder.Child.ChildBuilder(super=" + super.toString() + ", childField=" + this.childField + ")"; + } + } + @java.lang.SuppressWarnings("all") + protected Child(final SuperBuilderAbstractToBuilder.Child.ChildBuilder<?, ?> b) { + super(b); + this.childField = b.childField; + } + } + public static class GrandChild extends Child { + String grandChildField; + @java.lang.SuppressWarnings("all") + public static abstract class GrandChildBuilder<C extends SuperBuilderAbstractToBuilder.GrandChild, B extends SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilder<C, B>> extends Child.ChildBuilder<C, B> { + @java.lang.SuppressWarnings("all") + private String grandChildField; + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected B $fillValuesFrom(final C instance) { + super.$fillValuesFrom(instance); + SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilder.$fillValuesFromInstanceIntoBuilder(instance, this); + return self(); + } + @java.lang.SuppressWarnings("all") + private static void $fillValuesFromInstanceIntoBuilder(final SuperBuilderAbstractToBuilder.GrandChild instance, final SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilder<?, ?> b) { + b.grandChildField(instance.grandChildField); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected abstract B self(); + @java.lang.Override + @java.lang.SuppressWarnings("all") + public abstract C build(); + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public B grandChildField(final String grandChildField) { + this.grandChildField = grandChildField; + return self(); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilder(super=" + super.toString() + ", grandChildField=" + this.grandChildField + ")"; + } + } + @java.lang.SuppressWarnings("all") + private static final class GrandChildBuilderImpl extends SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilder<SuperBuilderAbstractToBuilder.GrandChild, SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilderImpl> { + @java.lang.SuppressWarnings("all") + private GrandChildBuilderImpl() { + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilderImpl self() { + return this; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public SuperBuilderAbstractToBuilder.GrandChild build() { + return new SuperBuilderAbstractToBuilder.GrandChild(this); + } + } + @java.lang.SuppressWarnings("all") + protected GrandChild(final SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilder<?, ?> b) { + super(b); + this.grandChildField = b.grandChildField; + } + @java.lang.SuppressWarnings("all") + public static SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilder<?, ?> builder() { + return new SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilderImpl(); + } + @java.lang.SuppressWarnings("all") + public SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilder<?, ?> toBuilder() { + return new SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilderImpl().$fillValuesFrom(this); + } + } + public static void test() { + GrandChild x = GrandChild.builder().grandChildField("").parentField(5).childField(2.5).build().toBuilder().build(); + } +} diff --git a/test/transform/resource/after-delombok/SuperBuilderBasic.java b/test/transform/resource/after-delombok/SuperBuilderBasic.java index 482ead86..7fff2ef8 100644 --- a/test/transform/resource/after-delombok/SuperBuilderBasic.java +++ b/test/transform/resource/after-delombok/SuperBuilderBasic.java @@ -1,142 +1,142 @@ -import java.util.List;
-public class SuperBuilderBasic {
- public static class Parent {
- int field1;
- List<String> items;
- @java.lang.SuppressWarnings("all")
- public static abstract class ParentBuilder<C extends SuperBuilderBasic.Parent, B extends SuperBuilderBasic.Parent.ParentBuilder<C, B>> {
- @java.lang.SuppressWarnings("all")
- private int field1;
- @java.lang.SuppressWarnings("all")
- private java.util.ArrayList<String> items;
- @java.lang.SuppressWarnings("all")
- protected abstract B self();
- @java.lang.SuppressWarnings("all")
- public abstract C build();
- /**
- * @return {@code this}.
- */
- @java.lang.SuppressWarnings("all")
- public B field1(final int field1) {
- this.field1 = field1;
- return self();
- }
- @java.lang.SuppressWarnings("all")
- public B item(final String item) {
- if (this.items == null) this.items = new java.util.ArrayList<String>();
- this.items.add(item);
- return self();
- }
- @java.lang.SuppressWarnings("all")
- public B items(final java.util.Collection<? extends String> items) {
- if (items == null) {
- throw new java.lang.NullPointerException("items cannot be null");
- }
- if (this.items == null) this.items = new java.util.ArrayList<String>();
- this.items.addAll(items);
- return self();
- }
- @java.lang.SuppressWarnings("all")
- public B clearItems() {
- if (this.items != null) this.items.clear();
- return self();
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public java.lang.String toString() {
- return "SuperBuilderBasic.Parent.ParentBuilder(field1=" + this.field1 + ", items=" + this.items + ")";
- }
- }
- @java.lang.SuppressWarnings("all")
- private static final class ParentBuilderImpl extends SuperBuilderBasic.Parent.ParentBuilder<SuperBuilderBasic.Parent, SuperBuilderBasic.Parent.ParentBuilderImpl> {
- @java.lang.SuppressWarnings("all")
- private ParentBuilderImpl() {
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected SuperBuilderBasic.Parent.ParentBuilderImpl self() {
- return this;
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public SuperBuilderBasic.Parent build() {
- return new SuperBuilderBasic.Parent(this);
- }
- }
- @java.lang.SuppressWarnings("all")
- protected Parent(final SuperBuilderBasic.Parent.ParentBuilder<?, ?> b) {
- this.field1 = b.field1;
- java.util.List<String> items;
- switch (b.items == null ? 0 : b.items.size()) {
- case 0:
- items = java.util.Collections.emptyList();
- break;
- case 1:
- items = java.util.Collections.singletonList(b.items.get(0));
- break;
- default:
- items = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(b.items));
- }
- this.items = items;
- }
- @java.lang.SuppressWarnings("all")
- public static SuperBuilderBasic.Parent.ParentBuilder<?, ?> builder() {
- return new SuperBuilderBasic.Parent.ParentBuilderImpl();
- }
- }
- public static class Child extends SuperBuilderBasic.Parent {
- double field3;
- @java.lang.SuppressWarnings("all")
- public static abstract class ChildBuilder<C extends SuperBuilderBasic.Child, B extends SuperBuilderBasic.Child.ChildBuilder<C, B>> extends SuperBuilderBasic.Parent.ParentBuilder<C, B> {
- @java.lang.SuppressWarnings("all")
- private double field3;
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected abstract B self();
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public abstract C build();
- /**
- * @return {@code this}.
- */
- @java.lang.SuppressWarnings("all")
- public B field3(final double field3) {
- this.field3 = field3;
- return self();
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public java.lang.String toString() {
- return "SuperBuilderBasic.Child.ChildBuilder(super=" + super.toString() + ", field3=" + this.field3 + ")";
- }
- }
- @java.lang.SuppressWarnings("all")
- private static final class ChildBuilderImpl extends SuperBuilderBasic.Child.ChildBuilder<SuperBuilderBasic.Child, SuperBuilderBasic.Child.ChildBuilderImpl> {
- @java.lang.SuppressWarnings("all")
- private ChildBuilderImpl() {
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected SuperBuilderBasic.Child.ChildBuilderImpl self() {
- return this;
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public SuperBuilderBasic.Child build() {
- return new SuperBuilderBasic.Child(this);
- }
- }
- @java.lang.SuppressWarnings("all")
- protected Child(final SuperBuilderBasic.Child.ChildBuilder<?, ?> b) {
- super(b);
- this.field3 = b.field3;
- }
- @java.lang.SuppressWarnings("all")
- public static SuperBuilderBasic.Child.ChildBuilder<?, ?> builder() {
- return new SuperBuilderBasic.Child.ChildBuilderImpl();
- }
- }
- public static void test() {
- Child x = Child.builder().field3(0.0).field1(5).item("").build();
- }
-}
+import java.util.List; +public class SuperBuilderBasic { + public static class Parent { + int field1; + List<String> items; + @java.lang.SuppressWarnings("all") + public static abstract class ParentBuilder<C extends SuperBuilderBasic.Parent, B extends SuperBuilderBasic.Parent.ParentBuilder<C, B>> { + @java.lang.SuppressWarnings("all") + private int field1; + @java.lang.SuppressWarnings("all") + private java.util.ArrayList<String> items; + @java.lang.SuppressWarnings("all") + protected abstract B self(); + @java.lang.SuppressWarnings("all") + public abstract C build(); + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public B field1(final int field1) { + this.field1 = field1; + return self(); + } + @java.lang.SuppressWarnings("all") + public B item(final String item) { + if (this.items == null) this.items = new java.util.ArrayList<String>(); + this.items.add(item); + return self(); + } + @java.lang.SuppressWarnings("all") + public B items(final java.util.Collection<? extends String> items) { + if (items == null) { + throw new java.lang.NullPointerException("items cannot be null"); + } + if (this.items == null) this.items = new java.util.ArrayList<String>(); + this.items.addAll(items); + return self(); + } + @java.lang.SuppressWarnings("all") + public B clearItems() { + if (this.items != null) this.items.clear(); + return self(); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "SuperBuilderBasic.Parent.ParentBuilder(field1=" + this.field1 + ", items=" + this.items + ")"; + } + } + @java.lang.SuppressWarnings("all") + private static final class ParentBuilderImpl extends SuperBuilderBasic.Parent.ParentBuilder<SuperBuilderBasic.Parent, SuperBuilderBasic.Parent.ParentBuilderImpl> { + @java.lang.SuppressWarnings("all") + private ParentBuilderImpl() { + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected SuperBuilderBasic.Parent.ParentBuilderImpl self() { + return this; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public SuperBuilderBasic.Parent build() { + return new SuperBuilderBasic.Parent(this); + } + } + @java.lang.SuppressWarnings("all") + protected Parent(final SuperBuilderBasic.Parent.ParentBuilder<?, ?> b) { + this.field1 = b.field1; + java.util.List<String> items; + switch (b.items == null ? 0 : b.items.size()) { + case 0: + items = java.util.Collections.emptyList(); + break; + case 1: + items = java.util.Collections.singletonList(b.items.get(0)); + break; + default: + items = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(b.items)); + } + this.items = items; + } + @java.lang.SuppressWarnings("all") + public static SuperBuilderBasic.Parent.ParentBuilder<?, ?> builder() { + return new SuperBuilderBasic.Parent.ParentBuilderImpl(); + } + } + public static class Child extends SuperBuilderBasic.Parent { + double field3; + @java.lang.SuppressWarnings("all") + public static abstract class ChildBuilder<C extends SuperBuilderBasic.Child, B extends SuperBuilderBasic.Child.ChildBuilder<C, B>> extends SuperBuilderBasic.Parent.ParentBuilder<C, B> { + @java.lang.SuppressWarnings("all") + private double field3; + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected abstract B self(); + @java.lang.Override + @java.lang.SuppressWarnings("all") + public abstract C build(); + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public B field3(final double field3) { + this.field3 = field3; + return self(); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "SuperBuilderBasic.Child.ChildBuilder(super=" + super.toString() + ", field3=" + this.field3 + ")"; + } + } + @java.lang.SuppressWarnings("all") + private static final class ChildBuilderImpl extends SuperBuilderBasic.Child.ChildBuilder<SuperBuilderBasic.Child, SuperBuilderBasic.Child.ChildBuilderImpl> { + @java.lang.SuppressWarnings("all") + private ChildBuilderImpl() { + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected SuperBuilderBasic.Child.ChildBuilderImpl self() { + return this; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public SuperBuilderBasic.Child build() { + return new SuperBuilderBasic.Child(this); + } + } + @java.lang.SuppressWarnings("all") + protected Child(final SuperBuilderBasic.Child.ChildBuilder<?, ?> b) { + super(b); + this.field3 = b.field3; + } + @java.lang.SuppressWarnings("all") + public static SuperBuilderBasic.Child.ChildBuilder<?, ?> builder() { + return new SuperBuilderBasic.Child.ChildBuilderImpl(); + } + } + public static void test() { + Child x = Child.builder().field3(0.0).field1(5).item("").build(); + } +} diff --git a/test/transform/resource/after-delombok/SuperBuilderBasicToBuilder.java b/test/transform/resource/after-delombok/SuperBuilderBasicToBuilder.java index 7c1b6ff0..add6f841 100644 --- a/test/transform/resource/after-delombok/SuperBuilderBasicToBuilder.java +++ b/test/transform/resource/after-delombok/SuperBuilderBasicToBuilder.java @@ -1,216 +1,216 @@ -import java.util.List;
-public class SuperBuilderBasicToBuilder {
- public static class Parent {
- private int field1;
- int obtainViaField;
- int obtainViaMethod;
- String obtainViaStaticMethod;
- List<String> items;
- private int method() {
- return 2;
- }
- private static String staticMethod(Parent instance) {
- return "staticMethod";
- }
- @java.lang.SuppressWarnings("all")
- public static abstract class ParentBuilder<C extends SuperBuilderBasicToBuilder.Parent, B extends SuperBuilderBasicToBuilder.Parent.ParentBuilder<C, B>> {
- @java.lang.SuppressWarnings("all")
- private int field1;
- @java.lang.SuppressWarnings("all")
- private int obtainViaField;
- @java.lang.SuppressWarnings("all")
- private int obtainViaMethod;
- @java.lang.SuppressWarnings("all")
- private String obtainViaStaticMethod;
- @java.lang.SuppressWarnings("all")
- private java.util.ArrayList<String> items;
- @java.lang.SuppressWarnings("all")
- protected B $fillValuesFrom(final C instance) {
- SuperBuilderBasicToBuilder.Parent.ParentBuilder.$fillValuesFromInstanceIntoBuilder(instance, this);
- return self();
- }
- @java.lang.SuppressWarnings("all")
- private static void $fillValuesFromInstanceIntoBuilder(final SuperBuilderBasicToBuilder.Parent instance, final SuperBuilderBasicToBuilder.Parent.ParentBuilder<?, ?> b) {
- b.field1(instance.field1);
- b.obtainViaField(instance.field1);
- b.obtainViaMethod(instance.method());
- b.obtainViaStaticMethod(SuperBuilderBasicToBuilder.Parent.staticMethod(instance));
- b.items(instance.items == null ? java.util.Collections.emptyList() : instance.items);
- }
- @java.lang.SuppressWarnings("all")
- protected abstract B self();
- @java.lang.SuppressWarnings("all")
- public abstract C build();
- /**
- * @return {@code this}.
- */
- @java.lang.SuppressWarnings("all")
- public B field1(final int field1) {
- this.field1 = field1;
- return self();
- }
- /**
- * @return {@code this}.
- */
- @java.lang.SuppressWarnings("all")
- public B obtainViaField(final int obtainViaField) {
- this.obtainViaField = obtainViaField;
- return self();
- }
- /**
- * @return {@code this}.
- */
- @java.lang.SuppressWarnings("all")
- public B obtainViaMethod(final int obtainViaMethod) {
- this.obtainViaMethod = obtainViaMethod;
- return self();
- }
- /**
- * @return {@code this}.
- */
- @java.lang.SuppressWarnings("all")
- public B obtainViaStaticMethod(final String obtainViaStaticMethod) {
- this.obtainViaStaticMethod = obtainViaStaticMethod;
- return self();
- }
- @java.lang.SuppressWarnings("all")
- public B item(final String item) {
- if (this.items == null) this.items = new java.util.ArrayList<String>();
- this.items.add(item);
- return self();
- }
- @java.lang.SuppressWarnings("all")
- public B items(final java.util.Collection<? extends String> items) {
- if (items == null) {
- throw new java.lang.NullPointerException("items cannot be null");
- }
- if (this.items == null) this.items = new java.util.ArrayList<String>();
- this.items.addAll(items);
- return self();
- }
- @java.lang.SuppressWarnings("all")
- public B clearItems() {
- if (this.items != null) this.items.clear();
- return self();
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public java.lang.String toString() {
- return "SuperBuilderBasicToBuilder.Parent.ParentBuilder(field1=" + this.field1 + ", obtainViaField=" + this.obtainViaField + ", obtainViaMethod=" + this.obtainViaMethod + ", obtainViaStaticMethod=" + this.obtainViaStaticMethod + ", items=" + this.items + ")";
- }
- }
- @java.lang.SuppressWarnings("all")
- private static final class ParentBuilderImpl extends SuperBuilderBasicToBuilder.Parent.ParentBuilder<SuperBuilderBasicToBuilder.Parent, SuperBuilderBasicToBuilder.Parent.ParentBuilderImpl> {
- @java.lang.SuppressWarnings("all")
- private ParentBuilderImpl() {
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected SuperBuilderBasicToBuilder.Parent.ParentBuilderImpl self() {
- return this;
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public SuperBuilderBasicToBuilder.Parent build() {
- return new SuperBuilderBasicToBuilder.Parent(this);
- }
- }
- @java.lang.SuppressWarnings("all")
- protected Parent(final SuperBuilderBasicToBuilder.Parent.ParentBuilder<?, ?> b) {
- this.field1 = b.field1;
- this.obtainViaField = b.obtainViaField;
- this.obtainViaMethod = b.obtainViaMethod;
- this.obtainViaStaticMethod = b.obtainViaStaticMethod;
- java.util.List<String> items;
- switch (b.items == null ? 0 : b.items.size()) {
- case 0:
- items = java.util.Collections.emptyList();
- break;
- case 1:
- items = java.util.Collections.singletonList(b.items.get(0));
- break;
- default:
- items = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(b.items));
- }
- this.items = items;
- }
- @java.lang.SuppressWarnings("all")
- public static SuperBuilderBasicToBuilder.Parent.ParentBuilder<?, ?> builder() {
- return new SuperBuilderBasicToBuilder.Parent.ParentBuilderImpl();
- }
- @java.lang.SuppressWarnings("all")
- public SuperBuilderBasicToBuilder.Parent.ParentBuilder<?, ?> toBuilder() {
- return new SuperBuilderBasicToBuilder.Parent.ParentBuilderImpl().$fillValuesFrom(this);
- }
- }
- public static class Child extends Parent {
- private double field3;
- @java.lang.SuppressWarnings("all")
- public static abstract class ChildBuilder<C extends SuperBuilderBasicToBuilder.Child, B extends SuperBuilderBasicToBuilder.Child.ChildBuilder<C, B>> extends Parent.ParentBuilder<C, B> {
- @java.lang.SuppressWarnings("all")
- private double field3;
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected B $fillValuesFrom(final C instance) {
- super.$fillValuesFrom(instance);
- SuperBuilderBasicToBuilder.Child.ChildBuilder.$fillValuesFromInstanceIntoBuilder(instance, this);
- return self();
- }
- @java.lang.SuppressWarnings("all")
- private static void $fillValuesFromInstanceIntoBuilder(final SuperBuilderBasicToBuilder.Child instance, final SuperBuilderBasicToBuilder.Child.ChildBuilder<?, ?> b) {
- b.field3(instance.field3);
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected abstract B self();
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public abstract C build();
- /**
- * @return {@code this}.
- */
- @java.lang.SuppressWarnings("all")
- public B field3(final double field3) {
- this.field3 = field3;
- return self();
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public java.lang.String toString() {
- return "SuperBuilderBasicToBuilder.Child.ChildBuilder(super=" + super.toString() + ", field3=" + this.field3 + ")";
- }
- }
- @java.lang.SuppressWarnings("all")
- private static final class ChildBuilderImpl extends SuperBuilderBasicToBuilder.Child.ChildBuilder<SuperBuilderBasicToBuilder.Child, SuperBuilderBasicToBuilder.Child.ChildBuilderImpl> {
- @java.lang.SuppressWarnings("all")
- private ChildBuilderImpl() {
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected SuperBuilderBasicToBuilder.Child.ChildBuilderImpl self() {
- return this;
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public SuperBuilderBasicToBuilder.Child build() {
- return new SuperBuilderBasicToBuilder.Child(this);
- }
- }
- @java.lang.SuppressWarnings("all")
- protected Child(final SuperBuilderBasicToBuilder.Child.ChildBuilder<?, ?> b) {
- super(b);
- this.field3 = b.field3;
- }
- @java.lang.SuppressWarnings("all")
- public static SuperBuilderBasicToBuilder.Child.ChildBuilder<?, ?> builder() {
- return new SuperBuilderBasicToBuilder.Child.ChildBuilderImpl();
- }
- @java.lang.SuppressWarnings("all")
- public SuperBuilderBasicToBuilder.Child.ChildBuilder<?, ?> toBuilder() {
- return new SuperBuilderBasicToBuilder.Child.ChildBuilderImpl().$fillValuesFrom(this);
- }
- }
- public static void test() {
- Child x = Child.builder().field3(0.0).field1(5).item("").build().toBuilder().build();
- }
-}
+import java.util.List; +public class SuperBuilderBasicToBuilder { + public static class Parent { + private int field1; + int obtainViaField; + int obtainViaMethod; + String obtainViaStaticMethod; + List<String> items; + private int method() { + return 2; + } + private static String staticMethod(Parent instance) { + return "staticMethod"; + } + @java.lang.SuppressWarnings("all") + public static abstract class ParentBuilder<C extends SuperBuilderBasicToBuilder.Parent, B extends SuperBuilderBasicToBuilder.Parent.ParentBuilder<C, B>> { + @java.lang.SuppressWarnings("all") + private int field1; + @java.lang.SuppressWarnings("all") + private int obtainViaField; + @java.lang.SuppressWarnings("all") + private int obtainViaMethod; + @java.lang.SuppressWarnings("all") + private String obtainViaStaticMethod; + @java.lang.SuppressWarnings("all") + private java.util.ArrayList<String> items; + @java.lang.SuppressWarnings("all") + protected B $fillValuesFrom(final C instance) { + SuperBuilderBasicToBuilder.Parent.ParentBuilder.$fillValuesFromInstanceIntoBuilder(instance, this); + return self(); + } + @java.lang.SuppressWarnings("all") + private static void $fillValuesFromInstanceIntoBuilder(final SuperBuilderBasicToBuilder.Parent instance, final SuperBuilderBasicToBuilder.Parent.ParentBuilder<?, ?> b) { + b.field1(instance.field1); + b.obtainViaField(instance.field1); + b.obtainViaMethod(instance.method()); + b.obtainViaStaticMethod(SuperBuilderBasicToBuilder.Parent.staticMethod(instance)); + b.items(instance.items == null ? java.util.Collections.<String>emptyList() : instance.items); + } + @java.lang.SuppressWarnings("all") + protected abstract B self(); + @java.lang.SuppressWarnings("all") + public abstract C build(); + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public B field1(final int field1) { + this.field1 = field1; + return self(); + } + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public B obtainViaField(final int obtainViaField) { + this.obtainViaField = obtainViaField; + return self(); + } + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public B obtainViaMethod(final int obtainViaMethod) { + this.obtainViaMethod = obtainViaMethod; + return self(); + } + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public B obtainViaStaticMethod(final String obtainViaStaticMethod) { + this.obtainViaStaticMethod = obtainViaStaticMethod; + return self(); + } + @java.lang.SuppressWarnings("all") + public B item(final String item) { + if (this.items == null) this.items = new java.util.ArrayList<String>(); + this.items.add(item); + return self(); + } + @java.lang.SuppressWarnings("all") + public B items(final java.util.Collection<? extends String> items) { + if (items == null) { + throw new java.lang.NullPointerException("items cannot be null"); + } + if (this.items == null) this.items = new java.util.ArrayList<String>(); + this.items.addAll(items); + return self(); + } + @java.lang.SuppressWarnings("all") + public B clearItems() { + if (this.items != null) this.items.clear(); + return self(); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "SuperBuilderBasicToBuilder.Parent.ParentBuilder(field1=" + this.field1 + ", obtainViaField=" + this.obtainViaField + ", obtainViaMethod=" + this.obtainViaMethod + ", obtainViaStaticMethod=" + this.obtainViaStaticMethod + ", items=" + this.items + ")"; + } + } + @java.lang.SuppressWarnings("all") + private static final class ParentBuilderImpl extends SuperBuilderBasicToBuilder.Parent.ParentBuilder<SuperBuilderBasicToBuilder.Parent, SuperBuilderBasicToBuilder.Parent.ParentBuilderImpl> { + @java.lang.SuppressWarnings("all") + private ParentBuilderImpl() { + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected SuperBuilderBasicToBuilder.Parent.ParentBuilderImpl self() { + return this; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public SuperBuilderBasicToBuilder.Parent build() { + return new SuperBuilderBasicToBuilder.Parent(this); + } + } + @java.lang.SuppressWarnings("all") + protected Parent(final SuperBuilderBasicToBuilder.Parent.ParentBuilder<?, ?> b) { + this.field1 = b.field1; + this.obtainViaField = b.obtainViaField; + this.obtainViaMethod = b.obtainViaMethod; + this.obtainViaStaticMethod = b.obtainViaStaticMethod; + java.util.List<String> items; + switch (b.items == null ? 0 : b.items.size()) { + case 0: + items = java.util.Collections.emptyList(); + break; + case 1: + items = java.util.Collections.singletonList(b.items.get(0)); + break; + default: + items = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(b.items)); + } + this.items = items; + } + @java.lang.SuppressWarnings("all") + public static SuperBuilderBasicToBuilder.Parent.ParentBuilder<?, ?> builder() { + return new SuperBuilderBasicToBuilder.Parent.ParentBuilderImpl(); + } + @java.lang.SuppressWarnings("all") + public SuperBuilderBasicToBuilder.Parent.ParentBuilder<?, ?> toBuilder() { + return new SuperBuilderBasicToBuilder.Parent.ParentBuilderImpl().$fillValuesFrom(this); + } + } + public static class Child extends Parent { + private double field3; + @java.lang.SuppressWarnings("all") + public static abstract class ChildBuilder<C extends SuperBuilderBasicToBuilder.Child, B extends SuperBuilderBasicToBuilder.Child.ChildBuilder<C, B>> extends Parent.ParentBuilder<C, B> { + @java.lang.SuppressWarnings("all") + private double field3; + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected B $fillValuesFrom(final C instance) { + super.$fillValuesFrom(instance); + SuperBuilderBasicToBuilder.Child.ChildBuilder.$fillValuesFromInstanceIntoBuilder(instance, this); + return self(); + } + @java.lang.SuppressWarnings("all") + private static void $fillValuesFromInstanceIntoBuilder(final SuperBuilderBasicToBuilder.Child instance, final SuperBuilderBasicToBuilder.Child.ChildBuilder<?, ?> b) { + b.field3(instance.field3); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected abstract B self(); + @java.lang.Override + @java.lang.SuppressWarnings("all") + public abstract C build(); + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public B field3(final double field3) { + this.field3 = field3; + return self(); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "SuperBuilderBasicToBuilder.Child.ChildBuilder(super=" + super.toString() + ", field3=" + this.field3 + ")"; + } + } + @java.lang.SuppressWarnings("all") + private static final class ChildBuilderImpl extends SuperBuilderBasicToBuilder.Child.ChildBuilder<SuperBuilderBasicToBuilder.Child, SuperBuilderBasicToBuilder.Child.ChildBuilderImpl> { + @java.lang.SuppressWarnings("all") + private ChildBuilderImpl() { + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected SuperBuilderBasicToBuilder.Child.ChildBuilderImpl self() { + return this; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public SuperBuilderBasicToBuilder.Child build() { + return new SuperBuilderBasicToBuilder.Child(this); + } + } + @java.lang.SuppressWarnings("all") + protected Child(final SuperBuilderBasicToBuilder.Child.ChildBuilder<?, ?> b) { + super(b); + this.field3 = b.field3; + } + @java.lang.SuppressWarnings("all") + public static SuperBuilderBasicToBuilder.Child.ChildBuilder<?, ?> builder() { + return new SuperBuilderBasicToBuilder.Child.ChildBuilderImpl(); + } + @java.lang.SuppressWarnings("all") + public SuperBuilderBasicToBuilder.Child.ChildBuilder<?, ?> toBuilder() { + return new SuperBuilderBasicToBuilder.Child.ChildBuilderImpl().$fillValuesFrom(this); + } + } + public static void test() { + Child x = Child.builder().field3(0.0).field1(5).item("").build().toBuilder().build(); + } +} diff --git a/test/transform/resource/after-delombok/SuperBuilderCustomized.java b/test/transform/resource/after-delombok/SuperBuilderCustomized.java index 7d7c4ca8..3a0bbd9b 100644 --- a/test/transform/resource/after-delombok/SuperBuilderCustomized.java +++ b/test/transform/resource/after-delombok/SuperBuilderCustomized.java @@ -1,103 +1,103 @@ -import java.util.List;
-public class SuperBuilderCustomized {
- public static class Parent {
- public static abstract class ParentBuilder<C extends Parent, B extends ParentBuilder<C, B>> {
- @java.lang.SuppressWarnings("all")
- private int field1;
- public B resetToDefault() {
- field1 = 0;
- return self();
- }
- public B field1(int field1) {
- this.field1 = field1 + 1;
- return self();
- }
- @java.lang.SuppressWarnings("all")
- protected abstract B self();
- @java.lang.SuppressWarnings("all")
- public abstract C build();
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public java.lang.String toString() {
- return "SuperBuilderCustomized.Parent.ParentBuilder(field1=" + this.field1 + ")";
- }
- }
- int field1;
- protected Parent(ParentBuilder<?, ?> b) {
- if (b.field1 == 0) throw new IllegalArgumentException("field1 must be != 0");
- this.field1 = b.field1;
- }
- public static SuperBuilderCustomized.Parent.ParentBuilder<?, ?> builder(int field1) {
- return new SuperBuilderCustomized.Parent.ParentBuilderImpl().field1(field1);
- }
- @java.lang.SuppressWarnings("all")
- private static final class ParentBuilderImpl extends SuperBuilderCustomized.Parent.ParentBuilder<SuperBuilderCustomized.Parent, SuperBuilderCustomized.Parent.ParentBuilderImpl> {
- @java.lang.SuppressWarnings("all")
- private ParentBuilderImpl() {
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected SuperBuilderCustomized.Parent.ParentBuilderImpl self() {
- return this;
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public SuperBuilderCustomized.Parent build() {
- return new SuperBuilderCustomized.Parent(this);
- }
- }
- }
- public static class Child extends Parent {
- private static final class ChildBuilderImpl extends ChildBuilder<Child, ChildBuilderImpl> {
- @Override
- public Child build() {
- this.resetToDefault();
- return new Child(this);
- }
- @java.lang.SuppressWarnings("all")
- private ChildBuilderImpl() {
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected SuperBuilderCustomized.Child.ChildBuilderImpl self() {
- return this;
- }
- }
- double field2;
- public static ChildBuilder<?, ?> builder() {
- return new ChildBuilderImpl().field2(10.0);
- }
- @java.lang.SuppressWarnings("all")
- public static abstract class ChildBuilder<C extends SuperBuilderCustomized.Child, B extends SuperBuilderCustomized.Child.ChildBuilder<C, B>> extends Parent.ParentBuilder<C, B> {
- @java.lang.SuppressWarnings("all")
- private double field2;
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected abstract B self();
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public abstract C build();
- /**
- * @return {@code this}.
- */
- @java.lang.SuppressWarnings("all")
- public B field2(final double field2) {
- this.field2 = field2;
- return self();
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public java.lang.String toString() {
- return "SuperBuilderCustomized.Child.ChildBuilder(super=" + super.toString() + ", field2=" + this.field2 + ")";
- }
- }
- @java.lang.SuppressWarnings("all")
- protected Child(final SuperBuilderCustomized.Child.ChildBuilder<?, ?> b) {
- super(b);
- this.field2 = b.field2;
- }
- }
- public static void test() {
- Child x = Child.builder().field2(1.0).field1(5).resetToDefault().build();
- }
-}
+import java.util.List; +public class SuperBuilderCustomized { + public static class Parent { + public static abstract class ParentBuilder<C extends Parent, B extends ParentBuilder<C, B>> { + @java.lang.SuppressWarnings("all") + private int field1; + public B resetToDefault() { + field1 = 0; + return self(); + } + public B field1(int field1) { + this.field1 = field1 + 1; + return self(); + } + @java.lang.SuppressWarnings("all") + protected abstract B self(); + @java.lang.SuppressWarnings("all") + public abstract C build(); + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "SuperBuilderCustomized.Parent.ParentBuilder(field1=" + this.field1 + ")"; + } + } + int field1; + protected Parent(ParentBuilder<?, ?> b) { + if (b.field1 == 0) throw new IllegalArgumentException("field1 must be != 0"); + this.field1 = b.field1; + } + public static SuperBuilderCustomized.Parent.ParentBuilder<?, ?> builder(int field1) { + return new SuperBuilderCustomized.Parent.ParentBuilderImpl().field1(field1); + } + @java.lang.SuppressWarnings("all") + private static final class ParentBuilderImpl extends SuperBuilderCustomized.Parent.ParentBuilder<SuperBuilderCustomized.Parent, SuperBuilderCustomized.Parent.ParentBuilderImpl> { + @java.lang.SuppressWarnings("all") + private ParentBuilderImpl() { + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected SuperBuilderCustomized.Parent.ParentBuilderImpl self() { + return this; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public SuperBuilderCustomized.Parent build() { + return new SuperBuilderCustomized.Parent(this); + } + } + } + public static class Child extends Parent { + private static final class ChildBuilderImpl extends ChildBuilder<Child, ChildBuilderImpl> { + @Override + public Child build() { + this.resetToDefault(); + return new Child(this); + } + @java.lang.SuppressWarnings("all") + private ChildBuilderImpl() { + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected SuperBuilderCustomized.Child.ChildBuilderImpl self() { + return this; + } + } + double field2; + public static ChildBuilder<?, ?> builder() { + return new ChildBuilderImpl().field2(10.0); + } + @java.lang.SuppressWarnings("all") + public static abstract class ChildBuilder<C extends SuperBuilderCustomized.Child, B extends SuperBuilderCustomized.Child.ChildBuilder<C, B>> extends Parent.ParentBuilder<C, B> { + @java.lang.SuppressWarnings("all") + private double field2; + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected abstract B self(); + @java.lang.Override + @java.lang.SuppressWarnings("all") + public abstract C build(); + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public B field2(final double field2) { + this.field2 = field2; + return self(); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "SuperBuilderCustomized.Child.ChildBuilder(super=" + super.toString() + ", field2=" + this.field2 + ")"; + } + } + @java.lang.SuppressWarnings("all") + protected Child(final SuperBuilderCustomized.Child.ChildBuilder<?, ?> b) { + super(b); + this.field2 = b.field2; + } + } + public static void test() { + Child x = Child.builder().field2(1.0).field1(5).resetToDefault().build(); + } +} diff --git a/test/transform/resource/after-delombok/SuperBuilderCustomizedWithSetterPrefix.java b/test/transform/resource/after-delombok/SuperBuilderCustomizedWithSetterPrefix.java index 8cc5dfe0..cee5ac89 100644 --- a/test/transform/resource/after-delombok/SuperBuilderCustomizedWithSetterPrefix.java +++ b/test/transform/resource/after-delombok/SuperBuilderCustomizedWithSetterPrefix.java @@ -1,50 +1,50 @@ -import java.util.List;
-public class SuperBuilderCustomizedWithSetterPrefix {
- public static class Parent {
- public static abstract class ParentBuilder<C extends Parent, B extends ParentBuilder<C, B>> {
- @java.lang.SuppressWarnings("all")
- private int field1;
- public B setField1(int field1) {
- this.field1 = field1 + 1;
- return self();
- }
- @java.lang.SuppressWarnings("all")
- protected abstract B self();
- @java.lang.SuppressWarnings("all")
- public abstract C build();
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public java.lang.String toString() {
- return "SuperBuilderCustomizedWithSetterPrefix.Parent.ParentBuilder(field1=" + this.field1 + ")";
- }
- }
- int field1;
- @java.lang.SuppressWarnings("all")
- private static final class ParentBuilderImpl extends SuperBuilderCustomizedWithSetterPrefix.Parent.ParentBuilder<SuperBuilderCustomizedWithSetterPrefix.Parent, SuperBuilderCustomizedWithSetterPrefix.Parent.ParentBuilderImpl> {
- @java.lang.SuppressWarnings("all")
- private ParentBuilderImpl() {
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected SuperBuilderCustomizedWithSetterPrefix.Parent.ParentBuilderImpl self() {
- return this;
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public SuperBuilderCustomizedWithSetterPrefix.Parent build() {
- return new SuperBuilderCustomizedWithSetterPrefix.Parent(this);
- }
- }
- @java.lang.SuppressWarnings("all")
- protected Parent(final SuperBuilderCustomizedWithSetterPrefix.Parent.ParentBuilder<?, ?> b) {
- this.field1 = b.field1;
- }
- @java.lang.SuppressWarnings("all")
- public static SuperBuilderCustomizedWithSetterPrefix.Parent.ParentBuilder<?, ?> builder() {
- return new SuperBuilderCustomizedWithSetterPrefix.Parent.ParentBuilderImpl();
- }
- }
- public static void test() {
- Parent x = Parent.builder().setField1(5).build();
- }
-}
+import java.util.List; +public class SuperBuilderCustomizedWithSetterPrefix { + public static class Parent { + public static abstract class ParentBuilder<C extends Parent, B extends ParentBuilder<C, B>> { + @java.lang.SuppressWarnings("all") + private int field1; + public B setField1(int field1) { + this.field1 = field1 + 1; + return self(); + } + @java.lang.SuppressWarnings("all") + protected abstract B self(); + @java.lang.SuppressWarnings("all") + public abstract C build(); + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "SuperBuilderCustomizedWithSetterPrefix.Parent.ParentBuilder(field1=" + this.field1 + ")"; + } + } + int field1; + @java.lang.SuppressWarnings("all") + private static final class ParentBuilderImpl extends SuperBuilderCustomizedWithSetterPrefix.Parent.ParentBuilder<SuperBuilderCustomizedWithSetterPrefix.Parent, SuperBuilderCustomizedWithSetterPrefix.Parent.ParentBuilderImpl> { + @java.lang.SuppressWarnings("all") + private ParentBuilderImpl() { + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected SuperBuilderCustomizedWithSetterPrefix.Parent.ParentBuilderImpl self() { + return this; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public SuperBuilderCustomizedWithSetterPrefix.Parent build() { + return new SuperBuilderCustomizedWithSetterPrefix.Parent(this); + } + } + @java.lang.SuppressWarnings("all") + protected Parent(final SuperBuilderCustomizedWithSetterPrefix.Parent.ParentBuilder<?, ?> b) { + this.field1 = b.field1; + } + @java.lang.SuppressWarnings("all") + public static SuperBuilderCustomizedWithSetterPrefix.Parent.ParentBuilder<?, ?> builder() { + return new SuperBuilderCustomizedWithSetterPrefix.Parent.ParentBuilderImpl(); + } + } + public static void test() { + Parent x = Parent.builder().setField1(5).build(); + } +} diff --git a/test/transform/resource/after-delombok/SuperBuilderInitializer.java b/test/transform/resource/after-delombok/SuperBuilderInitializer.java new file mode 100644 index 00000000..95943aa9 --- /dev/null +++ b/test/transform/resource/after-delombok/SuperBuilderInitializer.java @@ -0,0 +1,74 @@ +class SuperBuilderInitializer { + + public static class One { + private String world; + + { + world = "Hello"; + } + + private static final String world2; + + static { + world2 = "Hello"; + } + + + @java.lang.SuppressWarnings("all") + public static abstract class OneBuilder<C extends SuperBuilderInitializer.One, B extends SuperBuilderInitializer.One.OneBuilder<C, B>> { + @java.lang.SuppressWarnings("all") + private String world; + + @java.lang.SuppressWarnings("all") + protected abstract B self(); + + @java.lang.SuppressWarnings("all") + public abstract C build(); + + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public B world(final String world) { + this.world = world; + return self(); + } + + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "SuperBuilderInitializer.One.OneBuilder(world=" + this.world + ")"; + } + } + + + @java.lang.SuppressWarnings("all") + private static final class OneBuilderImpl extends SuperBuilderInitializer.One.OneBuilder<SuperBuilderInitializer.One, SuperBuilderInitializer.One.OneBuilderImpl> { + @java.lang.SuppressWarnings("all") + private OneBuilderImpl() { + } + + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected SuperBuilderInitializer.One.OneBuilderImpl self() { + return this; + } + + @java.lang.Override + @java.lang.SuppressWarnings("all") + public SuperBuilderInitializer.One build() { + return new SuperBuilderInitializer.One(this); + } + } + + @java.lang.SuppressWarnings("all") + protected One(final SuperBuilderInitializer.One.OneBuilder<?, ?> b) { + this.world = b.world; + } + + @java.lang.SuppressWarnings("all") + public static SuperBuilderInitializer.One.OneBuilder<?, ?> builder() { + return new SuperBuilderInitializer.One.OneBuilderImpl(); + } + } +} diff --git a/test/transform/resource/after-delombok/SuperBuilderNameClashes.java b/test/transform/resource/after-delombok/SuperBuilderNameClashes.java index bd176f49..8cef4e11 100644 --- a/test/transform/resource/after-delombok/SuperBuilderNameClashes.java +++ b/test/transform/resource/after-delombok/SuperBuilderNameClashes.java @@ -1,127 +1,127 @@ -public class SuperBuilderNameClashes {
- public static class GenericsClash<B, C, C2> {
- @java.lang.SuppressWarnings("all")
- public static abstract class GenericsClashBuilder<B, C, C2, C3 extends SuperBuilderNameClashes.GenericsClash<B, C, C2>, B2 extends SuperBuilderNameClashes.GenericsClash.GenericsClashBuilder<B, C, C2, C3, B2>> {
- @java.lang.SuppressWarnings("all")
- protected abstract B2 self();
- @java.lang.SuppressWarnings("all")
- public abstract C3 build();
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public java.lang.String toString() {
- return "SuperBuilderNameClashes.GenericsClash.GenericsClashBuilder()";
- }
- }
- @java.lang.SuppressWarnings("all")
- private static final class GenericsClashBuilderImpl<B, C, C2> extends SuperBuilderNameClashes.GenericsClash.GenericsClashBuilder<B, C, C2, SuperBuilderNameClashes.GenericsClash<B, C, C2>, SuperBuilderNameClashes.GenericsClash.GenericsClashBuilderImpl<B, C, C2>> {
- @java.lang.SuppressWarnings("all")
- private GenericsClashBuilderImpl() {
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected SuperBuilderNameClashes.GenericsClash.GenericsClashBuilderImpl<B, C, C2> self() {
- return this;
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public SuperBuilderNameClashes.GenericsClash<B, C, C2> build() {
- return new SuperBuilderNameClashes.GenericsClash<B, C, C2>(this);
- }
- }
- @java.lang.SuppressWarnings("all")
- protected GenericsClash(final SuperBuilderNameClashes.GenericsClash.GenericsClashBuilder<B, C, C2, ?, ?> b) {
- }
- @java.lang.SuppressWarnings("all")
- public static <B, C, C2> SuperBuilderNameClashes.GenericsClash.GenericsClashBuilder<B, C, C2, ?, ?> builder() {
- return new SuperBuilderNameClashes.GenericsClash.GenericsClashBuilderImpl<B, C, C2>();
- }
- }
- public static class B {
- @java.lang.SuppressWarnings("all")
- public static abstract class BBuilder<C extends SuperBuilderNameClashes.B, B2 extends SuperBuilderNameClashes.B.BBuilder<C, B2>> {
- @java.lang.SuppressWarnings("all")
- protected abstract B2 self();
- @java.lang.SuppressWarnings("all")
- public abstract C build();
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public java.lang.String toString() {
- return "SuperBuilderNameClashes.B.BBuilder()";
- }
- }
- @java.lang.SuppressWarnings("all")
- private static final class BBuilderImpl extends SuperBuilderNameClashes.B.BBuilder<SuperBuilderNameClashes.B, SuperBuilderNameClashes.B.BBuilderImpl> {
- @java.lang.SuppressWarnings("all")
- private BBuilderImpl() {
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected SuperBuilderNameClashes.B.BBuilderImpl self() {
- return this;
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public SuperBuilderNameClashes.B build() {
- return new SuperBuilderNameClashes.B(this);
- }
- }
- @java.lang.SuppressWarnings("all")
- protected B(final SuperBuilderNameClashes.B.BBuilder<?, ?> b) {
- }
- @java.lang.SuppressWarnings("all")
- public static SuperBuilderNameClashes.B.BBuilder<?, ?> builder() {
- return new SuperBuilderNameClashes.B.BBuilderImpl();
- }
- }
- public static class C2 {
- }
- public static class C {
- C2 c2;
- @java.lang.SuppressWarnings("all")
- public static abstract class CBuilder<C3 extends SuperBuilderNameClashes.C, B extends SuperBuilderNameClashes.C.CBuilder<C3, B>> {
- @java.lang.SuppressWarnings("all")
- private C2 c2;
- @java.lang.SuppressWarnings("all")
- protected abstract B self();
- @java.lang.SuppressWarnings("all")
- public abstract C3 build();
- /**
- * @return {@code this}.
- */
- @java.lang.SuppressWarnings("all")
- public B c2(final C2 c2) {
- this.c2 = c2;
- return self();
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public java.lang.String toString() {
- return "SuperBuilderNameClashes.C.CBuilder(c2=" + this.c2 + ")";
- }
- }
- @java.lang.SuppressWarnings("all")
- private static final class CBuilderImpl extends SuperBuilderNameClashes.C.CBuilder<SuperBuilderNameClashes.C, SuperBuilderNameClashes.C.CBuilderImpl> {
- @java.lang.SuppressWarnings("all")
- private CBuilderImpl() {
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected SuperBuilderNameClashes.C.CBuilderImpl self() {
- return this;
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public SuperBuilderNameClashes.C build() {
- return new SuperBuilderNameClashes.C(this);
- }
- }
- @java.lang.SuppressWarnings("all")
- protected C(final SuperBuilderNameClashes.C.CBuilder<?, ?> b) {
- this.c2 = b.c2;
- }
- @java.lang.SuppressWarnings("all")
- public static SuperBuilderNameClashes.C.CBuilder<?, ?> builder() {
- return new SuperBuilderNameClashes.C.CBuilderImpl();
- }
- }
-}
+public class SuperBuilderNameClashes { + public static class GenericsClash<B, C, C2> { + @java.lang.SuppressWarnings("all") + public static abstract class GenericsClashBuilder<B, C, C2, C3 extends SuperBuilderNameClashes.GenericsClash<B, C, C2>, B2 extends SuperBuilderNameClashes.GenericsClash.GenericsClashBuilder<B, C, C2, C3, B2>> { + @java.lang.SuppressWarnings("all") + protected abstract B2 self(); + @java.lang.SuppressWarnings("all") + public abstract C3 build(); + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "SuperBuilderNameClashes.GenericsClash.GenericsClashBuilder()"; + } + } + @java.lang.SuppressWarnings("all") + private static final class GenericsClashBuilderImpl<B, C, C2> extends SuperBuilderNameClashes.GenericsClash.GenericsClashBuilder<B, C, C2, SuperBuilderNameClashes.GenericsClash<B, C, C2>, SuperBuilderNameClashes.GenericsClash.GenericsClashBuilderImpl<B, C, C2>> { + @java.lang.SuppressWarnings("all") + private GenericsClashBuilderImpl() { + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected SuperBuilderNameClashes.GenericsClash.GenericsClashBuilderImpl<B, C, C2> self() { + return this; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public SuperBuilderNameClashes.GenericsClash<B, C, C2> build() { + return new SuperBuilderNameClashes.GenericsClash<B, C, C2>(this); + } + } + @java.lang.SuppressWarnings("all") + protected GenericsClash(final SuperBuilderNameClashes.GenericsClash.GenericsClashBuilder<B, C, C2, ?, ?> b) { + } + @java.lang.SuppressWarnings("all") + public static <B, C, C2> SuperBuilderNameClashes.GenericsClash.GenericsClashBuilder<B, C, C2, ?, ?> builder() { + return new SuperBuilderNameClashes.GenericsClash.GenericsClashBuilderImpl<B, C, C2>(); + } + } + public static class B { + @java.lang.SuppressWarnings("all") + public static abstract class BBuilder<C extends SuperBuilderNameClashes.B, B2 extends SuperBuilderNameClashes.B.BBuilder<C, B2>> { + @java.lang.SuppressWarnings("all") + protected abstract B2 self(); + @java.lang.SuppressWarnings("all") + public abstract C build(); + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "SuperBuilderNameClashes.B.BBuilder()"; + } + } + @java.lang.SuppressWarnings("all") + private static final class BBuilderImpl extends SuperBuilderNameClashes.B.BBuilder<SuperBuilderNameClashes.B, SuperBuilderNameClashes.B.BBuilderImpl> { + @java.lang.SuppressWarnings("all") + private BBuilderImpl() { + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected SuperBuilderNameClashes.B.BBuilderImpl self() { + return this; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public SuperBuilderNameClashes.B build() { + return new SuperBuilderNameClashes.B(this); + } + } + @java.lang.SuppressWarnings("all") + protected B(final SuperBuilderNameClashes.B.BBuilder<?, ?> b) { + } + @java.lang.SuppressWarnings("all") + public static SuperBuilderNameClashes.B.BBuilder<?, ?> builder() { + return new SuperBuilderNameClashes.B.BBuilderImpl(); + } + } + public static class C2 { + } + public static class C { + C2 c2; + @java.lang.SuppressWarnings("all") + public static abstract class CBuilder<C3 extends SuperBuilderNameClashes.C, B extends SuperBuilderNameClashes.C.CBuilder<C3, B>> { + @java.lang.SuppressWarnings("all") + private C2 c2; + @java.lang.SuppressWarnings("all") + protected abstract B self(); + @java.lang.SuppressWarnings("all") + public abstract C3 build(); + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public B c2(final C2 c2) { + this.c2 = c2; + return self(); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "SuperBuilderNameClashes.C.CBuilder(c2=" + this.c2 + ")"; + } + } + @java.lang.SuppressWarnings("all") + private static final class CBuilderImpl extends SuperBuilderNameClashes.C.CBuilder<SuperBuilderNameClashes.C, SuperBuilderNameClashes.C.CBuilderImpl> { + @java.lang.SuppressWarnings("all") + private CBuilderImpl() { + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected SuperBuilderNameClashes.C.CBuilderImpl self() { + return this; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public SuperBuilderNameClashes.C build() { + return new SuperBuilderNameClashes.C(this); + } + } + @java.lang.SuppressWarnings("all") + protected C(final SuperBuilderNameClashes.C.CBuilder<?, ?> b) { + this.c2 = b.c2; + } + @java.lang.SuppressWarnings("all") + public static SuperBuilderNameClashes.C.CBuilder<?, ?> builder() { + return new SuperBuilderNameClashes.C.CBuilderImpl(); + } + } +} diff --git a/test/transform/resource/after-delombok/SuperBuilderNestedGenericTypes.java b/test/transform/resource/after-delombok/SuperBuilderNestedGenericTypes.java index ad738c01..fadc0580 100644 --- a/test/transform/resource/after-delombok/SuperBuilderNestedGenericTypes.java +++ b/test/transform/resource/after-delombok/SuperBuilderNestedGenericTypes.java @@ -1,41 +1,41 @@ -public class SuperBuilderNestedGenericTypes {
- public static abstract class Generic<T extends Generic<?>> {
- @java.lang.SuppressWarnings("all")
- public static abstract class GenericBuilder<T extends Generic<?>, C extends SuperBuilderNestedGenericTypes.Generic<T>, B extends SuperBuilderNestedGenericTypes.Generic.GenericBuilder<T, C, B>> {
- @java.lang.SuppressWarnings("all")
- protected abstract B self();
- @java.lang.SuppressWarnings("all")
- public abstract C build();
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public java.lang.String toString() {
- return "SuperBuilderNestedGenericTypes.Generic.GenericBuilder()";
- }
- }
- @java.lang.SuppressWarnings("all")
- protected Generic(final SuperBuilderNestedGenericTypes.Generic.GenericBuilder<T, ?, ?> b) {
- }
- }
- public static abstract class NestedGeneric<T extends OtherGeneric<?>> extends Generic<NestedGeneric<? extends OtherGeneric<?>>> {
- @java.lang.SuppressWarnings("all")
- public static abstract class NestedGenericBuilder<T extends OtherGeneric<?>, C extends SuperBuilderNestedGenericTypes.NestedGeneric<T>, B extends SuperBuilderNestedGenericTypes.NestedGeneric.NestedGenericBuilder<T, C, B>> extends Generic.GenericBuilder<NestedGeneric<? extends OtherGeneric<?>>, C, B> {
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected abstract B self();
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public abstract C build();
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public java.lang.String toString() {
- return "SuperBuilderNestedGenericTypes.NestedGeneric.NestedGenericBuilder(super=" + super.toString() + ")";
- }
- }
- @java.lang.SuppressWarnings("all")
- protected NestedGeneric(final SuperBuilderNestedGenericTypes.NestedGeneric.NestedGenericBuilder<T, ?, ?> b) {
- super(b);
- }
- }
- public interface OtherGeneric<T> {
- }
-}
+public class SuperBuilderNestedGenericTypes { + public static abstract class Generic<T extends Generic<?>> { + @java.lang.SuppressWarnings("all") + public static abstract class GenericBuilder<T extends Generic<?>, C extends SuperBuilderNestedGenericTypes.Generic<T>, B extends SuperBuilderNestedGenericTypes.Generic.GenericBuilder<T, C, B>> { + @java.lang.SuppressWarnings("all") + protected abstract B self(); + @java.lang.SuppressWarnings("all") + public abstract C build(); + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "SuperBuilderNestedGenericTypes.Generic.GenericBuilder()"; + } + } + @java.lang.SuppressWarnings("all") + protected Generic(final SuperBuilderNestedGenericTypes.Generic.GenericBuilder<T, ?, ?> b) { + } + } + public static abstract class NestedGeneric<T extends OtherGeneric<?>> extends Generic<NestedGeneric<? extends OtherGeneric<?>>> { + @java.lang.SuppressWarnings("all") + public static abstract class NestedGenericBuilder<T extends OtherGeneric<?>, C extends SuperBuilderNestedGenericTypes.NestedGeneric<T>, B extends SuperBuilderNestedGenericTypes.NestedGeneric.NestedGenericBuilder<T, C, B>> extends Generic.GenericBuilder<NestedGeneric<? extends OtherGeneric<?>>, C, B> { + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected abstract B self(); + @java.lang.Override + @java.lang.SuppressWarnings("all") + public abstract C build(); + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "SuperBuilderNestedGenericTypes.NestedGeneric.NestedGenericBuilder(super=" + super.toString() + ")"; + } + } + @java.lang.SuppressWarnings("all") + protected NestedGeneric(final SuperBuilderNestedGenericTypes.NestedGeneric.NestedGenericBuilder<T, ?, ?> b) { + super(b); + } + } + public interface OtherGeneric<T> { + } +} diff --git a/test/transform/resource/after-delombok/SuperBuilderSingularAnnotatedTypes.java b/test/transform/resource/after-delombok/SuperBuilderSingularAnnotatedTypes.java index f6e0f024..ad51816a 100644 --- a/test/transform/resource/after-delombok/SuperBuilderSingularAnnotatedTypes.java +++ b/test/transform/resource/after-delombok/SuperBuilderSingularAnnotatedTypes.java @@ -1,3 +1,4 @@ +//version 8: import java.lang.annotation.ElementType; import java.lang.annotation.Target; import java.util.Set; diff --git a/test/transform/resource/after-delombok/SuperBuilderSingularCustomized.java b/test/transform/resource/after-delombok/SuperBuilderSingularCustomized.java new file mode 100644 index 00000000..04cfd9f2 --- /dev/null +++ b/test/transform/resource/after-delombok/SuperBuilderSingularCustomized.java @@ -0,0 +1,77 @@ +import java.util.Set; +class SuperBuilderSingularCustomized { + private Set<String> foos; + public static abstract class SuperBuilderSingularCustomizedBuilder<C extends SuperBuilderSingularCustomized, B extends SuperBuilderSingularCustomized.SuperBuilderSingularCustomizedBuilder<C, B>> { + @java.lang.SuppressWarnings("all") + private java.util.ArrayList<String> foos; + public B custom(final String value) { + return self(); + } + @java.lang.SuppressWarnings("all") + protected abstract B self(); + @java.lang.SuppressWarnings("all") + public abstract C build(); + @java.lang.SuppressWarnings("all") + public B foo(final String foo) { + if (this.foos == null) this.foos = new java.util.ArrayList<String>(); + this.foos.add(foo); + return self(); + } + @java.lang.SuppressWarnings("all") + public B foos(final java.util.Collection<? extends String> foos) { + if (foos == null) { + throw new java.lang.NullPointerException("foos cannot be null"); + } + if (this.foos == null) this.foos = new java.util.ArrayList<String>(); + this.foos.addAll(foos); + return self(); + } + @java.lang.SuppressWarnings("all") + public B clearFoos() { + if (this.foos != null) this.foos.clear(); + return self(); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "SuperBuilderSingularCustomized.SuperBuilderSingularCustomizedBuilder(foos=" + this.foos + ")"; + } + } + @java.lang.SuppressWarnings("all") + private static final class SuperBuilderSingularCustomizedBuilderImpl extends SuperBuilderSingularCustomized.SuperBuilderSingularCustomizedBuilder<SuperBuilderSingularCustomized, SuperBuilderSingularCustomized.SuperBuilderSingularCustomizedBuilderImpl> { + @java.lang.SuppressWarnings("all") + private SuperBuilderSingularCustomizedBuilderImpl() { + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected SuperBuilderSingularCustomized.SuperBuilderSingularCustomizedBuilderImpl self() { + return this; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public SuperBuilderSingularCustomized build() { + return new SuperBuilderSingularCustomized(this); + } + } + @java.lang.SuppressWarnings("all") + protected SuperBuilderSingularCustomized(final SuperBuilderSingularCustomized.SuperBuilderSingularCustomizedBuilder<?, ?> b) { + java.util.Set<String> foos; + switch (b.foos == null ? 0 : b.foos.size()) { + case 0: + foos = java.util.Collections.emptySet(); + break; + case 1: + foos = java.util.Collections.singleton(b.foos.get(0)); + break; + default: + foos = new java.util.LinkedHashSet<String>(b.foos.size() < 1073741824 ? 1 + b.foos.size() + (b.foos.size() - 3) / 3 : java.lang.Integer.MAX_VALUE); + foos.addAll(b.foos); + foos = java.util.Collections.unmodifiableSet(foos); + } + this.foos = foos; + } + @java.lang.SuppressWarnings("all") + public static SuperBuilderSingularCustomized.SuperBuilderSingularCustomizedBuilder<?, ?> builder() { + return new SuperBuilderSingularCustomized.SuperBuilderSingularCustomizedBuilderImpl(); + } +}
\ No newline at end of file diff --git a/test/transform/resource/after-delombok/SuperBuilderWithCustomBuilderMethod.java b/test/transform/resource/after-delombok/SuperBuilderWithCustomBuilderMethod.java index 7e9337c9..9237a148 100644 --- a/test/transform/resource/after-delombok/SuperBuilderWithCustomBuilderMethod.java +++ b/test/transform/resource/after-delombok/SuperBuilderWithCustomBuilderMethod.java @@ -1,141 +1,142 @@ -import java.util.List;
-public class SuperBuilderWithCustomBuilderMethod {
- public static class Parent<A> {
- A field1;
- List<String> items;
- @java.lang.SuppressWarnings("all")
- public static abstract class ParentBuilder<A, C extends SuperBuilderWithCustomBuilderMethod.Parent<A>, B extends SuperBuilderWithCustomBuilderMethod.Parent.ParentBuilder<A, C, B>> {
- @java.lang.SuppressWarnings("all")
- private A field1;
- @java.lang.SuppressWarnings("all")
- private java.util.ArrayList<String> items;
- @java.lang.SuppressWarnings("all")
- protected abstract B self();
- @java.lang.SuppressWarnings("all")
- public abstract C build();
- /**
- * @return {@code this}.
- */
- @java.lang.SuppressWarnings("all")
- public B field1(final A field1) {
- this.field1 = field1;
- return self();
- }
- @java.lang.SuppressWarnings("all")
- public B item(final String item) {
- if (this.items == null) this.items = new java.util.ArrayList<String>();
- this.items.add(item);
- return self();
- }
- @java.lang.SuppressWarnings("all")
- public B items(final java.util.Collection<? extends String> items) {
- if (items == null) {
- throw new java.lang.NullPointerException("items cannot be null");
- }
- if (this.items == null) this.items = new java.util.ArrayList<String>();
- this.items.addAll(items);
- return self();
- }
- @java.lang.SuppressWarnings("all")
- public B clearItems() {
- if (this.items != null) this.items.clear();
- return self();
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public java.lang.String toString() {
- return "SuperBuilderWithCustomBuilderMethod.Parent.ParentBuilder(field1=" + this.field1 + ", items=" + this.items + ")";
- }
- }
- @java.lang.SuppressWarnings("all")
- private static final class ParentBuilderImpl<A> extends SuperBuilderWithCustomBuilderMethod.Parent.ParentBuilder<A, SuperBuilderWithCustomBuilderMethod.Parent<A>, SuperBuilderWithCustomBuilderMethod.Parent.ParentBuilderImpl<A>> {
- @java.lang.SuppressWarnings("all")
- private ParentBuilderImpl() {
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected SuperBuilderWithCustomBuilderMethod.Parent.ParentBuilderImpl<A> self() {
- return this;
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public SuperBuilderWithCustomBuilderMethod.Parent<A> build() {
- return new SuperBuilderWithCustomBuilderMethod.Parent<A>(this);
- }
- }
- @java.lang.SuppressWarnings("all")
- protected Parent(final SuperBuilderWithCustomBuilderMethod.Parent.ParentBuilder<A, ?, ?> b) {
- this.field1 = b.field1;
- java.util.List<String> items;
- switch (b.items == null ? 0 : b.items.size()) {
- case 0:
- items = java.util.Collections.emptyList();
- break;
- case 1:
- items = java.util.Collections.singletonList(b.items.get(0));
- break;
- default:
- items = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(b.items));
- }
- this.items = items;
- }
- @java.lang.SuppressWarnings("all")
- public static <A> SuperBuilderWithCustomBuilderMethod.Parent.ParentBuilder<A, ?, ?> builder() {
- return new SuperBuilderWithCustomBuilderMethod.Parent.ParentBuilderImpl<A>();
- }
- }
- public static class Child<A> extends Parent<A> {
- double field3;
- public static <A> ChildBuilder<A, ?, ?> builder() {
- return new ChildBuilderImpl<A>().item("default item");
- }
- @java.lang.SuppressWarnings("all")
- public static abstract class ChildBuilder<A, C extends SuperBuilderWithCustomBuilderMethod.Child<A>, B extends SuperBuilderWithCustomBuilderMethod.Child.ChildBuilder<A, C, B>> extends Parent.ParentBuilder<A, C, B> {
- @java.lang.SuppressWarnings("all")
- private double field3;
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected abstract B self();
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public abstract C build();
- /**
- * @return {@code this}.
- */
- @java.lang.SuppressWarnings("all")
- public B field3(final double field3) {
- this.field3 = field3;
- return self();
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public java.lang.String toString() {
- return "SuperBuilderWithCustomBuilderMethod.Child.ChildBuilder(super=" + super.toString() + ", field3=" + this.field3 + ")";
- }
- }
- @java.lang.SuppressWarnings("all")
- private static final class ChildBuilderImpl<A> extends SuperBuilderWithCustomBuilderMethod.Child.ChildBuilder<A, SuperBuilderWithCustomBuilderMethod.Child<A>, SuperBuilderWithCustomBuilderMethod.Child.ChildBuilderImpl<A>> {
- @java.lang.SuppressWarnings("all")
- private ChildBuilderImpl() {
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected SuperBuilderWithCustomBuilderMethod.Child.ChildBuilderImpl<A> self() {
- return this;
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public SuperBuilderWithCustomBuilderMethod.Child<A> build() {
- return new SuperBuilderWithCustomBuilderMethod.Child<A>(this);
- }
- }
- @java.lang.SuppressWarnings("all")
- protected Child(final SuperBuilderWithCustomBuilderMethod.Child.ChildBuilder<A, ?, ?> b) {
- super(b);
- this.field3 = b.field3;
- }
- }
- public static void test() {
- Child<Integer> x = Child.<Integer>builder().field3(0.0).field1(5).item("").build();
- }
-}
+//version 8: Javac 6 will error out due to `ChildBuilder` not existing before properly running lombok. Giving j6 support status, not worth fixing. +import java.util.List; +public class SuperBuilderWithCustomBuilderMethod { + public static class Parent<A> { + A field1; + List<String> items; + @java.lang.SuppressWarnings("all") + public static abstract class ParentBuilder<A, C extends SuperBuilderWithCustomBuilderMethod.Parent<A>, B extends SuperBuilderWithCustomBuilderMethod.Parent.ParentBuilder<A, C, B>> { + @java.lang.SuppressWarnings("all") + private A field1; + @java.lang.SuppressWarnings("all") + private java.util.ArrayList<String> items; + @java.lang.SuppressWarnings("all") + protected abstract B self(); + @java.lang.SuppressWarnings("all") + public abstract C build(); + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public B field1(final A field1) { + this.field1 = field1; + return self(); + } + @java.lang.SuppressWarnings("all") + public B item(final String item) { + if (this.items == null) this.items = new java.util.ArrayList<String>(); + this.items.add(item); + return self(); + } + @java.lang.SuppressWarnings("all") + public B items(final java.util.Collection<? extends String> items) { + if (items == null) { + throw new java.lang.NullPointerException("items cannot be null"); + } + if (this.items == null) this.items = new java.util.ArrayList<String>(); + this.items.addAll(items); + return self(); + } + @java.lang.SuppressWarnings("all") + public B clearItems() { + if (this.items != null) this.items.clear(); + return self(); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "SuperBuilderWithCustomBuilderMethod.Parent.ParentBuilder(field1=" + this.field1 + ", items=" + this.items + ")"; + } + } + @java.lang.SuppressWarnings("all") + private static final class ParentBuilderImpl<A> extends SuperBuilderWithCustomBuilderMethod.Parent.ParentBuilder<A, SuperBuilderWithCustomBuilderMethod.Parent<A>, SuperBuilderWithCustomBuilderMethod.Parent.ParentBuilderImpl<A>> { + @java.lang.SuppressWarnings("all") + private ParentBuilderImpl() { + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected SuperBuilderWithCustomBuilderMethod.Parent.ParentBuilderImpl<A> self() { + return this; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public SuperBuilderWithCustomBuilderMethod.Parent<A> build() { + return new SuperBuilderWithCustomBuilderMethod.Parent<A>(this); + } + } + @java.lang.SuppressWarnings("all") + protected Parent(final SuperBuilderWithCustomBuilderMethod.Parent.ParentBuilder<A, ?, ?> b) { + this.field1 = b.field1; + java.util.List<String> items; + switch (b.items == null ? 0 : b.items.size()) { + case 0: + items = java.util.Collections.emptyList(); + break; + case 1: + items = java.util.Collections.singletonList(b.items.get(0)); + break; + default: + items = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(b.items)); + } + this.items = items; + } + @java.lang.SuppressWarnings("all") + public static <A> SuperBuilderWithCustomBuilderMethod.Parent.ParentBuilder<A, ?, ?> builder() { + return new SuperBuilderWithCustomBuilderMethod.Parent.ParentBuilderImpl<A>(); + } + } + public static class Child<A> extends Parent<A> { + double field3; + public static <A> ChildBuilder<A, ?, ?> builder() { + return new ChildBuilderImpl<A>().item("default item"); + } + @java.lang.SuppressWarnings("all") + public static abstract class ChildBuilder<A, C extends SuperBuilderWithCustomBuilderMethod.Child<A>, B extends SuperBuilderWithCustomBuilderMethod.Child.ChildBuilder<A, C, B>> extends Parent.ParentBuilder<A, C, B> { + @java.lang.SuppressWarnings("all") + private double field3; + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected abstract B self(); + @java.lang.Override + @java.lang.SuppressWarnings("all") + public abstract C build(); + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public B field3(final double field3) { + this.field3 = field3; + return self(); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "SuperBuilderWithCustomBuilderMethod.Child.ChildBuilder(super=" + super.toString() + ", field3=" + this.field3 + ")"; + } + } + @java.lang.SuppressWarnings("all") + private static final class ChildBuilderImpl<A> extends SuperBuilderWithCustomBuilderMethod.Child.ChildBuilder<A, SuperBuilderWithCustomBuilderMethod.Child<A>, SuperBuilderWithCustomBuilderMethod.Child.ChildBuilderImpl<A>> { + @java.lang.SuppressWarnings("all") + private ChildBuilderImpl() { + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected SuperBuilderWithCustomBuilderMethod.Child.ChildBuilderImpl<A> self() { + return this; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public SuperBuilderWithCustomBuilderMethod.Child<A> build() { + return new SuperBuilderWithCustomBuilderMethod.Child<A>(this); + } + } + @java.lang.SuppressWarnings("all") + protected Child(final SuperBuilderWithCustomBuilderMethod.Child.ChildBuilder<A, ?, ?> b) { + super(b); + this.field3 = b.field3; + } + } + public static void test() { + Child<Integer> x = Child.<Integer>builder().field3(0.0).field1(5).item("").build(); + } +} diff --git a/test/transform/resource/after-delombok/SuperBuilderWithDefaults.java b/test/transform/resource/after-delombok/SuperBuilderWithDefaults.java index 40f0900b..a9d92ff9 100644 --- a/test/transform/resource/after-delombok/SuperBuilderWithDefaults.java +++ b/test/transform/resource/after-delombok/SuperBuilderWithDefaults.java @@ -1,143 +1,143 @@ -import java.util.List;
-public class SuperBuilderWithDefaults {
- public static class Parent<N extends Number> {
- private long millis;
- private N numberField;
- @java.lang.SuppressWarnings("all")
- private static <N extends Number> long $default$millis() {
- return System.currentTimeMillis();
- }
- @java.lang.SuppressWarnings("all")
- private static <N extends Number> N $default$numberField() {
- return null;
- }
- @java.lang.SuppressWarnings("all")
- public static abstract class ParentBuilder<N extends Number, C extends SuperBuilderWithDefaults.Parent<N>, B extends SuperBuilderWithDefaults.Parent.ParentBuilder<N, C, B>> {
- @java.lang.SuppressWarnings("all")
- private boolean millis$set;
- @java.lang.SuppressWarnings("all")
- private long millis$value;
- @java.lang.SuppressWarnings("all")
- private boolean numberField$set;
- @java.lang.SuppressWarnings("all")
- private N numberField$value;
- @java.lang.SuppressWarnings("all")
- protected abstract B self();
- @java.lang.SuppressWarnings("all")
- public abstract C build();
- /**
- * @return {@code this}.
- */
- @java.lang.SuppressWarnings("all")
- public B millis(final long millis) {
- this.millis$value = millis;
- millis$set = true;
- return self();
- }
- /**
- * @return {@code this}.
- */
- @java.lang.SuppressWarnings("all")
- public B numberField(final N numberField) {
- this.numberField$value = numberField;
- numberField$set = true;
- return self();
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public java.lang.String toString() {
- return "SuperBuilderWithDefaults.Parent.ParentBuilder(millis$value=" + this.millis$value + ", numberField$value=" + this.numberField$value + ")";
- }
- }
- @java.lang.SuppressWarnings("all")
- private static final class ParentBuilderImpl<N extends Number> extends SuperBuilderWithDefaults.Parent.ParentBuilder<N, SuperBuilderWithDefaults.Parent<N>, SuperBuilderWithDefaults.Parent.ParentBuilderImpl<N>> {
- @java.lang.SuppressWarnings("all")
- private ParentBuilderImpl() {
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected SuperBuilderWithDefaults.Parent.ParentBuilderImpl<N> self() {
- return this;
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public SuperBuilderWithDefaults.Parent<N> build() {
- return new SuperBuilderWithDefaults.Parent<N>(this);
- }
- }
- @java.lang.SuppressWarnings("all")
- protected Parent(final SuperBuilderWithDefaults.Parent.ParentBuilder<N, ?, ?> b) {
- if (b.millis$set) this.millis = b.millis$value;
- else this.millis = SuperBuilderWithDefaults.Parent.<N>$default$millis();
- if (b.numberField$set) this.numberField = b.numberField$value;
- else this.numberField = SuperBuilderWithDefaults.Parent.<N>$default$numberField();
- }
- @java.lang.SuppressWarnings("all")
- public static <N extends Number> SuperBuilderWithDefaults.Parent.ParentBuilder<N, ?, ?> builder() {
- return new SuperBuilderWithDefaults.Parent.ParentBuilderImpl<N>();
- }
- }
- public static class Child extends Parent<Integer> {
- private double doubleField;
- @java.lang.SuppressWarnings("all")
- private static double $default$doubleField() {
- return Math.PI;
- }
- @java.lang.SuppressWarnings("all")
- public static abstract class ChildBuilder<C extends SuperBuilderWithDefaults.Child, B extends SuperBuilderWithDefaults.Child.ChildBuilder<C, B>> extends Parent.ParentBuilder<Integer, C, B> {
- @java.lang.SuppressWarnings("all")
- private boolean doubleField$set;
- @java.lang.SuppressWarnings("all")
- private double doubleField$value;
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected abstract B self();
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public abstract C build();
- /**
- * @return {@code this}.
- */
- @java.lang.SuppressWarnings("all")
- public B doubleField(final double doubleField) {
- this.doubleField$value = doubleField;
- doubleField$set = true;
- return self();
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public java.lang.String toString() {
- return "SuperBuilderWithDefaults.Child.ChildBuilder(super=" + super.toString() + ", doubleField$value=" + this.doubleField$value + ")";
- }
- }
- @java.lang.SuppressWarnings("all")
- private static final class ChildBuilderImpl extends SuperBuilderWithDefaults.Child.ChildBuilder<SuperBuilderWithDefaults.Child, SuperBuilderWithDefaults.Child.ChildBuilderImpl> {
- @java.lang.SuppressWarnings("all")
- private ChildBuilderImpl() {
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected SuperBuilderWithDefaults.Child.ChildBuilderImpl self() {
- return this;
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public SuperBuilderWithDefaults.Child build() {
- return new SuperBuilderWithDefaults.Child(this);
- }
- }
- @java.lang.SuppressWarnings("all")
- protected Child(final SuperBuilderWithDefaults.Child.ChildBuilder<?, ?> b) {
- super(b);
- if (b.doubleField$set) this.doubleField = b.doubleField$value;
- else this.doubleField = SuperBuilderWithDefaults.Child.$default$doubleField();
- }
- @java.lang.SuppressWarnings("all")
- public static SuperBuilderWithDefaults.Child.ChildBuilder<?, ?> builder() {
- return new SuperBuilderWithDefaults.Child.ChildBuilderImpl();
- }
- }
- public static void test() {
- Child x = Child.builder().doubleField(0.1).numberField(5).millis(1234567890L).build();
- }
-}
+import java.util.List; +public class SuperBuilderWithDefaults { + public static class Parent<N extends Number> { + private long millis; + private N numberField; + @java.lang.SuppressWarnings("all") + private static <N extends Number> long $default$millis() { + return System.currentTimeMillis(); + } + @java.lang.SuppressWarnings("all") + private static <N extends Number> N $default$numberField() { + return null; + } + @java.lang.SuppressWarnings("all") + public static abstract class ParentBuilder<N extends Number, C extends SuperBuilderWithDefaults.Parent<N>, B extends SuperBuilderWithDefaults.Parent.ParentBuilder<N, C, B>> { + @java.lang.SuppressWarnings("all") + private boolean millis$set; + @java.lang.SuppressWarnings("all") + private long millis$value; + @java.lang.SuppressWarnings("all") + private boolean numberField$set; + @java.lang.SuppressWarnings("all") + private N numberField$value; + @java.lang.SuppressWarnings("all") + protected abstract B self(); + @java.lang.SuppressWarnings("all") + public abstract C build(); + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public B millis(final long millis) { + this.millis$value = millis; + millis$set = true; + return self(); + } + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public B numberField(final N numberField) { + this.numberField$value = numberField; + numberField$set = true; + return self(); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "SuperBuilderWithDefaults.Parent.ParentBuilder(millis$value=" + this.millis$value + ", numberField$value=" + this.numberField$value + ")"; + } + } + @java.lang.SuppressWarnings("all") + private static final class ParentBuilderImpl<N extends Number> extends SuperBuilderWithDefaults.Parent.ParentBuilder<N, SuperBuilderWithDefaults.Parent<N>, SuperBuilderWithDefaults.Parent.ParentBuilderImpl<N>> { + @java.lang.SuppressWarnings("all") + private ParentBuilderImpl() { + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected SuperBuilderWithDefaults.Parent.ParentBuilderImpl<N> self() { + return this; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public SuperBuilderWithDefaults.Parent<N> build() { + return new SuperBuilderWithDefaults.Parent<N>(this); + } + } + @java.lang.SuppressWarnings("all") + protected Parent(final SuperBuilderWithDefaults.Parent.ParentBuilder<N, ?, ?> b) { + if (b.millis$set) this.millis = b.millis$value; + else this.millis = SuperBuilderWithDefaults.Parent.<N>$default$millis(); + if (b.numberField$set) this.numberField = b.numberField$value; + else this.numberField = SuperBuilderWithDefaults.Parent.<N>$default$numberField(); + } + @java.lang.SuppressWarnings("all") + public static <N extends Number> SuperBuilderWithDefaults.Parent.ParentBuilder<N, ?, ?> builder() { + return new SuperBuilderWithDefaults.Parent.ParentBuilderImpl<N>(); + } + } + public static class Child extends Parent<Integer> { + private double doubleField; + @java.lang.SuppressWarnings("all") + private static double $default$doubleField() { + return Math.PI; + } + @java.lang.SuppressWarnings("all") + public static abstract class ChildBuilder<C extends SuperBuilderWithDefaults.Child, B extends SuperBuilderWithDefaults.Child.ChildBuilder<C, B>> extends Parent.ParentBuilder<Integer, C, B> { + @java.lang.SuppressWarnings("all") + private boolean doubleField$set; + @java.lang.SuppressWarnings("all") + private double doubleField$value; + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected abstract B self(); + @java.lang.Override + @java.lang.SuppressWarnings("all") + public abstract C build(); + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public B doubleField(final double doubleField) { + this.doubleField$value = doubleField; + doubleField$set = true; + return self(); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "SuperBuilderWithDefaults.Child.ChildBuilder(super=" + super.toString() + ", doubleField$value=" + this.doubleField$value + ")"; + } + } + @java.lang.SuppressWarnings("all") + private static final class ChildBuilderImpl extends SuperBuilderWithDefaults.Child.ChildBuilder<SuperBuilderWithDefaults.Child, SuperBuilderWithDefaults.Child.ChildBuilderImpl> { + @java.lang.SuppressWarnings("all") + private ChildBuilderImpl() { + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected SuperBuilderWithDefaults.Child.ChildBuilderImpl self() { + return this; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public SuperBuilderWithDefaults.Child build() { + return new SuperBuilderWithDefaults.Child(this); + } + } + @java.lang.SuppressWarnings("all") + protected Child(final SuperBuilderWithDefaults.Child.ChildBuilder<?, ?> b) { + super(b); + if (b.doubleField$set) this.doubleField = b.doubleField$value; + else this.doubleField = SuperBuilderWithDefaults.Child.$default$doubleField(); + } + @java.lang.SuppressWarnings("all") + public static SuperBuilderWithDefaults.Child.ChildBuilder<?, ?> builder() { + return new SuperBuilderWithDefaults.Child.ChildBuilderImpl(); + } + } + public static void test() { + Child x = Child.builder().doubleField(0.1).numberField(5).millis(1234567890L).build(); + } +} diff --git a/test/transform/resource/after-delombok/SuperBuilderWithExistingConstructor.java b/test/transform/resource/after-delombok/SuperBuilderWithExistingConstructor.java new file mode 100644 index 00000000..c6ab1072 --- /dev/null +++ b/test/transform/resource/after-delombok/SuperBuilderWithExistingConstructor.java @@ -0,0 +1,39 @@ +public class SuperBuilderWithExistingConstructor { + public SuperBuilderWithExistingConstructor() { + } + @java.lang.SuppressWarnings("all") + public static abstract class SuperBuilderWithExistingConstructorBuilder<C extends SuperBuilderWithExistingConstructor, B extends SuperBuilderWithExistingConstructor.SuperBuilderWithExistingConstructorBuilder<C, B>> { + @java.lang.SuppressWarnings("all") + protected abstract B self(); + @java.lang.SuppressWarnings("all") + public abstract C build(); + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "SuperBuilderWithExistingConstructor.SuperBuilderWithExistingConstructorBuilder()"; + } + } + @java.lang.SuppressWarnings("all") + private static final class SuperBuilderWithExistingConstructorBuilderImpl extends SuperBuilderWithExistingConstructor.SuperBuilderWithExistingConstructorBuilder<SuperBuilderWithExistingConstructor, SuperBuilderWithExistingConstructor.SuperBuilderWithExistingConstructorBuilderImpl> { + @java.lang.SuppressWarnings("all") + private SuperBuilderWithExistingConstructorBuilderImpl() { + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected SuperBuilderWithExistingConstructor.SuperBuilderWithExistingConstructorBuilderImpl self() { + return this; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public SuperBuilderWithExistingConstructor build() { + return new SuperBuilderWithExistingConstructor(this); + } + } + @java.lang.SuppressWarnings("all") + protected SuperBuilderWithExistingConstructor(final SuperBuilderWithExistingConstructor.SuperBuilderWithExistingConstructorBuilder<?, ?> b) { + } + @java.lang.SuppressWarnings("all") + public static SuperBuilderWithExistingConstructor.SuperBuilderWithExistingConstructorBuilder<?, ?> builder() { + return new SuperBuilderWithExistingConstructor.SuperBuilderWithExistingConstructorBuilderImpl(); + } +}
\ No newline at end of file diff --git a/test/transform/resource/after-delombok/SuperBuilderWithGenerics.java b/test/transform/resource/after-delombok/SuperBuilderWithGenerics.java index 0c3d2379..017ebf31 100644 --- a/test/transform/resource/after-delombok/SuperBuilderWithGenerics.java +++ b/test/transform/resource/after-delombok/SuperBuilderWithGenerics.java @@ -1,142 +1,142 @@ -import java.util.List;
-public class SuperBuilderWithGenerics {
- public static class Parent<A> {
- A field1;
- List<String> items;
- @java.lang.SuppressWarnings("all")
- public static abstract class ParentBuilder<A, C extends SuperBuilderWithGenerics.Parent<A>, B extends SuperBuilderWithGenerics.Parent.ParentBuilder<A, C, B>> {
- @java.lang.SuppressWarnings("all")
- private A field1;
- @java.lang.SuppressWarnings("all")
- private java.util.ArrayList<String> items;
- @java.lang.SuppressWarnings("all")
- protected abstract B self();
- @java.lang.SuppressWarnings("all")
- public abstract C build();
- /**
- * @return {@code this}.
- */
- @java.lang.SuppressWarnings("all")
- public B field1(final A field1) {
- this.field1 = field1;
- return self();
- }
- @java.lang.SuppressWarnings("all")
- public B item(final String item) {
- if (this.items == null) this.items = new java.util.ArrayList<String>();
- this.items.add(item);
- return self();
- }
- @java.lang.SuppressWarnings("all")
- public B items(final java.util.Collection<? extends String> items) {
- if (items == null) {
- throw new java.lang.NullPointerException("items cannot be null");
- }
- if (this.items == null) this.items = new java.util.ArrayList<String>();
- this.items.addAll(items);
- return self();
- }
- @java.lang.SuppressWarnings("all")
- public B clearItems() {
- if (this.items != null) this.items.clear();
- return self();
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public java.lang.String toString() {
- return "SuperBuilderWithGenerics.Parent.ParentBuilder(field1=" + this.field1 + ", items=" + this.items + ")";
- }
- }
- @java.lang.SuppressWarnings("all")
- private static final class ParentBuilderImpl<A> extends SuperBuilderWithGenerics.Parent.ParentBuilder<A, SuperBuilderWithGenerics.Parent<A>, SuperBuilderWithGenerics.Parent.ParentBuilderImpl<A>> {
- @java.lang.SuppressWarnings("all")
- private ParentBuilderImpl() {
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected SuperBuilderWithGenerics.Parent.ParentBuilderImpl<A> self() {
- return this;
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public SuperBuilderWithGenerics.Parent<A> build() {
- return new SuperBuilderWithGenerics.Parent<A>(this);
- }
- }
- @java.lang.SuppressWarnings("all")
- protected Parent(final SuperBuilderWithGenerics.Parent.ParentBuilder<A, ?, ?> b) {
- this.field1 = b.field1;
- java.util.List<String> items;
- switch (b.items == null ? 0 : b.items.size()) {
- case 0:
- items = java.util.Collections.emptyList();
- break;
- case 1:
- items = java.util.Collections.singletonList(b.items.get(0));
- break;
- default:
- items = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(b.items));
- }
- this.items = items;
- }
- @java.lang.SuppressWarnings("all")
- public static <A> SuperBuilderWithGenerics.Parent.ParentBuilder<A, ?, ?> builder() {
- return new SuperBuilderWithGenerics.Parent.ParentBuilderImpl<A>();
- }
- }
- public static class Child<A> extends Parent<A> {
- double field3;
- @java.lang.SuppressWarnings("all")
- public static abstract class ChildBuilder<A, C extends SuperBuilderWithGenerics.Child<A>, B extends SuperBuilderWithGenerics.Child.ChildBuilder<A, C, B>> extends Parent.ParentBuilder<A, C, B> {
- @java.lang.SuppressWarnings("all")
- private double field3;
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected abstract B self();
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public abstract C build();
- /**
- * @return {@code this}.
- */
- @java.lang.SuppressWarnings("all")
- public B field3(final double field3) {
- this.field3 = field3;
- return self();
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public java.lang.String toString() {
- return "SuperBuilderWithGenerics.Child.ChildBuilder(super=" + super.toString() + ", field3=" + this.field3 + ")";
- }
- }
- @java.lang.SuppressWarnings("all")
- private static final class ChildBuilderImpl<A> extends SuperBuilderWithGenerics.Child.ChildBuilder<A, SuperBuilderWithGenerics.Child<A>, SuperBuilderWithGenerics.Child.ChildBuilderImpl<A>> {
- @java.lang.SuppressWarnings("all")
- private ChildBuilderImpl() {
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected SuperBuilderWithGenerics.Child.ChildBuilderImpl<A> self() {
- return this;
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public SuperBuilderWithGenerics.Child<A> build() {
- return new SuperBuilderWithGenerics.Child<A>(this);
- }
- }
- @java.lang.SuppressWarnings("all")
- protected Child(final SuperBuilderWithGenerics.Child.ChildBuilder<A, ?, ?> b) {
- super(b);
- this.field3 = b.field3;
- }
- @java.lang.SuppressWarnings("all")
- public static <A> SuperBuilderWithGenerics.Child.ChildBuilder<A, ?, ?> builder() {
- return new SuperBuilderWithGenerics.Child.ChildBuilderImpl<A>();
- }
- }
- public static void test() {
- Child<Integer> x = Child.<Integer>builder().field3(0.0).field1(5).item("").build();
- }
-}
+import java.util.List; +public class SuperBuilderWithGenerics { + public static class Parent<A> { + A field1; + List<String> items; + @java.lang.SuppressWarnings("all") + public static abstract class ParentBuilder<A, C extends SuperBuilderWithGenerics.Parent<A>, B extends SuperBuilderWithGenerics.Parent.ParentBuilder<A, C, B>> { + @java.lang.SuppressWarnings("all") + private A field1; + @java.lang.SuppressWarnings("all") + private java.util.ArrayList<String> items; + @java.lang.SuppressWarnings("all") + protected abstract B self(); + @java.lang.SuppressWarnings("all") + public abstract C build(); + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public B field1(final A field1) { + this.field1 = field1; + return self(); + } + @java.lang.SuppressWarnings("all") + public B item(final String item) { + if (this.items == null) this.items = new java.util.ArrayList<String>(); + this.items.add(item); + return self(); + } + @java.lang.SuppressWarnings("all") + public B items(final java.util.Collection<? extends String> items) { + if (items == null) { + throw new java.lang.NullPointerException("items cannot be null"); + } + if (this.items == null) this.items = new java.util.ArrayList<String>(); + this.items.addAll(items); + return self(); + } + @java.lang.SuppressWarnings("all") + public B clearItems() { + if (this.items != null) this.items.clear(); + return self(); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "SuperBuilderWithGenerics.Parent.ParentBuilder(field1=" + this.field1 + ", items=" + this.items + ")"; + } + } + @java.lang.SuppressWarnings("all") + private static final class ParentBuilderImpl<A> extends SuperBuilderWithGenerics.Parent.ParentBuilder<A, SuperBuilderWithGenerics.Parent<A>, SuperBuilderWithGenerics.Parent.ParentBuilderImpl<A>> { + @java.lang.SuppressWarnings("all") + private ParentBuilderImpl() { + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected SuperBuilderWithGenerics.Parent.ParentBuilderImpl<A> self() { + return this; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public SuperBuilderWithGenerics.Parent<A> build() { + return new SuperBuilderWithGenerics.Parent<A>(this); + } + } + @java.lang.SuppressWarnings("all") + protected Parent(final SuperBuilderWithGenerics.Parent.ParentBuilder<A, ?, ?> b) { + this.field1 = b.field1; + java.util.List<String> items; + switch (b.items == null ? 0 : b.items.size()) { + case 0: + items = java.util.Collections.emptyList(); + break; + case 1: + items = java.util.Collections.singletonList(b.items.get(0)); + break; + default: + items = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(b.items)); + } + this.items = items; + } + @java.lang.SuppressWarnings("all") + public static <A> SuperBuilderWithGenerics.Parent.ParentBuilder<A, ?, ?> builder() { + return new SuperBuilderWithGenerics.Parent.ParentBuilderImpl<A>(); + } + } + public static class Child<A> extends Parent<A> { + double field3; + @java.lang.SuppressWarnings("all") + public static abstract class ChildBuilder<A, C extends SuperBuilderWithGenerics.Child<A>, B extends SuperBuilderWithGenerics.Child.ChildBuilder<A, C, B>> extends Parent.ParentBuilder<A, C, B> { + @java.lang.SuppressWarnings("all") + private double field3; + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected abstract B self(); + @java.lang.Override + @java.lang.SuppressWarnings("all") + public abstract C build(); + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public B field3(final double field3) { + this.field3 = field3; + return self(); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "SuperBuilderWithGenerics.Child.ChildBuilder(super=" + super.toString() + ", field3=" + this.field3 + ")"; + } + } + @java.lang.SuppressWarnings("all") + private static final class ChildBuilderImpl<A> extends SuperBuilderWithGenerics.Child.ChildBuilder<A, SuperBuilderWithGenerics.Child<A>, SuperBuilderWithGenerics.Child.ChildBuilderImpl<A>> { + @java.lang.SuppressWarnings("all") + private ChildBuilderImpl() { + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected SuperBuilderWithGenerics.Child.ChildBuilderImpl<A> self() { + return this; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public SuperBuilderWithGenerics.Child<A> build() { + return new SuperBuilderWithGenerics.Child<A>(this); + } + } + @java.lang.SuppressWarnings("all") + protected Child(final SuperBuilderWithGenerics.Child.ChildBuilder<A, ?, ?> b) { + super(b); + this.field3 = b.field3; + } + @java.lang.SuppressWarnings("all") + public static <A> SuperBuilderWithGenerics.Child.ChildBuilder<A, ?, ?> builder() { + return new SuperBuilderWithGenerics.Child.ChildBuilderImpl<A>(); + } + } + public static void test() { + Child<Integer> x = Child.<Integer>builder().field3(0.0).field1(5).item("").build(); + } +} diff --git a/test/transform/resource/after-delombok/SuperBuilderWithGenerics2.java b/test/transform/resource/after-delombok/SuperBuilderWithGenerics2.java index 71e29d92..8c465b0e 100644 --- a/test/transform/resource/after-delombok/SuperBuilderWithGenerics2.java +++ b/test/transform/resource/after-delombok/SuperBuilderWithGenerics2.java @@ -1,142 +1,142 @@ -import java.util.List;
-public class SuperBuilderWithGenerics2 {
- public static class Parent<A> {
- A field1;
- List<String> items;
- @java.lang.SuppressWarnings("all")
- public static abstract class ParentBuilder<A, C extends SuperBuilderWithGenerics2.Parent<A>, B extends SuperBuilderWithGenerics2.Parent.ParentBuilder<A, C, B>> {
- @java.lang.SuppressWarnings("all")
- private A field1;
- @java.lang.SuppressWarnings("all")
- private java.util.ArrayList<String> items;
- @java.lang.SuppressWarnings("all")
- protected abstract B self();
- @java.lang.SuppressWarnings("all")
- public abstract C build();
- /**
- * @return {@code this}.
- */
- @java.lang.SuppressWarnings("all")
- public B field1(final A field1) {
- this.field1 = field1;
- return self();
- }
- @java.lang.SuppressWarnings("all")
- public B item(final String item) {
- if (this.items == null) this.items = new java.util.ArrayList<String>();
- this.items.add(item);
- return self();
- }
- @java.lang.SuppressWarnings("all")
- public B items(final java.util.Collection<? extends String> items) {
- if (items == null) {
- throw new java.lang.NullPointerException("items cannot be null");
- }
- if (this.items == null) this.items = new java.util.ArrayList<String>();
- this.items.addAll(items);
- return self();
- }
- @java.lang.SuppressWarnings("all")
- public B clearItems() {
- if (this.items != null) this.items.clear();
- return self();
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public java.lang.String toString() {
- return "SuperBuilderWithGenerics2.Parent.ParentBuilder(field1=" + this.field1 + ", items=" + this.items + ")";
- }
- }
- @java.lang.SuppressWarnings("all")
- private static final class ParentBuilderImpl<A> extends SuperBuilderWithGenerics2.Parent.ParentBuilder<A, SuperBuilderWithGenerics2.Parent<A>, SuperBuilderWithGenerics2.Parent.ParentBuilderImpl<A>> {
- @java.lang.SuppressWarnings("all")
- private ParentBuilderImpl() {
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected SuperBuilderWithGenerics2.Parent.ParentBuilderImpl<A> self() {
- return this;
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public SuperBuilderWithGenerics2.Parent<A> build() {
- return new SuperBuilderWithGenerics2.Parent<A>(this);
- }
- }
- @java.lang.SuppressWarnings("all")
- protected Parent(final SuperBuilderWithGenerics2.Parent.ParentBuilder<A, ?, ?> b) {
- this.field1 = b.field1;
- java.util.List<String> items;
- switch (b.items == null ? 0 : b.items.size()) {
- case 0:
- items = java.util.Collections.emptyList();
- break;
- case 1:
- items = java.util.Collections.singletonList(b.items.get(0));
- break;
- default:
- items = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(b.items));
- }
- this.items = items;
- }
- @java.lang.SuppressWarnings("all")
- public static <A> SuperBuilderWithGenerics2.Parent.ParentBuilder<A, ?, ?> builder() {
- return new SuperBuilderWithGenerics2.Parent.ParentBuilderImpl<A>();
- }
- }
- public static class Child<A> extends Parent<String> {
- A field3;
- @java.lang.SuppressWarnings("all")
- public static abstract class ChildBuilder<A, C extends SuperBuilderWithGenerics2.Child<A>, B extends SuperBuilderWithGenerics2.Child.ChildBuilder<A, C, B>> extends Parent.ParentBuilder<String, C, B> {
- @java.lang.SuppressWarnings("all")
- private A field3;
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected abstract B self();
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public abstract C build();
- /**
- * @return {@code this}.
- */
- @java.lang.SuppressWarnings("all")
- public B field3(final A field3) {
- this.field3 = field3;
- return self();
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public java.lang.String toString() {
- return "SuperBuilderWithGenerics2.Child.ChildBuilder(super=" + super.toString() + ", field3=" + this.field3 + ")";
- }
- }
- @java.lang.SuppressWarnings("all")
- private static final class ChildBuilderImpl<A> extends SuperBuilderWithGenerics2.Child.ChildBuilder<A, SuperBuilderWithGenerics2.Child<A>, SuperBuilderWithGenerics2.Child.ChildBuilderImpl<A>> {
- @java.lang.SuppressWarnings("all")
- private ChildBuilderImpl() {
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected SuperBuilderWithGenerics2.Child.ChildBuilderImpl<A> self() {
- return this;
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public SuperBuilderWithGenerics2.Child<A> build() {
- return new SuperBuilderWithGenerics2.Child<A>(this);
- }
- }
- @java.lang.SuppressWarnings("all")
- protected Child(final SuperBuilderWithGenerics2.Child.ChildBuilder<A, ?, ?> b) {
- super(b);
- this.field3 = b.field3;
- }
- @java.lang.SuppressWarnings("all")
- public static <A> SuperBuilderWithGenerics2.Child.ChildBuilder<A, ?, ?> builder2() {
- return new SuperBuilderWithGenerics2.Child.ChildBuilderImpl<A>();
- }
- }
- public static void test() {
- Child<Integer> x = Child.<Integer>builder2().field3(1).field1("value").item("").build();
- }
-}
+import java.util.List; +public class SuperBuilderWithGenerics2 { + public static class Parent<A> { + A field1; + List<String> items; + @java.lang.SuppressWarnings("all") + public static abstract class ParentBuilder<A, C extends SuperBuilderWithGenerics2.Parent<A>, B extends SuperBuilderWithGenerics2.Parent.ParentBuilder<A, C, B>> { + @java.lang.SuppressWarnings("all") + private A field1; + @java.lang.SuppressWarnings("all") + private java.util.ArrayList<String> items; + @java.lang.SuppressWarnings("all") + protected abstract B self(); + @java.lang.SuppressWarnings("all") + public abstract C build(); + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public B field1(final A field1) { + this.field1 = field1; + return self(); + } + @java.lang.SuppressWarnings("all") + public B item(final String item) { + if (this.items == null) this.items = new java.util.ArrayList<String>(); + this.items.add(item); + return self(); + } + @java.lang.SuppressWarnings("all") + public B items(final java.util.Collection<? extends String> items) { + if (items == null) { + throw new java.lang.NullPointerException("items cannot be null"); + } + if (this.items == null) this.items = new java.util.ArrayList<String>(); + this.items.addAll(items); + return self(); + } + @java.lang.SuppressWarnings("all") + public B clearItems() { + if (this.items != null) this.items.clear(); + return self(); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "SuperBuilderWithGenerics2.Parent.ParentBuilder(field1=" + this.field1 + ", items=" + this.items + ")"; + } + } + @java.lang.SuppressWarnings("all") + private static final class ParentBuilderImpl<A> extends SuperBuilderWithGenerics2.Parent.ParentBuilder<A, SuperBuilderWithGenerics2.Parent<A>, SuperBuilderWithGenerics2.Parent.ParentBuilderImpl<A>> { + @java.lang.SuppressWarnings("all") + private ParentBuilderImpl() { + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected SuperBuilderWithGenerics2.Parent.ParentBuilderImpl<A> self() { + return this; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public SuperBuilderWithGenerics2.Parent<A> build() { + return new SuperBuilderWithGenerics2.Parent<A>(this); + } + } + @java.lang.SuppressWarnings("all") + protected Parent(final SuperBuilderWithGenerics2.Parent.ParentBuilder<A, ?, ?> b) { + this.field1 = b.field1; + java.util.List<String> items; + switch (b.items == null ? 0 : b.items.size()) { + case 0: + items = java.util.Collections.emptyList(); + break; + case 1: + items = java.util.Collections.singletonList(b.items.get(0)); + break; + default: + items = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(b.items)); + } + this.items = items; + } + @java.lang.SuppressWarnings("all") + public static <A> SuperBuilderWithGenerics2.Parent.ParentBuilder<A, ?, ?> builder() { + return new SuperBuilderWithGenerics2.Parent.ParentBuilderImpl<A>(); + } + } + public static class Child<A> extends Parent<String> { + A field3; + @java.lang.SuppressWarnings("all") + public static abstract class ChildBuilder<A, C extends SuperBuilderWithGenerics2.Child<A>, B extends SuperBuilderWithGenerics2.Child.ChildBuilder<A, C, B>> extends Parent.ParentBuilder<String, C, B> { + @java.lang.SuppressWarnings("all") + private A field3; + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected abstract B self(); + @java.lang.Override + @java.lang.SuppressWarnings("all") + public abstract C build(); + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public B field3(final A field3) { + this.field3 = field3; + return self(); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "SuperBuilderWithGenerics2.Child.ChildBuilder(super=" + super.toString() + ", field3=" + this.field3 + ")"; + } + } + @java.lang.SuppressWarnings("all") + private static final class ChildBuilderImpl<A> extends SuperBuilderWithGenerics2.Child.ChildBuilder<A, SuperBuilderWithGenerics2.Child<A>, SuperBuilderWithGenerics2.Child.ChildBuilderImpl<A>> { + @java.lang.SuppressWarnings("all") + private ChildBuilderImpl() { + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected SuperBuilderWithGenerics2.Child.ChildBuilderImpl<A> self() { + return this; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public SuperBuilderWithGenerics2.Child<A> build() { + return new SuperBuilderWithGenerics2.Child<A>(this); + } + } + @java.lang.SuppressWarnings("all") + protected Child(final SuperBuilderWithGenerics2.Child.ChildBuilder<A, ?, ?> b) { + super(b); + this.field3 = b.field3; + } + @java.lang.SuppressWarnings("all") + public static <A> SuperBuilderWithGenerics2.Child.ChildBuilder<A, ?, ?> builder2() { + return new SuperBuilderWithGenerics2.Child.ChildBuilderImpl<A>(); + } + } + public static void test() { + Child<Integer> x = Child.<Integer>builder2().field3(1).field1("value").item("").build(); + } +} diff --git a/test/transform/resource/after-delombok/SuperBuilderWithGenericsAndToBuilder.java b/test/transform/resource/after-delombok/SuperBuilderWithGenericsAndToBuilder.java index ac65a444..28c48db3 100644 --- a/test/transform/resource/after-delombok/SuperBuilderWithGenericsAndToBuilder.java +++ b/test/transform/resource/after-delombok/SuperBuilderWithGenericsAndToBuilder.java @@ -1,188 +1,188 @@ -import java.util.Map;
-public class SuperBuilderWithGenericsAndToBuilder {
- public static class Parent<A> {
- A field1;
- Map<Integer, String> items;
- @java.lang.SuppressWarnings("all")
- public static abstract class ParentBuilder<A, C extends SuperBuilderWithGenericsAndToBuilder.Parent<A>, B extends SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilder<A, C, B>> {
- @java.lang.SuppressWarnings("all")
- private A field1;
- @java.lang.SuppressWarnings("all")
- private java.util.ArrayList<Integer> items$key;
- @java.lang.SuppressWarnings("all")
- private java.util.ArrayList<String> items$value;
- @java.lang.SuppressWarnings("all")
- protected B $fillValuesFrom(final C instance) {
- SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilder.$fillValuesFromInstanceIntoBuilder(instance, this);
- return self();
- }
- @java.lang.SuppressWarnings("all")
- private static <A> void $fillValuesFromInstanceIntoBuilder(final SuperBuilderWithGenericsAndToBuilder.Parent<A> instance, final SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilder<A, ?, ?> b) {
- b.field1(instance.field1);
- b.items(instance.items == null ? java.util.Collections.emptyMap() : instance.items);
- }
- @java.lang.SuppressWarnings("all")
- protected abstract B self();
- @java.lang.SuppressWarnings("all")
- public abstract C build();
- /**
- * @return {@code this}.
- */
- @java.lang.SuppressWarnings("all")
- public B field1(final A field1) {
- this.field1 = field1;
- return self();
- }
- @java.lang.SuppressWarnings("all")
- public B item(final Integer itemKey, final String itemValue) {
- if (this.items$key == null) {
- this.items$key = new java.util.ArrayList<Integer>();
- this.items$value = new java.util.ArrayList<String>();
- }
- this.items$key.add(itemKey);
- this.items$value.add(itemValue);
- return self();
- }
- @java.lang.SuppressWarnings("all")
- public B items(final java.util.Map<? extends Integer, ? extends String> items) {
- if (items == null) {
- throw new java.lang.NullPointerException("items cannot be null");
- }
- if (this.items$key == null) {
- this.items$key = new java.util.ArrayList<Integer>();
- this.items$value = new java.util.ArrayList<String>();
- }
- for (final java.util.Map.Entry<? extends Integer, ? extends String> $lombokEntry : items.entrySet()) {
- this.items$key.add($lombokEntry.getKey());
- this.items$value.add($lombokEntry.getValue());
- }
- return self();
- }
- @java.lang.SuppressWarnings("all")
- public B clearItems() {
- if (this.items$key != null) {
- this.items$key.clear();
- this.items$value.clear();
- }
- return self();
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public java.lang.String toString() {
- return "SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilder(field1=" + this.field1 + ", items$key=" + this.items$key + ", items$value=" + this.items$value + ")";
- }
- }
- @java.lang.SuppressWarnings("all")
- private static final class ParentBuilderImpl<A> extends SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilder<A, SuperBuilderWithGenericsAndToBuilder.Parent<A>, SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilderImpl<A>> {
- @java.lang.SuppressWarnings("all")
- private ParentBuilderImpl() {
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilderImpl<A> self() {
- return this;
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public SuperBuilderWithGenericsAndToBuilder.Parent<A> build() {
- return new SuperBuilderWithGenericsAndToBuilder.Parent<A>(this);
- }
- }
- @java.lang.SuppressWarnings("all")
- protected Parent(final SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilder<A, ?, ?> b) {
- this.field1 = b.field1;
- java.util.Map<Integer, String> items;
- switch (b.items$key == null ? 0 : b.items$key.size()) {
- case 0:
- items = java.util.Collections.emptyMap();
- break;
- case 1:
- items = java.util.Collections.singletonMap(b.items$key.get(0), b.items$value.get(0));
- break;
- default:
- items = new java.util.LinkedHashMap<Integer, String>(b.items$key.size() < 1073741824 ? 1 + b.items$key.size() + (b.items$key.size() - 3) / 3 : java.lang.Integer.MAX_VALUE);
- for (int $i = 0; $i < b.items$key.size(); $i++) items.put(b.items$key.get($i), (String) b.items$value.get($i));
- items = java.util.Collections.unmodifiableMap(items);
- }
- this.items = items;
- }
- @java.lang.SuppressWarnings("all")
- public static <A> SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilder<A, ?, ?> builder() {
- return new SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilderImpl<A>();
- }
- @java.lang.SuppressWarnings("all")
- public SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilder<A, ?, ?> toBuilder() {
- return new SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilderImpl<A>().$fillValuesFrom(this);
- }
- }
- public static class Child<A> extends Parent<A> {
- double field3;
- @java.lang.SuppressWarnings("all")
- public static abstract class ChildBuilder<A, C extends SuperBuilderWithGenericsAndToBuilder.Child<A>, B extends SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilder<A, C, B>> extends Parent.ParentBuilder<A, C, B> {
- @java.lang.SuppressWarnings("all")
- private double field3;
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected B $fillValuesFrom(final C instance) {
- super.$fillValuesFrom(instance);
- SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilder.$fillValuesFromInstanceIntoBuilder(instance, this);
- return self();
- }
- @java.lang.SuppressWarnings("all")
- private static <A> void $fillValuesFromInstanceIntoBuilder(final SuperBuilderWithGenericsAndToBuilder.Child<A> instance, final SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilder<A, ?, ?> b) {
- b.field3(instance.field3);
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected abstract B self();
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public abstract C build();
- /**
- * @return {@code this}.
- */
- @java.lang.SuppressWarnings("all")
- public B field3(final double field3) {
- this.field3 = field3;
- return self();
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public java.lang.String toString() {
- return "SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilder(super=" + super.toString() + ", field3=" + this.field3 + ")";
- }
- }
- @java.lang.SuppressWarnings("all")
- private static final class ChildBuilderImpl<A> extends SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilder<A, SuperBuilderWithGenericsAndToBuilder.Child<A>, SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilderImpl<A>> {
- @java.lang.SuppressWarnings("all")
- private ChildBuilderImpl() {
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilderImpl<A> self() {
- return this;
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public SuperBuilderWithGenericsAndToBuilder.Child<A> build() {
- return new SuperBuilderWithGenericsAndToBuilder.Child<A>(this);
- }
- }
- @java.lang.SuppressWarnings("all")
- protected Child(final SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilder<A, ?, ?> b) {
- super(b);
- this.field3 = b.field3;
- }
- @java.lang.SuppressWarnings("all")
- public static <A> SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilder<A, ?, ?> builder() {
- return new SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilderImpl<A>();
- }
- @java.lang.SuppressWarnings("all")
- public SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilder<A, ?, ?> toBuilder() {
- return new SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilderImpl<A>().$fillValuesFrom(this);
- }
- }
- public static void test() {
- Child<Integer> x = Child.<Integer>builder().field3(0.0).field1(5).item(5, "").build().toBuilder().build();
- }
-}
+import java.util.Map; +public class SuperBuilderWithGenericsAndToBuilder { + public static class Parent<A> { + A field1; + Map<Integer, String> items; + @java.lang.SuppressWarnings("all") + public static abstract class ParentBuilder<A, C extends SuperBuilderWithGenericsAndToBuilder.Parent<A>, B extends SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilder<A, C, B>> { + @java.lang.SuppressWarnings("all") + private A field1; + @java.lang.SuppressWarnings("all") + private java.util.ArrayList<Integer> items$key; + @java.lang.SuppressWarnings("all") + private java.util.ArrayList<String> items$value; + @java.lang.SuppressWarnings("all") + protected B $fillValuesFrom(final C instance) { + SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilder.$fillValuesFromInstanceIntoBuilder(instance, this); + return self(); + } + @java.lang.SuppressWarnings("all") + private static <A> void $fillValuesFromInstanceIntoBuilder(final SuperBuilderWithGenericsAndToBuilder.Parent<A> instance, final SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilder<A, ?, ?> b) { + b.field1(instance.field1); + b.items(instance.items == null ? java.util.Collections.<Integer, String>emptyMap() : instance.items); + } + @java.lang.SuppressWarnings("all") + protected abstract B self(); + @java.lang.SuppressWarnings("all") + public abstract C build(); + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public B field1(final A field1) { + this.field1 = field1; + return self(); + } + @java.lang.SuppressWarnings("all") + public B item(final Integer itemKey, final String itemValue) { + if (this.items$key == null) { + this.items$key = new java.util.ArrayList<Integer>(); + this.items$value = new java.util.ArrayList<String>(); + } + this.items$key.add(itemKey); + this.items$value.add(itemValue); + return self(); + } + @java.lang.SuppressWarnings("all") + public B items(final java.util.Map<? extends Integer, ? extends String> items) { + if (items == null) { + throw new java.lang.NullPointerException("items cannot be null"); + } + if (this.items$key == null) { + this.items$key = new java.util.ArrayList<Integer>(); + this.items$value = new java.util.ArrayList<String>(); + } + for (final java.util.Map.Entry<? extends Integer, ? extends String> $lombokEntry : items.entrySet()) { + this.items$key.add($lombokEntry.getKey()); + this.items$value.add($lombokEntry.getValue()); + } + return self(); + } + @java.lang.SuppressWarnings("all") + public B clearItems() { + if (this.items$key != null) { + this.items$key.clear(); + this.items$value.clear(); + } + return self(); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilder(field1=" + this.field1 + ", items$key=" + this.items$key + ", items$value=" + this.items$value + ")"; + } + } + @java.lang.SuppressWarnings("all") + private static final class ParentBuilderImpl<A> extends SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilder<A, SuperBuilderWithGenericsAndToBuilder.Parent<A>, SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilderImpl<A>> { + @java.lang.SuppressWarnings("all") + private ParentBuilderImpl() { + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilderImpl<A> self() { + return this; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public SuperBuilderWithGenericsAndToBuilder.Parent<A> build() { + return new SuperBuilderWithGenericsAndToBuilder.Parent<A>(this); + } + } + @java.lang.SuppressWarnings("all") + protected Parent(final SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilder<A, ?, ?> b) { + this.field1 = b.field1; + java.util.Map<Integer, String> items; + switch (b.items$key == null ? 0 : b.items$key.size()) { + case 0: + items = java.util.Collections.emptyMap(); + break; + case 1: + items = java.util.Collections.singletonMap(b.items$key.get(0), b.items$value.get(0)); + break; + default: + items = new java.util.LinkedHashMap<Integer, String>(b.items$key.size() < 1073741824 ? 1 + b.items$key.size() + (b.items$key.size() - 3) / 3 : java.lang.Integer.MAX_VALUE); + for (int $i = 0; $i < b.items$key.size(); $i++) items.put(b.items$key.get($i), (String) b.items$value.get($i)); + items = java.util.Collections.unmodifiableMap(items); + } + this.items = items; + } + @java.lang.SuppressWarnings("all") + public static <A> SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilder<A, ?, ?> builder() { + return new SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilderImpl<A>(); + } + @java.lang.SuppressWarnings("all") + public SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilder<A, ?, ?> toBuilder() { + return new SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilderImpl<A>().$fillValuesFrom(this); + } + } + public static class Child<A> extends Parent<A> { + double field3; + @java.lang.SuppressWarnings("all") + public static abstract class ChildBuilder<A, C extends SuperBuilderWithGenericsAndToBuilder.Child<A>, B extends SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilder<A, C, B>> extends Parent.ParentBuilder<A, C, B> { + @java.lang.SuppressWarnings("all") + private double field3; + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected B $fillValuesFrom(final C instance) { + super.$fillValuesFrom(instance); + SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilder.$fillValuesFromInstanceIntoBuilder(instance, this); + return self(); + } + @java.lang.SuppressWarnings("all") + private static <A> void $fillValuesFromInstanceIntoBuilder(final SuperBuilderWithGenericsAndToBuilder.Child<A> instance, final SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilder<A, ?, ?> b) { + b.field3(instance.field3); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected abstract B self(); + @java.lang.Override + @java.lang.SuppressWarnings("all") + public abstract C build(); + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public B field3(final double field3) { + this.field3 = field3; + return self(); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilder(super=" + super.toString() + ", field3=" + this.field3 + ")"; + } + } + @java.lang.SuppressWarnings("all") + private static final class ChildBuilderImpl<A> extends SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilder<A, SuperBuilderWithGenericsAndToBuilder.Child<A>, SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilderImpl<A>> { + @java.lang.SuppressWarnings("all") + private ChildBuilderImpl() { + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilderImpl<A> self() { + return this; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public SuperBuilderWithGenericsAndToBuilder.Child<A> build() { + return new SuperBuilderWithGenericsAndToBuilder.Child<A>(this); + } + } + @java.lang.SuppressWarnings("all") + protected Child(final SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilder<A, ?, ?> b) { + super(b); + this.field3 = b.field3; + } + @java.lang.SuppressWarnings("all") + public static <A> SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilder<A, ?, ?> builder() { + return new SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilderImpl<A>(); + } + @java.lang.SuppressWarnings("all") + public SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilder<A, ?, ?> toBuilder() { + return new SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilderImpl<A>().$fillValuesFrom(this); + } + } + public static void test() { + Child<Integer> x = Child.<Integer>builder().field3(0.0).field1(5).item(5, "").build().toBuilder().build(); + } +} diff --git a/test/transform/resource/after-delombok/SuperBuilderWithNonNull.java b/test/transform/resource/after-delombok/SuperBuilderWithNonNull.java index 771e42f4..a3e15e8d 100644 --- a/test/transform/resource/after-delombok/SuperBuilderWithNonNull.java +++ b/test/transform/resource/after-delombok/SuperBuilderWithNonNull.java @@ -1,129 +1,130 @@ -import java.util.List;
-public class SuperBuilderWithNonNull {
- public static class Parent {
- @lombok.NonNull
- final String nonNullParentField;
- @java.lang.SuppressWarnings("all")
- private static String $default$nonNullParentField() {
- return "default";
- }
- @java.lang.SuppressWarnings("all")
- public static abstract class ParentBuilder<C extends SuperBuilderWithNonNull.Parent, B extends SuperBuilderWithNonNull.Parent.ParentBuilder<C, B>> {
- @java.lang.SuppressWarnings("all")
- private boolean nonNullParentField$set;
- @java.lang.SuppressWarnings("all")
- private String nonNullParentField$value;
- @java.lang.SuppressWarnings("all")
- protected abstract B self();
- @java.lang.SuppressWarnings("all")
- public abstract C build();
- /**
- * @return {@code this}.
- */
- @java.lang.SuppressWarnings("all")
- public B nonNullParentField(@lombok.NonNull final String nonNullParentField) {
- if (nonNullParentField == null) {
- throw new java.lang.NullPointerException("nonNullParentField is marked non-null but is null");
- }
- this.nonNullParentField$value = nonNullParentField;
- nonNullParentField$set = true;
- return self();
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public java.lang.String toString() {
- return "SuperBuilderWithNonNull.Parent.ParentBuilder(nonNullParentField$value=" + this.nonNullParentField$value + ")";
- }
- }
- @java.lang.SuppressWarnings("all")
- private static final class ParentBuilderImpl extends SuperBuilderWithNonNull.Parent.ParentBuilder<SuperBuilderWithNonNull.Parent, SuperBuilderWithNonNull.Parent.ParentBuilderImpl> {
- @java.lang.SuppressWarnings("all")
- private ParentBuilderImpl() {
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected SuperBuilderWithNonNull.Parent.ParentBuilderImpl self() {
- return this;
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public SuperBuilderWithNonNull.Parent build() {
- return new SuperBuilderWithNonNull.Parent(this);
- }
- }
- @java.lang.SuppressWarnings("all")
- protected Parent(final SuperBuilderWithNonNull.Parent.ParentBuilder<?, ?> b) {
- if (b.nonNullParentField$set) this.nonNullParentField = b.nonNullParentField$value;
- else this.nonNullParentField = SuperBuilderWithNonNull.Parent.$default$nonNullParentField();
- if (nonNullParentField == null) {
- throw new java.lang.NullPointerException("nonNullParentField is marked non-null but is null");
- }
- }
- @java.lang.SuppressWarnings("all")
- public static SuperBuilderWithNonNull.Parent.ParentBuilder<?, ?> builder() {
- return new SuperBuilderWithNonNull.Parent.ParentBuilderImpl();
- }
- }
- public static class Child extends Parent {
- @lombok.NonNull
- String nonNullChildField;
- @java.lang.SuppressWarnings("all")
- public static abstract class ChildBuilder<C extends SuperBuilderWithNonNull.Child, B extends SuperBuilderWithNonNull.Child.ChildBuilder<C, B>> extends Parent.ParentBuilder<C, B> {
- @java.lang.SuppressWarnings("all")
- private String nonNullChildField;
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected abstract B self();
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public abstract C build();
- /**
- * @return {@code this}.
- */
- @java.lang.SuppressWarnings("all")
- public B nonNullChildField(@lombok.NonNull final String nonNullChildField) {
- if (nonNullChildField == null) {
- throw new java.lang.NullPointerException("nonNullChildField is marked non-null but is null");
- }
- this.nonNullChildField = nonNullChildField;
- return self();
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public java.lang.String toString() {
- return "SuperBuilderWithNonNull.Child.ChildBuilder(super=" + super.toString() + ", nonNullChildField=" + this.nonNullChildField + ")";
- }
- }
- @java.lang.SuppressWarnings("all")
- private static final class ChildBuilderImpl extends SuperBuilderWithNonNull.Child.ChildBuilder<SuperBuilderWithNonNull.Child, SuperBuilderWithNonNull.Child.ChildBuilderImpl> {
- @java.lang.SuppressWarnings("all")
- private ChildBuilderImpl() {
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected SuperBuilderWithNonNull.Child.ChildBuilderImpl self() {
- return this;
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public SuperBuilderWithNonNull.Child build() {
- return new SuperBuilderWithNonNull.Child(this);
- }
- }
- @java.lang.SuppressWarnings("all")
- protected Child(final SuperBuilderWithNonNull.Child.ChildBuilder<?, ?> b) {
- super(b);
- this.nonNullChildField = b.nonNullChildField;
- if (nonNullChildField == null) {
- throw new java.lang.NullPointerException("nonNullChildField is marked non-null but is null");
- }
- }
- @java.lang.SuppressWarnings("all")
- public static SuperBuilderWithNonNull.Child.ChildBuilder<?, ?> builder() {
- return new SuperBuilderWithNonNull.Child.ChildBuilderImpl();
- }
- }
- public static void test() {
- Child x = Child.builder().nonNullChildField("child").nonNullParentField("parent").build();
- }
-}
+//version 8: +import java.util.List; +public class SuperBuilderWithNonNull { + public static class Parent { + @lombok.NonNull + final String nonNullParentField; + @java.lang.SuppressWarnings("all") + private static String $default$nonNullParentField() { + return "default"; + } + @java.lang.SuppressWarnings("all") + public static abstract class ParentBuilder<C extends SuperBuilderWithNonNull.Parent, B extends SuperBuilderWithNonNull.Parent.ParentBuilder<C, B>> { + @java.lang.SuppressWarnings("all") + private boolean nonNullParentField$set; + @java.lang.SuppressWarnings("all") + private String nonNullParentField$value; + @java.lang.SuppressWarnings("all") + protected abstract B self(); + @java.lang.SuppressWarnings("all") + public abstract C build(); + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public B nonNullParentField(@lombok.NonNull final String nonNullParentField) { + if (nonNullParentField == null) { + throw new java.lang.NullPointerException("nonNullParentField is marked non-null but is null"); + } + this.nonNullParentField$value = nonNullParentField; + nonNullParentField$set = true; + return self(); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "SuperBuilderWithNonNull.Parent.ParentBuilder(nonNullParentField$value=" + this.nonNullParentField$value + ")"; + } + } + @java.lang.SuppressWarnings("all") + private static final class ParentBuilderImpl extends SuperBuilderWithNonNull.Parent.ParentBuilder<SuperBuilderWithNonNull.Parent, SuperBuilderWithNonNull.Parent.ParentBuilderImpl> { + @java.lang.SuppressWarnings("all") + private ParentBuilderImpl() { + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected SuperBuilderWithNonNull.Parent.ParentBuilderImpl self() { + return this; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public SuperBuilderWithNonNull.Parent build() { + return new SuperBuilderWithNonNull.Parent(this); + } + } + @java.lang.SuppressWarnings("all") + protected Parent(final SuperBuilderWithNonNull.Parent.ParentBuilder<?, ?> b) { + if (b.nonNullParentField$set) this.nonNullParentField = b.nonNullParentField$value; + else this.nonNullParentField = SuperBuilderWithNonNull.Parent.$default$nonNullParentField(); + if (nonNullParentField == null) { + throw new java.lang.NullPointerException("nonNullParentField is marked non-null but is null"); + } + } + @java.lang.SuppressWarnings("all") + public static SuperBuilderWithNonNull.Parent.ParentBuilder<?, ?> builder() { + return new SuperBuilderWithNonNull.Parent.ParentBuilderImpl(); + } + } + public static class Child extends Parent { + @lombok.NonNull + String nonNullChildField; + @java.lang.SuppressWarnings("all") + public static abstract class ChildBuilder<C extends SuperBuilderWithNonNull.Child, B extends SuperBuilderWithNonNull.Child.ChildBuilder<C, B>> extends Parent.ParentBuilder<C, B> { + @java.lang.SuppressWarnings("all") + private String nonNullChildField; + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected abstract B self(); + @java.lang.Override + @java.lang.SuppressWarnings("all") + public abstract C build(); + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public B nonNullChildField(@lombok.NonNull final String nonNullChildField) { + if (nonNullChildField == null) { + throw new java.lang.NullPointerException("nonNullChildField is marked non-null but is null"); + } + this.nonNullChildField = nonNullChildField; + return self(); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "SuperBuilderWithNonNull.Child.ChildBuilder(super=" + super.toString() + ", nonNullChildField=" + this.nonNullChildField + ")"; + } + } + @java.lang.SuppressWarnings("all") + private static final class ChildBuilderImpl extends SuperBuilderWithNonNull.Child.ChildBuilder<SuperBuilderWithNonNull.Child, SuperBuilderWithNonNull.Child.ChildBuilderImpl> { + @java.lang.SuppressWarnings("all") + private ChildBuilderImpl() { + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected SuperBuilderWithNonNull.Child.ChildBuilderImpl self() { + return this; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public SuperBuilderWithNonNull.Child build() { + return new SuperBuilderWithNonNull.Child(this); + } + } + @java.lang.SuppressWarnings("all") + protected Child(final SuperBuilderWithNonNull.Child.ChildBuilder<?, ?> b) { + super(b); + this.nonNullChildField = b.nonNullChildField; + if (nonNullChildField == null) { + throw new java.lang.NullPointerException("nonNullChildField is marked non-null but is null"); + } + } + @java.lang.SuppressWarnings("all") + public static SuperBuilderWithNonNull.Child.ChildBuilder<?, ?> builder() { + return new SuperBuilderWithNonNull.Child.ChildBuilderImpl(); + } + } + public static void test() { + Child x = Child.builder().nonNullChildField("child").nonNullParentField("parent").build(); + } +} diff --git a/test/transform/resource/after-delombok/SuperBuilderWithSetterPrefix.java b/test/transform/resource/after-delombok/SuperBuilderWithSetterPrefix.java index 0f007350..88db8511 100644 --- a/test/transform/resource/after-delombok/SuperBuilderWithSetterPrefix.java +++ b/test/transform/resource/after-delombok/SuperBuilderWithSetterPrefix.java @@ -1,216 +1,216 @@ -import java.util.List;
-public class SuperBuilderWithSetterPrefix {
- public static class Parent {
- private int field1;
- int obtainViaField;
- int obtainViaMethod;
- String obtainViaStaticMethod;
- List<String> items;
- private int method() {
- return 2;
- }
- private static String staticMethod(Parent instance) {
- return "staticMethod";
- }
- @java.lang.SuppressWarnings("all")
- public static abstract class ParentBuilder<C extends SuperBuilderWithSetterPrefix.Parent, B extends SuperBuilderWithSetterPrefix.Parent.ParentBuilder<C, B>> {
- @java.lang.SuppressWarnings("all")
- private int field1;
- @java.lang.SuppressWarnings("all")
- private int obtainViaField;
- @java.lang.SuppressWarnings("all")
- private int obtainViaMethod;
- @java.lang.SuppressWarnings("all")
- private String obtainViaStaticMethod;
- @java.lang.SuppressWarnings("all")
- private java.util.ArrayList<String> items;
- @java.lang.SuppressWarnings("all")
- protected B $fillValuesFrom(final C instance) {
- SuperBuilderWithSetterPrefix.Parent.ParentBuilder.$fillValuesFromInstanceIntoBuilder(instance, this);
- return self();
- }
- @java.lang.SuppressWarnings("all")
- private static void $fillValuesFromInstanceIntoBuilder(final SuperBuilderWithSetterPrefix.Parent instance, final SuperBuilderWithSetterPrefix.Parent.ParentBuilder<?, ?> b) {
- b.withField1(instance.field1);
- b.withObtainViaField(instance.field1);
- b.withObtainViaMethod(instance.method());
- b.withObtainViaStaticMethod(SuperBuilderWithSetterPrefix.Parent.staticMethod(instance));
- b.withItems(instance.items == null ? java.util.Collections.emptyList() : instance.items);
- }
- @java.lang.SuppressWarnings("all")
- protected abstract B self();
- @java.lang.SuppressWarnings("all")
- public abstract C build();
- /**
- * @return {@code this}.
- */
- @java.lang.SuppressWarnings("all")
- public B withField1(final int field1) {
- this.field1 = field1;
- return self();
- }
- /**
- * @return {@code this}.
- */
- @java.lang.SuppressWarnings("all")
- public B withObtainViaField(final int obtainViaField) {
- this.obtainViaField = obtainViaField;
- return self();
- }
- /**
- * @return {@code this}.
- */
- @java.lang.SuppressWarnings("all")
- public B withObtainViaMethod(final int obtainViaMethod) {
- this.obtainViaMethod = obtainViaMethod;
- return self();
- }
- /**
- * @return {@code this}.
- */
- @java.lang.SuppressWarnings("all")
- public B withObtainViaStaticMethod(final String obtainViaStaticMethod) {
- this.obtainViaStaticMethod = obtainViaStaticMethod;
- return self();
- }
- @java.lang.SuppressWarnings("all")
- public B withItem(final String item) {
- if (this.items == null) this.items = new java.util.ArrayList<String>();
- this.items.add(item);
- return self();
- }
- @java.lang.SuppressWarnings("all")
- public B withItems(final java.util.Collection<? extends String> items) {
- if (items == null) {
- throw new java.lang.NullPointerException("items cannot be null");
- }
- if (this.items == null) this.items = new java.util.ArrayList<String>();
- this.items.addAll(items);
- return self();
- }
- @java.lang.SuppressWarnings("all")
- public B clearItems() {
- if (this.items != null) this.items.clear();
- return self();
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public java.lang.String toString() {
- return "SuperBuilderWithSetterPrefix.Parent.ParentBuilder(field1=" + this.field1 + ", obtainViaField=" + this.obtainViaField + ", obtainViaMethod=" + this.obtainViaMethod + ", obtainViaStaticMethod=" + this.obtainViaStaticMethod + ", items=" + this.items + ")";
- }
- }
- @java.lang.SuppressWarnings("all")
- private static final class ParentBuilderImpl extends SuperBuilderWithSetterPrefix.Parent.ParentBuilder<SuperBuilderWithSetterPrefix.Parent, SuperBuilderWithSetterPrefix.Parent.ParentBuilderImpl> {
- @java.lang.SuppressWarnings("all")
- private ParentBuilderImpl() {
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected SuperBuilderWithSetterPrefix.Parent.ParentBuilderImpl self() {
- return this;
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public SuperBuilderWithSetterPrefix.Parent build() {
- return new SuperBuilderWithSetterPrefix.Parent(this);
- }
- }
- @java.lang.SuppressWarnings("all")
- protected Parent(final SuperBuilderWithSetterPrefix.Parent.ParentBuilder<?, ?> b) {
- this.field1 = b.field1;
- this.obtainViaField = b.obtainViaField;
- this.obtainViaMethod = b.obtainViaMethod;
- this.obtainViaStaticMethod = b.obtainViaStaticMethod;
- java.util.List<String> items;
- switch (b.items == null ? 0 : b.items.size()) {
- case 0:
- items = java.util.Collections.emptyList();
- break;
- case 1:
- items = java.util.Collections.singletonList(b.items.get(0));
- break;
- default:
- items = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(b.items));
- }
- this.items = items;
- }
- @java.lang.SuppressWarnings("all")
- public static SuperBuilderWithSetterPrefix.Parent.ParentBuilder<?, ?> builder() {
- return new SuperBuilderWithSetterPrefix.Parent.ParentBuilderImpl();
- }
- @java.lang.SuppressWarnings("all")
- public SuperBuilderWithSetterPrefix.Parent.ParentBuilder<?, ?> toBuilder() {
- return new SuperBuilderWithSetterPrefix.Parent.ParentBuilderImpl().$fillValuesFrom(this);
- }
- }
- public static class Child extends Parent {
- private double field3;
- @java.lang.SuppressWarnings("all")
- public static abstract class ChildBuilder<C extends SuperBuilderWithSetterPrefix.Child, B extends SuperBuilderWithSetterPrefix.Child.ChildBuilder<C, B>> extends Parent.ParentBuilder<C, B> {
- @java.lang.SuppressWarnings("all")
- private double field3;
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected B $fillValuesFrom(final C instance) {
- super.$fillValuesFrom(instance);
- SuperBuilderWithSetterPrefix.Child.ChildBuilder.$fillValuesFromInstanceIntoBuilder(instance, this);
- return self();
- }
- @java.lang.SuppressWarnings("all")
- private static void $fillValuesFromInstanceIntoBuilder(final SuperBuilderWithSetterPrefix.Child instance, final SuperBuilderWithSetterPrefix.Child.ChildBuilder<?, ?> b) {
- b.setField3(instance.field3);
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected abstract B self();
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public abstract C build();
- /**
- * @return {@code this}.
- */
- @java.lang.SuppressWarnings("all")
- public B setField3(final double field3) {
- this.field3 = field3;
- return self();
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public java.lang.String toString() {
- return "SuperBuilderWithSetterPrefix.Child.ChildBuilder(super=" + super.toString() + ", field3=" + this.field3 + ")";
- }
- }
- @java.lang.SuppressWarnings("all")
- private static final class ChildBuilderImpl extends SuperBuilderWithSetterPrefix.Child.ChildBuilder<SuperBuilderWithSetterPrefix.Child, SuperBuilderWithSetterPrefix.Child.ChildBuilderImpl> {
- @java.lang.SuppressWarnings("all")
- private ChildBuilderImpl() {
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- protected SuperBuilderWithSetterPrefix.Child.ChildBuilderImpl self() {
- return this;
- }
- @java.lang.Override
- @java.lang.SuppressWarnings("all")
- public SuperBuilderWithSetterPrefix.Child build() {
- return new SuperBuilderWithSetterPrefix.Child(this);
- }
- }
- @java.lang.SuppressWarnings("all")
- protected Child(final SuperBuilderWithSetterPrefix.Child.ChildBuilder<?, ?> b) {
- super(b);
- this.field3 = b.field3;
- }
- @java.lang.SuppressWarnings("all")
- public static SuperBuilderWithSetterPrefix.Child.ChildBuilder<?, ?> builder() {
- return new SuperBuilderWithSetterPrefix.Child.ChildBuilderImpl();
- }
- @java.lang.SuppressWarnings("all")
- public SuperBuilderWithSetterPrefix.Child.ChildBuilder<?, ?> toBuilder() {
- return new SuperBuilderWithSetterPrefix.Child.ChildBuilderImpl().$fillValuesFrom(this);
- }
- }
- public static void test() {
- Child x = Child.builder().setField3(0.0).withField1(5).withItem("").build().toBuilder().build();
- }
-}
+import java.util.List; +public class SuperBuilderWithSetterPrefix { + public static class Parent { + private int field1; + int obtainViaField; + int obtainViaMethod; + String obtainViaStaticMethod; + List<String> items; + private int method() { + return 2; + } + private static String staticMethod(Parent instance) { + return "staticMethod"; + } + @java.lang.SuppressWarnings("all") + public static abstract class ParentBuilder<C extends SuperBuilderWithSetterPrefix.Parent, B extends SuperBuilderWithSetterPrefix.Parent.ParentBuilder<C, B>> { + @java.lang.SuppressWarnings("all") + private int field1; + @java.lang.SuppressWarnings("all") + private int obtainViaField; + @java.lang.SuppressWarnings("all") + private int obtainViaMethod; + @java.lang.SuppressWarnings("all") + private String obtainViaStaticMethod; + @java.lang.SuppressWarnings("all") + private java.util.ArrayList<String> items; + @java.lang.SuppressWarnings("all") + protected B $fillValuesFrom(final C instance) { + SuperBuilderWithSetterPrefix.Parent.ParentBuilder.$fillValuesFromInstanceIntoBuilder(instance, this); + return self(); + } + @java.lang.SuppressWarnings("all") + private static void $fillValuesFromInstanceIntoBuilder(final SuperBuilderWithSetterPrefix.Parent instance, final SuperBuilderWithSetterPrefix.Parent.ParentBuilder<?, ?> b) { + b.withField1(instance.field1); + b.withObtainViaField(instance.field1); + b.withObtainViaMethod(instance.method()); + b.withObtainViaStaticMethod(SuperBuilderWithSetterPrefix.Parent.staticMethod(instance)); + b.withItems(instance.items == null ? java.util.Collections.<String>emptyList() : instance.items); + } + @java.lang.SuppressWarnings("all") + protected abstract B self(); + @java.lang.SuppressWarnings("all") + public abstract C build(); + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public B withField1(final int field1) { + this.field1 = field1; + return self(); + } + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public B withObtainViaField(final int obtainViaField) { + this.obtainViaField = obtainViaField; + return self(); + } + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public B withObtainViaMethod(final int obtainViaMethod) { + this.obtainViaMethod = obtainViaMethod; + return self(); + } + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public B withObtainViaStaticMethod(final String obtainViaStaticMethod) { + this.obtainViaStaticMethod = obtainViaStaticMethod; + return self(); + } + @java.lang.SuppressWarnings("all") + public B withItem(final String item) { + if (this.items == null) this.items = new java.util.ArrayList<String>(); + this.items.add(item); + return self(); + } + @java.lang.SuppressWarnings("all") + public B withItems(final java.util.Collection<? extends String> items) { + if (items == null) { + throw new java.lang.NullPointerException("items cannot be null"); + } + if (this.items == null) this.items = new java.util.ArrayList<String>(); + this.items.addAll(items); + return self(); + } + @java.lang.SuppressWarnings("all") + public B clearItems() { + if (this.items != null) this.items.clear(); + return self(); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "SuperBuilderWithSetterPrefix.Parent.ParentBuilder(field1=" + this.field1 + ", obtainViaField=" + this.obtainViaField + ", obtainViaMethod=" + this.obtainViaMethod + ", obtainViaStaticMethod=" + this.obtainViaStaticMethod + ", items=" + this.items + ")"; + } + } + @java.lang.SuppressWarnings("all") + private static final class ParentBuilderImpl extends SuperBuilderWithSetterPrefix.Parent.ParentBuilder<SuperBuilderWithSetterPrefix.Parent, SuperBuilderWithSetterPrefix.Parent.ParentBuilderImpl> { + @java.lang.SuppressWarnings("all") + private ParentBuilderImpl() { + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected SuperBuilderWithSetterPrefix.Parent.ParentBuilderImpl self() { + return this; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public SuperBuilderWithSetterPrefix.Parent build() { + return new SuperBuilderWithSetterPrefix.Parent(this); + } + } + @java.lang.SuppressWarnings("all") + protected Parent(final SuperBuilderWithSetterPrefix.Parent.ParentBuilder<?, ?> b) { + this.field1 = b.field1; + this.obtainViaField = b.obtainViaField; + this.obtainViaMethod = b.obtainViaMethod; + this.obtainViaStaticMethod = b.obtainViaStaticMethod; + java.util.List<String> items; + switch (b.items == null ? 0 : b.items.size()) { + case 0: + items = java.util.Collections.emptyList(); + break; + case 1: + items = java.util.Collections.singletonList(b.items.get(0)); + break; + default: + items = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(b.items)); + } + this.items = items; + } + @java.lang.SuppressWarnings("all") + public static SuperBuilderWithSetterPrefix.Parent.ParentBuilder<?, ?> builder() { + return new SuperBuilderWithSetterPrefix.Parent.ParentBuilderImpl(); + } + @java.lang.SuppressWarnings("all") + public SuperBuilderWithSetterPrefix.Parent.ParentBuilder<?, ?> toBuilder() { + return new SuperBuilderWithSetterPrefix.Parent.ParentBuilderImpl().$fillValuesFrom(this); + } + } + public static class Child extends Parent { + private double field3; + @java.lang.SuppressWarnings("all") + public static abstract class ChildBuilder<C extends SuperBuilderWithSetterPrefix.Child, B extends SuperBuilderWithSetterPrefix.Child.ChildBuilder<C, B>> extends Parent.ParentBuilder<C, B> { + @java.lang.SuppressWarnings("all") + private double field3; + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected B $fillValuesFrom(final C instance) { + super.$fillValuesFrom(instance); + SuperBuilderWithSetterPrefix.Child.ChildBuilder.$fillValuesFromInstanceIntoBuilder(instance, this); + return self(); + } + @java.lang.SuppressWarnings("all") + private static void $fillValuesFromInstanceIntoBuilder(final SuperBuilderWithSetterPrefix.Child instance, final SuperBuilderWithSetterPrefix.Child.ChildBuilder<?, ?> b) { + b.setField3(instance.field3); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected abstract B self(); + @java.lang.Override + @java.lang.SuppressWarnings("all") + public abstract C build(); + /** + * @return {@code this}. + */ + @java.lang.SuppressWarnings("all") + public B setField3(final double field3) { + this.field3 = field3; + return self(); + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public java.lang.String toString() { + return "SuperBuilderWithSetterPrefix.Child.ChildBuilder(super=" + super.toString() + ", field3=" + this.field3 + ")"; + } + } + @java.lang.SuppressWarnings("all") + private static final class ChildBuilderImpl extends SuperBuilderWithSetterPrefix.Child.ChildBuilder<SuperBuilderWithSetterPrefix.Child, SuperBuilderWithSetterPrefix.Child.ChildBuilderImpl> { + @java.lang.SuppressWarnings("all") + private ChildBuilderImpl() { + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + protected SuperBuilderWithSetterPrefix.Child.ChildBuilderImpl self() { + return this; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + public SuperBuilderWithSetterPrefix.Child build() { + return new SuperBuilderWithSetterPrefix.Child(this); + } + } + @java.lang.SuppressWarnings("all") + protected Child(final SuperBuilderWithSetterPrefix.Child.ChildBuilder<?, ?> b) { + super(b); + this.field3 = b.field3; + } + @java.lang.SuppressWarnings("all") + public static SuperBuilderWithSetterPrefix.Child.ChildBuilder<?, ?> builder() { + return new SuperBuilderWithSetterPrefix.Child.ChildBuilderImpl(); + } + @java.lang.SuppressWarnings("all") + public SuperBuilderWithSetterPrefix.Child.ChildBuilder<?, ?> toBuilder() { + return new SuperBuilderWithSetterPrefix.Child.ChildBuilderImpl().$fillValuesFrom(this); + } + } + public static void test() { + Child x = Child.builder().setField3(0.0).withField1(5).withItem("").build().toBuilder().build(); + } +} diff --git a/test/transform/resource/after-delombok/SynchronizedInRecord.java b/test/transform/resource/after-delombok/SynchronizedInRecord.java new file mode 100644 index 00000000..32e7daee --- /dev/null +++ b/test/transform/resource/after-delombok/SynchronizedInRecord.java @@ -0,0 +1,6 @@ +// version 14: +public record SynchronizedInRecord(String a, String b) { + public void foo() { + String foo = "bar"; + } +} diff --git a/test/transform/resource/after-delombok/ToStringOnRecord.java b/test/transform/resource/after-delombok/ToStringOnRecord.java new file mode 100644 index 00000000..6d6d4edf --- /dev/null +++ b/test/transform/resource/after-delombok/ToStringOnRecord.java @@ -0,0 +1,3 @@ +// version 14: +public record ToStringOnRecord(String a, String b) { +} diff --git a/test/transform/resource/after-delombok/TypeUseAnnotations.java b/test/transform/resource/after-delombok/TypeUseAnnotations.java index fbf32577..37c24c53 100644 --- a/test/transform/resource/after-delombok/TypeUseAnnotations.java +++ b/test/transform/resource/after-delombok/TypeUseAnnotations.java @@ -1,3 +1,4 @@ +//version 8: import java.lang.annotation.ElementType; import java.lang.annotation.Target; import java.util.List; diff --git a/test/transform/resource/after-delombok/UtilityClassOnRecord.java b/test/transform/resource/after-delombok/UtilityClassOnRecord.java new file mode 100644 index 00000000..3606b452 --- /dev/null +++ b/test/transform/resource/after-delombok/UtilityClassOnRecord.java @@ -0,0 +1,3 @@ +// version 14: +public record UtilityClassOnRecord(String a, String b) { +} diff --git a/test/transform/resource/after-delombok/ValDelegateMethodReference.java b/test/transform/resource/after-delombok/ValDelegateMethodReference.java index 186e2aaa..c62edd66 100644 --- a/test/transform/resource/after-delombok/ValDelegateMethodReference.java +++ b/test/transform/resource/after-delombok/ValDelegateMethodReference.java @@ -1,3 +1,4 @@ +//version 8: import java.util.function.Function; public class ValDelegateMethodReference { diff --git a/test/transform/resource/after-delombok/ValWeirdTypes.java b/test/transform/resource/after-delombok/ValWeirdTypes.java index bc18fdac..b3ecfc49 100644 --- a/test/transform/resource/after-delombok/ValWeirdTypes.java +++ b/test/transform/resource/after-delombok/ValWeirdTypes.java @@ -1,3 +1,4 @@ +// version 8: In java6/7, lub types worked differently, so, the `arraysAsList` method has a slightly different inferred type there. import java.math.BigDecimal; import java.util.*; public class ValWeirdTypes<Z> { diff --git a/test/transform/resource/after-delombok/ValueOnRecord.java b/test/transform/resource/after-delombok/ValueOnRecord.java new file mode 100644 index 00000000..daf92236 --- /dev/null +++ b/test/transform/resource/after-delombok/ValueOnRecord.java @@ -0,0 +1,3 @@ +// version 14: +public record ValueOnRecord(String a, String b) { +} diff --git a/test/transform/resource/after-delombok/WithByNullAnnos.java b/test/transform/resource/after-delombok/WithByNullAnnos.java index cdaed973..04d64f16 100644 --- a/test/transform/resource/after-delombok/WithByNullAnnos.java +++ b/test/transform/resource/after-delombok/WithByNullAnnos.java @@ -1,3 +1,4 @@ +//version 8: import java.util.List; public class WithByNullAnnos { final List<String> test; diff --git a/test/transform/resource/after-delombok/WithByOnRecord.java b/test/transform/resource/after-delombok/WithByOnRecord.java new file mode 100644 index 00000000..4d1ccd01 --- /dev/null +++ b/test/transform/resource/after-delombok/WithByOnRecord.java @@ -0,0 +1,11 @@ +// version 14: +public record WithByOnRecord(String a, String b) { + @java.lang.SuppressWarnings("all") + public WithByOnRecord withABy(final java.util.function.Function<? super String, ? extends String> transformer) { + return new WithByOnRecord(transformer.apply(this.a), this.b); + } + @java.lang.SuppressWarnings("all") + public WithByOnRecord withBBy(final java.util.function.Function<? super String, ? extends String> transformer) { + return new WithByOnRecord(this.a, transformer.apply(this.b)); + } +} diff --git a/test/transform/resource/after-delombok/WithByOnRecordComponent.java b/test/transform/resource/after-delombok/WithByOnRecordComponent.java new file mode 100644 index 00000000..851c5560 --- /dev/null +++ b/test/transform/resource/after-delombok/WithByOnRecordComponent.java @@ -0,0 +1,7 @@ +// version 14: +public record WithByOnRecordComponent(String a, String b) { + @java.lang.SuppressWarnings("all") + public WithByOnRecordComponent withABy(final java.util.function.Function<? super String, ? extends String> transformer) { + return new WithByOnRecordComponent(transformer.apply(this.a), this.b); + } +} diff --git a/test/transform/resource/after-delombok/WithByTypes.java b/test/transform/resource/after-delombok/WithByTypes.java index e5e2fb07..f1f1ef5f 100644 --- a/test/transform/resource/after-delombok/WithByTypes.java +++ b/test/transform/resource/after-delombok/WithByTypes.java @@ -1,3 +1,4 @@ +//version 8: public class WithByTypes<T> { private final int a; private final long b; diff --git a/test/transform/resource/after-delombok/WithOnClass.java b/test/transform/resource/after-delombok/WithOnClass.java index 34c6d811..0fa973eb 100644 --- a/test/transform/resource/after-delombok/WithOnClass.java +++ b/test/transform/resource/after-delombok/WithOnClass.java @@ -1,3 +1,4 @@ +//version 8: class WithOnClass1 { boolean isNone; boolean isPublic; diff --git a/test/transform/resource/after-delombok/WithOnRecord.java b/test/transform/resource/after-delombok/WithOnRecord.java new file mode 100644 index 00000000..5c2f0a8f --- /dev/null +++ b/test/transform/resource/after-delombok/WithOnRecord.java @@ -0,0 +1,17 @@ +// version 14: +public record WithOnRecord(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 WithOnRecord withA(final String a) { + return this.a == a ? this : new WithOnRecord(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 WithOnRecord withB(final String b) { + return this.b == b ? this : new WithOnRecord(this.a, b); + } +} diff --git a/test/transform/resource/after-delombok/WithOnRecordComponent.java b/test/transform/resource/after-delombok/WithOnRecordComponent.java new file mode 100644 index 00000000..217da88a --- /dev/null +++ b/test/transform/resource/after-delombok/WithOnRecordComponent.java @@ -0,0 +1,10 @@ +// version 14: +public record WithOnRecordComponent(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 WithOnRecordComponent withA(final String a) { + return this.a == a ? this : new WithOnRecordComponent(a, this.b); + } +} diff --git a/test/transform/resource/after-delombok/WithPlain.java b/test/transform/resource/after-delombok/WithPlain.java index 547c6fb9..6a1c46e6 100644 --- a/test/transform/resource/after-delombok/WithPlain.java +++ b/test/transform/resource/after-delombok/WithPlain.java @@ -1,3 +1,4 @@ +//version 8: springframework dep is too new to run on j6 class WithPlain { int i; final int foo; diff --git a/test/transform/resource/after-ecj/BuilderAccessWithGetter.java b/test/transform/resource/after-ecj/BuilderAccessWithGetter.java new file mode 100644 index 00000000..7ad5fa6a --- /dev/null +++ b/test/transform/resource/after-ecj/BuilderAccessWithGetter.java @@ -0,0 +1,35 @@ +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +public final @Builder(access = AccessLevel.PRIVATE) class BuilderAccessWithGetter { + private static @java.lang.SuppressWarnings("all") class BuilderAccessWithGetterBuilder { + private @java.lang.SuppressWarnings("all") String string; + @java.lang.SuppressWarnings("all") BuilderAccessWithGetterBuilder() { + super(); + } + /** + * @return {@code this}. + */ + private @java.lang.SuppressWarnings("all") BuilderAccessWithGetter.BuilderAccessWithGetterBuilder string(final String string) { + this.string = string; + return this; + } + private @java.lang.SuppressWarnings("all") BuilderAccessWithGetter build() { + return new BuilderAccessWithGetter(this.string); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (("BuilderAccessWithGetter.BuilderAccessWithGetterBuilder(string=" + this.string) + ")"); + } + } + private final @Getter String string; + @java.lang.SuppressWarnings("all") BuilderAccessWithGetter(final String string) { + super(); + this.string = string; + } + private static @java.lang.SuppressWarnings("all") BuilderAccessWithGetter.BuilderAccessWithGetterBuilder builder() { + return new BuilderAccessWithGetter.BuilderAccessWithGetterBuilder(); + } + public @java.lang.SuppressWarnings("all") String getString() { + return this.string; + } +} diff --git a/test/transform/resource/after-ecj/BuilderJavadoc.java b/test/transform/resource/after-ecj/BuilderJavadoc.java index 3afd3be2..f5790ee7 100644 --- a/test/transform/resource/after-ecj/BuilderJavadoc.java +++ b/test/transform/resource/after-ecj/BuilderJavadoc.java @@ -58,7 +58,6 @@ import java.util.List; } /** * getsetwith gets a builder setter, an instance getter and setter, and a wither. - * * @return tag is moved to the getter. */ public @java.lang.SuppressWarnings("all") int getGetsetwith() { diff --git a/test/transform/resource/after-ecj/BuilderSimpleOnRecord.java b/test/transform/resource/after-ecj/BuilderSimpleOnRecord.java new file mode 100644 index 00000000..f866cd35 --- /dev/null +++ b/test/transform/resource/after-ecj/BuilderSimpleOnRecord.java @@ -0,0 +1,41 @@ +// version 14: +import java.util.List; +public @lombok.Builder(access = lombok.AccessLevel.PROTECTED) record BuilderSimpleOnRecord(List l, String a)<T> { + protected static @java.lang.SuppressWarnings("all") class BuilderSimpleOnRecordBuilder<T> { + private @java.lang.SuppressWarnings("all") List<T> l; + private @java.lang.SuppressWarnings("all") String a; + @java.lang.SuppressWarnings("all") BuilderSimpleOnRecordBuilder() { + super(); + } + /** + * @return {@code this}. + */ + public @java.lang.SuppressWarnings("all") BuilderSimpleOnRecord.BuilderSimpleOnRecordBuilder<T> l(final List<T> l) { + this.l = l; + return this; + } + /** + * @return {@code this}. + */ + public @java.lang.SuppressWarnings("all") BuilderSimpleOnRecord.BuilderSimpleOnRecordBuilder<T> a(final String a) { + this.a = a; + return this; + } + public @java.lang.SuppressWarnings("all") BuilderSimpleOnRecord<T> build() { + return new BuilderSimpleOnRecord<T>(this.l, this.a); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (((("BuilderSimpleOnRecord.BuilderSimpleOnRecordBuilder(l=" + this.l) + ", a=") + this.a) + ")"); + } + } +/* Implicit */ private final List<T> l; +/* Implicit */ private final String a; + public BuilderSimpleOnRecord(List<T> l, String a) { + super(); + .l = l; + .a = a; + } + protected static @java.lang.SuppressWarnings("all") <T>BuilderSimpleOnRecord.BuilderSimpleOnRecordBuilder<T> builder() { + return new BuilderSimpleOnRecord.BuilderSimpleOnRecordBuilder<T>(); + } +} diff --git a/test/transform/resource/after-ecj/BuilderSingularNullBehavior2.java b/test/transform/resource/after-ecj/BuilderSingularNullBehavior2.java index cf4bd91b..e1adccb5 100644 --- a/test/transform/resource/after-ecj/BuilderSingularNullBehavior2.java +++ b/test/transform/resource/after-ecj/BuilderSingularNullBehavior2.java @@ -1,3 +1,4 @@ +//version 8: springframework dep is too new to run on j6 import java.util.List; import lombok.Singular; @lombok.Builder class BuilderSingularNullBehavior2 { diff --git a/test/transform/resource/after-ecj/BuilderSingularOnRecord.java b/test/transform/resource/after-ecj/BuilderSingularOnRecord.java new file mode 100644 index 00000000..2db38515 --- /dev/null +++ b/test/transform/resource/after-ecj/BuilderSingularOnRecord.java @@ -0,0 +1,129 @@ +// version 14: +import java.util.Collection; +import java.util.List; +import lombok.Builder; +import lombok.Singular; +public @Builder record BuilderSingularOnRecord(List children, Collection scarves, List rawList)<T> { + public static @java.lang.SuppressWarnings("all") class BuilderSingularOnRecordBuilder<T> { + private @java.lang.SuppressWarnings("all") java.util.ArrayList<T> children; + private @java.lang.SuppressWarnings("all") java.util.ArrayList<Number> scarves; + private @java.lang.SuppressWarnings("all") java.util.ArrayList<java.lang.Object> rawList; + @java.lang.SuppressWarnings("all") BuilderSingularOnRecordBuilder() { + super(); + } + public @java.lang.SuppressWarnings("all") BuilderSingularOnRecord.BuilderSingularOnRecordBuilder<T> child(final T child) { + if ((this.children == null)) + this.children = new java.util.ArrayList<T>(); + this.children.add(child); + return this; + } + public @java.lang.SuppressWarnings("all") BuilderSingularOnRecord.BuilderSingularOnRecordBuilder<T> children(final java.util.Collection<? extends T> children) { + if ((children == null)) + { + throw new java.lang.NullPointerException("children cannot be null"); + } + if ((this.children == null)) + this.children = new java.util.ArrayList<T>(); + this.children.addAll(children); + return this; + } + public @java.lang.SuppressWarnings("all") BuilderSingularOnRecord.BuilderSingularOnRecordBuilder<T> clearChildren() { + if ((this.children != null)) + this.children.clear(); + return this; + } + public @java.lang.SuppressWarnings("all") BuilderSingularOnRecord.BuilderSingularOnRecordBuilder<T> scarf(final Number scarf) { + if ((this.scarves == null)) + this.scarves = new java.util.ArrayList<Number>(); + this.scarves.add(scarf); + return this; + } + public @java.lang.SuppressWarnings("all") BuilderSingularOnRecord.BuilderSingularOnRecordBuilder<T> scarves(final java.util.Collection<? extends Number> scarves) { + if ((scarves == null)) + { + throw new java.lang.NullPointerException("scarves cannot be null"); + } + if ((this.scarves == null)) + this.scarves = new java.util.ArrayList<Number>(); + this.scarves.addAll(scarves); + return this; + } + public @java.lang.SuppressWarnings("all") BuilderSingularOnRecord.BuilderSingularOnRecordBuilder<T> clearScarves() { + if ((this.scarves != null)) + this.scarves.clear(); + return this; + } + public @java.lang.SuppressWarnings("all") BuilderSingularOnRecord.BuilderSingularOnRecordBuilder<T> rawList(final java.lang.Object rawList) { + if ((this.rawList == null)) + this.rawList = new java.util.ArrayList<java.lang.Object>(); + this.rawList.add(rawList); + return this; + } + public @java.lang.SuppressWarnings("all") BuilderSingularOnRecord.BuilderSingularOnRecordBuilder<T> rawList(final java.util.Collection<?> rawList) { + if ((rawList == null)) + { + throw new java.lang.NullPointerException("rawList cannot be null"); + } + if ((this.rawList == null)) + this.rawList = new java.util.ArrayList<java.lang.Object>(); + this.rawList.addAll(rawList); + return this; + } + public @java.lang.SuppressWarnings("all") BuilderSingularOnRecord.BuilderSingularOnRecordBuilder<T> clearRawList() { + if ((this.rawList != null)) + this.rawList.clear(); + return this; + } + public @java.lang.SuppressWarnings("all") BuilderSingularOnRecord<T> build() { + java.util.List<T> children; + switch (((this.children == null) ? 0 : this.children.size())) { + case 0 : + children = java.util.Collections.emptyList(); + break; + case 1 : + children = java.util.Collections.singletonList(this.children.get(0)); + break; + default : + children = java.util.Collections.unmodifiableList(new java.util.ArrayList<T>(this.children)); + } + java.util.Collection<Number> scarves; + switch (((this.scarves == null) ? 0 : this.scarves.size())) { + case 0 : + scarves = java.util.Collections.emptyList(); + break; + case 1 : + scarves = java.util.Collections.singletonList(this.scarves.get(0)); + break; + default : + scarves = java.util.Collections.unmodifiableList(new java.util.ArrayList<Number>(this.scarves)); + } + java.util.List<java.lang.Object> rawList; + switch (((this.rawList == null) ? 0 : this.rawList.size())) { + case 0 : + rawList = java.util.Collections.emptyList(); + break; + case 1 : + rawList = java.util.Collections.singletonList(this.rawList.get(0)); + break; + default : + rawList = java.util.Collections.unmodifiableList(new java.util.ArrayList<java.lang.Object>(this.rawList)); + } + return new BuilderSingularOnRecord<T>(children, scarves, rawList); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (((((("BuilderSingularOnRecord.BuilderSingularOnRecordBuilder(children=" + this.children) + ", scarves=") + this.scarves) + ", rawList=") + this.rawList) + ")"); + } + } +/* Implicit */ private final List<T> children; +/* Implicit */ private final Collection<? extends Number> scarves; +/* Implicit */ private final List rawList; + public BuilderSingularOnRecord(@Singular List<T> children, @Singular Collection<? extends Number> scarves, @SuppressWarnings("all") @Singular("rawList") List rawList) { + super(); + .children = children; + .scarves = scarves; + .rawList = rawList; + } + public static @java.lang.SuppressWarnings("all") <T>BuilderSingularOnRecord.BuilderSingularOnRecordBuilder<T> builder() { + return new BuilderSingularOnRecord.BuilderSingularOnRecordBuilder<T>(); + } +} diff --git a/test/transform/resource/after-ecj/CheckerFrameworkSuperBuilder.java b/test/transform/resource/after-ecj/CheckerFrameworkSuperBuilder.java index 1c552fcc..6236fc72 100644 --- a/test/transform/resource/after-ecj/CheckerFrameworkSuperBuilder.java +++ b/test/transform/resource/after-ecj/CheckerFrameworkSuperBuilder.java @@ -78,7 +78,7 @@ class CheckerFrameworkSuperBuilder { private static @java.lang.SuppressWarnings("all") int $default$x() { return 5; } - protected @java.lang.SuppressWarnings("all") Parent(final CheckerFrameworkSuperBuilder.Parent.ParentBuilder<?, ?> b) { + protected @org.checkerframework.dataflow.qual.SideEffectFree @java.lang.SuppressWarnings("all") Parent(final CheckerFrameworkSuperBuilder.Parent.ParentBuilder<?, ?> b) { super(); if (b.x$set) this.x = b.x$value; @@ -99,7 +99,7 @@ class CheckerFrameworkSuperBuilder { } this.names = names; } - public static @java.lang.SuppressWarnings("all") CheckerFrameworkSuperBuilder.Parent. @org.checkerframework.common.aliasing.qual.Unique ParentBuilder<?, ?> builder() { + public static @org.checkerframework.dataflow.qual.SideEffectFree @java.lang.SuppressWarnings("all") CheckerFrameworkSuperBuilder.Parent. @org.checkerframework.common.aliasing.qual.Unique ParentBuilder<?, ?> builder() { return new CheckerFrameworkSuperBuilder.Parent.ParentBuilderImpl(); } } @@ -148,7 +148,7 @@ class CheckerFrameworkSuperBuilder { private static @java.lang.SuppressWarnings("all") int $default$a() { return 1; } - protected @java.lang.SuppressWarnings("all") ZChild(final CheckerFrameworkSuperBuilder.ZChild.ZChildBuilder<?, ?> b) { + protected @org.checkerframework.dataflow.qual.SideEffectFree @java.lang.SuppressWarnings("all") ZChild(final CheckerFrameworkSuperBuilder.ZChild.ZChildBuilder<?, ?> b) { super(b); if (b.a$set) this.a = b.a$value; @@ -156,7 +156,7 @@ class CheckerFrameworkSuperBuilder { this.a = CheckerFrameworkSuperBuilder.ZChild.$default$a(); this.b = b.b; } - public static @java.lang.SuppressWarnings("all") CheckerFrameworkSuperBuilder.ZChild. @org.checkerframework.common.aliasing.qual.Unique ZChildBuilder<?, ?> builder() { + public static @org.checkerframework.dataflow.qual.SideEffectFree @java.lang.SuppressWarnings("all") CheckerFrameworkSuperBuilder.ZChild. @org.checkerframework.common.aliasing.qual.Unique ZChildBuilder<?, ?> builder() { return new CheckerFrameworkSuperBuilder.ZChild.ZChildBuilderImpl(); } } diff --git a/test/transform/resource/after-ecj/ConstructorsOnRecord.java b/test/transform/resource/after-ecj/ConstructorsOnRecord.java new file mode 100644 index 00000000..f1d4feb4 --- /dev/null +++ b/test/transform/resource/after-ecj/ConstructorsOnRecord.java @@ -0,0 +1,13 @@ +// version 14: +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; +import lombok.RequiredArgsConstructor; +public @AllArgsConstructor @RequiredArgsConstructor @NoArgsConstructor record ConstructorsOnRecord(String a, String b) { +/* Implicit */ private final String a; +/* Implicit */ private final String b; + public ConstructorsOnRecord(String a, String b) { + super(); + .a = a; + .b = b; + } +} diff --git a/test/transform/resource/after-ecj/DataOnRecord.java b/test/transform/resource/after-ecj/DataOnRecord.java new file mode 100644 index 00000000..64ee28a2 --- /dev/null +++ b/test/transform/resource/after-ecj/DataOnRecord.java @@ -0,0 +1,11 @@ +// version 14: +import lombok.Data; +public @Data record DataOnRecord(String a, String b) { +/* Implicit */ private final String a; +/* Implicit */ private final String b; + public DataOnRecord(String a, String b) { + super(); + .a = a; + .b = b; + } +} diff --git a/test/transform/resource/after-ecj/DataWithOverrideEqualsAndHashCode.java b/test/transform/resource/after-ecj/DataWithOverrideEqualsAndHashCode.java new file mode 100644 index 00000000..2149321f --- /dev/null +++ b/test/transform/resource/after-ecj/DataWithOverrideEqualsAndHashCode.java @@ -0,0 +1,25 @@ +import lombok.Data; +class DataWithOverrideEqualsAndHashCode { + class Data1 { + Data1() { + super(); + } + } + @Data class Data2 extends Data1 { + public int hashCode() { + return 42; + } + public boolean equals(Object other) { + return false; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return "DataWithOverrideEqualsAndHashCode.Data2()"; + } + public @java.lang.SuppressWarnings("all") Data2() { + super(); + } + } + DataWithOverrideEqualsAndHashCode() { + super(); + } +} diff --git a/test/transform/resource/after-ecj/EqualsAndHashCodeOnRecord.java b/test/transform/resource/after-ecj/EqualsAndHashCodeOnRecord.java new file mode 100644 index 00000000..583191e6 --- /dev/null +++ b/test/transform/resource/after-ecj/EqualsAndHashCodeOnRecord.java @@ -0,0 +1,11 @@ +// version 14: +import lombok.EqualsAndHashCode; +public @EqualsAndHashCode record EqualsAndHashCodeOnRecord(String a, String b) { +/* Implicit */ private final String a; +/* Implicit */ private final String b; + public EqualsAndHashCodeOnRecord(String a, String b) { + super(); + .a = a; + .b = b; + } +} diff --git a/test/transform/resource/after-ecj/ExtensionMethodChain.java b/test/transform/resource/after-ecj/ExtensionMethodChain.java new file mode 100644 index 00000000..8eda4bf8 --- /dev/null +++ b/test/transform/resource/after-ecj/ExtensionMethodChain.java @@ -0,0 +1,19 @@ +import java.util.Arrays; +import java.util.List; +import lombok.experimental.ExtensionMethod; +@ExtensionMethod(ExtensionMethodChain.Extensions.class) class ExtensionMethodChain { + static class Extensions { + Extensions() { + super(); + } + public static Integer intValue(String s) { + return Integer.valueOf(s); + } + } + ExtensionMethodChain() { + super(); + } + public void test() { + ExtensionMethodChain.Extensions.intValue("1").intValue(); + } +}
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/ExtensionMethodFunctional.java b/test/transform/resource/after-ecj/ExtensionMethodFunctional.java index e847c1f0..0971a9be 100644 --- a/test/transform/resource/after-ecj/ExtensionMethodFunctional.java +++ b/test/transform/resource/after-ecj/ExtensionMethodFunctional.java @@ -21,7 +21,7 @@ import lombok.experimental.ExtensionMethod; consumer[i].accept(o); } } - public static <T>List<T> toList(Stream<T> stream) { + public static <T>List<T> toList1(Stream<T> stream) { return (List<T>) stream.collect(Collectors.toList()); } public static <T, U>List<U> toList2(Stream<T> stream) { @@ -36,7 +36,7 @@ import lombok.experimental.ExtensionMethod; test = ExtensionMethodFunctional.Extensions.map(test, (<no type> s) -> ExtensionMethodFunctional.Extensions.reverse(s)); ExtensionMethodFunctional.Extensions.consume(test, (<no type> s) -> System.out.println(("1: " + s)), (<no type> s) -> System.out.println(("2: " + s))); ExtensionMethodFunctional.Extensions.consume(test, System.out::println, System.out::println); - ExtensionMethodFunctional.Extensions.toList(Stream.of("a", "b", "c").map(String::toUpperCase)); + ExtensionMethodFunctional.Extensions.toList1(Stream.of("a", "b", "c").map(String::toUpperCase)); List<Integer> i2 = ExtensionMethodFunctional.Extensions.toList2(Stream.of("a", "b", "c").map(String::toUpperCase)); } } diff --git a/test/transform/resource/after-ecj/ExtensionMethodNonStaticAccess.java b/test/transform/resource/after-ecj/ExtensionMethodNonStaticAccess.java new file mode 100644 index 00000000..c930a329 --- /dev/null +++ b/test/transform/resource/after-ecj/ExtensionMethodNonStaticAccess.java @@ -0,0 +1,22 @@ +class ExtensionMethodNonStaticAccess { + ExtensionMethodNonStaticAccess() { + super(); + } + public void method() { + Derived derived = new Derived(); + derived.staticMethod(); + } +} +class Base { + Base() { + super(); + } + static String staticMethod() { + return ""; + } +} +class Derived extends Base { + Derived() { + super(); + } +} diff --git a/test/transform/resource/after-ecj/FieldDefaultsOnRecord.java b/test/transform/resource/after-ecj/FieldDefaultsOnRecord.java new file mode 100644 index 00000000..cc1a23b3 --- /dev/null +++ b/test/transform/resource/after-ecj/FieldDefaultsOnRecord.java @@ -0,0 +1,10 @@ +// version 14: +public @lombok.experimental.FieldDefaults(makeFinal = true) record FieldDefaultsOnRecord(String a, String b) { +/* Implicit */ private final String a; +/* Implicit */ private final String b; + public FieldDefaultsOnRecord(String a, String b) { + super(); + .a = a; + .b = b; + } +} diff --git a/test/transform/resource/after-ecj/FieldNameConstantsOnRecord.java b/test/transform/resource/after-ecj/FieldNameConstantsOnRecord.java new file mode 100644 index 00000000..5d3b01da --- /dev/null +++ b/test/transform/resource/after-ecj/FieldNameConstantsOnRecord.java @@ -0,0 +1,28 @@ +// version 14: +import lombok.experimental.FieldNameConstants; +import lombok.AccessLevel; +public @FieldNameConstants(level = AccessLevel.PACKAGE) record FieldNameConstantsOnRecord(String iAmADvdPlayer, int $skipMe, int andMe, String butPrintMePlease) { + static final @java.lang.SuppressWarnings("all") class Fields { + public static final java.lang.String iAmADvdPlayer = "iAmADvdPlayer"; + public static final java.lang.String butPrintMePlease = "butPrintMePlease"; + <clinit>() { + } + private @java.lang.SuppressWarnings("all") Fields() { + super(); + } + } +/* Implicit */ private final String iAmADvdPlayer; +/* Implicit */ private final int $skipMe; +/* Implicit */ private final int andMe; +/* Implicit */ private final String butPrintMePlease; + static double skipMeToo; + <clinit>() { + } + public FieldNameConstantsOnRecord(String iAmADvdPlayer, int $skipMe, int andMe, String butPrintMePlease) { + super(); + .iAmADvdPlayer = iAmADvdPlayer; + .$skipMe = $skipMe; + .andMe = andMe; + .butPrintMePlease = butPrintMePlease; + } +} diff --git a/test/transform/resource/after-ecj/GetterOnRecord.java b/test/transform/resource/after-ecj/GetterOnRecord.java new file mode 100644 index 00000000..8ce516bf --- /dev/null +++ b/test/transform/resource/after-ecj/GetterOnRecord.java @@ -0,0 +1,11 @@ +// version 14: +import lombok.Getter; +public @Getter record GetterOnRecord(String a, String b) { +/* Implicit */ private final String a; +/* Implicit */ private final String b; + public GetterOnRecord(String a, String b) { + super(); + .a = a; + .b = b; + } +} diff --git a/test/transform/resource/after-ecj/JavadocMultiline.java b/test/transform/resource/after-ecj/JavadocMultiline.java new file mode 100644 index 00000000..bf058975 --- /dev/null +++ b/test/transform/resource/after-ecj/JavadocMultiline.java @@ -0,0 +1,40 @@ +@lombok.Getter @lombok.Setter class JavadocMultiline { + private java.util.List<Boolean> booleans; + private java.util.List<Boolean> booleans2; + JavadocMultiline() { + super(); + } + /** + * This is a list of booleans. + * + * @return A list of booleans to set for this object. This is a Javadoc return that is long + * enough to wrap to multiple lines. + */ + public @java.lang.SuppressWarnings("all") java.util.List<Boolean> getBooleans() { + return this.booleans; + } + /** + * This is a list of booleans. + */ + public @java.lang.SuppressWarnings("all") java.util.List<Boolean> getBooleans2() { + return this.booleans2; + } + /** + * This is a list of booleans. + * + * @param booleans A list of booleans to set for this object. This is a Javadoc param that is + * long enough to wrap to multiple lines. + */ + public @java.lang.SuppressWarnings("all") void setBooleans(final java.util.List<Boolean> booleans) { + this.booleans = booleans; + } + /** + * This is a list of booleans. + * + * @param booleans A list of booleans to set for this object. This is a Javadoc param that is + * long enough to wrap to multiple lines. + */ + public @java.lang.SuppressWarnings("all") void setBooleans2(final java.util.List<Boolean> booleans2) { + this.booleans2 = booleans2; + } +} diff --git a/test/transform/resource/after-ecj/LoggerConfigOnRecord.java b/test/transform/resource/after-ecj/LoggerConfigOnRecord.java new file mode 100644 index 00000000..3e12cbff --- /dev/null +++ b/test/transform/resource/after-ecj/LoggerConfigOnRecord.java @@ -0,0 +1,11 @@ +// version 14: +import lombok.extern.slf4j.Slf4j; +public @Slf4j record LoggerConfigOnRecord(String a, String b) { +/* Implicit */ private final String a; +/* Implicit */ private final String b; + public LoggerConfigOnRecord(String a, String b) { + super(); + .a = a; + .b = b; + } +} diff --git a/test/transform/resource/after-ecj/LoggerSlf4jInvalidTopic.java b/test/transform/resource/after-ecj/LoggerSlf4jInvalidTopic.java deleted file mode 100644 index 33e212e3..00000000 --- a/test/transform/resource/after-ecj/LoggerSlf4jInvalidTopic.java +++ /dev/null @@ -1,9 +0,0 @@ -import lombok.extern.slf4j.Slf4j; -@Slf4j(topic = 42) class LoggerSlf4jWithIntegerTopic { - private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(42); - <clinit>() { - } - LoggerSlf4jWithIntegerTopic() { - super(); - } -}
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/LoggerSlf4jOnRecord.java b/test/transform/resource/after-ecj/LoggerSlf4jOnRecord.java new file mode 100644 index 00000000..673f83a3 --- /dev/null +++ b/test/transform/resource/after-ecj/LoggerSlf4jOnRecord.java @@ -0,0 +1,14 @@ +// version 14: +import lombok.extern.slf4j.Slf4j; +public @Slf4j record LoggerSlf4jOnRecord(org log, String a) { + private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LoggerSlf4jOnRecord.class); +/* Implicit */ private final String a; +/* Implicit */ private final String b; + <clinit>() { + } + public LoggerSlf4jOnRecord(String a, String b) { + super(); + .a = a; + .b = b; + } +} diff --git a/test/transform/resource/after-ecj/NonNullExistingConstructorOnRecord.java b/test/transform/resource/after-ecj/NonNullExistingConstructorOnRecord.java new file mode 100644 index 00000000..6f351854 --- /dev/null +++ b/test/transform/resource/after-ecj/NonNullExistingConstructorOnRecord.java @@ -0,0 +1,26 @@ +// version 14: +import lombok.NonNull; +public record NonNullExistingConstructorOnRecord(String a, String b) { +/* Implicit */ private final String a; +/* Implicit */ private final String b; + public NonNullExistingConstructorOnRecord(@NonNull String b) { + this("default", b); + if ((b == null)) + { + throw new java.lang.NullPointerException("b is marked non-null but is null"); + } + } + public @java.lang.SuppressWarnings("all") NonNullExistingConstructorOnRecord(@NonNull String a, @NonNull String b) { + super(); + if ((a == null)) + { + throw new java.lang.NullPointerException("a is marked non-null but is null"); + } + if ((b == null)) + { + throw new java.lang.NullPointerException("b is marked non-null but is null"); + } + this.a = a; + this.b = b; + } +} diff --git a/test/transform/resource/after-ecj/NonNullOnRecord.java b/test/transform/resource/after-ecj/NonNullOnRecord.java new file mode 100644 index 00000000..d80e243b --- /dev/null +++ b/test/transform/resource/after-ecj/NonNullOnRecord.java @@ -0,0 +1,19 @@ +// version 14: +import lombok.NonNull; +public record NonNullOnRecord(String a, String b) { +/* Implicit */ private final String a; +/* Implicit */ private final String b; + public @java.lang.SuppressWarnings("all") NonNullOnRecord(@NonNull String a, @NonNull String b) { + super(); + if ((a == null)) + { + throw new java.lang.NullPointerException("a is marked non-null but is null"); + } + if ((b == null)) + { + throw new java.lang.NullPointerException("b is marked non-null but is null"); + } + this.a = a; + this.b = b; + } +} diff --git a/test/transform/resource/after-ecj/NonNullOnRecord2.java b/test/transform/resource/after-ecj/NonNullOnRecord2.java new file mode 100644 index 00000000..5820d453 --- /dev/null +++ b/test/transform/resource/after-ecj/NonNullOnRecord2.java @@ -0,0 +1,14 @@ +// version 14: +import lombok.NonNull; +record NonNullOnRecord2(String a) { +/* Implicit */ private final String a; + public NonNullOnRecord2(@NonNull String a) { + super(); + if ((a == null)) + { + throw new java.lang.NullPointerException("a is marked non-null but is null"); + } + System.out.println("Hello"); + this.a = a; + } +} diff --git a/test/transform/resource/after-ecj/NonNullOnRecord3.java b/test/transform/resource/after-ecj/NonNullOnRecord3.java new file mode 100644 index 00000000..44c00098 --- /dev/null +++ b/test/transform/resource/after-ecj/NonNullOnRecord3.java @@ -0,0 +1,20 @@ +// version 14: +import lombok.NonNull; +public record NonNullOnRecord3(String a) { +/* Implicit */ private final String a; + public NonNullOnRecord3(String a) { + super(); + .a = a; + } + public NonNullOnRecord3(String a) { + super(); + this.a = a; + } + public void method(@NonNull String param) { + if ((param == null)) + { + throw new java.lang.NullPointerException("param is marked non-null but is null"); + } + String asd = "a"; + } +} diff --git a/test/transform/resource/after-ecj/NullAnnotatedCheckerFrameworkSuperBuilder.java b/test/transform/resource/after-ecj/NullAnnotatedCheckerFrameworkSuperBuilder.java new file mode 100644 index 00000000..94b708d2 --- /dev/null +++ b/test/transform/resource/after-ecj/NullAnnotatedCheckerFrameworkSuperBuilder.java @@ -0,0 +1,166 @@ +import java.util.List; +import lombok.Singular; +class NullAnnotatedCheckerFrameworkSuperBuilder { + public static @lombok.experimental.SuperBuilder class Parent { + public static abstract @java.lang.SuppressWarnings("all") class ParentBuilder<C extends NullAnnotatedCheckerFrameworkSuperBuilder.Parent, B extends NullAnnotatedCheckerFrameworkSuperBuilder.Parent.ParentBuilder<C, B>> { + private @java.lang.SuppressWarnings("all") int x$value; + private @java.lang.SuppressWarnings("all") boolean x$set; + private @java.lang.SuppressWarnings("all") int y; + private @java.lang.SuppressWarnings("all") int z; + private @java.lang.SuppressWarnings("all") java.util.ArrayList<String> names; + public ParentBuilder() { + super(); + } + protected abstract @java.lang.SuppressWarnings("all") B self(); + public abstract @java.lang.SuppressWarnings("all") C build(); + /** + * @return {@code this}. + */ + public @org.checkerframework.checker.nullness.qual.NonNull @java.lang.SuppressWarnings("all") B x(final int x) { + this.x$value = x; + x$set = true; + return self(); + } + /** + * @return {@code this}. + */ + public @org.checkerframework.checker.nullness.qual.NonNull @java.lang.SuppressWarnings("all") B y(final int y) { + this.y = y; + return self(); + } + /** + * @return {@code this}. + */ + public @org.checkerframework.checker.nullness.qual.NonNull @java.lang.SuppressWarnings("all") B z(final int z) { + this.z = z; + return self(); + } + public @org.checkerframework.checker.nullness.qual.NonNull @java.lang.SuppressWarnings("all") B name(final String name) { + if ((this.names == null)) + this.names = new java.util.ArrayList<String>(); + this.names.add(name); + return self(); + } + public @org.checkerframework.checker.nullness.qual.NonNull @java.lang.SuppressWarnings("all") B names(final java.util. @org.checkerframework.checker.nullness.qual.NonNull Collection<? extends String> names) { + if ((names == null)) + { + throw new java.lang.NullPointerException("names cannot be null"); + } + if ((this.names == null)) + this.names = new java.util.ArrayList<String>(); + this.names.addAll(names); + return self(); + } + public @org.checkerframework.checker.nullness.qual.NonNull @java.lang.SuppressWarnings("all") B clearNames() { + if ((this.names != null)) + this.names.clear(); + return self(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.@org.checkerframework.checker.nullness.qual.NonNull String toString() { + return (((((((("NullAnnotatedCheckerFrameworkSuperBuilder.Parent.ParentBuilder(x$value=" + this.x$value) + ", y=") + this.y) + ", z=") + this.z) + ", names=") + this.names) + ")"); + } + } + private static final @java.lang.SuppressWarnings("all") class ParentBuilderImpl extends NullAnnotatedCheckerFrameworkSuperBuilder.Parent.ParentBuilder<NullAnnotatedCheckerFrameworkSuperBuilder.Parent, NullAnnotatedCheckerFrameworkSuperBuilder.Parent.ParentBuilderImpl> { + private ParentBuilderImpl() { + super(); + } + protected @java.lang.Override @java.lang.SuppressWarnings("all") NullAnnotatedCheckerFrameworkSuperBuilder.Parent.ParentBuilderImpl self() { + return this; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") NullAnnotatedCheckerFrameworkSuperBuilder.@org.checkerframework.checker.nullness.qual.NonNull Parent build() { + return new NullAnnotatedCheckerFrameworkSuperBuilder.Parent(this); + } + } + @lombok.Builder.Default int x; + int y; + int z; + @Singular List<String> names; + private static @java.lang.SuppressWarnings("all") int $default$x() { + return 5; + } + protected @java.lang.SuppressWarnings("all") Parent(final NullAnnotatedCheckerFrameworkSuperBuilder.Parent.ParentBuilder<?, ?> b) { + super(); + if (b.x$set) + this.x = b.x$value; + else + this.x = NullAnnotatedCheckerFrameworkSuperBuilder.Parent.$default$x(); + this.y = b.y; + this.z = b.z; + java.util.List<String> names; + switch (((b.names == null) ? 0 : b.names.size())) { + case 0 : + names = java.util.Collections.emptyList(); + break; + case 1 : + names = java.util.Collections.singletonList(b.names.get(0)); + break; + default : + names = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(b.names)); + } + this.names = names; + } + public static @java.lang.SuppressWarnings("all") NullAnnotatedCheckerFrameworkSuperBuilder.Parent. @org.checkerframework.checker.nullness.qual.NonNull ParentBuilder<?, ?> builder() { + return new NullAnnotatedCheckerFrameworkSuperBuilder.Parent.ParentBuilderImpl(); + } + } + public static @lombok.experimental.SuperBuilder class ZChild extends Parent { + public static abstract @java.lang.SuppressWarnings("all") class ZChildBuilder<C extends NullAnnotatedCheckerFrameworkSuperBuilder.ZChild, B extends NullAnnotatedCheckerFrameworkSuperBuilder.ZChild.ZChildBuilder<C, B>> extends Parent.ParentBuilder<C, B> { + private @java.lang.SuppressWarnings("all") int a$value; + private @java.lang.SuppressWarnings("all") boolean a$set; + private @java.lang.SuppressWarnings("all") int b; + public ZChildBuilder() { + super(); + } + protected abstract @java.lang.Override @java.lang.SuppressWarnings("all") B self(); + public abstract @java.lang.Override @java.lang.SuppressWarnings("all") C build(); + /** + * @return {@code this}. + */ + public @org.checkerframework.checker.nullness.qual.NonNull @java.lang.SuppressWarnings("all") B a(final int a) { + this.a$value = a; + a$set = true; + return self(); + } + /** + * @return {@code this}. + */ + public @org.checkerframework.checker.nullness.qual.NonNull @java.lang.SuppressWarnings("all") B b(final int b) { + this.b = b; + return self(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.@org.checkerframework.checker.nullness.qual.NonNull String toString() { + return (((((("NullAnnotatedCheckerFrameworkSuperBuilder.ZChild.ZChildBuilder(super=" + super.toString()) + ", a$value=") + this.a$value) + ", b=") + this.b) + ")"); + } + } + private static final @java.lang.SuppressWarnings("all") class ZChildBuilderImpl extends NullAnnotatedCheckerFrameworkSuperBuilder.ZChild.ZChildBuilder<NullAnnotatedCheckerFrameworkSuperBuilder.ZChild, NullAnnotatedCheckerFrameworkSuperBuilder.ZChild.ZChildBuilderImpl> { + private ZChildBuilderImpl() { + super(); + } + protected @java.lang.Override @java.lang.SuppressWarnings("all") NullAnnotatedCheckerFrameworkSuperBuilder.ZChild.ZChildBuilderImpl self() { + return this; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") NullAnnotatedCheckerFrameworkSuperBuilder.@org.checkerframework.checker.nullness.qual.NonNull ZChild build() { + return new NullAnnotatedCheckerFrameworkSuperBuilder.ZChild(this); + } + } + @lombok.Builder.Default int a; + int b; + private static @java.lang.SuppressWarnings("all") int $default$a() { + return 1; + } + protected @java.lang.SuppressWarnings("all") ZChild(final NullAnnotatedCheckerFrameworkSuperBuilder.ZChild.ZChildBuilder<?, ?> b) { + super(b); + if (b.a$set) + this.a = b.a$value; + else + this.a = NullAnnotatedCheckerFrameworkSuperBuilder.ZChild.$default$a(); + this.b = b.b; + } + public static @java.lang.SuppressWarnings("all") NullAnnotatedCheckerFrameworkSuperBuilder.ZChild. @org.checkerframework.checker.nullness.qual.NonNull ZChildBuilder<?, ?> builder() { + return new NullAnnotatedCheckerFrameworkSuperBuilder.ZChild.ZChildBuilderImpl(); + } + } + NullAnnotatedCheckerFrameworkSuperBuilder() { + super(); + } +}
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/SetterOnRecord.java b/test/transform/resource/after-ecj/SetterOnRecord.java new file mode 100644 index 00000000..e65eb1bd --- /dev/null +++ b/test/transform/resource/after-ecj/SetterOnRecord.java @@ -0,0 +1,11 @@ +// version 14: +import lombok.Setter; +public @Setter record SetterOnRecord(String a, String b) { +/* Implicit */ private final String a; +/* Implicit */ private final String b; + public SetterOnRecord(String a, String b) { + super(); + .a = a; + .b = b; + } +} diff --git a/test/transform/resource/after-ecj/SuperBuilderAbstract.java b/test/transform/resource/after-ecj/SuperBuilderAbstract.java index 88406272..2fef9451 100644 --- a/test/transform/resource/after-ecj/SuperBuilderAbstract.java +++ b/test/transform/resource/after-ecj/SuperBuilderAbstract.java @@ -1,111 +1,111 @@ -public class SuperBuilderAbstract {
- public static @lombok.experimental.SuperBuilder class Parent {
- public static abstract @java.lang.SuppressWarnings("all") class ParentBuilder<C extends SuperBuilderAbstract.Parent, B extends SuperBuilderAbstract.Parent.ParentBuilder<C, B>> {
- private @java.lang.SuppressWarnings("all") int parentField;
- public ParentBuilder() {
- super();
- }
- protected abstract @java.lang.SuppressWarnings("all") B self();
- public abstract @java.lang.SuppressWarnings("all") C build();
- /**
- * @return {@code this}.
- */
- public @java.lang.SuppressWarnings("all") B parentField(final int parentField) {
- this.parentField = parentField;
- return self();
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
- return (("SuperBuilderAbstract.Parent.ParentBuilder(parentField=" + this.parentField) + ")");
- }
- }
- private static final @java.lang.SuppressWarnings("all") class ParentBuilderImpl extends SuperBuilderAbstract.Parent.ParentBuilder<SuperBuilderAbstract.Parent, SuperBuilderAbstract.Parent.ParentBuilderImpl> {
- private ParentBuilderImpl() {
- super();
- }
- protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderAbstract.Parent.ParentBuilderImpl self() {
- return this;
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderAbstract.Parent build() {
- return new SuperBuilderAbstract.Parent(this);
- }
- }
- int parentField;
- protected @java.lang.SuppressWarnings("all") Parent(final SuperBuilderAbstract.Parent.ParentBuilder<?, ?> b) {
- super();
- this.parentField = b.parentField;
- }
- public static @java.lang.SuppressWarnings("all") SuperBuilderAbstract.Parent.ParentBuilder<?, ?> builder() {
- return new SuperBuilderAbstract.Parent.ParentBuilderImpl();
- }
- }
- public static abstract @lombok.experimental.SuperBuilder class Child extends Parent {
- public static abstract @java.lang.SuppressWarnings("all") class ChildBuilder<C extends SuperBuilderAbstract.Child, B extends SuperBuilderAbstract.Child.ChildBuilder<C, B>> extends Parent.ParentBuilder<C, B> {
- private @java.lang.SuppressWarnings("all") double childField;
- public ChildBuilder() {
- super();
- }
- protected abstract @java.lang.Override @java.lang.SuppressWarnings("all") B self();
- public abstract @java.lang.Override @java.lang.SuppressWarnings("all") C build();
- /**
- * @return {@code this}.
- */
- public @java.lang.SuppressWarnings("all") B childField(final double childField) {
- this.childField = childField;
- return self();
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
- return (((("SuperBuilderAbstract.Child.ChildBuilder(super=" + super.toString()) + ", childField=") + this.childField) + ")");
- }
- }
- double childField;
- protected @java.lang.SuppressWarnings("all") Child(final SuperBuilderAbstract.Child.ChildBuilder<?, ?> b) {
- super(b);
- this.childField = b.childField;
- }
- }
- public static @lombok.experimental.SuperBuilder class GrandChild extends Child {
- public static abstract @java.lang.SuppressWarnings("all") class GrandChildBuilder<C extends SuperBuilderAbstract.GrandChild, B extends SuperBuilderAbstract.GrandChild.GrandChildBuilder<C, B>> extends Child.ChildBuilder<C, B> {
- private @java.lang.SuppressWarnings("all") String grandChildField;
- public GrandChildBuilder() {
- super();
- }
- protected abstract @java.lang.Override @java.lang.SuppressWarnings("all") B self();
- public abstract @java.lang.Override @java.lang.SuppressWarnings("all") C build();
- /**
- * @return {@code this}.
- */
- public @java.lang.SuppressWarnings("all") B grandChildField(final String grandChildField) {
- this.grandChildField = grandChildField;
- return self();
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
- return (((("SuperBuilderAbstract.GrandChild.GrandChildBuilder(super=" + super.toString()) + ", grandChildField=") + this.grandChildField) + ")");
- }
- }
- private static final @java.lang.SuppressWarnings("all") class GrandChildBuilderImpl extends SuperBuilderAbstract.GrandChild.GrandChildBuilder<SuperBuilderAbstract.GrandChild, SuperBuilderAbstract.GrandChild.GrandChildBuilderImpl> {
- private GrandChildBuilderImpl() {
- super();
- }
- protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderAbstract.GrandChild.GrandChildBuilderImpl self() {
- return this;
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderAbstract.GrandChild build() {
- return new SuperBuilderAbstract.GrandChild(this);
- }
- }
- String grandChildField;
- protected @java.lang.SuppressWarnings("all") GrandChild(final SuperBuilderAbstract.GrandChild.GrandChildBuilder<?, ?> b) {
- super(b);
- this.grandChildField = b.grandChildField;
- }
- public static @java.lang.SuppressWarnings("all") SuperBuilderAbstract.GrandChild.GrandChildBuilder<?, ?> builder() {
- return new SuperBuilderAbstract.GrandChild.GrandChildBuilderImpl();
- }
- }
- public SuperBuilderAbstract() {
- super();
- }
- public static void test() {
- GrandChild x = GrandChild.builder().grandChildField("").parentField(5).childField(2.5).build();
- }
-}
+public class SuperBuilderAbstract { + public static @lombok.experimental.SuperBuilder class Parent { + public static abstract @java.lang.SuppressWarnings("all") class ParentBuilder<C extends SuperBuilderAbstract.Parent, B extends SuperBuilderAbstract.Parent.ParentBuilder<C, B>> { + private @java.lang.SuppressWarnings("all") int parentField; + public ParentBuilder() { + super(); + } + protected abstract @java.lang.SuppressWarnings("all") B self(); + public abstract @java.lang.SuppressWarnings("all") C build(); + /** + * @return {@code this}. + */ + public @java.lang.SuppressWarnings("all") B parentField(final int parentField) { + this.parentField = parentField; + return self(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (("SuperBuilderAbstract.Parent.ParentBuilder(parentField=" + this.parentField) + ")"); + } + } + private static final @java.lang.SuppressWarnings("all") class ParentBuilderImpl extends SuperBuilderAbstract.Parent.ParentBuilder<SuperBuilderAbstract.Parent, SuperBuilderAbstract.Parent.ParentBuilderImpl> { + private ParentBuilderImpl() { + super(); + } + protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderAbstract.Parent.ParentBuilderImpl self() { + return this; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderAbstract.Parent build() { + return new SuperBuilderAbstract.Parent(this); + } + } + int parentField; + protected @java.lang.SuppressWarnings("all") Parent(final SuperBuilderAbstract.Parent.ParentBuilder<?, ?> b) { + super(); + this.parentField = b.parentField; + } + public static @java.lang.SuppressWarnings("all") SuperBuilderAbstract.Parent.ParentBuilder<?, ?> builder() { + return new SuperBuilderAbstract.Parent.ParentBuilderImpl(); + } + } + public static abstract @lombok.experimental.SuperBuilder class Child extends Parent { + public static abstract @java.lang.SuppressWarnings("all") class ChildBuilder<C extends SuperBuilderAbstract.Child, B extends SuperBuilderAbstract.Child.ChildBuilder<C, B>> extends Parent.ParentBuilder<C, B> { + private @java.lang.SuppressWarnings("all") double childField; + public ChildBuilder() { + super(); + } + protected abstract @java.lang.Override @java.lang.SuppressWarnings("all") B self(); + public abstract @java.lang.Override @java.lang.SuppressWarnings("all") C build(); + /** + * @return {@code this}. + */ + public @java.lang.SuppressWarnings("all") B childField(final double childField) { + this.childField = childField; + return self(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (((("SuperBuilderAbstract.Child.ChildBuilder(super=" + super.toString()) + ", childField=") + this.childField) + ")"); + } + } + double childField; + protected @java.lang.SuppressWarnings("all") Child(final SuperBuilderAbstract.Child.ChildBuilder<?, ?> b) { + super(b); + this.childField = b.childField; + } + } + public static @lombok.experimental.SuperBuilder class GrandChild extends Child { + public static abstract @java.lang.SuppressWarnings("all") class GrandChildBuilder<C extends SuperBuilderAbstract.GrandChild, B extends SuperBuilderAbstract.GrandChild.GrandChildBuilder<C, B>> extends Child.ChildBuilder<C, B> { + private @java.lang.SuppressWarnings("all") String grandChildField; + public GrandChildBuilder() { + super(); + } + protected abstract @java.lang.Override @java.lang.SuppressWarnings("all") B self(); + public abstract @java.lang.Override @java.lang.SuppressWarnings("all") C build(); + /** + * @return {@code this}. + */ + public @java.lang.SuppressWarnings("all") B grandChildField(final String grandChildField) { + this.grandChildField = grandChildField; + return self(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (((("SuperBuilderAbstract.GrandChild.GrandChildBuilder(super=" + super.toString()) + ", grandChildField=") + this.grandChildField) + ")"); + } + } + private static final @java.lang.SuppressWarnings("all") class GrandChildBuilderImpl extends SuperBuilderAbstract.GrandChild.GrandChildBuilder<SuperBuilderAbstract.GrandChild, SuperBuilderAbstract.GrandChild.GrandChildBuilderImpl> { + private GrandChildBuilderImpl() { + super(); + } + protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderAbstract.GrandChild.GrandChildBuilderImpl self() { + return this; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderAbstract.GrandChild build() { + return new SuperBuilderAbstract.GrandChild(this); + } + } + String grandChildField; + protected @java.lang.SuppressWarnings("all") GrandChild(final SuperBuilderAbstract.GrandChild.GrandChildBuilder<?, ?> b) { + super(b); + this.grandChildField = b.grandChildField; + } + public static @java.lang.SuppressWarnings("all") SuperBuilderAbstract.GrandChild.GrandChildBuilder<?, ?> builder() { + return new SuperBuilderAbstract.GrandChild.GrandChildBuilderImpl(); + } + } + public SuperBuilderAbstract() { + super(); + } + public static void test() { + GrandChild x = GrandChild.builder().grandChildField("").parentField(5).childField(2.5).build(); + } +} diff --git a/test/transform/resource/after-ecj/SuperBuilderAbstractToBuilder.java b/test/transform/resource/after-ecj/SuperBuilderAbstractToBuilder.java index d1ce4fa9..2d2cd422 100644 --- a/test/transform/resource/after-ecj/SuperBuilderAbstractToBuilder.java +++ b/test/transform/resource/after-ecj/SuperBuilderAbstractToBuilder.java @@ -1,140 +1,140 @@ -public class SuperBuilderAbstractToBuilder {
- public static @lombok.experimental.SuperBuilder(toBuilder = true) class Parent {
- public static abstract @java.lang.SuppressWarnings("all") class ParentBuilder<C extends SuperBuilderAbstractToBuilder.Parent, B extends SuperBuilderAbstractToBuilder.Parent.ParentBuilder<C, B>> {
- private @java.lang.SuppressWarnings("all") int parentField;
- public ParentBuilder() {
- super();
- }
- protected @java.lang.SuppressWarnings("all") B $fillValuesFrom(final C instance) {
- SuperBuilderAbstractToBuilder.Parent.ParentBuilder.$fillValuesFromInstanceIntoBuilder(instance, this);
- return self();
- }
- private static @java.lang.SuppressWarnings("all") void $fillValuesFromInstanceIntoBuilder(final SuperBuilderAbstractToBuilder.Parent instance, final SuperBuilderAbstractToBuilder.Parent.ParentBuilder<?, ?> b) {
- b.parentField(instance.parentField);
- }
- protected abstract @java.lang.SuppressWarnings("all") B self();
- public abstract @java.lang.SuppressWarnings("all") C build();
- /**
- * @return {@code this}.
- */
- public @java.lang.SuppressWarnings("all") B parentField(final int parentField) {
- this.parentField = parentField;
- return self();
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
- return (("SuperBuilderAbstractToBuilder.Parent.ParentBuilder(parentField=" + this.parentField) + ")");
- }
- }
- private static final @java.lang.SuppressWarnings("all") class ParentBuilderImpl extends SuperBuilderAbstractToBuilder.Parent.ParentBuilder<SuperBuilderAbstractToBuilder.Parent, SuperBuilderAbstractToBuilder.Parent.ParentBuilderImpl> {
- private ParentBuilderImpl() {
- super();
- }
- protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderAbstractToBuilder.Parent.ParentBuilderImpl self() {
- return this;
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderAbstractToBuilder.Parent build() {
- return new SuperBuilderAbstractToBuilder.Parent(this);
- }
- }
- int parentField;
- protected @java.lang.SuppressWarnings("all") Parent(final SuperBuilderAbstractToBuilder.Parent.ParentBuilder<?, ?> b) {
- super();
- this.parentField = b.parentField;
- }
- public @java.lang.SuppressWarnings("all") SuperBuilderAbstractToBuilder.Parent.ParentBuilder<?, ?> toBuilder() {
- return new SuperBuilderAbstractToBuilder.Parent.ParentBuilderImpl().$fillValuesFrom(this);
- }
- public static @java.lang.SuppressWarnings("all") SuperBuilderAbstractToBuilder.Parent.ParentBuilder<?, ?> builder() {
- return new SuperBuilderAbstractToBuilder.Parent.ParentBuilderImpl();
- }
- }
- public static abstract @lombok.experimental.SuperBuilder(toBuilder = true) class Child extends Parent {
- public static abstract @java.lang.SuppressWarnings("all") class ChildBuilder<C extends SuperBuilderAbstractToBuilder.Child, B extends SuperBuilderAbstractToBuilder.Child.ChildBuilder<C, B>> extends Parent.ParentBuilder<C, B> {
- private @java.lang.SuppressWarnings("all") double childField;
- public ChildBuilder() {
- super();
- }
- protected @java.lang.Override @java.lang.SuppressWarnings("all") B $fillValuesFrom(final C instance) {
- super.$fillValuesFrom(instance);
- SuperBuilderAbstractToBuilder.Child.ChildBuilder.$fillValuesFromInstanceIntoBuilder(instance, this);
- return self();
- }
- private static @java.lang.SuppressWarnings("all") void $fillValuesFromInstanceIntoBuilder(final SuperBuilderAbstractToBuilder.Child instance, final SuperBuilderAbstractToBuilder.Child.ChildBuilder<?, ?> b) {
- b.childField(instance.childField);
- }
- protected abstract @java.lang.Override @java.lang.SuppressWarnings("all") B self();
- public abstract @java.lang.Override @java.lang.SuppressWarnings("all") C build();
- /**
- * @return {@code this}.
- */
- public @java.lang.SuppressWarnings("all") B childField(final double childField) {
- this.childField = childField;
- return self();
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
- return (((("SuperBuilderAbstractToBuilder.Child.ChildBuilder(super=" + super.toString()) + ", childField=") + this.childField) + ")");
- }
- }
- double childField;
- protected @java.lang.SuppressWarnings("all") Child(final SuperBuilderAbstractToBuilder.Child.ChildBuilder<?, ?> b) {
- super(b);
- this.childField = b.childField;
- }
- }
- public static @lombok.experimental.SuperBuilder(toBuilder = true) class GrandChild extends Child {
- public static abstract @java.lang.SuppressWarnings("all") class GrandChildBuilder<C extends SuperBuilderAbstractToBuilder.GrandChild, B extends SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilder<C, B>> extends Child.ChildBuilder<C, B> {
- private @java.lang.SuppressWarnings("all") String grandChildField;
- public GrandChildBuilder() {
- super();
- }
- protected @java.lang.Override @java.lang.SuppressWarnings("all") B $fillValuesFrom(final C instance) {
- super.$fillValuesFrom(instance);
- SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilder.$fillValuesFromInstanceIntoBuilder(instance, this);
- return self();
- }
- private static @java.lang.SuppressWarnings("all") void $fillValuesFromInstanceIntoBuilder(final SuperBuilderAbstractToBuilder.GrandChild instance, final SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilder<?, ?> b) {
- b.grandChildField(instance.grandChildField);
- }
- protected abstract @java.lang.Override @java.lang.SuppressWarnings("all") B self();
- public abstract @java.lang.Override @java.lang.SuppressWarnings("all") C build();
- /**
- * @return {@code this}.
- */
- public @java.lang.SuppressWarnings("all") B grandChildField(final String grandChildField) {
- this.grandChildField = grandChildField;
- return self();
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
- return (((("SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilder(super=" + super.toString()) + ", grandChildField=") + this.grandChildField) + ")");
- }
- }
- private static final @java.lang.SuppressWarnings("all") class GrandChildBuilderImpl extends SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilder<SuperBuilderAbstractToBuilder.GrandChild, SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilderImpl> {
- private GrandChildBuilderImpl() {
- super();
- }
- protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilderImpl self() {
- return this;
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderAbstractToBuilder.GrandChild build() {
- return new SuperBuilderAbstractToBuilder.GrandChild(this);
- }
- }
- String grandChildField;
- protected @java.lang.SuppressWarnings("all") GrandChild(final SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilder<?, ?> b) {
- super(b);
- this.grandChildField = b.grandChildField;
- }
- public @java.lang.SuppressWarnings("all") SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilder<?, ?> toBuilder() {
- return new SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilderImpl().$fillValuesFrom(this);
- }
- public static @java.lang.SuppressWarnings("all") SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilder<?, ?> builder() {
- return new SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilderImpl();
- }
- }
- public SuperBuilderAbstractToBuilder() {
- super();
- }
- public static void test() {
- GrandChild x = GrandChild.builder().grandChildField("").parentField(5).childField(2.5).build().toBuilder().build();
- }
-}
+public class SuperBuilderAbstractToBuilder { + public static @lombok.experimental.SuperBuilder(toBuilder = true) class Parent { + public static abstract @java.lang.SuppressWarnings("all") class ParentBuilder<C extends SuperBuilderAbstractToBuilder.Parent, B extends SuperBuilderAbstractToBuilder.Parent.ParentBuilder<C, B>> { + private @java.lang.SuppressWarnings("all") int parentField; + public ParentBuilder() { + super(); + } + protected @java.lang.SuppressWarnings("all") B $fillValuesFrom(final C instance) { + SuperBuilderAbstractToBuilder.Parent.ParentBuilder.$fillValuesFromInstanceIntoBuilder(instance, this); + return self(); + } + private static @java.lang.SuppressWarnings("all") void $fillValuesFromInstanceIntoBuilder(final SuperBuilderAbstractToBuilder.Parent instance, final SuperBuilderAbstractToBuilder.Parent.ParentBuilder<?, ?> b) { + b.parentField(instance.parentField); + } + protected abstract @java.lang.SuppressWarnings("all") B self(); + public abstract @java.lang.SuppressWarnings("all") C build(); + /** + * @return {@code this}. + */ + public @java.lang.SuppressWarnings("all") B parentField(final int parentField) { + this.parentField = parentField; + return self(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (("SuperBuilderAbstractToBuilder.Parent.ParentBuilder(parentField=" + this.parentField) + ")"); + } + } + private static final @java.lang.SuppressWarnings("all") class ParentBuilderImpl extends SuperBuilderAbstractToBuilder.Parent.ParentBuilder<SuperBuilderAbstractToBuilder.Parent, SuperBuilderAbstractToBuilder.Parent.ParentBuilderImpl> { + private ParentBuilderImpl() { + super(); + } + protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderAbstractToBuilder.Parent.ParentBuilderImpl self() { + return this; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderAbstractToBuilder.Parent build() { + return new SuperBuilderAbstractToBuilder.Parent(this); + } + } + int parentField; + protected @java.lang.SuppressWarnings("all") Parent(final SuperBuilderAbstractToBuilder.Parent.ParentBuilder<?, ?> b) { + super(); + this.parentField = b.parentField; + } + public @java.lang.SuppressWarnings("all") SuperBuilderAbstractToBuilder.Parent.ParentBuilder<?, ?> toBuilder() { + return new SuperBuilderAbstractToBuilder.Parent.ParentBuilderImpl().$fillValuesFrom(this); + } + public static @java.lang.SuppressWarnings("all") SuperBuilderAbstractToBuilder.Parent.ParentBuilder<?, ?> builder() { + return new SuperBuilderAbstractToBuilder.Parent.ParentBuilderImpl(); + } + } + public static abstract @lombok.experimental.SuperBuilder(toBuilder = true) class Child extends Parent { + public static abstract @java.lang.SuppressWarnings("all") class ChildBuilder<C extends SuperBuilderAbstractToBuilder.Child, B extends SuperBuilderAbstractToBuilder.Child.ChildBuilder<C, B>> extends Parent.ParentBuilder<C, B> { + private @java.lang.SuppressWarnings("all") double childField; + public ChildBuilder() { + super(); + } + protected @java.lang.Override @java.lang.SuppressWarnings("all") B $fillValuesFrom(final C instance) { + super.$fillValuesFrom(instance); + SuperBuilderAbstractToBuilder.Child.ChildBuilder.$fillValuesFromInstanceIntoBuilder(instance, this); + return self(); + } + private static @java.lang.SuppressWarnings("all") void $fillValuesFromInstanceIntoBuilder(final SuperBuilderAbstractToBuilder.Child instance, final SuperBuilderAbstractToBuilder.Child.ChildBuilder<?, ?> b) { + b.childField(instance.childField); + } + protected abstract @java.lang.Override @java.lang.SuppressWarnings("all") B self(); + public abstract @java.lang.Override @java.lang.SuppressWarnings("all") C build(); + /** + * @return {@code this}. + */ + public @java.lang.SuppressWarnings("all") B childField(final double childField) { + this.childField = childField; + return self(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (((("SuperBuilderAbstractToBuilder.Child.ChildBuilder(super=" + super.toString()) + ", childField=") + this.childField) + ")"); + } + } + double childField; + protected @java.lang.SuppressWarnings("all") Child(final SuperBuilderAbstractToBuilder.Child.ChildBuilder<?, ?> b) { + super(b); + this.childField = b.childField; + } + } + public static @lombok.experimental.SuperBuilder(toBuilder = true) class GrandChild extends Child { + public static abstract @java.lang.SuppressWarnings("all") class GrandChildBuilder<C extends SuperBuilderAbstractToBuilder.GrandChild, B extends SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilder<C, B>> extends Child.ChildBuilder<C, B> { + private @java.lang.SuppressWarnings("all") String grandChildField; + public GrandChildBuilder() { + super(); + } + protected @java.lang.Override @java.lang.SuppressWarnings("all") B $fillValuesFrom(final C instance) { + super.$fillValuesFrom(instance); + SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilder.$fillValuesFromInstanceIntoBuilder(instance, this); + return self(); + } + private static @java.lang.SuppressWarnings("all") void $fillValuesFromInstanceIntoBuilder(final SuperBuilderAbstractToBuilder.GrandChild instance, final SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilder<?, ?> b) { + b.grandChildField(instance.grandChildField); + } + protected abstract @java.lang.Override @java.lang.SuppressWarnings("all") B self(); + public abstract @java.lang.Override @java.lang.SuppressWarnings("all") C build(); + /** + * @return {@code this}. + */ + public @java.lang.SuppressWarnings("all") B grandChildField(final String grandChildField) { + this.grandChildField = grandChildField; + return self(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (((("SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilder(super=" + super.toString()) + ", grandChildField=") + this.grandChildField) + ")"); + } + } + private static final @java.lang.SuppressWarnings("all") class GrandChildBuilderImpl extends SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilder<SuperBuilderAbstractToBuilder.GrandChild, SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilderImpl> { + private GrandChildBuilderImpl() { + super(); + } + protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilderImpl self() { + return this; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderAbstractToBuilder.GrandChild build() { + return new SuperBuilderAbstractToBuilder.GrandChild(this); + } + } + String grandChildField; + protected @java.lang.SuppressWarnings("all") GrandChild(final SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilder<?, ?> b) { + super(b); + this.grandChildField = b.grandChildField; + } + public @java.lang.SuppressWarnings("all") SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilder<?, ?> toBuilder() { + return new SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilderImpl().$fillValuesFrom(this); + } + public static @java.lang.SuppressWarnings("all") SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilder<?, ?> builder() { + return new SuperBuilderAbstractToBuilder.GrandChild.GrandChildBuilderImpl(); + } + } + public SuperBuilderAbstractToBuilder() { + super(); + } + public static void test() { + GrandChild x = GrandChild.builder().grandChildField("").parentField(5).childField(2.5).build().toBuilder().build(); + } +} diff --git a/test/transform/resource/after-ecj/SuperBuilderBasic.java b/test/transform/resource/after-ecj/SuperBuilderBasic.java index b5e835d4..844206d0 100644 --- a/test/transform/resource/after-ecj/SuperBuilderBasic.java +++ b/test/transform/resource/after-ecj/SuperBuilderBasic.java @@ -1,122 +1,122 @@ -import java.util.List;
-public class SuperBuilderBasic {
- public static @lombok.experimental.SuperBuilder class Parent {
- public static abstract @java.lang.SuppressWarnings("all") class ParentBuilder<C extends SuperBuilderBasic.Parent, B extends SuperBuilderBasic.Parent.ParentBuilder<C, B>> {
- private @java.lang.SuppressWarnings("all") int field1;
- private @java.lang.SuppressWarnings("all") java.util.ArrayList<String> items;
- public ParentBuilder() {
- super();
- }
- protected abstract @java.lang.SuppressWarnings("all") B self();
- public abstract @java.lang.SuppressWarnings("all") C build();
- /**
- * @return {@code this}.
- */
- public @java.lang.SuppressWarnings("all") B field1(final int field1) {
- this.field1 = field1;
- return self();
- }
- public @java.lang.SuppressWarnings("all") B item(final String item) {
- if ((this.items == null))
- this.items = new java.util.ArrayList<String>();
- this.items.add(item);
- return self();
- }
- public @java.lang.SuppressWarnings("all") B items(final java.util.Collection<? extends String> items) {
- if ((items == null))
- {
- throw new java.lang.NullPointerException("items cannot be null");
- }
- if ((this.items == null))
- this.items = new java.util.ArrayList<String>();
- this.items.addAll(items);
- return self();
- }
- public @java.lang.SuppressWarnings("all") B clearItems() {
- if ((this.items != null))
- this.items.clear();
- return self();
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
- return (((("SuperBuilderBasic.Parent.ParentBuilder(field1=" + this.field1) + ", items=") + this.items) + ")");
- }
- }
- private static final @java.lang.SuppressWarnings("all") class ParentBuilderImpl extends SuperBuilderBasic.Parent.ParentBuilder<SuperBuilderBasic.Parent, SuperBuilderBasic.Parent.ParentBuilderImpl> {
- private ParentBuilderImpl() {
- super();
- }
- protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderBasic.Parent.ParentBuilderImpl self() {
- return this;
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderBasic.Parent build() {
- return new SuperBuilderBasic.Parent(this);
- }
- }
- int field1;
- @lombok.Singular List<String> items;
- protected @java.lang.SuppressWarnings("all") Parent(final SuperBuilderBasic.Parent.ParentBuilder<?, ?> b) {
- super();
- this.field1 = b.field1;
- java.util.List<String> items;
- switch (((b.items == null) ? 0 : b.items.size())) {
- case 0 :
- items = java.util.Collections.emptyList();
- break;
- case 1 :
- items = java.util.Collections.singletonList(b.items.get(0));
- break;
- default :
- items = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(b.items));
- }
- this.items = items;
- }
- public static @java.lang.SuppressWarnings("all") SuperBuilderBasic.Parent.ParentBuilder<?, ?> builder() {
- return new SuperBuilderBasic.Parent.ParentBuilderImpl();
- }
- }
- public static @lombok.experimental.SuperBuilder class Child extends SuperBuilderBasic.Parent {
- public static abstract @java.lang.SuppressWarnings("all") class ChildBuilder<C extends SuperBuilderBasic.Child, B extends SuperBuilderBasic.Child.ChildBuilder<C, B>> extends SuperBuilderBasic.Parent.ParentBuilder<C, B> {
- private @java.lang.SuppressWarnings("all") double field3;
- public ChildBuilder() {
- super();
- }
- protected abstract @java.lang.Override @java.lang.SuppressWarnings("all") B self();
- public abstract @java.lang.Override @java.lang.SuppressWarnings("all") C build();
- /**
- * @return {@code this}.
- */
- public @java.lang.SuppressWarnings("all") B field3(final double field3) {
- this.field3 = field3;
- return self();
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
- return (((("SuperBuilderBasic.Child.ChildBuilder(super=" + super.toString()) + ", field3=") + this.field3) + ")");
- }
- }
- private static final @java.lang.SuppressWarnings("all") class ChildBuilderImpl extends SuperBuilderBasic.Child.ChildBuilder<SuperBuilderBasic.Child, SuperBuilderBasic.Child.ChildBuilderImpl> {
- private ChildBuilderImpl() {
- super();
- }
- protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderBasic.Child.ChildBuilderImpl self() {
- return this;
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderBasic.Child build() {
- return new SuperBuilderBasic.Child(this);
- }
- }
- double field3;
- protected @java.lang.SuppressWarnings("all") Child(final SuperBuilderBasic.Child.ChildBuilder<?, ?> b) {
- super(b);
- this.field3 = b.field3;
- }
- public static @java.lang.SuppressWarnings("all") SuperBuilderBasic.Child.ChildBuilder<?, ?> builder() {
- return new SuperBuilderBasic.Child.ChildBuilderImpl();
- }
- }
- public SuperBuilderBasic() {
- super();
- }
- public static void test() {
- Child x = Child.builder().field3(0.0).field1(5).item("").build();
- }
-}
+import java.util.List; +public class SuperBuilderBasic { + public static @lombok.experimental.SuperBuilder class Parent { + public static abstract @java.lang.SuppressWarnings("all") class ParentBuilder<C extends SuperBuilderBasic.Parent, B extends SuperBuilderBasic.Parent.ParentBuilder<C, B>> { + private @java.lang.SuppressWarnings("all") int field1; + private @java.lang.SuppressWarnings("all") java.util.ArrayList<String> items; + public ParentBuilder() { + super(); + } + protected abstract @java.lang.SuppressWarnings("all") B self(); + public abstract @java.lang.SuppressWarnings("all") C build(); + /** + * @return {@code this}. + */ + public @java.lang.SuppressWarnings("all") B field1(final int field1) { + this.field1 = field1; + return self(); + } + public @java.lang.SuppressWarnings("all") B item(final String item) { + if ((this.items == null)) + this.items = new java.util.ArrayList<String>(); + this.items.add(item); + return self(); + } + public @java.lang.SuppressWarnings("all") B items(final java.util.Collection<? extends String> items) { + if ((items == null)) + { + throw new java.lang.NullPointerException("items cannot be null"); + } + if ((this.items == null)) + this.items = new java.util.ArrayList<String>(); + this.items.addAll(items); + return self(); + } + public @java.lang.SuppressWarnings("all") B clearItems() { + if ((this.items != null)) + this.items.clear(); + return self(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (((("SuperBuilderBasic.Parent.ParentBuilder(field1=" + this.field1) + ", items=") + this.items) + ")"); + } + } + private static final @java.lang.SuppressWarnings("all") class ParentBuilderImpl extends SuperBuilderBasic.Parent.ParentBuilder<SuperBuilderBasic.Parent, SuperBuilderBasic.Parent.ParentBuilderImpl> { + private ParentBuilderImpl() { + super(); + } + protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderBasic.Parent.ParentBuilderImpl self() { + return this; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderBasic.Parent build() { + return new SuperBuilderBasic.Parent(this); + } + } + int field1; + @lombok.Singular List<String> items; + protected @java.lang.SuppressWarnings("all") Parent(final SuperBuilderBasic.Parent.ParentBuilder<?, ?> b) { + super(); + this.field1 = b.field1; + java.util.List<String> items; + switch (((b.items == null) ? 0 : b.items.size())) { + case 0 : + items = java.util.Collections.emptyList(); + break; + case 1 : + items = java.util.Collections.singletonList(b.items.get(0)); + break; + default : + items = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(b.items)); + } + this.items = items; + } + public static @java.lang.SuppressWarnings("all") SuperBuilderBasic.Parent.ParentBuilder<?, ?> builder() { + return new SuperBuilderBasic.Parent.ParentBuilderImpl(); + } + } + public static @lombok.experimental.SuperBuilder class Child extends SuperBuilderBasic.Parent { + public static abstract @java.lang.SuppressWarnings("all") class ChildBuilder<C extends SuperBuilderBasic.Child, B extends SuperBuilderBasic.Child.ChildBuilder<C, B>> extends SuperBuilderBasic.Parent.ParentBuilder<C, B> { + private @java.lang.SuppressWarnings("all") double field3; + public ChildBuilder() { + super(); + } + protected abstract @java.lang.Override @java.lang.SuppressWarnings("all") B self(); + public abstract @java.lang.Override @java.lang.SuppressWarnings("all") C build(); + /** + * @return {@code this}. + */ + public @java.lang.SuppressWarnings("all") B field3(final double field3) { + this.field3 = field3; + return self(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (((("SuperBuilderBasic.Child.ChildBuilder(super=" + super.toString()) + ", field3=") + this.field3) + ")"); + } + } + private static final @java.lang.SuppressWarnings("all") class ChildBuilderImpl extends SuperBuilderBasic.Child.ChildBuilder<SuperBuilderBasic.Child, SuperBuilderBasic.Child.ChildBuilderImpl> { + private ChildBuilderImpl() { + super(); + } + protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderBasic.Child.ChildBuilderImpl self() { + return this; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderBasic.Child build() { + return new SuperBuilderBasic.Child(this); + } + } + double field3; + protected @java.lang.SuppressWarnings("all") Child(final SuperBuilderBasic.Child.ChildBuilder<?, ?> b) { + super(b); + this.field3 = b.field3; + } + public static @java.lang.SuppressWarnings("all") SuperBuilderBasic.Child.ChildBuilder<?, ?> builder() { + return new SuperBuilderBasic.Child.ChildBuilderImpl(); + } + } + public SuperBuilderBasic() { + super(); + } + public static void test() { + Child x = Child.builder().field3(0.0).field1(5).item("").build(); + } +} diff --git a/test/transform/resource/after-ecj/SuperBuilderBasicToBuilder.java b/test/transform/resource/after-ecj/SuperBuilderBasicToBuilder.java index f6d298e1..67ee62f6 100644 --- a/test/transform/resource/after-ecj/SuperBuilderBasicToBuilder.java +++ b/test/transform/resource/after-ecj/SuperBuilderBasicToBuilder.java @@ -1,183 +1,183 @@ -import java.util.List;
-public class SuperBuilderBasicToBuilder {
- public static @lombok.experimental.SuperBuilder(toBuilder = true) class Parent {
- public static abstract @java.lang.SuppressWarnings("all") class ParentBuilder<C extends SuperBuilderBasicToBuilder.Parent, B extends SuperBuilderBasicToBuilder.Parent.ParentBuilder<C, B>> {
- private @java.lang.SuppressWarnings("all") int field1;
- private @java.lang.SuppressWarnings("all") int obtainViaField;
- private @java.lang.SuppressWarnings("all") int obtainViaMethod;
- private @java.lang.SuppressWarnings("all") String obtainViaStaticMethod;
- private @java.lang.SuppressWarnings("all") java.util.ArrayList<String> items;
- public ParentBuilder() {
- super();
- }
- protected @java.lang.SuppressWarnings("all") B $fillValuesFrom(final C instance) {
- SuperBuilderBasicToBuilder.Parent.ParentBuilder.$fillValuesFromInstanceIntoBuilder(instance, this);
- return self();
- }
- private static @java.lang.SuppressWarnings("all") void $fillValuesFromInstanceIntoBuilder(final SuperBuilderBasicToBuilder.Parent instance, final SuperBuilderBasicToBuilder.Parent.ParentBuilder<?, ?> b) {
- b.field1(instance.field1);
- b.obtainViaField(instance.field1);
- b.obtainViaMethod(instance.method());
- b.obtainViaStaticMethod(SuperBuilderBasicToBuilder.Parent.staticMethod(instance));
- b.items(((instance.items == null) ? java.util.Collections.emptyList() : instance.items));
- }
- protected abstract @java.lang.SuppressWarnings("all") B self();
- public abstract @java.lang.SuppressWarnings("all") C build();
- /**
- * @return {@code this}.
- */
- public @java.lang.SuppressWarnings("all") B field1(final int field1) {
- this.field1 = field1;
- return self();
- }
- /**
- * @return {@code this}.
- */
- public @java.lang.SuppressWarnings("all") B obtainViaField(final int obtainViaField) {
- this.obtainViaField = obtainViaField;
- return self();
- }
- /**
- * @return {@code this}.
- */
- public @java.lang.SuppressWarnings("all") B obtainViaMethod(final int obtainViaMethod) {
- this.obtainViaMethod = obtainViaMethod;
- return self();
- }
- /**
- * @return {@code this}.
- */
- public @java.lang.SuppressWarnings("all") B obtainViaStaticMethod(final String obtainViaStaticMethod) {
- this.obtainViaStaticMethod = obtainViaStaticMethod;
- return self();
- }
- public @java.lang.SuppressWarnings("all") B item(final String item) {
- if ((this.items == null))
- this.items = new java.util.ArrayList<String>();
- this.items.add(item);
- return self();
- }
- public @java.lang.SuppressWarnings("all") B items(final java.util.Collection<? extends String> items) {
- if ((items == null))
- {
- throw new java.lang.NullPointerException("items cannot be null");
- }
- if ((this.items == null))
- this.items = new java.util.ArrayList<String>();
- this.items.addAll(items);
- return self();
- }
- public @java.lang.SuppressWarnings("all") B clearItems() {
- if ((this.items != null))
- this.items.clear();
- return self();
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
- return (((((((((("SuperBuilderBasicToBuilder.Parent.ParentBuilder(field1=" + this.field1) + ", obtainViaField=") + this.obtainViaField) + ", obtainViaMethod=") + this.obtainViaMethod) + ", obtainViaStaticMethod=") + this.obtainViaStaticMethod) + ", items=") + this.items) + ")");
- }
- }
- private static final @java.lang.SuppressWarnings("all") class ParentBuilderImpl extends SuperBuilderBasicToBuilder.Parent.ParentBuilder<SuperBuilderBasicToBuilder.Parent, SuperBuilderBasicToBuilder.Parent.ParentBuilderImpl> {
- private ParentBuilderImpl() {
- super();
- }
- protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderBasicToBuilder.Parent.ParentBuilderImpl self() {
- return this;
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderBasicToBuilder.Parent build() {
- return new SuperBuilderBasicToBuilder.Parent(this);
- }
- }
- private int field1;
- @lombok.Builder.ObtainVia(field = "field1") int obtainViaField;
- @lombok.Builder.ObtainVia(method = "method") int obtainViaMethod;
- @lombok.Builder.ObtainVia(method = "staticMethod",isStatic = true) String obtainViaStaticMethod;
- @lombok.Singular List<String> items;
- private int method() {
- return 2;
- }
- private static String staticMethod(Parent instance) {
- return "staticMethod";
- }
- protected @java.lang.SuppressWarnings("all") Parent(final SuperBuilderBasicToBuilder.Parent.ParentBuilder<?, ?> b) {
- super();
- this.field1 = b.field1;
- this.obtainViaField = b.obtainViaField;
- this.obtainViaMethod = b.obtainViaMethod;
- this.obtainViaStaticMethod = b.obtainViaStaticMethod;
- java.util.List<String> items;
- switch (((b.items == null) ? 0 : b.items.size())) {
- case 0 :
- items = java.util.Collections.emptyList();
- break;
- case 1 :
- items = java.util.Collections.singletonList(b.items.get(0));
- break;
- default :
- items = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(b.items));
- }
- this.items = items;
- }
- public @java.lang.SuppressWarnings("all") SuperBuilderBasicToBuilder.Parent.ParentBuilder<?, ?> toBuilder() {
- return new SuperBuilderBasicToBuilder.Parent.ParentBuilderImpl().$fillValuesFrom(this);
- }
- public static @java.lang.SuppressWarnings("all") SuperBuilderBasicToBuilder.Parent.ParentBuilder<?, ?> builder() {
- return new SuperBuilderBasicToBuilder.Parent.ParentBuilderImpl();
- }
- }
- public static @lombok.experimental.SuperBuilder(toBuilder = true) class Child extends Parent {
- public static abstract @java.lang.SuppressWarnings("all") class ChildBuilder<C extends SuperBuilderBasicToBuilder.Child, B extends SuperBuilderBasicToBuilder.Child.ChildBuilder<C, B>> extends Parent.ParentBuilder<C, B> {
- private @java.lang.SuppressWarnings("all") double field3;
- public ChildBuilder() {
- super();
- }
- protected @java.lang.Override @java.lang.SuppressWarnings("all") B $fillValuesFrom(final C instance) {
- super.$fillValuesFrom(instance);
- SuperBuilderBasicToBuilder.Child.ChildBuilder.$fillValuesFromInstanceIntoBuilder(instance, this);
- return self();
- }
- private static @java.lang.SuppressWarnings("all") void $fillValuesFromInstanceIntoBuilder(final SuperBuilderBasicToBuilder.Child instance, final SuperBuilderBasicToBuilder.Child.ChildBuilder<?, ?> b) {
- b.field3(instance.field3);
- }
- protected abstract @java.lang.Override @java.lang.SuppressWarnings("all") B self();
- public abstract @java.lang.Override @java.lang.SuppressWarnings("all") C build();
- /**
- * @return {@code this}.
- */
- public @java.lang.SuppressWarnings("all") B field3(final double field3) {
- this.field3 = field3;
- return self();
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
- return (((("SuperBuilderBasicToBuilder.Child.ChildBuilder(super=" + super.toString()) + ", field3=") + this.field3) + ")");
- }
- }
- private static final @java.lang.SuppressWarnings("all") class ChildBuilderImpl extends SuperBuilderBasicToBuilder.Child.ChildBuilder<SuperBuilderBasicToBuilder.Child, SuperBuilderBasicToBuilder.Child.ChildBuilderImpl> {
- private ChildBuilderImpl() {
- super();
- }
- protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderBasicToBuilder.Child.ChildBuilderImpl self() {
- return this;
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderBasicToBuilder.Child build() {
- return new SuperBuilderBasicToBuilder.Child(this);
- }
- }
- private double field3;
- protected @java.lang.SuppressWarnings("all") Child(final SuperBuilderBasicToBuilder.Child.ChildBuilder<?, ?> b) {
- super(b);
- this.field3 = b.field3;
- }
- public @java.lang.SuppressWarnings("all") SuperBuilderBasicToBuilder.Child.ChildBuilder<?, ?> toBuilder() {
- return new SuperBuilderBasicToBuilder.Child.ChildBuilderImpl().$fillValuesFrom(this);
- }
- public static @java.lang.SuppressWarnings("all") SuperBuilderBasicToBuilder.Child.ChildBuilder<?, ?> builder() {
- return new SuperBuilderBasicToBuilder.Child.ChildBuilderImpl();
- }
- }
- public SuperBuilderBasicToBuilder() {
- super();
- }
- public static void test() {
- Child x = Child.builder().field3(0.0).field1(5).item("").build().toBuilder().build();
- }
-}
+import java.util.List; +public class SuperBuilderBasicToBuilder { + public static @lombok.experimental.SuperBuilder(toBuilder = true) class Parent { + public static abstract @java.lang.SuppressWarnings("all") class ParentBuilder<C extends SuperBuilderBasicToBuilder.Parent, B extends SuperBuilderBasicToBuilder.Parent.ParentBuilder<C, B>> { + private @java.lang.SuppressWarnings("all") int field1; + private @java.lang.SuppressWarnings("all") int obtainViaField; + private @java.lang.SuppressWarnings("all") int obtainViaMethod; + private @java.lang.SuppressWarnings("all") String obtainViaStaticMethod; + private @java.lang.SuppressWarnings("all") java.util.ArrayList<String> items; + public ParentBuilder() { + super(); + } + protected @java.lang.SuppressWarnings("all") B $fillValuesFrom(final C instance) { + SuperBuilderBasicToBuilder.Parent.ParentBuilder.$fillValuesFromInstanceIntoBuilder(instance, this); + return self(); + } + private static @java.lang.SuppressWarnings("all") void $fillValuesFromInstanceIntoBuilder(final SuperBuilderBasicToBuilder.Parent instance, final SuperBuilderBasicToBuilder.Parent.ParentBuilder<?, ?> b) { + b.field1(instance.field1); + b.obtainViaField(instance.field1); + b.obtainViaMethod(instance.method()); + b.obtainViaStaticMethod(SuperBuilderBasicToBuilder.Parent.staticMethod(instance)); + b.items(((instance.items == null) ? java.util.Collections.<String>emptyList() : instance.items)); + } + protected abstract @java.lang.SuppressWarnings("all") B self(); + public abstract @java.lang.SuppressWarnings("all") C build(); + /** + * @return {@code this}. + */ + public @java.lang.SuppressWarnings("all") B field1(final int field1) { + this.field1 = field1; + return self(); + } + /** + * @return {@code this}. + */ + public @java.lang.SuppressWarnings("all") B obtainViaField(final int obtainViaField) { + this.obtainViaField = obtainViaField; + return self(); + } + /** + * @return {@code this}. + */ + public @java.lang.SuppressWarnings("all") B obtainViaMethod(final int obtainViaMethod) { + this.obtainViaMethod = obtainViaMethod; + return self(); + } + /** + * @return {@code this}. + */ + public @java.lang.SuppressWarnings("all") B obtainViaStaticMethod(final String obtainViaStaticMethod) { + this.obtainViaStaticMethod = obtainViaStaticMethod; + return self(); + } + public @java.lang.SuppressWarnings("all") B item(final String item) { + if ((this.items == null)) + this.items = new java.util.ArrayList<String>(); + this.items.add(item); + return self(); + } + public @java.lang.SuppressWarnings("all") B items(final java.util.Collection<? extends String> items) { + if ((items == null)) + { + throw new java.lang.NullPointerException("items cannot be null"); + } + if ((this.items == null)) + this.items = new java.util.ArrayList<String>(); + this.items.addAll(items); + return self(); + } + public @java.lang.SuppressWarnings("all") B clearItems() { + if ((this.items != null)) + this.items.clear(); + return self(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (((((((((("SuperBuilderBasicToBuilder.Parent.ParentBuilder(field1=" + this.field1) + ", obtainViaField=") + this.obtainViaField) + ", obtainViaMethod=") + this.obtainViaMethod) + ", obtainViaStaticMethod=") + this.obtainViaStaticMethod) + ", items=") + this.items) + ")"); + } + } + private static final @java.lang.SuppressWarnings("all") class ParentBuilderImpl extends SuperBuilderBasicToBuilder.Parent.ParentBuilder<SuperBuilderBasicToBuilder.Parent, SuperBuilderBasicToBuilder.Parent.ParentBuilderImpl> { + private ParentBuilderImpl() { + super(); + } + protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderBasicToBuilder.Parent.ParentBuilderImpl self() { + return this; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderBasicToBuilder.Parent build() { + return new SuperBuilderBasicToBuilder.Parent(this); + } + } + private int field1; + @lombok.Builder.ObtainVia(field = "field1") int obtainViaField; + @lombok.Builder.ObtainVia(method = "method") int obtainViaMethod; + @lombok.Builder.ObtainVia(method = "staticMethod",isStatic = true) String obtainViaStaticMethod; + @lombok.Singular List<String> items; + private int method() { + return 2; + } + private static String staticMethod(Parent instance) { + return "staticMethod"; + } + protected @java.lang.SuppressWarnings("all") Parent(final SuperBuilderBasicToBuilder.Parent.ParentBuilder<?, ?> b) { + super(); + this.field1 = b.field1; + this.obtainViaField = b.obtainViaField; + this.obtainViaMethod = b.obtainViaMethod; + this.obtainViaStaticMethod = b.obtainViaStaticMethod; + java.util.List<String> items; + switch (((b.items == null) ? 0 : b.items.size())) { + case 0 : + items = java.util.Collections.emptyList(); + break; + case 1 : + items = java.util.Collections.singletonList(b.items.get(0)); + break; + default : + items = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(b.items)); + } + this.items = items; + } + public @java.lang.SuppressWarnings("all") SuperBuilderBasicToBuilder.Parent.ParentBuilder<?, ?> toBuilder() { + return new SuperBuilderBasicToBuilder.Parent.ParentBuilderImpl().$fillValuesFrom(this); + } + public static @java.lang.SuppressWarnings("all") SuperBuilderBasicToBuilder.Parent.ParentBuilder<?, ?> builder() { + return new SuperBuilderBasicToBuilder.Parent.ParentBuilderImpl(); + } + } + public static @lombok.experimental.SuperBuilder(toBuilder = true) class Child extends Parent { + public static abstract @java.lang.SuppressWarnings("all") class ChildBuilder<C extends SuperBuilderBasicToBuilder.Child, B extends SuperBuilderBasicToBuilder.Child.ChildBuilder<C, B>> extends Parent.ParentBuilder<C, B> { + private @java.lang.SuppressWarnings("all") double field3; + public ChildBuilder() { + super(); + } + protected @java.lang.Override @java.lang.SuppressWarnings("all") B $fillValuesFrom(final C instance) { + super.$fillValuesFrom(instance); + SuperBuilderBasicToBuilder.Child.ChildBuilder.$fillValuesFromInstanceIntoBuilder(instance, this); + return self(); + } + private static @java.lang.SuppressWarnings("all") void $fillValuesFromInstanceIntoBuilder(final SuperBuilderBasicToBuilder.Child instance, final SuperBuilderBasicToBuilder.Child.ChildBuilder<?, ?> b) { + b.field3(instance.field3); + } + protected abstract @java.lang.Override @java.lang.SuppressWarnings("all") B self(); + public abstract @java.lang.Override @java.lang.SuppressWarnings("all") C build(); + /** + * @return {@code this}. + */ + public @java.lang.SuppressWarnings("all") B field3(final double field3) { + this.field3 = field3; + return self(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (((("SuperBuilderBasicToBuilder.Child.ChildBuilder(super=" + super.toString()) + ", field3=") + this.field3) + ")"); + } + } + private static final @java.lang.SuppressWarnings("all") class ChildBuilderImpl extends SuperBuilderBasicToBuilder.Child.ChildBuilder<SuperBuilderBasicToBuilder.Child, SuperBuilderBasicToBuilder.Child.ChildBuilderImpl> { + private ChildBuilderImpl() { + super(); + } + protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderBasicToBuilder.Child.ChildBuilderImpl self() { + return this; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderBasicToBuilder.Child build() { + return new SuperBuilderBasicToBuilder.Child(this); + } + } + private double field3; + protected @java.lang.SuppressWarnings("all") Child(final SuperBuilderBasicToBuilder.Child.ChildBuilder<?, ?> b) { + super(b); + this.field3 = b.field3; + } + public @java.lang.SuppressWarnings("all") SuperBuilderBasicToBuilder.Child.ChildBuilder<?, ?> toBuilder() { + return new SuperBuilderBasicToBuilder.Child.ChildBuilderImpl().$fillValuesFrom(this); + } + public static @java.lang.SuppressWarnings("all") SuperBuilderBasicToBuilder.Child.ChildBuilder<?, ?> builder() { + return new SuperBuilderBasicToBuilder.Child.ChildBuilderImpl(); + } + } + public SuperBuilderBasicToBuilder() { + super(); + } + public static void test() { + Child x = Child.builder().field3(0.0).field1(5).item("").build().toBuilder().build(); + } +} diff --git a/test/transform/resource/after-ecj/SuperBuilderCustomized.java b/test/transform/resource/after-ecj/SuperBuilderCustomized.java index c9619602..1fb41367 100644 --- a/test/transform/resource/after-ecj/SuperBuilderCustomized.java +++ b/test/transform/resource/after-ecj/SuperBuilderCustomized.java @@ -1,91 +1,91 @@ -import java.util.List;
-public class SuperBuilderCustomized {
- public static @lombok.experimental.SuperBuilder class Parent {
- public static abstract class ParentBuilder<C extends Parent, B extends ParentBuilder<C, B>> {
- private @java.lang.SuppressWarnings("all") int field1;
- public ParentBuilder() {
- super();
- }
- public B resetToDefault() {
- field1 = 0;
- return self();
- }
- public B field1(int field1) {
- this.field1 = (field1 + 1);
- return self();
- }
- protected abstract @java.lang.SuppressWarnings("all") B self();
- public abstract @java.lang.SuppressWarnings("all") C build();
- public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
- return (("SuperBuilderCustomized.Parent.ParentBuilder(field1=" + this.field1) + ")");
- }
- }
- private static final @java.lang.SuppressWarnings("all") class ParentBuilderImpl extends SuperBuilderCustomized.Parent.ParentBuilder<SuperBuilderCustomized.Parent, SuperBuilderCustomized.Parent.ParentBuilderImpl> {
- private ParentBuilderImpl() {
- super();
- }
- protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderCustomized.Parent.ParentBuilderImpl self() {
- return this;
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderCustomized.Parent build() {
- return new SuperBuilderCustomized.Parent(this);
- }
- }
- int field1;
- protected Parent(ParentBuilder<?, ?> b) {
- super();
- if ((b.field1 == 0))
- throw new IllegalArgumentException("field1 must be != 0");
- this.field1 = b.field1;
- }
- public static SuperBuilderCustomized.Parent.ParentBuilder<?, ?> builder(int field1) {
- return new SuperBuilderCustomized.Parent.ParentBuilderImpl().field1(field1);
- }
- }
- public static @lombok.experimental.SuperBuilder class Child extends Parent {
- private static final class ChildBuilderImpl extends ChildBuilder<Child, ChildBuilderImpl> {
- private ChildBuilderImpl() {
- super();
- }
- public @Override Child build() {
- this.resetToDefault();
- return new Child(this);
- }
- protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderCustomized.Child.ChildBuilderImpl self() {
- return this;
- }
- }
- public static abstract @java.lang.SuppressWarnings("all") class ChildBuilder<C extends SuperBuilderCustomized.Child, B extends SuperBuilderCustomized.Child.ChildBuilder<C, B>> extends Parent.ParentBuilder<C, B> {
- private @java.lang.SuppressWarnings("all") double field2;
- public ChildBuilder() {
- super();
- }
- protected abstract @java.lang.Override @java.lang.SuppressWarnings("all") B self();
- public abstract @java.lang.Override @java.lang.SuppressWarnings("all") C build();
- /**
- * @return {@code this}.
- */
- public @java.lang.SuppressWarnings("all") B field2(final double field2) {
- this.field2 = field2;
- return self();
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
- return (((("SuperBuilderCustomized.Child.ChildBuilder(super=" + super.toString()) + ", field2=") + this.field2) + ")");
- }
- }
- double field2;
- public static ChildBuilder<?, ?> builder() {
- return new ChildBuilderImpl().field2(10.0);
- }
- protected @java.lang.SuppressWarnings("all") Child(final SuperBuilderCustomized.Child.ChildBuilder<?, ?> b) {
- super(b);
- this.field2 = b.field2;
- }
- }
- public SuperBuilderCustomized() {
- super();
- }
- public static void test() {
- Child x = Child.builder().field2(1.0).field1(5).resetToDefault().build();
- }
-}
+import java.util.List; +public class SuperBuilderCustomized { + public static @lombok.experimental.SuperBuilder class Parent { + public static abstract class ParentBuilder<C extends Parent, B extends ParentBuilder<C, B>> { + private @java.lang.SuppressWarnings("all") int field1; + public ParentBuilder() { + super(); + } + public B resetToDefault() { + field1 = 0; + return self(); + } + public B field1(int field1) { + this.field1 = (field1 + 1); + return self(); + } + protected abstract @java.lang.SuppressWarnings("all") B self(); + public abstract @java.lang.SuppressWarnings("all") C build(); + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (("SuperBuilderCustomized.Parent.ParentBuilder(field1=" + this.field1) + ")"); + } + } + private static final @java.lang.SuppressWarnings("all") class ParentBuilderImpl extends SuperBuilderCustomized.Parent.ParentBuilder<SuperBuilderCustomized.Parent, SuperBuilderCustomized.Parent.ParentBuilderImpl> { + private ParentBuilderImpl() { + super(); + } + protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderCustomized.Parent.ParentBuilderImpl self() { + return this; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderCustomized.Parent build() { + return new SuperBuilderCustomized.Parent(this); + } + } + int field1; + protected Parent(ParentBuilder<?, ?> b) { + super(); + if ((b.field1 == 0)) + throw new IllegalArgumentException("field1 must be != 0"); + this.field1 = b.field1; + } + public static SuperBuilderCustomized.Parent.ParentBuilder<?, ?> builder(int field1) { + return new SuperBuilderCustomized.Parent.ParentBuilderImpl().field1(field1); + } + } + public static @lombok.experimental.SuperBuilder class Child extends Parent { + private static final class ChildBuilderImpl extends ChildBuilder<Child, ChildBuilderImpl> { + private ChildBuilderImpl() { + super(); + } + public @Override Child build() { + this.resetToDefault(); + return new Child(this); + } + protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderCustomized.Child.ChildBuilderImpl self() { + return this; + } + } + public static abstract @java.lang.SuppressWarnings("all") class ChildBuilder<C extends SuperBuilderCustomized.Child, B extends SuperBuilderCustomized.Child.ChildBuilder<C, B>> extends Parent.ParentBuilder<C, B> { + private @java.lang.SuppressWarnings("all") double field2; + public ChildBuilder() { + super(); + } + protected abstract @java.lang.Override @java.lang.SuppressWarnings("all") B self(); + public abstract @java.lang.Override @java.lang.SuppressWarnings("all") C build(); + /** + * @return {@code this}. + */ + public @java.lang.SuppressWarnings("all") B field2(final double field2) { + this.field2 = field2; + return self(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (((("SuperBuilderCustomized.Child.ChildBuilder(super=" + super.toString()) + ", field2=") + this.field2) + ")"); + } + } + double field2; + public static ChildBuilder<?, ?> builder() { + return new ChildBuilderImpl().field2(10.0); + } + protected @java.lang.SuppressWarnings("all") Child(final SuperBuilderCustomized.Child.ChildBuilder<?, ?> b) { + super(b); + this.field2 = b.field2; + } + } + public SuperBuilderCustomized() { + super(); + } + public static void test() { + Child x = Child.builder().field2(1.0).field1(5).resetToDefault().build(); + } +} diff --git a/test/transform/resource/after-ecj/SuperBuilderCustomizedWithSetterPrefix.java b/test/transform/resource/after-ecj/SuperBuilderCustomizedWithSetterPrefix.java index 283bacd4..142181ec 100644 --- a/test/transform/resource/after-ecj/SuperBuilderCustomizedWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/SuperBuilderCustomizedWithSetterPrefix.java @@ -1,45 +1,45 @@ -import java.util.List;
-public class SuperBuilderCustomizedWithSetterPrefix {
- public static @lombok.experimental.SuperBuilder(setterPrefix = "set") class Parent {
- public static abstract class ParentBuilder<C extends Parent, B extends ParentBuilder<C, B>> {
- private @java.lang.SuppressWarnings("all") int field1;
- public ParentBuilder() {
- super();
- }
- public B setField1(int field1) {
- this.field1 = (field1 + 1);
- return self();
- }
- protected abstract @java.lang.SuppressWarnings("all") B self();
- public abstract @java.lang.SuppressWarnings("all") C build();
- public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
- return (("SuperBuilderCustomizedWithSetterPrefix.Parent.ParentBuilder(field1=" + this.field1) + ")");
- }
- }
- private static final @java.lang.SuppressWarnings("all") class ParentBuilderImpl extends SuperBuilderCustomizedWithSetterPrefix.Parent.ParentBuilder<SuperBuilderCustomizedWithSetterPrefix.Parent, SuperBuilderCustomizedWithSetterPrefix.Parent.ParentBuilderImpl> {
- private ParentBuilderImpl() {
- super();
- }
- protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderCustomizedWithSetterPrefix.Parent.ParentBuilderImpl self() {
- return this;
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderCustomizedWithSetterPrefix.Parent build() {
- return new SuperBuilderCustomizedWithSetterPrefix.Parent(this);
- }
- }
- int field1;
- protected @java.lang.SuppressWarnings("all") Parent(final SuperBuilderCustomizedWithSetterPrefix.Parent.ParentBuilder<?, ?> b) {
- super();
- this.field1 = b.field1;
- }
- public static @java.lang.SuppressWarnings("all") SuperBuilderCustomizedWithSetterPrefix.Parent.ParentBuilder<?, ?> builder() {
- return new SuperBuilderCustomizedWithSetterPrefix.Parent.ParentBuilderImpl();
- }
- }
- public SuperBuilderCustomizedWithSetterPrefix() {
- super();
- }
- public static void test() {
- Parent x = Parent.builder().setField1(5).build();
- }
-}
+import java.util.List; +public class SuperBuilderCustomizedWithSetterPrefix { + public static @lombok.experimental.SuperBuilder(setterPrefix = "set") class Parent { + public static abstract class ParentBuilder<C extends Parent, B extends ParentBuilder<C, B>> { + private @java.lang.SuppressWarnings("all") int field1; + public ParentBuilder() { + super(); + } + public B setField1(int field1) { + this.field1 = (field1 + 1); + return self(); + } + protected abstract @java.lang.SuppressWarnings("all") B self(); + public abstract @java.lang.SuppressWarnings("all") C build(); + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (("SuperBuilderCustomizedWithSetterPrefix.Parent.ParentBuilder(field1=" + this.field1) + ")"); + } + } + private static final @java.lang.SuppressWarnings("all") class ParentBuilderImpl extends SuperBuilderCustomizedWithSetterPrefix.Parent.ParentBuilder<SuperBuilderCustomizedWithSetterPrefix.Parent, SuperBuilderCustomizedWithSetterPrefix.Parent.ParentBuilderImpl> { + private ParentBuilderImpl() { + super(); + } + protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderCustomizedWithSetterPrefix.Parent.ParentBuilderImpl self() { + return this; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderCustomizedWithSetterPrefix.Parent build() { + return new SuperBuilderCustomizedWithSetterPrefix.Parent(this); + } + } + int field1; + protected @java.lang.SuppressWarnings("all") Parent(final SuperBuilderCustomizedWithSetterPrefix.Parent.ParentBuilder<?, ?> b) { + super(); + this.field1 = b.field1; + } + public static @java.lang.SuppressWarnings("all") SuperBuilderCustomizedWithSetterPrefix.Parent.ParentBuilder<?, ?> builder() { + return new SuperBuilderCustomizedWithSetterPrefix.Parent.ParentBuilderImpl(); + } + } + public SuperBuilderCustomizedWithSetterPrefix() { + super(); + } + public static void test() { + Parent x = Parent.builder().setField1(5).build(); + } +} diff --git a/test/transform/resource/after-ecj/SuperBuilderInitializer.java b/test/transform/resource/after-ecj/SuperBuilderInitializer.java new file mode 100644 index 00000000..0425fb89 --- /dev/null +++ b/test/transform/resource/after-ecj/SuperBuilderInitializer.java @@ -0,0 +1,54 @@ +import lombok.experimental.SuperBuilder; +class SuperBuilderInitializer { + public static @SuperBuilder class One { + public static abstract @java.lang.SuppressWarnings("all") class OneBuilder<C extends SuperBuilderInitializer.One, B extends SuperBuilderInitializer.One.OneBuilder<C, B>> { + private @java.lang.SuppressWarnings("all") String world; + public OneBuilder() { + super(); + } + protected abstract @java.lang.SuppressWarnings("all") B self(); + public abstract @java.lang.SuppressWarnings("all") C build(); + /** + * @return {@code this}. + */ + public @java.lang.SuppressWarnings("all") B world(final String world) { + this.world = world; + return self(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (("SuperBuilderInitializer.One.OneBuilder(world=" + this.world) + ")"); + } + } + private static final @java.lang.SuppressWarnings("all") class OneBuilderImpl extends SuperBuilderInitializer.One.OneBuilder<SuperBuilderInitializer.One, SuperBuilderInitializer.One.OneBuilderImpl> { + private OneBuilderImpl() { + super(); + } + protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderInitializer.One.OneBuilderImpl self() { + return this; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderInitializer.One build() { + return new SuperBuilderInitializer.One(this); + } + } + private String world; + { + world = "Hello"; + } + private static final String world2; + static { + world2 = "Hello"; + } + <clinit>() { + } + protected @java.lang.SuppressWarnings("all") One(final SuperBuilderInitializer.One.OneBuilder<?, ?> b) { + super(); + this.world = b.world; + } + public static @java.lang.SuppressWarnings("all") SuperBuilderInitializer.One.OneBuilder<?, ?> builder() { + return new SuperBuilderInitializer.One.OneBuilderImpl(); + } + } + SuperBuilderInitializer() { + super(); + } +} diff --git a/test/transform/resource/after-ecj/SuperBuilderNestedGenericTypes.java b/test/transform/resource/after-ecj/SuperBuilderNestedGenericTypes.java index e511b276..0c51d4ee 100644 --- a/test/transform/resource/after-ecj/SuperBuilderNestedGenericTypes.java +++ b/test/transform/resource/after-ecj/SuperBuilderNestedGenericTypes.java @@ -1,37 +1,37 @@ -public class SuperBuilderNestedGenericTypes {
- public static abstract @lombok.experimental.SuperBuilder class Generic<T extends Generic<?>> {
- public static abstract @java.lang.SuppressWarnings("all") class GenericBuilder<T extends Generic<?>, C extends SuperBuilderNestedGenericTypes.Generic<T>, B extends SuperBuilderNestedGenericTypes.Generic.GenericBuilder<T, C, B>> {
- public GenericBuilder() {
- super();
- }
- protected abstract @java.lang.SuppressWarnings("all") B self();
- public abstract @java.lang.SuppressWarnings("all") C build();
- public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
- return "SuperBuilderNestedGenericTypes.Generic.GenericBuilder()";
- }
- }
- protected @java.lang.SuppressWarnings("all") Generic(final SuperBuilderNestedGenericTypes.Generic.GenericBuilder<T, ?, ?> b) {
- super();
- }
- }
- public static abstract @lombok.experimental.SuperBuilder class NestedGeneric<T extends OtherGeneric<?>> extends Generic<NestedGeneric<? extends OtherGeneric<?>>> {
- public static abstract @java.lang.SuppressWarnings("all") class NestedGenericBuilder<T extends OtherGeneric<?>, C extends SuperBuilderNestedGenericTypes.NestedGeneric<T>, B extends SuperBuilderNestedGenericTypes.NestedGeneric.NestedGenericBuilder<T, C, B>> extends Generic.GenericBuilder<NestedGeneric<? extends OtherGeneric<?>>, C, B> {
- public NestedGenericBuilder() {
- super();
- }
- protected abstract @java.lang.Override @java.lang.SuppressWarnings("all") B self();
- public abstract @java.lang.Override @java.lang.SuppressWarnings("all") C build();
- public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
- return (("SuperBuilderNestedGenericTypes.NestedGeneric.NestedGenericBuilder(super=" + super.toString()) + ")");
- }
- }
- protected @java.lang.SuppressWarnings("all") NestedGeneric(final SuperBuilderNestedGenericTypes.NestedGeneric.NestedGenericBuilder<T, ?, ?> b) {
- super(b);
- }
- }
- public interface OtherGeneric<T> {
- }
- public SuperBuilderNestedGenericTypes() {
- super();
- }
+public class SuperBuilderNestedGenericTypes { + public static abstract @lombok.experimental.SuperBuilder class Generic<T extends Generic<?>> { + public static abstract @java.lang.SuppressWarnings("all") class GenericBuilder<T extends Generic<?>, C extends SuperBuilderNestedGenericTypes.Generic<T>, B extends SuperBuilderNestedGenericTypes.Generic.GenericBuilder<T, C, B>> { + public GenericBuilder() { + super(); + } + protected abstract @java.lang.SuppressWarnings("all") B self(); + public abstract @java.lang.SuppressWarnings("all") C build(); + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return "SuperBuilderNestedGenericTypes.Generic.GenericBuilder()"; + } + } + protected @java.lang.SuppressWarnings("all") Generic(final SuperBuilderNestedGenericTypes.Generic.GenericBuilder<T, ?, ?> b) { + super(); + } + } + public static abstract @lombok.experimental.SuperBuilder class NestedGeneric<T extends OtherGeneric<?>> extends Generic<NestedGeneric<? extends OtherGeneric<?>>> { + public static abstract @java.lang.SuppressWarnings("all") class NestedGenericBuilder<T extends OtherGeneric<?>, C extends SuperBuilderNestedGenericTypes.NestedGeneric<T>, B extends SuperBuilderNestedGenericTypes.NestedGeneric.NestedGenericBuilder<T, C, B>> extends Generic.GenericBuilder<NestedGeneric<? extends OtherGeneric<?>>, C, B> { + public NestedGenericBuilder() { + super(); + } + protected abstract @java.lang.Override @java.lang.SuppressWarnings("all") B self(); + public abstract @java.lang.Override @java.lang.SuppressWarnings("all") C build(); + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (("SuperBuilderNestedGenericTypes.NestedGeneric.NestedGenericBuilder(super=" + super.toString()) + ")"); + } + } + protected @java.lang.SuppressWarnings("all") NestedGeneric(final SuperBuilderNestedGenericTypes.NestedGeneric.NestedGenericBuilder<T, ?, ?> b) { + super(b); + } + } + public interface OtherGeneric<T> { + } + public SuperBuilderNestedGenericTypes() { + super(); + } }
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/SuperBuilderSingularCustomized.java b/test/transform/resource/after-ecj/SuperBuilderSingularCustomized.java new file mode 100644 index 00000000..613edb03 --- /dev/null +++ b/test/transform/resource/after-ecj/SuperBuilderSingularCustomized.java @@ -0,0 +1,70 @@ +import java.util.Set; +@lombok.experimental.SuperBuilder class SuperBuilderSingularCustomized { + public static abstract class SuperBuilderSingularCustomizedBuilder<C extends SuperBuilderSingularCustomized, B extends SuperBuilderSingularCustomized.SuperBuilderSingularCustomizedBuilder<C, B>> { + private @java.lang.SuppressWarnings("all") java.util.ArrayList<String> foos; + public SuperBuilderSingularCustomizedBuilder() { + super(); + } + public B custom(final String value) { + return self(); + } + protected abstract @java.lang.SuppressWarnings("all") B self(); + public abstract @java.lang.SuppressWarnings("all") C build(); + public @java.lang.SuppressWarnings("all") B foo(final String foo) { + if ((this.foos == null)) + this.foos = new java.util.ArrayList<String>(); + this.foos.add(foo); + return self(); + } + public @java.lang.SuppressWarnings("all") B foos(final java.util.Collection<? extends String> foos) { + if ((foos == null)) + { + throw new java.lang.NullPointerException("foos cannot be null"); + } + if ((this.foos == null)) + this.foos = new java.util.ArrayList<String>(); + this.foos.addAll(foos); + return self(); + } + public @java.lang.SuppressWarnings("all") B clearFoos() { + if ((this.foos != null)) + this.foos.clear(); + return self(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (("SuperBuilderSingularCustomized.SuperBuilderSingularCustomizedBuilder(foos=" + this.foos) + ")"); + } + } + private static final @java.lang.SuppressWarnings("all") class SuperBuilderSingularCustomizedBuilderImpl extends SuperBuilderSingularCustomized.SuperBuilderSingularCustomizedBuilder<SuperBuilderSingularCustomized, SuperBuilderSingularCustomized.SuperBuilderSingularCustomizedBuilderImpl> { + private SuperBuilderSingularCustomizedBuilderImpl() { + super(); + } + protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderSingularCustomized.SuperBuilderSingularCustomizedBuilderImpl self() { + return this; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderSingularCustomized build() { + return new SuperBuilderSingularCustomized(this); + } + } + private @lombok.Singular Set<String> foos; + protected @java.lang.SuppressWarnings("all") SuperBuilderSingularCustomized(final SuperBuilderSingularCustomized.SuperBuilderSingularCustomizedBuilder<?, ?> b) { + super(); + java.util.Set<String> foos; + switch (((b.foos == null) ? 0 : b.foos.size())) { + case 0 : + foos = java.util.Collections.emptySet(); + break; + case 1 : + foos = java.util.Collections.singleton(b.foos.get(0)); + break; + default : + foos = new java.util.LinkedHashSet<String>(((b.foos.size() < 0x40000000) ? ((1 + b.foos.size()) + ((b.foos.size() - 3) / 3)) : java.lang.Integer.MAX_VALUE)); + foos.addAll(b.foos); + foos = java.util.Collections.unmodifiableSet(foos); + } + this.foos = foos; + } + public static @java.lang.SuppressWarnings("all") SuperBuilderSingularCustomized.SuperBuilderSingularCustomizedBuilder<?, ?> builder() { + return new SuperBuilderSingularCustomized.SuperBuilderSingularCustomizedBuilderImpl(); + } +}
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/SuperBuilderWithCustomBuilderMethod.java b/test/transform/resource/after-ecj/SuperBuilderWithCustomBuilderMethod.java index 5438f576..93b78c3d 100644 --- a/test/transform/resource/after-ecj/SuperBuilderWithCustomBuilderMethod.java +++ b/test/transform/resource/after-ecj/SuperBuilderWithCustomBuilderMethod.java @@ -1,122 +1,122 @@ -import java.util.List;
-public class SuperBuilderWithCustomBuilderMethod {
- public static @lombok.experimental.SuperBuilder class Parent<A> {
- public static abstract @java.lang.SuppressWarnings("all") class ParentBuilder<A, C extends SuperBuilderWithCustomBuilderMethod.Parent<A>, B extends SuperBuilderWithCustomBuilderMethod.Parent.ParentBuilder<A, C, B>> {
- private @java.lang.SuppressWarnings("all") A field1;
- private @java.lang.SuppressWarnings("all") java.util.ArrayList<String> items;
- public ParentBuilder() {
- super();
- }
- protected abstract @java.lang.SuppressWarnings("all") B self();
- public abstract @java.lang.SuppressWarnings("all") C build();
- /**
- * @return {@code this}.
- */
- public @java.lang.SuppressWarnings("all") B field1(final A field1) {
- this.field1 = field1;
- return self();
- }
- public @java.lang.SuppressWarnings("all") B item(final String item) {
- if ((this.items == null))
- this.items = new java.util.ArrayList<String>();
- this.items.add(item);
- return self();
- }
- public @java.lang.SuppressWarnings("all") B items(final java.util.Collection<? extends String> items) {
- if ((items == null))
- {
- throw new java.lang.NullPointerException("items cannot be null");
- }
- if ((this.items == null))
- this.items = new java.util.ArrayList<String>();
- this.items.addAll(items);
- return self();
- }
- public @java.lang.SuppressWarnings("all") B clearItems() {
- if ((this.items != null))
- this.items.clear();
- return self();
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
- return (((("SuperBuilderWithCustomBuilderMethod.Parent.ParentBuilder(field1=" + this.field1) + ", items=") + this.items) + ")");
- }
- }
- private static final @java.lang.SuppressWarnings("all") class ParentBuilderImpl<A> extends SuperBuilderWithCustomBuilderMethod.Parent.ParentBuilder<A, SuperBuilderWithCustomBuilderMethod.Parent<A>, SuperBuilderWithCustomBuilderMethod.Parent.ParentBuilderImpl<A>> {
- private ParentBuilderImpl() {
- super();
- }
- protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithCustomBuilderMethod.Parent.ParentBuilderImpl<A> self() {
- return this;
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithCustomBuilderMethod.Parent<A> build() {
- return new SuperBuilderWithCustomBuilderMethod.Parent<A>(this);
- }
- }
- A field1;
- @lombok.Singular List<String> items;
- protected @java.lang.SuppressWarnings("all") Parent(final SuperBuilderWithCustomBuilderMethod.Parent.ParentBuilder<A, ?, ?> b) {
- super();
- this.field1 = b.field1;
- java.util.List<String> items;
- switch (((b.items == null) ? 0 : b.items.size())) {
- case 0 :
- items = java.util.Collections.emptyList();
- break;
- case 1 :
- items = java.util.Collections.singletonList(b.items.get(0));
- break;
- default :
- items = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(b.items));
- }
- this.items = items;
- }
- public static @java.lang.SuppressWarnings("all") <A>SuperBuilderWithCustomBuilderMethod.Parent.ParentBuilder<A, ?, ?> builder() {
- return new SuperBuilderWithCustomBuilderMethod.Parent.ParentBuilderImpl<A>();
- }
- }
- public static @lombok.experimental.SuperBuilder class Child<A> extends Parent<A> {
- public static abstract @java.lang.SuppressWarnings("all") class ChildBuilder<A, C extends SuperBuilderWithCustomBuilderMethod.Child<A>, B extends SuperBuilderWithCustomBuilderMethod.Child.ChildBuilder<A, C, B>> extends Parent.ParentBuilder<A, C, B> {
- private @java.lang.SuppressWarnings("all") double field3;
- public ChildBuilder() {
- super();
- }
- protected abstract @java.lang.Override @java.lang.SuppressWarnings("all") B self();
- public abstract @java.lang.Override @java.lang.SuppressWarnings("all") C build();
- /**
- * @return {@code this}.
- */
- public @java.lang.SuppressWarnings("all") B field3(final double field3) {
- this.field3 = field3;
- return self();
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
- return (((("SuperBuilderWithCustomBuilderMethod.Child.ChildBuilder(super=" + super.toString()) + ", field3=") + this.field3) + ")");
- }
- }
- private static final @java.lang.SuppressWarnings("all") class ChildBuilderImpl<A> extends SuperBuilderWithCustomBuilderMethod.Child.ChildBuilder<A, SuperBuilderWithCustomBuilderMethod.Child<A>, SuperBuilderWithCustomBuilderMethod.Child.ChildBuilderImpl<A>> {
- private ChildBuilderImpl() {
- super();
- }
- protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithCustomBuilderMethod.Child.ChildBuilderImpl<A> self() {
- return this;
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithCustomBuilderMethod.Child<A> build() {
- return new SuperBuilderWithCustomBuilderMethod.Child<A>(this);
- }
- }
- double field3;
- public static <A>ChildBuilder<A, ?, ?> builder() {
- return new ChildBuilderImpl<A>().item("default item");
- }
- protected @java.lang.SuppressWarnings("all") Child(final SuperBuilderWithCustomBuilderMethod.Child.ChildBuilder<A, ?, ?> b) {
- super(b);
- this.field3 = b.field3;
- }
- }
- public SuperBuilderWithCustomBuilderMethod() {
- super();
- }
- public static void test() {
- Child<Integer> x = Child.<Integer>builder().field3(0.0).field1(5).item("").build();
- }
-}
+import java.util.List; +public class SuperBuilderWithCustomBuilderMethod { + public static @lombok.experimental.SuperBuilder class Parent<A> { + public static abstract @java.lang.SuppressWarnings("all") class ParentBuilder<A, C extends SuperBuilderWithCustomBuilderMethod.Parent<A>, B extends SuperBuilderWithCustomBuilderMethod.Parent.ParentBuilder<A, C, B>> { + private @java.lang.SuppressWarnings("all") A field1; + private @java.lang.SuppressWarnings("all") java.util.ArrayList<String> items; + public ParentBuilder() { + super(); + } + protected abstract @java.lang.SuppressWarnings("all") B self(); + public abstract @java.lang.SuppressWarnings("all") C build(); + /** + * @return {@code this}. + */ + public @java.lang.SuppressWarnings("all") B field1(final A field1) { + this.field1 = field1; + return self(); + } + public @java.lang.SuppressWarnings("all") B item(final String item) { + if ((this.items == null)) + this.items = new java.util.ArrayList<String>(); + this.items.add(item); + return self(); + } + public @java.lang.SuppressWarnings("all") B items(final java.util.Collection<? extends String> items) { + if ((items == null)) + { + throw new java.lang.NullPointerException("items cannot be null"); + } + if ((this.items == null)) + this.items = new java.util.ArrayList<String>(); + this.items.addAll(items); + return self(); + } + public @java.lang.SuppressWarnings("all") B clearItems() { + if ((this.items != null)) + this.items.clear(); + return self(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (((("SuperBuilderWithCustomBuilderMethod.Parent.ParentBuilder(field1=" + this.field1) + ", items=") + this.items) + ")"); + } + } + private static final @java.lang.SuppressWarnings("all") class ParentBuilderImpl<A> extends SuperBuilderWithCustomBuilderMethod.Parent.ParentBuilder<A, SuperBuilderWithCustomBuilderMethod.Parent<A>, SuperBuilderWithCustomBuilderMethod.Parent.ParentBuilderImpl<A>> { + private ParentBuilderImpl() { + super(); + } + protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithCustomBuilderMethod.Parent.ParentBuilderImpl<A> self() { + return this; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithCustomBuilderMethod.Parent<A> build() { + return new SuperBuilderWithCustomBuilderMethod.Parent<A>(this); + } + } + A field1; + @lombok.Singular List<String> items; + protected @java.lang.SuppressWarnings("all") Parent(final SuperBuilderWithCustomBuilderMethod.Parent.ParentBuilder<A, ?, ?> b) { + super(); + this.field1 = b.field1; + java.util.List<String> items; + switch (((b.items == null) ? 0 : b.items.size())) { + case 0 : + items = java.util.Collections.emptyList(); + break; + case 1 : + items = java.util.Collections.singletonList(b.items.get(0)); + break; + default : + items = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(b.items)); + } + this.items = items; + } + public static @java.lang.SuppressWarnings("all") <A>SuperBuilderWithCustomBuilderMethod.Parent.ParentBuilder<A, ?, ?> builder() { + return new SuperBuilderWithCustomBuilderMethod.Parent.ParentBuilderImpl<A>(); + } + } + public static @lombok.experimental.SuperBuilder class Child<A> extends Parent<A> { + public static abstract @java.lang.SuppressWarnings("all") class ChildBuilder<A, C extends SuperBuilderWithCustomBuilderMethod.Child<A>, B extends SuperBuilderWithCustomBuilderMethod.Child.ChildBuilder<A, C, B>> extends Parent.ParentBuilder<A, C, B> { + private @java.lang.SuppressWarnings("all") double field3; + public ChildBuilder() { + super(); + } + protected abstract @java.lang.Override @java.lang.SuppressWarnings("all") B self(); + public abstract @java.lang.Override @java.lang.SuppressWarnings("all") C build(); + /** + * @return {@code this}. + */ + public @java.lang.SuppressWarnings("all") B field3(final double field3) { + this.field3 = field3; + return self(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (((("SuperBuilderWithCustomBuilderMethod.Child.ChildBuilder(super=" + super.toString()) + ", field3=") + this.field3) + ")"); + } + } + private static final @java.lang.SuppressWarnings("all") class ChildBuilderImpl<A> extends SuperBuilderWithCustomBuilderMethod.Child.ChildBuilder<A, SuperBuilderWithCustomBuilderMethod.Child<A>, SuperBuilderWithCustomBuilderMethod.Child.ChildBuilderImpl<A>> { + private ChildBuilderImpl() { + super(); + } + protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithCustomBuilderMethod.Child.ChildBuilderImpl<A> self() { + return this; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithCustomBuilderMethod.Child<A> build() { + return new SuperBuilderWithCustomBuilderMethod.Child<A>(this); + } + } + double field3; + public static <A>ChildBuilder<A, ?, ?> builder() { + return new ChildBuilderImpl<A>().item("default item"); + } + protected @java.lang.SuppressWarnings("all") Child(final SuperBuilderWithCustomBuilderMethod.Child.ChildBuilder<A, ?, ?> b) { + super(b); + this.field3 = b.field3; + } + } + public SuperBuilderWithCustomBuilderMethod() { + super(); + } + public static void test() { + Child<Integer> x = Child.<Integer>builder().field3(0.0).field1(5).item("").build(); + } +} diff --git a/test/transform/resource/after-ecj/SuperBuilderWithDefaults.java b/test/transform/resource/after-ecj/SuperBuilderWithDefaults.java index 72079b2f..7c5a344a 100644 --- a/test/transform/resource/after-ecj/SuperBuilderWithDefaults.java +++ b/test/transform/resource/after-ecj/SuperBuilderWithDefaults.java @@ -1,121 +1,121 @@ -import java.util.List;
-public class SuperBuilderWithDefaults {
- public static @lombok.experimental.SuperBuilder class Parent<N extends Number> {
- public static abstract @java.lang.SuppressWarnings("all") class ParentBuilder<N extends Number, C extends SuperBuilderWithDefaults.Parent<N>, B extends SuperBuilderWithDefaults.Parent.ParentBuilder<N, C, B>> {
- private @java.lang.SuppressWarnings("all") long millis$value;
- private @java.lang.SuppressWarnings("all") boolean millis$set;
- private @java.lang.SuppressWarnings("all") N numberField$value;
- private @java.lang.SuppressWarnings("all") boolean numberField$set;
- public ParentBuilder() {
- super();
- }
- protected abstract @java.lang.SuppressWarnings("all") B self();
- public abstract @java.lang.SuppressWarnings("all") C build();
- /**
- * @return {@code this}.
- */
- public @java.lang.SuppressWarnings("all") B millis(final long millis) {
- this.millis$value = millis;
- millis$set = true;
- return self();
- }
- /**
- * @return {@code this}.
- */
- public @java.lang.SuppressWarnings("all") B numberField(final N numberField) {
- this.numberField$value = numberField;
- numberField$set = true;
- return self();
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
- return (((("SuperBuilderWithDefaults.Parent.ParentBuilder(millis$value=" + this.millis$value) + ", numberField$value=") + this.numberField$value) + ")");
- }
- }
- private static final @java.lang.SuppressWarnings("all") class ParentBuilderImpl<N extends Number> extends SuperBuilderWithDefaults.Parent.ParentBuilder<N, SuperBuilderWithDefaults.Parent<N>, SuperBuilderWithDefaults.Parent.ParentBuilderImpl<N>> {
- private ParentBuilderImpl() {
- super();
- }
- protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithDefaults.Parent.ParentBuilderImpl<N> self() {
- return this;
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithDefaults.Parent<N> build() {
- return new SuperBuilderWithDefaults.Parent<N>(this);
- }
- }
- private @lombok.Builder.Default long millis;
- private @lombok.Builder.Default N numberField;
- private static @java.lang.SuppressWarnings("all") <N extends Number>long $default$millis() {
- return System.currentTimeMillis();
- }
- private static @java.lang.SuppressWarnings("all") <N extends Number>N $default$numberField() {
- return null;
- }
- protected @java.lang.SuppressWarnings("all") Parent(final SuperBuilderWithDefaults.Parent.ParentBuilder<N, ?, ?> b) {
- super();
- if (b.millis$set)
- this.millis = b.millis$value;
- else
- this.millis = SuperBuilderWithDefaults.Parent.<N>$default$millis();
- if (b.numberField$set)
- this.numberField = b.numberField$value;
- else
- this.numberField = SuperBuilderWithDefaults.Parent.<N>$default$numberField();
- }
- public static @java.lang.SuppressWarnings("all") <N extends Number>SuperBuilderWithDefaults.Parent.ParentBuilder<N, ?, ?> builder() {
- return new SuperBuilderWithDefaults.Parent.ParentBuilderImpl<N>();
- }
- }
- public static @lombok.experimental.SuperBuilder class Child extends Parent<Integer> {
- public static abstract @java.lang.SuppressWarnings("all") class ChildBuilder<C extends SuperBuilderWithDefaults.Child, B extends SuperBuilderWithDefaults.Child.ChildBuilder<C, B>> extends Parent.ParentBuilder<Integer, C, B> {
- private @java.lang.SuppressWarnings("all") double doubleField$value;
- private @java.lang.SuppressWarnings("all") boolean doubleField$set;
- public ChildBuilder() {
- super();
- }
- protected abstract @java.lang.Override @java.lang.SuppressWarnings("all") B self();
- public abstract @java.lang.Override @java.lang.SuppressWarnings("all") C build();
- /**
- * @return {@code this}.
- */
- public @java.lang.SuppressWarnings("all") B doubleField(final double doubleField) {
- this.doubleField$value = doubleField;
- doubleField$set = true;
- return self();
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
- return (((("SuperBuilderWithDefaults.Child.ChildBuilder(super=" + super.toString()) + ", doubleField$value=") + this.doubleField$value) + ")");
- }
- }
- private static final @java.lang.SuppressWarnings("all") class ChildBuilderImpl extends SuperBuilderWithDefaults.Child.ChildBuilder<SuperBuilderWithDefaults.Child, SuperBuilderWithDefaults.Child.ChildBuilderImpl> {
- private ChildBuilderImpl() {
- super();
- }
- protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithDefaults.Child.ChildBuilderImpl self() {
- return this;
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithDefaults.Child build() {
- return new SuperBuilderWithDefaults.Child(this);
- }
- }
- private @lombok.Builder.Default double doubleField;
- private static @java.lang.SuppressWarnings("all") double $default$doubleField() {
- return Math.PI;
- }
- protected @java.lang.SuppressWarnings("all") Child(final SuperBuilderWithDefaults.Child.ChildBuilder<?, ?> b) {
- super(b);
- if (b.doubleField$set)
- this.doubleField = b.doubleField$value;
- else
- this.doubleField = SuperBuilderWithDefaults.Child.$default$doubleField();
- }
- public static @java.lang.SuppressWarnings("all") SuperBuilderWithDefaults.Child.ChildBuilder<?, ?> builder() {
- return new SuperBuilderWithDefaults.Child.ChildBuilderImpl();
- }
- }
- public SuperBuilderWithDefaults() {
- super();
- }
- public static void test() {
- Child x = Child.builder().doubleField(0.1).numberField(5).millis(1234567890L).build();
- }
-}
+import java.util.List; +public class SuperBuilderWithDefaults { + public static @lombok.experimental.SuperBuilder class Parent<N extends Number> { + public static abstract @java.lang.SuppressWarnings("all") class ParentBuilder<N extends Number, C extends SuperBuilderWithDefaults.Parent<N>, B extends SuperBuilderWithDefaults.Parent.ParentBuilder<N, C, B>> { + private @java.lang.SuppressWarnings("all") long millis$value; + private @java.lang.SuppressWarnings("all") boolean millis$set; + private @java.lang.SuppressWarnings("all") N numberField$value; + private @java.lang.SuppressWarnings("all") boolean numberField$set; + public ParentBuilder() { + super(); + } + protected abstract @java.lang.SuppressWarnings("all") B self(); + public abstract @java.lang.SuppressWarnings("all") C build(); + /** + * @return {@code this}. + */ + public @java.lang.SuppressWarnings("all") B millis(final long millis) { + this.millis$value = millis; + millis$set = true; + return self(); + } + /** + * @return {@code this}. + */ + public @java.lang.SuppressWarnings("all") B numberField(final N numberField) { + this.numberField$value = numberField; + numberField$set = true; + return self(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (((("SuperBuilderWithDefaults.Parent.ParentBuilder(millis$value=" + this.millis$value) + ", numberField$value=") + this.numberField$value) + ")"); + } + } + private static final @java.lang.SuppressWarnings("all") class ParentBuilderImpl<N extends Number> extends SuperBuilderWithDefaults.Parent.ParentBuilder<N, SuperBuilderWithDefaults.Parent<N>, SuperBuilderWithDefaults.Parent.ParentBuilderImpl<N>> { + private ParentBuilderImpl() { + super(); + } + protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithDefaults.Parent.ParentBuilderImpl<N> self() { + return this; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithDefaults.Parent<N> build() { + return new SuperBuilderWithDefaults.Parent<N>(this); + } + } + private @lombok.Builder.Default long millis; + private @lombok.Builder.Default N numberField; + private static @java.lang.SuppressWarnings("all") <N extends Number>long $default$millis() { + return System.currentTimeMillis(); + } + private static @java.lang.SuppressWarnings("all") <N extends Number>N $default$numberField() { + return null; + } + protected @java.lang.SuppressWarnings("all") Parent(final SuperBuilderWithDefaults.Parent.ParentBuilder<N, ?, ?> b) { + super(); + if (b.millis$set) + this.millis = b.millis$value; + else + this.millis = SuperBuilderWithDefaults.Parent.<N>$default$millis(); + if (b.numberField$set) + this.numberField = b.numberField$value; + else + this.numberField = SuperBuilderWithDefaults.Parent.<N>$default$numberField(); + } + public static @java.lang.SuppressWarnings("all") <N extends Number>SuperBuilderWithDefaults.Parent.ParentBuilder<N, ?, ?> builder() { + return new SuperBuilderWithDefaults.Parent.ParentBuilderImpl<N>(); + } + } + public static @lombok.experimental.SuperBuilder class Child extends Parent<Integer> { + public static abstract @java.lang.SuppressWarnings("all") class ChildBuilder<C extends SuperBuilderWithDefaults.Child, B extends SuperBuilderWithDefaults.Child.ChildBuilder<C, B>> extends Parent.ParentBuilder<Integer, C, B> { + private @java.lang.SuppressWarnings("all") double doubleField$value; + private @java.lang.SuppressWarnings("all") boolean doubleField$set; + public ChildBuilder() { + super(); + } + protected abstract @java.lang.Override @java.lang.SuppressWarnings("all") B self(); + public abstract @java.lang.Override @java.lang.SuppressWarnings("all") C build(); + /** + * @return {@code this}. + */ + public @java.lang.SuppressWarnings("all") B doubleField(final double doubleField) { + this.doubleField$value = doubleField; + doubleField$set = true; + return self(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (((("SuperBuilderWithDefaults.Child.ChildBuilder(super=" + super.toString()) + ", doubleField$value=") + this.doubleField$value) + ")"); + } + } + private static final @java.lang.SuppressWarnings("all") class ChildBuilderImpl extends SuperBuilderWithDefaults.Child.ChildBuilder<SuperBuilderWithDefaults.Child, SuperBuilderWithDefaults.Child.ChildBuilderImpl> { + private ChildBuilderImpl() { + super(); + } + protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithDefaults.Child.ChildBuilderImpl self() { + return this; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithDefaults.Child build() { + return new SuperBuilderWithDefaults.Child(this); + } + } + private @lombok.Builder.Default double doubleField; + private static @java.lang.SuppressWarnings("all") double $default$doubleField() { + return Math.PI; + } + protected @java.lang.SuppressWarnings("all") Child(final SuperBuilderWithDefaults.Child.ChildBuilder<?, ?> b) { + super(b); + if (b.doubleField$set) + this.doubleField = b.doubleField$value; + else + this.doubleField = SuperBuilderWithDefaults.Child.$default$doubleField(); + } + public static @java.lang.SuppressWarnings("all") SuperBuilderWithDefaults.Child.ChildBuilder<?, ?> builder() { + return new SuperBuilderWithDefaults.Child.ChildBuilderImpl(); + } + } + public SuperBuilderWithDefaults() { + super(); + } + public static void test() { + Child x = Child.builder().doubleField(0.1).numberField(5).millis(1234567890L).build(); + } +} diff --git a/test/transform/resource/after-ecj/SuperBuilderWithExistingConstructor.java b/test/transform/resource/after-ecj/SuperBuilderWithExistingConstructor.java new file mode 100644 index 00000000..d42c3ca7 --- /dev/null +++ b/test/transform/resource/after-ecj/SuperBuilderWithExistingConstructor.java @@ -0,0 +1,32 @@ +public @lombok.experimental.SuperBuilder class SuperBuilderWithExistingConstructor { + public static abstract @java.lang.SuppressWarnings("all") class SuperBuilderWithExistingConstructorBuilder<C extends SuperBuilderWithExistingConstructor, B extends SuperBuilderWithExistingConstructor.SuperBuilderWithExistingConstructorBuilder<C, B>> { + public SuperBuilderWithExistingConstructorBuilder() { + super(); + } + protected abstract @java.lang.SuppressWarnings("all") B self(); + public abstract @java.lang.SuppressWarnings("all") C build(); + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return "SuperBuilderWithExistingConstructor.SuperBuilderWithExistingConstructorBuilder()"; + } + } + private static final @java.lang.SuppressWarnings("all") class SuperBuilderWithExistingConstructorBuilderImpl extends SuperBuilderWithExistingConstructor.SuperBuilderWithExistingConstructorBuilder<SuperBuilderWithExistingConstructor, SuperBuilderWithExistingConstructor.SuperBuilderWithExistingConstructorBuilderImpl> { + private SuperBuilderWithExistingConstructorBuilderImpl() { + super(); + } + protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithExistingConstructor.SuperBuilderWithExistingConstructorBuilderImpl self() { + return this; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithExistingConstructor build() { + return new SuperBuilderWithExistingConstructor(this); + } + } + public SuperBuilderWithExistingConstructor() { + super(); + } + protected @java.lang.SuppressWarnings("all") SuperBuilderWithExistingConstructor(final SuperBuilderWithExistingConstructor.SuperBuilderWithExistingConstructorBuilder<?, ?> b) { + super(); + } + public static @java.lang.SuppressWarnings("all") SuperBuilderWithExistingConstructor.SuperBuilderWithExistingConstructorBuilder<?, ?> builder() { + return new SuperBuilderWithExistingConstructor.SuperBuilderWithExistingConstructorBuilderImpl(); + } +}
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/SuperBuilderWithGenerics.java b/test/transform/resource/after-ecj/SuperBuilderWithGenerics.java index bc9db55f..db989687 100644 --- a/test/transform/resource/after-ecj/SuperBuilderWithGenerics.java +++ b/test/transform/resource/after-ecj/SuperBuilderWithGenerics.java @@ -1,122 +1,122 @@ -import java.util.List;
-public class SuperBuilderWithGenerics {
- public static @lombok.experimental.SuperBuilder class Parent<A> {
- public static abstract @java.lang.SuppressWarnings("all") class ParentBuilder<A, C extends SuperBuilderWithGenerics.Parent<A>, B extends SuperBuilderWithGenerics.Parent.ParentBuilder<A, C, B>> {
- private @java.lang.SuppressWarnings("all") A field1;
- private @java.lang.SuppressWarnings("all") java.util.ArrayList<String> items;
- public ParentBuilder() {
- super();
- }
- protected abstract @java.lang.SuppressWarnings("all") B self();
- public abstract @java.lang.SuppressWarnings("all") C build();
- /**
- * @return {@code this}.
- */
- public @java.lang.SuppressWarnings("all") B field1(final A field1) {
- this.field1 = field1;
- return self();
- }
- public @java.lang.SuppressWarnings("all") B item(final String item) {
- if ((this.items == null))
- this.items = new java.util.ArrayList<String>();
- this.items.add(item);
- return self();
- }
- public @java.lang.SuppressWarnings("all") B items(final java.util.Collection<? extends String> items) {
- if ((items == null))
- {
- throw new java.lang.NullPointerException("items cannot be null");
- }
- if ((this.items == null))
- this.items = new java.util.ArrayList<String>();
- this.items.addAll(items);
- return self();
- }
- public @java.lang.SuppressWarnings("all") B clearItems() {
- if ((this.items != null))
- this.items.clear();
- return self();
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
- return (((("SuperBuilderWithGenerics.Parent.ParentBuilder(field1=" + this.field1) + ", items=") + this.items) + ")");
- }
- }
- private static final @java.lang.SuppressWarnings("all") class ParentBuilderImpl<A> extends SuperBuilderWithGenerics.Parent.ParentBuilder<A, SuperBuilderWithGenerics.Parent<A>, SuperBuilderWithGenerics.Parent.ParentBuilderImpl<A>> {
- private ParentBuilderImpl() {
- super();
- }
- protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithGenerics.Parent.ParentBuilderImpl<A> self() {
- return this;
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithGenerics.Parent<A> build() {
- return new SuperBuilderWithGenerics.Parent<A>(this);
- }
- }
- A field1;
- @lombok.Singular List<String> items;
- protected @java.lang.SuppressWarnings("all") Parent(final SuperBuilderWithGenerics.Parent.ParentBuilder<A, ?, ?> b) {
- super();
- this.field1 = b.field1;
- java.util.List<String> items;
- switch (((b.items == null) ? 0 : b.items.size())) {
- case 0 :
- items = java.util.Collections.emptyList();
- break;
- case 1 :
- items = java.util.Collections.singletonList(b.items.get(0));
- break;
- default :
- items = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(b.items));
- }
- this.items = items;
- }
- public static @java.lang.SuppressWarnings("all") <A>SuperBuilderWithGenerics.Parent.ParentBuilder<A, ?, ?> builder() {
- return new SuperBuilderWithGenerics.Parent.ParentBuilderImpl<A>();
- }
- }
- public static @lombok.experimental.SuperBuilder class Child<A> extends Parent<A> {
- public static abstract @java.lang.SuppressWarnings("all") class ChildBuilder<A, C extends SuperBuilderWithGenerics.Child<A>, B extends SuperBuilderWithGenerics.Child.ChildBuilder<A, C, B>> extends Parent.ParentBuilder<A, C, B> {
- private @java.lang.SuppressWarnings("all") double field3;
- public ChildBuilder() {
- super();
- }
- protected abstract @java.lang.Override @java.lang.SuppressWarnings("all") B self();
- public abstract @java.lang.Override @java.lang.SuppressWarnings("all") C build();
- /**
- * @return {@code this}.
- */
- public @java.lang.SuppressWarnings("all") B field3(final double field3) {
- this.field3 = field3;
- return self();
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
- return (((("SuperBuilderWithGenerics.Child.ChildBuilder(super=" + super.toString()) + ", field3=") + this.field3) + ")");
- }
- }
- private static final @java.lang.SuppressWarnings("all") class ChildBuilderImpl<A> extends SuperBuilderWithGenerics.Child.ChildBuilder<A, SuperBuilderWithGenerics.Child<A>, SuperBuilderWithGenerics.Child.ChildBuilderImpl<A>> {
- private ChildBuilderImpl() {
- super();
- }
- protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithGenerics.Child.ChildBuilderImpl<A> self() {
- return this;
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithGenerics.Child<A> build() {
- return new SuperBuilderWithGenerics.Child<A>(this);
- }
- }
- double field3;
- protected @java.lang.SuppressWarnings("all") Child(final SuperBuilderWithGenerics.Child.ChildBuilder<A, ?, ?> b) {
- super(b);
- this.field3 = b.field3;
- }
- public static @java.lang.SuppressWarnings("all") <A>SuperBuilderWithGenerics.Child.ChildBuilder<A, ?, ?> builder() {
- return new SuperBuilderWithGenerics.Child.ChildBuilderImpl<A>();
- }
- }
- public SuperBuilderWithGenerics() {
- super();
- }
- public static void test() {
- Child<Integer> x = Child.<Integer>builder().field3(0.0).field1(5).item("").build();
- }
-}
+import java.util.List; +public class SuperBuilderWithGenerics { + public static @lombok.experimental.SuperBuilder class Parent<A> { + public static abstract @java.lang.SuppressWarnings("all") class ParentBuilder<A, C extends SuperBuilderWithGenerics.Parent<A>, B extends SuperBuilderWithGenerics.Parent.ParentBuilder<A, C, B>> { + private @java.lang.SuppressWarnings("all") A field1; + private @java.lang.SuppressWarnings("all") java.util.ArrayList<String> items; + public ParentBuilder() { + super(); + } + protected abstract @java.lang.SuppressWarnings("all") B self(); + public abstract @java.lang.SuppressWarnings("all") C build(); + /** + * @return {@code this}. + */ + public @java.lang.SuppressWarnings("all") B field1(final A field1) { + this.field1 = field1; + return self(); + } + public @java.lang.SuppressWarnings("all") B item(final String item) { + if ((this.items == null)) + this.items = new java.util.ArrayList<String>(); + this.items.add(item); + return self(); + } + public @java.lang.SuppressWarnings("all") B items(final java.util.Collection<? extends String> items) { + if ((items == null)) + { + throw new java.lang.NullPointerException("items cannot be null"); + } + if ((this.items == null)) + this.items = new java.util.ArrayList<String>(); + this.items.addAll(items); + return self(); + } + public @java.lang.SuppressWarnings("all") B clearItems() { + if ((this.items != null)) + this.items.clear(); + return self(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (((("SuperBuilderWithGenerics.Parent.ParentBuilder(field1=" + this.field1) + ", items=") + this.items) + ")"); + } + } + private static final @java.lang.SuppressWarnings("all") class ParentBuilderImpl<A> extends SuperBuilderWithGenerics.Parent.ParentBuilder<A, SuperBuilderWithGenerics.Parent<A>, SuperBuilderWithGenerics.Parent.ParentBuilderImpl<A>> { + private ParentBuilderImpl() { + super(); + } + protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithGenerics.Parent.ParentBuilderImpl<A> self() { + return this; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithGenerics.Parent<A> build() { + return new SuperBuilderWithGenerics.Parent<A>(this); + } + } + A field1; + @lombok.Singular List<String> items; + protected @java.lang.SuppressWarnings("all") Parent(final SuperBuilderWithGenerics.Parent.ParentBuilder<A, ?, ?> b) { + super(); + this.field1 = b.field1; + java.util.List<String> items; + switch (((b.items == null) ? 0 : b.items.size())) { + case 0 : + items = java.util.Collections.emptyList(); + break; + case 1 : + items = java.util.Collections.singletonList(b.items.get(0)); + break; + default : + items = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(b.items)); + } + this.items = items; + } + public static @java.lang.SuppressWarnings("all") <A>SuperBuilderWithGenerics.Parent.ParentBuilder<A, ?, ?> builder() { + return new SuperBuilderWithGenerics.Parent.ParentBuilderImpl<A>(); + } + } + public static @lombok.experimental.SuperBuilder class Child<A> extends Parent<A> { + public static abstract @java.lang.SuppressWarnings("all") class ChildBuilder<A, C extends SuperBuilderWithGenerics.Child<A>, B extends SuperBuilderWithGenerics.Child.ChildBuilder<A, C, B>> extends Parent.ParentBuilder<A, C, B> { + private @java.lang.SuppressWarnings("all") double field3; + public ChildBuilder() { + super(); + } + protected abstract @java.lang.Override @java.lang.SuppressWarnings("all") B self(); + public abstract @java.lang.Override @java.lang.SuppressWarnings("all") C build(); + /** + * @return {@code this}. + */ + public @java.lang.SuppressWarnings("all") B field3(final double field3) { + this.field3 = field3; + return self(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (((("SuperBuilderWithGenerics.Child.ChildBuilder(super=" + super.toString()) + ", field3=") + this.field3) + ")"); + } + } + private static final @java.lang.SuppressWarnings("all") class ChildBuilderImpl<A> extends SuperBuilderWithGenerics.Child.ChildBuilder<A, SuperBuilderWithGenerics.Child<A>, SuperBuilderWithGenerics.Child.ChildBuilderImpl<A>> { + private ChildBuilderImpl() { + super(); + } + protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithGenerics.Child.ChildBuilderImpl<A> self() { + return this; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithGenerics.Child<A> build() { + return new SuperBuilderWithGenerics.Child<A>(this); + } + } + double field3; + protected @java.lang.SuppressWarnings("all") Child(final SuperBuilderWithGenerics.Child.ChildBuilder<A, ?, ?> b) { + super(b); + this.field3 = b.field3; + } + public static @java.lang.SuppressWarnings("all") <A>SuperBuilderWithGenerics.Child.ChildBuilder<A, ?, ?> builder() { + return new SuperBuilderWithGenerics.Child.ChildBuilderImpl<A>(); + } + } + public SuperBuilderWithGenerics() { + super(); + } + public static void test() { + Child<Integer> x = Child.<Integer>builder().field3(0.0).field1(5).item("").build(); + } +} diff --git a/test/transform/resource/after-ecj/SuperBuilderWithGenerics2.java b/test/transform/resource/after-ecj/SuperBuilderWithGenerics2.java index 07d10798..96e681f4 100644 --- a/test/transform/resource/after-ecj/SuperBuilderWithGenerics2.java +++ b/test/transform/resource/after-ecj/SuperBuilderWithGenerics2.java @@ -1,122 +1,122 @@ -import java.util.List;
-public class SuperBuilderWithGenerics2 {
- public static @lombok.experimental.SuperBuilder class Parent<A> {
- public static abstract @java.lang.SuppressWarnings("all") class ParentBuilder<A, C extends SuperBuilderWithGenerics2.Parent<A>, B extends SuperBuilderWithGenerics2.Parent.ParentBuilder<A, C, B>> {
- private @java.lang.SuppressWarnings("all") A field1;
- private @java.lang.SuppressWarnings("all") java.util.ArrayList<String> items;
- public ParentBuilder() {
- super();
- }
- protected abstract @java.lang.SuppressWarnings("all") B self();
- public abstract @java.lang.SuppressWarnings("all") C build();
- /**
- * @return {@code this}.
- */
- public @java.lang.SuppressWarnings("all") B field1(final A field1) {
- this.field1 = field1;
- return self();
- }
- public @java.lang.SuppressWarnings("all") B item(final String item) {
- if ((this.items == null))
- this.items = new java.util.ArrayList<String>();
- this.items.add(item);
- return self();
- }
- public @java.lang.SuppressWarnings("all") B items(final java.util.Collection<? extends String> items) {
- if ((items == null))
- {
- throw new java.lang.NullPointerException("items cannot be null");
- }
- if ((this.items == null))
- this.items = new java.util.ArrayList<String>();
- this.items.addAll(items);
- return self();
- }
- public @java.lang.SuppressWarnings("all") B clearItems() {
- if ((this.items != null))
- this.items.clear();
- return self();
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
- return (((("SuperBuilderWithGenerics2.Parent.ParentBuilder(field1=" + this.field1) + ", items=") + this.items) + ")");
- }
- }
- private static final @java.lang.SuppressWarnings("all") class ParentBuilderImpl<A> extends SuperBuilderWithGenerics2.Parent.ParentBuilder<A, SuperBuilderWithGenerics2.Parent<A>, SuperBuilderWithGenerics2.Parent.ParentBuilderImpl<A>> {
- private ParentBuilderImpl() {
- super();
- }
- protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithGenerics2.Parent.ParentBuilderImpl<A> self() {
- return this;
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithGenerics2.Parent<A> build() {
- return new SuperBuilderWithGenerics2.Parent<A>(this);
- }
- }
- A field1;
- @lombok.Singular List<String> items;
- protected @java.lang.SuppressWarnings("all") Parent(final SuperBuilderWithGenerics2.Parent.ParentBuilder<A, ?, ?> b) {
- super();
- this.field1 = b.field1;
- java.util.List<String> items;
- switch (((b.items == null) ? 0 : b.items.size())) {
- case 0 :
- items = java.util.Collections.emptyList();
- break;
- case 1 :
- items = java.util.Collections.singletonList(b.items.get(0));
- break;
- default :
- items = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(b.items));
- }
- this.items = items;
- }
- public static @java.lang.SuppressWarnings("all") <A>SuperBuilderWithGenerics2.Parent.ParentBuilder<A, ?, ?> builder() {
- return new SuperBuilderWithGenerics2.Parent.ParentBuilderImpl<A>();
- }
- }
- public static @lombok.experimental.SuperBuilder(builderMethodName = "builder2") class Child<A> extends Parent<String> {
- public static abstract @java.lang.SuppressWarnings("all") class ChildBuilder<A, C extends SuperBuilderWithGenerics2.Child<A>, B extends SuperBuilderWithGenerics2.Child.ChildBuilder<A, C, B>> extends Parent.ParentBuilder<String, C, B> {
- private @java.lang.SuppressWarnings("all") A field3;
- public ChildBuilder() {
- super();
- }
- protected abstract @java.lang.Override @java.lang.SuppressWarnings("all") B self();
- public abstract @java.lang.Override @java.lang.SuppressWarnings("all") C build();
- /**
- * @return {@code this}.
- */
- public @java.lang.SuppressWarnings("all") B field3(final A field3) {
- this.field3 = field3;
- return self();
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
- return (((("SuperBuilderWithGenerics2.Child.ChildBuilder(super=" + super.toString()) + ", field3=") + this.field3) + ")");
- }
- }
- private static final @java.lang.SuppressWarnings("all") class ChildBuilderImpl<A> extends SuperBuilderWithGenerics2.Child.ChildBuilder<A, SuperBuilderWithGenerics2.Child<A>, SuperBuilderWithGenerics2.Child.ChildBuilderImpl<A>> {
- private ChildBuilderImpl() {
- super();
- }
- protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithGenerics2.Child.ChildBuilderImpl<A> self() {
- return this;
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithGenerics2.Child<A> build() {
- return new SuperBuilderWithGenerics2.Child<A>(this);
- }
- }
- A field3;
- protected @java.lang.SuppressWarnings("all") Child(final SuperBuilderWithGenerics2.Child.ChildBuilder<A, ?, ?> b) {
- super(b);
- this.field3 = b.field3;
- }
- public static @java.lang.SuppressWarnings("all") <A>SuperBuilderWithGenerics2.Child.ChildBuilder<A, ?, ?> builder2() {
- return new SuperBuilderWithGenerics2.Child.ChildBuilderImpl<A>();
- }
- }
- public SuperBuilderWithGenerics2() {
- super();
- }
- public static void test() {
- Child<Integer> x = Child.<Integer>builder2().field3(1).field1("value").item("").build();
- }
-}
+import java.util.List; +public class SuperBuilderWithGenerics2 { + public static @lombok.experimental.SuperBuilder class Parent<A> { + public static abstract @java.lang.SuppressWarnings("all") class ParentBuilder<A, C extends SuperBuilderWithGenerics2.Parent<A>, B extends SuperBuilderWithGenerics2.Parent.ParentBuilder<A, C, B>> { + private @java.lang.SuppressWarnings("all") A field1; + private @java.lang.SuppressWarnings("all") java.util.ArrayList<String> items; + public ParentBuilder() { + super(); + } + protected abstract @java.lang.SuppressWarnings("all") B self(); + public abstract @java.lang.SuppressWarnings("all") C build(); + /** + * @return {@code this}. + */ + public @java.lang.SuppressWarnings("all") B field1(final A field1) { + this.field1 = field1; + return self(); + } + public @java.lang.SuppressWarnings("all") B item(final String item) { + if ((this.items == null)) + this.items = new java.util.ArrayList<String>(); + this.items.add(item); + return self(); + } + public @java.lang.SuppressWarnings("all") B items(final java.util.Collection<? extends String> items) { + if ((items == null)) + { + throw new java.lang.NullPointerException("items cannot be null"); + } + if ((this.items == null)) + this.items = new java.util.ArrayList<String>(); + this.items.addAll(items); + return self(); + } + public @java.lang.SuppressWarnings("all") B clearItems() { + if ((this.items != null)) + this.items.clear(); + return self(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (((("SuperBuilderWithGenerics2.Parent.ParentBuilder(field1=" + this.field1) + ", items=") + this.items) + ")"); + } + } + private static final @java.lang.SuppressWarnings("all") class ParentBuilderImpl<A> extends SuperBuilderWithGenerics2.Parent.ParentBuilder<A, SuperBuilderWithGenerics2.Parent<A>, SuperBuilderWithGenerics2.Parent.ParentBuilderImpl<A>> { + private ParentBuilderImpl() { + super(); + } + protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithGenerics2.Parent.ParentBuilderImpl<A> self() { + return this; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithGenerics2.Parent<A> build() { + return new SuperBuilderWithGenerics2.Parent<A>(this); + } + } + A field1; + @lombok.Singular List<String> items; + protected @java.lang.SuppressWarnings("all") Parent(final SuperBuilderWithGenerics2.Parent.ParentBuilder<A, ?, ?> b) { + super(); + this.field1 = b.field1; + java.util.List<String> items; + switch (((b.items == null) ? 0 : b.items.size())) { + case 0 : + items = java.util.Collections.emptyList(); + break; + case 1 : + items = java.util.Collections.singletonList(b.items.get(0)); + break; + default : + items = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(b.items)); + } + this.items = items; + } + public static @java.lang.SuppressWarnings("all") <A>SuperBuilderWithGenerics2.Parent.ParentBuilder<A, ?, ?> builder() { + return new SuperBuilderWithGenerics2.Parent.ParentBuilderImpl<A>(); + } + } + public static @lombok.experimental.SuperBuilder(builderMethodName = "builder2") class Child<A> extends Parent<String> { + public static abstract @java.lang.SuppressWarnings("all") class ChildBuilder<A, C extends SuperBuilderWithGenerics2.Child<A>, B extends SuperBuilderWithGenerics2.Child.ChildBuilder<A, C, B>> extends Parent.ParentBuilder<String, C, B> { + private @java.lang.SuppressWarnings("all") A field3; + public ChildBuilder() { + super(); + } + protected abstract @java.lang.Override @java.lang.SuppressWarnings("all") B self(); + public abstract @java.lang.Override @java.lang.SuppressWarnings("all") C build(); + /** + * @return {@code this}. + */ + public @java.lang.SuppressWarnings("all") B field3(final A field3) { + this.field3 = field3; + return self(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (((("SuperBuilderWithGenerics2.Child.ChildBuilder(super=" + super.toString()) + ", field3=") + this.field3) + ")"); + } + } + private static final @java.lang.SuppressWarnings("all") class ChildBuilderImpl<A> extends SuperBuilderWithGenerics2.Child.ChildBuilder<A, SuperBuilderWithGenerics2.Child<A>, SuperBuilderWithGenerics2.Child.ChildBuilderImpl<A>> { + private ChildBuilderImpl() { + super(); + } + protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithGenerics2.Child.ChildBuilderImpl<A> self() { + return this; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithGenerics2.Child<A> build() { + return new SuperBuilderWithGenerics2.Child<A>(this); + } + } + A field3; + protected @java.lang.SuppressWarnings("all") Child(final SuperBuilderWithGenerics2.Child.ChildBuilder<A, ?, ?> b) { + super(b); + this.field3 = b.field3; + } + public static @java.lang.SuppressWarnings("all") <A>SuperBuilderWithGenerics2.Child.ChildBuilder<A, ?, ?> builder2() { + return new SuperBuilderWithGenerics2.Child.ChildBuilderImpl<A>(); + } + } + public SuperBuilderWithGenerics2() { + super(); + } + public static void test() { + Child<Integer> x = Child.<Integer>builder2().field3(1).field1("value").item("").build(); + } +} diff --git a/test/transform/resource/after-ecj/SuperBuilderWithGenericsAndToBuilder.java b/test/transform/resource/after-ecj/SuperBuilderWithGenericsAndToBuilder.java index c1eb42fd..829b50b9 100644 --- a/test/transform/resource/after-ecj/SuperBuilderWithGenericsAndToBuilder.java +++ b/test/transform/resource/after-ecj/SuperBuilderWithGenericsAndToBuilder.java @@ -1,162 +1,162 @@ -import java.util.Map;
-public class SuperBuilderWithGenericsAndToBuilder {
- public static @lombok.experimental.SuperBuilder(toBuilder = true) class Parent<A> {
- public static abstract @java.lang.SuppressWarnings("all") class ParentBuilder<A, C extends SuperBuilderWithGenericsAndToBuilder.Parent<A>, B extends SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilder<A, C, B>> {
- private @java.lang.SuppressWarnings("all") A field1;
- private @java.lang.SuppressWarnings("all") java.util.ArrayList<Integer> items$key;
- private @java.lang.SuppressWarnings("all") java.util.ArrayList<String> items$value;
- public ParentBuilder() {
- super();
- }
- protected @java.lang.SuppressWarnings("all") B $fillValuesFrom(final C instance) {
- SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilder.$fillValuesFromInstanceIntoBuilder(instance, this);
- return self();
- }
- private static @java.lang.SuppressWarnings("all") <A>void $fillValuesFromInstanceIntoBuilder(final SuperBuilderWithGenericsAndToBuilder.Parent<A> instance, final SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilder<A, ?, ?> b) {
- b.field1(instance.field1);
- b.items(((instance.items == null) ? java.util.Collections.emptyMap() : instance.items));
- }
- protected abstract @java.lang.SuppressWarnings("all") B self();
- public abstract @java.lang.SuppressWarnings("all") C build();
- /**
- * @return {@code this}.
- */
- public @java.lang.SuppressWarnings("all") B field1(final A field1) {
- this.field1 = field1;
- return self();
- }
- public @java.lang.SuppressWarnings("all") B item(final Integer itemKey, final String itemValue) {
- if ((this.items$key == null))
- {
- this.items$key = new java.util.ArrayList<Integer>();
- this.items$value = new java.util.ArrayList<String>();
- }
- this.items$key.add(itemKey);
- this.items$value.add(itemValue);
- return self();
- }
- public @java.lang.SuppressWarnings("all") B items(final java.util.Map<? extends Integer, ? extends String> items) {
- if ((items == null))
- {
- throw new java.lang.NullPointerException("items cannot be null");
- }
- if ((this.items$key == null))
- {
- this.items$key = new java.util.ArrayList<Integer>();
- this.items$value = new java.util.ArrayList<String>();
- }
- for (java.util.Map.Entry<? extends Integer, ? extends String> $lombokEntry : items.entrySet())
- {
- this.items$key.add($lombokEntry.getKey());
- this.items$value.add($lombokEntry.getValue());
- }
- return self();
- }
- public @java.lang.SuppressWarnings("all") B clearItems() {
- if ((this.items$key != null))
- {
- this.items$key.clear();
- this.items$value.clear();
- }
- return self();
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
- return (((((("SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilder(field1=" + this.field1) + ", items$key=") + this.items$key) + ", items$value=") + this.items$value) + ")");
- }
- }
- private static final @java.lang.SuppressWarnings("all") class ParentBuilderImpl<A> extends SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilder<A, SuperBuilderWithGenericsAndToBuilder.Parent<A>, SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilderImpl<A>> {
- private ParentBuilderImpl() {
- super();
- }
- protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilderImpl<A> self() {
- return this;
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithGenericsAndToBuilder.Parent<A> build() {
- return new SuperBuilderWithGenericsAndToBuilder.Parent<A>(this);
- }
- }
- A field1;
- @lombok.Singular Map<Integer, String> items;
- protected @java.lang.SuppressWarnings("all") Parent(final SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilder<A, ?, ?> b) {
- super();
- this.field1 = b.field1;
- java.util.Map<Integer, String> items;
- switch (((b.items$key == null) ? 0 : b.items$key.size())) {
- case 0 :
- items = java.util.Collections.emptyMap();
- break;
- case 1 :
- items = java.util.Collections.singletonMap(b.items$key.get(0), b.items$value.get(0));
- break;
- default :
- items = new java.util.LinkedHashMap<Integer, String>(((b.items$key.size() < 0x40000000) ? ((1 + b.items$key.size()) + ((b.items$key.size() - 3) / 3)) : java.lang.Integer.MAX_VALUE));
- for (int $i = 0;; ($i < b.items$key.size()); $i ++)
- items.put(b.items$key.get($i), b.items$value.get($i));
- items = java.util.Collections.unmodifiableMap(items);
- }
- this.items = items;
- }
- public @java.lang.SuppressWarnings("all") SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilder<A, ?, ?> toBuilder() {
- return new SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilderImpl<A>().$fillValuesFrom(this);
- }
- public static @java.lang.SuppressWarnings("all") <A>SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilder<A, ?, ?> builder() {
- return new SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilderImpl<A>();
- }
- }
- public static @lombok.experimental.SuperBuilder(toBuilder = true) class Child<A> extends Parent<A> {
- public static abstract @java.lang.SuppressWarnings("all") class ChildBuilder<A, C extends SuperBuilderWithGenericsAndToBuilder.Child<A>, B extends SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilder<A, C, B>> extends Parent.ParentBuilder<A, C, B> {
- private @java.lang.SuppressWarnings("all") double field3;
- public ChildBuilder() {
- super();
- }
- protected @java.lang.Override @java.lang.SuppressWarnings("all") B $fillValuesFrom(final C instance) {
- super.$fillValuesFrom(instance);
- SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilder.$fillValuesFromInstanceIntoBuilder(instance, this);
- return self();
- }
- private static @java.lang.SuppressWarnings("all") <A>void $fillValuesFromInstanceIntoBuilder(final SuperBuilderWithGenericsAndToBuilder.Child<A> instance, final SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilder<A, ?, ?> b) {
- b.field3(instance.field3);
- }
- protected abstract @java.lang.Override @java.lang.SuppressWarnings("all") B self();
- public abstract @java.lang.Override @java.lang.SuppressWarnings("all") C build();
- /**
- * @return {@code this}.
- */
- public @java.lang.SuppressWarnings("all") B field3(final double field3) {
- this.field3 = field3;
- return self();
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
- return (((("SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilder(super=" + super.toString()) + ", field3=") + this.field3) + ")");
- }
- }
- private static final @java.lang.SuppressWarnings("all") class ChildBuilderImpl<A> extends SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilder<A, SuperBuilderWithGenericsAndToBuilder.Child<A>, SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilderImpl<A>> {
- private ChildBuilderImpl() {
- super();
- }
- protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilderImpl<A> self() {
- return this;
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithGenericsAndToBuilder.Child<A> build() {
- return new SuperBuilderWithGenericsAndToBuilder.Child<A>(this);
- }
- }
- double field3;
- protected @java.lang.SuppressWarnings("all") Child(final SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilder<A, ?, ?> b) {
- super(b);
- this.field3 = b.field3;
- }
- public @java.lang.SuppressWarnings("all") SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilder<A, ?, ?> toBuilder() {
- return new SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilderImpl<A>().$fillValuesFrom(this);
- }
- public static @java.lang.SuppressWarnings("all") <A>SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilder<A, ?, ?> builder() {
- return new SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilderImpl<A>();
- }
- }
- public SuperBuilderWithGenericsAndToBuilder() {
- super();
- }
- public static void test() {
- Child<Integer> x = Child.<Integer>builder().field3(0.0).field1(5).item(5, "").build().toBuilder().build();
- }
-}
+import java.util.Map; +public class SuperBuilderWithGenericsAndToBuilder { + public static @lombok.experimental.SuperBuilder(toBuilder = true) class Parent<A> { + public static abstract @java.lang.SuppressWarnings("all") class ParentBuilder<A, C extends SuperBuilderWithGenericsAndToBuilder.Parent<A>, B extends SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilder<A, C, B>> { + private @java.lang.SuppressWarnings("all") A field1; + private @java.lang.SuppressWarnings("all") java.util.ArrayList<Integer> items$key; + private @java.lang.SuppressWarnings("all") java.util.ArrayList<String> items$value; + public ParentBuilder() { + super(); + } + protected @java.lang.SuppressWarnings("all") B $fillValuesFrom(final C instance) { + SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilder.$fillValuesFromInstanceIntoBuilder(instance, this); + return self(); + } + private static @java.lang.SuppressWarnings("all") <A>void $fillValuesFromInstanceIntoBuilder(final SuperBuilderWithGenericsAndToBuilder.Parent<A> instance, final SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilder<A, ?, ?> b) { + b.field1(instance.field1); + b.items(((instance.items == null) ? java.util.Collections.<Integer, String>emptyMap() : instance.items)); + } + protected abstract @java.lang.SuppressWarnings("all") B self(); + public abstract @java.lang.SuppressWarnings("all") C build(); + /** + * @return {@code this}. + */ + public @java.lang.SuppressWarnings("all") B field1(final A field1) { + this.field1 = field1; + return self(); + } + public @java.lang.SuppressWarnings("all") B item(final Integer itemKey, final String itemValue) { + if ((this.items$key == null)) + { + this.items$key = new java.util.ArrayList<Integer>(); + this.items$value = new java.util.ArrayList<String>(); + } + this.items$key.add(itemKey); + this.items$value.add(itemValue); + return self(); + } + public @java.lang.SuppressWarnings("all") B items(final java.util.Map<? extends Integer, ? extends String> items) { + if ((items == null)) + { + throw new java.lang.NullPointerException("items cannot be null"); + } + if ((this.items$key == null)) + { + this.items$key = new java.util.ArrayList<Integer>(); + this.items$value = new java.util.ArrayList<String>(); + } + for (java.util.Map.Entry<? extends Integer, ? extends String> $lombokEntry : items.entrySet()) + { + this.items$key.add($lombokEntry.getKey()); + this.items$value.add($lombokEntry.getValue()); + } + return self(); + } + public @java.lang.SuppressWarnings("all") B clearItems() { + if ((this.items$key != null)) + { + this.items$key.clear(); + this.items$value.clear(); + } + return self(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (((((("SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilder(field1=" + this.field1) + ", items$key=") + this.items$key) + ", items$value=") + this.items$value) + ")"); + } + } + private static final @java.lang.SuppressWarnings("all") class ParentBuilderImpl<A> extends SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilder<A, SuperBuilderWithGenericsAndToBuilder.Parent<A>, SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilderImpl<A>> { + private ParentBuilderImpl() { + super(); + } + protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilderImpl<A> self() { + return this; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithGenericsAndToBuilder.Parent<A> build() { + return new SuperBuilderWithGenericsAndToBuilder.Parent<A>(this); + } + } + A field1; + @lombok.Singular Map<Integer, String> items; + protected @java.lang.SuppressWarnings("all") Parent(final SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilder<A, ?, ?> b) { + super(); + this.field1 = b.field1; + java.util.Map<Integer, String> items; + switch (((b.items$key == null) ? 0 : b.items$key.size())) { + case 0 : + items = java.util.Collections.emptyMap(); + break; + case 1 : + items = java.util.Collections.singletonMap(b.items$key.get(0), b.items$value.get(0)); + break; + default : + items = new java.util.LinkedHashMap<Integer, String>(((b.items$key.size() < 0x40000000) ? ((1 + b.items$key.size()) + ((b.items$key.size() - 3) / 3)) : java.lang.Integer.MAX_VALUE)); + for (int $i = 0;; ($i < b.items$key.size()); $i ++) + items.put(b.items$key.get($i), b.items$value.get($i)); + items = java.util.Collections.unmodifiableMap(items); + } + this.items = items; + } + public @java.lang.SuppressWarnings("all") SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilder<A, ?, ?> toBuilder() { + return new SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilderImpl<A>().$fillValuesFrom(this); + } + public static @java.lang.SuppressWarnings("all") <A>SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilder<A, ?, ?> builder() { + return new SuperBuilderWithGenericsAndToBuilder.Parent.ParentBuilderImpl<A>(); + } + } + public static @lombok.experimental.SuperBuilder(toBuilder = true) class Child<A> extends Parent<A> { + public static abstract @java.lang.SuppressWarnings("all") class ChildBuilder<A, C extends SuperBuilderWithGenericsAndToBuilder.Child<A>, B extends SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilder<A, C, B>> extends Parent.ParentBuilder<A, C, B> { + private @java.lang.SuppressWarnings("all") double field3; + public ChildBuilder() { + super(); + } + protected @java.lang.Override @java.lang.SuppressWarnings("all") B $fillValuesFrom(final C instance) { + super.$fillValuesFrom(instance); + SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilder.$fillValuesFromInstanceIntoBuilder(instance, this); + return self(); + } + private static @java.lang.SuppressWarnings("all") <A>void $fillValuesFromInstanceIntoBuilder(final SuperBuilderWithGenericsAndToBuilder.Child<A> instance, final SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilder<A, ?, ?> b) { + b.field3(instance.field3); + } + protected abstract @java.lang.Override @java.lang.SuppressWarnings("all") B self(); + public abstract @java.lang.Override @java.lang.SuppressWarnings("all") C build(); + /** + * @return {@code this}. + */ + public @java.lang.SuppressWarnings("all") B field3(final double field3) { + this.field3 = field3; + return self(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (((("SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilder(super=" + super.toString()) + ", field3=") + this.field3) + ")"); + } + } + private static final @java.lang.SuppressWarnings("all") class ChildBuilderImpl<A> extends SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilder<A, SuperBuilderWithGenericsAndToBuilder.Child<A>, SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilderImpl<A>> { + private ChildBuilderImpl() { + super(); + } + protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilderImpl<A> self() { + return this; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithGenericsAndToBuilder.Child<A> build() { + return new SuperBuilderWithGenericsAndToBuilder.Child<A>(this); + } + } + double field3; + protected @java.lang.SuppressWarnings("all") Child(final SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilder<A, ?, ?> b) { + super(b); + this.field3 = b.field3; + } + public @java.lang.SuppressWarnings("all") SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilder<A, ?, ?> toBuilder() { + return new SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilderImpl<A>().$fillValuesFrom(this); + } + public static @java.lang.SuppressWarnings("all") <A>SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilder<A, ?, ?> builder() { + return new SuperBuilderWithGenericsAndToBuilder.Child.ChildBuilderImpl<A>(); + } + } + public SuperBuilderWithGenericsAndToBuilder() { + super(); + } + public static void test() { + Child<Integer> x = Child.<Integer>builder().field3(0.0).field1(5).item(5, "").build().toBuilder().build(); + } +} diff --git a/test/transform/resource/after-ecj/SuperBuilderWithNonNull.java b/test/transform/resource/after-ecj/SuperBuilderWithNonNull.java index b9c96a38..28504f29 100644 --- a/test/transform/resource/after-ecj/SuperBuilderWithNonNull.java +++ b/test/transform/resource/after-ecj/SuperBuilderWithNonNull.java @@ -1,111 +1,111 @@ -import java.util.List;
-public class SuperBuilderWithNonNull {
- public static @lombok.experimental.SuperBuilder class Parent {
- public static abstract @java.lang.SuppressWarnings("all") class ParentBuilder<C extends SuperBuilderWithNonNull.Parent, B extends SuperBuilderWithNonNull.Parent.ParentBuilder<C, B>> {
- private @java.lang.SuppressWarnings("all") String nonNullParentField$value;
- private @java.lang.SuppressWarnings("all") boolean nonNullParentField$set;
- public ParentBuilder() {
- super();
- }
- protected abstract @java.lang.SuppressWarnings("all") B self();
- public abstract @java.lang.SuppressWarnings("all") C build();
- /**
- * @return {@code this}.
- */
- public @java.lang.SuppressWarnings("all") B nonNullParentField(final @lombok.NonNull String nonNullParentField) {
- if ((nonNullParentField == null))
- {
- throw new java.lang.NullPointerException("nonNullParentField is marked non-null but is null");
- }
- this.nonNullParentField$value = nonNullParentField;
- nonNullParentField$set = true;
- return self();
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
- return (("SuperBuilderWithNonNull.Parent.ParentBuilder(nonNullParentField$value=" + this.nonNullParentField$value) + ")");
- }
- }
- private static final @java.lang.SuppressWarnings("all") class ParentBuilderImpl extends SuperBuilderWithNonNull.Parent.ParentBuilder<SuperBuilderWithNonNull.Parent, SuperBuilderWithNonNull.Parent.ParentBuilderImpl> {
- private ParentBuilderImpl() {
- super();
- }
- protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithNonNull.Parent.ParentBuilderImpl self() {
- return this;
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithNonNull.Parent build() {
- return new SuperBuilderWithNonNull.Parent(this);
- }
- }
- final @lombok.NonNull @lombok.Builder.Default String nonNullParentField;
- private static @java.lang.SuppressWarnings("all") String $default$nonNullParentField() {
- return "default";
- }
- protected @java.lang.SuppressWarnings("all") Parent(final SuperBuilderWithNonNull.Parent.ParentBuilder<?, ?> b) {
- super();
- if (b.nonNullParentField$set)
- this.nonNullParentField = b.nonNullParentField$value;
- else
- this.nonNullParentField = SuperBuilderWithNonNull.Parent.$default$nonNullParentField();
- if ((nonNullParentField == null))
- {
- throw new java.lang.NullPointerException("nonNullParentField is marked non-null but is null");
- }
- }
- public static @java.lang.SuppressWarnings("all") SuperBuilderWithNonNull.Parent.ParentBuilder<?, ?> builder() {
- return new SuperBuilderWithNonNull.Parent.ParentBuilderImpl();
- }
- }
- public static @lombok.experimental.SuperBuilder class Child extends Parent {
- public static abstract @java.lang.SuppressWarnings("all") class ChildBuilder<C extends SuperBuilderWithNonNull.Child, B extends SuperBuilderWithNonNull.Child.ChildBuilder<C, B>> extends Parent.ParentBuilder<C, B> {
- private @java.lang.SuppressWarnings("all") String nonNullChildField;
- public ChildBuilder() {
- super();
- }
- protected abstract @java.lang.Override @java.lang.SuppressWarnings("all") B self();
- public abstract @java.lang.Override @java.lang.SuppressWarnings("all") C build();
- /**
- * @return {@code this}.
- */
- public @java.lang.SuppressWarnings("all") B nonNullChildField(final @lombok.NonNull String nonNullChildField) {
- if ((nonNullChildField == null))
- {
- throw new java.lang.NullPointerException("nonNullChildField is marked non-null but is null");
- }
- this.nonNullChildField = nonNullChildField;
- return self();
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
- return (((("SuperBuilderWithNonNull.Child.ChildBuilder(super=" + super.toString()) + ", nonNullChildField=") + this.nonNullChildField) + ")");
- }
- }
- private static final @java.lang.SuppressWarnings("all") class ChildBuilderImpl extends SuperBuilderWithNonNull.Child.ChildBuilder<SuperBuilderWithNonNull.Child, SuperBuilderWithNonNull.Child.ChildBuilderImpl> {
- private ChildBuilderImpl() {
- super();
- }
- protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithNonNull.Child.ChildBuilderImpl self() {
- return this;
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithNonNull.Child build() {
- return new SuperBuilderWithNonNull.Child(this);
- }
- }
- @lombok.NonNull String nonNullChildField;
- protected @java.lang.SuppressWarnings("all") Child(final SuperBuilderWithNonNull.Child.ChildBuilder<?, ?> b) {
- super(b);
- this.nonNullChildField = b.nonNullChildField;
- if ((nonNullChildField == null))
- {
- throw new java.lang.NullPointerException("nonNullChildField is marked non-null but is null");
- }
- }
- public static @java.lang.SuppressWarnings("all") SuperBuilderWithNonNull.Child.ChildBuilder<?, ?> builder() {
- return new SuperBuilderWithNonNull.Child.ChildBuilderImpl();
- }
- }
- public SuperBuilderWithNonNull() {
- super();
- }
- public static void test() {
- Child x = Child.builder().nonNullChildField("child").nonNullParentField("parent").build();
- }
-}
+import java.util.List; +public class SuperBuilderWithNonNull { + public static @lombok.experimental.SuperBuilder class Parent { + public static abstract @java.lang.SuppressWarnings("all") class ParentBuilder<C extends SuperBuilderWithNonNull.Parent, B extends SuperBuilderWithNonNull.Parent.ParentBuilder<C, B>> { + private @java.lang.SuppressWarnings("all") String nonNullParentField$value; + private @java.lang.SuppressWarnings("all") boolean nonNullParentField$set; + public ParentBuilder() { + super(); + } + protected abstract @java.lang.SuppressWarnings("all") B self(); + public abstract @java.lang.SuppressWarnings("all") C build(); + /** + * @return {@code this}. + */ + public @java.lang.SuppressWarnings("all") B nonNullParentField(final @lombok.NonNull String nonNullParentField) { + if ((nonNullParentField == null)) + { + throw new java.lang.NullPointerException("nonNullParentField is marked non-null but is null"); + } + this.nonNullParentField$value = nonNullParentField; + nonNullParentField$set = true; + return self(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (("SuperBuilderWithNonNull.Parent.ParentBuilder(nonNullParentField$value=" + this.nonNullParentField$value) + ")"); + } + } + private static final @java.lang.SuppressWarnings("all") class ParentBuilderImpl extends SuperBuilderWithNonNull.Parent.ParentBuilder<SuperBuilderWithNonNull.Parent, SuperBuilderWithNonNull.Parent.ParentBuilderImpl> { + private ParentBuilderImpl() { + super(); + } + protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithNonNull.Parent.ParentBuilderImpl self() { + return this; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithNonNull.Parent build() { + return new SuperBuilderWithNonNull.Parent(this); + } + } + final @lombok.NonNull @lombok.Builder.Default String nonNullParentField; + private static @java.lang.SuppressWarnings("all") String $default$nonNullParentField() { + return "default"; + } + protected @java.lang.SuppressWarnings("all") Parent(final SuperBuilderWithNonNull.Parent.ParentBuilder<?, ?> b) { + super(); + if (b.nonNullParentField$set) + this.nonNullParentField = b.nonNullParentField$value; + else + this.nonNullParentField = SuperBuilderWithNonNull.Parent.$default$nonNullParentField(); + if ((nonNullParentField == null)) + { + throw new java.lang.NullPointerException("nonNullParentField is marked non-null but is null"); + } + } + public static @java.lang.SuppressWarnings("all") SuperBuilderWithNonNull.Parent.ParentBuilder<?, ?> builder() { + return new SuperBuilderWithNonNull.Parent.ParentBuilderImpl(); + } + } + public static @lombok.experimental.SuperBuilder class Child extends Parent { + public static abstract @java.lang.SuppressWarnings("all") class ChildBuilder<C extends SuperBuilderWithNonNull.Child, B extends SuperBuilderWithNonNull.Child.ChildBuilder<C, B>> extends Parent.ParentBuilder<C, B> { + private @java.lang.SuppressWarnings("all") String nonNullChildField; + public ChildBuilder() { + super(); + } + protected abstract @java.lang.Override @java.lang.SuppressWarnings("all") B self(); + public abstract @java.lang.Override @java.lang.SuppressWarnings("all") C build(); + /** + * @return {@code this}. + */ + public @java.lang.SuppressWarnings("all") B nonNullChildField(final @lombok.NonNull String nonNullChildField) { + if ((nonNullChildField == null)) + { + throw new java.lang.NullPointerException("nonNullChildField is marked non-null but is null"); + } + this.nonNullChildField = nonNullChildField; + return self(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (((("SuperBuilderWithNonNull.Child.ChildBuilder(super=" + super.toString()) + ", nonNullChildField=") + this.nonNullChildField) + ")"); + } + } + private static final @java.lang.SuppressWarnings("all") class ChildBuilderImpl extends SuperBuilderWithNonNull.Child.ChildBuilder<SuperBuilderWithNonNull.Child, SuperBuilderWithNonNull.Child.ChildBuilderImpl> { + private ChildBuilderImpl() { + super(); + } + protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithNonNull.Child.ChildBuilderImpl self() { + return this; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithNonNull.Child build() { + return new SuperBuilderWithNonNull.Child(this); + } + } + @lombok.NonNull String nonNullChildField; + protected @java.lang.SuppressWarnings("all") Child(final SuperBuilderWithNonNull.Child.ChildBuilder<?, ?> b) { + super(b); + this.nonNullChildField = b.nonNullChildField; + if ((nonNullChildField == null)) + { + throw new java.lang.NullPointerException("nonNullChildField is marked non-null but is null"); + } + } + public static @java.lang.SuppressWarnings("all") SuperBuilderWithNonNull.Child.ChildBuilder<?, ?> builder() { + return new SuperBuilderWithNonNull.Child.ChildBuilderImpl(); + } + } + public SuperBuilderWithNonNull() { + super(); + } + public static void test() { + Child x = Child.builder().nonNullChildField("child").nonNullParentField("parent").build(); + } +} diff --git a/test/transform/resource/after-ecj/SuperBuilderWithSetterPrefix.java b/test/transform/resource/after-ecj/SuperBuilderWithSetterPrefix.java index 0edb6608..3a1278c1 100644 --- a/test/transform/resource/after-ecj/SuperBuilderWithSetterPrefix.java +++ b/test/transform/resource/after-ecj/SuperBuilderWithSetterPrefix.java @@ -1,183 +1,183 @@ -import java.util.List;
-public class SuperBuilderWithSetterPrefix {
- public static @lombok.experimental.SuperBuilder(toBuilder = true,setterPrefix = "with") class Parent {
- public static abstract @java.lang.SuppressWarnings("all") class ParentBuilder<C extends SuperBuilderWithSetterPrefix.Parent, B extends SuperBuilderWithSetterPrefix.Parent.ParentBuilder<C, B>> {
- private @java.lang.SuppressWarnings("all") int field1;
- private @java.lang.SuppressWarnings("all") int obtainViaField;
- private @java.lang.SuppressWarnings("all") int obtainViaMethod;
- private @java.lang.SuppressWarnings("all") String obtainViaStaticMethod;
- private @java.lang.SuppressWarnings("all") java.util.ArrayList<String> items;
- public ParentBuilder() {
- super();
- }
- protected @java.lang.SuppressWarnings("all") B $fillValuesFrom(final C instance) {
- SuperBuilderWithSetterPrefix.Parent.ParentBuilder.$fillValuesFromInstanceIntoBuilder(instance, this);
- return self();
- }
- private static @java.lang.SuppressWarnings("all") void $fillValuesFromInstanceIntoBuilder(final SuperBuilderWithSetterPrefix.Parent instance, final SuperBuilderWithSetterPrefix.Parent.ParentBuilder<?, ?> b) {
- b.withField1(instance.field1);
- b.withObtainViaField(instance.field1);
- b.withObtainViaMethod(instance.method());
- b.withObtainViaStaticMethod(SuperBuilderWithSetterPrefix.Parent.staticMethod(instance));
- b.withItems(((instance.items == null) ? java.util.Collections.emptyList() : instance.items));
- }
- protected abstract @java.lang.SuppressWarnings("all") B self();
- public abstract @java.lang.SuppressWarnings("all") C build();
- /**
- * @return {@code this}.
- */
- public @java.lang.SuppressWarnings("all") B withField1(final int field1) {
- this.field1 = field1;
- return self();
- }
- /**
- * @return {@code this}.
- */
- public @java.lang.SuppressWarnings("all") B withObtainViaField(final int obtainViaField) {
- this.obtainViaField = obtainViaField;
- return self();
- }
- /**
- * @return {@code this}.
- */
- public @java.lang.SuppressWarnings("all") B withObtainViaMethod(final int obtainViaMethod) {
- this.obtainViaMethod = obtainViaMethod;
- return self();
- }
- /**
- * @return {@code this}.
- */
- public @java.lang.SuppressWarnings("all") B withObtainViaStaticMethod(final String obtainViaStaticMethod) {
- this.obtainViaStaticMethod = obtainViaStaticMethod;
- return self();
- }
- public @java.lang.SuppressWarnings("all") B withItem(final String item) {
- if ((this.items == null))
- this.items = new java.util.ArrayList<String>();
- this.items.add(item);
- return self();
- }
- public @java.lang.SuppressWarnings("all") B withItems(final java.util.Collection<? extends String> items) {
- if ((items == null))
- {
- throw new java.lang.NullPointerException("items cannot be null");
- }
- if ((this.items == null))
- this.items = new java.util.ArrayList<String>();
- this.items.addAll(items);
- return self();
- }
- public @java.lang.SuppressWarnings("all") B clearItems() {
- if ((this.items != null))
- this.items.clear();
- return self();
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
- return (((((((((("SuperBuilderWithSetterPrefix.Parent.ParentBuilder(field1=" + this.field1) + ", obtainViaField=") + this.obtainViaField) + ", obtainViaMethod=") + this.obtainViaMethod) + ", obtainViaStaticMethod=") + this.obtainViaStaticMethod) + ", items=") + this.items) + ")");
- }
- }
- private static final @java.lang.SuppressWarnings("all") class ParentBuilderImpl extends SuperBuilderWithSetterPrefix.Parent.ParentBuilder<SuperBuilderWithSetterPrefix.Parent, SuperBuilderWithSetterPrefix.Parent.ParentBuilderImpl> {
- private ParentBuilderImpl() {
- super();
- }
- protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithSetterPrefix.Parent.ParentBuilderImpl self() {
- return this;
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithSetterPrefix.Parent build() {
- return new SuperBuilderWithSetterPrefix.Parent(this);
- }
- }
- private int field1;
- @lombok.Builder.ObtainVia(field = "field1") int obtainViaField;
- @lombok.Builder.ObtainVia(method = "method") int obtainViaMethod;
- @lombok.Builder.ObtainVia(method = "staticMethod",isStatic = true) String obtainViaStaticMethod;
- @lombok.Singular List<String> items;
- private int method() {
- return 2;
- }
- private static String staticMethod(Parent instance) {
- return "staticMethod";
- }
- protected @java.lang.SuppressWarnings("all") Parent(final SuperBuilderWithSetterPrefix.Parent.ParentBuilder<?, ?> b) {
- super();
- this.field1 = b.field1;
- this.obtainViaField = b.obtainViaField;
- this.obtainViaMethod = b.obtainViaMethod;
- this.obtainViaStaticMethod = b.obtainViaStaticMethod;
- java.util.List<String> items;
- switch (((b.items == null) ? 0 : b.items.size())) {
- case 0 :
- items = java.util.Collections.emptyList();
- break;
- case 1 :
- items = java.util.Collections.singletonList(b.items.get(0));
- break;
- default :
- items = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(b.items));
- }
- this.items = items;
- }
- public @java.lang.SuppressWarnings("all") SuperBuilderWithSetterPrefix.Parent.ParentBuilder<?, ?> toBuilder() {
- return new SuperBuilderWithSetterPrefix.Parent.ParentBuilderImpl().$fillValuesFrom(this);
- }
- public static @java.lang.SuppressWarnings("all") SuperBuilderWithSetterPrefix.Parent.ParentBuilder<?, ?> builder() {
- return new SuperBuilderWithSetterPrefix.Parent.ParentBuilderImpl();
- }
- }
- public static @lombok.experimental.SuperBuilder(toBuilder = true,setterPrefix = "set") class Child extends Parent {
- public static abstract @java.lang.SuppressWarnings("all") class ChildBuilder<C extends SuperBuilderWithSetterPrefix.Child, B extends SuperBuilderWithSetterPrefix.Child.ChildBuilder<C, B>> extends Parent.ParentBuilder<C, B> {
- private @java.lang.SuppressWarnings("all") double field3;
- public ChildBuilder() {
- super();
- }
- protected @java.lang.Override @java.lang.SuppressWarnings("all") B $fillValuesFrom(final C instance) {
- super.$fillValuesFrom(instance);
- SuperBuilderWithSetterPrefix.Child.ChildBuilder.$fillValuesFromInstanceIntoBuilder(instance, this);
- return self();
- }
- private static @java.lang.SuppressWarnings("all") void $fillValuesFromInstanceIntoBuilder(final SuperBuilderWithSetterPrefix.Child instance, final SuperBuilderWithSetterPrefix.Child.ChildBuilder<?, ?> b) {
- b.setField3(instance.field3);
- }
- protected abstract @java.lang.Override @java.lang.SuppressWarnings("all") B self();
- public abstract @java.lang.Override @java.lang.SuppressWarnings("all") C build();
- /**
- * @return {@code this}.
- */
- public @java.lang.SuppressWarnings("all") B setField3(final double field3) {
- this.field3 = field3;
- return self();
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
- return (((("SuperBuilderWithSetterPrefix.Child.ChildBuilder(super=" + super.toString()) + ", field3=") + this.field3) + ")");
- }
- }
- private static final @java.lang.SuppressWarnings("all") class ChildBuilderImpl extends SuperBuilderWithSetterPrefix.Child.ChildBuilder<SuperBuilderWithSetterPrefix.Child, SuperBuilderWithSetterPrefix.Child.ChildBuilderImpl> {
- private ChildBuilderImpl() {
- super();
- }
- protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithSetterPrefix.Child.ChildBuilderImpl self() {
- return this;
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithSetterPrefix.Child build() {
- return new SuperBuilderWithSetterPrefix.Child(this);
- }
- }
- private double field3;
- protected @java.lang.SuppressWarnings("all") Child(final SuperBuilderWithSetterPrefix.Child.ChildBuilder<?, ?> b) {
- super(b);
- this.field3 = b.field3;
- }
- public @java.lang.SuppressWarnings("all") SuperBuilderWithSetterPrefix.Child.ChildBuilder<?, ?> toBuilder() {
- return new SuperBuilderWithSetterPrefix.Child.ChildBuilderImpl().$fillValuesFrom(this);
- }
- public static @java.lang.SuppressWarnings("all") SuperBuilderWithSetterPrefix.Child.ChildBuilder<?, ?> builder() {
- return new SuperBuilderWithSetterPrefix.Child.ChildBuilderImpl();
- }
- }
- public SuperBuilderWithSetterPrefix() {
- super();
- }
- public static void test() {
- Child x = Child.builder().setField3(0.0).withField1(5).withItem("").build().toBuilder().build();
- }
-}
+import java.util.List; +public class SuperBuilderWithSetterPrefix { + public static @lombok.experimental.SuperBuilder(toBuilder = true,setterPrefix = "with") class Parent { + public static abstract @java.lang.SuppressWarnings("all") class ParentBuilder<C extends SuperBuilderWithSetterPrefix.Parent, B extends SuperBuilderWithSetterPrefix.Parent.ParentBuilder<C, B>> { + private @java.lang.SuppressWarnings("all") int field1; + private @java.lang.SuppressWarnings("all") int obtainViaField; + private @java.lang.SuppressWarnings("all") int obtainViaMethod; + private @java.lang.SuppressWarnings("all") String obtainViaStaticMethod; + private @java.lang.SuppressWarnings("all") java.util.ArrayList<String> items; + public ParentBuilder() { + super(); + } + protected @java.lang.SuppressWarnings("all") B $fillValuesFrom(final C instance) { + SuperBuilderWithSetterPrefix.Parent.ParentBuilder.$fillValuesFromInstanceIntoBuilder(instance, this); + return self(); + } + private static @java.lang.SuppressWarnings("all") void $fillValuesFromInstanceIntoBuilder(final SuperBuilderWithSetterPrefix.Parent instance, final SuperBuilderWithSetterPrefix.Parent.ParentBuilder<?, ?> b) { + b.withField1(instance.field1); + b.withObtainViaField(instance.field1); + b.withObtainViaMethod(instance.method()); + b.withObtainViaStaticMethod(SuperBuilderWithSetterPrefix.Parent.staticMethod(instance)); + b.withItems(((instance.items == null) ? java.util.Collections.<String>emptyList() : instance.items)); + } + protected abstract @java.lang.SuppressWarnings("all") B self(); + public abstract @java.lang.SuppressWarnings("all") C build(); + /** + * @return {@code this}. + */ + public @java.lang.SuppressWarnings("all") B withField1(final int field1) { + this.field1 = field1; + return self(); + } + /** + * @return {@code this}. + */ + public @java.lang.SuppressWarnings("all") B withObtainViaField(final int obtainViaField) { + this.obtainViaField = obtainViaField; + return self(); + } + /** + * @return {@code this}. + */ + public @java.lang.SuppressWarnings("all") B withObtainViaMethod(final int obtainViaMethod) { + this.obtainViaMethod = obtainViaMethod; + return self(); + } + /** + * @return {@code this}. + */ + public @java.lang.SuppressWarnings("all") B withObtainViaStaticMethod(final String obtainViaStaticMethod) { + this.obtainViaStaticMethod = obtainViaStaticMethod; + return self(); + } + public @java.lang.SuppressWarnings("all") B withItem(final String item) { + if ((this.items == null)) + this.items = new java.util.ArrayList<String>(); + this.items.add(item); + return self(); + } + public @java.lang.SuppressWarnings("all") B withItems(final java.util.Collection<? extends String> items) { + if ((items == null)) + { + throw new java.lang.NullPointerException("items cannot be null"); + } + if ((this.items == null)) + this.items = new java.util.ArrayList<String>(); + this.items.addAll(items); + return self(); + } + public @java.lang.SuppressWarnings("all") B clearItems() { + if ((this.items != null)) + this.items.clear(); + return self(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (((((((((("SuperBuilderWithSetterPrefix.Parent.ParentBuilder(field1=" + this.field1) + ", obtainViaField=") + this.obtainViaField) + ", obtainViaMethod=") + this.obtainViaMethod) + ", obtainViaStaticMethod=") + this.obtainViaStaticMethod) + ", items=") + this.items) + ")"); + } + } + private static final @java.lang.SuppressWarnings("all") class ParentBuilderImpl extends SuperBuilderWithSetterPrefix.Parent.ParentBuilder<SuperBuilderWithSetterPrefix.Parent, SuperBuilderWithSetterPrefix.Parent.ParentBuilderImpl> { + private ParentBuilderImpl() { + super(); + } + protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithSetterPrefix.Parent.ParentBuilderImpl self() { + return this; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithSetterPrefix.Parent build() { + return new SuperBuilderWithSetterPrefix.Parent(this); + } + } + private int field1; + @lombok.Builder.ObtainVia(field = "field1") int obtainViaField; + @lombok.Builder.ObtainVia(method = "method") int obtainViaMethod; + @lombok.Builder.ObtainVia(method = "staticMethod",isStatic = true) String obtainViaStaticMethod; + @lombok.Singular List<String> items; + private int method() { + return 2; + } + private static String staticMethod(Parent instance) { + return "staticMethod"; + } + protected @java.lang.SuppressWarnings("all") Parent(final SuperBuilderWithSetterPrefix.Parent.ParentBuilder<?, ?> b) { + super(); + this.field1 = b.field1; + this.obtainViaField = b.obtainViaField; + this.obtainViaMethod = b.obtainViaMethod; + this.obtainViaStaticMethod = b.obtainViaStaticMethod; + java.util.List<String> items; + switch (((b.items == null) ? 0 : b.items.size())) { + case 0 : + items = java.util.Collections.emptyList(); + break; + case 1 : + items = java.util.Collections.singletonList(b.items.get(0)); + break; + default : + items = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(b.items)); + } + this.items = items; + } + public @java.lang.SuppressWarnings("all") SuperBuilderWithSetterPrefix.Parent.ParentBuilder<?, ?> toBuilder() { + return new SuperBuilderWithSetterPrefix.Parent.ParentBuilderImpl().$fillValuesFrom(this); + } + public static @java.lang.SuppressWarnings("all") SuperBuilderWithSetterPrefix.Parent.ParentBuilder<?, ?> builder() { + return new SuperBuilderWithSetterPrefix.Parent.ParentBuilderImpl(); + } + } + public static @lombok.experimental.SuperBuilder(toBuilder = true,setterPrefix = "set") class Child extends Parent { + public static abstract @java.lang.SuppressWarnings("all") class ChildBuilder<C extends SuperBuilderWithSetterPrefix.Child, B extends SuperBuilderWithSetterPrefix.Child.ChildBuilder<C, B>> extends Parent.ParentBuilder<C, B> { + private @java.lang.SuppressWarnings("all") double field3; + public ChildBuilder() { + super(); + } + protected @java.lang.Override @java.lang.SuppressWarnings("all") B $fillValuesFrom(final C instance) { + super.$fillValuesFrom(instance); + SuperBuilderWithSetterPrefix.Child.ChildBuilder.$fillValuesFromInstanceIntoBuilder(instance, this); + return self(); + } + private static @java.lang.SuppressWarnings("all") void $fillValuesFromInstanceIntoBuilder(final SuperBuilderWithSetterPrefix.Child instance, final SuperBuilderWithSetterPrefix.Child.ChildBuilder<?, ?> b) { + b.setField3(instance.field3); + } + protected abstract @java.lang.Override @java.lang.SuppressWarnings("all") B self(); + public abstract @java.lang.Override @java.lang.SuppressWarnings("all") C build(); + /** + * @return {@code this}. + */ + public @java.lang.SuppressWarnings("all") B setField3(final double field3) { + this.field3 = field3; + return self(); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return (((("SuperBuilderWithSetterPrefix.Child.ChildBuilder(super=" + super.toString()) + ", field3=") + this.field3) + ")"); + } + } + private static final @java.lang.SuppressWarnings("all") class ChildBuilderImpl extends SuperBuilderWithSetterPrefix.Child.ChildBuilder<SuperBuilderWithSetterPrefix.Child, SuperBuilderWithSetterPrefix.Child.ChildBuilderImpl> { + private ChildBuilderImpl() { + super(); + } + protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithSetterPrefix.Child.ChildBuilderImpl self() { + return this; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithSetterPrefix.Child build() { + return new SuperBuilderWithSetterPrefix.Child(this); + } + } + private double field3; + protected @java.lang.SuppressWarnings("all") Child(final SuperBuilderWithSetterPrefix.Child.ChildBuilder<?, ?> b) { + super(b); + this.field3 = b.field3; + } + public @java.lang.SuppressWarnings("all") SuperBuilderWithSetterPrefix.Child.ChildBuilder<?, ?> toBuilder() { + return new SuperBuilderWithSetterPrefix.Child.ChildBuilderImpl().$fillValuesFrom(this); + } + public static @java.lang.SuppressWarnings("all") SuperBuilderWithSetterPrefix.Child.ChildBuilder<?, ?> builder() { + return new SuperBuilderWithSetterPrefix.Child.ChildBuilderImpl(); + } + } + public SuperBuilderWithSetterPrefix() { + super(); + } + public static void test() { + Child x = Child.builder().setField3(0.0).withField1(5).withItem("").build().toBuilder().build(); + } +} diff --git a/test/transform/resource/after-ecj/SynchronizedInRecord.java b/test/transform/resource/after-ecj/SynchronizedInRecord.java new file mode 100644 index 00000000..b4dc3770 --- /dev/null +++ b/test/transform/resource/after-ecj/SynchronizedInRecord.java @@ -0,0 +1,14 @@ +import lombok.Synchronized; +public record SynchronizedInRecord(java $lock, String a) { + private final java.lang.Object $lock = new java.lang.Object[0]; +/* Implicit */ private final String a; +/* Implicit */ private final String b; + public SynchronizedInRecord(String a, String b) { + super(); + .a = a; + .b = b; + } + public @Synchronized void foo() { + String foo = "bar"; + } +} diff --git a/test/transform/resource/after-ecj/ToStringOnRecord.java b/test/transform/resource/after-ecj/ToStringOnRecord.java new file mode 100644 index 00000000..9ca18e8c --- /dev/null +++ b/test/transform/resource/after-ecj/ToStringOnRecord.java @@ -0,0 +1,11 @@ +// version 14: +import lombok.ToString; +public @ToString record ToStringOnRecord(String a, String b) { +/* Implicit */ private final String a; +/* Implicit */ private final String b; + public ToStringOnRecord(String a, String b) { + super(); + .a = a; + .b = b; + } +} diff --git a/test/transform/resource/after-ecj/UtilityClassOnRecord.java b/test/transform/resource/after-ecj/UtilityClassOnRecord.java new file mode 100644 index 00000000..8ffa8909 --- /dev/null +++ b/test/transform/resource/after-ecj/UtilityClassOnRecord.java @@ -0,0 +1,11 @@ +// version 14: +import lombok.experimental.UtilityClass; +public @UtilityClass record UtilityClassOnRecord(String a, String b) { +/* Implicit */ private final String a; +/* Implicit */ private final String b; + public UtilityClassOnRecord(String a, String b) { + super(); + .a = a; + .b = b; + } +} diff --git a/test/transform/resource/after-ecj/ValueCallSuper.java b/test/transform/resource/after-ecj/ValueCallSuper.java index 2fef08ab..72422a4a 100644 --- a/test/transform/resource/after-ecj/ValueCallSuper.java +++ b/test/transform/resource/after-ecj/ValueCallSuper.java @@ -1,32 +1,32 @@ -class ValueParent {
- ValueParent() {
- super();
- }
-}
-final @lombok.Value class ValueCallSuper extends ValueParent {
- public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) {
- if ((o == this))
- return true;
- if ((! (o instanceof ValueCallSuper)))
- return false;
- final ValueCallSuper other = (ValueCallSuper) o;
- if ((! other.canEqual((java.lang.Object) this)))
- return false;
- if ((! super.equals(o)))
- return false;
- return true;
- }
- protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
- return (other instanceof ValueCallSuper);
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
- final int result = super.hashCode();
- return result;
- }
- public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
- return "ValueCallSuper()";
- }
- public @java.lang.SuppressWarnings("all") ValueCallSuper() {
- super();
- }
-}
+class ValueParent { + ValueParent() { + super(); + } +} +final @lombok.Value class ValueCallSuper extends ValueParent { + public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) { + if ((o == this)) + return true; + if ((! (o instanceof ValueCallSuper))) + return false; + final ValueCallSuper other = (ValueCallSuper) o; + if ((! other.canEqual((java.lang.Object) this))) + return false; + if ((! super.equals(o))) + return false; + return true; + } + protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) { + return (other instanceof ValueCallSuper); + } + public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() { + final int result = super.hashCode(); + return result; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() { + return "ValueCallSuper()"; + } + public @java.lang.SuppressWarnings("all") ValueCallSuper() { + super(); + } +} diff --git a/test/transform/resource/after-ecj/ValueOnRecord.java b/test/transform/resource/after-ecj/ValueOnRecord.java new file mode 100644 index 00000000..47535305 --- /dev/null +++ b/test/transform/resource/after-ecj/ValueOnRecord.java @@ -0,0 +1,11 @@ +// version 14: +import lombok.Value; +public @Value record ValueOnRecord(String a, String b) { +/* Implicit */ private final String a; +/* Implicit */ private final String b; + public ValueOnRecord(String a, String b) { + super(); + .a = a; + .b = b; + } +} diff --git a/test/transform/resource/after-ecj/WithByOnRecord.java b/test/transform/resource/after-ecj/WithByOnRecord.java new file mode 100644 index 00000000..161382d9 --- /dev/null +++ b/test/transform/resource/after-ecj/WithByOnRecord.java @@ -0,0 +1,17 @@ +// version 14: +import lombok.experimental.WithBy; +public @WithBy record WithByOnRecord(String a, String b) { +/* Implicit */ private final String a; +/* Implicit */ private final String b; + public WithByOnRecord(String a, String b) { + super(); + .a = a; + .b = b; + } + public @java.lang.SuppressWarnings("all") WithByOnRecord withABy(final java.util.function.Function<? super String, ? extends String> transformer) { + return new WithByOnRecord(transformer.apply(this.a), this.b); + } + public @java.lang.SuppressWarnings("all") WithByOnRecord withBBy(final java.util.function.Function<? super String, ? extends String> transformer) { + return new WithByOnRecord(this.a, transformer.apply(this.b)); + } +} diff --git a/test/transform/resource/after-ecj/WithByOnRecordComponent.java b/test/transform/resource/after-ecj/WithByOnRecordComponent.java new file mode 100644 index 00000000..efc62161 --- /dev/null +++ b/test/transform/resource/after-ecj/WithByOnRecordComponent.java @@ -0,0 +1,14 @@ +// version 14: +import lombok.experimental.WithBy; +public record WithByOnRecordComponent(String a, String b) { +/* Implicit */ private final String a; +/* Implicit */ private final String b; + public WithByOnRecordComponent( String a, String b) { + super(); + .a = a; + .b = b; + } + public @java.lang.SuppressWarnings("all") WithByOnRecordComponent withABy(final java.util.function.Function<? super String, ? extends String> transformer) { + return new WithByOnRecordComponent(transformer.apply(this.a), this.b); + } +} diff --git a/test/transform/resource/after-ecj/WithOnRecord.java b/test/transform/resource/after-ecj/WithOnRecord.java new file mode 100644 index 00000000..d62bbfab --- /dev/null +++ b/test/transform/resource/after-ecj/WithOnRecord.java @@ -0,0 +1,23 @@ +// version 14: +import lombok.With; +public @With record WithOnRecord(String a, String b) { +/* Implicit */ private final String a; +/* Implicit */ private final String b; + public WithOnRecord(String a, String b) { + super(); + .a = a; + .b = 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") WithOnRecord withA(final String a) { + return ((this.a == a) ? this : new WithOnRecord(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") WithOnRecord withB(final String b) { + return ((this.b == b) ? this : new WithOnRecord(this.a, b)); + } +} diff --git a/test/transform/resource/after-ecj/WithOnRecordComponent.java b/test/transform/resource/after-ecj/WithOnRecordComponent.java new file mode 100644 index 00000000..a141fa46 --- /dev/null +++ b/test/transform/resource/after-ecj/WithOnRecordComponent.java @@ -0,0 +1,17 @@ +// version 14: +import lombok.With; +public record WithOnRecordComponent(String a, String b) { +/* Implicit */ private final String a; +/* Implicit */ private final String b; + public WithOnRecordComponent( String a, String b) { + super(); + .a = a; + .b = 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") WithOnRecordComponent withA(final String a) { + return ((this.a == a) ? this : new WithOnRecordComponent(a, this.b)); + } +} diff --git a/test/transform/resource/before/BuilderAccessWithGetter.java b/test/transform/resource/before/BuilderAccessWithGetter.java new file mode 100644 index 00000000..38212ecf --- /dev/null +++ b/test/transform/resource/before/BuilderAccessWithGetter.java @@ -0,0 +1,10 @@ +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; + +@Builder(access = AccessLevel.PRIVATE) +public final class BuilderAccessWithGetter { + + @Getter + private final String string; +} diff --git a/test/transform/resource/before/BuilderSimpleOnRecord.java b/test/transform/resource/before/BuilderSimpleOnRecord.java new file mode 100644 index 00000000..fdf681e7 --- /dev/null +++ b/test/transform/resource/before/BuilderSimpleOnRecord.java @@ -0,0 +1,7 @@ +// version 14: + +import java.util.List; + +@lombok.Builder(access = lombok.AccessLevel.PROTECTED) +public record BuilderSimpleOnRecord<T>(List<T> l, String a) { +} diff --git a/test/transform/resource/before/BuilderSingularNullBehavior1.java b/test/transform/resource/before/BuilderSingularNullBehavior1.java index bcf473a4..add00ea7 100644 --- a/test/transform/resource/before/BuilderSingularNullBehavior1.java +++ b/test/transform/resource/before/BuilderSingularNullBehavior1.java @@ -1,3 +1,4 @@ +//version 8: //CONF: lombok.addNullAnnotations = checkerframework //CONF: lombok.nonNull.exceptionType = assertion import java.util.List; diff --git a/test/transform/resource/before/BuilderSingularNullBehavior2.java b/test/transform/resource/before/BuilderSingularNullBehavior2.java index 7d1d0e57..dde4eea9 100644 --- a/test/transform/resource/before/BuilderSingularNullBehavior2.java +++ b/test/transform/resource/before/BuilderSingularNullBehavior2.java @@ -1,3 +1,4 @@ +//version 8: springframework dep is too new to run on j6 //CONF: lombok.addNullAnnotations = spring //CONF: lombok.nonNull.exceptionType = JDK import java.util.List; diff --git a/test/transform/resource/before/BuilderSingularOnRecord.java b/test/transform/resource/before/BuilderSingularOnRecord.java new file mode 100644 index 00000000..c34fdabd --- /dev/null +++ b/test/transform/resource/before/BuilderSingularOnRecord.java @@ -0,0 +1,11 @@ +// version 14: + +import java.util.Collection; +import java.util.List; + +import lombok.Builder; +import lombok.Singular; + +@Builder +public record BuilderSingularOnRecord<T>(@Singular List<T> children, @Singular Collection<? extends Number> scarves, @SuppressWarnings("all") @Singular("rawList") List rawList) { +}
\ No newline at end of file diff --git a/test/transform/resource/before/BuilderWithNonNull.java b/test/transform/resource/before/BuilderWithNonNull.java index 03a54326..b0c1d36a 100644 --- a/test/transform/resource/before/BuilderWithNonNull.java +++ b/test/transform/resource/before/BuilderWithNonNull.java @@ -1,3 +1,4 @@ +//version 8: @lombok.Builder class BuilderWithNonNull { @lombok.NonNull diff --git a/test/transform/resource/before/BuilderWithNonNullWithSetterPrefix.java b/test/transform/resource/before/BuilderWithNonNullWithSetterPrefix.java index 8ef1f70e..7c1aa983 100644 --- a/test/transform/resource/before/BuilderWithNonNullWithSetterPrefix.java +++ b/test/transform/resource/before/BuilderWithNonNullWithSetterPrefix.java @@ -1,3 +1,4 @@ +//version 8: @lombok.Builder(setterPrefix = "with") class BuilderWithNonNullWithSetterPrefix { @lombok.NonNull diff --git a/test/transform/resource/before/CheckerFrameworkBasic.java b/test/transform/resource/before/CheckerFrameworkBasic.java index fb43ad08..4bf1ac73 100644 --- a/test/transform/resource/before/CheckerFrameworkBasic.java +++ b/test/transform/resource/before/CheckerFrameworkBasic.java @@ -1,3 +1,4 @@ +//version 8: //CONF: checkerframework = 4.0 import lombok.AllArgsConstructor; import lombok.Data; diff --git a/test/transform/resource/before/CheckerFrameworkBuilder.java b/test/transform/resource/before/CheckerFrameworkBuilder.java index 440b80e9..0f24e1b7 100644 --- a/test/transform/resource/before/CheckerFrameworkBuilder.java +++ b/test/transform/resource/before/CheckerFrameworkBuilder.java @@ -1,3 +1,4 @@ +//version 8: //CONF: checkerframework = 4.0 import java.util.List; import lombok.Builder; diff --git a/test/transform/resource/before/CheckerFrameworkSuperBuilder.java b/test/transform/resource/before/CheckerFrameworkSuperBuilder.java index ed9e14cb..fefff676 100644 --- a/test/transform/resource/before/CheckerFrameworkSuperBuilder.java +++ b/test/transform/resource/before/CheckerFrameworkSuperBuilder.java @@ -1,3 +1,4 @@ +//version 8: //CONF: checkerframework = 4.0 import java.util.List; import lombok.Singular; diff --git a/test/transform/resource/before/ConstructorsOnRecord.java b/test/transform/resource/before/ConstructorsOnRecord.java new file mode 100644 index 00000000..003fc533 --- /dev/null +++ b/test/transform/resource/before/ConstructorsOnRecord.java @@ -0,0 +1,11 @@ +// version 14: + +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; +import lombok.RequiredArgsConstructor; + +@AllArgsConstructor +@RequiredArgsConstructor +@NoArgsConstructor +public record ConstructorsOnRecord(String a, String b) { +}
\ No newline at end of file diff --git a/test/transform/resource/before/ConstructorsWithAccessors.java b/test/transform/resource/before/ConstructorsWithAccessors.java index e67a47ce..fc72be55 100644 --- a/test/transform/resource/before/ConstructorsWithAccessors.java +++ b/test/transform/resource/before/ConstructorsWithAccessors.java @@ -1,3 +1,4 @@ +//version 8: @lombok.AllArgsConstructor @lombok.experimental.Accessors(prefix={"p", "_"}) class ConstructorsWithAccessors { int plower; int pUpper; @@ -11,4 +12,3 @@ @lombok.NonNull Integer _huh; @lombok.NonNull final Integer __huh2; } - diff --git a/test/transform/resource/before/DataOnLocalClass.java b/test/transform/resource/before/DataOnLocalClass.java index b1272b7e..e4fa4cd5 100644 --- a/test/transform/resource/before/DataOnLocalClass.java +++ b/test/transform/resource/before/DataOnLocalClass.java @@ -1,3 +1,4 @@ +//version 8: import lombok.Data; class DataOnLocalClass1 { public static void main(String[] args) { diff --git a/test/transform/resource/before/DataOnRecord.java b/test/transform/resource/before/DataOnRecord.java new file mode 100644 index 00000000..caf14d52 --- /dev/null +++ b/test/transform/resource/before/DataOnRecord.java @@ -0,0 +1,7 @@ +// version 14: + +import lombok.Data; + +@Data +public record DataOnRecord(String a, String b) { +}
\ No newline at end of file diff --git a/test/transform/resource/before/DataWithOverrideEqualsAndHashCode.java b/test/transform/resource/before/DataWithOverrideEqualsAndHashCode.java new file mode 100644 index 00000000..78138bbf --- /dev/null +++ b/test/transform/resource/before/DataWithOverrideEqualsAndHashCode.java @@ -0,0 +1,18 @@ +import lombok.Data; + +class DataWithOverrideEqualsAndHashCode { + class Data1 { + + } + + @Data + class Data2 extends Data1 { + public int hashCode() { + return 42; + } + + public boolean equals(Object other) { + return false; + } + } +}
\ No newline at end of file diff --git a/test/transform/resource/before/EqualsAndHashCodeAnnotated.java b/test/transform/resource/before/EqualsAndHashCodeAnnotated.java index d672b982..f65d7b5b 100644 --- a/test/transform/resource/before/EqualsAndHashCodeAnnotated.java +++ b/test/transform/resource/before/EqualsAndHashCodeAnnotated.java @@ -1,4 +1,4 @@ -//version 8 +//version 8: import java.lang.annotation.*; @lombok.EqualsAndHashCode diff --git a/test/transform/resource/before/EqualsAndHashCodeOnRecord.java b/test/transform/resource/before/EqualsAndHashCodeOnRecord.java new file mode 100644 index 00000000..84b808bb --- /dev/null +++ b/test/transform/resource/before/EqualsAndHashCodeOnRecord.java @@ -0,0 +1,7 @@ +// version 14: + +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode +public record EqualsAndHashCodeOnRecord(String a, String b) { +}
\ No newline at end of file diff --git a/test/transform/resource/before/ExtensionMethodChain.java b/test/transform/resource/before/ExtensionMethodChain.java new file mode 100644 index 00000000..f7960ed4 --- /dev/null +++ b/test/transform/resource/before/ExtensionMethodChain.java @@ -0,0 +1,17 @@ +import java.util.Arrays; +import java.util.List; +import lombok.experimental.ExtensionMethod; + +@ExtensionMethod(ExtensionMethodChain.Extensions.class) +class ExtensionMethodChain { + + public void test() { + "1".intValue().intValue(); + } + + static class Extensions { + public static Integer intValue(String s) { + return Integer.valueOf(s); + } + } +} diff --git a/test/transform/resource/before/ExtensionMethodFunctional.java b/test/transform/resource/before/ExtensionMethodFunctional.java index a9e7dd9f..8586dd7a 100644 --- a/test/transform/resource/before/ExtensionMethodFunctional.java +++ b/test/transform/resource/before/ExtensionMethodFunctional.java @@ -16,7 +16,7 @@ class ExtensionMethodFunctional { test.consume(s -> System.out.println("1: " + s), s -> System.out.println("2: " + s)); test.consume(System.out::println, System.out::println); - Stream.of("a", "b", "c").map(String::toUpperCase).toList(); + Stream.of("a", "b", "c").map(String::toUpperCase).toList1(); List<Integer> i2 = Stream.of("a", "b", "c").map(String::toUpperCase).toList2(); } @@ -36,7 +36,7 @@ class ExtensionMethodFunctional { } } - public static <T> List<T> toList(Stream<T> stream) { + public static <T> List<T> toList1(Stream<T> stream) { return (List<T>) stream.collect(Collectors.toList()); } diff --git a/test/transform/resource/before/ExtensionMethodNonStaticAccess.java b/test/transform/resource/before/ExtensionMethodNonStaticAccess.java new file mode 100644 index 00000000..0d317c35 --- /dev/null +++ b/test/transform/resource/before/ExtensionMethodNonStaticAccess.java @@ -0,0 +1,18 @@ +//issue #2752: this test triggers an indirect static access and a non static access warning for the same method call +//platform ecj,eclipse +class ExtensionMethodNonStaticAccess { + public void method(){ + Derived derived = new Derived(); + derived.staticMethod(); + } +} + +class Base { + static String staticMethod() { + return ""; + } +} + +class Derived extends Base { + +}
\ No newline at end of file diff --git a/test/transform/resource/before/FieldDefaultsOnRecord.java b/test/transform/resource/before/FieldDefaultsOnRecord.java new file mode 100644 index 00000000..94089b41 --- /dev/null +++ b/test/transform/resource/before/FieldDefaultsOnRecord.java @@ -0,0 +1,5 @@ +// version 14: + +@lombok.experimental.FieldDefaults(makeFinal = true) +public record FieldDefaultsOnRecord(String a, String b) { +}
\ No newline at end of file diff --git a/test/transform/resource/before/FieldNameConstantsOnRecord.java b/test/transform/resource/before/FieldNameConstantsOnRecord.java new file mode 100644 index 00000000..876bb853 --- /dev/null +++ b/test/transform/resource/before/FieldNameConstantsOnRecord.java @@ -0,0 +1,9 @@ +// version 14: + +import lombok.experimental.FieldNameConstants; +import lombok.AccessLevel; + +@FieldNameConstants(level = AccessLevel.PACKAGE) +public record FieldNameConstantsOnRecord(String iAmADvdPlayer, int $skipMe, @FieldNameConstants.Exclude int andMe, String butPrintMePlease) { + static double skipMeToo; +}
\ No newline at end of file diff --git a/test/transform/resource/before/GetterOnClass.java b/test/transform/resource/before/GetterOnClass.java index 0a38b386..f44d2556 100644 --- a/test/transform/resource/before/GetterOnClass.java +++ b/test/transform/resource/before/GetterOnClass.java @@ -1,3 +1,4 @@ +//version 8: @lombok.Getter class GetterOnClass1 { @lombok.Getter(lombok.AccessLevel.NONE) diff --git a/test/transform/resource/before/GetterOnRecord.java b/test/transform/resource/before/GetterOnRecord.java new file mode 100644 index 00000000..0addbfc6 --- /dev/null +++ b/test/transform/resource/before/GetterOnRecord.java @@ -0,0 +1,7 @@ +// version 14: + +import lombok.Getter; + +@Getter +public record GetterOnRecord(String a, String b) { +}
\ No newline at end of file diff --git a/test/transform/resource/before/JacksonBuilderSingular.java b/test/transform/resource/before/JacksonBuilderSingular.java index c179c760..20d6979a 100644 --- a/test/transform/resource/before/JacksonBuilderSingular.java +++ b/test/transform/resource/before/JacksonBuilderSingular.java @@ -1,3 +1,4 @@ +//version 8: Jackson deps are at least Java7+. import java.util.List; import java.util.Map; diff --git a/test/transform/resource/before/JacksonJsonProperty.java b/test/transform/resource/before/JacksonJsonProperty.java index f0b7b2f2..c0bccfae 100644 --- a/test/transform/resource/before/JacksonJsonProperty.java +++ b/test/transform/resource/before/JacksonJsonProperty.java @@ -1,3 +1,4 @@ +//version 8: Jackson deps are at least Java7+. import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonSetter; import com.fasterxml.jackson.annotation.Nulls; diff --git a/test/transform/resource/before/JacksonizedBuilderComplex.java b/test/transform/resource/before/JacksonizedBuilderComplex.java index dec1cd3b..5942926d 100644 --- a/test/transform/resource/before/JacksonizedBuilderComplex.java +++ b/test/transform/resource/before/JacksonizedBuilderComplex.java @@ -1,10 +1,11 @@ -//CONF: lombok.builder.className = Test*Name
-import java.util.List;
-import lombok.Builder;
-import lombok.extern.jackson.Jacksonized;
-
-class JacksonizedBuilderComplex {
- @Jacksonized
- @Builder(buildMethodName = "execute", setterPrefix = "with")
- private static <T extends Number> void testVoidWithGenerics(T number, int arg2, String arg3, JacksonizedBuilderComplex selfRef) {}
-}
+//version 8: Jackson deps are at least Java7+. +//CONF: lombok.builder.className = Test*Name +import java.util.List; +import lombok.Builder; +import lombok.extern.jackson.Jacksonized; + +class JacksonizedBuilderComplex { + @Jacksonized + @Builder(buildMethodName = "execute", setterPrefix = "with") + private static <T extends Number> void testVoidWithGenerics(T number, int arg2, String arg3, JacksonizedBuilderComplex selfRef) {} +} diff --git a/test/transform/resource/before/JacksonizedBuilderSimple.java b/test/transform/resource/before/JacksonizedBuilderSimple.java index 6da015ec..b81a0f5d 100644 --- a/test/transform/resource/before/JacksonizedBuilderSimple.java +++ b/test/transform/resource/before/JacksonizedBuilderSimple.java @@ -1,3 +1,4 @@ +//version 8: Jackson deps are at least Java7+. import java.util.List; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; diff --git a/test/transform/resource/before/JacksonizedSuperBuilderSimple.java b/test/transform/resource/before/JacksonizedSuperBuilderSimple.java index 1e3bd0fc..23e52c97 100644 --- a/test/transform/resource/before/JacksonizedSuperBuilderSimple.java +++ b/test/transform/resource/before/JacksonizedSuperBuilderSimple.java @@ -1,3 +1,4 @@ +//version 8: Jackson deps are at least Java7+. public class JacksonizedSuperBuilderSimple { @lombok.extern.jackson.Jacksonized @lombok.experimental.SuperBuilder diff --git a/test/transform/resource/before/JacksonizedSuperBuilderWithJsonDeserialize.java b/test/transform/resource/before/JacksonizedSuperBuilderWithJsonDeserialize.java index 0c80d1a6..ac0dba07 100644 --- a/test/transform/resource/before/JacksonizedSuperBuilderWithJsonDeserialize.java +++ b/test/transform/resource/before/JacksonizedSuperBuilderWithJsonDeserialize.java @@ -1,3 +1,4 @@ +//version 8: Jackson deps are at least Java7+. @lombok.extern.jackson.Jacksonized @lombok.experimental.SuperBuilder @com.fasterxml.jackson.databind.annotation.JsonDeserialize diff --git a/test/transform/resource/before/JavadocMultiline.java b/test/transform/resource/before/JavadocMultiline.java new file mode 100644 index 00000000..8557dba8 --- /dev/null +++ b/test/transform/resource/before/JavadocMultiline.java @@ -0,0 +1,22 @@ +@lombok.Getter +@lombok.Setter +class JavadocMultiline { + /** + * This is a list of booleans. + * + * @param booleans A list of booleans to set for this object. This is a Javadoc param that is + * long enough to wrap to multiple lines. + * @return A list of booleans to set for this object. This is a Javadoc return that is long + * enough to wrap to multiple lines. + */ + private java.util.List<Boolean> booleans; + + + /** + * This is a list of booleans. + * + * @param booleans A list of booleans to set for this object. This is a Javadoc param that is + * long enough to wrap to multiple lines. + */ + private java.util.List<Boolean> booleans2; +} diff --git a/test/transform/resource/before/LoggerConfigOnRecord.java b/test/transform/resource/before/LoggerConfigOnRecord.java new file mode 100644 index 00000000..b30392b3 --- /dev/null +++ b/test/transform/resource/before/LoggerConfigOnRecord.java @@ -0,0 +1,8 @@ +// CONF: lombok.log.fieldIsStatic = false +// version 14: + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public record LoggerConfigOnRecord(String a, String b) { +}
\ No newline at end of file diff --git a/test/transform/resource/before/LoggerLog4j2.java b/test/transform/resource/before/LoggerLog4j2.java index 10b3aae5..1dd48d7a 100644 --- a/test/transform/resource/before/LoggerLog4j2.java +++ b/test/transform/resource/before/LoggerLog4j2.java @@ -1,3 +1,4 @@ +//version 8: import lombok.extern.log4j.Log4j2; @lombok.extern.log4j.Log4j2 diff --git a/test/transform/resource/before/LoggerSlf4jInvalidTopic.java b/test/transform/resource/before/LoggerSlf4jInvalidTopic.java deleted file mode 100644 index eed02f01..00000000 --- a/test/transform/resource/before/LoggerSlf4jInvalidTopic.java +++ /dev/null @@ -1,5 +0,0 @@ -import lombok.extern.slf4j.Slf4j; - -@Slf4j(topic=42) -class LoggerSlf4jWithIntegerTopic { -}
\ No newline at end of file diff --git a/test/transform/resource/before/LoggerSlf4jOnRecord.java b/test/transform/resource/before/LoggerSlf4jOnRecord.java new file mode 100644 index 00000000..26359fd6 --- /dev/null +++ b/test/transform/resource/before/LoggerSlf4jOnRecord.java @@ -0,0 +1,7 @@ +// version 14: + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public record LoggerSlf4jOnRecord(String a, String b) { +}
\ No newline at end of file diff --git a/test/transform/resource/before/NonNullExistingConstructorOnRecord.java b/test/transform/resource/before/NonNullExistingConstructorOnRecord.java new file mode 100644 index 00000000..6a00e2c4 --- /dev/null +++ b/test/transform/resource/before/NonNullExistingConstructorOnRecord.java @@ -0,0 +1,9 @@ +// version 14: + +import lombok.NonNull; + +public record NonNullExistingConstructorOnRecord(@NonNull String a, @NonNull String b) { + public NonNullExistingConstructorOnRecord(@NonNull String b) { + this("default", b); + } +}
\ No newline at end of file diff --git a/test/transform/resource/before/NonNullOnParameter.java b/test/transform/resource/before/NonNullOnParameter.java index 22aceac7..43175832 100644 --- a/test/transform/resource/before/NonNullOnParameter.java +++ b/test/transform/resource/before/NonNullOnParameter.java @@ -1,3 +1,4 @@ +//version 8: class NonNullOnParameter extends Thread { NonNullOnParameter(@lombok.NonNull String arg) { this(arg, ""); diff --git a/test/transform/resource/before/NonNullOnParameterAbstract.java b/test/transform/resource/before/NonNullOnParameterAbstract.java index 16691184..0508be42 100644 --- a/test/transform/resource/before/NonNullOnParameterAbstract.java +++ b/test/transform/resource/before/NonNullOnParameterAbstract.java @@ -1,3 +1,4 @@ +//version 8: abstract class NonNullOnParameterAbstract { public void test(@lombok.NonNull String arg) { System.out.println("Hey"); diff --git a/test/transform/resource/before/NonNullOnRecord.java b/test/transform/resource/before/NonNullOnRecord.java new file mode 100644 index 00000000..ba6121a6 --- /dev/null +++ b/test/transform/resource/before/NonNullOnRecord.java @@ -0,0 +1,6 @@ +// version 14: + +import lombok.NonNull; + +public record NonNullOnRecord(@NonNull String a, @NonNull String b) { +}
\ No newline at end of file diff --git a/test/transform/resource/before/NonNullOnRecord2.java b/test/transform/resource/before/NonNullOnRecord2.java new file mode 100644 index 00000000..3a4eacd4 --- /dev/null +++ b/test/transform/resource/before/NonNullOnRecord2.java @@ -0,0 +1,9 @@ +// version 14: + +import lombok.NonNull; + +record NonNullOnRecord2(@NonNull String a) { + public NonNullOnRecord2 { + System.out.println("Hello"); + } +}
\ No newline at end of file diff --git a/test/transform/resource/before/NonNullOnRecord3.java b/test/transform/resource/before/NonNullOnRecord3.java new file mode 100644 index 00000000..24198002 --- /dev/null +++ b/test/transform/resource/before/NonNullOnRecord3.java @@ -0,0 +1,13 @@ +// version 14: + +import lombok.NonNull; + +public record NonNullOnRecord3(@NonNull String a) { + public NonNullOnRecord3(String a) { + this.a = a; + } + + public void method(@NonNull String param) { + String asd = "a"; + } +}
\ No newline at end of file diff --git a/test/transform/resource/before/NonNullPlain.java b/test/transform/resource/before/NonNullPlain.java index a438d1d4..1a016fb4 100644 --- a/test/transform/resource/before/NonNullPlain.java +++ b/test/transform/resource/before/NonNullPlain.java @@ -1,3 +1,4 @@ +//version 8: import java.lang.annotation.*; @lombok.RequiredArgsConstructor diff --git a/test/transform/resource/before/NonNullWithAlternateException.java b/test/transform/resource/before/NonNullWithAlternateException.java index c47f5727..28b7be6d 100644 --- a/test/transform/resource/before/NonNullWithAlternateException.java +++ b/test/transform/resource/before/NonNullWithAlternateException.java @@ -1,3 +1,4 @@ +//version 8: //CONF: lombok.nonNull.exceptionType = IllegalArgumentException public class NonNullWithAlternateException { diff --git a/test/transform/resource/before/NonNullWithAssertion.java b/test/transform/resource/before/NonNullWithAssertion.java index c3d271a6..1e282ffa 100644 --- a/test/transform/resource/before/NonNullWithAssertion.java +++ b/test/transform/resource/before/NonNullWithAssertion.java @@ -1,3 +1,4 @@ +//version 8: //CONF: lombok.nonNull.exceptionType = Assertion public class NonNullWithAssertion { diff --git a/test/transform/resource/before/NonNullWithGuava.java b/test/transform/resource/before/NonNullWithGuava.java index dc877daa..e592ee14 100644 --- a/test/transform/resource/before/NonNullWithGuava.java +++ b/test/transform/resource/before/NonNullWithGuava.java @@ -1,3 +1,4 @@ +//version 8: //CONF: lombok.nonNull.exceptionType = Guava import static com.google.common.base.Preconditions.*; public class NonNullWithGuava { diff --git a/test/transform/resource/before/NonNullWithJdk.java b/test/transform/resource/before/NonNullWithJdk.java index c8cbf2ee..5c3d03a5 100644 --- a/test/transform/resource/before/NonNullWithJdk.java +++ b/test/transform/resource/before/NonNullWithJdk.java @@ -1,4 +1,4 @@ -//version 7: +//version 8: //CONF: lombok.nonNull.exceptionType = Jdk import static java.util.Objects.*; public class NonNullWithJdk { diff --git a/test/transform/resource/before/NonNullWithSneakyThrows.java b/test/transform/resource/before/NonNullWithSneakyThrows.java index 35f78a7f..00c03f04 100644 --- a/test/transform/resource/before/NonNullWithSneakyThrows.java +++ b/test/transform/resource/before/NonNullWithSneakyThrows.java @@ -1,3 +1,4 @@ +//version 8: class NonNullWithSneakyThrows { @lombok.SneakyThrows void test(@lombok.NonNull String in) { System.out.println(in); diff --git a/test/transform/resource/before/NullAnnotatedCheckerFrameworkSuperBuilder.java b/test/transform/resource/before/NullAnnotatedCheckerFrameworkSuperBuilder.java new file mode 100644 index 00000000..eea118cb --- /dev/null +++ b/test/transform/resource/before/NullAnnotatedCheckerFrameworkSuperBuilder.java @@ -0,0 +1,20 @@ +//version 8: +//CONF: lombok.addNullAnnotations = checkerframework +import java.util.List; +import lombok.Singular; + +class NullAnnotatedCheckerFrameworkSuperBuilder { + @lombok.experimental.SuperBuilder + public static class Parent { + @lombok.Builder.Default int x = 5; + int y; + int z; + @Singular List<String> names; + } + + @lombok.experimental.SuperBuilder + public static class ZChild extends Parent { + @lombok.Builder.Default int a = 1; + int b; + } +} diff --git a/test/transform/resource/before/NullLibrary1.java b/test/transform/resource/before/NullLibrary1.java index 95433270..d57d3d09 100644 --- a/test/transform/resource/before/NullLibrary1.java +++ b/test/transform/resource/before/NullLibrary1.java @@ -1,3 +1,4 @@ +//version 8: //CONF: lombok.addNullAnnotations = eclipse @lombok.EqualsAndHashCode @lombok.ToString diff --git a/test/transform/resource/before/NullLibrary2.java b/test/transform/resource/before/NullLibrary2.java index 17b1e6e0..6b0ce4b0 100644 --- a/test/transform/resource/before/NullLibrary2.java +++ b/test/transform/resource/before/NullLibrary2.java @@ -1,3 +1,4 @@ +//version 8: springframework dep is too new to run on j6 //CONF: lombok.addNullAnnotations = spring @lombok.EqualsAndHashCode @lombok.ToString diff --git a/test/transform/resource/before/SetterOnClass.java b/test/transform/resource/before/SetterOnClass.java index a7629ff0..b7ab4177 100644 --- a/test/transform/resource/before/SetterOnClass.java +++ b/test/transform/resource/before/SetterOnClass.java @@ -1,3 +1,4 @@ +//version 8: @lombok.Setter class SetterOnClass1 { @lombok.Setter(lombok.AccessLevel.NONE) diff --git a/test/transform/resource/before/SetterOnRecord.java b/test/transform/resource/before/SetterOnRecord.java new file mode 100644 index 00000000..97e1a966 --- /dev/null +++ b/test/transform/resource/before/SetterOnRecord.java @@ -0,0 +1,7 @@ +// version 14: + +import lombok.Setter; + +@Setter +public record SetterOnRecord(String a, String b) { +}
\ No newline at end of file diff --git a/test/transform/resource/before/StaticConstructor.java b/test/transform/resource/before/StaticConstructor.java index eff1fa9b..7b720c6f 100644 --- a/test/transform/resource/before/StaticConstructor.java +++ b/test/transform/resource/before/StaticConstructor.java @@ -1,3 +1,4 @@ +//version 8: //CONF: lombok.addNullAnnotations = checkerframework import lombok.AllArgsConstructor; @AllArgsConstructor(staticName = "of") diff --git a/test/transform/resource/before/SuperBuilderBasicToBuilder.java b/test/transform/resource/before/SuperBuilderBasicToBuilder.java index 93161443..bd97876e 100644 --- a/test/transform/resource/before/SuperBuilderBasicToBuilder.java +++ b/test/transform/resource/before/SuperBuilderBasicToBuilder.java @@ -15,7 +15,7 @@ public class SuperBuilderBasicToBuilder { private int method() { return 2; } - + private static String staticMethod(Parent instance) { return "staticMethod"; } diff --git a/test/transform/resource/before/SuperBuilderCustomized.java b/test/transform/resource/before/SuperBuilderCustomized.java index 8e641d90..652d0865 100644 --- a/test/transform/resource/before/SuperBuilderCustomized.java +++ b/test/transform/resource/before/SuperBuilderCustomized.java @@ -1,3 +1,4 @@ +//version 8: Javac 6 will error out due to `ChildBuilder` not existing before properly running lombok. Giving j6 support status, not worth fixing. import java.util.List; public class SuperBuilderCustomized { diff --git a/test/transform/resource/before/SuperBuilderInitializer.java b/test/transform/resource/before/SuperBuilderInitializer.java new file mode 100644 index 00000000..966a4daf --- /dev/null +++ b/test/transform/resource/before/SuperBuilderInitializer.java @@ -0,0 +1,16 @@ +import lombok.experimental.SuperBuilder; + +class SuperBuilderInitializer { + @SuperBuilder + public static class One { + private String world; + { + world = "Hello"; + } + + private static final String world2; + static { + world2 = "Hello"; + } + } +} diff --git a/test/transform/resource/before/SuperBuilderOnRecord.java b/test/transform/resource/before/SuperBuilderOnRecord.java new file mode 100644 index 00000000..23e5efac --- /dev/null +++ b/test/transform/resource/before/SuperBuilderOnRecord.java @@ -0,0 +1,8 @@ +// skip compare content +// version 14: + +import lombok.experimental.SuperBuilder; + +@SuperBuilder +record SuperBuilderOnRecord(String a, String b) { +}
\ No newline at end of file diff --git a/test/transform/resource/before/SuperBuilderSingularAnnotatedTypes.java b/test/transform/resource/before/SuperBuilderSingularAnnotatedTypes.java index d26352d2..097f4e60 100644 --- a/test/transform/resource/before/SuperBuilderSingularAnnotatedTypes.java +++ b/test/transform/resource/before/SuperBuilderSingularAnnotatedTypes.java @@ -1,4 +1,4 @@ -//VERSION 8: +//version 8: import java.lang.annotation.ElementType; import java.lang.annotation.Target; import java.util.Set; diff --git a/test/transform/resource/before/SuperBuilderSingularCustomized.java b/test/transform/resource/before/SuperBuilderSingularCustomized.java new file mode 100644 index 00000000..86b6022a --- /dev/null +++ b/test/transform/resource/before/SuperBuilderSingularCustomized.java @@ -0,0 +1,9 @@ +import java.util.Set; +@lombok.experimental.SuperBuilder +class SuperBuilderSingularCustomized { + @lombok.Singular private Set<String> foos; + public static abstract class SuperBuilderSingularCustomizedBuilder<C extends SuperBuilderSingularCustomized, B extends SuperBuilderSingularCustomized.SuperBuilderSingularCustomizedBuilder<C, B>> { + public B custom(final String value) { + return self(); + } + }} diff --git a/test/transform/resource/before/SuperBuilderWithCustomBuilderMethod.java b/test/transform/resource/before/SuperBuilderWithCustomBuilderMethod.java index d52cbded..b828eafe 100644 --- a/test/transform/resource/before/SuperBuilderWithCustomBuilderMethod.java +++ b/test/transform/resource/before/SuperBuilderWithCustomBuilderMethod.java @@ -1,3 +1,4 @@ +//version 8: Javac 6 will error out due to `ChildBuilder` not existing before properly running lombok. Giving j6 support status, not worth fixing. import java.util.List; public class SuperBuilderWithCustomBuilderMethod { diff --git a/test/transform/resource/before/SuperBuilderWithExistingConstructor.java b/test/transform/resource/before/SuperBuilderWithExistingConstructor.java new file mode 100644 index 00000000..d6bfe2ec --- /dev/null +++ b/test/transform/resource/before/SuperBuilderWithExistingConstructor.java @@ -0,0 +1,5 @@ +@lombok.experimental.SuperBuilder +public class SuperBuilderWithExistingConstructor { + public SuperBuilderWithExistingConstructor() { + } +} diff --git a/test/transform/resource/before/SuperBuilderWithNonNull.java b/test/transform/resource/before/SuperBuilderWithNonNull.java index 34668bbc..7287c688 100644 --- a/test/transform/resource/before/SuperBuilderWithNonNull.java +++ b/test/transform/resource/before/SuperBuilderWithNonNull.java @@ -1,3 +1,4 @@ +//version 8: import java.util.List; public class SuperBuilderWithNonNull { diff --git a/test/transform/resource/before/SynchronizedInRecord.java b/test/transform/resource/before/SynchronizedInRecord.java new file mode 100644 index 00000000..0569fd5e --- /dev/null +++ b/test/transform/resource/before/SynchronizedInRecord.java @@ -0,0 +1,10 @@ +// version 14: + +import lombok.Synchronized; + +public record SynchronizedInRecord(String a, String b) { + @Synchronized + public void foo() { + String foo = "bar"; + } +}
\ No newline at end of file diff --git a/test/transform/resource/before/ToStringOnRecord.java b/test/transform/resource/before/ToStringOnRecord.java new file mode 100644 index 00000000..2d3ae039 --- /dev/null +++ b/test/transform/resource/before/ToStringOnRecord.java @@ -0,0 +1,7 @@ +// version 14: + +import lombok.ToString; + +@ToString +public record ToStringOnRecord(String a, String b) { +}
\ No newline at end of file diff --git a/test/transform/resource/before/UtilityClassOnRecord.java b/test/transform/resource/before/UtilityClassOnRecord.java new file mode 100644 index 00000000..4d73a166 --- /dev/null +++ b/test/transform/resource/before/UtilityClassOnRecord.java @@ -0,0 +1,7 @@ +// version 14: + +import lombok.experimental.UtilityClass; + +@UtilityClass +public record UtilityClassOnRecord(String a, String b) { +}
\ No newline at end of file diff --git a/test/transform/resource/before/ValDelegateMethodReference.java b/test/transform/resource/before/ValDelegateMethodReference.java index 21b781aa..3d1f082c 100644 --- a/test/transform/resource/before/ValDelegateMethodReference.java +++ b/test/transform/resource/before/ValDelegateMethodReference.java @@ -1,3 +1,4 @@ +//version 8: //platform !eclipse: Requires a 'full' eclipse with intialized workspace, and we don't (yet) have that set up properly in the test run. import lombok.Getter; import lombok.Setter; diff --git a/test/transform/resource/before/ValWeirdTypes.java b/test/transform/resource/before/ValWeirdTypes.java index 8dd63e86..f62feca6 100644 --- a/test/transform/resource/before/ValWeirdTypes.java +++ b/test/transform/resource/before/ValWeirdTypes.java @@ -1,3 +1,4 @@ +// version 8: In java6/7, lub types worked differently, so, the `arraysAsList` method has a slightly different inferred type there. import java.math.BigDecimal; import java.util.*; import lombok.val; diff --git a/test/transform/resource/before/ValueCallSuper.java b/test/transform/resource/before/ValueCallSuper.java index e236b404..bf561998 100644 --- a/test/transform/resource/before/ValueCallSuper.java +++ b/test/transform/resource/before/ValueCallSuper.java @@ -1,7 +1,7 @@ -//CONF: lombok.equalsAndHashCode.callSuper = call
-
-class ValueParent {
-}
-@lombok.Value
-class ValueCallSuper extends ValueParent {
-}
+//CONF: lombok.equalsAndHashCode.callSuper = call + +class ValueParent { +} +@lombok.Value +class ValueCallSuper extends ValueParent { +} diff --git a/test/transform/resource/before/ValueOnRecord.java b/test/transform/resource/before/ValueOnRecord.java new file mode 100644 index 00000000..64f685be --- /dev/null +++ b/test/transform/resource/before/ValueOnRecord.java @@ -0,0 +1,7 @@ +// version 14: + +import lombok.Value; + +@Value +public record ValueOnRecord(String a, String b) { +}
\ No newline at end of file diff --git a/test/transform/resource/before/WithByNullAnnos.java b/test/transform/resource/before/WithByNullAnnos.java index 3fd8087f..a3ef6ac3 100644 --- a/test/transform/resource/before/WithByNullAnnos.java +++ b/test/transform/resource/before/WithByNullAnnos.java @@ -1,3 +1,4 @@ +//version 8: //CONF: lombok.addNullAnnotations=checkerframework import java.util.List; @lombok.RequiredArgsConstructor diff --git a/test/transform/resource/before/WithByOnRecord.java b/test/transform/resource/before/WithByOnRecord.java new file mode 100644 index 00000000..8558d9a7 --- /dev/null +++ b/test/transform/resource/before/WithByOnRecord.java @@ -0,0 +1,7 @@ +// version 14: + +import lombok.experimental.WithBy; + +@WithBy +public record WithByOnRecord(String a, String b) { +}
\ No newline at end of file diff --git a/test/transform/resource/before/WithByOnRecordComponent.java b/test/transform/resource/before/WithByOnRecordComponent.java new file mode 100644 index 00000000..48bd66ca --- /dev/null +++ b/test/transform/resource/before/WithByOnRecordComponent.java @@ -0,0 +1,6 @@ +// version 14: + +import lombok.experimental.WithBy; + +public record WithByOnRecordComponent(@WithBy String a, String b) { +}
\ No newline at end of file diff --git a/test/transform/resource/before/WithByTypes.java b/test/transform/resource/before/WithByTypes.java index 9d2fe358..e33b0dd6 100644 --- a/test/transform/resource/before/WithByTypes.java +++ b/test/transform/resource/before/WithByTypes.java @@ -1,3 +1,4 @@ +//version 8: @lombok.RequiredArgsConstructor @lombok.experimental.FieldDefaults(level = lombok.AccessLevel.PRIVATE, makeFinal = true) @lombok.experimental.WithBy diff --git a/test/transform/resource/before/WithOnClass.java b/test/transform/resource/before/WithOnClass.java index a6215b54..fb6350e7 100644 --- a/test/transform/resource/before/WithOnClass.java +++ b/test/transform/resource/before/WithOnClass.java @@ -1,3 +1,5 @@ +//version 8: + @lombok.With class WithOnClass1 { @lombok.With(lombok.AccessLevel.NONE) diff --git a/test/transform/resource/before/WithOnRecord.java b/test/transform/resource/before/WithOnRecord.java new file mode 100644 index 00000000..99e77630 --- /dev/null +++ b/test/transform/resource/before/WithOnRecord.java @@ -0,0 +1,7 @@ +// version 14: + +import lombok.With; + +@With +public record WithOnRecord(String a, String b) { +}
\ No newline at end of file diff --git a/test/transform/resource/before/WithOnRecordComponent.java b/test/transform/resource/before/WithOnRecordComponent.java new file mode 100644 index 00000000..d8461b8b --- /dev/null +++ b/test/transform/resource/before/WithOnRecordComponent.java @@ -0,0 +1,6 @@ +// version 14: + +import lombok.With; + +public record WithOnRecordComponent(@With String a, String b) { +}
\ No newline at end of file diff --git a/test/transform/resource/before/WithPlain.java b/test/transform/resource/before/WithPlain.java index 4f048242..9be8d4d5 100644 --- a/test/transform/resource/before/WithPlain.java +++ b/test/transform/resource/before/WithPlain.java @@ -1,3 +1,4 @@ +//version 8: springframework dep is too new to run on j6 //CONF: lombok.addNullAnnotations = spring import lombok.With; class WithPlain { diff --git a/test/transform/resource/messages-delombok/ConstructorsOnRecord.java.messages b/test/transform/resource/messages-delombok/ConstructorsOnRecord.java.messages new file mode 100644 index 00000000..d1732a8c --- /dev/null +++ b/test/transform/resource/messages-delombok/ConstructorsOnRecord.java.messages @@ -0,0 +1,3 @@ +7 AllArgsConstructor is only supported on a class or an enum. +8 RequiredArgsConstructor is only supported on a class or an enum. +9 NoArgsConstructor is only supported on a class or an enum. diff --git a/test/transform/resource/messages-delombok/DataOnRecord.java.messages b/test/transform/resource/messages-delombok/DataOnRecord.java.messages new file mode 100644 index 00000000..42a9625b --- /dev/null +++ b/test/transform/resource/messages-delombok/DataOnRecord.java.messages @@ -0,0 +1 @@ +5 @Data is only supported on a class. diff --git a/test/transform/resource/messages-delombok/EqualsAndHashCodeOnRecord.java.messages b/test/transform/resource/messages-delombok/EqualsAndHashCodeOnRecord.java.messages new file mode 100644 index 00000000..daa53bcd --- /dev/null +++ b/test/transform/resource/messages-delombok/EqualsAndHashCodeOnRecord.java.messages @@ -0,0 +1 @@ +5 @EqualsAndHashCode is only supported on a class. diff --git a/test/transform/resource/messages-delombok/FieldDefaultsOnRecord.java.messages b/test/transform/resource/messages-delombok/FieldDefaultsOnRecord.java.messages new file mode 100644 index 00000000..1afb1bdf --- /dev/null +++ b/test/transform/resource/messages-delombok/FieldDefaultsOnRecord.java.messages @@ -0,0 +1 @@ +3 @FieldDefaults is only supported on a class or an enum. diff --git a/test/transform/resource/messages-delombok/GetterOnRecord.java.messages b/test/transform/resource/messages-delombok/GetterOnRecord.java.messages new file mode 100644 index 00000000..0830c585 --- /dev/null +++ b/test/transform/resource/messages-delombok/GetterOnRecord.java.messages @@ -0,0 +1 @@ +5 @Getter is only supported on a class, an enum, or a field. diff --git a/test/transform/resource/messages-delombok/LoggerConfigOnRecord.java.messages b/test/transform/resource/messages-delombok/LoggerConfigOnRecord.java.messages new file mode 100644 index 00000000..7dd3294e --- /dev/null +++ b/test/transform/resource/messages-delombok/LoggerConfigOnRecord.java.messages @@ -0,0 +1 @@ +6 Logger fields must be static in records. diff --git a/test/transform/resource/messages-delombok/LoggerSlf4jInvalidTopic.java.messages b/test/transform/resource/messages-delombok/LoggerSlf4jInvalidTopic.java.messages deleted file mode 100644 index 8de0a120..00000000 --- a/test/transform/resource/messages-delombok/LoggerSlf4jInvalidTopic.java.messages +++ /dev/null @@ -1,2 +0,0 @@ -3 incompatible types: int cannot be converted to java.lang.String --1 not flagged modified
\ No newline at end of file diff --git a/test/transform/resource/messages-delombok/SetterOnRecord.java.messages b/test/transform/resource/messages-delombok/SetterOnRecord.java.messages new file mode 100644 index 00000000..1913765c --- /dev/null +++ b/test/transform/resource/messages-delombok/SetterOnRecord.java.messages @@ -0,0 +1 @@ +5 @Setter is only supported on a class or a field. diff --git a/test/transform/resource/messages-delombok/SuperBuilderOnRecord.java.messages b/test/transform/resource/messages-delombok/SuperBuilderOnRecord.java.messages new file mode 100644 index 00000000..42d73efe --- /dev/null +++ b/test/transform/resource/messages-delombok/SuperBuilderOnRecord.java.messages @@ -0,0 +1 @@ +6 @SuperBuilder is only supported on classes. diff --git a/test/transform/resource/messages-delombok/SynchronizedInRecord.java.messages b/test/transform/resource/messages-delombok/SynchronizedInRecord.java.messages new file mode 100644 index 00000000..d40e68b3 --- /dev/null +++ b/test/transform/resource/messages-delombok/SynchronizedInRecord.java.messages @@ -0,0 +1 @@ +5 @Synchronized is legal only on methods in classes and enums. diff --git a/test/transform/resource/messages-delombok/ToStringOnRecord.java.messages b/test/transform/resource/messages-delombok/ToStringOnRecord.java.messages new file mode 100644 index 00000000..0299664b --- /dev/null +++ b/test/transform/resource/messages-delombok/ToStringOnRecord.java.messages @@ -0,0 +1 @@ +5 @ToString is only supported on a class or enum. diff --git a/test/transform/resource/messages-delombok/UtilityClassErrors.java.messages b/test/transform/resource/messages-delombok/UtilityClassErrors.java.messages index 4afa12ec..21e23ed5 100644 --- a/test/transform/resource/messages-delombok/UtilityClassErrors.java.messages +++ b/test/transform/resource/messages-delombok/UtilityClassErrors.java.messages @@ -1,4 +1,4 @@ 4 @UtilityClasses cannot have declared constructors. 7 @UtilityClass cannot be placed on a method local or anonymous inner class, or any class nested in such a class. -12 @UtilityClass is only supported on a class (can't be an interface, enum, or annotation). +12 @UtilityClass is only supported on a class. 17 @UtilityClass automatically makes the class static, however, this class cannot be made static.
\ No newline at end of file diff --git a/test/transform/resource/messages-delombok/UtilityClassOnRecord.java.messages b/test/transform/resource/messages-delombok/UtilityClassOnRecord.java.messages new file mode 100644 index 00000000..4091de0c --- /dev/null +++ b/test/transform/resource/messages-delombok/UtilityClassOnRecord.java.messages @@ -0,0 +1 @@ +5 @UtilityClass is only supported on a class. diff --git a/test/transform/resource/messages-delombok/ValueOnRecord.java.messages b/test/transform/resource/messages-delombok/ValueOnRecord.java.messages new file mode 100644 index 00000000..ebb71090 --- /dev/null +++ b/test/transform/resource/messages-delombok/ValueOnRecord.java.messages @@ -0,0 +1 @@ +5 @Value is only supported on a class. diff --git a/test/transform/resource/messages-ecj/ConstructorsOnRecord.java.messages b/test/transform/resource/messages-ecj/ConstructorsOnRecord.java.messages new file mode 100644 index 00000000..d1732a8c --- /dev/null +++ b/test/transform/resource/messages-ecj/ConstructorsOnRecord.java.messages @@ -0,0 +1,3 @@ +7 AllArgsConstructor is only supported on a class or an enum. +8 RequiredArgsConstructor is only supported on a class or an enum. +9 NoArgsConstructor is only supported on a class or an enum. diff --git a/test/transform/resource/messages-ecj/DataOnRecord.java.messages b/test/transform/resource/messages-ecj/DataOnRecord.java.messages new file mode 100644 index 00000000..42a9625b --- /dev/null +++ b/test/transform/resource/messages-ecj/DataOnRecord.java.messages @@ -0,0 +1 @@ +5 @Data is only supported on a class. diff --git a/test/transform/resource/messages-ecj/EqualsAndHashCodeOnRecord.java.messages b/test/transform/resource/messages-ecj/EqualsAndHashCodeOnRecord.java.messages new file mode 100644 index 00000000..daa53bcd --- /dev/null +++ b/test/transform/resource/messages-ecj/EqualsAndHashCodeOnRecord.java.messages @@ -0,0 +1 @@ +5 @EqualsAndHashCode is only supported on a class. diff --git a/test/transform/resource/messages-ecj/ExtensionMethodNonStaticAccess.java.messages b/test/transform/resource/messages-ecj/ExtensionMethodNonStaticAccess.java.messages new file mode 100644 index 00000000..3f5f3988 --- /dev/null +++ b/test/transform/resource/messages-ecj/ExtensionMethodNonStaticAccess.java.messages @@ -0,0 +1,2 @@ +6 The static method staticMethod() from the type Base should be accessed directly +6 The static method staticMethod() from the type Base should be accessed in a static way
\ No newline at end of file diff --git a/test/transform/resource/messages-ecj/FieldDefaultsOnRecord.java.messages b/test/transform/resource/messages-ecj/FieldDefaultsOnRecord.java.messages new file mode 100644 index 00000000..1afb1bdf --- /dev/null +++ b/test/transform/resource/messages-ecj/FieldDefaultsOnRecord.java.messages @@ -0,0 +1 @@ +3 @FieldDefaults is only supported on a class or an enum. diff --git a/test/transform/resource/messages-ecj/GetterOnRecord.java.messages b/test/transform/resource/messages-ecj/GetterOnRecord.java.messages new file mode 100644 index 00000000..0830c585 --- /dev/null +++ b/test/transform/resource/messages-ecj/GetterOnRecord.java.messages @@ -0,0 +1 @@ +5 @Getter is only supported on a class, an enum, or a field. diff --git a/test/transform/resource/messages-ecj/LoggerConfigOnRecord.java.messages b/test/transform/resource/messages-ecj/LoggerConfigOnRecord.java.messages new file mode 100644 index 00000000..7dd3294e --- /dev/null +++ b/test/transform/resource/messages-ecj/LoggerConfigOnRecord.java.messages @@ -0,0 +1 @@ +6 Logger fields must be static in records. diff --git a/test/transform/resource/messages-ecj/LoggerSlf4jInvalidTopic.java.messages b/test/transform/resource/messages-ecj/LoggerSlf4jInvalidTopic.java.messages deleted file mode 100644 index 9bc2a82b..00000000 --- a/test/transform/resource/messages-ecj/LoggerSlf4jInvalidTopic.java.messages +++ /dev/null @@ -1 +0,0 @@ -3 Type mismatch: cannot convert from int to String
\ No newline at end of file diff --git a/test/transform/resource/messages-ecj/SetterOnRecord.java.messages b/test/transform/resource/messages-ecj/SetterOnRecord.java.messages new file mode 100644 index 00000000..1913765c --- /dev/null +++ b/test/transform/resource/messages-ecj/SetterOnRecord.java.messages @@ -0,0 +1 @@ +5 @Setter is only supported on a class or a field. diff --git a/test/transform/resource/messages-ecj/SuperBuilderOnRecord.java.messages b/test/transform/resource/messages-ecj/SuperBuilderOnRecord.java.messages new file mode 100644 index 00000000..42d73efe --- /dev/null +++ b/test/transform/resource/messages-ecj/SuperBuilderOnRecord.java.messages @@ -0,0 +1 @@ +6 @SuperBuilder is only supported on classes. diff --git a/test/transform/resource/messages-ecj/SynchronizedInRecord.java.messages b/test/transform/resource/messages-ecj/SynchronizedInRecord.java.messages new file mode 100644 index 00000000..af4b11f8 --- /dev/null +++ b/test/transform/resource/messages-ecj/SynchronizedInRecord.java.messages @@ -0,0 +1 @@ +6 @Synchronized is legal only on methods in classes and enums. diff --git a/test/transform/resource/messages-ecj/ToStringOnRecord.java.messages b/test/transform/resource/messages-ecj/ToStringOnRecord.java.messages new file mode 100644 index 00000000..0299664b --- /dev/null +++ b/test/transform/resource/messages-ecj/ToStringOnRecord.java.messages @@ -0,0 +1 @@ +5 @ToString is only supported on a class or enum. diff --git a/test/transform/resource/messages-ecj/UtilityClassErrors.java.messages b/test/transform/resource/messages-ecj/UtilityClassErrors.java.messages index 15c9b10f..21e23ed5 100644 --- a/test/transform/resource/messages-ecj/UtilityClassErrors.java.messages +++ b/test/transform/resource/messages-ecj/UtilityClassErrors.java.messages @@ -1,4 +1,4 @@ 4 @UtilityClasses cannot have declared constructors. 7 @UtilityClass cannot be placed on a method local or anonymous inner class, or any class nested in such a class. -12 @UtilityClass is only supported on a class (can't be an interface, enum, or annotation) +12 @UtilityClass is only supported on a class. 17 @UtilityClass automatically makes the class static, however, this class cannot be made static.
\ No newline at end of file diff --git a/test/transform/resource/messages-ecj/UtilityClassOnRecord.java.messages b/test/transform/resource/messages-ecj/UtilityClassOnRecord.java.messages new file mode 100644 index 00000000..4091de0c --- /dev/null +++ b/test/transform/resource/messages-ecj/UtilityClassOnRecord.java.messages @@ -0,0 +1 @@ +5 @UtilityClass is only supported on a class. diff --git a/test/transform/resource/messages-ecj/ValueOnRecord.java.messages b/test/transform/resource/messages-ecj/ValueOnRecord.java.messages new file mode 100644 index 00000000..ebb71090 --- /dev/null +++ b/test/transform/resource/messages-ecj/ValueOnRecord.java.messages @@ -0,0 +1 @@ +5 @Value is only supported on a class. diff --git a/test/transform/resource/messages-idempotent/LoggerSlf4jInvalidTopic.java.messages b/test/transform/resource/messages-idempotent/LoggerSlf4jInvalidTopic.java.messages deleted file mode 100644 index d894fad1..00000000 --- a/test/transform/resource/messages-idempotent/LoggerSlf4jInvalidTopic.java.messages +++ /dev/null @@ -1 +0,0 @@ -3 incompatible types: int cannot be converted to java.lang.String
\ No newline at end of file diff --git a/test/transform/src/lombok/transform/TestLombokFilesIdempotent.java b/test/transform/src/lombok/transform/TestLombokFilesIdempotent.java index 754a4237..42d2b636 100644 --- a/test/transform/src/lombok/transform/TestLombokFilesIdempotent.java +++ b/test/transform/src/lombok/transform/TestLombokFilesIdempotent.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2015 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -58,4 +58,8 @@ public class TestLombokFilesIdempotent extends DirectoryRunner.TestParams { public boolean expectChanges() { return false; } + + @Override public String testNamePrefix() { + return "idempotent-"; + } } diff --git a/test/transform/src/lombok/transform/TestSourceFiles.java b/test/transform/src/lombok/transform/TestSourceFiles.java index 17be133e..ac8b59c1 100644 --- a/test/transform/src/lombok/transform/TestSourceFiles.java +++ b/test/transform/src/lombok/transform/TestSourceFiles.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2015 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -58,4 +58,8 @@ public class TestSourceFiles extends DirectoryRunner.TestParams { public boolean expectChanges() { return false; } + + @Override public String testNamePrefix() { + return "prettyprint-"; + } } diff --git a/test/transform/src/lombok/transform/TestWithDelombok.java b/test/transform/src/lombok/transform/TestWithDelombok.java index 9f4cf94a..f075ba04 100644 --- a/test/transform/src/lombok/transform/TestWithDelombok.java +++ b/test/transform/src/lombok/transform/TestWithDelombok.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2015 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -58,4 +58,8 @@ public class TestWithDelombok extends DirectoryRunner.TestParams { public boolean expectChanges() { return true; } + + @Override public String testNamePrefix() { + return "javac-"; + } } diff --git a/test/transform/src/lombok/transform/TestWithEcj.java b/test/transform/src/lombok/transform/TestWithEcj.java index 3df8dc8b..7b2a6c03 100644 --- a/test/transform/src/lombok/transform/TestWithEcj.java +++ b/test/transform/src/lombok/transform/TestWithEcj.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2015 The Project Lombok Authors. + * Copyright (C) 2009-2021 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 @@ -62,4 +62,8 @@ public class TestWithEcj extends DirectoryRunner.TestParams { public boolean expectChanges() { return true; } + + @Override public String testNamePrefix() { + return "ecj-"; + } } diff --git a/website/resources/js/order-license.js b/website/resources/js/order-license.js index 21550f34..6745567d 100644 --- a/website/resources/js/order-license.js +++ b/website/resources/js/order-license.js @@ -110,7 +110,7 @@ formFail = true; } - if (!data.seats || isNaN(data.seats) || data.seats < 1) { + if (!data.seats || isNaN(data.seats) || data.seats < 10) { $("#seats").focus(); showError("seats"); formFail = true; diff --git a/website/templates/features/NonNull.html b/website/templates/features/NonNull.html index 67cc262c..57aa62fe 100644 --- a/website/templates/features/NonNull.html +++ b/website/templates/features/NonNull.html @@ -7,11 +7,11 @@ <@f.overview> <p> - You can use <code>@NonNull</code> on the parameter of a method or constructor to have lombok generate a null-check statement for you. + You can use <code>@NonNull</code> on a record component, or a parameter of a method or constructor. This will cause to lombok generate a null-check statement for you. </p><p> - Lombok has always treated various annotations generally named <code>@NonNull</code> on a field as a signal to generate a null-check if lombok generates an entire method or constructor for you, via for example <a href="/features/Data"><code>@Data</code></a>. Now, however, using lombok's own <code>@lombok.NonNull</code> on a parameter results in the insertion of just the null-check statement inside your own method or constructor. + Lombok has always treated various annotations generally named <code>@NonNull</code> on a field as a signal to generate a null-check if lombok generates an entire method or constructor for you, via for example <a href="/features/Data"><code>@Data</code></a>. However, using lombok's own <code>@lombok.NonNull</code> on a parameter or record component results in the insertion of the null-check at the top of that method. </p><p> - The null-check looks like <code>if (param == null) throw new NullPointerException("param is marked @NonNull but is null");</code> and will be inserted at the very top of your method. For constructors, the null-check will be inserted immediately following any explicit <code>this()</code> or <code>super()</code> calls. + The null-check looks like <code>if (param == null) throw new NullPointerException("param is marked @NonNull but is null");</code> and will be inserted at the very top of your method. For constructors, the null-check will be inserted immediately following any explicit <code>this()</code> or <code>super()</code> calls. For record components, the null-check will be inserted in the 'compact constructor' (the one that has no argument list at all), which will be generated if you have no constructor. If you have written out the record constructor in long form (with parameters matching your components exactly), then nothing happens - you'd have to annotate the parameters of this long-form constructor instead. </p><p> If a null-check is already present at the top, no additional null-check will be generated. </p> diff --git a/website/templates/features/experimental/Accessors.html b/website/templates/features/experimental/Accessors.html index 97017dc6..54d507f8 100644 --- a/website/templates/features/experimental/Accessors.html +++ b/website/templates/features/experimental/Accessors.html @@ -15,7 +15,12 @@ New feature – community feedback requested. </li> </ul> - Current status: <em>positive</em> - Currently we feel this feature may move out of experimental status with no or minor changes soon. + Current status: <em>neutral</em> - Some changes are expected. These changes are intended to be backwards compatible, but should start in an experimental feature: + <ul> + <li>Open feature request: naming behaviour for properties that start with a lowercase letter followed by an uppercase letter. Half of specs, tools and lombok users prefer that a field named <code>uLimit</code> into <code>getULimit</code> (including lombok) and the other half turn prefer <code>getuLimit</code>. <code>@Accessors</code> may be involved in any update that addresses this <a href="https://github.com/rzwitserloot/lombok/issues/2693">request</a>.</li> + <li>Open feature request: More control over naming accessors; for example to address creatively named boolean properties: Turn <code>boolean wasRunning</code> into <code>boolean wasRunning()</code> instead of <code>boolean isWasRunning()</code>, as well as more expansive prefix support. <code>@Accessors</code> will be involved if this feature <a href="https://github.com/rzwitserloot/lombok/issues/2464">request</a> is addressed.</li> + <li><code>@Accessors</code> currently does not 'cascade' from field <code>@Accessors</code> annotation to the class-level <code>@Accessors</code> annotation, but it does 'cascade' to <code>lombok.config</code>. Changing this is not difficult but backwards incompatible. It's not likely to break much existing code, but this needs to be decided on before the feature can move out of <em>experimental</em> status.</li> + </ul> </@f.experimental> <@f.overview> @@ -39,7 +44,7 @@ </li> </ul> <p><p> - The <code>@Accessors</code> annotation is legal on types and fields; the annotation that applies is the one on the field if present, otherwise the one on the class. When a <code>@Accessors</code> annotation on a field is present, any <code>@Accessors</code> annotation also present on that field's type is ignored. + The <code>@Accessors</code> annotation is legal on types and fields; the annotation that applies is the one on the field if present, otherwise the one on the class. When a <code>@Accessors</code> annotation on a field is present, any <code>@Accessors</code> annotation also present on the class the field is in, is entirely ignored, <em>even for properties not configured on the field <code>@Accessors</code></em>. This in contrast to any <code>lombok.config</code> configuration keys which serve as fall-back default if any explicit <code>@Accessors</code> annotation doesn't specify. </p> </@f.overview> diff --git a/website/templates/order-license.html b/website/templates/order-license.html index c3f52cef..1feacbbc 100644 --- a/website/templates/order-license.html +++ b/website/templates/order-license.html @@ -28,21 +28,21 @@ <div class="form-check"> <label class="form-check-label"> <input type="radio" class="form-check-input licenseType" name="licenseType" value="professional" checked="checked" /> - Professional (€2,- per developer per month; ~ $2.50). + Professional (€2,- per developer per month; ~ $2.40). </label> </div> <div class="form-check"> <label class="form-check-label"> <input type="radio" class="form-check-input licenseType" name="licenseType" value="enterprise" /> - Enterprise (€5,- per developer per month; ~ $6.10). + Enterprise (€5,- per developer per month; ~ $6.00). </label> </div> </div> <div id="licenseTypeErr" class="formErr" hidden="hidden">License type is a required field.</div> <div class="form-group"> - <label for="seats"># of developers using lombok</label> + <label for="seats"># of developers using lombok (minimum: 10)</label> <input type="number" placeholder="# of developers" class="form-control" id="seats" /> - <div id="seatsErr" class="formErr" hidden="hidden">We need to know the # of developers to determine the license price.</div> + <div id="seatsErr" class="formErr" hidden="hidden">We need to know the # of developers to determine the license price, and that # needs to be at least 10.</div> </div> </fieldset> <fieldset class="form-group"> |