Got rid of unnecessary type parameters.

This commit is contained in:
Evgeny Gerashchenko
2013-01-11 17:43:54 +04:00
parent 085ccd7327
commit dc876e8eeb
2 changed files with 33 additions and 46 deletions
@@ -106,7 +106,7 @@ public class JetSourceNavigationHelper {
return resultScope; return resultScope;
} }
private static List<JetFile> getContainingFiles(@NotNull Iterable<? extends JetNamedDeclaration> declarations) { private static List<JetFile> getContainingFiles(@NotNull Iterable<JetNamedDeclaration> declarations) {
Set<JetFile> result = Sets.newHashSet(); Set<JetFile> result = Sets.newHashSet();
for (JetNamedDeclaration declaration : declarations) { for (JetNamedDeclaration declaration : declarations) {
PsiFile containingFile = declaration.getContainingFile(); PsiFile containingFile = declaration.getContainingFile();
@@ -150,17 +150,14 @@ public class JetSourceNavigationHelper {
} }
@Nullable @Nullable
private static <Decl extends JetNamedDeclaration, Descr extends CallableDescriptor> JetNamedDeclaration private static JetNamedDeclaration getSourcePropertyOrFunction(@NotNull JetNamedDeclaration decompiledDeclaration) {
getSourcePropertyOrFunction(
@NotNull final Decl decompiledDeclaration
) {
String memberNameAsString = decompiledDeclaration.getName(); String memberNameAsString = decompiledDeclaration.getName();
assert memberNameAsString != null; assert memberNameAsString != null;
Name memberName = Name.identifier(memberNameAsString); Name memberName = Name.identifier(memberNameAsString);
PsiElement decompiledContainer = decompiledDeclaration.getParent(); PsiElement decompiledContainer = decompiledDeclaration.getParent();
Collection<Decl> candidates; Collection<JetNamedDeclaration> candidates;
if (decompiledContainer instanceof JetFile) { if (decompiledContainer instanceof JetFile) {
candidates = getInitialTopLevelCandidates(decompiledDeclaration); candidates = getInitialTopLevelCandidates(decompiledDeclaration);
} }
@@ -168,9 +165,10 @@ public class JetSourceNavigationHelper {
JetClassOrObject decompiledClassOrObject = (JetClassOrObject) decompiledContainer.getParent(); JetClassOrObject decompiledClassOrObject = (JetClassOrObject) decompiledContainer.getParent();
JetClassOrObject sourceClassOrObject = getSourceClassOrObject(decompiledClassOrObject); JetClassOrObject sourceClassOrObject = getSourceClassOrObject(decompiledClassOrObject);
//noinspection unchecked
candidates = sourceClassOrObject == null candidates = sourceClassOrObject == null
? Collections.<Decl>emptyList() ? Collections.<JetNamedDeclaration>emptyList()
: getInitialMemberCandidates(sourceClassOrObject, memberName, (Class<Decl>) decompiledDeclaration.getClass()); : getInitialMemberCandidates(sourceClassOrObject, memberName, (Class<JetNamedDeclaration>) decompiledDeclaration.getClass());
if (candidates.isEmpty()) { if (candidates.isEmpty()) {
if (decompiledDeclaration instanceof JetProperty && sourceClassOrObject instanceof JetClass) { if (decompiledDeclaration instanceof JetProperty && sourceClassOrObject instanceof JetClass) {
@@ -213,9 +211,9 @@ public class JetSourceNavigationHelper {
DefaultModuleConfiguration.createStandardConfiguration(project), DefaultModuleConfiguration.createStandardConfiguration(project),
providerFactory); providerFactory);
for (Decl candidate : candidates) { for (JetNamedDeclaration candidate : candidates) {
//noinspection unchecked //noinspection unchecked
Descr candidateDescriptor = (Descr) resolveSession.resolveToDescriptor(candidate); CallableDescriptor candidateDescriptor = (CallableDescriptor) resolveSession.resolveToDescriptor(candidate);
if (receiversMatch(decompiledDeclaration, candidateDescriptor) if (receiversMatch(decompiledDeclaration, candidateDescriptor)
&& valueParametersTypesMatch(decompiledDeclaration, candidateDescriptor) && valueParametersTypesMatch(decompiledDeclaration, candidateDescriptor)
&& typeParametersMatch((JetTypeParameterListOwner) decompiledDeclaration, candidateDescriptor.getTypeParameters())) { && typeParametersMatch((JetTypeParameterListOwner) decompiledDeclaration, candidateDescriptor.getTypeParameters())) {
@@ -244,7 +242,7 @@ public class JetSourceNavigationHelper {
} }
@NotNull @NotNull
private static <Decl extends JetNamedDeclaration> Collection<Decl> getInitialTopLevelCandidates(@NotNull Decl decompiledDeclaration) { private static Collection<JetNamedDeclaration> getInitialTopLevelCandidates(@NotNull JetNamedDeclaration decompiledDeclaration) {
FqName memberFqName = JetPsiUtil.getFQName(decompiledDeclaration); FqName memberFqName = JetPsiUtil.getFQName(decompiledDeclaration);
assert memberFqName != null; assert memberFqName != null;
@@ -252,8 +250,9 @@ 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 = //noinspection unchecked
(StringStubIndexExtension<Decl>) getIndexForTopLevelPropertyOrFunction(decompiledDeclaration); StringStubIndexExtension<JetNamedDeclaration> index =
(StringStubIndexExtension<JetNamedDeclaration>) getIndexForTopLevelPropertyOrFunction(decompiledDeclaration);
return index.get(memberFqName.getFqName(), decompiledDeclaration.getProject(), librarySourcesScope); return index.get(memberFqName.getFqName(), decompiledDeclaration.getProject(), librarySourcesScope);
} }
@@ -270,53 +269,53 @@ public class JetSourceNavigationHelper {
} }
@NotNull @NotNull
private static <Decl extends JetNamedDeclaration> List<Decl> getInitialMemberCandidates( private static List<JetNamedDeclaration> getInitialMemberCandidates(
@NotNull JetClassOrObject sourceClassOrObject, @NotNull JetClassOrObject sourceClassOrObject,
@NotNull final Name name, @NotNull final Name name,
@NotNull Class<Decl> declarationClass @NotNull Class<JetNamedDeclaration> declarationClass
) { ) {
List<Decl> allByClass = ContainerUtil.findAll(sourceClassOrObject.getDeclarations(), declarationClass); List<JetNamedDeclaration> allByClass = ContainerUtil.findAll(sourceClassOrObject.getDeclarations(), declarationClass);
return ContainerUtil.filter(allByClass, new Condition<Decl>() { return ContainerUtil.filter(allByClass, new Condition<JetNamedDeclaration>() {
@Override @Override
public boolean value(Decl declaration) { public boolean value(JetNamedDeclaration declaration) {
return name.equals(declaration.getNameAsSafeName()); return name.equals(declaration.getNameAsSafeName());
} }
}); });
} }
@NotNull @NotNull
private static <Decl extends JetNamedDeclaration, Descr extends CallableDescriptor> List<Decl> filterByReceiverPresenceAndParametersCount( private static List<JetNamedDeclaration> filterByReceiverPresenceAndParametersCount(
final @NotNull Decl decompiledDeclaration, final @NotNull JetNamedDeclaration decompiledDeclaration,
@NotNull Collection<Decl> candidates @NotNull Collection<JetNamedDeclaration> candidates
) { ) {
return ContainerUtil.filter(candidates, new Condition<Decl>() { return ContainerUtil.filter(candidates, new Condition<JetNamedDeclaration>() {
@Override @Override
public boolean value(Decl candidate) { public boolean value(JetNamedDeclaration candidate) {
return sameReceiverPresenceAndParametersCount(candidate, decompiledDeclaration); return sameReceiverPresenceAndParametersCount(candidate, decompiledDeclaration);
} }
}); });
} }
@NotNull @NotNull
private static <Decl extends JetNamedDeclaration, Descr extends CallableDescriptor> List<Decl> filterByReceiverAndParameterTypes( private static List<JetNamedDeclaration> filterByReceiverAndParameterTypes(
final @NotNull Decl decompiledDeclaration, final @NotNull JetNamedDeclaration decompiledDeclaration,
@NotNull Collection<Decl> candidates @NotNull Collection<JetNamedDeclaration> candidates
) { ) {
return ContainerUtil.filter(candidates, new Condition<Decl>() { return ContainerUtil.filter(candidates, new Condition<JetNamedDeclaration>() {
@Override @Override
public boolean value(Decl candidate) { public boolean value(JetNamedDeclaration candidate) {
return receiverAndParametersShortTypesMatch(candidate, decompiledDeclaration); return receiverAndParametersShortTypesMatch(candidate, decompiledDeclaration);
} }
}); });
} }
@Nullable @Nullable
public static JetNamedDeclaration getSourceProperty(final @NotNull JetProperty decompiledProperty) { public static JetNamedDeclaration getSourceProperty(@NotNull JetProperty decompiledProperty) {
return getSourcePropertyOrFunction(decompiledProperty); return getSourcePropertyOrFunction(decompiledProperty);
} }
@Nullable @Nullable
public static JetNamedDeclaration getSourceFunction(final @NotNull JetNamedFunction decompiledFunction) { public static JetNamedDeclaration getSourceFunction(@NotNull JetNamedFunction decompiledFunction) {
return getSourcePropertyOrFunction(decompiledFunction); return getSourcePropertyOrFunction(decompiledFunction);
} }
@@ -102,19 +102,13 @@ public class MemberMatching {
return getTypeShortName(a).equals(getTypeShortName(b)); return getTypeShortName(a).equals(getTypeShortName(b));
} }
static <Decl extends JetNamedDeclaration> boolean sameReceiverPresenceAndParametersCount( static boolean sameReceiverPresenceAndParametersCount(@NotNull JetNamedDeclaration a, @NotNull JetNamedDeclaration b) {
@NotNull Decl a,
@NotNull Decl b
) {
boolean sameReceiverPresence = (getReceiverType(a) == null) == (getReceiverType(b) == null); boolean sameReceiverPresence = (getReceiverType(a) == null) == (getReceiverType(b) == null);
boolean sameParametersCount = getValueParameters(a).size() == getValueParameters(b).size(); boolean sameParametersCount = getValueParameters(a).size() == getValueParameters(b).size();
return sameReceiverPresence && sameParametersCount; return sameReceiverPresence && sameParametersCount;
} }
static <Decl extends JetNamedDeclaration> boolean receiverAndParametersShortTypesMatch( static boolean receiverAndParametersShortTypesMatch(@NotNull JetNamedDeclaration a, @NotNull JetNamedDeclaration b) {
@NotNull Decl a,
@NotNull Decl b
) {
JetTypeReference aReceiver = getReceiverType(a); JetTypeReference aReceiver = getReceiverType(a);
JetTypeReference bReceiver = getReceiverType(b); JetTypeReference bReceiver = getReceiverType(b);
if ((aReceiver == null) != (bReceiver == null)) { if ((aReceiver == null) != (bReceiver == null)) {
@@ -146,10 +140,7 @@ public class MemberMatching {
/* DECLARATION AND DESCRIPTOR STRICT MATCHING */ /* DECLARATION AND DESCRIPTOR STRICT MATCHING */
static <Decl extends JetNamedDeclaration> boolean receiversMatch( static boolean receiversMatch(@NotNull JetNamedDeclaration declaration, @NotNull CallableDescriptor descriptor) {
@NotNull Decl declaration,
@NotNull CallableDescriptor descriptor
) {
JetTypeReference declarationReceiver = getReceiverType(declaration); JetTypeReference declarationReceiver = getReceiverType(declaration);
ReceiverParameterDescriptor descriptorReceiver = descriptor.getReceiverParameter(); ReceiverParameterDescriptor descriptorReceiver = descriptor.getReceiverParameter();
if (declarationReceiver == null && descriptorReceiver == null) { if (declarationReceiver == null && descriptorReceiver == null) {
@@ -161,10 +152,7 @@ public class MemberMatching {
return false; return false;
} }
static <Decl extends JetNamedDeclaration, Descr extends CallableDescriptor> boolean valueParametersTypesMatch( static boolean valueParametersTypesMatch(@NotNull JetNamedDeclaration declaration, @NotNull CallableDescriptor descriptor) {
@NotNull Decl declaration,
@NotNull Descr descriptor
) {
List<JetParameter> declarationParameters = getValueParameters(declaration); List<JetParameter> declarationParameters = getValueParameters(declaration);
List<ValueParameterDescriptor> descriptorParameters = descriptor.getValueParameters(); List<ValueParameterDescriptor> descriptorParameters = descriptor.getValueParameters();
if (descriptorParameters.size() != declarationParameters.size()) { if (descriptorParameters.size() != declarationParameters.size()) {