Skip to content

Commit

Permalink
setting javac based compilation unit resolver for early tests
Browse files Browse the repository at this point in the history
  • Loading branch information
martinlippert committed Dec 20, 2024
1 parent 617bc6c commit c323fb9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand Down Expand Up @@ -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<Classpath> classpaths = CUResolver.getClasspath(parser);
// environment = CUResolver.createLookupEnvironment(classpaths.toArray(new Classpath[classpaths.size()]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()]);
Expand Down

0 comments on commit c323fb9

Please sign in to comment.