дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-03 16:51:16 +02:00
fix(java): go to an interface method implemented by a superclass (#7781)
Go to Implementation on an interface method found nothing when the implementing class inherits the method from a superclass that does not implement the interface itself. The superclass's method is now listed, once however many classes inherit it. Closes #7760
Цей коміт міститься в:
1 джерело
82fdd97588
коміт
e86e28ae63
3 files changed
+45
-1
No files matched your search
Бінарний файл не відображається.
+20
-1
@@ -2,8 +2,10 @@ package ai.openidea.implementations;
|
||||
|
||||
import ai.openidea.Documents;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.OperationCanceledException;
|
||||
@@ -76,6 +78,7 @@ public final class ImplementationsCommand implements IDelegateCommandHandler {
|
||||
CreateTypeHierarchyOperation operation = new CreateTypeHierarchyOperation(type, workingCopies, scope, true);
|
||||
operation.runOperation(monitor);
|
||||
ITypeHierarchy hierarchy = operation.getResult();
|
||||
Set<IMember> seen = new HashSet<>();
|
||||
for (IType subtype : hierarchy.getAllSubtypes(type)) {
|
||||
if (monitor.isCanceled()) throw new OperationCanceledException();
|
||||
IMember found;
|
||||
@@ -84,14 +87,30 @@ public final class ImplementationsCommand implements IDelegateCommandHandler {
|
||||
} else {
|
||||
// Seen from the subtype, so its type arguments substitute the method's type variables.
|
||||
IMethod overriding = new MethodOverrideTester(subtype, hierarchy).findOverridingMethodInType(subtype, method);
|
||||
if (overriding == null && !subtype.isInterface()) overriding = inherited(subtype, method, monitor);
|
||||
found = overriding == null || Flags.isAbstract(overriding.getFlags()) ? null : overriding;
|
||||
}
|
||||
Location location = found == null ? null : JDTUtils.toLocation(found);
|
||||
Location location = found == null || !seen.add(found) ? null : JDTUtils.toLocation(found);
|
||||
if (location != null) result.add(location);
|
||||
}
|
||||
return !type.isBinary();
|
||||
}
|
||||
|
||||
/**
|
||||
* The method of a superclass of {@code type} that implements {@code method} for it: a class
|
||||
* that implements an interface with a method it inherits from a class that doesn't.
|
||||
*/
|
||||
private static IMethod inherited(IType type, IMethod method, IProgressMonitor monitor) throws JavaModelException {
|
||||
ITypeHierarchy supertypes = type.newSupertypeHierarchy(monitor);
|
||||
MethodOverrideTester tester = new MethodOverrideTester(type, supertypes);
|
||||
for (IType s = supertypes.getSuperclass(type); s != null; s = supertypes.getSuperclass(s)) {
|
||||
if (s.isInterface()) break;
|
||||
IMethod found = tester.findOverridingMethodInType(s, method);
|
||||
if (found != null) return found;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** The project's compiled Kotlin classes, attached as a library by the Kotlin bridge. */
|
||||
private static boolean isKotlinOutput(IPackageFragmentRoot root) throws JavaModelException {
|
||||
if (root.getKind() != IPackageFragmentRoot.K_BINARY) return false;
|
||||
|
||||
@@ -86,6 +86,29 @@ public class Words implements SubRepo {
|
||||
return "words";
|
||||
}
|
||||
}
|
||||
''',
|
||||
'Handler.java': '''package zoo;
|
||||
|
||||
public interface Handler {
|
||||
void handle();
|
||||
}
|
||||
''',
|
||||
'BaseHandler.java': '''package zoo;
|
||||
|
||||
public class BaseHandler {
|
||||
public void handle() {
|
||||
}
|
||||
}
|
||||
''',
|
||||
'HandlerImpl.java': '''package zoo;
|
||||
|
||||
public class HandlerImpl extends BaseHandler implements Handler {
|
||||
}
|
||||
''',
|
||||
'OtherHandler.java': '''package zoo;
|
||||
|
||||
public class OtherHandler extends BaseHandler implements Handler {
|
||||
}
|
||||
''',
|
||||
'Task.java': '''package zoo;
|
||||
|
||||
@@ -246,6 +269,8 @@ try:
|
||||
('Repo.java', 'save(T'): (['Anon.java:5', 'Anon.java:9', 'Longs.java:0', 'Numbers.java:3', 'Words.java:3'], True),
|
||||
('Use.java', 'save("x")'): (['Anon.java:5', 'Anon.java:9', 'Longs.java:0', 'Numbers.java:3', 'Words.java:3'], True),
|
||||
('Repo.java', 'name()'): (['Words.java:6'], True),
|
||||
# Implemented by a superclass of the implementing classes, listed once.
|
||||
('Handler.java', 'handle()'): (['BaseHandler.java:3'], True),
|
||||
# A library type's implementations in the sources; the library has more.
|
||||
('Use.java', 'Runnable task'): (['Task.java:2'], False),
|
||||
('Use.java', 'run();'): (['Task.java:3'], False),
|
||||
|
||||
Reference in new issue
Заблокувати користувача