inheritor navigation works from Java to Kotlin
This commit is contained in:
@@ -207,20 +207,15 @@ public class JetClass extends JetTypeParameterListOwner
|
|||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public List<String> getSuperNames() {
|
public List<String> getSuperNames() {
|
||||||
final JetDelegationSpecifierList delegationSpecifierList = getDelegationSpecifierList();
|
final List<JetDelegationSpecifier> specifiers = getDelegationSpecifiers();
|
||||||
if (delegationSpecifierList == null) return Collections.emptyList();
|
|
||||||
final List<JetDelegationSpecifier> specifiers = delegationSpecifierList.getDelegationSpecifiers();
|
|
||||||
if (specifiers.size() == 0) return Collections.emptyList();
|
if (specifiers.size() == 0) return Collections.emptyList();
|
||||||
List<String> result = new ArrayList<String>();
|
List<String> result = new ArrayList<String>();
|
||||||
for (JetDelegationSpecifier specifier : specifiers) {
|
for (JetDelegationSpecifier specifier : specifiers) {
|
||||||
final JetTypeReference typeReference = specifier.getTypeReference();
|
final JetUserType superType = specifier.getTypeAsUserType();
|
||||||
if (typeReference != null) {
|
if (superType != null) {
|
||||||
final JetTypeElement typeElement = typeReference.getTypeElement();
|
final String referencedName = superType.getReferencedName();
|
||||||
if (typeElement instanceof JetUserType) {
|
if (referencedName != null) {
|
||||||
final String referencedName = ((JetUserType) typeElement).getReferencedName();
|
addSuperName(result, referencedName);
|
||||||
if (referencedName != null) {
|
|
||||||
addSuperName(result, referencedName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,4 +43,16 @@ public class JetDelegationSpecifier extends JetElement{
|
|||||||
public JetTypeReference getTypeReference() {
|
public JetTypeReference getTypeReference() {
|
||||||
return (JetTypeReference) findChildByType(JetNodeTypes.TYPE_REFERENCE);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,16 +82,8 @@ public class JetDelegatorToSuperCall extends JetDelegationSpecifier implements J
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JetTypeArgumentList getTypeArgumentList() {
|
public JetTypeArgumentList getTypeArgumentList() {
|
||||||
JetTypeReference typeReference = getTypeReference();
|
final JetUserType userType = getTypeAsUserType();
|
||||||
if (typeReference == null) {
|
return userType != null ? userType.getTypeArgumentList() : null;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
JetTypeElement typeElement = typeReference.getTypeElement();
|
|
||||||
if (typeElement instanceof JetUserType) {
|
|
||||||
JetUserType userType = (JetUserType) typeElement;
|
|
||||||
return userType.getTypeArgumentList();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -186,6 +186,7 @@
|
|||||||
<psi.treeChangePreprocessor implementation="org.jetbrains.jet.asJava.JetCodeBlockModificationListener"/>
|
<psi.treeChangePreprocessor implementation="org.jetbrains.jet.asJava.JetCodeBlockModificationListener"/>
|
||||||
|
|
||||||
<referencesSearch implementation="org.jetbrains.jet.plugin.references.KotlinReferencesSearcher"/>
|
<referencesSearch implementation="org.jetbrains.jet.plugin.references.KotlinReferencesSearcher"/>
|
||||||
|
<directClassInheritorsSearch implementation="org.jetbrains.jet.plugin.references.KotlinDirectInheritorsSearcher"/>
|
||||||
|
|
||||||
<toolWindow id="Kotlin"
|
<toolWindow id="Kotlin"
|
||||||
factoryClass="org.jetbrains.jet.plugin.internal.KotlinInternalToolWindowFactory"
|
factoryClass="org.jetbrains.jet.plugin.internal.KotlinInternalToolWindowFactory"
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2012 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.jet.plugin.references;
|
||||||
|
|
||||||
|
import com.intellij.openapi.application.QueryExecutorBase;
|
||||||
|
import com.intellij.psi.PsiClass;
|
||||||
|
import com.intellij.psi.PsiElement;
|
||||||
|
import com.intellij.psi.PsiReference;
|
||||||
|
import com.intellij.psi.search.GlobalSearchScope;
|
||||||
|
import com.intellij.psi.search.searches.DirectClassInheritorsSearch;
|
||||||
|
import com.intellij.util.Processor;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.asJava.JetLightClass;
|
||||||
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
|
import org.jetbrains.jet.plugin.stubindex.JetSuperClassIndex;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author yole
|
||||||
|
*/
|
||||||
|
public class KotlinDirectInheritorsSearcher extends QueryExecutorBase<PsiClass, DirectClassInheritorsSearch.SearchParameters> {
|
||||||
|
public KotlinDirectInheritorsSearcher() {
|
||||||
|
super(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void processQuery(@NotNull DirectClassInheritorsSearch.SearchParameters queryParameters, @NotNull Processor<PsiClass> 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<JetClassOrObject> candidates = JetSuperClassIndex.getInstance().get(name, clazz.getProject(), scope);
|
||||||
|
for (JetClassOrObject candidate : candidates) {
|
||||||
|
if (!(candidate instanceof JetClass)) continue;
|
||||||
|
final List<JetDelegationSpecifier> 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user