Use contributed search participants in call hierarchy#2881
Open
arcivanov wants to merge 1 commit intoeclipse-jdt:masterfrom
Open
Use contributed search participants in call hierarchy#2881arcivanov wants to merge 1 commit intoeclipse-jdt:masterfrom
arcivanov wants to merge 1 commit intoeclipse-jdt:masterfrom
Conversation
Incoming calls (CallerMethodWrapper):
Replace hardcoded `new SearchParticipant[] { getDefaultSearchParticipant() }`
with `SearchEngine.getSearchParticipants()` so that incoming call searches
include results from contributed search participants registered via the
`org.eclipse.jdt.core.searchParticipant` extension point. For contributed
(non-Java) elements, accept A_INACCURATE matches since JDT's MatchLocator
cannot resolve type bindings for types not compiled by ECJ.
Outgoing calls (CalleeMethodWrapper):
When the member has no Java AST (i.e. `getCompilationUnitNode()` returns
null), fall back to `SearchParticipant.locateCallees()` on all contributed
participants. Each participant can report call sites within the member's
body. Returned callees are resolved to full declarations via
`resolveCallee()`, which handles METHOD, FIELD, and TYPE element types.
Outgoing calls from Java to non-Java targets (CalleeAnalyzerVisitor):
When a Java method invocation has a null ECJ binding (receiver type is from
a contributed language, not compiled by ECJ), fall back to resolveViaSearch()
which uses SearchEngine.getSearchParticipants() to find METHOD DECLARATIONS
matching the method name across all contributed participants.
Non-standard ICompilationUnit handling (CallHierarchyCore):
Guard getCompilationUnitNode() with isJavaLikeFileName() check so non-Java
source files (e.g. .kt) are not parsed as Java AST, which would produce
broken results and false positives in outgoing call analysis.
Dependency:
Bump `org.eclipse.jdt.core` dependency to `[3.46.0,4.0.0)` for the
`SearchEngine.getSearchParticipants()` and `SearchParticipant.locateCallees()`
APIs added in eclipse-jdt/eclipse.jdt.core#4938.
Depends on eclipse-jdt/eclipse.jdt.core#4938.
Companion to eclipse-jdtls/eclipse.jdt.ls#3732.
6a0934b to
1321bcb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Enable cross-language call hierarchy by using contributed search participants in both incoming and outgoing call analysis.
Incoming calls (
CallerMethodWrapper)Replace hardcoded
new SearchParticipant[] { getDefaultSearchParticipant() }withSearchEngine.getSearchParticipants()so that incoming call searches include results from contributed search participants registered via theorg.eclipse.jdt.core.searchParticipantextension point. For contributed (non-Java) elements, acceptA_INACCURATEmatches since JDT'sMatchLocatorcannot resolve type bindings for types not compiled by ECJ.Outgoing calls (
CalleeMethodWrapper)When the member has no Java AST (i.e.
getCompilationUnitNode()returns null), fall back toSearchParticipant.locateCallees()on all contributed participants. Each participant can report call sites within the member's body. Returned callees are resolved to full declarations viaresolveCallee(), which handlesMETHOD,FIELD, andTYPEelement types.Outgoing calls from Java to non-Java targets (
CalleeAnalyzerVisitor)When a Java method invocation has a null ECJ binding (receiver type is from a contributed language, not compiled by ECJ), fall back to
resolveViaSearch()which usesSearchEngine.getSearchParticipants()to findMETHODDECLARATIONSmatching the method name across all contributed participants.Declaration resolution with filtering (
CallHierarchyCore.findFirstDeclaration)Shared utility method
findFirstDeclaration()searches for the first matchingIMemberdeclaration by name, with optional post-filters applied inacceptSearchMatch():Non-standard
ICompilationUnithandling (CallHierarchyCore)getCompilationUnitNode()withisJavaLikeFileName()check so non-Java source files (e.g..kt) are not parsed as Java ASTClassCastExceptionfor non-standardICompilationUnitimplementations that do not implement the internal compiler interface required byASTParser.createAST()Dependency
Bump
org.eclipse.jdt.coredependency to[3.46.0,4.0.0)for theSearchEngine.getSearchParticipants()andSearchParticipant.locateCallees()APIs.Related PRs
searchParticipantextension point,SearchParticipantRegistry,SearchEngine.getSearchParticipants(), andSearchParticipant.locateCallees()SearchEngine.getSearchParticipants()Test plan
CallHierarchyParticipantTest:searchParticipantsIncludesContributed— verifies contributed participant is returned bygetSearchParticipants()outgoingCallsJavaASTPathUnchanged— regression: Java AST callee analysis still worksoutgoingCallsFallBackToParticipants—locateCallees()called for binary members without source, returns 2 calleesoutgoingCallsResolvesExistingCallees— existingIMembercallees resolved directlyoutgoingCallsFallBackOnClassCastException— non-standardICompilationUnittriggersClassCastException, falls back to participant pathincomingCallsUsesAllParticipants— regression: incoming call search with all participants finds Java callers correctlyCallHierarchyTesttests pass (regression)