From 8b57eaa12fdea485f783ed1aa1d61fb9b778787b Mon Sep 17 00:00:00 2001 From: Rawi01 Date: Sun, 9 Feb 2025 23:46:44 +0100 Subject: [PATCH] [fixes #3823] Set missing source position for receiver annotation --- buildScripts/tests.ant.xml | 1 + .../lombok/eclipse/handlers/HandleBuilder.java | 17 ++++++----------- test/core/src/lombok/RunTestsViaEcj.java | 4 ++-- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/buildScripts/tests.ant.xml b/buildScripts/tests.ant.xml index 3fe241b6..90fb89c3 100644 --- a/buildScripts/tests.ant.xml +++ b/buildScripts/tests.ant.xml @@ -237,6 +237,7 @@ This buildfile is part of projectlombok.org. It takes care of compiling and runn + diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java index 161de8ca..92692213 100755 --- a/src/core/lombok/eclipse/handlers/HandleBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2024 The Project Lombok Authors. + * Copyright (C) 2013-2025 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 @@ -59,7 +59,6 @@ import org.eclipse.jdt.internal.compiler.ast.QualifiedThisReference; import org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference; import org.eclipse.jdt.internal.compiler.ast.Receiver; import org.eclipse.jdt.internal.compiler.ast.ReturnStatement; -import org.eclipse.jdt.internal.compiler.ast.SingleMemberAnnotation; import org.eclipse.jdt.internal.compiler.ast.SingleNameReference; import org.eclipse.jdt.internal.compiler.ast.SingleTypeReference; import org.eclipse.jdt.internal.compiler.ast.Statement; @@ -778,28 +777,24 @@ public class HandleBuilder extends EclipseAnnotationHandler { if (mandatories.size() == 0) return null; - int pS = job.source.sourceStart, pE = job.source.sourceEnd; - char[][] nameCalled = fromQualifiedName(CheckerFrameworkVersion.NAME__CALLED); - SingleMemberAnnotation ann = new SingleMemberAnnotation(new QualifiedTypeReference(nameCalled, poss(job.source, nameCalled.length)), pS); + Expression memberValue; if (mandatories.size() == 1) { - ann.memberValue = new StringLiteral(mandatories.get(0), 0, 0, 0); + memberValue = new StringLiteral(mandatories.get(0), 0, 0, 0); } else { ArrayInitializer arr = new ArrayInitializer(); - arr.sourceStart = pS; - arr.sourceEnd = pE; arr.expressions = new Expression[mandatories.size()]; for (int i = 0; i < arr.expressions.length; i++) { - arr.expressions[i] = new StringLiteral(mandatories.get(i), pS, pE, 0); + arr.expressions[i] = new StringLiteral(mandatories.get(i), job.source.sourceStart, job.source.sourceEnd, 0); } - ann.memberValue = arr; + memberValue = arr; } ann.declarationSourceEnd = pE; TypeReference typeReference = job.createBuilderTypeReference(); int len = typeReference.getTypeName().length; typeReference.annotations = new Annotation[len][]; - typeReference.annotations[len - 1] = new Annotation[] {ann}; + typeReference.annotations[len - 1] = EclipseHandlerUtil.addAnnotation(job.source, null, nameCalled, memberValue); return new Receiver(new char[] { 't', 'h', 'i', 's' }, 0, typeReference, null, 0); } diff --git a/test/core/src/lombok/RunTestsViaEcj.java b/test/core/src/lombok/RunTestsViaEcj.java index 3a0f02e2..53008987 100644 --- a/test/core/src/lombok/RunTestsViaEcj.java +++ b/test/core/src/lombok/RunTestsViaEcj.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2024 The Project Lombok Authors. + * Copyright (C) 2010-2025 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 @@ -242,7 +242,7 @@ public class RunTestsViaEcj extends AbstractRunTests { return source; } }; - return AST.convertCompilationUnit(4, cud, options, false, ccu, 0, null); + return AST.convertCompilationUnit(8, cud, options, false, ccu, 0, null); } }