mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 18:18:48 +00:00
Merge branch 'kchirls-master'
This commit is contained in:
commit
49a4342088
7 files changed
+86
-6
No files matched your search
@@ -7,6 +7,7 @@ Dave Brosius <dbrosius@mebigfatguy.com>
|
||||
Dawid Rusin <dawidrusin90@gmail.com>
|
||||
Enrique da Costa Cambio <enrique.dacostacambio@gmail.com>
|
||||
Jappe van der Hel <jappe.vanderhel@gmail.com>
|
||||
Kevin Chirls <kchirls@users.noreply.github.com>
|
||||
Liu DongMiao <liudongmiao@gmail.com>
|
||||
Luan Nico <luannico27@gmail.com>
|
||||
Maarten Mulders <mthmulders@users.noreply.github.com>
|
||||
|
||||
@@ -350,7 +350,7 @@ public class HandleConstructor {
|
||||
Annotation[] nonNulls = findAnnotations(field, NON_NULL_PATTERN);
|
||||
Annotation[] nullables = findAnnotations(field, NULLABLE_PATTERN);
|
||||
if (nonNulls.length != 0) {
|
||||
Statement nullCheck = generateNullCheck(field, sourceNode);
|
||||
Statement nullCheck = generateNullCheck(parameter, sourceNode);
|
||||
if (nullCheck != null) nullChecks.add(nullCheck);
|
||||
}
|
||||
parameter.annotations = copyAnnotations(source, nonNulls, nullables);
|
||||
|
||||
@@ -289,7 +289,7 @@ public class HandleConstructor {
|
||||
JCVariableDecl param = maker.VarDef(maker.Modifiers(flags, nonNulls.appendList(nullables)), fieldName, field.vartype, null);
|
||||
params.append(param);
|
||||
if (!nonNulls.isEmpty()) {
|
||||
JCStatement nullCheck = generateNullCheck(maker, fieldNode, source);
|
||||
JCStatement nullCheck = generateNullCheck(maker, fieldNode, param, source);
|
||||
if (nullCheck != null) nullChecks.append(nullCheck);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1211,16 +1211,25 @@ public class JavacHandlerUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a new statement that checks if the given variable is null, and if so, throws a specified exception with the
|
||||
* Generates a new statement that checks if the given variable is null, and if so, throws a configured exception with the
|
||||
* variable name as message.
|
||||
*
|
||||
* @param exName The name of the exception to throw; normally {@code java.lang.NullPointerException}.
|
||||
*/
|
||||
public static JCStatement generateNullCheck(JavacTreeMaker maker, JavacNode variable, JavacNode source) {
|
||||
return generateNullCheck(maker, variable, (JCVariableDecl)variable.get(), source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a new statement that checks if the given variable is null, and if so, throws a configured exception with the
|
||||
* variable name as message.
|
||||
*
|
||||
* This is a special case method reserved for use when the provided declaration differs from the
|
||||
* variable's declaration, i.e. in a constructor or setter where the local parameter is named the same but with the prefix
|
||||
* stripped as a result of @Accessors.prefix.
|
||||
*/
|
||||
public static JCStatement generateNullCheck(JavacTreeMaker maker, JavacNode variable, JCVariableDecl varDecl, JavacNode source) {
|
||||
NullCheckExceptionType exceptionType = source.getAst().readConfiguration(ConfigurationKeys.NON_NULL_EXCEPTION_TYPE);
|
||||
if (exceptionType == null) exceptionType = NullCheckExceptionType.NULL_POINTER_EXCEPTION;
|
||||
|
||||
JCVariableDecl varDecl = (JCVariableDecl) variable.get();
|
||||
if (isPrimitive(varDecl.vartype)) return null;
|
||||
Name fieldName = varDecl.name;
|
||||
JCExpression exType = genTypeRef(variable, exceptionType.getExceptionType());
|
||||
|
||||
@@ -14,3 +14,36 @@ class ConstructorsWithAccessors {
|
||||
this.__huh2 = _huh2;
|
||||
}
|
||||
}
|
||||
|
||||
class ConstructorsWithAccessorsNonNull {
|
||||
@lombok.NonNull
|
||||
Integer plower;
|
||||
@lombok.NonNull
|
||||
Integer pUpper;
|
||||
@lombok.NonNull
|
||||
Integer _huh;
|
||||
@lombok.NonNull
|
||||
final Integer __huh2;
|
||||
|
||||
@java.beans.ConstructorProperties({"plower", "upper", "huh", "_huh2"})
|
||||
@java.lang.SuppressWarnings("all")
|
||||
@javax.annotation.Generated("lombok")
|
||||
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");
|
||||
}
|
||||
if (upper == null) {
|
||||
throw new java.lang.NullPointerException("upper");
|
||||
}
|
||||
if (huh == null) {
|
||||
throw new java.lang.NullPointerException("huh");
|
||||
}
|
||||
if (_huh2 == null) {
|
||||
throw new java.lang.NullPointerException("_huh2");
|
||||
}
|
||||
this.plower = plower;
|
||||
this.pUpper = upper;
|
||||
this._huh = huh;
|
||||
this.__huh2 = _huh2;
|
||||
}
|
||||
}
|
||||
@@ -11,3 +11,32 @@
|
||||
this.__huh2 = _huh2;
|
||||
}
|
||||
}
|
||||
@lombok.AllArgsConstructor @lombok.experimental.Accessors(prefix = {"p", "_"}) class ConstructorsWithAccessorsNonNull {
|
||||
@lombok.NonNull Integer plower;
|
||||
@lombok.NonNull Integer pUpper;
|
||||
@lombok.NonNull Integer _huh;
|
||||
final @lombok.NonNull Integer __huh2;
|
||||
public @java.beans.ConstructorProperties({"plower", "upper", "huh", "_huh2"}) @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") ConstructorsWithAccessorsNonNull(final @lombok.NonNull Integer plower, final @lombok.NonNull Integer upper, final @lombok.NonNull Integer huh, final @lombok.NonNull Integer _huh2) {
|
||||
super();
|
||||
if ((plower == null))
|
||||
{
|
||||
throw new java.lang.NullPointerException("plower");
|
||||
}
|
||||
if ((upper == null))
|
||||
{
|
||||
throw new java.lang.NullPointerException("upper");
|
||||
}
|
||||
if ((huh == null))
|
||||
{
|
||||
throw new java.lang.NullPointerException("huh");
|
||||
}
|
||||
if ((_huh2 == null))
|
||||
{
|
||||
throw new java.lang.NullPointerException("_huh2");
|
||||
}
|
||||
this.plower = plower;
|
||||
this.pUpper = upper;
|
||||
this._huh = huh;
|
||||
this.__huh2 = _huh2;
|
||||
}
|
||||
}
|
||||
@@ -4,3 +4,11 @@
|
||||
int _huh;
|
||||
int __huh2;
|
||||
}
|
||||
|
||||
@lombok.AllArgsConstructor @lombok.experimental.Accessors(prefix={"p", "_"}) class ConstructorsWithAccessorsNonNull {
|
||||
@lombok.NonNull Integer plower;
|
||||
@lombok.NonNull Integer pUpper;
|
||||
@lombok.NonNull Integer _huh;
|
||||
@lombok.NonNull final Integer __huh2;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user