From 8ed2e07ceffea954c3d7721cbdf0044821fbfc2b Mon Sep 17 00:00:00 2001 From: Jinbo Wang Date: Thu, 29 Aug 2024 10:20:02 +0800 Subject: [PATCH] Enable lombok annotation processing when parsing DOM for workingcopy (#759) --- .../dom/JavacCompilationUnitResolver.java | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacCompilationUnitResolver.java b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacCompilationUnitResolver.java index 82feba92807..57096c70edb 100644 --- a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacCompilationUnitResolver.java +++ b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacCompilationUnitResolver.java @@ -33,6 +33,7 @@ import javax.tools.DiagnosticListener; import javax.tools.JavaFileManager; import javax.tools.JavaFileObject; +import javax.tools.StandardLocation; import javax.tools.ToolProvider; import org.eclipse.core.resources.IResource; @@ -595,7 +596,7 @@ public Void visitClass(ClassTree node, Void p) { JCCompilationUnit javacCompilationUnit = null; - Iterable options = Arrays.asList("-proc:none"); // disable annotation processing in the parser. + Iterable options = configureAPIfNecessary(fileManager) ? null : Arrays.asList("-proc:none"); JavacTask task = ((JavacTool)compiler).getTask(null, fileManager, null /* already added to context */, options, List.of() /* already set */, fileObjects, context); { // don't know yet a better way to ensure those necessary flags get configured @@ -950,4 +951,47 @@ private static Function javacAdditionalBindingCreator(Map apPaths = fileManager.getLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH); + if (apPaths != null) { + return true; + } + + Iterable apModulePaths = fileManager.getLocation(StandardLocation.ANNOTATION_PROCESSOR_MODULE_PATH); + if (apModulePaths != null) { + return true; + } + + Iterable classPaths = fileManager.getLocation(StandardLocation.CLASS_PATH); + if (classPaths != null) { + for(File cp : classPaths) { + String fileName = cp.getName(); + if (fileName != null && fileName.startsWith("lombok") && fileName.endsWith(".jar")) { + try { + fileManager.setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH, List.of(cp)); + return true; + } catch (IOException ex) { + ILog.get().error(ex.getMessage(), ex); + } + } + } + } + + Iterable modulePaths = fileManager.getLocation(StandardLocation.MODULE_PATH); + if (modulePaths != null) { + for(File mp : modulePaths) { + String fileName = mp.getName(); + if (fileName != null && fileName.startsWith("lombok") && fileName.endsWith(".jar")) { + try { + fileManager.setLocation(StandardLocation.ANNOTATION_PROCESSOR_MODULE_PATH, List.of(mp)); + return true; + } catch (IOException ex) { + ILog.get().error(ex.getMessage(), ex); + } + } + } + } + + return false; + } }