mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 20:17:25 +00:00
Merge ../lombok-branch-master into nullness-annotations
This commit is contained in:
commit
3f5e4a2819
196 files changed
+2599
-268
No files matched your search
@@ -49,6 +49,7 @@ Takuya Murakami <tmurakam@tmurakam.org>
|
||||
Thomas Darimont <thomas.darimont@gmail.com>
|
||||
Till Brychcy <till.brychcy@mercateo.com>
|
||||
Victor Williams Stafusa da Silva <victorwssilva@gmail.com>
|
||||
Yonatan Sherwin <yonatansherwin@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 in relation to all commits you add to Project Lombok, and you certify that you have the right to do so.
|
||||
@@ -152,13 +152,18 @@ This buildfile is part of projectlombok.org. It takes care of compiling and runn
|
||||
|
||||
<macrodef name="test.eclipse-X">
|
||||
<attribute name="version" />
|
||||
<attribute name="compiler.compliance.level" default="latest" />
|
||||
<sequential>
|
||||
<echo>Running TestEclipse on eclipse-@{version} on JVM${ant.java.version}.</echo>
|
||||
<condition property="compiler.compliance.level" value="-Dcompiler.compliance.level=@{compiler.compliance.level}" else="-Dnot=set">
|
||||
<not><equals arg1="@{compiler.compliance.level}" arg2="latest" /></not>
|
||||
</condition>
|
||||
<echo>Running TestEclipse on eclipse-@{version} on JVM${ant.java.version} using. Compiler compliance level: @{compiler.compliance.level}</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 value="${compiler.compliance.level}" />
|
||||
<classpath location="build/ant" />
|
||||
<classpath refid="cp.test" />
|
||||
<classpath refid="cp.stripe" />
|
||||
@@ -175,11 +180,16 @@ This buildfile is part of projectlombok.org. It takes care of compiling and runn
|
||||
<test.eclipse-X version="oxygen" />
|
||||
</target>
|
||||
|
||||
<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">
|
||||
<target name="test.eclipse-202006" depends="test.formatter.compile, test.compile" description="runs the tests on your default VM, testing the 2020-06 release of eclipse">
|
||||
<fetchdep.eclipse version="202006" />
|
||||
<test.eclipse-X version="202006" />
|
||||
</target>
|
||||
|
||||
<target name="test.eclipse-202006-jdk8" depends="test.formatter.compile, test.compile" description="runs the tests on your default VM, testing the 2020-06 release of eclipse with compiler compliance level 8">
|
||||
<fetchdep.eclipse version="202006" />
|
||||
<test.eclipse-X version="202006" compiler.compliance.level="8" />
|
||||
</target>
|
||||
|
||||
<macrodef name="test.ecj-X">
|
||||
<attribute name="version" />
|
||||
<sequential>
|
||||
@@ -217,5 +227,5 @@ This buildfile is part of projectlombok.org. It takes care of compiling and runn
|
||||
</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" />
|
||||
<target name="test.broad" depends="test.javac8, test.javac14, test.eclipse-oxygen, test.eclipse-202006, test.eclipse-202006-jdk8" description="runs the tests against the default JVM, javac, and eclipse" />
|
||||
</project>
|
||||
+11
-2
@@ -1,8 +1,17 @@
|
||||
Lombok Changelog
|
||||
----------------
|
||||
|
||||
### v1.18.21 "Edgy Guinea Pig"
|
||||
* Added the `@StandardException` feature. [Pull Request #2702](https://github.com/projectlombok/lombok/pull/2702).
|
||||
### v1.18.24 "Edgy Guinea Pig"
|
||||
* FEATURE: Turning a field named `uShape` into a getter is tricky: `getUShape` or `getuShape`? The community is split on which style to use. Lombok does `getUShape`, but if you prefer the `getuShape` style, add to `lombok.config`: `lombok.accessors.capitalization = beanspec`. [Issue #2693](https://github.com/projectlombok/lombok/issues/2693) [Pull Request #2996](https://github.com/projectlombok/lombok/pull/2996). Thanks __@YonathanSherwin__!
|
||||
* BUGFIX: Various save actions and refactor scripts in eclipse work better. [Issue #2995](https://github.com/projectlombok/lombok/issues/2995) [Issue #1309](https://github.com/projectlombok/lombok/issues/1309) [Issue #2985](https://github.com/projectlombok/lombok/issues/2985) [Issue #2509](https://github.com/projectlombok/lombok/issues/2509)
|
||||
|
||||
### v1.18.22 (October 6th, 2021)
|
||||
* PLATFORM: JDK17 support added. [Issue #2898](https://github.com/projectlombok/lombok/issues/2898).
|
||||
* FEATURE: Added the `@StandardException` feature. [Pull Request #2702](https://github.com/projectlombok/lombok/pull/2702).
|
||||
* IMPROBABLE BREAKING CHANGE: If the underlying compiler and `--release` / `--source` option is 10 or higher, lombok's `val` is now replaced by `final var`. That means compound declarations such as `val x = 10, y = 12;` now fail (lombok's old `val` implementation supported it, javac's `var` does not), but IDE support in particular is more reliable. We decided it was worth the tradeoff.
|
||||
* BUGFIX: Syntax highlighting in VSCode now works reliably when using lombok. [Issue #2950](https://github.com/projectlombok/lombok/issues/2950).
|
||||
* BUGFIX: Eclipse's _organize imports_ feature would sometimes remove your `lombok.val` import. [Issue #2972](https://github.com/projectlombok/lombok/issues/2972).
|
||||
|
||||
|
||||
### v1.18.20 (April 2nd, 2021)
|
||||
* PLATFORM: JDK16 support added. [Issue #2681](https://github.com/projectlombok/lombok/issues/2681).
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
# How to debug lombok running in eclipse
|
||||
|
||||
## Overview
|
||||
|
||||
Lombok's build scripting can generate a target for you, that lets you run the same eclipse installation inside eclipse, in debug mode. Now you can add breakpoints.
|
||||
|
||||
As lombok is an agent, lombok __must__ load from a jar file.
|
||||
Nevertheless, lombok can be hot-code-replaced in the debugger.
|
||||
This works via the loader: The lombok agent has its own classloading architecture, and this architecture is capable of loading lombok's class files from a location of your choosing. Choose the /bin dir from your eclipse project which will help with debugging; eclipse will then be able to apply HCR to the eclipse-running-in-eclipse. Unless there are issues with the loader architecture itself, of course.
|
||||
|
||||
The end goal is that you can make some changes to the lombok sources in your eclipse, then click the 'debug' button, and a new 'test eclipse' starts up using lombok as you wrote it just now. You can now make changes to lombok sources in the original eclipse, hit 'save', and these changes now get automatically applied to the 'test eclipse', as long as you aren't making any changes to signatures (add or remove methods/fields/types, or change return types, param types, etc).
|
||||
|
||||
If you have the sources to eclipse itself, you can open them, set breakpoints, and step through, though be aware that lombok's agent injection system does cause some issues here; we move methods into different classes and eclipse's debugger naturally doesn't understand this, so you can't breakpoint lombok's own patch methods, and stepping through them 'works' but looks bizarre in the debugger as the debugger now thinks your source file clearly cannot possibly match the class file currently running. Just keep going ('step out'), eclipse will figure it out again once you're back in un-instrumented eclipse code.
|
||||
|
||||
|
||||
TODO:
|
||||
|
||||
Describe in detail:
|
||||
|
||||
* Which ant tasks to run to create the targets
|
||||
* How to modify this target, if needed, to point at your bin dir
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
As per @Rawi01's experimenting:
|
||||
|
||||
* VSCode's lombok plugin simply adds the appropriate `-javaagent` options when it fires up the eclipse-based language server. You can also add debug flags here.
|
||||
* Add the flags `-agentlib:jdwp-transport=dt_socket,server=y,suspend=n,quiet=y,address=12345` to the `settings.json` of the VSCode lombok plugin, and then tell your debugger to attach to localhost:12345.
|
||||
* Set the property `java.server.launchMode` to `"Standard"`.
|
||||
* Consider activing the language server debug mode.
|
||||
|
||||
@@ -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
|
||||
@@ -24,6 +24,7 @@ package lombok;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.core.configuration.CallSuperType;
|
||||
import lombok.core.configuration.CapitalizationStrategy;
|
||||
import lombok.core.configuration.CheckerFrameworkVersion;
|
||||
import lombok.core.configuration.ConfigurationKey;
|
||||
import lombok.core.configuration.FlagUsageType;
|
||||
@@ -558,6 +559,15 @@ public class ConfigurationKeys {
|
||||
*/
|
||||
public static final ConfigurationKey<Boolean> ACCESSORS_FLUENT = new ConfigurationKey<Boolean>("lombok.accessors.fluent", "Generate getters and setters using only the field name (no get/set prefix) (default: false).") {};
|
||||
|
||||
/**
|
||||
* lombok configuration: {@code lombok.accessors.capitalization} = {@code basic} | {@code beanspec}.
|
||||
*
|
||||
* Which capitalization rule is used to turn field names into getter/setter/with names and vice versa for field names that start with 1 lowercase letter, then 1 uppercase letter.
|
||||
* basic = {@code uShape} becomes {@code getUShape}, beanspec = {@code uShape} becomes {@code getuShape} (default = basic).
|
||||
*/
|
||||
public static final ConfigurationKey<CapitalizationStrategy> ACCESSORS_JAVA_BEANS_SPEC_CAPITALIZATION = new ConfigurationKey<CapitalizationStrategy>("lombok.accessors.capitalization", "Which capitalization strategy to use when converting field names to accessor names and vice versa (default: basic).") {};
|
||||
|
||||
|
||||
// ----- ExtensionMethod -----
|
||||
|
||||
/**
|
||||
|
||||
@@ -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
|
||||
@@ -430,6 +430,9 @@ public abstract class AST<A extends AST<A, L, N>, L extends LombokNode<A, L, N>,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The {@code lombok.config} configuration value for the provided {@code key}, or {@code null} if that key is not in the config / there is no config.
|
||||
*/
|
||||
public final <T> T readConfiguration(ConfigurationKey<T> key) {
|
||||
long start = configTracker == null ? 0L : configTracker.start();
|
||||
try {
|
||||
@@ -438,4 +441,17 @@ public abstract class AST<A extends AST<A, L, N>, L extends LombokNode<A, L, N>,
|
||||
if (configTracker != null) configTracker.end(start);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The {@code lombok.config} configuration value for the provided {@code key}, or {@code defaultValue} if that key is not in the config / there is no config.
|
||||
*/
|
||||
public final <T> T readConfigurationOr(ConfigurationKey<T> key, T defaultValue) {
|
||||
long start = configTracker == null ? 0L : configTracker.start();
|
||||
try {
|
||||
T value = LombokConfiguration.read(key, this);
|
||||
return value != null ? value : defaultValue;
|
||||
} finally {
|
||||
if (configTracker != null) configTracker.end(start);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.21";
|
||||
private static final String VERSION = "1.18.23";
|
||||
private static final String RELEASE_NAME = "Edgy Guinea Pig";
|
||||
// private static final String RELEASE_NAME = "Envious Ferret";
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.core.configuration;
|
||||
|
||||
/** Used for lombok configuration to determine how to transform field names when turning them into accessor method names and vice versa. */
|
||||
public enum CapitalizationStrategy {
|
||||
BASIC {
|
||||
@Override public String capitalize(String in) {
|
||||
if (in.length() == 0) return in;
|
||||
char first = in.charAt(0);
|
||||
if (!Character.isLowerCase(first)) return in;
|
||||
boolean useUpperCase = in.length() > 2 &&
|
||||
(Character.isTitleCase(in.charAt(1)) || Character.isUpperCase(in.charAt(1)));
|
||||
return (useUpperCase ? Character.toUpperCase(first) : Character.toTitleCase(first)) + in.substring(1);
|
||||
}
|
||||
},
|
||||
BEANSPEC {
|
||||
@Override public String capitalize(String in) {
|
||||
if (in.length() == 0) return in;
|
||||
char first = in.charAt(0);
|
||||
if (!Character.isLowerCase(first) || (in.length() > 1 && Character.isUpperCase(in.charAt(1)))) return in;
|
||||
boolean useUpperCase = in.length() > 2 && Character.isTitleCase(in.charAt(1));
|
||||
return (useUpperCase ? Character.toUpperCase(first) : Character.toTitleCase(first)) + in.substring(1);
|
||||
}
|
||||
},
|
||||
;
|
||||
|
||||
public static CapitalizationStrategy defaultValue() {
|
||||
return BASIC;
|
||||
}
|
||||
|
||||
public abstract String capitalize(String in);
|
||||
}
|
||||
@@ -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
|
||||
@@ -21,7 +21,7 @@
|
||||
*/
|
||||
package lombok.core.configuration;
|
||||
|
||||
/** Used for lombok configuration to flag usages of certain lombok feature. */
|
||||
/** Used for lombok configuration to flag usages of certain lombok features. */
|
||||
public enum FlagUsageType {
|
||||
WARNING, ERROR, ALLOW;
|
||||
}
|
||||
@@ -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
|
||||
@@ -46,6 +46,7 @@ import lombok.core.AnnotationValues;
|
||||
import lombok.core.JavaIdentifiers;
|
||||
import lombok.core.LombokNode;
|
||||
import lombok.core.configuration.AllowHelper;
|
||||
import lombok.core.configuration.CapitalizationStrategy;
|
||||
import lombok.core.configuration.ConfigurationKey;
|
||||
import lombok.core.configuration.FlagUsageType;
|
||||
import lombok.experimental.Accessors;
|
||||
@@ -431,6 +432,7 @@ public class HandlerUtil {
|
||||
"com.fasterxml.jackson.annotation.JsonSetter",
|
||||
"com.fasterxml.jackson.annotation.JsonSubTypes",
|
||||
"com.fasterxml.jackson.annotation.JsonTypeInfo",
|
||||
"com.fasterxml.jackson.annotation.JsonUnwrapped",
|
||||
"com.fasterxml.jackson.annotation.JsonView",
|
||||
"com.fasterxml.jackson.databind.annotation.JsonDeserialize",
|
||||
"com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper",
|
||||
@@ -692,11 +694,13 @@ public class HandlerUtil {
|
||||
if (Boolean.TRUE.equals(ast.readConfiguration(ConfigurationKeys.GETTER_CONSEQUENT_BOOLEAN))) isBoolean = false;
|
||||
boolean explicitPrefix = accessors != null && accessors.isExplicit("prefix");
|
||||
boolean explicitFluent = accessors != null && accessors.isExplicit("fluent");
|
||||
boolean explicitJavaBeansSpecCapitalization = accessors != null && accessors.isExplicit("javaBeansSpecCapitalization");
|
||||
|
||||
Accessors ac = (explicitPrefix || explicitFluent) ? accessors.getInstance() : null;
|
||||
Accessors ac = (explicitPrefix || explicitFluent || explicitJavaBeansSpecCapitalization) ? accessors.getInstance() : null;
|
||||
|
||||
List<String> prefix = explicitPrefix ? Arrays.asList(ac.prefix()) : ast.readConfiguration(ConfigurationKeys.ACCESSORS_PREFIX);
|
||||
boolean fluent = explicitFluent ? ac.fluent() : Boolean.TRUE.equals(ast.readConfiguration(ConfigurationKeys.ACCESSORS_FLUENT));
|
||||
CapitalizationStrategy capitalizationStrategy = ast.readConfigurationOr(ConfigurationKeys.ACCESSORS_JAVA_BEANS_SPEC_CAPITALIZATION, CapitalizationStrategy.defaultValue());
|
||||
|
||||
fieldName = removePrefix(fieldName, prefix);
|
||||
if (fieldName == null) return null;
|
||||
@@ -709,7 +713,7 @@ public class HandlerUtil {
|
||||
return booleanPrefix + fName.substring(2);
|
||||
}
|
||||
|
||||
return buildAccessorName(isBoolean ? booleanPrefix : normalPrefix, fName);
|
||||
return buildAccessorName(isBoolean ? booleanPrefix : normalPrefix, fName, capitalizationStrategy);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -787,6 +791,7 @@ public class HandlerUtil {
|
||||
|
||||
List<String> prefix = explicitPrefix ? Arrays.asList(ac.prefix()) : ast.readConfiguration(ConfigurationKeys.ACCESSORS_PREFIX);
|
||||
boolean fluent = explicitFluent ? ac.fluent() : Boolean.TRUE.equals(ast.readConfiguration(ConfigurationKeys.ACCESSORS_FLUENT));
|
||||
CapitalizationStrategy capitalizationStrategy = ast.readConfigurationOr(ConfigurationKeys.ACCESSORS_JAVA_BEANS_SPEC_CAPITALIZATION, CapitalizationStrategy.defaultValue());
|
||||
|
||||
fieldName = removePrefix(fieldName, prefix);
|
||||
if (fieldName == null) return Collections.emptyList();
|
||||
@@ -798,8 +803,8 @@ public class HandlerUtil {
|
||||
if (adhereToFluent && fluent) {
|
||||
names.add(baseName);
|
||||
} else {
|
||||
names.add(buildAccessorName(normalPrefix, baseName));
|
||||
if (!normalPrefix.equals(booleanPrefix)) names.add(buildAccessorName(booleanPrefix, baseName));
|
||||
names.add(buildAccessorName(normalPrefix, baseName, capitalizationStrategy));
|
||||
if (!normalPrefix.equals(booleanPrefix)) names.add(buildAccessorName(booleanPrefix, baseName, capitalizationStrategy));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -825,23 +830,36 @@ public class HandlerUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param node Any node (used to fetch config of capitalization strategy).
|
||||
* @param prefix Something like {@code get} or {@code set} or {@code is}.
|
||||
* @param suffix Something like {@code running}.
|
||||
* @return prefix + smartly title-cased suffix. For example, {@code setRunning}.
|
||||
*/
|
||||
public static String buildAccessorName(String prefix, String suffix) {
|
||||
public static String buildAccessorName(AST<?, ?, ?> ast, String prefix, String suffix) {
|
||||
CapitalizationStrategy capitalizationStrategy = ast.readConfigurationOr(ConfigurationKeys.ACCESSORS_JAVA_BEANS_SPEC_CAPITALIZATION, CapitalizationStrategy.defaultValue());
|
||||
return buildAccessorName(prefix, suffix, capitalizationStrategy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param node Any node (used to fetch config of capitalization strategy).
|
||||
* @param prefix Something like {@code get} or {@code set} or {@code is}.
|
||||
* @param suffix Something like {@code running}.
|
||||
* @return prefix + smartly title-cased suffix. For example, {@code setRunning}.
|
||||
*/
|
||||
public static String buildAccessorName(LombokNode<?, ?, ?> node, String prefix, String suffix) {
|
||||
CapitalizationStrategy capitalizationStrategy = node.getAst().readConfigurationOr(ConfigurationKeys.ACCESSORS_JAVA_BEANS_SPEC_CAPITALIZATION, CapitalizationStrategy.defaultValue());
|
||||
return buildAccessorName(prefix, suffix, capitalizationStrategy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param prefix Something like {@code get} or {@code set} or {@code is}.
|
||||
* @param suffix Something like {@code running}.
|
||||
* @param capitalizationStrategy Which strategy to use to capitalize the name part.
|
||||
*/
|
||||
private static String buildAccessorName(String prefix, String suffix, CapitalizationStrategy capitalizationStrategy) {
|
||||
if (suffix.length() == 0) return prefix;
|
||||
if (prefix.length() == 0) return suffix;
|
||||
|
||||
char first = suffix.charAt(0);
|
||||
if (Character.isLowerCase(first)) {
|
||||
boolean useUpperCase = suffix.length() > 2 &&
|
||||
(Character.isTitleCase(suffix.charAt(1)) || Character.isUpperCase(suffix.charAt(1)));
|
||||
suffix = String.format("%s%s",
|
||||
useUpperCase ? Character.toUpperCase(first) : Character.toTitleCase(first),
|
||||
suffix.subSequence(1, suffix.length()));
|
||||
}
|
||||
return String.format("%s%s", prefix, suffix);
|
||||
return prefix + capitalizationStrategy.capitalize(suffix);
|
||||
}
|
||||
|
||||
public static String camelCaseToConstant(String fieldName) {
|
||||
|
||||
@@ -215,13 +215,16 @@ public class EclipseNode extends lombok.core.LombokNode<EclipseAST, EclipseNode,
|
||||
|
||||
@Override public boolean isStatic() {
|
||||
if (node instanceof TypeDeclaration) {
|
||||
TypeDeclaration t = (TypeDeclaration) node;
|
||||
int f = t.modifiers;
|
||||
if (((ClassFileConstants.AccInterface | ClassFileConstants.AccEnum) & f) != 0) return true;
|
||||
|
||||
EclipseNode directUp = directUp();
|
||||
if (directUp == null || directUp.getKind() == Kind.COMPILATION_UNIT) return true;
|
||||
if (!(directUp.get() instanceof TypeDeclaration)) return false;
|
||||
TypeDeclaration p = (TypeDeclaration) directUp.get();
|
||||
int f = p.modifiers;
|
||||
if ((ClassFileConstants.AccInterface & f) != 0) return true;
|
||||
if ((ClassFileConstants.AccEnum & f) != 0) return true;
|
||||
f = p.modifiers;
|
||||
if (((ClassFileConstants.AccInterface | ClassFileConstants.AccEnum) & f) != 0) return true;
|
||||
}
|
||||
|
||||
if (node instanceof FieldDeclaration) {
|
||||
|
||||
@@ -95,6 +95,7 @@ import org.eclipse.jdt.internal.compiler.ast.TypeParameter;
|
||||
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
|
||||
import org.eclipse.jdt.internal.compiler.ast.Wildcard;
|
||||
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
|
||||
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
|
||||
import org.eclipse.jdt.internal.compiler.lookup.Binding;
|
||||
import org.eclipse.jdt.internal.compiler.lookup.CaptureBinding;
|
||||
import org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding;
|
||||
@@ -337,6 +338,8 @@ public class EclipseHandlerUtil {
|
||||
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;
|
||||
public static final Class<?> COMPILATION_UNIT;
|
||||
public static final Method COMPILATION_UNIT_ORIGINAL_FROM_CLONE;
|
||||
static {
|
||||
STRING_LITERAL__LINE_NUMBER = getField(StringLiteral.class, "lineNumber");
|
||||
ANNOTATION__MEMBER_VALUE_PAIR_NAME = getField(Annotation.class, "memberValuePairName");
|
||||
@@ -346,6 +349,8 @@ public class EclipseHandlerUtil {
|
||||
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");
|
||||
COMPILATION_UNIT = getClass("org.eclipse.jdt.internal.core.CompilationUnit");
|
||||
COMPILATION_UNIT_ORIGINAL_FROM_CLONE = COMPILATION_UNIT == null ? null : Permit.permissiveGetMethod(COMPILATION_UNIT, "originalFromClone");
|
||||
}
|
||||
|
||||
public static int reflectInt(Field f, Object o) {
|
||||
@@ -1042,7 +1047,7 @@ public class EclipseHandlerUtil {
|
||||
res[count] = name;
|
||||
|
||||
n = parent;
|
||||
while (n != null && n.getKind() == Kind.TYPE && n.get() instanceof TypeDeclaration) {
|
||||
while (count > 0) {
|
||||
TypeDeclaration td = (TypeDeclaration) n.get();
|
||||
res[--count] = td.name;
|
||||
n = n.up();
|
||||
@@ -2052,11 +2057,7 @@ public class EclipseHandlerUtil {
|
||||
}
|
||||
|
||||
int pS = source.sourceStart, pE = source.sourceEnd;
|
||||
long p = (long)pS << 32 | pE;
|
||||
long[] poss = new long[annotationTypeFqn.length];
|
||||
Arrays.fill(poss, p);
|
||||
QualifiedTypeReference qualifiedType = new QualifiedTypeReference(annotationTypeFqn, poss);
|
||||
setGeneratedBy(qualifiedType, source);
|
||||
TypeReference qualifiedType = generateQualifiedTypeRef(source, annotationTypeFqn);
|
||||
Annotation ann;
|
||||
if (args != null && args.length == 1 && args[0] instanceof Expression) {
|
||||
SingleMemberAnnotation sma = new SingleMemberAnnotation(qualifiedType, pS);
|
||||
@@ -2635,6 +2636,13 @@ public class EclipseHandlerUtil {
|
||||
return isTypeAndDoesNotHaveFlags(typeNode, ClassFileConstants.AccInterface | ClassFileConstants.AccAnnotation | AccRecord);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if the provided node is an actual class, an enum or a record and not some other type declaration (so, not an annotation definition or interface).
|
||||
*/
|
||||
public static boolean isClassEnumOrRecord(EclipseNode typeNode) {
|
||||
return isTypeAndDoesNotHaveFlags(typeNode, ClassFileConstants.AccInterface | ClassFileConstants.AccAnnotation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if the provided node is a record declaration (so, not an annotation definition, interface, enum, or plain class).
|
||||
*/
|
||||
@@ -2662,6 +2670,21 @@ public class EclipseHandlerUtil {
|
||||
return (modifiers & flags) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if the provided node supports static methods and types (top level or static class)
|
||||
*/
|
||||
public static boolean isStaticAllowed(EclipseNode typeNode) {
|
||||
boolean staticAllowed = true;
|
||||
|
||||
while (typeNode.getKind() != Kind.COMPILATION_UNIT) {
|
||||
if (!staticAllowed) return false;
|
||||
|
||||
staticAllowed = typeNode.isStatic();
|
||||
typeNode = typeNode.up();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static AbstractVariableDeclaration[] getRecordComponents(TypeDeclaration typeDeclaration) {
|
||||
if (typeDeclaration == null || (typeDeclaration.modifiers & AccRecord) == 0) return null;
|
||||
try {
|
||||
@@ -2713,7 +2736,14 @@ public class EclipseHandlerUtil {
|
||||
public static void setDocComment(CompilationUnitDeclaration cud, TypeDeclaration type, ASTNode node, String doc) {
|
||||
if (doc == null) return;
|
||||
|
||||
Map<String, String> docs = EcjAugments.CompilationUnit_javadoc.setIfAbsent(cud.compilationResult.compilationUnit, new HashMap<String, String>());
|
||||
ICompilationUnit compilationUnit = cud.compilationResult.compilationUnit;
|
||||
if (compilationUnit.getClass().equals(COMPILATION_UNIT)) {
|
||||
try {
|
||||
compilationUnit = (ICompilationUnit) Permit.invoke(COMPILATION_UNIT_ORIGINAL_FROM_CLONE, compilationUnit);
|
||||
} catch (Throwable t) { }
|
||||
}
|
||||
|
||||
Map<String, String> docs = EcjAugments.CompilationUnit_javadoc.setIfAbsent(compilationUnit, new HashMap<String, String>());
|
||||
if (node instanceof AbstractMethodDeclaration) {
|
||||
AbstractMethodDeclaration methodDeclaration = (AbstractMethodDeclaration) node;
|
||||
String signature = getSignature(type, methodDeclaration);
|
||||
|
||||
@@ -293,6 +293,11 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> {
|
||||
|
||||
List<EclipseNode> nonFinalNonDefaultedFields = null;
|
||||
|
||||
if (!isStaticAllowed(upToTypeNode(parent))) {
|
||||
annotationNode.addError("@Builder is not supported on non-static nested classes.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (parent.get() instanceof TypeDeclaration) {
|
||||
if (!isClass(parent) && !isRecord(parent)) {
|
||||
annotationNode.addError(BUILDER_NODE_NOT_SUPPORTED_ERR);
|
||||
@@ -660,7 +665,7 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> {
|
||||
for (BuilderFieldData bfd : job.builderFields) {
|
||||
String setterName = new String(bfd.name);
|
||||
String setterPrefix = !prefix.isEmpty() ? prefix : job.oldFluent ? "" : "set";
|
||||
if (!setterPrefix.isEmpty()) setterName = HandlerUtil.buildAccessorName(setterPrefix, setterName);
|
||||
if (!setterPrefix.isEmpty()) setterName = HandlerUtil.buildAccessorName(job.sourceNode, setterPrefix, setterName);
|
||||
|
||||
MessageSend ms = new MessageSend();
|
||||
Expression[] tgt = new Expression[bfd.singularData == null ? 1 : 2];
|
||||
@@ -1028,9 +1033,9 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> {
|
||||
String setterPrefix = prefix.isEmpty() ? "set" : prefix;
|
||||
String setterName;
|
||||
if (job.oldFluent) {
|
||||
setterName = prefix.isEmpty() ? new String(bfd.name) : HandlerUtil.buildAccessorName(setterPrefix, new String(bfd.name));
|
||||
setterName = prefix.isEmpty() ? new String(bfd.name) : HandlerUtil.buildAccessorName(job.sourceNode, setterPrefix, new String(bfd.name));
|
||||
} else {
|
||||
setterName = HandlerUtil.buildAccessorName(setterPrefix, new String(bfd.name));
|
||||
setterName = HandlerUtil.buildAccessorName(job.sourceNode, setterPrefix, new String(bfd.name));
|
||||
}
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
|
||||
@@ -538,14 +538,15 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH
|
||||
if (addWildcards) genericsCount.add(arraySizeOf(((TypeDeclaration) type.get()).typeParameters));
|
||||
boolean staticContext = (((TypeDeclaration) type.get()).modifiers & ClassFileConstants.AccStatic) != 0;
|
||||
EclipseNode tNode = type.up();
|
||||
if (!staticContext && tNode.getKind() == Kind.TYPE && (((TypeDeclaration) tNode.get()).modifiers & ClassFileConstants.AccInterface) != 0) staticContext = true;
|
||||
|
||||
while (tNode != null && tNode.getKind() == Kind.TYPE) {
|
||||
TypeDeclaration td = (TypeDeclaration) tNode.get();
|
||||
if (td.name == null || td.name.length == 0) break;
|
||||
list.add(tNode.getName());
|
||||
if (addWildcards) genericsCount.add(staticContext ? 0 : arraySizeOf(((TypeDeclaration) tNode.get()).typeParameters));
|
||||
if (!staticContext) staticContext = (((TypeDeclaration) tNode.get()).modifiers & Modifier.STATIC) != 0;
|
||||
if (!staticContext && tNode.getKind() == Kind.TYPE && (td.modifiers & ClassFileConstants.AccInterface) != 0) staticContext = true;
|
||||
if (addWildcards) genericsCount.add(staticContext ? 0 : arraySizeOf(td.typeParameters));
|
||||
if (!staticContext) staticContext = (td.modifiers & Modifier.STATIC) != 0;
|
||||
tNode = tNode.up();
|
||||
if (!staticContext && tNode.getKind() == Kind.TYPE && (((TypeDeclaration) tNode.get()).modifiers & ClassFileConstants.AccInterface) != 0) staticContext = true;
|
||||
}
|
||||
Collections.reverse(list);
|
||||
if (addWildcards) Collections.reverse(genericsCount);
|
||||
|
||||
@@ -160,6 +160,8 @@ public class HandleFieldDefaults extends EclipseASTAdapter {
|
||||
boolean defaultToFinal = makeFinalIsExplicit ? false : Boolean.TRUE.equals(typeNode.getAst().readConfiguration(ConfigurationKeys.FIELD_DEFAULTS_FINAL_EVERYWHERE));
|
||||
|
||||
if (!defaultToPrivate && !defaultToFinal && fieldDefaults == null) return;
|
||||
// Do not apply field defaults to records if set using the the config system
|
||||
if (fieldDefaults == null && !isClassOrEnum(typeNode)) return;
|
||||
AccessLevel fdAccessLevel = (fieldDefaults != null && levelIsExplicit) ? fd.level() : defaultToPrivate ? AccessLevel.PRIVATE : null;
|
||||
boolean fdToFinal = (fieldDefaults != null && makeFinalIsExplicit) ? fd.makeFinal() : defaultToFinal;
|
||||
|
||||
|
||||
@@ -60,14 +60,12 @@ public class HandleFieldNameConstants extends EclipseAnnotationHandler<FieldName
|
||||
private static final IdentifierName FIELDS = IdentifierName.valueOf("Fields");
|
||||
|
||||
public void generateFieldNameConstantsForType(EclipseNode typeNode, EclipseNode errorNode, AccessLevel level, boolean asEnum, IdentifierName innerTypeName, boolean onlyExplicit, boolean uppercase) {
|
||||
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) {
|
||||
errorNode.addError("@FieldNameConstants is only supported on a class or an enum.");
|
||||
if (!isClassEnumOrRecord(typeNode)) {
|
||||
errorNode.addError("@FieldNameConstants is only supported on a class, an enum or a record.");
|
||||
return;
|
||||
}
|
||||
if (!isStaticAllowed(typeNode)) {
|
||||
errorNode.addError("@FieldNameConstants is not supported on non-static nested classes.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -88,6 +88,11 @@ public class HandleLog {
|
||||
return;
|
||||
}
|
||||
|
||||
if (useStatic && !isStaticAllowed(owner)) {
|
||||
annotationNode.addError(framework.getAnnotationAsString() + " is not supported on non-static nested classes.");
|
||||
return;
|
||||
}
|
||||
|
||||
Object valueGuess = annotation.getValueGuess("topic");
|
||||
Expression loggerTopic = (Expression) annotation.getActualExpression("topic");
|
||||
|
||||
|
||||
@@ -184,6 +184,10 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> {
|
||||
annotationNode.addError("@SuperBuilder is only supported on classes.");
|
||||
return;
|
||||
}
|
||||
if (!isStaticAllowed(parent)) {
|
||||
annotationNode.addError("@SuperBuilder is not supported on non-static nested classes.");
|
||||
return;
|
||||
}
|
||||
|
||||
job.parentType = parent;
|
||||
TypeDeclaration td = (TypeDeclaration) parent.get();
|
||||
@@ -794,7 +798,7 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> {
|
||||
}
|
||||
|
||||
private MessageSend createSetterCallWithInstanceValue(BuilderFieldData bfd, EclipseNode type, ASTNode source, String setterPrefix) {
|
||||
char[] setterName = HandlerUtil.buildAccessorName(setterPrefix, String.valueOf(bfd.name)).toCharArray();
|
||||
char[] setterName = HandlerUtil.buildAccessorName(type, setterPrefix, String.valueOf(bfd.name)).toCharArray();
|
||||
MessageSend ms = new MessageSend();
|
||||
Expression[] tgt = new Expression[bfd.singularData == null ? 1 : 2];
|
||||
|
||||
@@ -1000,7 +1004,7 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> {
|
||||
if (existing == null) existing = EMPTY_METHODS;
|
||||
int len = existing.length;
|
||||
|
||||
String setterName = HandlerUtil.buildAccessorName(setterPrefix, new String(paramName));
|
||||
String setterName = HandlerUtil.buildAccessorName(job.sourceNode, setterPrefix, new String(paramName));
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (!(existing[i] instanceof MethodDeclaration)) continue;
|
||||
|
||||
@@ -315,7 +315,9 @@ public class HandleToString extends EclipseAnnotationHandler<ToString> {
|
||||
String typeName = getSingleTypeName(type);
|
||||
EclipseNode upType = type.up();
|
||||
while (upType.getKind() == Kind.TYPE) {
|
||||
typeName = getSingleTypeName(upType) + "." + typeName;
|
||||
String upTypeName = getSingleTypeName(upType);
|
||||
if (upTypeName.isEmpty()) break;
|
||||
typeName = upTypeName + "." + typeName;
|
||||
upType = upType.up();
|
||||
}
|
||||
return typeName;
|
||||
|
||||
@@ -23,6 +23,7 @@ package lombok.eclipse.handlers;
|
||||
|
||||
import static lombok.core.handlers.HandlerUtil.handleFlagUsage;
|
||||
import static lombok.eclipse.handlers.EclipseHandlerUtil.typeMatches;
|
||||
|
||||
import lombok.ConfigurationKeys;
|
||||
import lombok.val;
|
||||
import lombok.var;
|
||||
@@ -42,7 +43,7 @@ import org.eclipse.jdt.internal.compiler.ast.NullLiteral;
|
||||
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
|
||||
|
||||
/*
|
||||
* This class just handles 3 basic error cases. The real meat of eclipse 'val' support is in {@code PatchVal} and {@code PatchValEclipse}.
|
||||
* This class just handles 3 basic error cases. The real meat of eclipse 'val' support is in {@code PatchVal} and {@code PatchValEclipse}
|
||||
*/
|
||||
@Provides(EclipseASTVisitor.class)
|
||||
@DeferUntilPostDiet
|
||||
|
||||
@@ -126,7 +126,7 @@ abstract class EclipseGuavaSingularizer extends EclipseSingularizer {
|
||||
FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L);
|
||||
thisDotField.receiver = new ThisReference(0, 0);
|
||||
Assignment a = new Assignment(thisDotField, new NullLiteral(0, 0), 0);
|
||||
md.selector = HandlerUtil.buildAccessorName("clear", new String(data.getPluralName())).toCharArray();
|
||||
md.selector = HandlerUtil.buildAccessorName(builderType, "clear", new String(data.getPluralName())).toCharArray();
|
||||
md.statements = returnStatement != null ? new Statement[] {a, returnStatement} : new Statement[] {a};
|
||||
md.returnType = returnType;
|
||||
md.annotations = generateSelfReturnAnnotations(deprecate, cfv, data.getSource());
|
||||
@@ -173,8 +173,8 @@ abstract class EclipseGuavaSingularizer extends EclipseSingularizer {
|
||||
md.arguments[i].annotations = typeUseAnns;
|
||||
}
|
||||
md.returnType = returnType;
|
||||
char[] prefixedSingularName = data.getSetterPrefix().length == 0 ? data.getSingularName() : HandlerUtil.buildAccessorName(new String(data.getSetterPrefix()), new String(data.getSingularName())).toCharArray();
|
||||
md.selector = fluent ? prefixedSingularName : HandlerUtil.buildAccessorName("add", new String(data.getSingularName())).toCharArray();
|
||||
char[] prefixedSingularName = data.getSetterPrefix().length == 0 ? data.getSingularName() : HandlerUtil.buildAccessorName(builderType, new String(data.getSetterPrefix()), new String(data.getSingularName())).toCharArray();
|
||||
md.selector = fluent ? prefixedSingularName : HandlerUtil.buildAccessorName(builderType, "add", new String(data.getSingularName())).toCharArray();
|
||||
Annotation[] selfReturnAnnotations = generateSelfReturnAnnotations(deprecate, cfv, data.getSource());
|
||||
Annotation[] copyToSetterAnnotations = copyAnnotations(md, findCopyableToBuilderSingularSetterAnnotations(data.getAnnotation().up()));
|
||||
md.annotations = concat(selfReturnAnnotations, copyToSetterAnnotations, Annotation.class);
|
||||
@@ -213,8 +213,8 @@ abstract class EclipseGuavaSingularizer extends EclipseSingularizer {
|
||||
|
||||
md.arguments = new Argument[] {param};
|
||||
md.returnType = returnType;
|
||||
char[] prefixedSelector = data.getSetterPrefix().length == 0 ? data.getPluralName() : HandlerUtil.buildAccessorName(new String(data.getSetterPrefix()), new String(data.getPluralName())).toCharArray();
|
||||
md.selector = fluent ? prefixedSelector : HandlerUtil.buildAccessorName("addAll", new String(data.getPluralName())).toCharArray();
|
||||
char[] prefixedSelector = data.getSetterPrefix().length == 0 ? data.getPluralName() : HandlerUtil.buildAccessorName(builderType, new String(data.getSetterPrefix()), new String(data.getPluralName())).toCharArray();
|
||||
md.selector = fluent ? prefixedSelector : HandlerUtil.buildAccessorName(builderType, "addAll", new String(data.getPluralName())).toCharArray();
|
||||
Annotation[] selfReturnAnnotations = generateSelfReturnAnnotations(deprecate, cfv, data.getSource());
|
||||
Annotation[] copyToSetterAnnotations = copyAnnotations(md, findCopyableToSetterAnnotations(data.getAnnotation().up()));
|
||||
md.annotations = concat(selfReturnAnnotations, copyToSetterAnnotations, Annotation.class);
|
||||
|
||||
@@ -112,7 +112,7 @@ abstract class EclipseJavaUtilListSetSingularizer extends EclipseJavaUtilSingula
|
||||
thisDotField.receiver = new ThisReference(0, 0);
|
||||
FieldReference thisDotField2 = new FieldReference(data.getPluralName(), 0L);
|
||||
thisDotField2.receiver = new ThisReference(0, 0);
|
||||
md.selector = HandlerUtil.buildAccessorName("clear", new String(data.getPluralName())).toCharArray();
|
||||
md.selector = HandlerUtil.buildAccessorName(builderType, "clear", new String(data.getPluralName())).toCharArray();
|
||||
MessageSend clearMsg = new MessageSend();
|
||||
clearMsg.receiver = thisDotField2;
|
||||
clearMsg.selector = "clear".toCharArray();
|
||||
@@ -151,8 +151,8 @@ abstract class EclipseJavaUtilListSetSingularizer extends EclipseJavaUtilSingula
|
||||
param.annotations = typeUseAnns;
|
||||
md.arguments = new Argument[] {param};
|
||||
md.returnType = returnType;
|
||||
char[] prefixedSingularName = data.getSetterPrefix().length == 0 ? data.getSingularName() : HandlerUtil.buildAccessorName(new String(data.getSetterPrefix()), new String(data.getSingularName())).toCharArray();
|
||||
md.selector = fluent ? prefixedSingularName : HandlerUtil.buildAccessorName("add", new String(data.getSingularName())).toCharArray();
|
||||
char[] prefixedSingularName = data.getSetterPrefix().length == 0 ? data.getSingularName() : HandlerUtil.buildAccessorName(builderType, new String(data.getSetterPrefix()), new String(data.getSingularName())).toCharArray();
|
||||
md.selector = fluent ? prefixedSingularName : HandlerUtil.buildAccessorName(builderType, "add", new String(data.getSingularName())).toCharArray();
|
||||
Annotation[] selfReturnAnnotations = generateSelfReturnAnnotations(deprecate, cfv, data.getSource());
|
||||
Annotation[] copyToSetterAnnotations = copyAnnotations(md, findCopyableToBuilderSingularSetterAnnotations(data.getAnnotation().up()));
|
||||
md.annotations = concat(selfReturnAnnotations, copyToSetterAnnotations, Annotation.class);
|
||||
@@ -189,8 +189,8 @@ abstract class EclipseJavaUtilListSetSingularizer extends EclipseJavaUtilSingula
|
||||
|
||||
md.arguments = new Argument[] {param};
|
||||
md.returnType = returnType;
|
||||
char[] prefixedSelector = data.getSetterPrefix().length == 0 ? data.getPluralName() : HandlerUtil.buildAccessorName(new String(data.getSetterPrefix()), new String(data.getPluralName())).toCharArray();
|
||||
md.selector = fluent ? prefixedSelector : HandlerUtil.buildAccessorName("addAll", new String(data.getPluralName())).toCharArray();
|
||||
char[] prefixedSelector = data.getSetterPrefix().length == 0 ? data.getPluralName() : HandlerUtil.buildAccessorName(builderType, new String(data.getSetterPrefix()), new String(data.getPluralName())).toCharArray();
|
||||
md.selector = fluent ? prefixedSelector : HandlerUtil.buildAccessorName(builderType, "addAll", new String(data.getPluralName())).toCharArray();
|
||||
Annotation[] selfReturnAnnotations = generateSelfReturnAnnotations(deprecate, cfv, data.getSource());
|
||||
Annotation[] copyToSetterAnnotations = copyAnnotations(md, findCopyableToSetterAnnotations(data.getAnnotation().up()));
|
||||
md.annotations = concat(selfReturnAnnotations, copyToSetterAnnotations, Annotation.class);
|
||||
|
||||
@@ -177,7 +177,7 @@ public class EclipseJavaUtilMapSingularizer extends EclipseJavaUtilSingularizer
|
||||
thisDotField2.receiver = new ThisReference(0, 0);
|
||||
FieldReference thisDotField3 = new FieldReference(valueFieldName, 0L);
|
||||
thisDotField3.receiver = new ThisReference(0, 0);
|
||||
md.selector = HandlerUtil.buildAccessorName("clear", new String(data.getPluralName())).toCharArray();
|
||||
md.selector = HandlerUtil.buildAccessorName(builderType, "clear", new String(data.getPluralName())).toCharArray();
|
||||
MessageSend clearMsg1 = new MessageSend();
|
||||
clearMsg1.receiver = thisDotField2;
|
||||
clearMsg1.selector = "clear".toCharArray();
|
||||
@@ -249,7 +249,7 @@ public class EclipseJavaUtilMapSingularizer extends EclipseJavaUtilSingularizer
|
||||
|
||||
String name = new String(data.getSingularName());
|
||||
String setterPrefix = data.getSetterPrefix().length > 0 ? new String(data.getSetterPrefix()) : fluent ? "" : "put";
|
||||
String setterName = HandlerUtil.buildAccessorName(setterPrefix, name);
|
||||
String setterName = HandlerUtil.buildAccessorName(builderType, setterPrefix, name);
|
||||
|
||||
md.selector = setterName.toCharArray();
|
||||
Annotation[] selfReturnAnnotations = generateSelfReturnAnnotations(deprecate, cfv, data.getSource());
|
||||
@@ -325,7 +325,7 @@ public class EclipseJavaUtilMapSingularizer extends EclipseJavaUtilSingularizer
|
||||
|
||||
String name = new String(data.getPluralName());
|
||||
String setterPrefix = data.getSetterPrefix().length > 0 ? new String(data.getSetterPrefix()) : fluent ? "" : "put";
|
||||
String setterName = HandlerUtil.buildAccessorName(setterPrefix, name);
|
||||
String setterName = HandlerUtil.buildAccessorName(builderType, setterPrefix, name);
|
||||
|
||||
md.selector = setterName.toCharArray();
|
||||
Annotation[] selfReturnAnnotations = generateSelfReturnAnnotations(deprecate, cfv, data.getSource());
|
||||
|
||||
@@ -228,7 +228,7 @@ public class JavacAST extends AST<JavacAST, JavacNode, JCTree> {
|
||||
int underscoreIdx = nm.indexOf('_');
|
||||
if (underscoreIdx > -1) return Integer.parseInt(nm.substring(underscoreIdx + 1));
|
||||
// assume java9+
|
||||
return Integer.parseInt(nm);
|
||||
return Integer.parseInt(nm.substring(3));
|
||||
} catch (Exception ignore) {}
|
||||
return 6;
|
||||
}
|
||||
|
||||
@@ -286,13 +286,15 @@ public class JavacNode extends lombok.core.LombokNode<JavacAST, JavacNode, JCTre
|
||||
|
||||
@Override public boolean isStatic() {
|
||||
if (node instanceof JCClassDecl) {
|
||||
JCClassDecl t = (JCClassDecl) node;
|
||||
long f = t.mods.flags;
|
||||
if (((Flags.INTERFACE | Flags.ENUM) & f) != 0) return true;
|
||||
JavacNode directUp = directUp();
|
||||
if (directUp == null || directUp.getKind() == Kind.COMPILATION_UNIT) return true;
|
||||
if (!(directUp.get() instanceof JCClassDecl)) return false;
|
||||
JCClassDecl p = (JCClassDecl) directUp.get();
|
||||
long f = p.mods.flags;
|
||||
if ((Flags.INTERFACE & f) != 0) return true;
|
||||
if ((Flags.ENUM & f) != 0) return true;
|
||||
f = p.mods.flags;
|
||||
if (((Flags.INTERFACE | Flags.ENUM) & f) != 0) return true;
|
||||
}
|
||||
|
||||
if (node instanceof JCVariableDecl) {
|
||||
|
||||
@@ -234,6 +234,11 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
|
||||
|
||||
ArrayList<JavacNode> nonFinalNonDefaultedFields = null;
|
||||
|
||||
if (!isStaticAllowed(upToTypeNode(parent))) {
|
||||
annotationNode.addError("@Builder is not supported on non-static nested classes.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (parent.get() instanceof JCClassDecl) {
|
||||
if (!isClass(parent) && !isRecord(parent)) {
|
||||
annotationNode.addError(BUILDER_NODE_NOT_SUPPORTED_ERR);
|
||||
@@ -631,7 +636,7 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
|
||||
for (BuilderFieldData bfd : job.builderFields) {
|
||||
String setterPrefix = !prefix.isEmpty() ? prefix : job.oldFluent ? "" : "set";
|
||||
String prefixedSetterName = bfd.name.toString();
|
||||
if (!setterPrefix.isEmpty()) prefixedSetterName = HandlerUtil.buildAccessorName(setterPrefix, prefixedSetterName);
|
||||
if (!setterPrefix.isEmpty()) prefixedSetterName = HandlerUtil.buildAccessorName(job.sourceNode, setterPrefix, prefixedSetterName);
|
||||
|
||||
Name setterName = job.toName(prefixedSetterName);
|
||||
JCExpression[] tgt = new JCExpression[bfd.singularData == null ? 1 : 2];
|
||||
@@ -896,7 +901,7 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
|
||||
private void makePrefixedSetterMethodForBuilder(BuilderJob job, BuilderFieldData bfd, boolean deprecate, String prefix) {
|
||||
JavacNode fieldNode = bfd.createdFields.get(0);
|
||||
String setterPrefix = !prefix.isEmpty() ? prefix : job.oldFluent ? "" : "set";
|
||||
String setterName = HandlerUtil.buildAccessorName(setterPrefix, bfd.name.toString());
|
||||
String setterName = HandlerUtil.buildAccessorName(job.sourceNode, setterPrefix, bfd.name.toString());
|
||||
Name setterName_ = job.builderType.toName(setterName);
|
||||
|
||||
for (JavacNode child : job.builderType.down()) {
|
||||
|
||||
@@ -385,7 +385,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
|
||||
boolean staticContext = (((JCClassDecl) type.get()).getModifiers().flags & Flags.STATIC) != 0;
|
||||
JavacNode tNode = type.up();
|
||||
|
||||
while (tNode != null && tNode.getKind() == Kind.TYPE) {
|
||||
while (tNode != null && tNode.getKind() == Kind.TYPE && !tNode.getName().isEmpty()) {
|
||||
list.add(tNode.getName());
|
||||
if (addWildcards) genericsCount.add(staticContext ? 0 : ((JCClassDecl) tNode.get()).typarams.size());
|
||||
if (!staticContext) staticContext = (((JCClassDecl) tNode.get()).getModifiers().flags & Flags.STATIC) != 0;
|
||||
|
||||
@@ -140,6 +140,8 @@ public class HandleFieldDefaults extends JavacASTAdapter {
|
||||
boolean defaultToFinal = makeFinalIsExplicit ? false : Boolean.TRUE.equals(typeNode.getAst().readConfiguration(ConfigurationKeys.FIELD_DEFAULTS_FINAL_EVERYWHERE));
|
||||
|
||||
if (!defaultToPrivate && !defaultToFinal && fieldDefaults == null) return;
|
||||
// Do not apply field defaults to records if set using the the config system
|
||||
if (fieldDefaults == null && !isClassOrEnum(typeNode)) return;
|
||||
AccessLevel fdAccessLevel = (fieldDefaults != null && levelIsExplicit) ? fd.level() : defaultToPrivate ? AccessLevel.PRIVATE : null;
|
||||
boolean fdToFinal = (fieldDefaults != null && makeFinalIsExplicit) ? fd.makeFinal() : defaultToFinal;
|
||||
|
||||
|
||||
@@ -57,14 +57,12 @@ public class HandleFieldNameConstants extends JavacAnnotationHandler<FieldNameCo
|
||||
private static final IdentifierName FIELDS = IdentifierName.valueOf("Fields");
|
||||
|
||||
public void generateFieldNameConstantsForType(JavacNode typeNode, JavacNode errorNode, AccessLevel level, boolean asEnum, IdentifierName innerTypeName, boolean onlyExplicit, boolean uppercase) {
|
||||
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("@FieldNameConstants is only supported on a class or an enum.");
|
||||
if (!isClassEnumOrRecord(typeNode)) {
|
||||
errorNode.addError("@FieldNameConstants is only supported on a class, an enum or a record.");
|
||||
return;
|
||||
}
|
||||
if (!isStaticAllowed(typeNode)) {
|
||||
errorNode.addError("@FieldNameConstants is not supported on non-static nested classes.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -80,6 +80,11 @@ public class HandleLog {
|
||||
return;
|
||||
}
|
||||
|
||||
if (useStatic && !isStaticAllowed(typeNode)) {
|
||||
annotationNode.addError(framework.getAnnotationAsString() + " is not supported on non-static nested classes.");
|
||||
return;
|
||||
}
|
||||
|
||||
Object valueGuess = annotation.getValueGuess("topic");
|
||||
JCExpression loggerTopic = (JCExpression) annotation.getActualExpression("topic");
|
||||
|
||||
|
||||
@@ -99,7 +99,6 @@ public class HandleNonNull extends JavacAnnotationHandler<NonNull> {
|
||||
return recursiveSetGeneratedBy(constr, source);
|
||||
} else {
|
||||
existingCtr.mods = mods;
|
||||
existingCtr.params = params.toList();
|
||||
existingCtr.body = body;
|
||||
existingCtr = recursiveSetGeneratedBy(existingCtr, source);
|
||||
addSuppressWarningsAll(existingCtr.mods, typeNode, typeNode.getNodeFor(getGeneratedBy(existingCtr)), typeNode.getContext());
|
||||
|
||||
@@ -43,7 +43,6 @@ import com.sun.tools.javac.code.Flags;
|
||||
import com.sun.tools.javac.tree.JCTree.JCAnnotation;
|
||||
import com.sun.tools.javac.tree.JCTree.JCAssign;
|
||||
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.JCMethodDecl;
|
||||
import com.sun.tools.javac.tree.JCTree.JCReturn;
|
||||
|
||||
@@ -163,6 +163,10 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> {
|
||||
annotationNode.addError("@SuperBuilder is only supported on classes.");
|
||||
return;
|
||||
}
|
||||
if (!isStaticAllowed(parent)) {
|
||||
annotationNode.addError("@SuperBuilder is not supported on non-static nested classes.");
|
||||
return;
|
||||
}
|
||||
|
||||
job.parentType = parent;
|
||||
JCClassDecl td = (JCClassDecl) parent.get();
|
||||
@@ -773,7 +777,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> {
|
||||
arg = maker.Conditional(eqNull, emptyCollection, tgt[1]);
|
||||
}
|
||||
|
||||
String setterName = HandlerUtil.buildAccessorName(setterPrefix, bfd.name.toString());
|
||||
String setterName = HandlerUtil.buildAccessorName(job.sourceNode, setterPrefix, bfd.name.toString());
|
||||
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;
|
||||
@@ -945,7 +949,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> {
|
||||
}
|
||||
|
||||
private void generateSimpleSetterMethodForBuilder(SuperBuilderJob job, boolean deprecate, JavacNode fieldNode, Name paramName, Name nameOfSetFlag, JCExpression returnType, JCStatement returnStatement, List<JCAnnotation> annosOnParam, JavacNode originalFieldNode, String setterPrefix) {
|
||||
String setterName = HandlerUtil.buildAccessorName(setterPrefix, paramName.toString());
|
||||
String setterName = HandlerUtil.buildAccessorName(job.sourceNode, setterPrefix, paramName.toString());
|
||||
Name setterName_ = job.builderType.toName(setterName);
|
||||
|
||||
for (JavacNode child : job.builderType.down()) {
|
||||
|
||||
@@ -44,7 +44,6 @@ import com.sun.tools.javac.code.Flags;
|
||||
import com.sun.tools.javac.tree.JCTree.JCAnnotation;
|
||||
import com.sun.tools.javac.tree.JCTree.JCArrayTypeTree;
|
||||
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.JCMethodDecl;
|
||||
import com.sun.tools.javac.tree.JCTree.JCMethodInvocation;
|
||||
@@ -252,10 +251,10 @@ public class HandleToString extends JavacAnnotationHandler<ToString> {
|
||||
}
|
||||
|
||||
public static String getTypeName(JavacNode typeNode) {
|
||||
String typeName = ((JCClassDecl) typeNode.get()).name.toString();
|
||||
String typeName = typeNode.getName();
|
||||
JavacNode upType = typeNode.up();
|
||||
while (upType.getKind() == Kind.TYPE) {
|
||||
typeName = ((JCClassDecl) upType.get()).name.toString() + "." + typeName;
|
||||
while (upType.getKind() == Kind.TYPE && !upType.getName().isEmpty()) {
|
||||
typeName = upType.getName() + "." + typeName;
|
||||
upType = upType.up();
|
||||
}
|
||||
return typeName;
|
||||
|
||||
@@ -115,6 +115,12 @@ public class HandleVal extends JavacASTAdapter {
|
||||
local.mods.annotations = local.mods.annotations == null ? List.of(valAnnotation) : local.mods.annotations.append(valAnnotation);
|
||||
}
|
||||
|
||||
if (localNode.getSourceVersion() >= 10) {
|
||||
local.vartype = null;
|
||||
localNode.getAst().setChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
if (JavacResolution.platformHasTargetTyping()) {
|
||||
local.vartype = localNode.getAst().getTreeMaker().Ident(localNode.getAst().toName("___Lombok_VAL_Attrib__"));
|
||||
} else {
|
||||
|
||||
@@ -106,6 +106,7 @@ import lombok.javac.Javac;
|
||||
import lombok.javac.JavacAugments;
|
||||
import lombok.javac.JavacNode;
|
||||
import lombok.javac.JavacTreeMaker;
|
||||
import lombok.javac.JavacTreeMaker.TypeTag;
|
||||
import lombok.permit.Permit;
|
||||
|
||||
/**
|
||||
@@ -1286,6 +1287,7 @@ public class JavacHandlerUtil {
|
||||
static Type classEnter(JCTree tree, JavacNode parent) {
|
||||
Enter enter = Enter.instance(parent.getContext());
|
||||
Env<AttrContext> classEnv = enter.getEnv((TypeSymbol) parent.getElement());
|
||||
if (classEnv == null) return null;
|
||||
Type type = (Type) Permit.invokeSneaky(classEnter, enter, tree, classEnv);
|
||||
if (type == null) return null;
|
||||
type.complete();
|
||||
@@ -1902,7 +1904,7 @@ public class JavacHandlerUtil {
|
||||
|
||||
public static JCExpression namePlusTypeParamsToTypeReference(JavacTreeMaker maker, JavacNode parentType, Name typeName, boolean instance, List<JCTypeParameter> params, List<JCAnnotation> annotations) {
|
||||
JCExpression r = null;
|
||||
if (parentType != null && parentType.getKind() == Kind.TYPE) {
|
||||
if (parentType != null && parentType.getKind() == Kind.TYPE && !parentType.getName().isEmpty()) {
|
||||
JCClassDecl td = (JCClassDecl) parentType.get();
|
||||
boolean outerInstance = instance && ((td.mods.flags & Flags.STATIC) == 0);
|
||||
List<JCTypeParameter> outerParams = instance ? td.typarams : List.<JCTypeParameter>nil();
|
||||
@@ -1978,6 +1980,13 @@ public class JavacHandlerUtil {
|
||||
return isClassAndDoesNotHaveFlags(typeNode, Flags.INTERFACE | Flags.ANNOTATION | RECORD);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if the provided node is an actual class, an enum or a record and not some other type declaration (so, not an annotation definition or interface).
|
||||
*/
|
||||
public static boolean isClassEnumOrRecord(JavacNode typeNode) {
|
||||
return isClassAndDoesNotHaveFlags(typeNode, Flags.INTERFACE | Flags.ANNOTATION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if the provided node is a record declaration (so, not an annotation definition, interface, enum, or plain class).
|
||||
*/
|
||||
@@ -1994,6 +2003,21 @@ public class JavacHandlerUtil {
|
||||
return (typeDeclflags & flags) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if the provided node supports static methods and types (top level or static class)
|
||||
*/
|
||||
public static boolean isStaticAllowed(JavacNode typeNode) {
|
||||
boolean staticAllowed = true;
|
||||
|
||||
while (typeNode.getKind() != Kind.COMPILATION_UNIT) {
|
||||
if (!staticAllowed) return false;
|
||||
|
||||
staticAllowed = typeNode.isStatic();
|
||||
typeNode = typeNode.up();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static JavacNode upToTypeNode(JavacNode node) {
|
||||
if (node == null) throw new NullPointerException("node");
|
||||
while ((node != null) && !(node.get() instanceof JCClassDecl)) node = node.up();
|
||||
@@ -2028,7 +2052,9 @@ public class JavacHandlerUtil {
|
||||
private static JCExpression cloneType0(JavacTreeMaker maker, JCTree in) {
|
||||
if (in == null) return null;
|
||||
|
||||
if (in instanceof JCPrimitiveTypeTree) return (JCExpression) in;
|
||||
if (in instanceof JCPrimitiveTypeTree) {
|
||||
return maker.TypeIdent(TypeTag.typeTag(in));
|
||||
}
|
||||
|
||||
if (in instanceof JCIdent) {
|
||||
return maker.Ident(((JCIdent) in).name);
|
||||
|
||||
@@ -300,7 +300,7 @@ public class JavacSingularsRecipes {
|
||||
ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
|
||||
statements.append(clearStatement);
|
||||
|
||||
Name methodName = builderType.toName(HandlerUtil.buildAccessorName("clear", data.getPluralName().toString()));
|
||||
Name methodName = builderType.toName(HandlerUtil.buildAccessorName(source, "clear", data.getPluralName().toString()));
|
||||
finishAndInjectMethod(cfv, maker, returnType, returnStatement, data, builderType, source, deprecate, statements, methodName, List.<JCVariableDecl>nil(), List.<JCAnnotation>nil(), access, null);
|
||||
}
|
||||
|
||||
@@ -312,7 +312,7 @@ public class JavacSingularsRecipes {
|
||||
Name name = data.getSingularName();
|
||||
String setterPrefix = data.getSetterPrefix();
|
||||
if (setterPrefix.isEmpty() && !fluent) setterPrefix = getAddMethodName();
|
||||
if (!setterPrefix.isEmpty()) name = builderType.toName(HandlerUtil.buildAccessorName(setterPrefix, name.toString()));
|
||||
if (!setterPrefix.isEmpty()) name = builderType.toName(HandlerUtil.buildAccessorName(source, setterPrefix, name.toString()));
|
||||
|
||||
statements.prepend(createConstructBuilderVarIfNeeded(maker, data, builderType, source));
|
||||
List<JCAnnotation> methodAnnotations = copyAnnotations(findCopyableToBuilderSingularSetterAnnotations(data.annotation.up()));
|
||||
@@ -344,7 +344,7 @@ public class JavacSingularsRecipes {
|
||||
Name name = data.getPluralName();
|
||||
String setterPrefix = data.getSetterPrefix();
|
||||
if (setterPrefix.isEmpty() && !fluent) setterPrefix = getAddMethodName() + "All";
|
||||
if (!setterPrefix.isEmpty()) name = builderType.toName(HandlerUtil.buildAccessorName(setterPrefix, name.toString()));
|
||||
if (!setterPrefix.isEmpty()) name = builderType.toName(HandlerUtil.buildAccessorName(source, setterPrefix, name.toString()));
|
||||
JCExpression paramType = getPluralMethodParamType(builderType);
|
||||
paramType = addTypeArgs(getTypeArgumentsCount(), true, builderType, paramType, data.getTypeArgs(), source);
|
||||
long paramFlags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, builderType.getContext());
|
||||
|
||||
@@ -43,9 +43,9 @@ 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.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
@@ -733,7 +733,7 @@ public class Delombok {
|
||||
List<JCCompilationUnit> roots = new ArrayList<JCCompilationUnit>();
|
||||
Map<JCCompilationUnit, File> baseMap = new IdentityHashMap<JCCompilationUnit, File>();
|
||||
|
||||
Set<AbstractProcessor> processors = new HashSet<AbstractProcessor>();
|
||||
Set<AbstractProcessor> processors = new LinkedHashSet<AbstractProcessor>();
|
||||
processors.add(new lombok.javac.apt.LombokProcessor());
|
||||
processors.addAll(additionalAnnotationProcessors);
|
||||
|
||||
|
||||
@@ -545,6 +545,12 @@ public class PrettyPrinter extends JCTree.Visitor {
|
||||
print(tree.implementing, ", ");
|
||||
}
|
||||
|
||||
List<JCExpression> permitting = readObject(tree, "permitting", List.<JCExpression>nil());
|
||||
if (permitting.nonEmpty()) {
|
||||
print(" permits ");
|
||||
print(permitting, ", ");
|
||||
}
|
||||
|
||||
println(" {");
|
||||
indent++;
|
||||
printClassMembers(tree.defs, isEnum, isInterface);
|
||||
@@ -1016,6 +1022,8 @@ public class PrettyPrinter extends JCTree.Visitor {
|
||||
if ((v & TRANSIENT) != 0) print("transient ");
|
||||
if ((v & NATIVE) != 0) print("native ");
|
||||
if ((v & ABSTRACT) != 0) print("abstract ");
|
||||
if ((v & SEALED) != 0) print("sealed ");
|
||||
if ((v & NON_SEALED) != 0) print("non-sealed ");
|
||||
if ((v & STRICTFP) != 0) print("strictfp ");
|
||||
if ((v & DEFAULT) != 0 && (v & INTERFACE) == 0) print("default ");
|
||||
}
|
||||
@@ -1324,13 +1332,16 @@ public class PrettyPrinter extends JCTree.Visitor {
|
||||
@Override public void visitCase(JCCase tree) {
|
||||
// Starting with JDK12, switches allow multiple expressions per case, and can take the form of an expression (preview feature).
|
||||
|
||||
List<JCExpression> pats = readObject(tree, "pats", null); // JDK 12+
|
||||
List<JCTree> pats = readObject(tree, "labels", null); // JDK 17+
|
||||
if (pats == null) {
|
||||
JCExpression pat = readObject(tree, "pat", null); // JDK -11
|
||||
pats = pat == null ? List.<JCExpression>nil() : List.of(pat);
|
||||
pats = readObject(tree, "pats", null); // JDK 12-17
|
||||
}
|
||||
if (pats == null) {
|
||||
JCTree pat = readObject(tree, "pat", null); // JDK -11
|
||||
pats = pat == null ? List.<JCTree>nil() : List.of(pat);
|
||||
}
|
||||
|
||||
if (pats.isEmpty()) {
|
||||
if (pats.isEmpty() || pats.size() == 1 && pats.head.getClass().getName().endsWith("$JCDefaultCaseLabel")) {
|
||||
aPrint("default");
|
||||
} else {
|
||||
aPrint("case ");
|
||||
@@ -1421,6 +1432,22 @@ public class PrettyPrinter extends JCTree.Visitor {
|
||||
print((Name) readObject(var, "name", null));
|
||||
}
|
||||
|
||||
void printDefaultCase(JCTree tree) {
|
||||
print("default");
|
||||
}
|
||||
|
||||
void printGuardPattern(JCTree tree) {
|
||||
print((JCTree) readObject(tree, "patt", null));
|
||||
print(" && ");
|
||||
print((JCExpression) readObject(tree, "expr", null));
|
||||
}
|
||||
|
||||
void printParenthesizedPattern(JCTree tree) {
|
||||
print("(");
|
||||
print((JCTree) readObject(tree, "pattern", null));
|
||||
print(")");
|
||||
}
|
||||
|
||||
@Override public void visitTry(JCTry tree) {
|
||||
aPrint("try ");
|
||||
List<?> resources = readObject(tree, "resources", List.nil());
|
||||
@@ -1639,6 +1666,12 @@ public class PrettyPrinter extends JCTree.Visitor {
|
||||
printYieldExpression(tree);
|
||||
} else if (className.endsWith("$JCBindingPattern")) { // Introduced as preview in JDK14
|
||||
printBindingPattern(tree);
|
||||
} else if (className.endsWith("$JCDefaultCaseLabel")) { // Introduced in JDK17
|
||||
printDefaultCase(tree);
|
||||
} else if (className.endsWith("$JCGuardPattern")) { // Introduced in JDK17
|
||||
printGuardPattern(tree);
|
||||
} else if (className.endsWith("$JCParenthesizedPattern")) { // Introduced in JDK17
|
||||
printParenthesizedPattern(tree);
|
||||
} else {
|
||||
throw new AssertionError("Unhandled tree type: " + tree.getClass() + ": " + tree);
|
||||
}
|
||||
|
||||
@@ -87,14 +87,14 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable {
|
||||
patchHideGeneratedNodes(sm);
|
||||
patchPostCompileHookEclipse(sm);
|
||||
patchFixSourceTypeConverter(sm);
|
||||
patchDisableLombokForCodeCleanup(sm);
|
||||
patchListRewriteHandleGeneratedMethods(sm);
|
||||
patchSyntaxAndOccurrencesHighlighting(sm);
|
||||
patchSortMembersOperation(sm);
|
||||
patchExtractInterface(sm);
|
||||
patchExtractInterfaceAndPullUp(sm);
|
||||
patchAboutDialog(sm);
|
||||
patchEclipseDebugPatches(sm);
|
||||
patchJavadoc(sm);
|
||||
patchASTConverterLiterals(sm);
|
||||
|
||||
patchPostCompileHookEcj(sm);
|
||||
|
||||
@@ -134,7 +134,7 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable {
|
||||
.transplant().build());
|
||||
}
|
||||
|
||||
private static void patchExtractInterface(ScriptManager sm) {
|
||||
private static void patchExtractInterfaceAndPullUp(ScriptManager sm) {
|
||||
/* Fix sourceEnding for generated nodes to avoid null pointer */
|
||||
sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.wrapMethodCall()
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.compiler.SourceElementNotifier", "notifySourceElementRequestor", "void", "org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration", "org.eclipse.jdt.internal.compiler.ast.TypeDeclaration", "org.eclipse.jdt.internal.compiler.ast.ImportReference"))
|
||||
@@ -156,10 +156,31 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable {
|
||||
.requestExtra(StackRequest.THIS, StackRequest.PARAM4)
|
||||
.transplant().build());
|
||||
|
||||
/* get real generated node in stead of a random one generated by the annotation */
|
||||
/* Get real node source instead of the annotation */
|
||||
sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.wrapMethodCall()
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.corext.refactoring.structure.HierarchyProcessor", "createPlaceholderForSingleVariableDeclaration", "org.eclipse.jdt.core.dom.SingleVariableDeclaration",
|
||||
"org.eclipse.jdt.core.dom.SingleVariableDeclaration",
|
||||
"org.eclipse.jdt.core.ICompilationUnit",
|
||||
"org.eclipse.jdt.core.dom.rewrite.ASTRewrite"
|
||||
))
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.corext.refactoring.structure.HierarchyProcessor", "createPlaceholderForType", "org.eclipse.jdt.core.dom.Type",
|
||||
"org.eclipse.jdt.core.dom.Type",
|
||||
"org.eclipse.jdt.core.ICompilationUnit",
|
||||
"org.eclipse.jdt.core.dom.rewrite.ASTRewrite"
|
||||
))
|
||||
.methodToWrap(new Hook("org.eclipse.jdt.core.IBuffer", "getText", "java.lang.String", "int", "int"))
|
||||
.wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "getRealNodeSource", "java.lang.String", "java.lang.String", "org.eclipse.jdt.core.dom.ASTNode"))
|
||||
.requestExtra(StackRequest.PARAM1)
|
||||
.transplant()
|
||||
.build());
|
||||
|
||||
/* Get real generated node instead of a random one generated by the annotation */
|
||||
sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.replaceMethodCall()
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.corext.refactoring.structure.ExtractInterfaceProcessor", "createMemberDeclarations"))
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.corext.refactoring.structure.ExtractInterfaceProcessor", "createMethodComments"))
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.corext.refactoring.structure.PullUpRefactoringProcessor", "createAbstractMethod"))
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.corext.refactoring.structure.PullUpRefactoringProcessor", "addMethodStubForAbstractMethod"))
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.corext.refactoring.structure.PullUpRefactoringProcessor", "createChangeManager"))
|
||||
.methodToReplace(new Hook("org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil", "getMethodDeclarationNode", "org.eclipse.jdt.core.dom.MethodDeclaration", "org.eclipse.jdt.core.IMethod", "org.eclipse.jdt.core.dom.CompilationUnit"))
|
||||
.replacementMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "getRealMethodDeclarationNode", "org.eclipse.jdt.core.dom.MethodDeclaration", "org.eclipse.jdt.core.IMethod", "org.eclipse.jdt.core.dom.CompilationUnit"))
|
||||
.transplant().build());
|
||||
@@ -177,6 +198,29 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable {
|
||||
.decisionMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "isGenerated", "boolean", "org.eclipse.jdt.core.dom.ASTNode"))
|
||||
.request(StackRequest.PARAM2)
|
||||
.transplant().build());
|
||||
|
||||
/* Do not add a modifier to the generating annotation during pull up
|
||||
*
|
||||
* Example: Pull up a protected method (canEqual()/@EqualsAndHashCode)
|
||||
*/
|
||||
sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.exitEarly()
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.corext.refactoring.structure.MemberVisibilityAdjustor$IncomingMemberVisibilityAdjustment", "rewriteVisibility"))
|
||||
.decisionMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "skipRewriteVisibility", "boolean", "org.eclipse.jdt.internal.corext.refactoring.structure.MemberVisibilityAdjustor$IncomingMemberVisibilityAdjustment"))
|
||||
.request(StackRequest.THIS)
|
||||
.transplant()
|
||||
.build());
|
||||
|
||||
/*
|
||||
* ImportRemover sometimes removes lombok imports if a generated method/type gets changed. Skipping all generated nodes fixes this behavior.
|
||||
*
|
||||
* Example: Create a class (Use.java) that uses a generated method (Test t; t.toString();) and pull up this generated method.
|
||||
*/
|
||||
sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.exitEarly()
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.corext.refactoring.structure.ImportRemover", "registerRemovedNode", "void", "org.eclipse.jdt.core.dom.ASTNode"))
|
||||
.decisionMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "isGenerated", "boolean", "org.eclipse.jdt.core.dom.ASTNode"))
|
||||
.request(StackRequest.PARAM1)
|
||||
.transplant()
|
||||
.build());
|
||||
}
|
||||
|
||||
private static void patchAboutDialog(ScriptManager sm) {
|
||||
@@ -200,20 +244,13 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable {
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.ui.search.OccurrencesFinder", "addUsage"))
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.ui.search.OccurrencesFinder", "addWrite"))
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlightingReconciler$PositionCollector", "visit", "boolean", "org.eclipse.jdt.core.dom.SimpleName"))
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.ui.javaeditor.SemanticHighlightingReconciler$PositionCollector", "visitLiteral", "boolean", "org.eclipse.jdt.core.dom.Expression"))
|
||||
.decisionMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "isGenerated", "boolean", "org.eclipse.jdt.core.dom.ASTNode"))
|
||||
.valueMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "returnFalse", "boolean", "java.lang.Object"))
|
||||
.request(StackRequest.PARAM1)
|
||||
.build());
|
||||
}
|
||||
|
||||
private static void patchDisableLombokForCodeCleanup(ScriptManager sm) {
|
||||
sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.exitEarly()
|
||||
.target(new MethodTarget("org.eclipse.jdt.core.dom.ASTNode", "accept", "void", "org.eclipse.jdt.core.dom.ASTVisitor"))
|
||||
.decisionMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "isRefactoringVisitorAndGenerated", "boolean", "org.eclipse.jdt.core.dom.ASTNode", "org.eclipse.jdt.core.dom.ASTVisitor"))
|
||||
.request(StackRequest.THIS, StackRequest.PARAM1)
|
||||
.build());
|
||||
}
|
||||
|
||||
private static void patchListRewriteHandleGeneratedMethods(ScriptManager sm) {
|
||||
sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.replaceMethodCall()
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteAnalyzer$ListRewriter", "rewriteList"))
|
||||
@@ -308,6 +345,12 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable {
|
||||
"org.eclipse.jdt.core.dom.SimpleName[]"))
|
||||
.request(StackRequest.RETURN_VALUE).build());
|
||||
|
||||
sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.exitEarly()
|
||||
.target(new MethodTarget("org.eclipse.jdt.core.dom.ASTNode", "accept", "void", "org.eclipse.jdt.core.dom.ASTVisitor"))
|
||||
.decisionMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "isBlockedVisitorAndGenerated", "boolean", "org.eclipse.jdt.core.dom.ASTNode", "org.eclipse.jdt.core.dom.ASTVisitor"))
|
||||
.request(StackRequest.THIS, StackRequest.PARAM1)
|
||||
.build());
|
||||
|
||||
patchRefactorScripts(sm);
|
||||
patchFormatters(sm);
|
||||
}
|
||||
@@ -528,6 +571,13 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable {
|
||||
"org.eclipse.jdt.core.dom.Name", "java.lang.Object"))
|
||||
.transplant().build());
|
||||
|
||||
sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.wrapMethodCall()
|
||||
.target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "convert", "org.eclipse.jdt.core.dom.ASTNode", "boolean", "org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration"))
|
||||
.methodToWrap(new Hook("org.eclipse.jdt.core.dom.Block", "<init>", "void", "org.eclipse.jdt.core.dom.AST"))
|
||||
.requestExtra(StackRequest.PARAM2)
|
||||
.wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "setIsGeneratedFlag", "void",
|
||||
"org.eclipse.jdt.core.dom.ASTNode", "org.eclipse.jdt.internal.compiler.ast.ASTNode"))
|
||||
.transplant().build());
|
||||
|
||||
sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.wrapMethodCall()
|
||||
.target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "convertType", "org.eclipse.jdt.core.dom.Type", "org.eclipse.jdt.internal.compiler.ast.TypeReference"))
|
||||
@@ -766,6 +816,7 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable {
|
||||
|
||||
sm.addScript(ScriptBuilder.replaceMethodCall()
|
||||
.target(new MethodTarget(LOCALDECLARATION_SIG, "resolve", "void", BLOCKSCOPE_SIG))
|
||||
.target(new MethodTarget(LOCALDECLARATION_SIG, "resolve", "void", BLOCKSCOPE_SIG, "boolean"))
|
||||
.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))
|
||||
@@ -895,6 +946,14 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable {
|
||||
.requestExtra(StackRequest.PARAM1)
|
||||
.build());
|
||||
|
||||
/* This is a copy for the language server implementation that also supports markdown */
|
||||
sm.addScript(ScriptBuilder.wrapMethodCall()
|
||||
.target(new MethodTarget("org.eclipse.jdt.ls.core.internal.javadoc.JavadocContentAccess2", "getHTMLContent", "java.lang.String", "org.eclipse.jdt.core.IJavaElement", "boolean"))
|
||||
.methodToWrap(new Hook("org.eclipse.jdt.ls.core.internal.javadoc.JavadocContentAccess2", "getHTMLContentFromSource", "java.lang.String", "org.eclipse.jdt.core.IJavaElement"))
|
||||
.wrapMethod(new Hook("lombok.launch.PatchFixesHider$Javadoc", "getHTMLContentFromSource", "java.lang.String", "java.lang.String", "org.eclipse.jdt.core.IJavaElement"))
|
||||
.requestExtra(StackRequest.PARAM1)
|
||||
.build());
|
||||
|
||||
/* This is an older version that uses IMember instead of IJavaElement */
|
||||
sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.wrapMethodCall()
|
||||
.target(new MethodTarget("org.eclipse.jdt.internal.ui.text.javadoc.JavadocContentAccess2", "getHTMLContent", "java.lang.String", "org.eclipse.jdt.core.IMember", "boolean"))
|
||||
@@ -919,4 +978,22 @@ public class EclipsePatcher implements AgentLauncher.AgentLaunchable {
|
||||
.build());
|
||||
}
|
||||
|
||||
private static void patchASTConverterLiterals(ScriptManager sm) {
|
||||
sm.addScriptIfWitness(OSGI_TYPES, ScriptBuilder.wrapMethodCall()
|
||||
.target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "convert", "org.eclipse.jdt.core.dom.Expression", "org.eclipse.jdt.internal.compiler.ast.StringLiteral"))
|
||||
.target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "convert", "org.eclipse.jdt.core.dom.Expression", "org.eclipse.jdt.internal.compiler.ast.TextBlock"))
|
||||
.target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "convert", "org.eclipse.jdt.core.dom.CharacterLiteral", "org.eclipse.jdt.internal.compiler.ast.CharLiteral"))
|
||||
.target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "convert", "org.eclipse.jdt.core.dom.NumberLiteral", "org.eclipse.jdt.internal.compiler.ast.DoubleLiteral"))
|
||||
.target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "convert", "org.eclipse.jdt.core.dom.NumberLiteral", "org.eclipse.jdt.internal.compiler.ast.FloatLiteral"))
|
||||
.target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "convert", "org.eclipse.jdt.core.dom.NumberLiteral", "org.eclipse.jdt.internal.compiler.ast.LongLiteral"))
|
||||
.target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "convert", "org.eclipse.jdt.core.dom.NumberLiteral", "org.eclipse.jdt.internal.compiler.ast.LongLiteralMinValue"))
|
||||
.target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "convert", "org.eclipse.jdt.core.dom.NumberLiteral", "org.eclipse.jdt.internal.compiler.ast.IntLiteral"))
|
||||
.target(new MethodTarget("org.eclipse.jdt.core.dom.ASTConverter", "convert", "org.eclipse.jdt.core.dom.NumberLiteral", "org.eclipse.jdt.internal.compiler.ast.IntLiteralMinValue"))
|
||||
.methodToWrap(new Hook("java.lang.String", "<init>", "void", "char[]", "int", "int"))
|
||||
.requestExtra(StackRequest.PARAM1)
|
||||
.wrapMethod(new Hook("lombok.launch.PatchFixesHider$PatchFixes", "getRealNodeSource", "java.lang.String", "java.lang.String", "org.eclipse.jdt.internal.compiler.ast.ASTNode"))
|
||||
.transplant()
|
||||
.build());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
@@ -103,8 +103,9 @@ public class PatchJavadoc {
|
||||
private static class Reflection {
|
||||
private static final Method javadoc2HTML;
|
||||
private static final Method oldJavadoc2HTML;
|
||||
private static final Method lsJavadoc2HTML;
|
||||
static {
|
||||
Method a = null, b = null;
|
||||
Method a = null, b = null, c = null;
|
||||
|
||||
try {
|
||||
a = Permit.getMethod(JavadocContentAccess2.class, "javadoc2HTML", IMember.class, IJavaElement.class, String.class);
|
||||
@@ -112,9 +113,13 @@ public class PatchJavadoc {
|
||||
try {
|
||||
b = Permit.getMethod(JavadocContentAccess2.class, "javadoc2HTML", IMember.class, String.class);
|
||||
} catch (Throwable t) {}
|
||||
try {
|
||||
c = Permit.getMethod(Class.forName("org.eclipse.jdt.ls.core.internal.javadoc.JavadocContentAccess2"), "javadoc2HTML", IMember.class, IJavaElement.class, String.class);
|
||||
} catch (Throwable t) {}
|
||||
|
||||
javadoc2HTML = a;
|
||||
oldJavadoc2HTML = b;
|
||||
lsJavadoc2HTML = c;
|
||||
}
|
||||
|
||||
private static String javadoc2HTML(IMember member, IJavaElement element, String rawJavadoc) {
|
||||
@@ -125,6 +130,13 @@ public class PatchJavadoc {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (lsJavadoc2HTML != null) {
|
||||
try {
|
||||
return (String) lsJavadoc2HTML.invoke(null, member, element, rawJavadoc);
|
||||
} catch (Throwable t) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (oldJavadoc2HTML != null) {
|
||||
try {
|
||||
return (String) oldJavadoc2HTML.invoke(null, member, rawJavadoc);
|
||||
|
||||
@@ -35,13 +35,11 @@ import org.eclipse.jdt.internal.compiler.ast.FunctionalExpression;
|
||||
import org.eclipse.jdt.internal.compiler.ast.ImportReference;
|
||||
import org.eclipse.jdt.internal.compiler.ast.LambdaExpression;
|
||||
import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration;
|
||||
import org.eclipse.jdt.internal.compiler.ast.MessageSend;
|
||||
import org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference;
|
||||
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.eclipse.jdt.internal.compiler.impl.Constant;
|
||||
import org.eclipse.jdt.internal.compiler.impl.ReferenceContext;
|
||||
import org.eclipse.jdt.internal.compiler.lookup.ArrayBinding;
|
||||
import org.eclipse.jdt.internal.compiler.lookup.Binding;
|
||||
@@ -59,8 +57,8 @@ import org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static lombok.Lombok.sneakyThrow;
|
||||
import static lombok.eclipse.Eclipse.poss;
|
||||
import static lombok.eclipse.handlers.EclipseHandlerUtil.makeType;
|
||||
import static lombok.eclipse.Eclipse.*;
|
||||
import static lombok.eclipse.handlers.EclipseHandlerUtil.*;
|
||||
import static org.eclipse.jdt.core.compiler.CategorizedProblem.CAT_TYPE;
|
||||
|
||||
public class PatchVal {
|
||||
@@ -237,13 +235,19 @@ public class PatchVal {
|
||||
|
||||
TypeReference replacement = null;
|
||||
|
||||
// Java 10+: Lombok uses the native 'var' support and transforms 'val' to 'final var'.
|
||||
if (hasNativeVarSupport(scope) && val) {
|
||||
replacement = new SingleTypeReference("var".toCharArray(), pos(local.type));
|
||||
local.initialization = init;
|
||||
init = null;
|
||||
}
|
||||
|
||||
if (init != null) {
|
||||
if (init.getClass().getName().equals("org.eclipse.jdt.internal.compiler.ast.LambdaExpression")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TypeBinding resolved = null;
|
||||
Constant oldConstant = init.constant;
|
||||
try {
|
||||
resolved = decomponent ? getForEachComponentType(init, scope) : resolveForExpression(init, scope);
|
||||
} catch (NullPointerException e) {
|
||||
@@ -253,6 +257,46 @@ public class PatchVal {
|
||||
// just go with 'Object' and let the IDE print the appropriate errors.
|
||||
resolved = null;
|
||||
}
|
||||
|
||||
if (resolved == null) {
|
||||
if (init instanceof ConditionalExpression) {
|
||||
ConditionalExpression cexp = (ConditionalExpression) init;
|
||||
Expression ifTrue = cexp.valueIfTrue;
|
||||
Expression ifFalse = cexp.valueIfFalse;
|
||||
TypeBinding ifTrueResolvedType = ifTrue.resolvedType;
|
||||
CompilationResult compilationResult = scope.referenceCompilationUnit().compilationResult;
|
||||
CategorizedProblem[] problems = compilationResult.problems;
|
||||
CategorizedProblem lastProblem = problems[compilationResult.problemCount - 1];
|
||||
if (ifTrueResolvedType != null && ifFalse.resolvedType == null && lastProblem.getCategoryID() == CAT_TYPE) {
|
||||
int problemCount = compilationResult.problemCount;
|
||||
for (int i = 0; i < problemCount; ++i) {
|
||||
if (problems[i] == lastProblem) {
|
||||
problems[i] = null;
|
||||
if (i + 1 < problemCount) {
|
||||
System.arraycopy(problems, i + 1, problems, i, problemCount - i + 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
compilationResult.removeProblem(lastProblem);
|
||||
if (!compilationResult.hasErrors()) {
|
||||
clearIgnoreFurtherInvestigationField(scope.referenceContext());
|
||||
setValue(getField(CompilationResult.class, "hasMandatoryErrors"), compilationResult, false);
|
||||
}
|
||||
|
||||
if (ifFalse instanceof FunctionalExpression) {
|
||||
FunctionalExpression functionalExpression = (FunctionalExpression) ifFalse;
|
||||
functionalExpression.setExpectedType(ifTrueResolvedType);
|
||||
}
|
||||
if (ifFalse.resolvedType == null) {
|
||||
resolveForExpression(ifFalse, scope);
|
||||
}
|
||||
|
||||
resolved = ifTrueResolvedType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (resolved != null) {
|
||||
try {
|
||||
replacement = makeType(resolved, local.type, false);
|
||||
@@ -260,10 +304,6 @@ public class PatchVal {
|
||||
} catch (Exception e) {
|
||||
// Some type thing failed.
|
||||
}
|
||||
} else {
|
||||
if (init instanceof MessageSend && ((MessageSend) init).actualReceiverType == null) {
|
||||
init.constant = oldConstant;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,6 +321,14 @@ public class PatchVal {
|
||||
return is(local.type, scope, "lombok.val");
|
||||
}
|
||||
|
||||
private static boolean hasNativeVarSupport(Scope scope) {
|
||||
long sl = scope.problemReporter().options.sourceLevel >> 16;
|
||||
long cl = scope.problemReporter().options.complianceLevel >> 16;
|
||||
if (sl == 0) sl = cl;
|
||||
if (cl == 0) cl = sl;
|
||||
return Math.min((int)(sl - 44), (int)(cl - 44)) >= 10;
|
||||
}
|
||||
|
||||
public static boolean handleValForForEach(ForeachStatement forEach, BlockScope scope) {
|
||||
if (forEach.elementVariable == null) return false;
|
||||
|
||||
@@ -288,6 +336,8 @@ public class PatchVal {
|
||||
boolean var = isVar(forEach.elementVariable, scope);
|
||||
if (!(val || var)) return false;
|
||||
|
||||
if (hasNativeVarSupport(scope)) return false;
|
||||
|
||||
TypeBinding component = getForEachComponentType(forEach.collection, scope);
|
||||
if (component == null) return false;
|
||||
TypeReference replacement = makeType(component, forEach.elementVariable.type, false);
|
||||
@@ -353,43 +403,7 @@ public class PatchVal {
|
||||
// Known cause of issues; for example: val e = mth("X"), where mth takes 2 arguments.
|
||||
return null;
|
||||
} catch (AbortCompilation e) {
|
||||
if (collection instanceof ConditionalExpression) {
|
||||
ConditionalExpression cexp = (ConditionalExpression) collection;
|
||||
Expression ifTrue = cexp.valueIfTrue;
|
||||
Expression ifFalse = cexp.valueIfFalse;
|
||||
TypeBinding ifTrueResolvedType = ifTrue.resolvedType;
|
||||
CategorizedProblem problem = e.problem;
|
||||
if (ifTrueResolvedType != null && ifFalse.resolvedType == null && problem.getCategoryID() == CAT_TYPE) {
|
||||
CompilationResult compilationResult = e.compilationResult;
|
||||
CategorizedProblem[] problems = compilationResult.problems;
|
||||
int problemCount = compilationResult.problemCount;
|
||||
for (int i = 0; i < problemCount; ++i) {
|
||||
if (problems[i] == problem) {
|
||||
problems[i] = null;
|
||||
if (i + 1 < problemCount) {
|
||||
System.arraycopy(problems, i + 1, problems, i, problemCount - i + 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
compilationResult.removeProblem(problem);
|
||||
if (!compilationResult.hasErrors()) {
|
||||
clearIgnoreFurtherInvestigationField(scope.referenceContext());
|
||||
setValue(getField(CompilationResult.class, "hasMandatoryErrors"), compilationResult, false);
|
||||
}
|
||||
|
||||
if (ifFalse instanceof FunctionalExpression) {
|
||||
FunctionalExpression functionalExpression = (FunctionalExpression) ifFalse;
|
||||
functionalExpression.setExpectedType(ifTrueResolvedType);
|
||||
}
|
||||
if (ifFalse.resolvedType == null) {
|
||||
ifFalse.resolve(scope);
|
||||
}
|
||||
|
||||
return ifTrueResolvedType;
|
||||
}
|
||||
}
|
||||
throw e;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,7 @@ import org.eclipse.jdt.internal.core.dom.rewrite.RewriteEvent;
|
||||
import org.eclipse.jdt.internal.core.dom.rewrite.TokenScanner;
|
||||
import org.eclipse.jdt.internal.corext.refactoring.SearchResultGroup;
|
||||
import org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil;
|
||||
import org.eclipse.jdt.internal.corext.refactoring.structure.MemberVisibilityAdjustor.IncomingMemberVisibilityAdjustment;
|
||||
|
||||
import static lombok.eclipse.EcjAugments.ASTNode_generatedBy;
|
||||
|
||||
@@ -413,25 +414,27 @@ final class PatchFixesHider {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean isRefactoringVisitorAndGenerated(org.eclipse.jdt.core.dom.ASTNode node, org.eclipse.jdt.core.dom.ASTVisitor visitor) {
|
||||
if (visitor == null) return false;
|
||||
|
||||
String className = visitor.getClass().getName();
|
||||
if (!(className.startsWith("org.eclipse.jdt.internal.corext.fix") || className.startsWith("org.eclipse.jdt.internal.ui.fix"))) return false;
|
||||
|
||||
|
||||
public static boolean isGenerated(org.eclipse.jdt.core.IMember member) {
|
||||
boolean result = false;
|
||||
try {
|
||||
result = ((Boolean)node.getClass().getField("$isGenerated").get(node)).booleanValue();
|
||||
if (!result && node.getParent() != null && node.getParent() instanceof org.eclipse.jdt.core.dom.QualifiedName) {
|
||||
result = isGenerated(node.getParent());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
result = member.getNameRange().getLength() <= 0 || member.getNameRange().equals(member.getSourceRange());
|
||||
} catch (JavaModelException e) {
|
||||
// better to assume it isn't generated
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean isBlockedVisitorAndGenerated(org.eclipse.jdt.core.dom.ASTNode node, org.eclipse.jdt.core.dom.ASTVisitor visitor) {
|
||||
if (visitor == null) return false;
|
||||
|
||||
String className = visitor.getClass().getName();
|
||||
if (!(className.startsWith("org.eclipse.jdt.internal.corext.fix") || className.startsWith("org.eclipse.jdt.internal.ui.fix") || className.startsWith("org.eclipse.jdt.ls.core.internal.semantictokens.SemanticTokensVisitor"))) return false;
|
||||
if (className.equals("org.eclipse.jdt.internal.corext.fix.VariableDeclarationFixCore$WrittenNamesFinder")) return false;
|
||||
|
||||
return isGenerated(node);
|
||||
}
|
||||
|
||||
public static boolean isListRewriteOnGeneratedNode(org.eclipse.jdt.core.dom.rewrite.ListRewrite rewrite) {
|
||||
return isGenerated(rewrite.getParent());
|
||||
}
|
||||
@@ -473,8 +476,10 @@ final class PatchFixesHider {
|
||||
StringBuilder signature = new StringBuilder();
|
||||
addAnnotations(annotations, signature);
|
||||
|
||||
if ((Boolean)processor.getClass().getDeclaredField("fPublic").get(processor)) signature.append("public ");
|
||||
if ((Boolean)processor.getClass().getDeclaredField("fAbstract").get(processor)) signature.append("abstract ");
|
||||
try {
|
||||
if ((Boolean)processor.getClass().getDeclaredField("fPublic").get(processor)) signature.append("public ");
|
||||
if ((Boolean)processor.getClass().getDeclaredField("fAbstract").get(processor)) signature.append("abstract ");
|
||||
} catch (Throwable t) { }
|
||||
|
||||
signature
|
||||
.append(declaration.getReturnType2().toString())
|
||||
@@ -520,7 +525,7 @@ final class PatchFixesHider {
|
||||
for (Object value : normalAnn.values()) values.add(value.toString());
|
||||
}
|
||||
|
||||
signature.append("@").append(annotation.resolveTypeBinding().getQualifiedName());
|
||||
signature.append("@").append(annotation.getTypeName().getFullyQualifiedName());
|
||||
if (!values.isEmpty()) {
|
||||
signature.append("(");
|
||||
boolean first = true;
|
||||
@@ -696,7 +701,7 @@ final class PatchFixesHider {
|
||||
public static IMethod[] removeGeneratedMethods(IMethod[] methods) throws Exception {
|
||||
List<IMethod> result = new ArrayList<IMethod>();
|
||||
for (IMethod m : methods) {
|
||||
if (m.getNameRange().getLength() > 0 && !m.getNameRange().equals(m.getSourceRange())) result.add(m);
|
||||
if (!isGenerated(m)) result.add(m);
|
||||
}
|
||||
return result.size() == methods.length ? methods : result.toArray(new IMethod[0]);
|
||||
}
|
||||
@@ -799,5 +804,21 @@ final class PatchFixesHider {
|
||||
|
||||
return replace;
|
||||
}
|
||||
|
||||
public static String getRealNodeSource(String original, org.eclipse.jdt.internal.compiler.ast.ASTNode node) {
|
||||
if (!isGenerated(node)) return original;
|
||||
|
||||
return node.toString();
|
||||
}
|
||||
|
||||
public static java.lang.String getRealNodeSource(java.lang.String original, org.eclipse.jdt.core.dom.ASTNode node) throws Exception {
|
||||
if (!isGenerated(node)) return original;
|
||||
|
||||
return node.toString();
|
||||
}
|
||||
|
||||
public static boolean skipRewriteVisibility(IncomingMemberVisibilityAdjustment adjustment) {
|
||||
return isGenerated(adjustment.getMember());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,16 +64,4 @@ public abstract class IdeLocation {
|
||||
return x == null ? p.getPath() : x;
|
||||
}
|
||||
}
|
||||
|
||||
private static final String LEGAL_PATH_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_/";
|
||||
private static final String LEGAL_PATH_CHARS_WINDOWS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,/;'[]{}!@#$^&()-_+= :\\";
|
||||
public static String escapePath(String path) {
|
||||
StringBuilder out = new StringBuilder();
|
||||
String legalChars = OsUtils.getOS() == OsUtils.OS.UNIX ? LEGAL_PATH_CHARS : LEGAL_PATH_CHARS_WINDOWS;
|
||||
for (char c : path.toCharArray()) {
|
||||
if (legalChars.indexOf(c) == -1) out.append('\\');
|
||||
out.append(c);
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
}
|
||||
@@ -347,8 +347,10 @@ public final class EclipseProductLocation extends IdeLocation {
|
||||
pathPrefix = pathToLombokJarPrefix;
|
||||
}
|
||||
|
||||
// NB: You may be tempted to escape this, but don't; there is no possibility to escape this, but
|
||||
// eclipse/java reads the string following the colon in 'raw' fashion. Spaces, colons - all works fine.
|
||||
newContents.append(String.format(
|
||||
"-javaagent:%s", escapePath(pathPrefix + "lombok.jar"))).append(OS_NEWLINE);
|
||||
"-javaagent:%s", pathPrefix + "lombok.jar")).append(OS_NEWLINE);
|
||||
|
||||
FileOutputStream fos = new FileOutputStream(eclipseIniPath);
|
||||
try {
|
||||
|
||||
@@ -35,6 +35,7 @@ import lombok.installer.OsUtils;
|
||||
public class StandardProductDescriptor implements EclipseProductDescriptor {
|
||||
|
||||
private static final String USER_HOME = System.getProperty("user.home", ".");
|
||||
private static final String[] BASE_WINDOWS_ROOTS = {"\\", "\\Program Files", "\\Program Files (x86)", "\\ProgramData\\Chocolatey\\lib"};
|
||||
private static final String[] WINDOWS_ROOTS = windowsRoots();
|
||||
private static final String[] MAC_ROOTS = {"/Applications", USER_HOME};
|
||||
private static final String[] UNIX_ROOTS = {USER_HOME};
|
||||
@@ -159,8 +160,11 @@ public class StandardProductDescriptor implements EclipseProductDescriptor {
|
||||
|
||||
private static String[] windowsRoots() {
|
||||
String localAppData = windowsLocalAppData();
|
||||
if (localAppData == null) return new String[] {"\\", "\\Program Files", "\\Program Files (x86)", USER_HOME};
|
||||
return new String[] {"\\", "\\Program Files", "\\Program Files (x86)", USER_HOME, localAppData};
|
||||
String[] out = new String[BASE_WINDOWS_ROOTS.length + (localAppData == null ? 1 : 2)];
|
||||
System.arraycopy(BASE_WINDOWS_ROOTS, 0, out, 0, BASE_WINDOWS_ROOTS.length);
|
||||
out[BASE_WINDOWS_ROOTS.length] = USER_HOME;
|
||||
if (localAppData != null) out[BASE_WINDOWS_ROOTS.length + 1] = localAppData;
|
||||
return out;
|
||||
}
|
||||
|
||||
private static String windowsLocalAppData() {
|
||||
|
||||
@@ -224,8 +224,11 @@ public class Eclipse {
|
||||
int highestVersionSoFar = 0;
|
||||
for (Field f : ClassFileConstants.class.getDeclaredFields()) {
|
||||
try {
|
||||
if (f.getName().startsWith("JDK1_")) {
|
||||
int thisVersion = Integer.parseInt(f.getName().substring("JDK1_".length()));
|
||||
if (f.getName().startsWith("JDK")) {
|
||||
String versionString = f.getName().substring("JDK".length());
|
||||
if (versionString.startsWith("1_")) versionString = versionString.substring("1_".length());
|
||||
|
||||
int thisVersion = Integer.parseInt(versionString);
|
||||
if (thisVersion > highestVersionSoFar) {
|
||||
highestVersionSoFar = thisVersion;
|
||||
latestEcjCompilerVersionConstantCached = (Long) f.get(null);
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
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
|
||||
}
|
||||
@@ -80,6 +80,8 @@ public class Javac {
|
||||
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)
|
||||
public static final long SEALED = 1L << 62; // ClassSymbols (Flag to indicate sealed class/interface declaration)
|
||||
public static final long NON_SEALED = 1L << 63; // ClassSymbols (Flag to indicate that the class/interface was declared with the non-sealed modifier)
|
||||
|
||||
/**
|
||||
* 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}.
|
||||
|
||||
@@ -607,7 +607,19 @@ public class JavacTreeMaker {
|
||||
|
||||
public JCCase Case(JCExpression pat, List<JCStatement> stats) {
|
||||
if (tryResolve(Case11)) return invoke(Case11, pat, stats);
|
||||
return invoke(Case12.Case12, Case12.CASE_KIND_STATEMENT, pat == null ? com.sun.tools.javac.util.List.nil() : com.sun.tools.javac.util.List.of(pat), stats, null);
|
||||
List<JCTree> labels;
|
||||
if (pat == null) {
|
||||
labels = tryResolve(DefaultCaseLabel) ? List.of(DefaultCaseLabel()) : List.<JCTree>nil();
|
||||
} else {
|
||||
labels = List.<JCTree>of(pat);
|
||||
}
|
||||
return invoke(Case12.Case12, Case12.CASE_KIND_STATEMENT, labels, stats, null);
|
||||
}
|
||||
|
||||
//javac versions: 17
|
||||
private static final MethodId<JCTree> DefaultCaseLabel = MethodId("DefaultCaseLabel", JCTree.class);
|
||||
public JCTree DefaultCaseLabel() {
|
||||
return invoke(DefaultCaseLabel);
|
||||
}
|
||||
|
||||
//javac versions: 6-8
|
||||
|
||||
@@ -32,8 +32,10 @@ import lombok.javac.JavacTreeMaker.TypeTag;
|
||||
import com.sun.source.tree.LabeledStatementTree;
|
||||
import com.sun.source.tree.VariableTree;
|
||||
import com.sun.tools.javac.tree.JCTree;
|
||||
import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
|
||||
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
|
||||
import com.sun.tools.javac.tree.TreeCopier;
|
||||
import com.sun.tools.javac.tree.TreeScanner;
|
||||
import com.sun.tools.javac.util.Context;
|
||||
import com.sun.tools.javac.util.List;
|
||||
|
||||
@@ -109,6 +111,21 @@ public class TreeMirrorMaker extends TreeCopier<Void> {
|
||||
if (wipeSymAndType) {
|
||||
copy.sym = null;
|
||||
copy.type = null;
|
||||
} else {
|
||||
if (original.vartype != null) {
|
||||
copy.vartype.type = original.vartype.type;
|
||||
original.vartype.accept(new TreeScanner() {
|
||||
@Override public void scan(JCTree tree) {
|
||||
super.scan(tree);
|
||||
originalToCopy.get(tree).type = tree.type;
|
||||
}
|
||||
|
||||
@Override public void visitSelect(JCFieldAccess tree) {
|
||||
super.visitSelect(tree);
|
||||
((JCFieldAccess) originalToCopy.get(tree)).sym = tree.sym;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
*/
|
||||
package lombok.javac.java8;
|
||||
|
||||
import java.nio.Buffer;
|
||||
import java.nio.CharBuffer;
|
||||
|
||||
import com.sun.tools.javac.parser.Scanner;
|
||||
@@ -79,7 +80,7 @@ public class CommentCollectingScannerFactory extends ScannerFactory {
|
||||
int limit;
|
||||
if (input instanceof CharBuffer && ((CharBuffer) input).hasArray()) {
|
||||
CharBuffer cb = (CharBuffer) input;
|
||||
cb.compact().flip();
|
||||
((Buffer)cb.compact()).flip();
|
||||
array = cb.array();
|
||||
limit = cb.limit();
|
||||
} else {
|
||||
|
||||
@@ -55,7 +55,8 @@ public class DirectoryRunner extends Runner {
|
||||
},
|
||||
ECJ {
|
||||
@Override public int getVersion() {
|
||||
return Eclipse.getEcjCompilerVersion();
|
||||
String javaVersionString = System.getProperty("compiler.compliance.level");
|
||||
return javaVersionString != null ? Integer.parseInt(javaVersionString) : Eclipse.getEcjCompilerVersion();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -161,6 +161,7 @@ public class LombokTestSource {
|
||||
private static final Pattern UNCHANGED_PATTERN = Pattern.compile("^\\s*unchanged\\s*(?:[-:].*)?$", Pattern.CASE_INSENSITIVE);
|
||||
private static final Pattern SKIP_COMPARE_CONTENT_PATTERN = Pattern.compile("^\\s*skip[- ]?compare[- ]?contents?\\s*(?:[-:].*)?$", Pattern.CASE_INSENSITIVE);
|
||||
private static final Pattern SKIP_IDEMPOTENT_PATTERN = Pattern.compile("^\\s*skip[- ]?idempotent\\s*(?:[-:].*)?$", Pattern.CASE_INSENSITIVE);
|
||||
private static final Pattern ISSUE_REF_PATTERN = Pattern.compile("^\\s*issue #?\\d+(:?\\s+.*)?$", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
private LombokTestSource(File file, String content, List<CompilerMessageMatcher> messages, List<String> directives) {
|
||||
this.file = file;
|
||||
@@ -200,6 +201,9 @@ public class LombokTestSource {
|
||||
skipIdempotent = true;
|
||||
continue;
|
||||
}
|
||||
if (ISSUE_REF_PATTERN.matcher(directive).matches()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lc.startsWith("platform ")) {
|
||||
String platformDesc = lc.substring("platform ".length());
|
||||
|
||||
@@ -42,7 +42,6 @@ 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.ElementKind;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
|
||||
import com.sun.source.util.TreePath;
|
||||
@@ -211,8 +210,8 @@ public class RunTestsViaDelombok extends AbstractRunTests {
|
||||
}
|
||||
|
||||
@Override public void visitVarDef(JCVariableDecl tree) {
|
||||
// Skip non-field variables
|
||||
if (!(parent instanceof JCClassDecl)) return;
|
||||
// Skip local variables
|
||||
if (!(parent instanceof JCClassDecl || parent instanceof JCMethodDecl)) return;
|
||||
|
||||
validateSymbol(tree, tree.sym);
|
||||
super.visitVarDef(tree);
|
||||
@@ -222,8 +221,8 @@ public class RunTestsViaDelombok extends AbstractRunTests {
|
||||
if (sym == null) {
|
||||
fail("Missing symbol for " + tree);
|
||||
}
|
||||
// Skip top level classes
|
||||
if (sym.owner.getKind() == ElementKind.PACKAGE) return;
|
||||
// Only classes have enclosed elements, skip everything else
|
||||
if (!sym.owner.getKind().isClass()) return;
|
||||
|
||||
if (!sym.owner.getEnclosedElements().contains(sym)) {
|
||||
fail(tree + " not added to parent");
|
||||
|
||||
@@ -64,9 +64,22 @@ import org.osgi.framework.BundleContext;
|
||||
public class RunTestsViaEcj extends AbstractRunTests {
|
||||
protected CompilerOptions ecjCompilerOptions() {
|
||||
CompilerOptions options = new CompilerOptions();
|
||||
options.complianceLevel = Eclipse.getLatestEcjCompilerVersionConstant();
|
||||
options.sourceLevel = Eclipse.getLatestEcjCompilerVersionConstant();
|
||||
options.targetJDK = Eclipse.getLatestEcjCompilerVersionConstant();
|
||||
Map<String, String> warnings = new HashMap<String, String>();
|
||||
|
||||
String javaVersionString = System.getProperty("compiler.compliance.level");
|
||||
long ecjCompilerVersionConstant = Eclipse.getLatestEcjCompilerVersionConstant();
|
||||
long ecjCompilerVersion = Eclipse.getEcjCompilerVersion();
|
||||
if (javaVersionString != null) {
|
||||
long javaVersion = Long.parseLong(javaVersionString);
|
||||
ecjCompilerVersionConstant = (javaVersion + 44) << 16;
|
||||
ecjCompilerVersion = javaVersion;
|
||||
} else {
|
||||
// Preview features are only allowed if the maximum compiler version is equal to the source version
|
||||
warnings.put("org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures", "enabled");
|
||||
}
|
||||
options.complianceLevel = ecjCompilerVersionConstant;
|
||||
options.sourceLevel = ecjCompilerVersionConstant;
|
||||
options.targetJDK = ecjCompilerVersionConstant;
|
||||
options.docCommentSupport = false;
|
||||
options.parseLiteralExpressionsAsConstants = true;
|
||||
options.inlineJsrBytecode = true;
|
||||
@@ -78,17 +91,14 @@ public class RunTestsViaEcj extends AbstractRunTests {
|
||||
options.reportUnusedParameterWhenOverridingConcrete = false;
|
||||
options.reportDeadCodeInTrivialIfStatement = false;
|
||||
options.generateClassFiles = false;
|
||||
Map<String, String> warnings = new HashMap<String, String>();
|
||||
warnings.put(CompilerOptions.OPTION_ReportUnusedLocal, "ignore");
|
||||
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);
|
||||
warnings.put(CompilerOptions.OPTION_Source, (ecjCompilerVersion < 9 ? "1." : "") + ecjCompilerVersion);
|
||||
options.set(warnings);
|
||||
return options;
|
||||
}
|
||||
@@ -96,7 +106,7 @@ public class RunTestsViaEcj extends AbstractRunTests {
|
||||
protected IErrorHandlingPolicy ecjErrorHandlingPolicy() {
|
||||
return new IErrorHandlingPolicy() {
|
||||
public boolean stopOnFirstError() {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean proceedOnErrors() {
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
public class Sealed {
|
||||
public abstract sealed class Parent permits Child1, Child2 {
|
||||
}
|
||||
|
||||
public final class Child1 extends Parent {
|
||||
}
|
||||
|
||||
public abstract non-sealed class Child2 extends Parent {
|
||||
}
|
||||
|
||||
public sealed interface SealedInterface permits ChildInterface1 {
|
||||
}
|
||||
|
||||
public non-sealed interface ChildInterface1 extends SealedInterface {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
public class Switch17 {
|
||||
String switchPatternMatching(Object o) {
|
||||
return switch (o) {
|
||||
case Integer i -> String.format("int %d", i);
|
||||
case Long l -> String.format("long %d", l);
|
||||
case Double d -> String.format("double %f", d);
|
||||
case String s -> String.format("String %s", s);
|
||||
default -> o.toString();
|
||||
};
|
||||
}
|
||||
|
||||
String switchNull(Object o) {
|
||||
return switch (o) {
|
||||
case null, default -> "?";
|
||||
};
|
||||
}
|
||||
|
||||
String switchGuardPattern(Object o) {
|
||||
return switch (o) {
|
||||
case String s && s.length() > 1 -> s;
|
||||
default -> o.toString();
|
||||
};
|
||||
}
|
||||
|
||||
String switchParenthesizedPattern(Object o) {
|
||||
return switch (o) {
|
||||
case (String s) -> s;
|
||||
default -> o.toString();
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -16,17 +16,17 @@ class ThisParameter {
|
||||
void runtimeTagged(@RuntimeTagged("runtime") ThisParameter this) {
|
||||
// no content
|
||||
}
|
||||
@Target(ElementType.PARAMETER)
|
||||
@Target(ElementType.TYPE_USE)
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@interface SourceTagged {
|
||||
String value();
|
||||
}
|
||||
@Target(ElementType.PARAMETER)
|
||||
@Target(ElementType.TYPE_USE)
|
||||
@Retention(RetentionPolicy.CLASS)
|
||||
@interface ClassTagged {
|
||||
String value();
|
||||
}
|
||||
@Target(ElementType.PARAMETER)
|
||||
@Target(ElementType.TYPE_USE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface RuntimeTagged {
|
||||
String value();
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
// version 15:
|
||||
public class Sealed {
|
||||
public abstract sealed class Parent permits Child1, Child2 {
|
||||
}
|
||||
|
||||
public final class Child1 extends Parent {
|
||||
}
|
||||
|
||||
public abstract non-sealed class Child2 extends Parent {
|
||||
}
|
||||
|
||||
public sealed interface SealedInterface permits ChildInterface1 {
|
||||
}
|
||||
|
||||
public non-sealed interface ChildInterface1 extends SealedInterface {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// version 17:
|
||||
public class Switch17 {
|
||||
String switchPatternMatching(Object o) {
|
||||
return switch (o) {
|
||||
case Integer i -> String.format("int %d", i);
|
||||
case Long l -> String.format("long %d", l);
|
||||
case Double d -> String.format("double %f", d);
|
||||
case String s -> String.format("String %s", s);
|
||||
default -> o.toString();
|
||||
};
|
||||
}
|
||||
|
||||
String switchNull(Object o) {
|
||||
return switch (o) {
|
||||
case null, default -> "?";
|
||||
};
|
||||
}
|
||||
|
||||
String switchGuardPattern(Object o) {
|
||||
return switch (o) {
|
||||
case String s && s.length() > 1 -> s;
|
||||
default -> o.toString();
|
||||
};
|
||||
}
|
||||
|
||||
String switchParenthesizedPattern(Object o) {
|
||||
return switch (o) {
|
||||
case (String s) -> s;
|
||||
default -> o.toString();
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// version 9: the 'this' param option exists in java8, but is bugged, in that annotations are not allowed on them, even without a @Target. The only purpose of the this param is annotations, so, boy, isn't that a punch in the face?
|
||||
// version 8:
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
@@ -22,19 +22,19 @@ class ThisParameter {
|
||||
// no content
|
||||
}
|
||||
|
||||
@Target(ElementType.PARAMETER)
|
||||
@Target(ElementType.TYPE_USE)
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@interface SourceTagged {
|
||||
String value();
|
||||
}
|
||||
|
||||
@Target(ElementType.PARAMETER)
|
||||
@Target(ElementType.TYPE_USE)
|
||||
@Retention(RetentionPolicy.CLASS)
|
||||
@interface ClassTagged {
|
||||
String value();
|
||||
}
|
||||
|
||||
@Target(ElementType.PARAMETER)
|
||||
@Target(ElementType.TYPE_USE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface RuntimeTagged {
|
||||
String value();
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
OPTIONAL 9 as of release 17, all floating-point expressions are evaluated strictly and 'strictfp' is not required
|
||||
@@ -0,0 +1 @@
|
||||
OPTIONAL 16 as of release 17, all floating-point expressions are evaluated strictly and 'strictfp' is not required
|
||||
@@ -0,0 +1,22 @@
|
||||
public class AccessorsInAnonymousClass {
|
||||
Object annonymous = new Object() {
|
||||
|
||||
class Inner {
|
||||
private String string;
|
||||
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public String string() {
|
||||
return this.string;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code this}.
|
||||
*/
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public Inner string(final String string) {
|
||||
this.string = string;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
public class BuilderInAnonymousClass {
|
||||
Object annonymous = new Object() {
|
||||
|
||||
class Inner {
|
||||
private String string;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
class BuilderNestedInEnum {
|
||||
public enum TestEnum {
|
||||
FOO, BAR;
|
||||
public static final class TestBuilder {
|
||||
private final String field;
|
||||
@java.lang.SuppressWarnings("all")
|
||||
TestBuilder(final String field) {
|
||||
this.field = field;
|
||||
}
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public static class TestBuilderBuilder {
|
||||
@java.lang.SuppressWarnings("all")
|
||||
private String field;
|
||||
@java.lang.SuppressWarnings("all")
|
||||
TestBuilderBuilder() {
|
||||
}
|
||||
/**
|
||||
* @return {@code this}.
|
||||
*/
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public BuilderNestedInEnum.TestEnum.TestBuilder.TestBuilderBuilder field(final String field) {
|
||||
this.field = field;
|
||||
return this;
|
||||
}
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public BuilderNestedInEnum.TestEnum.TestBuilder build() {
|
||||
return new BuilderNestedInEnum.TestEnum.TestBuilder(this.field);
|
||||
}
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public java.lang.String toString() {
|
||||
return "BuilderNestedInEnum.TestEnum.TestBuilder.TestBuilderBuilder(field=" + this.field + ")";
|
||||
}
|
||||
}
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public static BuilderNestedInEnum.TestEnum.TestBuilder.TestBuilderBuilder builder() {
|
||||
return new BuilderNestedInEnum.TestEnum.TestBuilder.TestBuilderBuilder();
|
||||
}
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public String getField() {
|
||||
return this.field;
|
||||
}
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public boolean equals(final java.lang.Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof BuilderNestedInEnum.TestEnum.TestBuilder)) return false;
|
||||
final BuilderNestedInEnum.TestEnum.TestBuilder other = (BuilderNestedInEnum.TestEnum.TestBuilder) o;
|
||||
final java.lang.Object this$field = this.getField();
|
||||
final java.lang.Object other$field = other.getField();
|
||||
if (this$field == null ? other$field != null : !this$field.equals(other$field)) return false;
|
||||
return true;
|
||||
}
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public int hashCode() {
|
||||
final int PRIME = 59;
|
||||
int result = 1;
|
||||
final java.lang.Object $field = this.getField();
|
||||
result = result * PRIME + ($field == null ? 43 : $field.hashCode());
|
||||
return result;
|
||||
}
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public java.lang.String toString() {
|
||||
return "BuilderNestedInEnum.TestEnum.TestBuilder(field=" + this.getField() + ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
class BuilderWithJavaBeansSpecCapitalization {
|
||||
java.util.List<String> a;
|
||||
java.util.List<String> aField;
|
||||
String bField;
|
||||
@java.lang.SuppressWarnings("all")
|
||||
BuilderWithJavaBeansSpecCapitalization(final java.util.List<String> a, final java.util.List<String> aField, final String bField) {
|
||||
this.a = a;
|
||||
this.aField = aField;
|
||||
this.bField = bField;
|
||||
}
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public static class BuilderWithJavaBeansSpecCapitalizationBuilder {
|
||||
@java.lang.SuppressWarnings("all")
|
||||
private java.util.ArrayList<String> a;
|
||||
@java.lang.SuppressWarnings("all")
|
||||
private java.util.ArrayList<String> aField;
|
||||
@java.lang.SuppressWarnings("all")
|
||||
private String bField;
|
||||
@java.lang.SuppressWarnings("all")
|
||||
BuilderWithJavaBeansSpecCapitalizationBuilder() {
|
||||
}
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder setZ(final String z) {
|
||||
if (this.a == null) this.a = new java.util.ArrayList<String>();
|
||||
this.a.add(z);
|
||||
return this;
|
||||
}
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder setA(final java.util.Collection<? extends String> a) {
|
||||
if (a == null) {
|
||||
throw new java.lang.NullPointerException("a cannot be null");
|
||||
}
|
||||
if (this.a == null) this.a = new java.util.ArrayList<String>();
|
||||
this.a.addAll(a);
|
||||
return this;
|
||||
}
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder clearA() {
|
||||
if (this.a != null) this.a.clear();
|
||||
return this;
|
||||
}
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder setyField(final String yField) {
|
||||
if (this.aField == null) this.aField = new java.util.ArrayList<String>();
|
||||
this.aField.add(yField);
|
||||
return this;
|
||||
}
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder setaField(final java.util.Collection<? extends String> aField) {
|
||||
if (aField == null) {
|
||||
throw new java.lang.NullPointerException("aField cannot be null");
|
||||
}
|
||||
if (this.aField == null) this.aField = new java.util.ArrayList<String>();
|
||||
this.aField.addAll(aField);
|
||||
return this;
|
||||
}
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder clearaField() {
|
||||
if (this.aField != null) this.aField.clear();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @return {@code this}.
|
||||
*/
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder setbField(final String bField) {
|
||||
this.bField = bField;
|
||||
return this;
|
||||
}
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public BuilderWithJavaBeansSpecCapitalization build() {
|
||||
java.util.List<String> a;
|
||||
switch (this.a == null ? 0 : this.a.size()) {
|
||||
case 0:
|
||||
a = java.util.Collections.emptyList();
|
||||
break;
|
||||
case 1:
|
||||
a = java.util.Collections.singletonList(this.a.get(0));
|
||||
break;
|
||||
default:
|
||||
a = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(this.a));
|
||||
}
|
||||
java.util.List<String> aField;
|
||||
switch (this.aField == null ? 0 : this.aField.size()) {
|
||||
case 0:
|
||||
aField = java.util.Collections.emptyList();
|
||||
break;
|
||||
case 1:
|
||||
aField = java.util.Collections.singletonList(this.aField.get(0));
|
||||
break;
|
||||
default:
|
||||
aField = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(this.aField));
|
||||
}
|
||||
return new BuilderWithJavaBeansSpecCapitalization(a, aField, this.bField);
|
||||
}
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public java.lang.String toString() {
|
||||
return "BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder(a=" + this.a + ", aField=" + this.aField + ", bField=" + this.bField + ")";
|
||||
}
|
||||
}
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public static BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder builder() {
|
||||
return new BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
//version 8:
|
||||
import lombok.NonNull;
|
||||
|
||||
public class ConstructorsInAnonymousClass {
|
||||
Object annonymous = new Object() {
|
||||
|
||||
class Inner {
|
||||
private String string;
|
||||
@NonNull
|
||||
private String string2;
|
||||
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public Inner(final String string, @NonNull final String string2) {
|
||||
if (string2 == null) {
|
||||
throw new java.lang.NullPointerException("string2 is marked non-null but is null");
|
||||
}
|
||||
this.string = string;
|
||||
this.string2 = string2;
|
||||
}
|
||||
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public Inner(@NonNull final String string2) {
|
||||
if (string2 == null) {
|
||||
throw new java.lang.NullPointerException("string2 is marked non-null but is null");
|
||||
}
|
||||
this.string2 = string2;
|
||||
}
|
||||
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public Inner() {
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
public class DataInAnonymousClass {
|
||||
Object annonymous = new Object() {
|
||||
|
||||
class Inner {
|
||||
private String string;
|
||||
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public Inner() {
|
||||
}
|
||||
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public String getString() {
|
||||
return this.string;
|
||||
}
|
||||
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public void setString(final String string) {
|
||||
this.string = string;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public boolean equals(final java.lang.Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof Inner)) return false;
|
||||
final Inner other = (Inner) o;
|
||||
if (!other.canEqual((java.lang.Object) this)) return false;
|
||||
final java.lang.Object this$string = this.getString();
|
||||
final java.lang.Object other$string = other.getString();
|
||||
if (this$string == null ? other$string != null : !this$string.equals(other$string)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@java.lang.SuppressWarnings("all")
|
||||
protected boolean canEqual(final java.lang.Object other) {
|
||||
return other instanceof Inner;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public int hashCode() {
|
||||
final int PRIME = 59;
|
||||
int result = 1;
|
||||
final java.lang.Object $string = this.getString();
|
||||
result = result * PRIME + ($string == null ? 43 : $string.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public java.lang.String toString() {
|
||||
return "Inner(string=" + this.getString() + ")";
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
public class EqualsAndHashCodeInAnonymousClass {
|
||||
Object annonymous = new Object() {
|
||||
|
||||
class Inner {
|
||||
private String string;
|
||||
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public boolean equals(final java.lang.Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof Inner)) return false;
|
||||
final Inner other = (Inner) o;
|
||||
if (!other.canEqual((java.lang.Object) this)) return false;
|
||||
final java.lang.Object this$string = this.string;
|
||||
final java.lang.Object other$string = other.string;
|
||||
if (this$string == null ? other$string != null : !this$string.equals(other$string)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@java.lang.SuppressWarnings("all")
|
||||
protected boolean canEqual(final java.lang.Object other) {
|
||||
return other instanceof Inner;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public int hashCode() {
|
||||
final int PRIME = 59;
|
||||
int result = 1;
|
||||
final java.lang.Object $string = this.string;
|
||||
result = result * PRIME + ($string == null ? 43 : $string.hashCode());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
// version 14:
|
||||
public record FieldDefaultsViaConfigOnRecord(String a, String b) {
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
public class FieldNameConstantsInAnonymousClass {
|
||||
Object annonymous = new Object() {
|
||||
|
||||
class Inner {
|
||||
private String string;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
public class GetterInAnonymousClass {
|
||||
Object annonymous = new Object() {
|
||||
|
||||
class Inner {
|
||||
private String string;
|
||||
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public String getString() {
|
||||
return this.string;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
public class GetterLazyInAnonymousClass {
|
||||
Object annonymous = new Object() {
|
||||
|
||||
class Inner {
|
||||
private final java.util.concurrent.atomic.AtomicReference<java.lang.Object> string = new java.util.concurrent.atomic.AtomicReference<java.lang.Object>();
|
||||
|
||||
@java.lang.SuppressWarnings({"all", "unchecked"})
|
||||
public String getString() {
|
||||
java.lang.Object value = this.string.get();
|
||||
if (value == null) {
|
||||
synchronized (this.string) {
|
||||
value = this.string.get();
|
||||
if (value == null) {
|
||||
final String actualValue = "test";
|
||||
value = actualValue == null ? this.string : actualValue;
|
||||
this.string.set(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return (String) (value == this.string ? null : value);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
class GetterWithJavaBeansSpecCapitalization {
|
||||
int a;
|
||||
int aField;
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public int getA() {
|
||||
return this.a;
|
||||
}
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public int getaField() {
|
||||
return this.aField;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
public class LoggerSlf4jInAnonymousClass {
|
||||
Object annonymous = new Object() {
|
||||
|
||||
class Inner {
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
public class SetterInAnonymousClass {
|
||||
Object annonymous = new Object() {
|
||||
|
||||
class Inner {
|
||||
private String string;
|
||||
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public void setString(final String string) {
|
||||
this.string = string;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
class SetterWithJavaBeansSpecCapitalization {
|
||||
int a;
|
||||
int aField;
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public void setA(final int a) {
|
||||
this.a = a;
|
||||
}
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public void setaField(final int aField) {
|
||||
this.aField = aField;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
public class SuperBuilderInAnonymousClass {
|
||||
Object annonymous = new Object() {
|
||||
|
||||
class InnerParent {
|
||||
private String string;
|
||||
}
|
||||
|
||||
class InnerChild {
|
||||
private String string;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
public class SynchronizedInAnonymousClass {
|
||||
Object annonymous = new Object() {
|
||||
|
||||
class Inner {
|
||||
@java.lang.SuppressWarnings("all")
|
||||
private final java.lang.Object $lock = new java.lang.Object[0];
|
||||
|
||||
public void foo() {
|
||||
synchronized (this.$lock) {
|
||||
String foo = "bar";
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
public class ToStringInAnonymousClass {
|
||||
Object annonymous = new Object() {
|
||||
|
||||
class Inner {
|
||||
private String string;
|
||||
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public java.lang.String toString() {
|
||||
return "Inner(string=" + this.string + ")";
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
public class UtilityClassInAnonymousClass {
|
||||
Object annonymous = new Object() {
|
||||
|
||||
class Inner {
|
||||
private String string;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ValAnonymousSubclassSelfReference {
|
||||
public <T> void test(T arg) {
|
||||
T d = arg;
|
||||
Integer[] e = new Integer[1];
|
||||
int[] f = new int[0];
|
||||
java.util.Map<java.lang.String, Integer> g = new HashMap<String, Integer>();
|
||||
Integer h = 0;
|
||||
int i = 0;
|
||||
final int j = 1;
|
||||
final int k = 2;
|
||||
new ValAnonymousSubclassSelfReference() {
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
public class ValInvalidParameter {
|
||||
public void val() {
|
||||
final java.lang.Object a = a(new NonExistingClass());
|
||||
final java.lang.Object b = a(a(new NonExistingClass()));
|
||||
final java.lang.Object c = nonExisitingMethod(b(1));
|
||||
final java.lang.Object d = nonExistingObject.nonExistingMethod();
|
||||
final java.lang.Object e = b(1).nonExistingMethod();
|
||||
final java.lang.Object f = 1 > 2 ? a(new NonExistingClass()) : a(new NonExistingClass());
|
||||
final java.lang.Object g = b2(1);
|
||||
final java.lang.Integer h = b2(a("a"), a(null));
|
||||
final int i = a(a(null));
|
||||
}
|
||||
|
||||
public int a(String param) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int a(Integer param) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Integer b(int i) {
|
||||
return i;
|
||||
}
|
||||
|
||||
public Integer b2(int i, int j) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
// version 14:
|
||||
public class ValSwitchExpression {
|
||||
public void method(int arg) {
|
||||
final int x = switch (arg) {
|
||||
final var x = switch (arg) {
|
||||
default -> {
|
||||
final java.lang.String s = "string";
|
||||
final var s = "string";
|
||||
yield arg;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
// version 10:
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ValToNative {
|
||||
private void test() throws IOException {
|
||||
final var intField = 1;
|
||||
for (final var s : Arrays.asList("1")) {
|
||||
final var s2 = s;
|
||||
}
|
||||
try (var in = getClass().getResourceAsStream("ValToNative.class")) {
|
||||
final var j = in.read();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
public class ValueInAnonymousClass {
|
||||
Object annonymous = new Object() {
|
||||
|
||||
final class Inner {
|
||||
private final String string;
|
||||
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public Inner(final String string) {
|
||||
this.string = string;
|
||||
}
|
||||
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public String getString() {
|
||||
return this.string;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public boolean equals(final java.lang.Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof Inner)) return false;
|
||||
final Inner other = (Inner) o;
|
||||
final java.lang.Object this$string = this.getString();
|
||||
final java.lang.Object other$string = other.getString();
|
||||
if (this$string == null ? other$string != null : !this$string.equals(other$string)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public int hashCode() {
|
||||
final int PRIME = 59;
|
||||
int result = 1;
|
||||
final java.lang.Object $string = this.getString();
|
||||
result = result * PRIME + ($string == null ? 43 : $string.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public java.lang.String toString() {
|
||||
return "Inner(string=" + this.getString() + ")";
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
final class ValueWithJavaBeansSpecCapitalization {
|
||||
private final int aField;
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public ValueWithJavaBeansSpecCapitalization(final int aField) {
|
||||
this.aField = aField;
|
||||
}
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public int getaField() {
|
||||
return this.aField;
|
||||
}
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public boolean equals(final java.lang.Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof ValueWithJavaBeansSpecCapitalization)) return false;
|
||||
final ValueWithJavaBeansSpecCapitalization other = (ValueWithJavaBeansSpecCapitalization) o;
|
||||
if (this.getaField() != other.getaField()) return false;
|
||||
return true;
|
||||
}
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public int hashCode() {
|
||||
final int PRIME = 59;
|
||||
int result = 1;
|
||||
result = result * PRIME + this.getaField();
|
||||
return result;
|
||||
}
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public java.lang.String toString() {
|
||||
return "ValueWithJavaBeansSpecCapitalization(aField=" + this.getaField() + ")";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
//version 8:
|
||||
public class WithByInAnonymousClass {
|
||||
Object annonymous = new Object() {
|
||||
|
||||
class Inner {
|
||||
private Inner(String string) {
|
||||
}
|
||||
|
||||
private String string;
|
||||
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public Inner withStringBy(final java.util.function.Function<? super String, ? extends String> transformer) {
|
||||
return new Inner(transformer.apply(this.string));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
public class WithInAnonymousClass {
|
||||
Object annonymous = new Object() {
|
||||
|
||||
class Inner {
|
||||
private Inner(String string) {
|
||||
}
|
||||
|
||||
private String string;
|
||||
|
||||
/**
|
||||
* @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 Inner withString(final String string) {
|
||||
return this.string == string ? this : new Inner(string);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
class WithWithJavaBeansSpecCapitalization {
|
||||
int aField;
|
||||
WithWithJavaBeansSpecCapitalization(int aField) {
|
||||
}
|
||||
/**
|
||||
* @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 WithWithJavaBeansSpecCapitalization withaField(final int aField) {
|
||||
return this.aField == aField ? this : new WithWithJavaBeansSpecCapitalization(aField);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
public class AccessorsInAnonymousClass {
|
||||
Object annonymous = new Object() {
|
||||
@Getter @Setter @Accessors(fluent = true) class Inner {
|
||||
private String string;
|
||||
Inner() {
|
||||
super();
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") String string() {
|
||||
return this.string;
|
||||
}
|
||||
/**
|
||||
* @return {@code this}.
|
||||
*/
|
||||
public @java.lang.SuppressWarnings("all") Inner string(final String string) {
|
||||
this.string = string;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
x() {
|
||||
super();
|
||||
}
|
||||
};
|
||||
public AccessorsInAnonymousClass() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import lombok.Builder;
|
||||
public class BuilderInAnonymousClass {
|
||||
Object annonymous = new Object() {
|
||||
@Builder class Inner {
|
||||
private String string;
|
||||
Inner() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
x() {
|
||||
super();
|
||||
}
|
||||
};
|
||||
public BuilderInAnonymousClass() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
class BuilderNestedInEnum {
|
||||
public enum TestEnum {
|
||||
public static final @lombok.Builder @lombok.Value class TestBuilder {
|
||||
public static @java.lang.SuppressWarnings("all") class TestBuilderBuilder {
|
||||
private @java.lang.SuppressWarnings("all") String field;
|
||||
@java.lang.SuppressWarnings("all") TestBuilderBuilder() {
|
||||
super();
|
||||
}
|
||||
/**
|
||||
* @return {@code this}.
|
||||
*/
|
||||
public @java.lang.SuppressWarnings("all") BuilderNestedInEnum.TestEnum.TestBuilder.TestBuilderBuilder field(final String field) {
|
||||
this.field = field;
|
||||
return this;
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") BuilderNestedInEnum.TestEnum.TestBuilder build() {
|
||||
return new BuilderNestedInEnum.TestEnum.TestBuilder(this.field);
|
||||
}
|
||||
public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
|
||||
return (("BuilderNestedInEnum.TestEnum.TestBuilder.TestBuilderBuilder(field=" + this.field) + ")");
|
||||
}
|
||||
}
|
||||
private final String field;
|
||||
@java.lang.SuppressWarnings("all") TestBuilder(final String field) {
|
||||
super();
|
||||
this.field = field;
|
||||
}
|
||||
public static @java.lang.SuppressWarnings("all") BuilderNestedInEnum.TestEnum.TestBuilder.TestBuilderBuilder builder() {
|
||||
return new BuilderNestedInEnum.TestEnum.TestBuilder.TestBuilderBuilder();
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") String getField() {
|
||||
return this.field;
|
||||
}
|
||||
public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) {
|
||||
if ((o == this))
|
||||
return true;
|
||||
if ((! (o instanceof BuilderNestedInEnum.TestEnum.TestBuilder)))
|
||||
return false;
|
||||
final BuilderNestedInEnum.TestEnum.TestBuilder other = (BuilderNestedInEnum.TestEnum.TestBuilder) o;
|
||||
final java.lang.Object this$field = this.getField();
|
||||
final java.lang.Object other$field = other.getField();
|
||||
if (((this$field == null) ? (other$field != null) : (! this$field.equals(other$field))))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
|
||||
final int PRIME = 59;
|
||||
int result = 1;
|
||||
final java.lang.Object $field = this.getField();
|
||||
result = ((result * PRIME) + (($field == null) ? 43 : $field.hashCode()));
|
||||
return result;
|
||||
}
|
||||
public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
|
||||
return (("BuilderNestedInEnum.TestEnum.TestBuilder(field=" + this.getField()) + ")");
|
||||
}
|
||||
}
|
||||
FOO(),
|
||||
BAR(),
|
||||
<clinit>() {
|
||||
}
|
||||
public TestEnum() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
BuilderNestedInEnum() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
@lombok.Builder(setterPrefix = "set") class BuilderWithJavaBeansSpecCapitalization {
|
||||
public static @java.lang.SuppressWarnings("all") class BuilderWithJavaBeansSpecCapitalizationBuilder {
|
||||
private @java.lang.SuppressWarnings("all") java.util.ArrayList<String> a;
|
||||
private @java.lang.SuppressWarnings("all") java.util.ArrayList<String> aField;
|
||||
private @java.lang.SuppressWarnings("all") String bField;
|
||||
@java.lang.SuppressWarnings("all") BuilderWithJavaBeansSpecCapitalizationBuilder() {
|
||||
super();
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder setZ(final String z) {
|
||||
if ((this.a == null))
|
||||
this.a = new java.util.ArrayList<String>();
|
||||
this.a.add(z);
|
||||
return this;
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder setA(final java.util.Collection<? extends String> a) {
|
||||
if ((a == null))
|
||||
{
|
||||
throw new java.lang.NullPointerException("a cannot be null");
|
||||
}
|
||||
if ((this.a == null))
|
||||
this.a = new java.util.ArrayList<String>();
|
||||
this.a.addAll(a);
|
||||
return this;
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder clearA() {
|
||||
if ((this.a != null))
|
||||
this.a.clear();
|
||||
return this;
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder setyField(final String yField) {
|
||||
if ((this.aField == null))
|
||||
this.aField = new java.util.ArrayList<String>();
|
||||
this.aField.add(yField);
|
||||
return this;
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder setaField(final java.util.Collection<? extends String> aField) {
|
||||
if ((aField == null))
|
||||
{
|
||||
throw new java.lang.NullPointerException("aField cannot be null");
|
||||
}
|
||||
if ((this.aField == null))
|
||||
this.aField = new java.util.ArrayList<String>();
|
||||
this.aField.addAll(aField);
|
||||
return this;
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder clearaField() {
|
||||
if ((this.aField != null))
|
||||
this.aField.clear();
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @return {@code this}.
|
||||
*/
|
||||
public @java.lang.SuppressWarnings("all") BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder setbField(final String bField) {
|
||||
this.bField = bField;
|
||||
return this;
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") BuilderWithJavaBeansSpecCapitalization build() {
|
||||
java.util.List<String> a;
|
||||
switch (((this.a == null) ? 0 : this.a.size())) {
|
||||
case 0 :
|
||||
a = java.util.Collections.emptyList();
|
||||
break;
|
||||
case 1 :
|
||||
a = java.util.Collections.singletonList(this.a.get(0));
|
||||
break;
|
||||
default :
|
||||
a = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(this.a));
|
||||
}
|
||||
java.util.List<String> aField;
|
||||
switch (((this.aField == null) ? 0 : this.aField.size())) {
|
||||
case 0 :
|
||||
aField = java.util.Collections.emptyList();
|
||||
break;
|
||||
case 1 :
|
||||
aField = java.util.Collections.singletonList(this.aField.get(0));
|
||||
break;
|
||||
default :
|
||||
aField = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(this.aField));
|
||||
}
|
||||
return new BuilderWithJavaBeansSpecCapitalization(a, aField, this.bField);
|
||||
}
|
||||
public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
|
||||
return (((((("BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder(a=" + this.a) + ", aField=") + this.aField) + ", bField=") + this.bField) + ")");
|
||||
}
|
||||
}
|
||||
@lombok.Singular("z") java.util.List<String> a;
|
||||
@lombok.Singular("yField") java.util.List<String> aField;
|
||||
String bField;
|
||||
@java.lang.SuppressWarnings("all") BuilderWithJavaBeansSpecCapitalization(final java.util.List<String> a, final java.util.List<String> aField, final String bField) {
|
||||
super();
|
||||
this.a = a;
|
||||
this.aField = aField;
|
||||
this.bField = bField;
|
||||
}
|
||||
public static @java.lang.SuppressWarnings("all") BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder builder() {
|
||||
return new BuilderWithJavaBeansSpecCapitalization.BuilderWithJavaBeansSpecCapitalizationBuilder();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
public class ConstructorsInAnonymousClass {
|
||||
Object annonymous = new Object() {
|
||||
@AllArgsConstructor @RequiredArgsConstructor @NoArgsConstructor class Inner {
|
||||
private String string;
|
||||
private @NonNull String string2;
|
||||
public @java.lang.SuppressWarnings("all") Inner(final String string, final @NonNull String string2) {
|
||||
super();
|
||||
if ((string2 == null))
|
||||
{
|
||||
throw new java.lang.NullPointerException("string2 is marked non-null but is null");
|
||||
}
|
||||
this.string = string;
|
||||
this.string2 = string2;
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") Inner(final @NonNull String string2) {
|
||||
super();
|
||||
if ((string2 == null))
|
||||
{
|
||||
throw new java.lang.NullPointerException("string2 is marked non-null but is null");
|
||||
}
|
||||
this.string2 = string2;
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") Inner() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
x() {
|
||||
super();
|
||||
}
|
||||
};
|
||||
public ConstructorsInAnonymousClass() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import lombok.Data;
|
||||
public class DataInAnonymousClass {
|
||||
Object annonymous = new Object() {
|
||||
@Data class Inner {
|
||||
private String string;
|
||||
public @java.lang.SuppressWarnings("all") String getString() {
|
||||
return this.string;
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") void setString(final String string) {
|
||||
this.string = string;
|
||||
}
|
||||
public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) {
|
||||
if ((o == this))
|
||||
return true;
|
||||
if ((! (o instanceof Inner)))
|
||||
return false;
|
||||
final Inner other = (Inner) o;
|
||||
if ((! other.canEqual((java.lang.Object) this)))
|
||||
return false;
|
||||
final java.lang.Object this$string = this.getString();
|
||||
final java.lang.Object other$string = other.getString();
|
||||
if (((this$string == null) ? (other$string != null) : (! this$string.equals(other$string))))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
|
||||
return (other instanceof Inner);
|
||||
}
|
||||
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
|
||||
final int PRIME = 59;
|
||||
int result = 1;
|
||||
final java.lang.Object $string = this.getString();
|
||||
result = ((result * PRIME) + (($string == null) ? 43 : $string.hashCode()));
|
||||
return result;
|
||||
}
|
||||
public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
|
||||
return (("Inner(string=" + this.getString()) + ")");
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") Inner() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
x() {
|
||||
super();
|
||||
}
|
||||
};
|
||||
public DataInAnonymousClass() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import lombok.EqualsAndHashCode;
|
||||
public class EqualsAndHashCodeInAnonymousClass {
|
||||
Object annonymous = new Object() {
|
||||
@EqualsAndHashCode class Inner {
|
||||
private String string;
|
||||
Inner() {
|
||||
super();
|
||||
}
|
||||
public @java.lang.Override @java.lang.SuppressWarnings("all") boolean equals(final java.lang.Object o) {
|
||||
if ((o == this))
|
||||
return true;
|
||||
if ((! (o instanceof Inner)))
|
||||
return false;
|
||||
final Inner other = (Inner) o;
|
||||
if ((! other.canEqual((java.lang.Object) this)))
|
||||
return false;
|
||||
final java.lang.Object this$string = this.string;
|
||||
final java.lang.Object other$string = other.string;
|
||||
if (((this$string == null) ? (other$string != null) : (! this$string.equals(other$string))))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
protected @java.lang.SuppressWarnings("all") boolean canEqual(final java.lang.Object other) {
|
||||
return (other instanceof Inner);
|
||||
}
|
||||
public @java.lang.Override @java.lang.SuppressWarnings("all") int hashCode() {
|
||||
final int PRIME = 59;
|
||||
int result = 1;
|
||||
final java.lang.Object $string = this.string;
|
||||
result = ((result * PRIME) + (($string == null) ? 43 : $string.hashCode()));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
x() {
|
||||
super();
|
||||
}
|
||||
};
|
||||
public EqualsAndHashCodeInAnonymousClass() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
Loaded 100 of 196 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user