@@ -75,7 +75,7 @@ public List<CallHierarchyItem> prepareCallHierarchy(CallHierarchyPrepareParams p
75
75
int character = params .getPosition ().getCharacter ();
76
76
77
77
try {
78
- IMember candidate = getCallHierarchyElement (uri , line , character , monitor );
78
+ IMember candidate = getCallHierarchyElement (uri , line , character , true , monitor );
79
79
if (candidate == null ) {
80
80
return null ;
81
81
}
@@ -140,7 +140,7 @@ public List<CallHierarchyOutgoingCall> callHierarchyOutgoingCalls(CallHierarchyO
140
140
return null ;
141
141
}
142
142
143
- private IMember getCallHierarchyElement (String uri , int line , int character , IProgressMonitor monitor ) throws JavaModelException {
143
+ private IMember getCallHierarchyElement (String uri , int line , int character , boolean prepare , IProgressMonitor monitor ) throws JavaModelException {
144
144
Assert .isNotNull (uri , "uri" );
145
145
146
146
ITypeRoot root = JDTUtils .resolveTypeRoot (uri );
@@ -162,7 +162,12 @@ private IMember getCallHierarchyElement(String uri, int line, int character, IPr
162
162
int offset = JsonRpcHelpers .toOffset (root , line , character );
163
163
List <IJavaElement > selectedElements = codeResolve (root , offset );
164
164
Stream <IJavaElement > possibleElements = selectedElements .stream ().filter (CallHierarchyCore ::isPossibleInputElement );
165
- Optional <IJavaElement > firstElement = possibleElements .findFirst ();
165
+ Optional <IJavaElement > firstElement = possibleElements .findFirst ().flatMap (element -> {
166
+ if (!prepare && element instanceof IType ) {
167
+ return Optional .ofNullable (getEnclosingMember (root , offset )).map (IJavaElement .class ::cast ).filter (e -> !element .equals (e )).or (() -> Optional .of (element ));
168
+ }
169
+ return Optional .of (element );
170
+ });
166
171
if (firstElement .isPresent () && firstElement .get () instanceof IMember member ) {
167
172
candidate = member ;
168
173
}
@@ -177,7 +182,7 @@ private IMember getCallHierarchyElement(String uri, int line, int character, IPr
177
182
178
183
private List <CallHierarchyIncomingCall > getIncomingCallItemsAt (String uri , int line , int character , IProgressMonitor monitor ) throws JavaModelException {
179
184
SubMonitor sub = SubMonitor .convert (monitor , 2 );
180
- IMember candidate = getCallHierarchyElement (uri , line , character , sub .split (1 ));
185
+ IMember candidate = getCallHierarchyElement (uri , line , character , false , sub .split (1 ));
181
186
if (candidate == null ) {
182
187
return null ;
183
188
}
@@ -228,7 +233,7 @@ private Range getRange(IOpenable openable, CallLocation location) {
228
233
229
234
private List <CallHierarchyOutgoingCall > getOutgoingCallItemsAt (String uri , int line , int character , IProgressMonitor monitor ) throws JavaModelException {
230
235
SubMonitor sub = SubMonitor .convert (monitor , 2 );
231
- IMember candidate = getCallHierarchyElement (uri , line , character , sub .split (1 ));
236
+ IMember candidate = getCallHierarchyElement (uri , line , character , false , sub .split (1 ));
232
237
if (candidate == null ) {
233
238
return null ;
234
239
}
0 commit comments