diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClass.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClass.java index 47e15fe4c71..4b3b5480b77 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClass.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClass.java @@ -207,20 +207,15 @@ public class JetClass extends JetTypeParameterListOwner */ @NotNull public List getSuperNames() { - final JetDelegationSpecifierList delegationSpecifierList = getDelegationSpecifierList(); - if (delegationSpecifierList == null) return Collections.emptyList(); - final List specifiers = delegationSpecifierList.getDelegationSpecifiers(); + final List specifiers = getDelegationSpecifiers(); if (specifiers.size() == 0) return Collections.emptyList(); List result = new ArrayList(); for (JetDelegationSpecifier specifier : specifiers) { - final JetTypeReference typeReference = specifier.getTypeReference(); - if (typeReference != null) { - final JetTypeElement typeElement = typeReference.getTypeElement(); - if (typeElement instanceof JetUserType) { - final String referencedName = ((JetUserType) typeElement).getReferencedName(); - if (referencedName != null) { - addSuperName(result, referencedName); - } + final JetUserType superType = specifier.getTypeAsUserType(); + if (superType != null) { + final String referencedName = superType.getReferencedName(); + if (referencedName != null) { + addSuperName(result, referencedName); } } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDelegationSpecifier.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDelegationSpecifier.java index aa0d200df7c..8790d3554e8 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDelegationSpecifier.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDelegationSpecifier.java @@ -43,4 +43,16 @@ public class JetDelegationSpecifier extends JetElement{ public JetTypeReference getTypeReference() { return (JetTypeReference) findChildByType(JetNodeTypes.TYPE_REFERENCE); } + + @Nullable + public JetUserType getTypeAsUserType() { + final JetTypeReference reference = getTypeReference(); + if (reference != null) { + final JetTypeElement element = reference.getTypeElement(); + if (element instanceof JetUserType) { + return ((JetUserType) element); + } + } + return null; + } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDelegatorToSuperCall.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDelegatorToSuperCall.java index 764e88117a2..ce7650afcd0 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDelegatorToSuperCall.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDelegatorToSuperCall.java @@ -82,16 +82,8 @@ public class JetDelegatorToSuperCall extends JetDelegationSpecifier implements J @Override public JetTypeArgumentList getTypeArgumentList() { - JetTypeReference typeReference = getTypeReference(); - if (typeReference == null) { - return null; - } - JetTypeElement typeElement = typeReference.getTypeElement(); - if (typeElement instanceof JetUserType) { - JetUserType userType = (JetUserType) typeElement; - return userType.getTypeArgumentList(); - } - return null; + final JetUserType userType = getTypeAsUserType(); + return userType != null ? userType.getTypeArgumentList() : null; } } diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index 88cfc9f789a..b916b9f6239 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -186,6 +186,7 @@ + { + public KotlinDirectInheritorsSearcher() { + super(true); + } + + @Override + public void processQuery(@NotNull DirectClassInheritorsSearch.SearchParameters queryParameters, @NotNull Processor consumer) { + final PsiClass clazz = queryParameters.getClassToProcess(); + final String name = clazz.getName(); + if (name == null || !(queryParameters.getScope() instanceof GlobalSearchScope)) return; + GlobalSearchScope scope = (GlobalSearchScope) queryParameters.getScope(); + final Collection candidates = JetSuperClassIndex.getInstance().get(name, clazz.getProject(), scope); + for (JetClassOrObject candidate : candidates) { + if (!(candidate instanceof JetClass)) continue; + final List specifiers = candidate.getDelegationSpecifiers(); + for (JetDelegationSpecifier specifier : specifiers) { + final JetUserType type = specifier.getTypeAsUserType(); + if (type != null) { + final JetSimpleNameExpression referenceExpression = type.getReferenceExpression(); + if (referenceExpression != null) { + final PsiReference reference = referenceExpression.getReference(); + final PsiElement resolved = reference != null ? reference.resolve() : null; + if (resolved instanceof PsiClass && resolved.isEquivalentTo(clazz)) { + consumer.process(JetLightClass.wrapDelegate((JetClass) candidate)); + } + } + } + } + } + } +}