|
13 | 13 | import software.coley.sourcesolver.model.CompilationUnitModel; |
14 | 14 | import software.coley.sourcesolver.model.ErroneousModel; |
15 | 15 | import software.coley.sourcesolver.model.MethodBodyModel; |
| 16 | +import software.coley.sourcesolver.model.MethodModel; |
16 | 17 | import software.coley.sourcesolver.model.Model; |
17 | 18 | import software.coley.sourcesolver.model.TypeModel; |
18 | 19 | import software.coley.sourcesolver.model.VariableModel; |
@@ -164,12 +165,17 @@ else if (resolution instanceof ClassResolution classResolution) { |
164 | 165 | if (methodPath == null) |
165 | 166 | return null; |
166 | 167 |
|
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 |
169 | 171 | 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 | + } |
173 | 179 | return AstResolveResult.reference(methodPath); |
174 | 180 | } else if (resolution instanceof MultiMemberResolution multiMemberResolution) { |
175 | 181 | // Used in static star import contexts such as 'Math.*' or single method static imports such as 'Math.min'. |
|
0 commit comments