add information about whether the index is complete or not during reconciling

this will allow reconcilers that use the index to validate something to trigger another reconciling once the index is complete in the future
This commit is contained in:
Martin Lippert
2025-03-20 21:39:40 +01:00
parent eb74a5dc82
commit d3b086893f
25 changed files with 66 additions and 51 deletions

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 Broadcom, Inc.
* Copyright (c) 2024, 2025 Broadcom, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -42,7 +42,7 @@ public class JdtCronReconciler implements JdtAstReconciler {
@Override
public ASTVisitor createVisitor(IJavaProject project, URI docURI, CompilationUnit cu,
IProblemCollector problemCollector, boolean isCompleteAst) {
IProblemCollector problemCollector, boolean isCompleteAst, boolean isIndexComplete) {
return new ASTVisitor() {
@Override
public boolean visit(NormalAnnotation node) {

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 Broadcom, Inc.
* Copyright (c) 2024, 2025 Broadcom, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -54,7 +54,7 @@ public class QueryJdtAstReconciler implements JdtAstReconciler {
}
@Override
public ASTVisitor createVisitor(IJavaProject project, URI docURI, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst) throws RequiredCompleteAstException {
public ASTVisitor createVisitor(IJavaProject project, URI docURI, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst, boolean isIndexComplete) throws RequiredCompleteAstException {
AnnotationHierarchies annotationHierarchies = AnnotationHierarchies.get(cu);
return new ASTVisitor() {

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023, 2024 VMware, Inc.
* Copyright (c) 2023, 2025 VMware, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -34,7 +34,7 @@ public abstract class AbstractSecurityLamdaDslReconciler implements JdtAstReconc
}
@Override
public ASTVisitor createVisitor(IJavaProject project, URI docUri, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst) {
public ASTVisitor createVisitor(IJavaProject project, URI docUri, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst, boolean isIndexComplete) {
if (isCompleteAst) {
return new ASTVisitor() {

View File

@@ -65,7 +65,7 @@ public class AddConfigurationIfBeansPresentReconciler implements JdtAstReconcile
}
@Override
public ASTVisitor createVisitor(IJavaProject project, URI docUri, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst) {
public ASTVisitor createVisitor(IJavaProject project, URI docUri, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst, boolean isIndexComplete) {
return new ASTVisitor() {
@Override

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023, 2024 VMware, Inc.
* Copyright (c) 2023, 2025 VMware, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -57,7 +57,7 @@ public class AuthorizeHttpRequestsReconciler implements JdtAstReconciler {
}
@Override
public ASTVisitor createVisitor(IJavaProject project, URI docUri, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst) {
public ASTVisitor createVisitor(IJavaProject project, URI docUri, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst, boolean isIndexComplete) {
if (isCompleteAst) {
return new ASTVisitor() {

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023, 2024 VMware, Inc.
* Copyright (c) 2023, 2025 VMware, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -67,7 +67,7 @@ public class AutowiredFieldIntoConstructorParameterReconciler implements JdtAstR
}
@Override
public ASTVisitor createVisitor(IJavaProject project, URI docUri, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst) {
public ASTVisitor createVisitor(IJavaProject project, URI docUri, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst, boolean isIndexComplete) {
Path sourceFile = Paths.get(docUri);
// Check if source file belongs to non-test java sources folder
if (IClasspathUtil.getProjectJavaSourceFoldersWithoutTests(project.getClasspath())

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022, 2024 VMware, Inc.
* Copyright (c) 2022, 2025 VMware, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -66,7 +66,7 @@ public class BeanMethodNotPublicReconciler implements JdtAstReconciler {
}
@Override
public ASTVisitor createVisitor(IJavaProject project, URI docUri, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst) {
public ASTVisitor createVisitor(IJavaProject project, URI docUri, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst, boolean isIndexComplete) {
return new ASTVisitor() {

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023, 2024 VMware, Inc.
* Copyright (c) 2023, 2025 VMware, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -56,7 +56,7 @@ public class BeanPostProcessingIgnoreInAotReconciler implements JdtAstReconciler
}
@Override
public ASTVisitor createVisitor(IJavaProject project, URI docUri, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst) {
public ASTVisitor createVisitor(IJavaProject project, URI docUri, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst, boolean isIndexComplete) {
return new ASTVisitor() {

View File

@@ -64,7 +64,7 @@ public class BeanRegistrarDeclarationReconciler implements JdtAstReconciler {
@Override
public ASTVisitor createVisitor(IJavaProject project, URI docURI, CompilationUnit cu,
IProblemCollector problemCollector, boolean isCompleteAst) {
IProblemCollector problemCollector, boolean isCompleteAst, boolean isIndexComplete) {
return new ASTVisitor() {
@Override

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023, 2024 VMware, Inc.
* Copyright (c) 2023, 2025 VMware, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -45,7 +45,7 @@ public class Boot3NotSupportedTypeReconciler implements JdtAstReconciler {
}
@Override
public ASTVisitor createVisitor(IJavaProject project, URI docURI, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst) {
public ASTVisitor createVisitor(IJavaProject project, URI docURI, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst, boolean isIndexComplete) {
return new ASTVisitor() {
@Override

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023, 2024 VMware, Inc.
* Copyright (c) 2023, 2025 VMware, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -70,7 +70,7 @@ public class EntityIdForRepoReconciler implements JdtAstReconciler {
}
@Override
public ASTVisitor createVisitor(IJavaProject project, URI docURI, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst) {
public ASTVisitor createVisitor(IJavaProject project, URI docURI, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst, boolean isIndexComplete) {
AnnotationHierarchies annotationHierarchies = AnnotationHierarchies.get(cu);
return new ASTVisitor() {

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 Broadcom
* Copyright (c) 2024, 2025 Broadcom
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -74,7 +74,7 @@ public class ImplicitWebAnnotationNamesReconciler implements JdtAstReconciler {
}
@Override
public ASTVisitor createVisitor(IJavaProject project, URI docUri, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst) {
public ASTVisitor createVisitor(IJavaProject project, URI docUri, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst, boolean isIndexComplete) {
return new ASTVisitor() {

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023, 2024 VMware, Inc.
* Copyright (c) 2023, 2025 VMware, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -32,6 +32,6 @@ public interface JdtAstReconciler {
ProblemType getProblemType();
ASTVisitor createVisitor(IJavaProject project, URI docURI, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst);
ASTVisitor createVisitor(IJavaProject project, URI docURI, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst, boolean isIndexComplete);
}

View File

@@ -88,21 +88,23 @@ public class JdtReconciler implements JavaReconciler {
compilationUnitCache.withCompilationUnit(project, uri, cu -> {
if (cu != null) {
try {
reconcile(project, URI.create(doc.getUri()), cu, problemCollector, true);
reconcile(project, URI.create(doc.getUri()), cu, problemCollector, true, true);
} catch (RequiredCompleteAstException e) {
log.error("Unexpected incomplete AST", e);
}
// TODO: is the index indeed complete?!? do need to react to complete index exception instead ?!?
}
log.info("reconciling (JDT): " + doc.getUri() + " done in " + (System.currentTimeMillis() - s) + "ms");
return null;
});
}
public ASTVisitor createCompositeVisitor(IJavaProject project, URI docURI, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst) throws RequiredCompleteAstException {
public ASTVisitor createCompositeVisitor(IJavaProject project, URI docURI, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst,
boolean isIndexComplete) throws RequiredCompleteAstException {
CompositeASTVisitor compositeVisitor = new CompositeASTVisitor();
for (JdtAstReconciler reconciler : getApplicableReconcilers(project)) {
ASTVisitor visitor = reconciler.createVisitor(project, docURI, cu, problemCollector, isCompleteAst);
ASTVisitor visitor = reconciler.createVisitor(project, docURI, cu, problemCollector, isCompleteAst, isIndexComplete);
if (visitor != null) {
compositeVisitor.add(visitor);
@@ -113,7 +115,9 @@ public class JdtReconciler implements JavaReconciler {
}
public void reconcile(IJavaProject project, URI docUri, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst) throws RequiredCompleteAstException {
public void reconcile(IJavaProject project, URI docUri, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst, boolean isIndexComplete)
throws RequiredCompleteAstException, RequiredCompleteIndexException {
long start = System.currentTimeMillis();
if (!config.isJavaSourceReconcileEnabled()) {
@@ -121,7 +125,7 @@ public class JdtReconciler implements JavaReconciler {
}
try {
ASTVisitor compositeVisitor = createCompositeVisitor(project, docUri, cu, problemCollector, isCompleteAst);
ASTVisitor compositeVisitor = createCompositeVisitor(project, docUri, cu, problemCollector, isCompleteAst, isIndexComplete);
cu.accept(compositeVisitor);
// for (JdtAstReconciler reconciler : getApplicableReconcilers(project)) {

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023, 2024 VMware, Inc.
* Copyright (c) 2023, 2025 VMware, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -52,7 +52,7 @@ public class ModulithTypeReferenceViolationReconciler implements JdtAstReconcile
}
@Override
public ASTVisitor createVisitor(IJavaProject project, URI docUri, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst) {
public ASTVisitor createVisitor(IJavaProject project, URI docUri, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst, boolean isIndexComplete) {
Path sourceFile = Paths.get(docUri);
if (IClasspathUtil.getProjectJavaSourceFoldersWithoutTests(project.getClasspath())

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023, 2024 VMware, Inc.
* Copyright (c) 2023, 2025 VMware, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -57,7 +57,7 @@ public class NoAutowiredOnConstructorReconciler implements JdtAstReconciler {
}
@Override
public ASTVisitor createVisitor(IJavaProject project, URI docUri, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst) {
public ASTVisitor createVisitor(IJavaProject project, URI docUri, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst, boolean isIndexComplete) {
AnnotationHierarchies annotationHierarchies = AnnotationHierarchies.get(cu);
return new ASTVisitor() {

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023, 2024 VMware, Inc.
* Copyright (c) 2023, 2025 VMware, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -55,7 +55,7 @@ public class NoRepoAnnotationReconciler implements JdtAstReconciler {
}
@Override
public ASTVisitor createVisitor(IJavaProject project, URI docUri, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst) {
public ASTVisitor createVisitor(IJavaProject project, URI docUri, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst, boolean isIndexComplete) {
return new ASTVisitor() {

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023, 2024 VMware, Inc.
* Copyright (c) 2023, 2025 VMware, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -69,7 +69,7 @@ public class NoRequestMappingAnnotationReconciler implements JdtAstReconciler {
}
@Override
public ASTVisitor createVisitor(IJavaProject project, URI docUri, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst) {
public ASTVisitor createVisitor(IJavaProject project, URI docUri, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst, boolean isIndexComplete) {
return new ASTVisitor() {

View File

@@ -71,7 +71,7 @@ public class NotRegisteredBeansReconciler implements JdtAstReconciler {
}
@Override
public ASTVisitor createVisitor(IJavaProject project, URI docUri, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst) {
public ASTVisitor createVisitor(IJavaProject project, URI docUri, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst, boolean isIndexComplete) {
return new ASTVisitor() {

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023, 2024 VMware, Inc.
* Copyright (c) 2023, 2025 VMware, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -57,7 +57,7 @@ public class PreciseBeanTypeReconciler implements JdtAstReconciler {
}
@Override
public ASTVisitor createVisitor(IJavaProject project, URI docUri, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst) {
public ASTVisitor createVisitor(IJavaProject project, URI docUri, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst, boolean isIndexComplete) {
final AnnotationHierarchies annotationHierarchies = AnnotationHierarchies.get(cu);
return new ASTVisitor() {

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023, 2024 VMware, Inc.
* Copyright (c) 2023, 2025 VMware, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -74,7 +74,7 @@ public class UnnecessarySpringExtensionReconciler implements JdtAstReconciler {
}
@Override
public ASTVisitor createVisitor(IJavaProject project, URI docUri, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst) {
public ASTVisitor createVisitor(IJavaProject project, URI docUri, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst, boolean isIndexComplete) {
return new ASTVisitor() {
@Override

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023, 2024 VMware, Inc.
* Copyright (c) 2023, 2025 VMware, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -85,7 +85,7 @@ public class WebSecurityConfigurerAdapterReconciler implements JdtAstReconciler
}
@Override
public ASTVisitor createVisitor(IJavaProject project, URI docUri, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst) {
public ASTVisitor createVisitor(IJavaProject project, URI docUri, CompilationUnit cu, IProblemCollector problemCollector, boolean isCompleteAst, boolean isIndexComplete) {
AnnotationHierarchies annotationHierarchies = AnnotationHierarchies.get(cu);
return new ASTVisitor() {

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022, 2023 VMware, Inc.
* Copyright (c) 2022, 2025 VMware, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -112,7 +112,7 @@ public class RewriteCodeActionHandler implements JavaCodeActionHandler {
List<CodeAction> cas = new ArrayList<>();
List<ReconcileProblem> problems = new ArrayList<>();
BasicProblemCollector problemsCollector = new BasicProblemCollector(problems);
jdtReconciler.reconcile(project, uri, cu, problemsCollector, true);
jdtReconciler.reconcile(project, uri, cu, problemsCollector, true, true);
for (ReconcileProblem p : problems) {
if (p.getOffset() <= region.getOffset() && p.getOffset() + p.getLength() >= region.getOffset() + region.getLength() && severityProvider.getDiagnosticSeverity(p) == null) {
for (QuickfixData<?> qf : p.getQuickfixes()) {

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 Broadcom, Inc.
* Copyright (c) 2024, 2025 Broadcom, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -45,7 +45,7 @@ public class JdtSpelReconciler implements JdtAstReconciler {
@Override
public ASTVisitor createVisitor(IJavaProject project, URI docURI, CompilationUnit cu,
IProblemCollector problemCollector, boolean isCompleteAst) {
IProblemCollector problemCollector, boolean isCompleteAst, boolean isIndexComplete) {
return new ASTVisitor() {
@Override
public boolean visit(SingleMemberAnnotation node) {

View File

@@ -81,10 +81,21 @@ public abstract class BaseReconcilerTest {
}
List<ReconcileProblem> reconcile(String fileName, String source, boolean isCompleteAst, Path... additionalSources) throws Exception {
return reconcile(this::getReconciler, fileName, source, isCompleteAst, additionalSources);
return reconcile(this::getReconciler, fileName, source, isCompleteAst, true, additionalSources);
}
List<ReconcileProblem> reconcile(Supplier<JdtAstReconciler> reconcilerFactory, String fileName, String source, boolean isCompleteAst, Path... additionalSources) throws Exception {
List<ReconcileProblem> reconcile(String fileName, String source, boolean isCompleteAst, boolean isIndexComplete, Path... additionalSources) throws Exception {
return reconcile(this::getReconciler, fileName, source, isCompleteAst, isIndexComplete, additionalSources);
}
List<ReconcileProblem> reconcile(Supplier<JdtAstReconciler> reconcilerFactory, String fileName, String source, boolean isCompleteAst,
Path... additionalSources) throws Exception {
return reconcile(reconcilerFactory, fileName, source, isCompleteAst, true, additionalSources);
}
List<ReconcileProblem> reconcile(Supplier<JdtAstReconciler> reconcilerFactory, String fileName, String source, boolean isCompleteAst,
boolean isIndexComplete, Path... additionalSources) throws Exception {
Path path = createFile(fileName, source);
TestProblemCollector problemCollector = new TestProblemCollector();
AtomicBoolean requiredCompleteAst = new AtomicBoolean(false);
@@ -95,7 +106,7 @@ public abstract class BaseReconcilerTest {
public void acceptAST(String sourceFilePath, CompilationUnit cu) {
try {
JdtAstReconciler reconciler = reconcilerFactory.get();
ASTVisitor visitor = reconciler.createVisitor(project, path.toUri(), cu, problemCollector, isCompleteAst);
ASTVisitor visitor = reconciler.createVisitor(project, path.toUri(), cu, problemCollector, isCompleteAst, isIndexComplete);
if (visitor != null) {
// use a composite visitor here to make sure that the tests will fail if there is anything missing in the composite