Got rid of two methods of MemberNavigationStrategy.

This commit is contained in:
Evgeny Gerashchenko
2013-01-11 17:07:27 +04:00
parent 9120732ad3
commit 897cfc534e
2 changed files with 19 additions and 39 deletions
@@ -46,6 +46,8 @@ import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.lexer.JetTokens;
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.Collections;
@@ -161,7 +163,7 @@ public class JetSourceNavigationHelper {
Collection<Decl> candidates;
if (decompiledContainer instanceof JetFile) {
candidates = getInitialTopLevelCandidates(decompiledDeclaration, navigationStrategy);
candidates = getInitialTopLevelCandidates(decompiledDeclaration);
}
else if (decompiledContainer instanceof JetClassBody) {
JetClassOrObject decompiledClassOrObject = (JetClassOrObject) decompiledContainer.getParent();
@@ -169,8 +171,7 @@ public class JetSourceNavigationHelper {
candidates = sourceClassOrObject == null
? Collections.<Decl>emptyList()
: getInitialMemberCandidates(sourceClassOrObject, memberName,
navigationStrategy.getDeclarationClass());
: getInitialMemberCandidates(sourceClassOrObject, memberName, (Class<Decl>) decompiledDeclaration.getClass());
if (candidates.isEmpty()) {
if (decompiledDeclaration instanceof JetProperty && sourceClassOrObject instanceof JetClass) {
@@ -245,10 +246,7 @@ public class JetSourceNavigationHelper {
}
@NotNull
private static <Decl extends JetNamedDeclaration, Descr extends CallableDescriptor> Collection<Decl> getInitialTopLevelCandidates(
@NotNull Decl decompiledDeclaration,
@NotNull MemberNavigationStrategy<Decl, Descr> navigationStrategy
) {
private static <Decl extends JetNamedDeclaration> Collection<Decl> getInitialTopLevelCandidates(@NotNull Decl decompiledDeclaration) {
FqName memberFqName = JetPsiUtil.getFQName(decompiledDeclaration);
assert memberFqName != null;
@@ -256,10 +254,23 @@ public class JetSourceNavigationHelper {
if (librarySourcesScope == GlobalSearchScope.EMPTY_SCOPE) { // .getProject() == null for EMPTY_SCOPE, and this breaks code
return Collections.emptyList();
}
StringStubIndexExtension<Decl> index = navigationStrategy.getIndexForTopLevelMembers();
StringStubIndexExtension<Decl> index =
(StringStubIndexExtension<Decl>) getIndexForTopLevelPropertyOrFunction(decompiledDeclaration);
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
private static <Decl extends JetNamedDeclaration> List<Decl> getInitialMemberCandidates(
@NotNull JetClassOrObject sourceClassOrObject,
@@ -16,7 +16,6 @@
package org.jetbrains.jet.plugin.libraries;
import com.intellij.psi.stubs.StringStubIndexExtension;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
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.VariableDescriptor;
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.List;
interface MemberNavigationStrategy<Decl extends JetNamedDeclaration, Descr extends CallableDescriptor> {
@NotNull
Class<Decl> getDeclarationClass();
@NotNull
List<JetParameter> getValueParameters(@NotNull Decl declaration);
@@ -43,15 +37,7 @@ interface MemberNavigationStrategy<Decl extends JetNamedDeclaration, Descr exten
@Nullable
JetTypeReference getReceiverType(@NotNull Decl declaration);
@NotNull
StringStubIndexExtension<Decl> getIndexForTopLevelMembers();
class FunctionStrategy implements MemberNavigationStrategy<JetNamedFunction, FunctionDescriptor> {
@NotNull
@Override
public Class<JetNamedFunction> getDeclarationClass() {
return JetNamedFunction.class;
}
@NotNull
@Override
@@ -70,20 +56,9 @@ interface MemberNavigationStrategy<Decl extends JetNamedDeclaration, Descr exten
public JetTypeReference getReceiverType(@NotNull JetNamedFunction declaration) {
return declaration.getReceiverTypeRef();
}
@NotNull
@Override
public StringStubIndexExtension<JetNamedFunction> getIndexForTopLevelMembers() {
return JetTopLevelFunctionsFqnNameIndex.getInstance();
}
}
class PropertyStrategy implements MemberNavigationStrategy<JetProperty, VariableDescriptor> {
@NotNull
@Override
public Class<JetProperty> getDeclarationClass() {
return JetProperty.class;
}
@NotNull
@Override
@@ -102,11 +77,5 @@ interface MemberNavigationStrategy<Decl extends JetNamedDeclaration, Descr exten
public JetTypeReference getReceiverType(@NotNull JetProperty declaration) {
return declaration.getReceiverTypeRef();
}
@NotNull
@Override
public StringStubIndexExtension<JetProperty> getIndexForTopLevelMembers() {
return JetTopLevelPropertiesFqnNameIndex.getInstance();
}
}
}