mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-15 02:17:12 +00:00
fix: Don't alter the AST node positions of original code.
This commit is contained in:
1 parent
9f5de53e06
commit
b313df556d
9 files changed
+22
-17
No files matched your search
@@ -364,7 +364,7 @@ public class HandleConstructor {
|
||||
if (addConstructorProperties && !isLocalType(typeNode) && LombokOptionsFactory.getDelombokOptions(typeNode.getContext()).getFormatPreferences().generateConstructorProperties()) {
|
||||
addConstructorProperties(mods, typeNode, fieldsToParam);
|
||||
}
|
||||
if (onConstructor != null) mods.annotations = mods.annotations.appendList(copyAnnotations(onConstructor));
|
||||
if (onConstructor != null) mods.annotations = mods.annotations.appendList(copyAnnotations(onConstructor, maker));
|
||||
return recursiveSetGeneratedBy(maker.MethodDef(mods, typeNode.toName("<init>"),
|
||||
null, List.<JCTypeParameter>nil(), params.toList(), List.<JCExpression>nil(),
|
||||
maker.Block(0L, nullChecks.appendList(assigns).toList()), null), source);
|
||||
|
||||
@@ -190,7 +190,7 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
|
||||
injectMethod(typeNode, equalsMethod);
|
||||
|
||||
if (needsCanEqual && canEqualExists == MemberExistsResult.NOT_EXISTS) {
|
||||
JCMethodDecl canEqualMethod = createCanEqual(typeNode, source, copyAnnotations(onParam));
|
||||
JCMethodDecl canEqualMethod = createCanEqual(typeNode, source, copyAnnotations(onParam, typeNode.getTreeMaker()));
|
||||
injectMethod(typeNode, canEqualMethod);
|
||||
}
|
||||
|
||||
|
||||
@@ -250,7 +250,7 @@ public class HandleGetter extends JavacAnnotationHandler<Getter> {
|
||||
|
||||
List<JCAnnotation> copyableAnnotations = findCopyableAnnotations(field);
|
||||
List<JCAnnotation> delegates = findDelegatesAndRemoveFromField(field);
|
||||
List<JCAnnotation> annsOnMethod = copyAnnotations(onMethod).appendList(copyableAnnotations);
|
||||
List<JCAnnotation> annsOnMethod = copyAnnotations(onMethod, field.getTreeMaker()).appendList(copyableAnnotations);
|
||||
if (field.isFinal()) {
|
||||
if (getCheckerFrameworkVersion(field).generatePure()) annsOnMethod = annsOnMethod.prepend(treeMaker.Annotation(genTypeRef(field, CheckerFrameworkVersion.NAME__PURE), List.<JCExpression>nil()));
|
||||
} else {
|
||||
|
||||
@@ -136,7 +136,7 @@ public class HandleJacksonized extends JavacAnnotationHandler<Jacksonized> {
|
||||
|
||||
// Copy annotations from the class to the builder class.
|
||||
List<JCAnnotation> copyableAnnotations = findJacksonAnnotationsOnClass(tdNode);
|
||||
List<JCAnnotation> copiedAnnotations = copyAnnotations(copyableAnnotations);
|
||||
List<JCAnnotation> copiedAnnotations = copyAnnotations(copyableAnnotations, maker);
|
||||
for (JCAnnotation anno : copiedAnnotations) {
|
||||
recursiveSetGeneratedBy(anno, annotationNode);
|
||||
}
|
||||
|
||||
@@ -241,7 +241,7 @@ public class HandleSetter extends JavacAnnotationHandler<Setter> {
|
||||
List<JCAnnotation> copyableAnnotations = findCopyableAnnotations(field);
|
||||
|
||||
Name methodName = field.toName(setterName);
|
||||
List<JCAnnotation> annsOnParam = copyAnnotations(onParam).appendList(copyableAnnotations);
|
||||
List<JCAnnotation> annsOnParam = copyAnnotations(onParam, treeMaker).appendList(copyableAnnotations);
|
||||
|
||||
long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, field.getContext());
|
||||
JCExpression pType = cloneType(treeMaker, fieldDecl.vartype, source);
|
||||
@@ -274,7 +274,7 @@ public class HandleSetter extends JavacAnnotationHandler<Setter> {
|
||||
List<JCExpression> throwsClauses = List.nil();
|
||||
JCExpression annotationMethodDefaultValue = null;
|
||||
|
||||
List<JCAnnotation> annsOnMethod = mergeAnnotations(copyAnnotations(onMethod), findCopyableToSetterAnnotations(field));
|
||||
List<JCAnnotation> annsOnMethod = mergeAnnotations(copyAnnotations(onMethod, treeMaker), findCopyableToSetterAnnotations(field));
|
||||
if (isFieldDeprecated(field) || deprecate) {
|
||||
annsOnMethod = annsOnMethod.prepend(treeMaker.Annotation(genJavaLangTypeRef(field, "Deprecated"), List.<JCExpression>nil()));
|
||||
}
|
||||
|
||||
@@ -229,7 +229,7 @@ public class HandleWith extends JavacAnnotationHandler<With> {
|
||||
|
||||
JCBlock methodBody = null;
|
||||
long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, field.getContext());
|
||||
List<JCAnnotation> annsOnParam = copyAnnotations(onParam).appendList(copyableAnnotations);
|
||||
List<JCAnnotation> annsOnParam = copyAnnotations(onParam, maker).appendList(copyableAnnotations);
|
||||
|
||||
JCExpression pType = cloneType(maker, fieldDecl.vartype, source);
|
||||
JCVariableDecl param = maker.VarDef(maker.Modifiers(flags, annsOnParam), fieldDecl.name, pType, null);
|
||||
@@ -278,7 +278,7 @@ public class HandleWith extends JavacAnnotationHandler<With> {
|
||||
List<JCExpression> throwsClauses = List.nil();
|
||||
JCExpression annotationMethodDefaultValue = null;
|
||||
|
||||
List<JCAnnotation> annsOnMethod = copyAnnotations(onMethod);
|
||||
List<JCAnnotation> annsOnMethod = copyAnnotations(onMethod, maker);
|
||||
CheckerFrameworkVersion checkerFramework = getCheckerFrameworkVersion(source);
|
||||
if (checkerFramework.generateSideEffectFree()) annsOnMethod = annsOnMethod.prepend(maker.Annotation(genTypeRef(source, CheckerFrameworkVersion.NAME__SIDE_EFFECT_FREE), List.<JCExpression>nil()));
|
||||
|
||||
|
||||
@@ -321,7 +321,7 @@ public class HandleWithBy extends JavacAnnotationHandler<WithBy> {
|
||||
List<JCExpression> throwsClauses = List.nil();
|
||||
JCExpression annotationMethodDefaultValue = null;
|
||||
|
||||
List<JCAnnotation> annsOnMethod = copyAnnotations(onMethod);
|
||||
List<JCAnnotation> annsOnMethod = copyAnnotations(onMethod, maker);
|
||||
CheckerFrameworkVersion checkerFramework = getCheckerFrameworkVersion(source);
|
||||
if (checkerFramework.generateSideEffectFree()) annsOnMethod = annsOnMethod.prepend(maker.Annotation(genTypeRef(source, CheckerFrameworkVersion.NAME__SIDE_EFFECT_FREE), List.<JCExpression>nil()));
|
||||
|
||||
|
||||
@@ -1746,7 +1746,8 @@ public class JavacHandlerUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
return copyAnnotations(result.toList());
|
||||
|
||||
return copyAnnotations(result.toList(), node.getTreeMaker());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1784,7 +1785,7 @@ public class JavacHandlerUtil {
|
||||
if (annoName == null) return List.nil();
|
||||
|
||||
if (!annoName.isEmpty()) {
|
||||
for (String bn : annotationsToFind) if (typeMatches(bn, node, annoName)) return List.of(anno);
|
||||
for (String bn : annotationsToFind) if (typeMatches(bn, node, annoName)) return copyAnnotations(List.of(anno), node.getTreeMaker());
|
||||
}
|
||||
|
||||
ListBuffer<JCAnnotation> result = new ListBuffer<JCAnnotation>();
|
||||
@@ -1799,7 +1800,7 @@ public class JavacHandlerUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
return copyAnnotations(result.toList());
|
||||
return copyAnnotations(result.toList(), node.getTreeMaker());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2108,14 +2109,18 @@ public class JavacHandlerUtil {
|
||||
errorNode.addError(out.append(" are not allowed on builder classes.").toString());
|
||||
}
|
||||
|
||||
static List<JCAnnotation> copyAnnotations(List<? extends JCExpression> in) {
|
||||
static List<JCAnnotation> copyAnnotations(List<? extends JCExpression> in, JavacTreeMaker maker) {
|
||||
ListBuffer<JCAnnotation> out = new ListBuffer<JCAnnotation>();
|
||||
for (JCExpression expr : in) {
|
||||
if (!(expr instanceof JCAnnotation)) continue;
|
||||
out.append((JCAnnotation) expr.clone());
|
||||
out.append(copyAnnotation((JCAnnotation) expr, maker));
|
||||
}
|
||||
return out.toList();
|
||||
}
|
||||
|
||||
static JCAnnotation copyAnnotation(JCAnnotation annotation, JavacTreeMaker maker) {
|
||||
return maker.Annotation(annotation.annotationType, annotation.args);
|
||||
}
|
||||
|
||||
static List<JCAnnotation> mergeAnnotations(List<JCAnnotation> a, List<JCAnnotation> b) {
|
||||
if (a == null || a.isEmpty()) return b;
|
||||
@@ -2266,7 +2271,7 @@ public class JavacHandlerUtil {
|
||||
|
||||
if (JCAnnotatedTypeReflect.is(in)) {
|
||||
JCExpression underlyingType = cloneType0(maker, JCAnnotatedTypeReflect.getUnderlyingType(in));
|
||||
List<JCAnnotation> anns = copyAnnotations(JCAnnotatedTypeReflect.getAnnotations(in));
|
||||
List<JCAnnotation> anns = copyAnnotations(JCAnnotatedTypeReflect.getAnnotations(in), maker);
|
||||
return JCAnnotatedTypeReflect.create(anns, underlyingType);
|
||||
}
|
||||
|
||||
|
||||
@@ -315,7 +315,7 @@ public class JavacSingularsRecipes {
|
||||
if (!setterPrefix.isEmpty()) name = builderType.toName(HandlerUtil.buildAccessorName(source, setterPrefix, name.toString()));
|
||||
|
||||
statements.prepend(createConstructBuilderVarIfNeeded(maker, data, builderType, source));
|
||||
List<JCAnnotation> methodAnnotations = copyAnnotations(findCopyableToBuilderSingularSetterAnnotations(data.annotation.up()));
|
||||
List<JCAnnotation> methodAnnotations = copyAnnotations(findCopyableToBuilderSingularSetterAnnotations(data.annotation.up()), maker);
|
||||
finishAndInjectMethod(cfv, maker, returnType, returnStatement, data, builderType, source, deprecate, statements, name, params, methodAnnotations, access, null);
|
||||
}
|
||||
|
||||
@@ -362,7 +362,7 @@ public class JavacSingularsRecipes {
|
||||
statements.prepend(JavacHandlerUtil.generateNullCheck(maker, null, data.getPluralName(), builderType, "%s cannot be null"));
|
||||
}
|
||||
|
||||
List<JCAnnotation> methodAnnotations = copyAnnotations(findCopyableToSetterAnnotations(data.annotation.up()));
|
||||
List<JCAnnotation> methodAnnotations = copyAnnotations(findCopyableToSetterAnnotations(data.annotation.up()), maker);
|
||||
|
||||
finishAndInjectMethod(cfv, maker, returnType, returnStatement, data, builderType, source, deprecate, statements, name, List.of(param), methodAnnotations, access, ignoreNullCollections);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user