Got rid of two methods of MemberNavigationStrategy.
This commit is contained in:
@@ -46,6 +46,8 @@ import org.jetbrains.jet.lang.resolve.name.Name;
|
|||||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||||
import org.jetbrains.jet.lexer.JetTokens;
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
import org.jetbrains.jet.plugin.stubindex.JetFullClassNameIndex;
|
import org.jetbrains.jet.plugin.stubindex.JetFullClassNameIndex;
|
||||||
|
import org.jetbrains.jet.plugin.stubindex.JetTopLevelFunctionsFqnNameIndex;
|
||||||
|
import org.jetbrains.jet.plugin.stubindex.JetTopLevelPropertiesFqnNameIndex;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -161,7 +163,7 @@ public class JetSourceNavigationHelper {
|
|||||||
|
|
||||||
Collection<Decl> candidates;
|
Collection<Decl> candidates;
|
||||||
if (decompiledContainer instanceof JetFile) {
|
if (decompiledContainer instanceof JetFile) {
|
||||||
candidates = getInitialTopLevelCandidates(decompiledDeclaration, navigationStrategy);
|
candidates = getInitialTopLevelCandidates(decompiledDeclaration);
|
||||||
}
|
}
|
||||||
else if (decompiledContainer instanceof JetClassBody) {
|
else if (decompiledContainer instanceof JetClassBody) {
|
||||||
JetClassOrObject decompiledClassOrObject = (JetClassOrObject) decompiledContainer.getParent();
|
JetClassOrObject decompiledClassOrObject = (JetClassOrObject) decompiledContainer.getParent();
|
||||||
@@ -169,8 +171,7 @@ public class JetSourceNavigationHelper {
|
|||||||
|
|
||||||
candidates = sourceClassOrObject == null
|
candidates = sourceClassOrObject == null
|
||||||
? Collections.<Decl>emptyList()
|
? Collections.<Decl>emptyList()
|
||||||
: getInitialMemberCandidates(sourceClassOrObject, memberName,
|
: getInitialMemberCandidates(sourceClassOrObject, memberName, (Class<Decl>) decompiledDeclaration.getClass());
|
||||||
navigationStrategy.getDeclarationClass());
|
|
||||||
|
|
||||||
if (candidates.isEmpty()) {
|
if (candidates.isEmpty()) {
|
||||||
if (decompiledDeclaration instanceof JetProperty && sourceClassOrObject instanceof JetClass) {
|
if (decompiledDeclaration instanceof JetProperty && sourceClassOrObject instanceof JetClass) {
|
||||||
@@ -245,10 +246,7 @@ public class JetSourceNavigationHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static <Decl extends JetNamedDeclaration, Descr extends CallableDescriptor> Collection<Decl> getInitialTopLevelCandidates(
|
private static <Decl extends JetNamedDeclaration> Collection<Decl> getInitialTopLevelCandidates(@NotNull Decl decompiledDeclaration) {
|
||||||
@NotNull Decl decompiledDeclaration,
|
|
||||||
@NotNull MemberNavigationStrategy<Decl, Descr> navigationStrategy
|
|
||||||
) {
|
|
||||||
FqName memberFqName = JetPsiUtil.getFQName(decompiledDeclaration);
|
FqName memberFqName = JetPsiUtil.getFQName(decompiledDeclaration);
|
||||||
assert memberFqName != null;
|
assert memberFqName != null;
|
||||||
|
|
||||||
@@ -256,10 +254,23 @@ public class JetSourceNavigationHelper {
|
|||||||
if (librarySourcesScope == GlobalSearchScope.EMPTY_SCOPE) { // .getProject() == null for EMPTY_SCOPE, and this breaks code
|
if (librarySourcesScope == GlobalSearchScope.EMPTY_SCOPE) { // .getProject() == null for EMPTY_SCOPE, and this breaks code
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
StringStubIndexExtension<Decl> index = navigationStrategy.getIndexForTopLevelMembers();
|
StringStubIndexExtension<Decl> index =
|
||||||
|
(StringStubIndexExtension<Decl>) getIndexForTopLevelPropertyOrFunction(decompiledDeclaration);
|
||||||
return index.get(memberFqName.getFqName(), decompiledDeclaration.getProject(), librarySourcesScope);
|
return index.get(memberFqName.getFqName(), decompiledDeclaration.getProject(), librarySourcesScope);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static StringStubIndexExtension<? extends JetNamedDeclaration> getIndexForTopLevelPropertyOrFunction(
|
||||||
|
@NotNull JetNamedDeclaration decompiledDeclaration
|
||||||
|
) {
|
||||||
|
if (decompiledDeclaration instanceof JetNamedFunction) {
|
||||||
|
return JetTopLevelFunctionsFqnNameIndex.getInstance();
|
||||||
|
}
|
||||||
|
if (decompiledDeclaration instanceof JetProperty) {
|
||||||
|
return JetTopLevelPropertiesFqnNameIndex.getInstance();
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("Neither function nor declaration: " + decompiledDeclaration.getClass().getName());
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static <Decl extends JetNamedDeclaration> List<Decl> getInitialMemberCandidates(
|
private static <Decl extends JetNamedDeclaration> List<Decl> getInitialMemberCandidates(
|
||||||
@NotNull JetClassOrObject sourceClassOrObject,
|
@NotNull JetClassOrObject sourceClassOrObject,
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.plugin.libraries;
|
package org.jetbrains.jet.plugin.libraries;
|
||||||
|
|
||||||
import com.intellij.psi.stubs.StringStubIndexExtension;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||||
@@ -24,16 +23,11 @@ import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
|||||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.plugin.stubindex.JetTopLevelFunctionsFqnNameIndex;
|
|
||||||
import org.jetbrains.jet.plugin.stubindex.JetTopLevelPropertiesFqnNameIndex;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
interface MemberNavigationStrategy<Decl extends JetNamedDeclaration, Descr extends CallableDescriptor> {
|
interface MemberNavigationStrategy<Decl extends JetNamedDeclaration, Descr extends CallableDescriptor> {
|
||||||
@NotNull
|
|
||||||
Class<Decl> getDeclarationClass();
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
List<JetParameter> getValueParameters(@NotNull Decl declaration);
|
List<JetParameter> getValueParameters(@NotNull Decl declaration);
|
||||||
|
|
||||||
@@ -43,15 +37,7 @@ interface MemberNavigationStrategy<Decl extends JetNamedDeclaration, Descr exten
|
|||||||
@Nullable
|
@Nullable
|
||||||
JetTypeReference getReceiverType(@NotNull Decl declaration);
|
JetTypeReference getReceiverType(@NotNull Decl declaration);
|
||||||
|
|
||||||
@NotNull
|
|
||||||
StringStubIndexExtension<Decl> getIndexForTopLevelMembers();
|
|
||||||
|
|
||||||
class FunctionStrategy implements MemberNavigationStrategy<JetNamedFunction, FunctionDescriptor> {
|
class FunctionStrategy implements MemberNavigationStrategy<JetNamedFunction, FunctionDescriptor> {
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Class<JetNamedFunction> getDeclarationClass() {
|
|
||||||
return JetNamedFunction.class;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
@@ -70,20 +56,9 @@ interface MemberNavigationStrategy<Decl extends JetNamedDeclaration, Descr exten
|
|||||||
public JetTypeReference getReceiverType(@NotNull JetNamedFunction declaration) {
|
public JetTypeReference getReceiverType(@NotNull JetNamedFunction declaration) {
|
||||||
return declaration.getReceiverTypeRef();
|
return declaration.getReceiverTypeRef();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public StringStubIndexExtension<JetNamedFunction> getIndexForTopLevelMembers() {
|
|
||||||
return JetTopLevelFunctionsFqnNameIndex.getInstance();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class PropertyStrategy implements MemberNavigationStrategy<JetProperty, VariableDescriptor> {
|
class PropertyStrategy implements MemberNavigationStrategy<JetProperty, VariableDescriptor> {
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Class<JetProperty> getDeclarationClass() {
|
|
||||||
return JetProperty.class;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
@@ -102,11 +77,5 @@ interface MemberNavigationStrategy<Decl extends JetNamedDeclaration, Descr exten
|
|||||||
public JetTypeReference getReceiverType(@NotNull JetProperty declaration) {
|
public JetTypeReference getReceiverType(@NotNull JetProperty declaration) {
|
||||||
return declaration.getReceiverTypeRef();
|
return declaration.getReceiverTypeRef();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public StringStubIndexExtension<JetProperty> getIndexForTopLevelMembers() {
|
|
||||||
return JetTopLevelPropertiesFqnNameIndex.getInstance();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user