Skip to content

Commit 02ae0f9

Browse files
committed
Fix right click resolution on method references being treated as a declaration
1 parent 7c9b340 commit 02ae0f9

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

recaf-core/src/main/java/software/coley/recaf/services/source/ResolverAdapter.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import software.coley.sourcesolver.model.CompilationUnitModel;
1414
import software.coley.sourcesolver.model.ErroneousModel;
1515
import software.coley.sourcesolver.model.MethodBodyModel;
16+
import software.coley.sourcesolver.model.MethodModel;
1617
import software.coley.sourcesolver.model.Model;
1718
import software.coley.sourcesolver.model.TypeModel;
1819
import software.coley.sourcesolver.model.VariableModel;
@@ -164,12 +165,17 @@ else if (resolution instanceof ClassResolution classResolution) {
164165
if (methodPath == null)
165166
return null;
166167

167-
// Determine if it's a declaration or reference.
168-
// - Check if any declared class's methods have the target model in their range (the name and such, not the body)
168+
// The model we resolved is a declaration if:
169+
// - It is a 'MethodModel' that resolves to the same method
170+
// - The declaring class must define a method of the same name/type
169171
for (ClassModel declaredClass : getUnit().getRecursiveChildrenOfType(ClassModel.class))
170-
if (declaredClass.resolve(this) instanceof ClassResolution declaredClassResolution && declaredClassResolution.matches(methodResolution.getOwnerResolution()))
171-
if (methodResolution.matches(declaredClassResolution.getDeclaredMemberResolution(methodEntry)))
172-
return AstResolveResult.declared(methodPath);
172+
if (target instanceof MethodModel targetMethod
173+
&& targetMethod.resolve(this).equals(methodResolution)
174+
&& declaredClass.resolve(this) instanceof ClassResolution declaredClassResolution
175+
&& declaredClassResolution.matches(methodResolution.getOwnerResolution())
176+
&& methodResolution.matches(declaredClassResolution.getDeclaredMemberResolution(methodEntry))) {
177+
return AstResolveResult.declared(methodPath);
178+
}
173179
return AstResolveResult.reference(methodPath);
174180
} else if (resolution instanceof MultiMemberResolution multiMemberResolution) {
175181
// Used in static star import contexts such as 'Math.*' or single method static imports such as 'Math.min'.

0 commit comments

Comments
 (0)