[bugfix] mixing @Delegate and @Getter(lazy) causes positions to be lost. 15 years and nobody found this bug - not worth an issue or a changelog.

This commit is contained in:
Reinier Zwitserloot authored and Roel Spilker committed 2024-05-17 22:22:35 +02:00
1 parent 280d12c62d
commit 3022b26a9b
2 files changed
+17 -2

No files matched your search

@@ -218,7 +218,7 @@ public class HandleGetter extends JavacAnnotationHandler<Getter> {
long access = toJavacModifier(level) | (fieldDecl.mods.flags & Flags.STATIC);
injectMethod(fieldNode.up(), createGetter(access, fieldNode, fieldNode.getTreeMaker(), source, lazy, onMethod));
injectMethod(fieldNode.up(), source, createGetter(access, fieldNode, fieldNode.getTreeMaker(), source, lazy, onMethod));
}
public JCMethodDecl createGetter(long access, JavacNode field, JavacTreeMaker treeMaker, JavacNode source, boolean lazy, List<JCAnnotation> onMethod) {
@@ -1369,6 +1369,21 @@ public class JavacHandlerUtil {
* Also takes care of updating the JavacAST.
*/
public static void injectMethod(JavacNode typeNode, JCMethodDecl method) {
JavacNode source = typeNode.getNodeFor(getGeneratedBy(method));
injectMethod(typeNode, source, method);
}
/**
* Adds the given new method declaration to the provided type AST Node.
* Can also inject constructors.
*
* Also takes care of updating the JavacAST.
*
* Ordinarily the 'source' is determined automatically. In rare cases generally involving combinations between
* annotations, some of which require re-attribution such as {@code @Delegate}, that doesn't work. This method
* exists if you explicitly have the source.
*/
public static void injectMethod(JavacNode typeNode, JavacNode source, JCMethodDecl method) {
JCClassDecl type = (JCClassDecl) typeNode.get();
if (method.getName().contentEquals("<init>")) {
@@ -1389,7 +1404,7 @@ public class JavacHandlerUtil {
}
addSuppressWarningsAll(method.mods, typeNode, typeNode.getNodeFor(getGeneratedBy(method)), typeNode.getContext());
addGenerated(method.mods, typeNode, typeNode.getNodeFor(getGeneratedBy(method)), typeNode.getContext());
addGenerated(method.mods, typeNode, source, typeNode.getContext());
type.defs = type.defs.append(method);
EnterReflect.memberEnter(method, typeNode);