From 451b85fca1195c6495e3fcd724868b0202370f90 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Tue, 25 Jun 2024 13:28:50 -0400 Subject: [PATCH] Refactor `ASTRequestor` to reduce the access it has to the compiler This reduces the access that `ASTRequestor` has to the `CompilationUnitResolver` to just the method it needs, `createBinding`. This also makes it possible to use an alternate additional binding resolver instead of hardcoding the one implemented by `CompilationUnitResolver`. Signed-off-by: David Thompson --- .../dom/org/eclipse/jdt/core/dom/ASTRequestor.java | 14 +++++++++----- .../jdt/core/dom/CompilationUnitResolver.java | 4 ++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTRequestor.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTRequestor.java index def8407dfd2..84af2004ed3 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTRequestor.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTRequestor.java @@ -13,6 +13,8 @@ *******************************************************************************/ package org.eclipse.jdt.core.dom; +import java.util.function.Function; + import org.eclipse.jdt.core.ICompilationUnit; /** @@ -36,12 +38,14 @@ public abstract class ASTRequestor { /** - * The compilation unit resolver used to resolve bindings, or - * null if none. Note that this field is non-null + * The function used to resolve additional bindings, + * or null if none. + * The function accepts the binding key and returns the corresponding IBinding. + * Note that this field is non-null * only within the dynamic scope of a call to * ASTParser.createASTs. */ - CompilationUnitResolver compilationUnitResolver = null; + Function additionalBindingResolver = null; /** * Creates a new instance. @@ -111,8 +115,8 @@ public final IBinding[] createBindings(String[] bindingKeys) { IBinding[] result = new IBinding[length]; for (int i = 0; i < length; i++) { result[i] = null; - if (this.compilationUnitResolver != null) { - result[i] = this.compilationUnitResolver.createBinding(bindingKeys[i]); + if (this.additionalBindingResolver != null) { + result[i] = this.additionalBindingResolver.apply(bindingKeys[i]); } } return result; 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 1988de8c26b..34fedcae59c 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 @@ -964,7 +964,7 @@ private void resolve( int flags) { // temporarily connect ourselves to the ASTResolver - must disconnect when done - astRequestor.compilationUnitResolver = this; + astRequestor.additionalBindingResolver = this::createBinding; this.bindingTables = new DefaultBindingResolver.BindingTables(); CompilationUnitDeclaration unit = null; try { @@ -1067,7 +1067,7 @@ private void resolve( throw e; // rethrow } finally { // disconnect ourselves from ast requestor - astRequestor.compilationUnitResolver = null; + astRequestor.additionalBindingResolver = null; } }