From dc876e8eebbe4b4f0eff8fa5f03b21426bae969c Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Fri, 11 Jan 2013 17:43:54 +0400 Subject: [PATCH] Got rid of unnecessary type parameters. --- .../libraries/JetSourceNavigationHelper.java | 59 +++++++++---------- .../jet/plugin/libraries/MemberMatching.java | 20 ++----- 2 files changed, 33 insertions(+), 46 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/libraries/JetSourceNavigationHelper.java b/idea/src/org/jetbrains/jet/plugin/libraries/JetSourceNavigationHelper.java index f40483bb10b..83f917e580c 100644 --- a/idea/src/org/jetbrains/jet/plugin/libraries/JetSourceNavigationHelper.java +++ b/idea/src/org/jetbrains/jet/plugin/libraries/JetSourceNavigationHelper.java @@ -106,7 +106,7 @@ public class JetSourceNavigationHelper { return resultScope; } - private static List getContainingFiles(@NotNull Iterable declarations) { + private static List getContainingFiles(@NotNull Iterable declarations) { Set result = Sets.newHashSet(); for (JetNamedDeclaration declaration : declarations) { PsiFile containingFile = declaration.getContainingFile(); @@ -150,17 +150,14 @@ public class JetSourceNavigationHelper { } @Nullable - private static JetNamedDeclaration - getSourcePropertyOrFunction( - @NotNull final Decl decompiledDeclaration - ) { + private static JetNamedDeclaration getSourcePropertyOrFunction(@NotNull JetNamedDeclaration decompiledDeclaration) { String memberNameAsString = decompiledDeclaration.getName(); assert memberNameAsString != null; Name memberName = Name.identifier(memberNameAsString); PsiElement decompiledContainer = decompiledDeclaration.getParent(); - Collection candidates; + Collection candidates; if (decompiledContainer instanceof JetFile) { candidates = getInitialTopLevelCandidates(decompiledDeclaration); } @@ -168,9 +165,10 @@ public class JetSourceNavigationHelper { JetClassOrObject decompiledClassOrObject = (JetClassOrObject) decompiledContainer.getParent(); JetClassOrObject sourceClassOrObject = getSourceClassOrObject(decompiledClassOrObject); + //noinspection unchecked candidates = sourceClassOrObject == null - ? Collections.emptyList() - : getInitialMemberCandidates(sourceClassOrObject, memberName, (Class) decompiledDeclaration.getClass()); + ? Collections.emptyList() + : getInitialMemberCandidates(sourceClassOrObject, memberName, (Class) decompiledDeclaration.getClass()); if (candidates.isEmpty()) { if (decompiledDeclaration instanceof JetProperty && sourceClassOrObject instanceof JetClass) { @@ -213,9 +211,9 @@ public class JetSourceNavigationHelper { DefaultModuleConfiguration.createStandardConfiguration(project), providerFactory); - for (Decl candidate : candidates) { + for (JetNamedDeclaration candidate : candidates) { //noinspection unchecked - Descr candidateDescriptor = (Descr) resolveSession.resolveToDescriptor(candidate); + CallableDescriptor candidateDescriptor = (CallableDescriptor) resolveSession.resolveToDescriptor(candidate); if (receiversMatch(decompiledDeclaration, candidateDescriptor) && valueParametersTypesMatch(decompiledDeclaration, candidateDescriptor) && typeParametersMatch((JetTypeParameterListOwner) decompiledDeclaration, candidateDescriptor.getTypeParameters())) { @@ -244,7 +242,7 @@ public class JetSourceNavigationHelper { } @NotNull - private static Collection getInitialTopLevelCandidates(@NotNull Decl decompiledDeclaration) { + private static Collection getInitialTopLevelCandidates(@NotNull JetNamedDeclaration decompiledDeclaration) { FqName memberFqName = JetPsiUtil.getFQName(decompiledDeclaration); assert memberFqName != null; @@ -252,8 +250,9 @@ public class JetSourceNavigationHelper { if (librarySourcesScope == GlobalSearchScope.EMPTY_SCOPE) { // .getProject() == null for EMPTY_SCOPE, and this breaks code return Collections.emptyList(); } - StringStubIndexExtension index = - (StringStubIndexExtension) getIndexForTopLevelPropertyOrFunction(decompiledDeclaration); + //noinspection unchecked + StringStubIndexExtension index = + (StringStubIndexExtension) getIndexForTopLevelPropertyOrFunction(decompiledDeclaration); return index.get(memberFqName.getFqName(), decompiledDeclaration.getProject(), librarySourcesScope); } @@ -270,53 +269,53 @@ public class JetSourceNavigationHelper { } @NotNull - private static List getInitialMemberCandidates( + private static List getInitialMemberCandidates( @NotNull JetClassOrObject sourceClassOrObject, @NotNull final Name name, - @NotNull Class declarationClass + @NotNull Class declarationClass ) { - List allByClass = ContainerUtil.findAll(sourceClassOrObject.getDeclarations(), declarationClass); - return ContainerUtil.filter(allByClass, new Condition() { + List allByClass = ContainerUtil.findAll(sourceClassOrObject.getDeclarations(), declarationClass); + return ContainerUtil.filter(allByClass, new Condition() { @Override - public boolean value(Decl declaration) { + public boolean value(JetNamedDeclaration declaration) { return name.equals(declaration.getNameAsSafeName()); } }); } @NotNull - private static List filterByReceiverPresenceAndParametersCount( - final @NotNull Decl decompiledDeclaration, - @NotNull Collection candidates + private static List filterByReceiverPresenceAndParametersCount( + final @NotNull JetNamedDeclaration decompiledDeclaration, + @NotNull Collection candidates ) { - return ContainerUtil.filter(candidates, new Condition() { + return ContainerUtil.filter(candidates, new Condition() { @Override - public boolean value(Decl candidate) { + public boolean value(JetNamedDeclaration candidate) { return sameReceiverPresenceAndParametersCount(candidate, decompiledDeclaration); } }); } @NotNull - private static List filterByReceiverAndParameterTypes( - final @NotNull Decl decompiledDeclaration, - @NotNull Collection candidates + private static List filterByReceiverAndParameterTypes( + final @NotNull JetNamedDeclaration decompiledDeclaration, + @NotNull Collection candidates ) { - return ContainerUtil.filter(candidates, new Condition() { + return ContainerUtil.filter(candidates, new Condition() { @Override - public boolean value(Decl candidate) { + public boolean value(JetNamedDeclaration candidate) { return receiverAndParametersShortTypesMatch(candidate, decompiledDeclaration); } }); } @Nullable - public static JetNamedDeclaration getSourceProperty(final @NotNull JetProperty decompiledProperty) { + public static JetNamedDeclaration getSourceProperty(@NotNull JetProperty decompiledProperty) { return getSourcePropertyOrFunction(decompiledProperty); } @Nullable - public static JetNamedDeclaration getSourceFunction(final @NotNull JetNamedFunction decompiledFunction) { + public static JetNamedDeclaration getSourceFunction(@NotNull JetNamedFunction decompiledFunction) { return getSourcePropertyOrFunction(decompiledFunction); } diff --git a/idea/src/org/jetbrains/jet/plugin/libraries/MemberMatching.java b/idea/src/org/jetbrains/jet/plugin/libraries/MemberMatching.java index 9912db81ed7..e4ccd6a6072 100644 --- a/idea/src/org/jetbrains/jet/plugin/libraries/MemberMatching.java +++ b/idea/src/org/jetbrains/jet/plugin/libraries/MemberMatching.java @@ -102,19 +102,13 @@ public class MemberMatching { return getTypeShortName(a).equals(getTypeShortName(b)); } - static boolean sameReceiverPresenceAndParametersCount( - @NotNull Decl a, - @NotNull Decl b - ) { + static boolean sameReceiverPresenceAndParametersCount(@NotNull JetNamedDeclaration a, @NotNull JetNamedDeclaration b) { boolean sameReceiverPresence = (getReceiverType(a) == null) == (getReceiverType(b) == null); boolean sameParametersCount = getValueParameters(a).size() == getValueParameters(b).size(); return sameReceiverPresence && sameParametersCount; } - static boolean receiverAndParametersShortTypesMatch( - @NotNull Decl a, - @NotNull Decl b - ) { + static boolean receiverAndParametersShortTypesMatch(@NotNull JetNamedDeclaration a, @NotNull JetNamedDeclaration b) { JetTypeReference aReceiver = getReceiverType(a); JetTypeReference bReceiver = getReceiverType(b); if ((aReceiver == null) != (bReceiver == null)) { @@ -146,10 +140,7 @@ public class MemberMatching { /* DECLARATION AND DESCRIPTOR STRICT MATCHING */ - static boolean receiversMatch( - @NotNull Decl declaration, - @NotNull CallableDescriptor descriptor - ) { + static boolean receiversMatch(@NotNull JetNamedDeclaration declaration, @NotNull CallableDescriptor descriptor) { JetTypeReference declarationReceiver = getReceiverType(declaration); ReceiverParameterDescriptor descriptorReceiver = descriptor.getReceiverParameter(); if (declarationReceiver == null && descriptorReceiver == null) { @@ -161,10 +152,7 @@ public class MemberMatching { return false; } - static boolean valueParametersTypesMatch( - @NotNull Decl declaration, - @NotNull Descr descriptor - ) { + static boolean valueParametersTypesMatch(@NotNull JetNamedDeclaration declaration, @NotNull CallableDescriptor descriptor) { List declarationParameters = getValueParameters(declaration); List descriptorParameters = descriptor.getValueParameters(); if (descriptorParameters.size() != declarationParameters.size()) {