aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--buildScripts/website.ant.xml25
-rw-r--r--doc/changelog.markdown10
-rw-r--r--src/core/lombok/Builder.java2
-rw-r--r--src/core/lombok/EqualsAndHashCode.java9
-rw-r--r--src/core/lombok/NonNull.java13
-rw-r--r--src/core/lombok/ToString.java15
-rwxr-xr-xsrc/core/lombok/core/AST.java11
-rw-r--r--src/core/lombok/core/CleanupRegistry.java4
-rw-r--r--src/core/lombok/core/LombokNode.java9
-rw-r--r--src/core/lombok/core/configuration/NullCheckExceptionType.java24
-rw-r--r--src/core/lombok/core/handlers/HandlerUtil.java8
-rw-r--r--src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java53
-rwxr-xr-xsrc/core/lombok/eclipse/handlers/HandleBuilder.java26
-rw-r--r--src/core/lombok/eclipse/handlers/HandleNonNull.java37
-rwxr-xr-xsrc/core/lombok/eclipse/handlers/HandleSuperBuilder.java27
-rw-r--r--src/core/lombok/experimental/FieldNameConstants.java2
-rw-r--r--src/core/lombok/experimental/SuperBuilder.java2
-rw-r--r--src/core/lombok/javac/handlers/HandleBuilder.java26
-rw-r--r--src/core/lombok/javac/handlers/HandleNonNull.java25
-rw-r--r--src/core/lombok/javac/handlers/HandleSuperBuilder.java23
-rw-r--r--src/core/lombok/javac/handlers/JavacHandlerUtil.java69
-rwxr-xr-xsrc/delombok/lombok/delombok/Delombok.java1
-rw-r--r--src/delombok/lombok/delombok/PrettyPrinter.java6
-rw-r--r--test/pretty/resource/after/Java11Var.javva6
-rw-r--r--test/pretty/resource/before/Java11Var.java7
-rw-r--r--test/transform/resource/after-delombok/BuilderSingularAnnotatedTypes.java6
-rw-r--r--test/transform/resource/after-delombok/BuilderWithNoBuilderMethod.java33
-rw-r--r--test/transform/resource/after-delombok/ConstructorsWithAccessors.java8
-rw-r--r--test/transform/resource/after-delombok/DataOnLocalClass.java4
-rw-r--r--test/transform/resource/after-delombok/NonNullOnParameter.java22
-rw-r--r--test/transform/resource/after-delombok/NonNullOnParameterAbstract.java2
-rw-r--r--test/transform/resource/after-delombok/NonNullOnParameterOfDefaultMethod.java2
-rw-r--r--test/transform/resource/after-delombok/NonNullPlain.java4
-rw-r--r--test/transform/resource/after-delombok/NonNullTypeUse.java10
-rw-r--r--test/transform/resource/after-delombok/NonNullWithAlternateException.java4
-rw-r--r--test/transform/resource/after-delombok/NonNullWithAssertion.java16
-rw-r--r--test/transform/resource/after-delombok/NonNullWithSneakyThrows.java2
-rw-r--r--test/transform/resource/after-delombok/SetterOnClass.java2
-rw-r--r--test/transform/resource/after-delombok/SuperBuilderSingularAnnotatedTypes.java6
-rw-r--r--test/transform/resource/after-delombok/SuperBuilderWithNonNull.java8
-rw-r--r--test/transform/resource/after-delombok/WitherOnClass.java2
-rw-r--r--test/transform/resource/after-ecj/BuilderSingularAnnotatedTypes.java6
-rw-r--r--test/transform/resource/after-ecj/BuilderWithNoBuilderMethod.java27
-rw-r--r--test/transform/resource/after-ecj/ConstructorsWithAccessors.java8
-rw-r--r--test/transform/resource/after-ecj/DataOnLocalClass.java4
-rw-r--r--test/transform/resource/after-ecj/NonNullOnParameter.java24
-rw-r--r--test/transform/resource/after-ecj/NonNullOnParameterAbstract.java2
-rw-r--r--test/transform/resource/after-ecj/NonNullOnParameterOfDefaultMethod.java2
-rw-r--r--test/transform/resource/after-ecj/NonNullPlain.java4
-rw-r--r--test/transform/resource/after-ecj/NonNullTypeUse.java10
-rw-r--r--test/transform/resource/after-ecj/NonNullWithAlternateException.java4
-rw-r--r--test/transform/resource/after-ecj/NonNullWithAssertion.java18
-rw-r--r--test/transform/resource/after-ecj/NonNullWithSneakyThrows.java2
-rw-r--r--test/transform/resource/after-ecj/SetterOnClass.java2
-rw-r--r--test/transform/resource/after-ecj/SuperBuilderSingularAnnotatedTypes.java6
-rw-r--r--test/transform/resource/after-ecj/SuperBuilderWithNonNull.java4
-rw-r--r--test/transform/resource/after-ecj/WitherOnClass.java2
-rw-r--r--test/transform/resource/before/BuilderWithNoBuilderMethod.java5
-rw-r--r--test/transform/resource/before/NonNullOnParameter.java9
-rw-r--r--test/transform/resource/before/NonNullWithAssertion.java13
-rw-r--r--test/transform/resource/messages-delombok/BuilderDefaultsWarnings.java.messages2
-rw-r--r--website/resources/css/custom.css7
-rw-r--r--website/templates/features/Builder.html9
-rw-r--r--website/templates/features/NonNull.html6
-rw-r--r--website/templates/features/configuration.html2
-rw-r--r--website/templates/features/var.html2
66 files changed, 537 insertions, 214 deletions
diff --git a/buildScripts/website.ant.xml b/buildScripts/website.ant.xml
index 7fbd911e..62cb9a44 100644
--- a/buildScripts/website.ant.xml
+++ b/buildScripts/website.ant.xml
@@ -281,21 +281,21 @@ such as applying the templates to produce the website, converting the changelog
<property name="javadoc.overview.html" location="build/javadoc.overview.html" />
<echo file="${javadoc.overview.html}"><![CDATA[<html><body>
Welcome to the lombok javadoc.&nbsp;If you're just looking to learn more about using lombok
- You probably want to look at <a href="https://projectlombok.org/features/index.html">the feature documentation</a>.&nbsp;Otherwise,
+ You probably want to look at <a href="https://projectlombok.org/features/all">the feature documentation</a>.&nbsp;Otherwise,
check the <a href="lombok/package-summary.html">lombok</a> package.&nbsp;If you're trying to extend lombok or
write your own plugins, the other packages are what you're looking for.</body></html>
]]></echo>
- <javadoc sourcepath="src/core" defaultexcludes="yes" destdir="build/api" windowtitle="Lombok" Overview="${javadoc.overview.html}">
+ <javadoc sourcepath="src/core" defaultexcludes="yes" destdir="build/api" windowtitle="Lombok" source="1.8" Overview="${javadoc.overview.html}">
<package name="lombok" />
<package name="lombok.experimental" />
<package name="lombok.extern.*" />
<classpath refid="build.path" />
<classpath location="build/lombok" />
<header><![CDATA[<a href='https://projectlombok.org/' target='_blank'>Lombok</a> - ]]>v${lombok.version}</header>
- <bottom><![CDATA[<i>Copyright &copy; 2009-2018 The Project Lombok Authors, licensed under the <a href='http://www.opensource.org/licenses/mit-license.php' target='_blank'>MIT licence</a>.]]></bottom>
+ <bottom><![CDATA[<i>Copyright &copy; 2009-2019 The Project Lombok Authors, licensed under the <a href='http://www.opensource.org/licenses/mit-license.php' target='_blank'>MIT licence</a>.]]></bottom>
</javadoc>
<!-- bugfix for boneheaded javadoc bug where ?is-external=true is inserted before an anchor ref, breaking the anchor ref.
- is-external=true doesn't actually do anything, so, we'll just get rid of it. -->
+ is-external=true doesn't actually do anything except mess with titles, so, we'll just get rid of it. -->
<replaceregexp match="\?is-external=true#" replace="#" flags="gi">
<fileset dir="build/api" includes="**/*.html" />
</replaceregexp>
@@ -304,12 +304,25 @@ such as applying the templates to produce the website, converting the changelog
<fileset dir="build/api" includes="**/*.html" />
<filterchain>
<linecontainsregexp negate="true">
- <regexp pattern="(Generated by javadoc)|(.META NAME=.date.)" />
+ <regexp pattern="(Generated by javadoc)|(.META NAME=.date.)|(meta name=.dc.created.)" />
</linecontainsregexp>
</filterchain>
</copy>
<copy todir="doc/api">
- <fileset dir="build/api" excludes="**/*.html" />
+ <fileset dir="build/api" includes="**/*.css" />
+ <filterchain>
+ <linecontainsregexp negate="true">
+ <regexp pattern="@import.*dejavu.css.*" />
+ </linecontainsregexp>
+ </filterchain>
+ </copy>
+ <copy todir="doc/api">
+ <fileset dir="build/api">
+ <exclude name="**/*.html" />
+ <exclude name="**/*.css" />
+ </fileset>
</copy>
+ <echo append="true" file="doc/api/module-search-index.js"></echo>
+ <echo append="true" file="doc/api/tag-search-index.js"></echo>
</target>
</project>
diff --git a/doc/changelog.markdown b/doc/changelog.markdown
index 26ad3dcb..64ddcc7f 100644
--- a/doc/changelog.markdown
+++ b/doc/changelog.markdown
@@ -2,7 +2,13 @@ Lombok Changelog
----------------
### v1.18.7 "Edgy Guinea Pig"
-* BUGFIX: var/val on methods that return an intersection type would now work in Eclipse [Issue #1986](https://github.com/rzwitserloot/lombok/issues/1986)
+* FEATURE: You can now suppress generation of the `builder` method when using `@Builder`; usually because you're only interested in the `toBuilder` method. As a convenience we won't emit warnings about missing `@Builder.Default` annotations when you do this. [Issue #2046](https://github.com/rzwitserloot/lombok/issues/2046)
+* FEATURE: When using `@NonNull`, or any other annotation that would result in a null-check, you can configure to generate an assert statement instead. [Issue #2078](https://github.com/rzwitserloot/lombok/issues/2078).
+* BUGFIX: var/val on methods that return an intersection type would now work in Eclipse. [Issue #1986](https://github.com/rzwitserloot/lombok/issues/1986)
+* BUGFIX: Fix for java6 regression if a field has javadoc. [Issue #2066](https://github.com/rzwitserloot/lombok/issues/2066)
+* BUGFIX: Delombok now delomboks java10's own `var` as `var` and not as the actual underlying type. [Issue #2049](https://github.com/rzwitserloot/lombok/issues/2049)
+* BUGFIX: If you use `@Builder` and manually write the `build()` method in your builder class, javac would error out instead of deferring to your implementation. [Issue #2050](https://github.com/rzwitserloot/lombok/issues/2050) [Issue #2061](https://github.com/rzwitserloot/lombok/issues/2061)
+* IMPROBABLE BREAKING CHANGE: For fields and parameters marked non-null, if the method body starts with an assert statement to ensure the value isn't null, no code to throw an exception will be generated.
### v1.18.6 (February 12th, 2019)
* FEATURE: Javadoc on fields will now also be copied to the Builders' setters. Thanks for the contribution, Emil Lundberg. [Issue #2008](https://github.com/rzwitserloot/lombok/issues/2008)
@@ -32,7 +38,6 @@ Lombok Changelog
* BUGFIX: Fix NetBeans compile on save. [Issue #1770](https://github.com/rzwitserloot/lombok/issues/1770)
* BUGFIX: If you manually write your builder class so you can add a few methods of your own, and those methods refer to generated methods, you'd usually run into various bizarre error messages, but only on JDK9/10/11. This one is hard to describe, but we fixed it. [Issue #1907](https://github.com/rzwitserloot/lombok/issues/1907)
-
### v1.18.2 (July 26th, 2018)
* BUGFIX: mapstruct + lombok in eclipse should hopefully work again. [Issue #1359](https://github.com/rzwitserloot/lombok/issues/1359) and [mapstruct issue #1159](https://github.com/mapstruct/mapstruct/issues/1159)
* BUGFIX: Equals and hashCode again exclude transient fields by default. [Issue #1724](https://github.com/rzwitserloot/lombok/issues/1724)
@@ -40,6 +45,7 @@ Lombok Changelog
* BUGFIX: Lombok and gradle v4.9 didn't work together; that's been fixed. [Issue #1716](https://github.com/rzwitserloot/lombok/issues/1716) and [gradle-apt-plugin issue #87](https://github.com/tbroyer/gradle-apt-plugin/issues/87)
* FEATURE: You can now make builders for type hierarchies, using the new (experimental) `@SuperBuilder` annotation. Thanks for the contribution, Jan Rieke. [`@SuperBuilder` documentation](https://projectlombok.org/features/experimental/SuperBuilder)
* FEATURE: `@NoArgsConstructor`, including forcing one with `lombok.config: lombok.noArgsConstructor.extraPrivate=true` now take any defaults set with `@Builder.Default` into account. [Issue #1347](https://github.com/rzwitserloot/lombok/issues/1347)
+
### v1.18.0 (June 5th, 2018)
* BREAKING CHANGE: The in 1.16.22 introduced configuration key `lombok.noArgsConstructor.extraPrivate` is now `false` by default. [Issue #1708](https://github.com/rzwitserloot/lombok/issues/1708)
* BUGFIX: Do not generate a private no-args constructor if that breaks the code. [Issue #1703](https://github.com/rzwitserloot/lombok/issues/1703), [Issue #1704](https://github.com/rzwitserloot/lombok/issues/1704), [Issue #1712](https://github.com/rzwitserloot/lombok/issues/1712)
diff --git a/src/core/lombok/Builder.java b/src/core/lombok/Builder.java
index ea94eb4e..c83b3670 100644
--- a/src/core/lombok/Builder.java
+++ b/src/core/lombok/Builder.java
@@ -120,7 +120,7 @@ public @interface Builder {
@Retention(SOURCE)
public @interface Default {}
- /** @return Name of the method that creates a new builder instance. Default: {@code builder}. */
+ /** @return Name of the method that creates a new builder instance. Default: {@code builder}. If the empty string, suppress generating the {@code builder} method. */
String builderMethodName() default "builder";
/** @return Name of the method in the builder class that creates an instance of your {@code @Builder}-annotated class. */
diff --git a/src/core/lombok/EqualsAndHashCode.java b/src/core/lombok/EqualsAndHashCode.java
index b2fc672d..e752165c 100644
--- a/src/core/lombok/EqualsAndHashCode.java
+++ b/src/core/lombok/EqualsAndHashCode.java
@@ -97,6 +97,8 @@ public @interface EqualsAndHashCode {
/**
* Only include fields and methods explicitly marked with {@code @EqualsAndHashCode.Include}.
* Normally, all (non-static, non-transient) fields are included by default.
+ *
+ * @return If {@code true}, don't include non-static non-transient fields automatically (default: {@code false}).
*/
boolean onlyExplicitlyIncluded() default false;
@@ -113,7 +115,12 @@ public @interface EqualsAndHashCode {
@Target({ElementType.FIELD, ElementType.METHOD})
@Retention(RetentionPolicy.SOURCE)
public @interface Include {
- /** Defaults to the method name of the annotated member. If on a method and the name equals the name of a default-included field, this member takes its place. */
+ /**
+ * Defaults to the method name of the annotated member.
+ * If on a method and the name equals the name of a default-included field, this member takes its place.
+ *
+ * @return If present, this method serves as replacement for the named field.
+ */
String replaces() default "";
}
}
diff --git a/src/core/lombok/NonNull.java b/src/core/lombok/NonNull.java
index caf6ed05..ba8c24a4 100644
--- a/src/core/lombok/NonNull.java
+++ b/src/core/lombok/NonNull.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2013 The Project Lombok Authors.
+ * Copyright (C) 2009-2019 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -30,16 +30,7 @@ import java.lang.annotation.Target;
/**
* If put on a parameter, lombok will insert a null-check at the start of the method / constructor's body, throwing a
* {@code NullPointerException} with the parameter's name as message. If put on a field, any generated method assigning
- * a value to this field will also produce these nullchecks.
- * <p>
- * Note that any annotation named {@code NonNull} with any casing and any package will result in nullchecks produced for
- * generated methods (and the annotation will be copied to the getter return type and any parameters of generated methods),
- * but <em>only</em> this annotation, if present on a parameter, will result in a null check inserted into your otherwise
- * handwritten method.
- *
- * WARNING: If the java community ever does decide on supporting a single {@code @NonNull} annotation (for example via JSR305), then
- * this annotation will <strong>be deleted</strong> from the lombok package. If the need to update an import statement scares
- * you, you should use your own annotation named {@code @NonNull} instead of this one.
+ * a value to this field will also produce these null-checks.
*/
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE, ElementType.TYPE_USE})
@Retention(RetentionPolicy.CLASS)
diff --git a/src/core/lombok/ToString.java b/src/core/lombok/ToString.java
index ae3f071f..34418a2f 100644
--- a/src/core/lombok/ToString.java
+++ b/src/core/lombok/ToString.java
@@ -83,6 +83,8 @@ public @interface ToString {
/**
* Only include fields and methods explicitly marked with {@code @ToString.Include}.
* Normally, all (non-static) fields are included by default.
+ *
+ * @return If {@code true}, don't include non-static fields automatically (default: {@code false}).
*/
boolean onlyExplicitlyIncluded() default false;
@@ -102,10 +104,19 @@ public @interface ToString {
// /** If true and the return value is {@code null}, omit this member entirely from the {@code toString} output. */
// boolean skipNull() default false; // -- We'll add it later, it requires a complete rework on the toString code we generate.
- /** Higher ranks are printed first. Members of the same rank are printed in the order they appear in the source file. */
+ /**
+ * Higher ranks are printed first. Members of the same rank are printed in the order they appear in the source file.
+ *
+ * @return ordering within the generating {@code toString()}; higher numbers are printed first.
+ */
int rank() default 0;
- /** Defaults to the field / method name of the annotated member. If the name equals the name of a default-included field, this member takes its place. */
+ /**
+ * Defaults to the field / method name of the annotated member.
+ * If the name equals the name of a default-included field, this member takes its place.
+ *
+ * @return The name to show in the generated {@code toString()}. Also, if this annotation is on a method and the name matches an existing field, it replaces that field.
+ */
String name() default "";
}
}
diff --git a/src/core/lombok/core/AST.java b/src/core/lombok/core/AST.java
index 78761f46..9f3a471f 100755
--- a/src/core/lombok/core/AST.java
+++ b/src/core/lombok/core/AST.java
@@ -60,6 +60,7 @@ public abstract class AST<A extends AST<A, L, N>, L extends LombokNode<A, L, N>,
private final String fileName;
private final String packageDeclaration;
private final ImportList imports;
+ private TypeResolver importsAsResolver;
Map<N, N> identityDetector = new IdentityHashMap<N, N>();
private Map<N, L> nodeMap = new IdentityHashMap<N, L>();
private boolean changed = false;
@@ -112,14 +113,20 @@ public abstract class AST<A extends AST<A, L, N>, L extends LombokNode<A, L, N>,
/**
* Return the contents of each non-static import statement on this AST's top (Compilation Unit) node.
- *
- * Example: "java.util.IOException".
*/
public final ImportList getImportList() {
return imports;
}
/**
+ * Return the contents of each non-static import statement on this AST's top (Compilation Unit) node, packed into a (cached) TypeResolver.
+ */
+ public final TypeResolver getImportListAsTypeResolver() {
+ if (importsAsResolver != null) return importsAsResolver;
+ return importsAsResolver = new TypeResolver(getImportList());
+ }
+
+ /**
* Puts the given node in the map so that javac/Eclipse's own internal AST object can be translated to
* an AST.Node object. Also registers the object as visited to avoid endless loops.
*/
diff --git a/src/core/lombok/core/CleanupRegistry.java b/src/core/lombok/core/CleanupRegistry.java
index 82a52fdb..d6aee477 100644
--- a/src/core/lombok/core/CleanupRegistry.java
+++ b/src/core/lombok/core/CleanupRegistry.java
@@ -21,8 +21,8 @@
*/
package lombok.core;
-import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
public class CleanupRegistry {
private static final class CleanupKey {
@@ -48,7 +48,7 @@ public class CleanupRegistry {
}
}
- private final Map<CleanupKey, CleanupTask> tasks = new ConcurrentHashMap<CleanupKey, CleanupTask>();
+ private final ConcurrentMap<CleanupKey, CleanupTask> tasks = new ConcurrentHashMap<CleanupKey, CleanupTask>();
public void registerTask(String key, Object target, CleanupTask task) {
CleanupKey ck = new CleanupKey(key, target);
diff --git a/src/core/lombok/core/LombokNode.java b/src/core/lombok/core/LombokNode.java
index ae8fd325..843a78f0 100644
--- a/src/core/lombok/core/LombokNode.java
+++ b/src/core/lombok/core/LombokNode.java
@@ -97,6 +97,15 @@ public abstract class LombokNode<A extends AST<A, L, N>, L extends LombokNode<A,
}
/**
+ * Convenient shortcut to the owning ast object's {@code getImportListAsTypeResolver} method.
+ *
+ * @see AST#getImportListAsTypeResolver()
+ */
+ public TypeResolver getImportListAsTypeResolver() {
+ return getAst().getImportListAsTypeResolver();
+ }
+
+ /**
* See {@link #isStructurallySignificant}.
*/
protected abstract boolean calculateIsStructurallySignificant(N parent);
diff --git a/src/core/lombok/core/configuration/NullCheckExceptionType.java b/src/core/lombok/core/configuration/NullCheckExceptionType.java
index c4bb71f2..d226c0a8 100644
--- a/src/core/lombok/core/configuration/NullCheckExceptionType.java
+++ b/src/core/lombok/core/configuration/NullCheckExceptionType.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2014-2018 The Project Lombok Authors.
+ * Copyright (C) 2014-2019 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -22,27 +22,27 @@
package lombok.core.configuration;
-@ExampleValueString("[NullPointerException | IllegalArgumentException]")
+@ExampleValueString("[NullPointerException | IllegalArgumentException | Assertion]")
public enum NullCheckExceptionType {
ILLEGAL_ARGUMENT_EXCEPTION {
- public String toExceptionMessage(String fieldName) {
- return fieldName + " is marked @NonNull but is null";
- }
-
@Override public String getExceptionType() {
return "java.lang.IllegalArgumentException";
}
},
NULL_POINTER_EXCEPTION {
- @Override public String toExceptionMessage(String fieldName) {
- return fieldName + " is marked @NonNull but is null";
- }
-
- public String getExceptionType() {
+ @Override public String getExceptionType() {
return "java.lang.NullPointerException";
}
+ },
+ ASSERTION {
+ @Override public String getExceptionType() {
+ return null;
+ }
};
- public abstract String toExceptionMessage(String fieldName);
+ public String toExceptionMessage(String fieldName) {
+ return fieldName + " is marked non-null but is null";
+ }
+
public abstract String getExceptionType();
}
diff --git a/src/core/lombok/core/handlers/HandlerUtil.java b/src/core/lombok/core/handlers/HandlerUtil.java
index d0092b53..64d17cd9 100644
--- a/src/core/lombok/core/handlers/HandlerUtil.java
+++ b/src/core/lombok/core/handlers/HandlerUtil.java
@@ -84,8 +84,7 @@ public class HandlerUtil {
"com.sun.istack.internal.NotNull",
"edu.umd.cs.findbugs.annotations.NonNull",
"javax.annotation.Nonnull",
- // The field might contain a null value until it is persisted.
- // "javax.validation.constraints.NotNull",
+ // "javax.validation.constraints.NotNull", // The field might contain a null value until it is persisted.
"lombok.NonNull",
"org.checkerframework.checker.nullness.qual.NonNull",
"org.eclipse.jdt.annotation.NonNull",
@@ -105,8 +104,8 @@ public class HandlerUtil {
"javax.annotation.Nonnull",
"javax.annotation.Nullable",
"lombok.NonNull",
- // To update Checker Framework annotations, run:
- // grep --recursive --files-with-matches -e '^@Target\b.*TYPE_USE' $CHECKERFRAMEWORK/checker/src/main/java $CHECKERFRAMEWORK/framework/src/main/java | grep '\.java$' | sed 's/.*\/java\//\t\t\t"/' | sed 's/\.java$/",/' | sed 's/\//./g' | sort
+ // To update Checker Framework annotations, run:
+ // grep --recursive --files-with-matches -e '^@Target\b.*TYPE_USE' $CHECKERFRAMEWORK/checker/src/main/java $CHECKERFRAMEWORK/framework/src/main/java | grep '\.java$' | sed 's/.*\/java\//\t\t\t"/' | sed 's/\.java$/",/' | sed 's/\//./g' | sort
"org.checkerframework.checker.compilermsgs.qual.CompilerMessageKey",
"org.checkerframework.checker.compilermsgs.qual.CompilerMessageKeyBottom",
"org.checkerframework.checker.compilermsgs.qual.UnknownCompilerMessageKey",
@@ -293,6 +292,7 @@ public class HandlerUtil {
"org.checkerframework.common.value.qual.UnknownVal",
"org.checkerframework.framework.qual.PolyAll",
"org.checkerframework.framework.util.PurityUnqualified",
+
"org.eclipse.jdt.annotation.NonNull",
"org.eclipse.jdt.annotation.Nullable",
"org.jetbrains.annotations.NotNull",
diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
index 9439caf3..010dc9d8 100644
--- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
+++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
@@ -66,6 +66,7 @@ import org.eclipse.jdt.internal.compiler.ast.Annotation;
import org.eclipse.jdt.internal.compiler.ast.ArrayInitializer;
import org.eclipse.jdt.internal.compiler.ast.ArrayQualifiedTypeReference;
import org.eclipse.jdt.internal.compiler.ast.ArrayTypeReference;
+import org.eclipse.jdt.internal.compiler.ast.AssertStatement;
import org.eclipse.jdt.internal.compiler.ast.Block;
import org.eclipse.jdt.internal.compiler.ast.CastExpression;
import org.eclipse.jdt.internal.compiler.ast.CharLiteral;
@@ -221,14 +222,14 @@ public class EclipseHandlerUtil {
* @param typeRef A type reference to check.
*/
public static boolean typeMatches(String type, EclipseNode node, TypeReference typeRef) {
- if (typeRef == null || typeRef.getTypeName() == null || typeRef.getTypeName().length == 0) return false;
- String lastPartA = new String(typeRef.getTypeName()[typeRef.getTypeName().length -1]);
- int lastIndex = type.lastIndexOf('.');
- String lastPartB = lastIndex == -1 ? type : type.substring(lastIndex + 1);
- if (!lastPartA.equals(lastPartB)) return false;
- String typeName = toQualifiedName(typeRef.getTypeName());
-
- TypeResolver resolver = new TypeResolver(node.getImportList());
+ char[][] tn = typeRef == null ? null : typeRef.getTypeName();
+ if (tn == null || tn.length == 0) return false;
+ char[] lastPartA = tn[tn.length - 1];
+ int lastIndex = type.lastIndexOf('.') + 1;
+ if (lastPartA.length != type.length() - lastIndex) return false;
+ for (int i = 0; i < lastPartA.length; i++) if (lastPartA[i] != type.charAt(i + lastIndex)) return false;
+ String typeName = toQualifiedName(tn);
+ TypeResolver resolver = node.getImportListAsTypeResolver();
return resolver.typeMatches(node, type, typeName);
}
@@ -1786,27 +1787,39 @@ public class EclipseHandlerUtil {
if (isPrimitive(variable.type)) return null;
AllocationExpression exception = new AllocationExpression();
setGeneratedBy(exception, source);
- int partCount = 1;
+
+ SingleNameReference varName = new SingleNameReference(variable.name, p);
+ setGeneratedBy(varName, source);
+ NullLiteral nullLiteral = new NullLiteral(pS, pE);
+ setGeneratedBy(nullLiteral, source);
+
+ int equalOperator = exceptionType == NullCheckExceptionType.ASSERTION ? OperatorIds.NOT_EQUAL : OperatorIds.EQUAL_EQUAL;
+ EqualExpression equalExpression = new EqualExpression(varName, nullLiteral, equalOperator);
+ equalExpression.sourceStart = pS; equalExpression.statementEnd = equalExpression.sourceEnd = pE;
+ setGeneratedBy(equalExpression, source);
+
+ StringLiteral message = new StringLiteral(exceptionType.toExceptionMessage(new String(variable.name)).toCharArray(), pS, pE, 0);
+ setGeneratedBy(message, source);
+
+ if (exceptionType == NullCheckExceptionType.ASSERTION) {
+ Statement assertStatement = new AssertStatement(message, equalExpression, pS);
+ setGeneratedBy(assertStatement, source);
+ return assertStatement;
+ }
+
String exceptionTypeStr = exceptionType.getExceptionType();
+ int partCount = 1;
for (int i = 0; i < exceptionTypeStr.length(); i++) if (exceptionTypeStr.charAt(i) == '.') partCount++;
long[] ps = new long[partCount];
Arrays.fill(ps, 0L);
exception.type = new QualifiedTypeReference(fromQualifiedName(exceptionTypeStr), ps);
setGeneratedBy(exception.type, source);
- exception.arguments = new Expression[] {
- new StringLiteral(exceptionType.toExceptionMessage(new String(variable.name)).toCharArray(), pS, pE, 0)
- };
- setGeneratedBy(exception.arguments[0], source);
+ exception.arguments = new Expression[] {message};
+
ThrowStatement throwStatement = new ThrowStatement(exception, pS, pE);
setGeneratedBy(throwStatement, source);
- SingleNameReference varName = new SingleNameReference(variable.name, p);
- setGeneratedBy(varName, source);
- NullLiteral nullLiteral = new NullLiteral(pS, pE);
- setGeneratedBy(nullLiteral, source);
- EqualExpression equalExpression = new EqualExpression(varName, nullLiteral, OperatorIds.EQUAL_EQUAL);
- equalExpression.sourceStart = pS; equalExpression.statementEnd = equalExpression.sourceEnd = pE;
- setGeneratedBy(equalExpression, source);
+
Block throwBlock = new Block(0);
throwBlock.statements = new Statement[] {throwStatement};
throwBlock.sourceStart = pS; throwBlock.sourceEnd = pE;
diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java
index 3391b99d..7a831f3d 100755
--- a/src/core/lombok/eclipse/handlers/HandleBuilder.java
+++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java
@@ -170,10 +170,18 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> {
List<char[]> typeArgsForToBuilder = null;
if (builderMethodName == null) builderMethodName = "builder";
- if (buildMethodName == null) builderMethodName = "build";
+ if (buildMethodName == null) buildMethodName = "build";
if (builderClassName == null) builderClassName = "";
- if (!checkName("builderMethodName", builderMethodName, annotationNode)) return;
+ boolean generateBuilderMethod;
+ if (builderMethodName.isEmpty()) {
+ generateBuilderMethod = false;
+ } else if (!checkName("builderMethodName", builderMethodName, annotationNode)) {
+ return;
+ } else {
+ generateBuilderMethod = true;
+ }
+
if (!checkName("buildMethodName", buildMethodName, annotationNode)) return;
if (!builderClassName.isEmpty()) {
if (!checkName("builderClassName", builderClassName, annotationNode)) return;
@@ -192,6 +200,8 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> {
boolean addCleaning = false;
boolean isStatic = true;
+ List<EclipseNode> nonFinalNonDefaultedFields = null;
+
if (parent.get() instanceof TypeDeclaration) {
tdParent = parent;
TypeDeclaration td = (TypeDeclaration) tdParent.get();
@@ -225,7 +235,8 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> {
if (fd.initialization != null && isDefault == null) {
if (isFinal) continue;
- fieldNode.addWarning("@Builder will ignore the initializing expression entirely. If you want the initializing expression to serve as default, add @Builder.Default. If it is not supposed to be settable during building, make the field final.");
+ if (nonFinalNonDefaultedFields == null) nonFinalNonDefaultedFields = new ArrayList<EclipseNode>();
+ nonFinalNonDefaultedFields.add(fieldNode);
}
if (isDefault != null) {
@@ -486,7 +497,8 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> {
if (cleanMethod != null) injectMethod(builderType, cleanMethod);
}
- if (methodExists(builderMethodName, tdParent, -1) == MemberExistsResult.NOT_EXISTS) {
+ if (generateBuilderMethod && methodExists(builderMethodName, tdParent, -1) != MemberExistsResult.NOT_EXISTS) generateBuilderMethod = false;
+ if (generateBuilderMethod) {
MethodDeclaration md = generateBuilderMethod(isStatic, builderMethodName, builderClassName, tdParent, typeParams, ast);
if (md != null) injectMethod(tdParent, md);
}
@@ -508,6 +520,12 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> {
if (md != null) injectMethod(tdParent, md);
}
+
+ if (nonFinalNonDefaultedFields != null && generateBuilderMethod) {
+ for (EclipseNode fieldNode : nonFinalNonDefaultedFields) {
+ fieldNode.addWarning("@Builder will ignore the initializing expression entirely. If you want the initializing expression to serve as default, add @Builder.Default. If it is not supposed to be settable during building, make the field final.");
+ }
+ }
}
private static final char[] BUILDER_TEMP_VAR = {'b', 'u', 'i', 'l', 'd', 'e', 'r'};
diff --git a/src/core/lombok/eclipse/handlers/HandleNonNull.java b/src/core/lombok/eclipse/handlers/HandleNonNull.java
index 1672618d..77c77e1e 100644
--- a/src/core/lombok/eclipse/handlers/HandleNonNull.java
+++ b/src/core/lombok/eclipse/handlers/HandleNonNull.java
@@ -21,27 +21,18 @@
*/
package lombok.eclipse.handlers;
-import static lombok.core.handlers.HandlerUtil.*;
+import static lombok.core.handlers.HandlerUtil.handleFlagUsage;
import static lombok.eclipse.Eclipse.isPrimitive;
import static lombok.eclipse.handlers.EclipseHandlerUtil.*;
import java.util.Arrays;
-import lombok.ConfigurationKeys;
-import lombok.NonNull;
-import lombok.core.AST.Kind;
-import lombok.core.AnnotationValues;
-import lombok.core.HandlerPriority;
-import lombok.eclipse.DeferUntilPostDiet;
-import lombok.eclipse.EclipseAST;
-import lombok.eclipse.EclipseAnnotationHandler;
-import lombok.eclipse.EclipseNode;
-
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
import org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration;
import org.eclipse.jdt.internal.compiler.ast.Annotation;
import org.eclipse.jdt.internal.compiler.ast.Argument;
+import org.eclipse.jdt.internal.compiler.ast.AssertStatement;
import org.eclipse.jdt.internal.compiler.ast.Block;
import org.eclipse.jdt.internal.compiler.ast.EqualExpression;
import org.eclipse.jdt.internal.compiler.ast.Expression;
@@ -56,6 +47,16 @@ import org.eclipse.jdt.internal.compiler.ast.TryStatement;
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
import org.mangosdk.spi.ProviderFor;
+import lombok.ConfigurationKeys;
+import lombok.NonNull;
+import lombok.core.AST.Kind;
+import lombok.core.AnnotationValues;
+import lombok.core.HandlerPriority;
+import lombok.eclipse.DeferUntilPostDiet;
+import lombok.eclipse.EclipseAST;
+import lombok.eclipse.EclipseAnnotationHandler;
+import lombok.eclipse.EclipseNode;
+
@DeferUntilPostDiet
@ProviderFor(EclipseAnnotationHandler.class)
@HandlerPriority(value = 512) // 2^9; onParameter=@__(@NonNull) has to run first.
@@ -191,9 +192,11 @@ public class HandleNonNull extends EclipseAnnotationHandler<NonNull> {
}
public char[] returnVarNameIfNullCheck(Statement stat) {
- if (!(stat instanceof IfStatement)) return null;
+ boolean isIf = stat instanceof IfStatement;
+ if (!isIf && !(stat instanceof AssertStatement)) return null;
- /* Check that the if's statement is a throw statement, possibly in a block. */ {
+ if (isIf) {
+ /* Check that the if's statement is a throw statement, possibly in a block. */
Statement then = ((IfStatement) stat).thenStatement;
if (then instanceof Block) {
Statement[] blockStatements = ((Block) then).statements;
@@ -206,11 +209,15 @@ public class HandleNonNull extends EclipseAnnotationHandler<NonNull> {
/* Check that the if's conditional is like 'x == null'. Return from this method (don't generate
a nullcheck) if 'x' is equal to our own variable's name: There's already a nullcheck here. */ {
- Expression cond = ((IfStatement) stat).condition;
+ Expression cond = isIf ? ((IfStatement) stat).condition : ((AssertStatement) stat).assertExpression;
if (!(cond instanceof EqualExpression)) return null;
EqualExpression bin = (EqualExpression) cond;
int operatorId = ((bin.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT);
- if (operatorId != OperatorIds.EQUAL_EQUAL) return null;
+ if (isIf) {
+ if (operatorId != OperatorIds.EQUAL_EQUAL) return null;
+ } else {
+ if (operatorId != OperatorIds.NOT_EQUAL) return null;
+ }
if (!(bin.left instanceof SingleNameReference)) return null;
if (!(bin.right instanceof NullLiteral)) return null;
return ((SingleNameReference) bin.left).token;
diff --git a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java
index 7b6a3c28..6f34eb30 100755
--- a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java
+++ b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java
@@ -129,7 +129,14 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> {
if (builderMethodName == null) builderMethodName = "builder";
if (buildMethodName == null) buildMethodName = "build";
- if (!checkName("builderMethodName", builderMethodName, annotationNode)) return;
+ boolean generateBuilderMethod;
+ if (builderMethodName.isEmpty()) {
+ generateBuilderMethod = false;
+ } else if (!checkName("builderMethodName", builderMethodName, annotationNode)) {
+ return;
+ } else {
+ generateBuilderMethod = true;
+ }
if (!checkName("buildMethodName", buildMethodName, annotationNode)) return;
boolean toBuilder = superbuilderAnnotation.toBuilder();
@@ -150,6 +157,8 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> {
// Gather all fields of the class that should be set by the builder.
List<EclipseNode> allFields = new ArrayList<EclipseNode>();
+ List<EclipseNode> nonFinalNonDefaultedFields = null;
+
boolean valuePresent = (hasAnnotation(lombok.Value.class, tdParent) || hasAnnotation("lombok.experimental.Value", tdParent));
for (EclipseNode fieldNode : HandleConstructor.findAllFields(tdParent, true)) {
FieldDeclaration fd = (FieldDeclaration) fieldNode.get();
@@ -177,10 +186,9 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> {
}
if (fd.initialization != null && isDefault == null) {
- if (isFinal) {
- continue;
- }
- fieldNode.addWarning("@Builder will ignore the initializing expression entirely. If you want the initializing expression to serve as default, add @Builder.Default. If it is not supposed to be settable during building, make the field final.");
+ if (isFinal) continue;
+ if (nonFinalNonDefaultedFields == null) nonFinalNonDefaultedFields = new ArrayList<EclipseNode>();
+ nonFinalNonDefaultedFields.add(fieldNode);
}
if (isDefault != null) {
@@ -386,10 +394,17 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> {
}
// Add the builder() method to the annotated class.
- if (methodExists(builderMethodName, tdParent, -1) == MemberExistsResult.NOT_EXISTS) {
+ if (generateBuilderMethod && methodExists(builderMethodName, tdParent, -1) != MemberExistsResult.NOT_EXISTS) generateBuilderMethod = false;
+ if (generateBuilderMethod) {
MethodDeclaration md = generateBuilderMethod(builderMethodName, builderClassName, builderImplClassName, tdParent, typeParams, ast);
if (md != null) injectMethod(tdParent, md);
}
+
+ if (nonFinalNonDefaultedFields != null && generateBuilderMethod) {
+ for (EclipseNode fieldNode : nonFinalNonDefaultedFields) {
+ fieldNode.addWarning("@SuperBuilder will ignore the initializing expression entirely. If you want the initializing expression to serve as default, add @Builder.Default. If it is not supposed to be settable during building, make the field final.");
+ }
+ }
}
private EclipseNode generateBuilderAbstractClass(EclipseNode tdParent, String builderClass,
diff --git a/src/core/lombok/experimental/FieldNameConstants.java b/src/core/lombok/experimental/FieldNameConstants.java
index d6886890..da97a721 100644
--- a/src/core/lombok/experimental/FieldNameConstants.java
+++ b/src/core/lombok/experimental/FieldNameConstants.java
@@ -41,6 +41,8 @@ public @interface FieldNameConstants {
/**
* Only include fields and methods explicitly marked with {@code @FieldNameConstants.Include}.
* Normally, all (non-static) fields are included by default.
+ *
+ * @return If {@code true}, don't include non-static fields automatically (default: {@code false}).
*/
boolean onlyExplicitlyIncluded() default false;
diff --git a/src/core/lombok/experimental/SuperBuilder.java b/src/core/lombok/experimental/SuperBuilder.java
index be6ea304..aef76a46 100644
--- a/src/core/lombok/experimental/SuperBuilder.java
+++ b/src/core/lombok/experimental/SuperBuilder.java
@@ -49,7 +49,7 @@ import lombok.Singular;
@Target(TYPE)
@Retention(SOURCE)
public @interface SuperBuilder {
- /** @return Name of the method that creates a new builder instance. Default: {@code builder}. */
+ /** @return Name of the method that creates a new builder instance. Default: {@code builder}. If the empty string, suppress generating the {@code builder} method. */
String builderMethodName() default "builder";
/** @return Name of the method in the builder class that creates an instance of your {@code @Builder}-annotated class. */
diff --git a/src/core/lombok/javac/handlers/HandleBuilder.java b/src/core/lombok/javac/handlers/HandleBuilder.java
index 609adbd6..d6fb9728 100644
--- a/src/core/lombok/javac/handlers/HandleBuilder.java
+++ b/src/core/lombok/javac/handlers/HandleBuilder.java
@@ -119,7 +119,15 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
if (buildMethodName == null) buildMethodName = "build";
if (builderClassName == null) builderClassName = "";
- if (!checkName("builderMethodName", builderMethodName, annotationNode)) return;
+ boolean generateBuilderMethod;
+ if (builderMethodName.isEmpty()) {
+ generateBuilderMethod = false;
+ } else if (!checkName("builderMethodName", builderMethodName, annotationNode)) {
+ return;
+ } else {
+ generateBuilderMethod = true;
+ }
+
if (!checkName("buildMethodName", buildMethodName, annotationNode)) return;
if (!builderClassName.isEmpty()) {
if (!checkName("builderClassName", builderClassName, annotationNode)) return;
@@ -140,6 +148,8 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
boolean addCleaning = false;
boolean isStatic = true;
+ ArrayList<JavacNode> nonFinalNonDefaultedFields = null;
+
if (parent.get() instanceof JCClassDecl) {
tdParent = parent;
JCClassDecl td = (JCClassDecl) tdParent.get();
@@ -172,7 +182,8 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
if (fd.init != null && isDefault == null) {
if (isFinal) continue;
- fieldNode.addWarning("@Builder will ignore the initializing expression entirely. If you want the initializing expression to serve as default, add @Builder.Default. If it is not supposed to be settable during building, make the field final.");
+ if (nonFinalNonDefaultedFields == null) nonFinalNonDefaultedFields = new ArrayList<JavacNode>();
+ nonFinalNonDefaultedFields.add(fieldNode);
}
if (isDefault != null) {
@@ -406,7 +417,7 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
}
{
- MemberExistsResult methodExists = methodExists(builderMethodName, builderType, -1);
+ MemberExistsResult methodExists = methodExists(buildMethodName, builderType, -1);
if (methodExists == MemberExistsResult.EXISTS_BY_LOMBOK) methodExists = methodExists(buildMethodName, builderType, 0);
if (methodExists == MemberExistsResult.NOT_EXISTS) {
JCMethodDecl md = generateBuildMethod(tdParent, isStatic, buildMethodName, nameOfBuilderMethod, returnType, builderFields, builderType, thrownExceptions, ast, addCleaning);
@@ -431,7 +442,8 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
if (addCleaning) injectMethod(builderType, generateCleanMethod(builderFields, builderType, ast));
- if (methodExists(builderMethodName, tdParent, -1) == MemberExistsResult.NOT_EXISTS) {
+ if (generateBuilderMethod && methodExists(builderMethodName, tdParent, -1) != MemberExistsResult.NOT_EXISTS) generateBuilderMethod = false;
+ if (generateBuilderMethod) {
JCMethodDecl md = generateBuilderMethod(isStatic, builderMethodName, builderClassName, annotationNode, tdParent, typeParams);
recursiveSetGeneratedBy(md, ast, annotationNode.getContext());
if (md != null) injectMethod(tdParent, md);
@@ -459,6 +471,12 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
}
}
}
+
+ if (nonFinalNonDefaultedFields != null && generateBuilderMethod) {
+ for (JavacNode fieldNode : nonFinalNonDefaultedFields) {
+ fieldNode.addWarning("@Builder will ignore the initializing expression entirely. If you want the initializing expression to serve as default, add @Builder.Default. If it is not supposed to be settable during building, make the field final.");
+ }
+ }
}
private static String unpack(JCExpression expr) {
diff --git a/src/core/lombok/javac/handlers/HandleNonNull.java b/src/core/lombok/javac/handlers/HandleNonNull.java
index 9a81ffff..49b987ce 100644
--- a/src/core/lombok/javac/handlers/HandleNonNull.java
+++ b/src/core/lombok/javac/handlers/HandleNonNull.java
@@ -21,13 +21,16 @@
*/
package lombok.javac.handlers;
-import static lombok.core.handlers.HandlerUtil.*;
+import static lombok.core.handlers.HandlerUtil.handleFlagUsage;
import static lombok.javac.Javac.*;
+import static lombok.javac.JavacTreeMaker.TreeTag.treeTag;
+import static lombok.javac.JavacTreeMaker.TypeTag.typeTag;
import static lombok.javac.handlers.JavacHandlerUtil.*;
import org.mangosdk.spi.ProviderFor;
import com.sun.tools.javac.tree.JCTree.JCAnnotation;
+import com.sun.tools.javac.tree.JCTree.JCAssert;
import com.sun.tools.javac.tree.JCTree.JCBinary;
import com.sun.tools.javac.tree.JCTree.JCBlock;
import com.sun.tools.javac.tree.JCTree.JCExpression;
@@ -45,13 +48,11 @@ import com.sun.tools.javac.util.List;
import lombok.ConfigurationKeys;
import lombok.NonNull;
+import lombok.core.AST.Kind;
import lombok.core.AnnotationValues;
import lombok.core.HandlerPriority;
-import lombok.core.AST.Kind;
import lombok.javac.JavacAnnotationHandler;
import lombok.javac.JavacNode;
-import static lombok.javac.JavacTreeMaker.TypeTag.*;
-import static lombok.javac.JavacTreeMaker.TreeTag.*;
@ProviderFor(JavacAnnotationHandler.class)
@HandlerPriority(value = 512) // 2^9; onParameter=@__(@NonNull) has to run first.
@@ -161,14 +162,16 @@ public class HandleNonNull extends JavacAnnotationHandler<NonNull> {
}
/**
- * Checks if the statement is of the form 'if (x == null) {throw WHATEVER;},
+ * Checks if the statement is of the form 'if (x == null) {throw WHATEVER;}' or 'assert x != null;',
* where the block braces are optional. If it is of this form, returns "x".
* If it is not of this form, returns null.
*/
public String returnVarNameIfNullCheck(JCStatement stat) {
- if (!(stat instanceof JCIf)) return null;
+ boolean isIf = stat instanceof JCIf;
+ if (!isIf && !(stat instanceof JCAssert)) return null;
- /* Check that the if's statement is a throw statement, possibly in a block. */ {
+ if (isIf) {
+ /* Check that the if's statement is a throw statement, possibly in a block. */
JCStatement then = ((JCIf) stat).thenpart;
if (then instanceof JCBlock) {
List<JCStatement> stats = ((JCBlock) then).stats;
@@ -180,11 +183,15 @@ public class HandleNonNull extends JavacAnnotationHandler<NonNull> {
/* Check that the if's conditional is like 'x == null'. Return from this method (don't generate
a nullcheck) if 'x' is equal to our own variable's name: There's already a nullcheck here. */ {
- JCExpression cond = ((JCIf) stat).cond;
+ JCExpression cond = isIf ? ((JCIf) stat).cond : ((JCAssert) stat).cond;
while (cond instanceof JCParens) cond = ((JCParens) cond).expr;
if (!(cond instanceof JCBinary)) return null;
JCBinary bin = (JCBinary) cond;
- if (!CTC_EQUAL.equals(treeTag(bin))) return null;
+ if (isIf) {
+ if (!CTC_EQUAL.equals(treeTag(bin))) return null;
+ } else {
+ if (!CTC_NOT_EQUAL.equals(treeTag(bin))) return null;
+ }
if (!(bin.lhs instanceof JCIdent)) return null;
if (!(bin.rhs instanceof JCLiteral)) return null;
if (!CTC_BOT.equals(typeTag(bin.rhs))) return null;
diff --git a/src/core/lombok/javac/handlers/HandleSuperBuilder.java b/src/core/lombok/javac/handlers/HandleSuperBuilder.java
index 7ef6b658..7eb9873b 100644
--- a/src/core/lombok/javac/handlers/HandleSuperBuilder.java
+++ b/src/core/lombok/javac/handlers/HandleSuperBuilder.java
@@ -103,7 +103,14 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> {
if (builderMethodName == null) builderMethodName = "builder";
if (buildMethodName == null) buildMethodName = "build";
- if (!checkName("builderMethodName", builderMethodName, annotationNode)) return;
+ boolean generateBuilderMethod;
+ if (builderMethodName.isEmpty()) {
+ generateBuilderMethod = false;
+ } else if (!checkName("builderMethodName", builderMethodName, annotationNode)) {
+ return;
+ } else {
+ generateBuilderMethod = true;
+ }
if (!checkName("buildMethodName", buildMethodName, annotationNode)) return;
boolean toBuilder = superbuilderAnnotation.toBuilder();
@@ -125,6 +132,8 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> {
// Gather all fields of the class that should be set by the builder.
JCClassDecl td = (JCClassDecl) tdParent.get();
ListBuffer<JavacNode> allFields = new ListBuffer<JavacNode>();
+ ArrayList<JavacNode> nonFinalNonDefaultedFields = null;
+
boolean valuePresent = (hasAnnotation(lombok.Value.class, tdParent) || hasAnnotation("lombok.experimental.Value", tdParent));
for (JavacNode fieldNode : HandleConstructor.findAllFields(tdParent, true)) {
JCVariableDecl fd = (JCVariableDecl) fieldNode.get();
@@ -150,7 +159,8 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> {
if (fd.init != null && isDefault == null) {
if (isFinal) continue;
- fieldNode.addWarning("@SuperBuilder will ignore the initializing expression entirely. If you want the initializing expression to serve as default, add @Builder.Default. If it is not supposed to be settable during building, make the field final.");
+ if (nonFinalNonDefaultedFields == null) nonFinalNonDefaultedFields = new ArrayList<JavacNode>();
+ nonFinalNonDefaultedFields.add(fieldNode);
}
if (isDefault != null) {
@@ -347,7 +357,8 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> {
// Add the builder() method to the annotated class.
// Allow users to specify their own builder() methods, e.g., to provide default values.
- if (methodExists(builderMethodName, tdParent, -1) == MemberExistsResult.NOT_EXISTS) {
+ if (generateBuilderMethod && methodExists(builderMethodName, tdParent, -1) != MemberExistsResult.NOT_EXISTS) generateBuilderMethod = false;
+ if (generateBuilderMethod) {
JCMethodDecl builderMethod = generateBuilderMethod(builderMethodName, builderClassName, builderImplClassName, annotationNode, tdParent, typeParams);
recursiveSetGeneratedBy(builderMethod, ast, annotationNode.getContext());
if (builderMethod != null) injectMethod(tdParent, builderMethod);
@@ -369,6 +380,12 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> {
// Should not happen.
}
}
+
+ if (nonFinalNonDefaultedFields != null && generateBuilderMethod) {
+ for (JavacNode fieldNode : nonFinalNonDefaultedFields) {
+ fieldNode.addWarning("@SuperBuilder will ignore the initializing expression entirely. If you want the initializing expression to serve as default, add @Builder.Default. If it is not supposed to be settable during building, make the field final.");
+ }
+ }
}
/**
diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
index f08098d2..509a7397 100644
--- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java
+++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
@@ -40,36 +40,15 @@ import java.util.regex.Pattern;
import javax.lang.model.element.Element;
-import lombok.AccessLevel;
-import lombok.ConfigurationKeys;
-import lombok.Data;
-import lombok.Getter;
-import lombok.core.AST.Kind;
-import lombok.core.AnnotationValues;
-import lombok.core.LombokImmutableList;
-import lombok.core.AnnotationValues.AnnotationValue;
-import lombok.core.CleanupTask;
-import lombok.core.TypeResolver;
-import lombok.core.configuration.NullCheckExceptionType;
-import lombok.core.configuration.TypeName;
-import lombok.core.handlers.HandlerUtil;
-import lombok.delombok.LombokOptionsFactory;
-import lombok.experimental.Accessors;
-import lombok.experimental.Tolerate;
-import lombok.javac.Javac;
-import lombok.javac.JavacNode;
-import lombok.javac.JavacTreeMaker;
-import lombok.permit.Permit;
-
import com.sun.tools.javac.code.BoundKind;
import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.code.Scope;
import com.sun.tools.javac.code.Symbol;
-import com.sun.tools.javac.code.Symtab;
-import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.code.Symbol.ClassSymbol;
import com.sun.tools.javac.code.Symbol.MethodSymbol;
import com.sun.tools.javac.code.Symbol.VarSymbol;
+import com.sun.tools.javac.code.Symtab;
+import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.code.Type.MethodType;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.JCTree.JCAnnotation;
@@ -83,6 +62,7 @@ import com.sun.tools.javac.tree.JCTree.JCExpressionStatement;
import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
import com.sun.tools.javac.tree.JCTree.JCIdent;
import com.sun.tools.javac.tree.JCTree.JCImport;
+import com.sun.tools.javac.tree.JCTree.JCLiteral;
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
import com.sun.tools.javac.tree.JCTree.JCMethodInvocation;
import com.sun.tools.javac.tree.JCTree.JCModifiers;
@@ -103,6 +83,28 @@ import com.sun.tools.javac.util.ListBuffer;
import com.sun.tools.javac.util.Name;
import com.sun.tools.javac.util.Options;
+import lombok.AccessLevel;
+import lombok.ConfigurationKeys;
+import lombok.Data;
+import lombok.Getter;
+import lombok.core.AST.Kind;
+import lombok.core.AnnotationValues;
+import lombok.core.AnnotationValues.AnnotationValue;
+import lombok.core.CleanupTask;
+import lombok.core.LombokImmutableList;
+import lombok.core.TypeResolver;
+import lombok.core.configuration.NullCheckExceptionType;
+import lombok.core.configuration.TypeName;
+import lombok.core.handlers.HandlerUtil;
+import lombok.core.handlers.HandlerUtil.FieldAccess;
+import lombok.delombok.LombokOptionsFactory;
+import lombok.experimental.Accessors;
+import lombok.experimental.Tolerate;
+import lombok.javac.Javac;
+import lombok.javac.JavacNode;
+import lombok.javac.JavacTreeMaker;
+import lombok.permit.Permit;
+
/**
* Container for static utility methods useful to handlers written for javac.
*/
@@ -265,7 +267,7 @@ public class JavacHandlerUtil {
*/
public static boolean annotationTypeMatches(Class<? extends Annotation> type, JavacNode node) {
if (node.getKind() != Kind.ANNOTATION) return false;
- return typeMatches(type, node, ((JCAnnotation)node.get()).annotationType);
+ return typeMatches(type, node, ((JCAnnotation) node.get()).annotationType);
}
/**
@@ -298,9 +300,14 @@ public class JavacHandlerUtil {
* @param typeNode A type reference to check.
*/
public static boolean typeMatches(String type, JavacNode node, JCTree typeNode) {
- String typeName = typeNode.toString();
-
- TypeResolver resolver = new TypeResolver(node.getImportList());
+ String typeName = typeNode == null ? null : typeNode.toString();
+ if (typeName == null || typeName.length() == 0) return false;
+ int lastIndexA = typeName.lastIndexOf('.') + 1;
+ int lastIndexB = Math.max(type.lastIndexOf('.'), type.lastIndexOf('$')) + 1;
+ int len = typeName.length() - lastIndexA;
+ if (len != type.length() - lastIndexB) return false;
+ for (int i = 0; i < len; i++) if (typeName.charAt(i + lastIndexA) != type.charAt(i + lastIndexB)) return false;
+ TypeResolver resolver = node.getImportListAsTypeResolver();
return resolver.typeMatches(node, type, typeName);
}
@@ -1479,8 +1486,14 @@ public class JavacHandlerUtil {
if (isPrimitive(varDecl.vartype)) return null;
Name fieldName = varDecl.name;
+
+ JCLiteral message = maker.Literal(exceptionType.toExceptionMessage(fieldName.toString()));
+ if (exceptionType == NullCheckExceptionType.ASSERTION) {
+ return maker.Assert(maker.Binary(CTC_NOT_EQUAL, maker.Ident(fieldName), maker.Literal(CTC_BOT, null)), message);
+ }
+
JCExpression exType = genTypeRef(variable, exceptionType.getExceptionType());
- JCExpression exception = maker.NewClass(null, List.<JCExpression>nil(), exType, List.<JCExpression>of(maker.Literal(exceptionType.toExceptionMessage(fieldName.toString()))), null);
+ JCExpression exception = maker.NewClass(null, List.<JCExpression>nil(), exType, List.<JCExpression>of(message), null);
JCStatement throwStatement = maker.Throw(exception);
JCBlock throwBlock = maker.Block(0, List.of(throwStatement));
return maker.If(maker.Binary(CTC_EQUAL, maker.Ident(fieldName), maker.Literal(CTC_BOT, null)), throwBlock, null);
diff --git a/src/delombok/lombok/delombok/Delombok.java b/src/delombok/lombok/delombok/Delombok.java
index 9582c3b8..8f4f99e5 100755
--- a/src/delombok/lombok/delombok/Delombok.java
+++ b/src/delombok/lombok/delombok/Delombok.java
@@ -753,6 +753,7 @@ public class Delombok {
Object care = callAttributeMethodOnJavaCompiler(delegate, delegate.todo);
callFlowMethodOnJavaCompiler(delegate, care);
+
FormatPreferences fps = new FormatPreferences(formatPrefs);
for (JCCompilationUnit unit : roots) {
DelombokResult result = new DelombokResult(catcher.getComments(unit), unit, force || options.isChanged(unit), fps);
diff --git a/src/delombok/lombok/delombok/PrettyPrinter.java b/src/delombok/lombok/delombok/PrettyPrinter.java
index 353bd753..832dbe0a 100644
--- a/src/delombok/lombok/delombok/PrettyPrinter.java
+++ b/src/delombok/lombok/delombok/PrettyPrinter.java
@@ -648,7 +648,11 @@ public class PrettyPrinter extends JCTree.Visitor {
*/
try {
innermostArrayBracketsAreVarargs = varargs;
- print(tree.vartype);
+ if (tree.vartype == null || tree.vartype.pos == -1) {
+ print("var");
+ } else {
+ print(tree.vartype);
+ }
} finally {
innermostArrayBracketsAreVarargs = false;
}
diff --git a/test/pretty/resource/after/Java11Var.javva b/test/pretty/resource/after/Java11Var.javva
new file mode 100644
index 00000000..cec4be6d
--- /dev/null
+++ b/test/pretty/resource/after/Java11Var.javva
@@ -0,0 +1,6 @@
+public class Java11Var {
+ public void test() {
+ var b = 10;
+ int c = 11;
+ }
+}
diff --git a/test/pretty/resource/before/Java11Var.java b/test/pretty/resource/before/Java11Var.java
new file mode 100644
index 00000000..cfbe1989
--- /dev/null
+++ b/test/pretty/resource/before/Java11Var.java
@@ -0,0 +1,7 @@
+//version 11:
+public class Java11Var {
+ public void test() {
+ var b = 10;
+ int c = 11;
+ }
+}
diff --git a/test/transform/resource/after-delombok/BuilderSingularAnnotatedTypes.java b/test/transform/resource/after-delombok/BuilderSingularAnnotatedTypes.java
index 93825659..88459e67 100644
--- a/test/transform/resource/after-delombok/BuilderSingularAnnotatedTypes.java
+++ b/test/transform/resource/after-delombok/BuilderSingularAnnotatedTypes.java
@@ -28,7 +28,7 @@ class BuilderSingularAnnotatedTypes {
@java.lang.SuppressWarnings("all")
public BuilderSingularAnnotatedTypesBuilder foo(@MyAnnotation @NonNull final String foo) {
if (foo == null) {
- throw new java.lang.NullPointerException("foo is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("foo is marked non-null but is null");
}
if (this.foos == null) this.foos = new java.util.ArrayList<@MyAnnotation @NonNull String>();
this.foos.add(foo);
@@ -48,10 +48,10 @@ class BuilderSingularAnnotatedTypes {
@java.lang.SuppressWarnings("all")
public BuilderSingularAnnotatedTypesBuilder bar(@MyAnnotation @NonNull final String barKey, @MyAnnotation @NonNull final Integer barValue) {
if (barKey == null) {
- throw new java.lang.NullPointerException("barKey is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("barKey is marked non-null but is null");
}
if (barValue == null) {
- throw new java.lang.NullPointerException("barValue is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("barValue is marked non-null but is null");
}
if (this.bars$key == null) {
this.bars$key = new java.util.ArrayList<@MyAnnotation @NonNull String>();
diff --git a/test/transform/resource/after-delombok/BuilderWithNoBuilderMethod.java b/test/transform/resource/after-delombok/BuilderWithNoBuilderMethod.java
new file mode 100644
index 00000000..35e2c79e
--- /dev/null
+++ b/test/transform/resource/after-delombok/BuilderWithNoBuilderMethod.java
@@ -0,0 +1,33 @@
+class BuilderWithNoBuilderMethod {
+ private String a = "";
+ @java.lang.SuppressWarnings("all")
+ BuilderWithNoBuilderMethod(final String a) {
+ this.a = a;
+ }
+ @java.lang.SuppressWarnings("all")
+ public static class BuilderWithNoBuilderMethodBuilder {
+ @java.lang.SuppressWarnings("all")
+ private String a;
+ @java.lang.SuppressWarnings("all")
+ BuilderWithNoBuilderMethodBuilder() {
+ }
+ @java.lang.SuppressWarnings("all")
+ public BuilderWithNoBuilderMethodBuilder a(final String a) {
+ this.a = a;
+ return this;
+ }
+ @java.lang.SuppressWarnings("all")
+ public BuilderWithNoBuilderMethod build() {
+ return new BuilderWithNoBuilderMethod(a);
+ }
+ @java.lang.Override
+ @java.lang.SuppressWarnings("all")
+ public java.lang.String toString() {
+ return "BuilderWithNoBuilderMethod.BuilderWithNoBuilderMethodBuilder(a=" + this.a + ")";
+ }
+ }
+ @java.lang.SuppressWarnings("all")
+ public BuilderWithNoBuilderMethodBuilder toBuilder() {
+ return new BuilderWithNoBuilderMethodBuilder().a(this.a);
+ }
+}
diff --git a/test/transform/resource/after-delombok/ConstructorsWithAccessors.java b/test/transform/resource/after-delombok/ConstructorsWithAccessors.java
index 2e09b2df..3614d682 100644
--- a/test/transform/resource/after-delombok/ConstructorsWithAccessors.java
+++ b/test/transform/resource/after-delombok/ConstructorsWithAccessors.java
@@ -26,16 +26,16 @@ class ConstructorsWithAccessorsNonNull {
@java.lang.SuppressWarnings("all")
public ConstructorsWithAccessorsNonNull(@lombok.NonNull final Integer plower, @lombok.NonNull final Integer upper, @lombok.NonNull final Integer huh, @lombok.NonNull final Integer _huh2) {
if (plower == null) {
- throw new java.lang.NullPointerException("plower is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("plower is marked non-null but is null");
}
if (upper == null) {
- throw new java.lang.NullPointerException("upper is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("upper is marked non-null but is null");
}
if (huh == null) {
- throw new java.lang.NullPointerException("huh is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("huh is marked non-null but is null");
}
if (_huh2 == null) {
- throw new java.lang.NullPointerException("_huh2 is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("_huh2 is marked non-null but is null");
}
this.plower = plower;
this.pUpper = upper;
diff --git a/test/transform/resource/after-delombok/DataOnLocalClass.java b/test/transform/resource/after-delombok/DataOnLocalClass.java
index d611490b..80f3ca83 100644
--- a/test/transform/resource/after-delombok/DataOnLocalClass.java
+++ b/test/transform/resource/after-delombok/DataOnLocalClass.java
@@ -64,7 +64,7 @@ class DataOnLocalClass2 {
@java.lang.SuppressWarnings("all")
public InnerLocal(@lombok.NonNull final String name) {
if (name == null) {
- throw new java.lang.NullPointerException("name is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("name is marked non-null but is null");
}
this.name = name;
}
@@ -76,7 +76,7 @@ class DataOnLocalClass2 {
@java.lang.SuppressWarnings("all")
public void setName(@lombok.NonNull final String name) {
if (name == null) {
- throw new java.lang.NullPointerException("name is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("name is marked non-null but is null");
}
this.name = name;
}
diff --git a/test/transform/resource/after-delombok/NonNullOnParameter.java b/test/transform/resource/after-delombok/NonNullOnParameter.java
index fa06e41b..4f6df920 100644
--- a/test/transform/resource/after-delombok/NonNullOnParameter.java
+++ b/test/transform/resource/after-delombok/NonNullOnParameter.java
@@ -2,22 +2,22 @@ class NonNullOnParameter extends Thread {
NonNullOnParameter(@lombok.NonNull String arg) {
this(arg, "");
if (arg == null) {
- throw new java.lang.NullPointerException("arg is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("arg is marked non-null but is null");
}
}
NonNullOnParameter(@lombok.NonNull String arg, @lombok.NonNull String arg2) {
super(arg);
if (arg2 == null) {
- throw new java.lang.NullPointerException("arg2 is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("arg2 is marked non-null but is null");
}
if (arg == null) throw new NullPointerException();
}
public void test2(@lombok.NonNull String arg, @lombok.NonNull String arg2, @lombok.NonNull String arg3) {
if (arg == null) {
- throw new java.lang.NullPointerException("arg is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("arg is marked non-null but is null");
}
if (arg3 == null) {
- throw new java.lang.NullPointerException("arg3 is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("arg3 is marked non-null but is null");
}
if (arg2 == null) {
throw new NullPointerException("arg2");
@@ -26,23 +26,29 @@ class NonNullOnParameter extends Thread {
}
public void test3(@lombok.NonNull String arg) {
if (arg == null) {
- throw new java.lang.NullPointerException("arg is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("arg is marked non-null but is null");
}
if (arg != null) throw new IllegalStateException();
}
public void test(@lombok.NonNull String stringArg, @lombok.NonNull String arg2, @lombok.NonNull int primitiveArg) {
if (stringArg == null) {
- throw new java.lang.NullPointerException("stringArg is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("stringArg is marked non-null but is null");
}
if (arg2 == null) {
- throw new java.lang.NullPointerException("arg2 is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("arg2 is marked non-null but is null");
}
}
public void test(@lombok.NonNull String arg) {
if (arg == null) {
- throw new java.lang.NullPointerException("arg is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("arg is marked non-null but is null");
}
System.out.println("Hey");
if (arg == null) throw new NullPointerException();
}
+ public void testWithAssert(@lombok.NonNull String param) {
+ assert param != null;
+ }
+ public void testWithAssertAndMessage(@lombok.NonNull String param) {
+ assert param != null : "Oops";
+ }
}
diff --git a/test/transform/resource/after-delombok/NonNullOnParameterAbstract.java b/test/transform/resource/after-delombok/NonNullOnParameterAbstract.java
index a2dcb49c..88577f25 100644
--- a/test/transform/resource/after-delombok/NonNullOnParameterAbstract.java
+++ b/test/transform/resource/after-delombok/NonNullOnParameterAbstract.java
@@ -1,7 +1,7 @@
abstract class NonNullOnParameterAbstract {
public void test(@lombok.NonNull String arg) {
if (arg == null) {
- throw new java.lang.NullPointerException("arg is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("arg is marked non-null but is null");
}
System.out.println("Hey");
}
diff --git a/test/transform/resource/after-delombok/NonNullOnParameterOfDefaultMethod.java b/test/transform/resource/after-delombok/NonNullOnParameterOfDefaultMethod.java
index cf10253b..876a3440 100644
--- a/test/transform/resource/after-delombok/NonNullOnParameterOfDefaultMethod.java
+++ b/test/transform/resource/after-delombok/NonNullOnParameterOfDefaultMethod.java
@@ -3,7 +3,7 @@ interface NonNullOnParameterOfDefaultMethod {
void test(@lombok.NonNull String arg);
default void test2(@lombok.NonNull String arg) {
if (arg == null) {
- throw new java.lang.NullPointerException("arg is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("arg is marked non-null but is null");
}
System.out.println(arg);
}
diff --git a/test/transform/resource/after-delombok/NonNullPlain.java b/test/transform/resource/after-delombok/NonNullPlain.java
index d3de3dcf..24377237 100644
--- a/test/transform/resource/after-delombok/NonNullPlain.java
+++ b/test/transform/resource/after-delombok/NonNullPlain.java
@@ -13,7 +13,7 @@ class NonNullPlain {
@java.lang.SuppressWarnings("all")
public NonNullPlain(@lombok.NonNull final int i, @lombok.NonNull final String s) {
if (s == null) {
- throw new java.lang.NullPointerException("s is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("s is marked non-null but is null");
}
this.i = i;
this.s = s;
@@ -39,7 +39,7 @@ class NonNullPlain {
@java.lang.SuppressWarnings("all")
public void setS(@lombok.NonNull final String s) {
if (s == null) {
- throw new java.lang.NullPointerException("s is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("s is marked non-null but is null");
}
this.s = s;
}
diff --git a/test/transform/resource/after-delombok/NonNullTypeUse.java b/test/transform/resource/after-delombok/NonNullTypeUse.java
index 27719480..7c438501 100644
--- a/test/transform/resource/after-delombok/NonNullTypeUse.java
+++ b/test/transform/resource/after-delombok/NonNullTypeUse.java
@@ -2,12 +2,12 @@ import lombok.NonNull;
class NonNullTypeUse {
void test1(@NonNull String[][][] args) {
if (args == null) {
- throw new java.lang.NullPointerException("args is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("args is marked non-null but is null");
}
}
void test2(String @NonNull [][][] args) {
if (args == null) {
- throw new java.lang.NullPointerException("args is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("args is marked non-null but is null");
}
}
void test3(String[] @NonNull [][] args) {
@@ -16,17 +16,17 @@ class NonNullTypeUse {
}
void test5(@NonNull String simple) {
if (simple == null) {
- throw new java.lang.NullPointerException("simple is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("simple is marked non-null but is null");
}
}
void test6(java.lang.@NonNull String weird) {
if (weird == null) {
- throw new java.lang.NullPointerException("weird is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("weird is marked non-null but is null");
}
}
void test7(java.lang.String @NonNull [][] weird) {
if (weird == null) {
- throw new java.lang.NullPointerException("weird is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("weird is marked non-null but is null");
}
}
}
diff --git a/test/transform/resource/after-delombok/NonNullWithAlternateException.java b/test/transform/resource/after-delombok/NonNullWithAlternateException.java
index 982da7d8..7f30fd1f 100644
--- a/test/transform/resource/after-delombok/NonNullWithAlternateException.java
+++ b/test/transform/resource/after-delombok/NonNullWithAlternateException.java
@@ -3,14 +3,14 @@ public class NonNullWithAlternateException {
private String test;
public void testMethod(@lombok.NonNull String arg) {
if (arg == null) {
- throw new java.lang.IllegalArgumentException("arg is marked @NonNull but is null");
+ throw new java.lang.IllegalArgumentException("arg is marked non-null but is null");
}
System.out.println(arg);
}
@java.lang.SuppressWarnings("all")
public void setTest(@lombok.NonNull final String test) {
if (test == null) {
- throw new java.lang.IllegalArgumentException("test is marked @NonNull but is null");
+ throw new java.lang.IllegalArgumentException("test is marked non-null but is null");
}
this.test = test;
}
diff --git a/test/transform/resource/after-delombok/NonNullWithAssertion.java b/test/transform/resource/after-delombok/NonNullWithAssertion.java
new file mode 100644
index 00000000..15dc0254
--- /dev/null
+++ b/test/transform/resource/after-delombok/NonNullWithAssertion.java
@@ -0,0 +1,16 @@
+public class NonNullWithAssertion {
+ @lombok.NonNull
+ private String test;
+ public void testMethod(@lombok.NonNull String arg) {
+ assert arg != null : "arg is marked non-null but is null";
+ System.out.println(arg);
+ }
+ public void testMethodWithIf(@lombok.NonNull String arg) {
+ if (arg == null) throw new NullPointerException("Oops");
+ }
+ @java.lang.SuppressWarnings("all")
+ public void setTest(@lombok.NonNull final String test) {
+ assert test != null : "test is marked non-null but is null";
+ this.test = test;
+ }
+} \ No newline at end of file
diff --git a/test/transform/resource/after-delombok/NonNullWithSneakyThrows.java b/test/transform/resource/after-delombok/NonNullWithSneakyThrows.java
index 5000f16d..44640164 100644
--- a/test/transform/resource/after-delombok/NonNullWithSneakyThrows.java
+++ b/test/transform/resource/after-delombok/NonNullWithSneakyThrows.java
@@ -2,7 +2,7 @@ class NonNullWithSneakyThrows {
void test(@lombok.NonNull String in) {
try {
if (in == null) {
- throw new java.lang.NullPointerException("in is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("in is marked non-null but is null");
}
System.out.println(in);
} catch (final java.lang.Throwable $ex) {
diff --git a/test/transform/resource/after-delombok/SetterOnClass.java b/test/transform/resource/after-delombok/SetterOnClass.java
index f880e20b..24f376cb 100644
--- a/test/transform/resource/after-delombok/SetterOnClass.java
+++ b/test/transform/resource/after-delombok/SetterOnClass.java
@@ -54,7 +54,7 @@ class SetterOnClass6 {
@java.lang.SuppressWarnings("all")
public void setNonNull(@lombok.NonNull final String nonNull) {
if (nonNull == null) {
- throw new java.lang.NullPointerException("nonNull is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("nonNull is marked non-null but is null");
}
this.nonNull = nonNull;
}
diff --git a/test/transform/resource/after-delombok/SuperBuilderSingularAnnotatedTypes.java b/test/transform/resource/after-delombok/SuperBuilderSingularAnnotatedTypes.java
index 1baf81aa..61c2557c 100644
--- a/test/transform/resource/after-delombok/SuperBuilderSingularAnnotatedTypes.java
+++ b/test/transform/resource/after-delombok/SuperBuilderSingularAnnotatedTypes.java
@@ -24,7 +24,7 @@ class SuperBuilderSingularAnnotatedTypes {
@java.lang.SuppressWarnings("all")
public B foo(@MyAnnotation @NonNull final String foo) {
if (foo == null) {
- throw new java.lang.NullPointerException("foo is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("foo is marked non-null but is null");
}
if (this.foos == null) this.foos = new java.util.ArrayList<@MyAnnotation @NonNull String>();
this.foos.add(foo);
@@ -44,10 +44,10 @@ class SuperBuilderSingularAnnotatedTypes {
@java.lang.SuppressWarnings("all")
public B bar(@MyAnnotation @NonNull final String barKey, @MyAnnotation @NonNull final Integer barValue) {
if (barKey == null) {
- throw new java.lang.NullPointerException("barKey is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("barKey is marked non-null but is null");
}
if (barValue == null) {
- throw new java.lang.NullPointerException("barValue is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("barValue is marked non-null but is null");
}
if (this.bars$key == null) {
this.bars$key = new java.util.ArrayList<@MyAnnotation @NonNull String>();
diff --git a/test/transform/resource/after-delombok/SuperBuilderWithNonNull.java b/test/transform/resource/after-delombok/SuperBuilderWithNonNull.java
index cac5482b..ce5c838c 100644
--- a/test/transform/resource/after-delombok/SuperBuilderWithNonNull.java
+++ b/test/transform/resource/after-delombok/SuperBuilderWithNonNull.java
@@ -20,7 +20,7 @@ public class SuperBuilderWithNonNull {
@java.lang.SuppressWarnings("all")
public B nonNullParentField(@lombok.NonNull final String nonNullParentField) {
if (nonNullParentField == null) {
- throw new java.lang.NullPointerException("nonNullParentField is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("nonNullParentField is marked non-null but is null");
}
this.nonNullParentField = nonNullParentField;
nonNullParentField$set = true;
@@ -53,7 +53,7 @@ public class SuperBuilderWithNonNull {
if (b.nonNullParentField$set) this.nonNullParentField = b.nonNullParentField;
else this.nonNullParentField = Parent.$default$nonNullParentField();
if (nonNullParentField == null) {
- throw new java.lang.NullPointerException("nonNullParentField is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("nonNullParentField is marked non-null but is null");
}
}
@java.lang.SuppressWarnings("all")
@@ -77,7 +77,7 @@ public class SuperBuilderWithNonNull {
@java.lang.SuppressWarnings("all")
public B nonNullChildField(@lombok.NonNull final String nonNullChildField) {
if (nonNullChildField == null) {
- throw new java.lang.NullPointerException("nonNullChildField is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("nonNullChildField is marked non-null but is null");
}
this.nonNullChildField = nonNullChildField;
return self();
@@ -109,7 +109,7 @@ public class SuperBuilderWithNonNull {
super(b);
this.nonNullChildField = b.nonNullChildField;
if (nonNullChildField == null) {
- throw new java.lang.NullPointerException("nonNullChildField is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("nonNullChildField is marked non-null but is null");
}
}
@java.lang.SuppressWarnings("all")
diff --git a/test/transform/resource/after-delombok/WitherOnClass.java b/test/transform/resource/after-delombok/WitherOnClass.java
index 93309c89..abc93446 100644
--- a/test/transform/resource/after-delombok/WitherOnClass.java
+++ b/test/transform/resource/after-delombok/WitherOnClass.java
@@ -36,7 +36,7 @@ class WitherOnClass3 {
@java.lang.SuppressWarnings("all")
public WitherOnClass3 withNonNull(@lombok.NonNull final String nonNull) {
if (nonNull == null) {
- throw new java.lang.NullPointerException("nonNull is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("nonNull is marked non-null but is null");
}
return this.nonNull == nonNull ? this : new WitherOnClass3(this.couldBeNull, nonNull);
}
diff --git a/test/transform/resource/after-ecj/BuilderSingularAnnotatedTypes.java b/test/transform/resource/after-ecj/BuilderSingularAnnotatedTypes.java
index 26023e1a..511c153a 100644
--- a/test/transform/resource/after-ecj/BuilderSingularAnnotatedTypes.java
+++ b/test/transform/resource/after-ecj/BuilderSingularAnnotatedTypes.java
@@ -17,7 +17,7 @@ import lombok.Singular;
public @java.lang.SuppressWarnings("all") BuilderSingularAnnotatedTypesBuilder foo(final @MyAnnotation @NonNull String foo) {
if ((foo == null))
{
- throw new java.lang.NullPointerException("foo is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("foo is marked non-null but is null");
}
if ((this.foos == null))
this.foos = new java.util.ArrayList<@MyAnnotation @NonNull String>();
@@ -38,11 +38,11 @@ import lombok.Singular;
public @java.lang.SuppressWarnings("all") BuilderSingularAnnotatedTypesBuilder bar(final @MyAnnotation @NonNull String barKey, final @MyAnnotation @NonNull Integer barValue) {
if ((barKey == null))
{
- throw new java.lang.NullPointerException("barKey is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("barKey is marked non-null but is null");
}
if ((barValue == null))
{
- throw new java.lang.NullPointerException("barValue is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("barValue is marked non-null but is null");
}
if ((this.bars$key == null))
{
diff --git a/test/transform/resource/after-ecj/BuilderWithNoBuilderMethod.java b/test/transform/resource/after-ecj/BuilderWithNoBuilderMethod.java
new file mode 100644
index 00000000..624b14b9
--- /dev/null
+++ b/test/transform/resource/after-ecj/BuilderWithNoBuilderMethod.java
@@ -0,0 +1,27 @@
+import lombok.Builder;
+@Builder(toBuilder = true,builderMethodName = "") class BuilderWithNoBuilderMethod {
+ public static @java.lang.SuppressWarnings("all") class BuilderWithNoBuilderMethodBuilder {
+ private @java.lang.SuppressWarnings("all") String a;
+ @java.lang.SuppressWarnings("all") BuilderWithNoBuilderMethodBuilder() {
+ super();
+ }
+ public @java.lang.SuppressWarnings("all") BuilderWithNoBuilderMethodBuilder a(final String a) {
+ this.a = a;
+ return this;
+ }
+ public @java.lang.SuppressWarnings("all") BuilderWithNoBuilderMethod build() {
+ return new BuilderWithNoBuilderMethod(a);
+ }
+ public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
+ return (("BuilderWithNoBuilderMethod.BuilderWithNoBuilderMethodBuilder(a=" + this.a) + ")");
+ }
+ }
+ private String a = "";
+ @java.lang.SuppressWarnings("all") BuilderWithNoBuilderMethod(final String a) {
+ super();
+ this.a = a;
+ }
+ public @java.lang.SuppressWarnings("all") BuilderWithNoBuilderMethodBuilder toBuilder() {
+ return new BuilderWithNoBuilderMethodBuilder().a(this.a);
+ }
+}
diff --git a/test/transform/resource/after-ecj/ConstructorsWithAccessors.java b/test/transform/resource/after-ecj/ConstructorsWithAccessors.java
index 6050ab9f..552c5c2d 100644
--- a/test/transform/resource/after-ecj/ConstructorsWithAccessors.java
+++ b/test/transform/resource/after-ecj/ConstructorsWithAccessors.java
@@ -20,19 +20,19 @@
super();
if ((plower == null))
{
- throw new java.lang.NullPointerException("plower is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("plower is marked non-null but is null");
}
if ((upper == null))
{
- throw new java.lang.NullPointerException("upper is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("upper is marked non-null but is null");
}
if ((huh == null))
{
- throw new java.lang.NullPointerException("huh is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("huh is marked non-null but is null");
}
if ((_huh2 == null))
{
- throw new java.lang.NullPointerException("_huh2 is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("_huh2 is marked non-null but is null");
}
this.plower = plower;
this.pUpper = upper;
diff --git a/test/transform/resource/after-ecj/DataOnLocalClass.java b/test/transform/resource/after-ecj/DataOnLocalClass.java
index ff2a3d20..ae986676 100644
--- a/test/transform/resource/after-ecj/DataOnLocalClass.java
+++ b/test/transform/resource/after-ecj/DataOnLocalClass.java
@@ -64,7 +64,7 @@ class DataOnLocalClass2 {
public @java.lang.SuppressWarnings("all") void setName(final @lombok.NonNull String name) {
if ((name == null))
{
- throw new java.lang.NullPointerException("name is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("name is marked non-null but is null");
}
this.name = name;
}
@@ -99,7 +99,7 @@ class DataOnLocalClass2 {
super();
if ((name == null))
{
- throw new java.lang.NullPointerException("name is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("name is marked non-null but is null");
}
this.name = name;
}
diff --git a/test/transform/resource/after-ecj/NonNullOnParameter.java b/test/transform/resource/after-ecj/NonNullOnParameter.java
index fde47e1d..4f873ab6 100644
--- a/test/transform/resource/after-ecj/NonNullOnParameter.java
+++ b/test/transform/resource/after-ecj/NonNullOnParameter.java
@@ -1,16 +1,18 @@
class NonNullOnParameter extends Thread {
+ <clinit>() {
+ }
NonNullOnParameter(@lombok.NonNull String arg) {
this(arg, "");
if ((arg == null))
{
- throw new java.lang.NullPointerException("arg is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("arg is marked non-null but is null");
}
}
NonNullOnParameter(@lombok.NonNull String arg, @lombok.NonNull String arg2) {
super(arg);
if ((arg2 == null))
{
- throw new java.lang.NullPointerException("arg2 is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("arg2 is marked non-null but is null");
}
if ((arg == null))
throw new NullPointerException();
@@ -18,11 +20,11 @@ class NonNullOnParameter extends Thread {
public void test2(@lombok.NonNull String arg, @lombok.NonNull String arg2, @lombok.NonNull String arg3) {
if ((arg == null))
{
- throw new java.lang.NullPointerException("arg is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("arg is marked non-null but is null");
}
if ((arg3 == null))
{
- throw new java.lang.NullPointerException("arg3 is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("arg3 is marked non-null but is null");
}
if ((arg2 == null))
{
@@ -34,7 +36,7 @@ class NonNullOnParameter extends Thread {
public void test3(@lombok.NonNull String arg) {
if ((arg == null))
{
- throw new java.lang.NullPointerException("arg is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("arg is marked non-null but is null");
}
if ((arg != null))
throw new IllegalStateException();
@@ -42,20 +44,26 @@ class NonNullOnParameter extends Thread {
public void test(@lombok.NonNull String stringArg, @lombok.NonNull String arg2, @lombok.NonNull int primitiveArg) {
if ((stringArg == null))
{
- throw new java.lang.NullPointerException("stringArg is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("stringArg is marked non-null but is null");
}
if ((arg2 == null))
{
- throw new java.lang.NullPointerException("arg2 is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("arg2 is marked non-null but is null");
}
}
public void test(@lombok.NonNull String arg) {
if ((arg == null))
{
- throw new java.lang.NullPointerException("arg is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("arg is marked non-null but is null");
}
System.out.println("Hey");
if ((arg == null))
throw new NullPointerException();
}
+ public void testWithAssert(@lombok.NonNull String param) {
+ assert (param != null);
+ }
+ public void testWithAssertAndMessage(@lombok.NonNull String param) {
+ assert (param != null): "Oops";
+ }
} \ No newline at end of file
diff --git a/test/transform/resource/after-ecj/NonNullOnParameterAbstract.java b/test/transform/resource/after-ecj/NonNullOnParameterAbstract.java
index d3e1fdd6..cc8ddcaa 100644
--- a/test/transform/resource/after-ecj/NonNullOnParameterAbstract.java
+++ b/test/transform/resource/after-ecj/NonNullOnParameterAbstract.java
@@ -5,7 +5,7 @@ abstract class NonNullOnParameterAbstract {
public void test(@lombok.NonNull String arg) {
if ((arg == null))
{
- throw new java.lang.NullPointerException("arg is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("arg is marked non-null but is null");
}
System.out.println("Hey");
}
diff --git a/test/transform/resource/after-ecj/NonNullOnParameterOfDefaultMethod.java b/test/transform/resource/after-ecj/NonNullOnParameterOfDefaultMethod.java
index 7293bcf5..830cff13 100644
--- a/test/transform/resource/after-ecj/NonNullOnParameterOfDefaultMethod.java
+++ b/test/transform/resource/after-ecj/NonNullOnParameterOfDefaultMethod.java
@@ -3,7 +3,7 @@ interface NonNullOnParameterOfDefaultMethod {
default void test2(@lombok.NonNull String arg) {
if ((arg == null))
{
- throw new java.lang.NullPointerException("arg is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("arg is marked non-null but is null");
}
System.out.println(arg);
}
diff --git a/test/transform/resource/after-ecj/NonNullPlain.java b/test/transform/resource/after-ecj/NonNullPlain.java
index c703f38a..bf43cb7f 100644
--- a/test/transform/resource/after-ecj/NonNullPlain.java
+++ b/test/transform/resource/after-ecj/NonNullPlain.java
@@ -9,7 +9,7 @@ import java.lang.annotation.*;
super();
if ((s == null))
{
- throw new java.lang.NullPointerException("s is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("s is marked non-null but is null");
}
this.i = i;
this.s = s;
@@ -29,7 +29,7 @@ import java.lang.annotation.*;
public @java.lang.SuppressWarnings("all") void setS(final @lombok.NonNull String s) {
if ((s == null))
{
- throw new java.lang.NullPointerException("s is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("s is marked non-null but is null");
}
this.s = s;
}
diff --git a/test/transform/resource/after-ecj/NonNullTypeUse.java b/test/transform/resource/after-ecj/NonNullTypeUse.java
index 4cf1aa5a..add140ea 100644
--- a/test/transform/resource/after-ecj/NonNullTypeUse.java
+++ b/test/transform/resource/after-ecj/NonNullTypeUse.java
@@ -6,13 +6,13 @@ class NonNullTypeUse {
void test1(@NonNull String[][][] args) {
if ((args == null))
{
- throw new java.lang.NullPointerException("args is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("args is marked non-null but is null");
}
}
void test2(String @NonNull [][][] args) {
if ((args == null))
{
- throw new java.lang.NullPointerException("args is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("args is marked non-null but is null");
}
}
void test3(String[] @NonNull [][] args) {
@@ -22,19 +22,19 @@ class NonNullTypeUse {
void test5(@NonNull String simple) {
if ((simple == null))
{
- throw new java.lang.NullPointerException("simple is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("simple is marked non-null but is null");
}
}
void test6(java.lang.@NonNull String weird) {
if ((weird == null))
{
- throw new java.lang.NullPointerException("weird is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("weird is marked non-null but is null");
}
}
void test7(java.lang.String @NonNull [][] weird) {
if ((weird == null))
{
- throw new java.lang.NullPointerException("weird is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("weird is marked non-null but is null");
}
}
} \ No newline at end of file
diff --git a/test/transform/resource/after-ecj/NonNullWithAlternateException.java b/test/transform/resource/after-ecj/NonNullWithAlternateException.java
index 39e9c0a8..9a2a4e3d 100644
--- a/test/transform/resource/after-ecj/NonNullWithAlternateException.java
+++ b/test/transform/resource/after-ecj/NonNullWithAlternateException.java
@@ -6,14 +6,14 @@ public class NonNullWithAlternateException {
public void testMethod(@lombok.NonNull String arg) {
if ((arg == null))
{
- throw new java.lang.IllegalArgumentException("arg is marked @NonNull but is null");
+ throw new java.lang.IllegalArgumentException("arg is marked non-null but is null");
}
System.out.println(arg);
}
public @java.lang.SuppressWarnings("all") void setTest(final @lombok.NonNull String test) {
if ((test == null))
{
- throw new java.lang.IllegalArgumentException("test is marked @NonNull but is null");
+ throw new java.lang.IllegalArgumentException("test is marked non-null but is null");
}
this.test = test;
}
diff --git a/test/transform/resource/after-ecj/NonNullWithAssertion.java b/test/transform/resource/after-ecj/NonNullWithAssertion.java
new file mode 100644
index 00000000..d6f2b0f1
--- /dev/null
+++ b/test/transform/resource/after-ecj/NonNullWithAssertion.java
@@ -0,0 +1,18 @@
+public class NonNullWithAssertion {
+ private @lombok.NonNull @lombok.Setter String test;
+ public NonNullWithAssertion() {
+ super();
+ }
+ public void testMethod(@lombok.NonNull String arg) {
+ assert (arg != null): "arg is marked non-null but is null";
+ System.out.println(arg);
+ }
+ public void testMethodWithIf(@lombok.NonNull String arg) {
+ if ((arg == null))
+ throw new NullPointerException("Oops");
+ }
+ public @java.lang.SuppressWarnings("all") void setTest(final @lombok.NonNull String test) {
+ assert (test != null): "test is marked non-null but is null";
+ this.test = test;
+ }
+} \ No newline at end of file
diff --git a/test/transform/resource/after-ecj/NonNullWithSneakyThrows.java b/test/transform/resource/after-ecj/NonNullWithSneakyThrows.java
index 22799b5e..ee08dbf8 100644
--- a/test/transform/resource/after-ecj/NonNullWithSneakyThrows.java
+++ b/test/transform/resource/after-ecj/NonNullWithSneakyThrows.java
@@ -7,7 +7,7 @@ class NonNullWithSneakyThrows {
{
if ((in == null))
{
- throw new java.lang.NullPointerException("in is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("in is marked non-null but is null");
}
System.out.println(in);
}
diff --git a/test/transform/resource/after-ecj/SetterOnClass.java b/test/transform/resource/after-ecj/SetterOnClass.java
index c7aec900..9ed77bd4 100644
--- a/test/transform/resource/after-ecj/SetterOnClass.java
+++ b/test/transform/resource/after-ecj/SetterOnClass.java
@@ -64,7 +64,7 @@
public @java.lang.SuppressWarnings("all") void setNonNull(final @lombok.NonNull String nonNull) {
if ((nonNull == null))
{
- throw new java.lang.NullPointerException("nonNull is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("nonNull is marked non-null but is null");
}
this.nonNull = nonNull;
}
diff --git a/test/transform/resource/after-ecj/SuperBuilderSingularAnnotatedTypes.java b/test/transform/resource/after-ecj/SuperBuilderSingularAnnotatedTypes.java
index bb02024d..9b89f2a8 100644
--- a/test/transform/resource/after-ecj/SuperBuilderSingularAnnotatedTypes.java
+++ b/test/transform/resource/after-ecj/SuperBuilderSingularAnnotatedTypes.java
@@ -19,7 +19,7 @@ import lombok.Singular;
public @java.lang.SuppressWarnings("all") B foo(final @MyAnnotation @NonNull String foo) {
if ((foo == null))
{
- throw new java.lang.NullPointerException("foo is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("foo is marked non-null but is null");
}
if ((this.foos == null))
this.foos = new java.util.ArrayList<@MyAnnotation @NonNull String>();
@@ -40,11 +40,11 @@ import lombok.Singular;
public @java.lang.SuppressWarnings("all") B bar(final @MyAnnotation @NonNull String barKey, final @MyAnnotation @NonNull Integer barValue) {
if ((barKey == null))
{
- throw new java.lang.NullPointerException("barKey is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("barKey is marked non-null but is null");
}
if ((barValue == null))
{
- throw new java.lang.NullPointerException("barValue is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("barValue is marked non-null but is null");
}
if ((this.bars$key == null))
{
diff --git a/test/transform/resource/after-ecj/SuperBuilderWithNonNull.java b/test/transform/resource/after-ecj/SuperBuilderWithNonNull.java
index 1c4bd53d..4b5cb188 100644
--- a/test/transform/resource/after-ecj/SuperBuilderWithNonNull.java
+++ b/test/transform/resource/after-ecj/SuperBuilderWithNonNull.java
@@ -41,7 +41,7 @@ public class SuperBuilderWithNonNull {
this.nonNullParentField = Parent.$default$nonNullParentField();
if ((nonNullParentField == null))
{
- throw new java.lang.NullPointerException("nonNullParentField is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("nonNullParentField is marked non-null but is null");
}
}
public static @java.lang.SuppressWarnings("all") ParentBuilder<?, ?> builder() {
@@ -81,7 +81,7 @@ public class SuperBuilderWithNonNull {
this.nonNullChildField = b.nonNullChildField;
if ((nonNullChildField == null))
{
- throw new java.lang.NullPointerException("nonNullChildField is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("nonNullChildField is marked non-null but is null");
}
}
public static @java.lang.SuppressWarnings("all") ChildBuilder<?, ?> builder() {
diff --git a/test/transform/resource/after-ecj/WitherOnClass.java b/test/transform/resource/after-ecj/WitherOnClass.java
index 086ba591..166d1842 100644
--- a/test/transform/resource/after-ecj/WitherOnClass.java
+++ b/test/transform/resource/after-ecj/WitherOnClass.java
@@ -34,7 +34,7 @@
public @java.lang.SuppressWarnings("all") WitherOnClass3 withNonNull(final @lombok.NonNull String nonNull) {
if ((nonNull == null))
{
- throw new java.lang.NullPointerException("nonNull is marked @NonNull but is null");
+ throw new java.lang.NullPointerException("nonNull is marked non-null but is null");
}
return ((this.nonNull == nonNull) ? this : new WitherOnClass3(this.couldBeNull, nonNull));
}
diff --git a/test/transform/resource/before/BuilderWithNoBuilderMethod.java b/test/transform/resource/before/BuilderWithNoBuilderMethod.java
new file mode 100644
index 00000000..3f2b21ac
--- /dev/null
+++ b/test/transform/resource/before/BuilderWithNoBuilderMethod.java
@@ -0,0 +1,5 @@
+import lombok.Builder;
+@Builder(toBuilder = true, builderMethodName = "")
+class BuilderWithNoBuilderMethod {
+ private String a = "";
+}
diff --git a/test/transform/resource/before/NonNullOnParameter.java b/test/transform/resource/before/NonNullOnParameter.java
index 7eb4c565..22aceac7 100644
--- a/test/transform/resource/before/NonNullOnParameter.java
+++ b/test/transform/resource/before/NonNullOnParameter.java
@@ -27,4 +27,13 @@ class NonNullOnParameter extends Thread {
System.out.println("Hey");
if (arg == null) throw new NullPointerException();
}
+
+ public void testWithAssert(@lombok.NonNull String param) {
+ assert param != null;
+ }
+
+ public void testWithAssertAndMessage(@lombok.NonNull String param) {
+ assert param != null : "Oops";
+ }
+
} \ No newline at end of file
diff --git a/test/transform/resource/before/NonNullWithAssertion.java b/test/transform/resource/before/NonNullWithAssertion.java
new file mode 100644
index 00000000..c3d271a6
--- /dev/null
+++ b/test/transform/resource/before/NonNullWithAssertion.java
@@ -0,0 +1,13 @@
+//CONF: lombok.nonNull.exceptionType = Assertion
+
+public class NonNullWithAssertion {
+ @lombok.NonNull @lombok.Setter private String test;
+
+ public void testMethod(@lombok.NonNull String arg) {
+ System.out.println(arg);
+ }
+
+ public void testMethodWithIf(@lombok.NonNull String arg) {
+ if (arg == null) throw new NullPointerException("Oops");
+ }
+}
diff --git a/test/transform/resource/messages-delombok/BuilderDefaultsWarnings.java.messages b/test/transform/resource/messages-delombok/BuilderDefaultsWarnings.java.messages
index 694511f8..c6590132 100644
--- a/test/transform/resource/messages-delombok/BuilderDefaultsWarnings.java.messages
+++ b/test/transform/resource/messages-delombok/BuilderDefaultsWarnings.java.messages
@@ -1,4 +1,4 @@
13 @Builder.Default requires @Builder on the class for it to mean anything.
-6 @Builder will ignore the initializing expression entirely. If you want the initializing expression to serve as default, add @Builder.Default. If it is not supposed to be settable during building, make the field final.
8 @Builder.Default requires an initializing expression (' = something;').
9 @Builder.Default and @Singular cannot be mixed.
+6 @Builder will ignore the initializing expression entirely. If you want the initializing expression to serve as default, add @Builder.Default. If it is not supposed to be settable during building, make the field final.
diff --git a/website/resources/css/custom.css b/website/resources/css/custom.css
index 2815fd21..6774a7d5 100644
--- a/website/resources/css/custom.css
+++ b/website/resources/css/custom.css
@@ -1,3 +1,10 @@
+.importantNotification {
+ background-color: #FFEBCD;
+ border-radius: 20px;
+ padding: 10px;
+ margin: 10px;
+}
+
#clickForVideo {
padding: 20px 30px;
background-color: #DDD;
diff --git a/website/templates/features/Builder.html b/website/templates/features/Builder.html
index 082b97ed..0818f9d2 100644
--- a/website/templates/features/Builder.html
+++ b/website/templates/features/Builder.html
@@ -10,6 +10,8 @@
<code>@Builder</code> with <code>@Singular</code> adds a clear method since lombok v1.16.8.
</p><p>
<code>@Builder.Default</code> functionality was added in lombok v1.16.16.
+ </p><p>
+ <code>@Builder(builderMethodName = "")</code> is legal (and will suppress generation of the builder method) starting with lombok v1.18.8.
</p>
</@f.history>
@@ -184,6 +186,13 @@ public class JacksonExample {
</p><p>
Various well known annotations about nullity cause null checks to be inserted and will be copied to parameter of the builder's 'setter' method. See <a href="/features/GetterSetter">Getter/Setter</a> documentation's small print for more information.
</p><p>
+ You can suppress the generation of the <code>builder()</code> method, for example because you <em>just</em> want the <code>toBuilder()</code> functionality, by using:
+ <code>@Builder(builderMethodName = "")</code>. Any warnings about missing <code>@Builder.Default</code> annotations will disappear when you do this, as such warnings
+ are not relevant when only using <code>toBuilder()</code> to make builder instances.
+ </p><p>
+ You can use <code>@Builder</code> for copy constructors: <code>foo.toBuilder().build()</code> makes a shallow clone. Consider suppressing the generating of the
+ <code>builder</code> method if you just want this functionality, by using: <code>@Builder(toBuilder = true, builderMethodName = "")</code>.
+ </p><p>
Due to a peculiar way javac processes static imports, trying to do a non-star static import of the static <code>builder()</code> method won't work. Either use a star static import: `import static TypeThatHasABuilder.*;` or don't statically import the <code>builder</code> method.
</p>
</@f.smallPrint>
diff --git a/website/templates/features/NonNull.html b/website/templates/features/NonNull.html
index 66ab2fc2..e01a3088 100644
--- a/website/templates/features/NonNull.html
+++ b/website/templates/features/NonNull.html
@@ -21,9 +21,9 @@
<@f.confKeys>
<dt>
- <code>lombok.nonNull.exceptionType</code> = [<code>NullPointerException</code> | <code>IllegalArgumentException</code>] (default: <code>NullPointerException</code>).
+ <code>lombok.nonNull.exceptionType</code> = [<code>NullPointerException</code> | <code>IllegalArgumentException</code> | <code>Assertion</code>] (default: <code>NullPointerException</code>).
</dt><dd>
- When lombok generates a null-check <code>if</code> statement, by default, a <code>java.lang.NullPointerException</code> will be thrown with '<em>field name</em> is marked @NonNull but is null' as the exception message. However, you can use <code>IllegalArgumentException</code> in this configuration key to have lombok throw that exception with this message instead.
+ When lombok generates a null-check <code>if</code> statement, by default, a <code>java.lang.NullPointerException</code> will be thrown with '<em>field name</em> is marked non-null but is null' as the exception message. However, you can use <code>IllegalArgumentException</code> in this configuration key to have lombok throw that exception with this message instead. By using <code>Assertion</code>, an <code>assert</code> statement with the same message will be generated.
</dd><dt>
<code>lombok.nonNull.flagUsage</code> = [<code>warning</code> | <code>error</code>] (default: not set)
</dt><dd>
@@ -33,7 +33,7 @@
<@f.smallPrint>
<p>
- Lombok's detection scheme for already existing null-checks consists of scanning for if statements that look just like lombok's own. Any 'throws' statement as the 'then' part of the if statement, whether in braces or not, counts. The conditional of the if statement <em>must</em> look exactly like <code>PARAMNAME == null</code>. The first statement in your method that is not such a null-check stops the process of inspecting for null-checks.
+ Lombok's detection scheme for already existing null-checks consists of scanning for if statements or assert statements that look just like lombok's own. Any 'throws' statement as the 'then' part of the if statement, whether in braces or not, counts. The conditional of the if statement <em>must</em> look exactly like <code>PARAMNAME == null</code>; the assert statement <em>must</em> look exactly like <code>PARAMNAME != null</code>. The first statement in your method that is not such a null-check stops the process of inspecting for null-checks.
</p><p>
While <code>@Data</code> and other method-generating lombok annotations will trigger on various well-known annotations that signify the field must never be <code>@NonNull</code>, this feature only triggers on lombok's own <code>@NonNull</code> annotation from the <code>lombok</code> package.
</p><p>
diff --git a/website/templates/features/configuration.html b/website/templates/features/configuration.html
index 09cd46c2..7a15f252 100644
--- a/website/templates/features/configuration.html
+++ b/website/templates/features/configuration.html
@@ -84,7 +84,7 @@
<code>lombok.addJavaxGeneratedAnnotation = true</code>
</div>
We advise against this; JDK9 breaks this annotation, and it's unlikely to ever get fixed.<br />
- <em>NB:</em> Until Lombok v2.0.0, this setting defaulted to <code>true</code>.
+ <em>NB:</em> Until Lombok v1.16.20, this setting defaulted to <code>true</code>.
</p><p>
Lombok can be configured to add <code>@lombok.Generated</code> annotations to all generated nodes where possible; useful for JaCoCo (which has built in support),
or other style checkers and code coverage tools:
diff --git a/website/templates/features/var.html b/website/templates/features/var.html
index 60e24914..bf28752f 100644
--- a/website/templates/features/var.html
+++ b/website/templates/features/var.html
@@ -3,7 +3,7 @@
<@f.scaffold title="var" logline="Mutably! Hassle-free local variables.">
<@f.history>
<p><ul>
- <li><code>var</code> was promoted to the main package in lombok 2.0.0; given that <a href="http://openjdk.java.net/jeps/286">JEP 286</a> establishes expectations, and lombok's take on <code>var</code> follows these, we've decided to promote <code>var</code> eventhough the feature remains controversial.</li>
+ <li><code>var</code> was promoted to the main package in lombok 1.16.20; given that <a href="http://openjdk.java.net/jeps/286">JEP 286</a> establishes expectations, and lombok's take on <code>var</code> follows these, we've decided to promote <code>var</code> eventhough the feature remains controversial.</li>
<li><code>var</code> was introduced in lombok 1.16.12 as experimental feature.</li>
</ul></p>
</@f.history>