From c323fb9ede70bd8fa7668542a8c3b36c9cdd0827 Mon Sep 17 00:00:00 2001 From: Martin Lippert Date: Fri, 20 Dec 2024 17:53:44 +0100 Subject: [PATCH] setting javac based compilation unit resolver for early tests --- .../boot/java/utils/ASTParserCleanupEnabled.java | 14 ++++++++++++++ .../vscode/boot/java/utils/SpringIndexerJava.java | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/utils/ASTParserCleanupEnabled.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/utils/ASTParserCleanupEnabled.java index 1007fbb938..5dce361caf 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/utils/ASTParserCleanupEnabled.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/utils/ASTParserCleanupEnabled.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.springframework.ide.vscode.boot.java.utils; +import java.lang.reflect.Field; import java.util.Map; import org.eclipse.core.runtime.IProgressMonitor; @@ -18,6 +19,8 @@ import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.ASTParser; import org.eclipse.jdt.core.dom.FileASTRequestor; +import org.eclipse.jdt.core.dom.JavacCompilationUnitResolver; +import org.eclipse.jdt.internal.core.dom.ICompilationUnitResolver; import org.springframework.ide.vscode.boot.java.annotations.AnnotationHierarchies; /** @@ -48,6 +51,17 @@ public ASTParserCleanupEnabled(String[] classpathEntries, String[] sourceEntries parser.setIgnoreMethodBodies(ignoreMethodBodies); parser.setEnvironment(classpathEntries, sourceEntries, null, false); + + try { + Field field = parser.getClass().getDeclaredField("unitResolver"); + field.setAccessible(true); + + ICompilationUnitResolver resolver = new JavacCompilationUnitResolver(); + field.set(parser, resolver); + } catch (Exception e) { + e.printStackTrace(); + } + // List classpaths = CUResolver.getClasspath(parser); // environment = CUResolver.createLookupEnvironment(classpaths.toArray(new Classpath[classpaths.size()])); diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/utils/SpringIndexerJava.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/utils/SpringIndexerJava.java index fcf1751009..7e5bccd2e6 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/utils/SpringIndexerJava.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/utils/SpringIndexerJava.java @@ -587,7 +587,7 @@ public void acceptAST(String sourceFilePath, CompilationUnit cu) { }; ASTParserCleanupEnabled parser = createParser(project, annotations, ignoreMethodBodies); - parser.createASTs(javaFiles, null, new String[0], requestor, null); + parser.createASTs(javaFiles, new String[javaFiles.length], new String[0], requestor, null); parser.cleanup(); return (String[]) nextPassFiles.toArray(new String[nextPassFiles.size()]);