mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-13 14:16:11 +00:00
Merge pull request #3137 from JohnPaulTaylorII/master
[fixes #3133] Additional bits setting when creating type annotations
This commit is contained in:
7 files changed
+26
-17
No files matched your search
@@ -2601,25 +2601,25 @@ public class EclipseHandlerUtil {
|
||||
applyAnnotationToMethodDecl(typeNode, mth, lib.getNonNullAnnotation(), lib.isTypeUse());
|
||||
}
|
||||
|
||||
public static void createRelevantNullableAnnotation(EclipseNode typeNode, Argument arg) {
|
||||
public static void createRelevantNullableAnnotation(EclipseNode typeNode, Argument arg, MethodDeclaration mth) {
|
||||
NullAnnotationLibrary lib = typeNode.getAst().readConfiguration(ConfigurationKeys.ADD_NULL_ANNOTATIONS);
|
||||
if (lib == null) return;
|
||||
|
||||
applyAnnotationToVarDecl(typeNode, arg, lib.getNullableAnnotation(), lib.isTypeUse());
|
||||
applyAnnotationToVarDecl(typeNode, arg, mth, lib.getNullableAnnotation(), lib.isTypeUse());
|
||||
}
|
||||
|
||||
public static void createRelevantNullableAnnotation(EclipseNode typeNode, Argument arg, List<NullAnnotationLibrary> applied) {
|
||||
public static void createRelevantNullableAnnotation(EclipseNode typeNode, Argument arg, MethodDeclaration mth, List<NullAnnotationLibrary> applied) {
|
||||
NullAnnotationLibrary lib = typeNode.getAst().readConfiguration(ConfigurationKeys.ADD_NULL_ANNOTATIONS);
|
||||
if (lib == null || applied.contains(lib)) return;
|
||||
|
||||
applyAnnotationToVarDecl(typeNode, arg, lib.getNullableAnnotation(), lib.isTypeUse());
|
||||
applyAnnotationToVarDecl(typeNode, arg, mth, lib.getNullableAnnotation(), lib.isTypeUse());
|
||||
}
|
||||
|
||||
public static void createRelevantNonNullAnnotation(EclipseNode typeNode, Argument arg) {
|
||||
public static void createRelevantNonNullAnnotation(EclipseNode typeNode, Argument arg, MethodDeclaration mth) {
|
||||
NullAnnotationLibrary lib = typeNode.getAst().readConfiguration(ConfigurationKeys.ADD_NULL_ANNOTATIONS);
|
||||
if (lib == null) return;
|
||||
|
||||
applyAnnotationToVarDecl(typeNode, arg, lib.getNonNullAnnotation(), lib.isTypeUse());
|
||||
applyAnnotationToVarDecl(typeNode, arg, mth, lib.getNonNullAnnotation(), lib.isTypeUse());
|
||||
}
|
||||
|
||||
private static void applyAnnotationToMethodDecl(EclipseNode typeNode, MethodDeclaration mth, String annType, boolean typeUse) {
|
||||
@@ -2653,9 +2653,10 @@ public class EclipseHandlerUtil {
|
||||
}
|
||||
a[0] = ann;
|
||||
mth.returnType.annotations[len - 1] = a;
|
||||
mth.bits |= Eclipse.HasTypeAnnotations;
|
||||
}
|
||||
}
|
||||
private static void applyAnnotationToVarDecl(EclipseNode typeNode, Argument arg, String annType, boolean typeUse) {
|
||||
private static void applyAnnotationToVarDecl(EclipseNode typeNode, Argument arg, MethodDeclaration mth, String annType, boolean typeUse) {
|
||||
if (annType == null) return;
|
||||
|
||||
int partCount = 1;
|
||||
@@ -2686,6 +2687,9 @@ public class EclipseHandlerUtil {
|
||||
}
|
||||
a[0] = ann;
|
||||
arg.type.annotations[len - 1] = a;
|
||||
arg.type.bits |= Eclipse.HasTypeAnnotations;
|
||||
arg.bits |= Eclipse.HasTypeAnnotations;
|
||||
mth.bits |= Eclipse.HasTypeAnnotations;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ import org.eclipse.jdt.internal.compiler.ast.FieldReference;
|
||||
import org.eclipse.jdt.internal.compiler.ast.IfStatement;
|
||||
import org.eclipse.jdt.internal.compiler.ast.IntLiteral;
|
||||
import org.eclipse.jdt.internal.compiler.ast.MessageSend;
|
||||
import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
|
||||
import org.eclipse.jdt.internal.compiler.ast.NullLiteral;
|
||||
import org.eclipse.jdt.internal.compiler.ast.OperatorIds;
|
||||
import org.eclipse.jdt.internal.compiler.ast.ParameterizedQualifiedTypeReference;
|
||||
@@ -430,7 +431,7 @@ public class EclipseSingularsRecipes {
|
||||
}
|
||||
}
|
||||
|
||||
protected void nullBehaviorize(EclipseNode typeNode, SingularData data, List<Statement> statements, Argument arg) {
|
||||
protected void nullBehaviorize(EclipseNode typeNode, SingularData data, List<Statement> statements, Argument arg, MethodDeclaration md) {
|
||||
boolean ignoreNullCollections = data.isIgnoreNullCollections();
|
||||
|
||||
if (ignoreNullCollections) {
|
||||
@@ -439,11 +440,11 @@ public class EclipseSingularsRecipes {
|
||||
b.statements = statements.toArray(new Statement[statements.size()]);
|
||||
statements.clear();
|
||||
statements.add(new IfStatement(isNotNull, b, 0, 0));
|
||||
EclipseHandlerUtil.createRelevantNullableAnnotation(typeNode, arg);
|
||||
EclipseHandlerUtil.createRelevantNullableAnnotation(typeNode, arg, md);
|
||||
return;
|
||||
}
|
||||
|
||||
EclipseHandlerUtil.createRelevantNonNullAnnotation(typeNode, arg);
|
||||
EclipseHandlerUtil.createRelevantNonNullAnnotation(typeNode, arg, md);
|
||||
Statement nullCheck = EclipseHandlerUtil.generateNullCheck(null, data.getPluralName(), typeNode, "%s cannot be null");
|
||||
statements.add(0, nullCheck);
|
||||
}
|
||||
|
||||
@@ -642,13 +642,17 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH
|
||||
method.bodyStart = method.declarationSourceStart = method.sourceStart = source.sourceStart;
|
||||
method.bodyEnd = method.declarationSourceEnd = method.sourceEnd = source.sourceEnd;
|
||||
QualifiedTypeReference objectRef = new QualifiedTypeReference(TypeConstants.JAVA_LANG_OBJECT, new long[] { p, p, p });
|
||||
if (onParamTypeNullable != null) objectRef.annotations = new Annotation[][] {null, null, onParamTypeNullable};
|
||||
if (onParamTypeNullable != null) {
|
||||
objectRef.annotations = new Annotation[][] {null, null, onParamTypeNullable};
|
||||
objectRef.bits |= Eclipse.HasTypeAnnotations;
|
||||
method.bits |= Eclipse.HasTypeAnnotations;
|
||||
}
|
||||
setGeneratedBy(objectRef, source);
|
||||
method.arguments = new Argument[] {new Argument(new char[] { 'o' }, 0, objectRef, Modifier.FINAL)};
|
||||
method.arguments[0].sourceStart = pS; method.arguments[0].sourceEnd = pE;
|
||||
if (!onParam.isEmpty() || onParamNullable != null)
|
||||
method.arguments[0].annotations = copyAnnotations(source, onParam.toArray(new Annotation[0]), onParamNullable);
|
||||
EclipseHandlerUtil.createRelevantNullableAnnotation(type, method.arguments[0], applied);
|
||||
EclipseHandlerUtil.createRelevantNullableAnnotation(type, method.arguments[0], method, applied);
|
||||
setGeneratedBy(method.arguments[0], source);
|
||||
|
||||
List<Statement> statements = new ArrayList<Statement>();
|
||||
@@ -898,7 +902,7 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH
|
||||
method.arguments = new Argument[] {new Argument(otherName, 0, objectRef, Modifier.FINAL)};
|
||||
method.arguments[0].sourceStart = pS; method.arguments[0].sourceEnd = pE;
|
||||
if (!onParam.isEmpty()) method.arguments[0].annotations = onParam.toArray(new Annotation[0]);
|
||||
EclipseHandlerUtil.createRelevantNullableAnnotation(type, method.arguments[0]);
|
||||
EclipseHandlerUtil.createRelevantNullableAnnotation(type, method.arguments[0], method);
|
||||
setGeneratedBy(method.arguments[0], source);
|
||||
|
||||
SingleNameReference otherRef = new SingleNameReference(otherName, p);
|
||||
|
||||
@@ -373,7 +373,7 @@ public class HandleWithBy extends EclipseAnnotationHandler<WithBy> {
|
||||
method.statements = statements.toArray(new Statement[0]);
|
||||
}
|
||||
|
||||
createRelevantNonNullAnnotation(sourceNode, param);
|
||||
createRelevantNonNullAnnotation(sourceNode, param, method);
|
||||
createRelevantNonNullAnnotation(fieldNode, method);
|
||||
|
||||
method.traverse(new SetGeneratedByVisitor(source), parent.scope);
|
||||
|
||||
@@ -207,7 +207,7 @@ abstract class EclipseGuavaSingularizer extends EclipseSingularizer {
|
||||
paramType = addTypeArgs(getTypeArgumentsCount(), true, builderType, paramType, data.getTypeArgs());
|
||||
Argument param = new Argument(data.getPluralName(), 0, paramType, ClassFileConstants.AccFinal);
|
||||
|
||||
nullBehaviorize(builderType, data, statements, param);
|
||||
nullBehaviorize(builderType, data, statements, param, md);
|
||||
|
||||
if (returnStatement != null) statements.add(returnStatement);
|
||||
|
||||
|
||||
@@ -184,7 +184,7 @@ abstract class EclipseJavaUtilListSetSingularizer extends EclipseJavaUtilSingula
|
||||
paramType = addTypeArgs(1, true, builderType, paramType, data.getTypeArgs());
|
||||
Argument param = new Argument(data.getPluralName(), 0, paramType, ClassFileConstants.AccFinal);
|
||||
|
||||
nullBehaviorize(builderType, data, statements, param);
|
||||
nullBehaviorize(builderType, data, statements, param, md);
|
||||
if (returnStatement != null) statements.add(returnStatement);
|
||||
|
||||
md.statements = statements.toArray(new Statement[0]);
|
||||
|
||||
@@ -316,7 +316,7 @@ public class EclipseJavaUtilMapSingularizer extends EclipseJavaUtilSingularizer
|
||||
paramType = addTypeArgs(2, true, builderType, paramType, data.getTypeArgs());
|
||||
Argument param = new Argument(data.getPluralName(), 0, paramType, ClassFileConstants.AccFinal);
|
||||
|
||||
nullBehaviorize(builderType, data, statements, param);
|
||||
nullBehaviorize(builderType, data, statements, param, md);
|
||||
|
||||
if (returnStatement != null) statements.add(returnStatement);
|
||||
|
||||
|
||||
Reference in new issue
Block a user