From 0223aa7271ac295fd2d9371ee2089717e72faf12 Mon Sep 17 00:00:00 2001 From: Rob Stryker Date: Tue, 11 Jun 2024 16:52:07 -0400 Subject: [PATCH] Clean up API changes and proposed interface Signed-off-by: Rob Stryker --- .../dom/org/eclipse/jdt/core/dom/ASTParser.java | 8 ++++---- .../jdt/core/dom/CompilationUnitResolver.java | 4 ++-- .../jdt/core/dom/ICompilationUnitResolver.java | 17 ++++++++++++++++- .../org/eclipse/jdt/core/dom/NodeSearcher.java | 5 +---- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTParser.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTParser.java index a09ea0b8426..2c6102d1a8c 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTParser.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTParser.java @@ -1165,7 +1165,7 @@ private ASTNode internalCreateASTCached(IProgressMonitor monitor) { break; case K_COMPILATION_UNIT : try { - NodeSearcher searcher = null; + boolean useSearcher = false; org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit = null; WorkingCopyOwner wcOwner = this.workingCopyOwner; if (this.typeRoot instanceof ClassFileWorkingCopy) { @@ -1233,13 +1233,13 @@ private ASTNode internalCreateASTCached(IProgressMonitor monitor) { throw new IllegalStateException(); } if ((this.bits & CompilationUnitResolver.PARTIAL) != 0) { - searcher = new NodeSearcher(this.focalPointPosition); + useSearcher = true; } int flags = 0; if ((this.bits & CompilationUnitResolver.STATEMENT_RECOVERY) != 0) { flags |= ICompilationUnit.ENABLE_STATEMENTS_RECOVERY; } - if (searcher == null && ((this.bits & CompilationUnitResolver.IGNORE_METHOD_BODIES) != 0)) { + if (!useSearcher && ((this.bits & CompilationUnitResolver.IGNORE_METHOD_BODIES) != 0)) { flags |= ICompilationUnit.IGNORE_METHOD_BODIES; } @@ -1249,7 +1249,7 @@ private ASTNode internalCreateASTCached(IProgressMonitor monitor) { } } - CompilationUnit result2 = this.unitResolver.toCompilationUnit(sourceUnit, needToResolveBindings, this.project, getClasspath(), searcher, this.apiLevel, this.compilerOptions, this.workingCopyOwner, wcOwner, flags, monitor); + CompilationUnit result2 = this.unitResolver.toCompilationUnit(sourceUnit, needToResolveBindings, this.project, getClasspath(), useSearcher ? this.focalPointPosition : -1, this.apiLevel, this.compilerOptions, this.workingCopyOwner, wcOwner, flags, monitor); result2.setTypeRoot(this.typeRoot); return result2; } finally { diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java index 959a8c6afbf..dcca57b177e 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/CompilationUnitResolver.java @@ -112,10 +112,10 @@ public void resolve(ICompilationUnit[] compilationUnits, String[] bindingKeys, A } @Override - public CompilationUnit toCompilationUnit(org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit, final boolean initialNeedsToResolveBinding, IJavaProject project, List classpaths, NodeSearcher nodeSearcher, + public CompilationUnit toCompilationUnit(org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit, final boolean initialNeedsToResolveBinding, IJavaProject project, List classpaths, int focalPosition, int apiLevel, Map compilerOptions, WorkingCopyOwner parsedUnitWorkingCopyOwner, WorkingCopyOwner typeRootWorkingCopyOwner, int flags, IProgressMonitor monitor) { return CompilationUnitResolver.toCompilationUnit(sourceUnit, initialNeedsToResolveBinding, project, - classpaths, nodeSearcher, apiLevel, compilerOptions, parsedUnitWorkingCopyOwner, typeRootWorkingCopyOwner, flags, monitor); + classpaths, focalPosition == -1 ? null : new NodeSearcher(focalPosition), apiLevel, compilerOptions, parsedUnitWorkingCopyOwner, typeRootWorkingCopyOwner, flags, monitor); } } diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ICompilationUnitResolver.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ICompilationUnitResolver.java index 8d379504309..39b1bf52433 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ICompilationUnitResolver.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ICompilationUnitResolver.java @@ -37,6 +37,21 @@ void resolve(ICompilationUnit[] compilationUnits, String[] bindingKeys, ASTReque Map compilerOptions, IJavaProject project, WorkingCopyOwner workingCopyOwner, int flags, IProgressMonitor monitor); - CompilationUnit toCompilationUnit(org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit, final boolean initialNeedsToResolveBinding, IJavaProject project, List classpaths, NodeSearcher nodeSearcher, + /** + * + * @param sourceUnit + * @param initialNeedsToResolveBinding + * @param project + * @param classpaths + * @param focalPosition a position to focus on, or -1 if N/A + * @param apiLevel + * @param compilerOptions + * @param parsedUnitWorkingCopyOwner + * @param typeRootWorkingCopyOwner + * @param flags + * @param monitor + * @return + */ + CompilationUnit toCompilationUnit(org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit, final boolean initialNeedsToResolveBinding, IJavaProject project, List classpaths, int focalPosition, int apiLevel, Map compilerOptions, WorkingCopyOwner parsedUnitWorkingCopyOwner, WorkingCopyOwner typeRootWorkingCopyOwner, int flags, IProgressMonitor monitor); } diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/NodeSearcher.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/NodeSearcher.java index 4028ab16425..30537d2152b 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/NodeSearcher.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/NodeSearcher.java @@ -23,10 +23,7 @@ import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope; import org.eclipse.jdt.internal.compiler.lookup.MethodScope; -/** - * @since 3.38 - */ -public class NodeSearcher extends ASTVisitor { +class NodeSearcher extends ASTVisitor { public org.eclipse.jdt.internal.compiler.ast.ASTNode found; public TypeDeclaration enclosingType; public int position;