CodeActions to JDT reconciler. Don't use OR CU cache.
This commit is contained in:
@@ -154,8 +154,8 @@ public class BootJavaConfig implements InitializingBean {
|
||||
return enabled != null && enabled.booleanValue();
|
||||
}
|
||||
|
||||
public boolean isRewriteReconcileEnabled() {
|
||||
Boolean enabled = getRawSettings().getBoolean("boot-java", "rewrite", "reconcile");
|
||||
public boolean isJavaSourceReconcileEnabled() {
|
||||
Boolean enabled = getRawSettings().getBoolean("boot-java", "validation", "java", "reconcilers");
|
||||
return enabled == null ? false : enabled.booleanValue();
|
||||
}
|
||||
|
||||
|
||||
@@ -38,8 +38,8 @@ public class RewriteConfig {
|
||||
}
|
||||
|
||||
@ConditionalOnBean(RewriteRecipeRepository.class)
|
||||
@Bean RewriteRefactorings rewriteRefactorings(SimpleLanguageServer server, JavaProjectFinder projectFinder, RewriteRecipeRepository recipeRepo, RewriteCompilationUnitCache cuCache) {
|
||||
return new RewriteRefactorings(server, projectFinder, recipeRepo, cuCache);
|
||||
@Bean RewriteRefactorings rewriteRefactorings(SimpleLanguageServer server, JavaProjectFinder projectFinder, RewriteRecipeRepository recipeRepo) {
|
||||
return new RewriteRefactorings(server, projectFinder, recipeRepo);
|
||||
}
|
||||
|
||||
@ConditionalOnBean(RewriteRecipeRepository.class)
|
||||
|
||||
@@ -58,6 +58,10 @@ public class JdtReconciler implements JavaReconciler {
|
||||
|
||||
@Override
|
||||
public void reconcile(IJavaProject project, final IDocument doc, final IProblemCollector problemCollector) {
|
||||
if (!config.isJavaSourceReconcileEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final long s = System.currentTimeMillis();
|
||||
URI uri = URI.create(doc.getUri());
|
||||
compilationUnitCache.withCompilationUnit(project, uri, cu -> {
|
||||
@@ -75,6 +79,9 @@ public class JdtReconciler implements JavaReconciler {
|
||||
|
||||
|
||||
public void reconcile(IJavaProject project, URI docUri, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst) throws RequiredCompleteAstException {
|
||||
if (!config.isJavaSourceReconcileEnabled()) {
|
||||
return;
|
||||
}
|
||||
for (JdtAstReconciler reconciler : getApplicableReconcilers(project)) {
|
||||
try {
|
||||
reconciler.reconcile(project, docUri, cu, problemCollector, isCompleteAst);
|
||||
|
||||
@@ -92,7 +92,8 @@ public class RewriteCodeActionHandler implements JavaCodeActionHandler {
|
||||
@Override
|
||||
public List<Either<Command, CodeAction>> handle(IJavaProject project, CancelChecker cancelToken,
|
||||
CodeActionCapabilities capabilities, CodeActionContext context, TextDocument doc, IRegion region) {
|
||||
if (!config.isRewriteReconcileEnabled()) {
|
||||
// Short circuit here to avoid parsing the java source for nothing.
|
||||
if (!config.isJavaSourceReconcileEnabled()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
|
||||
@@ -76,33 +76,33 @@ public class RewriteReconciler implements JavaReconciler {
|
||||
|
||||
@Override
|
||||
public void reconcile(IJavaProject project, IDocument doc, IProblemCollector problemCollector) {
|
||||
if (!config.isRewriteReconcileEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
try {
|
||||
problemCollector.beginCollecting();
|
||||
|
||||
List<RecipeCodeActionDescriptor> descriptors = getProblemRecipeDescriptors(project);
|
||||
|
||||
if (!descriptors.isEmpty()) {
|
||||
CompilationUnit cu = cuCache.getCU(project, URI.create(doc.getUri()));
|
||||
if (cu != null) {
|
||||
collectProblems(project, descriptors, doc, cu, problemCollector::accept);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (ORAstUtils.isExceptionFromInterrupedThread(e)) {
|
||||
log.debug("", e);
|
||||
} else {
|
||||
log.error("", e);
|
||||
}
|
||||
} finally {
|
||||
problemCollector.endCollecting();
|
||||
log.info("reconciling (OpenRewrite): " + doc.getUri() + " done in " + (System.currentTimeMillis() - start) + "ms");
|
||||
}
|
||||
// if (!config.isRewriteReconcileEnabled()) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// long start = System.currentTimeMillis();
|
||||
//
|
||||
// try {
|
||||
// problemCollector.beginCollecting();
|
||||
//
|
||||
// List<RecipeCodeActionDescriptor> descriptors = getProblemRecipeDescriptors(project);
|
||||
//
|
||||
// if (!descriptors.isEmpty()) {
|
||||
// CompilationUnit cu = cuCache.getCU(project, URI.create(doc.getUri()));
|
||||
// if (cu != null) {
|
||||
// collectProblems(project, descriptors, doc, cu, problemCollector::accept);
|
||||
// }
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// if (ORAstUtils.isExceptionFromInterrupedThread(e)) {
|
||||
// log.debug("", e);
|
||||
// } else {
|
||||
// log.error("", e);
|
||||
// }
|
||||
// } finally {
|
||||
// problemCollector.endCollecting();
|
||||
// log.info("reconciling (OpenRewrite): " + doc.getUri() + " done in " + (System.currentTimeMillis() - start) + "ms");
|
||||
// }
|
||||
}
|
||||
|
||||
private List<ReconcileProblem> createProblems(IDocument doc, FixAssistMarker m, J astNode) {
|
||||
@@ -140,7 +140,7 @@ public class RewriteReconciler implements JavaReconciler {
|
||||
@Override
|
||||
public Map<IDocument, Collection<ReconcileProblem>> reconcile(IJavaProject project, List<TextDocument> docs, Runnable incrementProgress) {
|
||||
|
||||
if (!config.isRewriteReconcileEnabled()) {
|
||||
if (!config.isJavaSourceReconcileEnabled()) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
@@ -251,7 +251,7 @@ public class RewriteReconciler implements JavaReconciler {
|
||||
// Parse in batches and share the parser
|
||||
private Map<IDocument, Collection<ReconcileProblem>> doReconcile(IJavaProject project, List<TextDocument> docs, JavaParser javaParser, JavaSourceSet javaSourceSet, Runnable incrementProgress) {
|
||||
Map<IDocument, Collection<ReconcileProblem>> allProblems = new HashMap<>();
|
||||
if (javaParser != null && config.isRewriteReconcileEnabled()) {
|
||||
if (javaParser != null && config.isJavaSourceReconcileEnabled()) {
|
||||
try {
|
||||
List<RecipeCodeActionDescriptor> descriptors = getProblemRecipeDescriptors(project);
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -70,17 +69,14 @@ public class RewriteRefactorings implements CodeActionResolver, QuickfixHandler
|
||||
|
||||
private SimpleLanguageServer server;
|
||||
|
||||
private RewriteCompilationUnitCache cuCache;
|
||||
|
||||
private JavaProjectFinder projectFinder;
|
||||
|
||||
private Gson gson;
|
||||
|
||||
public RewriteRefactorings(SimpleLanguageServer server, JavaProjectFinder projectFinder, RewriteRecipeRepository recipeRepo, RewriteCompilationUnitCache cuCache) {
|
||||
public RewriteRefactorings(SimpleLanguageServer server, JavaProjectFinder projectFinder, RewriteRecipeRepository recipeRepo) {
|
||||
this.server = server;
|
||||
this.projectFinder = projectFinder;
|
||||
this.recipeRepo = recipeRepo;
|
||||
this.cuCache = cuCache;
|
||||
this.gson = new GsonBuilder()
|
||||
.registerTypeAdapter(RecipeScope.class, (JsonDeserializer<RecipeScope>) (json, type, context) -> {
|
||||
try {
|
||||
@@ -164,13 +160,9 @@ public class RewriteRefactorings implements CodeActionResolver, QuickfixHandler
|
||||
progress.done();
|
||||
}
|
||||
} else {
|
||||
if (data.getTypeStubs().length == 0) {
|
||||
cus = data.getDocUris().stream().map(docUri -> cuCache.getCU(project.get(), URI.create(docUri))).filter(Objects::nonNull).collect(Collectors.toList());
|
||||
} else {
|
||||
JavaParser jp = ORAstUtils.createJavaParserBuilder(project.get()).dependsOn(data.getTypeStubs()).build();
|
||||
List<Input> inputs = data.getDocUris().stream().map(URI::create).map(Paths::get).map(p -> ORAstUtils.getParserInput(server.getTextDocumentService(), p)).collect(Collectors.toList());
|
||||
cus = ORAstUtils.parseInputs(jp, inputs, null);
|
||||
}
|
||||
JavaParser jp = ORAstUtils.createJavaParserBuilder(project.get()).dependsOn(data.getTypeStubs()).build();
|
||||
List<Input> inputs = data.getDocUris().stream().map(URI::create).map(Paths::get).map(p -> ORAstUtils.getParserInput(server.getTextDocumentService(), p)).collect(Collectors.toList());
|
||||
cus = ORAstUtils.parseInputs(jp, inputs, null);
|
||||
return applyRecipe(r, project.get(), cus);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,6 +61,10 @@ public class SpringValidationBeanMethodNotPublicTest {
|
||||
@BeforeEach
|
||||
public void setup() throws Exception {
|
||||
harness.intialize(null);
|
||||
|
||||
String changedSettings = "{\"boot-java\": {\"validation\": {\"java\": { \"reconcilers\": true}}}}";
|
||||
JsonElement settingsAsJson = new Gson().fromJson(changedSettings, JsonElement.class);
|
||||
harness.changeConfiguration(new Settings(settingsAsJson));
|
||||
|
||||
directory = new File(ProjectsHarness.class.getResource("/test-projects/test-spring-validations/").toURI());
|
||||
|
||||
@@ -105,7 +109,7 @@ public class SpringValidationBeanMethodNotPublicTest {
|
||||
assertEquals(1, diagnostics.size());
|
||||
assertEquals(DiagnosticSeverity.Hint, diagnostic.getSeverity());
|
||||
|
||||
String changedSettings = "{\"spring-boot\": {\"ls\": {\"problem\": {\"boot2\": {\"JAVA_PUBLIC_BEAN_METHOD\": \"ERROR\"}}}}}";
|
||||
String changedSettings = "{\"spring-boot\": {\"ls\": {\"problem\": {\"boot2\": {\"JAVA_PUBLIC_BEAN_METHOD\": \"ERROR\"}}}}, \"boot-java\": {\"validation\": {\"java\": { \"reconcilers\": true}}}}";
|
||||
JsonElement settingsAsJson = new Gson().fromJson(changedSettings, JsonElement.class);
|
||||
Settings settings = new Settings(settingsAsJson);
|
||||
|
||||
|
||||
@@ -56,6 +56,7 @@ import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFin
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.ProjectObserver;
|
||||
import org.springframework.ide.vscode.commons.languageserver.reconcile.IProblemCollector;
|
||||
import org.springframework.ide.vscode.commons.languageserver.reconcile.ReconcileProblem;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.Settings;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleTextDocumentService;
|
||||
import org.springframework.ide.vscode.commons.maven.java.MavenJavaProject;
|
||||
@@ -65,6 +66,9 @@ import org.springframework.ide.vscode.project.harness.BootLanguageServerHarness;
|
||||
import org.springframework.ide.vscode.project.harness.ProjectsHarness;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
|
||||
/**
|
||||
* @author Martin Lippert
|
||||
*/
|
||||
@@ -145,6 +149,10 @@ public class ValueSpelExpressionValidationTest {
|
||||
public void setup() throws Exception {
|
||||
harness.intialize(null);
|
||||
|
||||
String changedSettings = "{\"boot-java\": {\"validation\": {\"java\": { \"reconcilers\": true}}}}";
|
||||
JsonElement settingsAsJson = new Gson().fromJson(changedSettings, JsonElement.class);
|
||||
harness.changeConfiguration(new Settings(settingsAsJson));
|
||||
|
||||
directory = new File(ProjectsHarness.class.getResource("/test-projects/test-annotations/").toURI());
|
||||
docUri = directory.toPath().resolve("src/main/java/org/test/TestValueCompletion.java").toUri().toASCIIString();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user