Got rid of MemberNavigationStrategy.

This commit is contained in:
Evgeny Gerashchenko
2013-01-11 17:39:05 +04:00
parent 6d567750d1
commit 085ccd7327
3 changed files with 9 additions and 46 deletions
@@ -152,8 +152,7 @@ public class JetSourceNavigationHelper {
@Nullable @Nullable
private static <Decl extends JetNamedDeclaration, Descr extends CallableDescriptor> JetNamedDeclaration private static <Decl extends JetNamedDeclaration, Descr extends CallableDescriptor> JetNamedDeclaration
getSourcePropertyOrFunction( getSourcePropertyOrFunction(
@NotNull final Decl decompiledDeclaration, @NotNull final Decl decompiledDeclaration
@NotNull final MemberNavigationStrategy<Decl, Descr> navigationStrategy
) { ) {
String memberNameAsString = decompiledDeclaration.getName(); String memberNameAsString = decompiledDeclaration.getName();
assert memberNameAsString != null; assert memberNameAsString != null;
@@ -185,14 +184,14 @@ public class JetSourceNavigationHelper {
} }
if (!forceResolve) { if (!forceResolve) {
candidates = filterByReceiverPresenceAndParametersCount(decompiledDeclaration, navigationStrategy, candidates); candidates = filterByReceiverPresenceAndParametersCount(decompiledDeclaration, candidates);
if (candidates.size() <= 1) { if (candidates.size() <= 1) {
return candidates.isEmpty() ? null : candidates.iterator().next(); return candidates.isEmpty() ? null : candidates.iterator().next();
} }
if (!haveRenamesInImports(getContainingFiles(candidates))) { if (!haveRenamesInImports(getContainingFiles(candidates))) {
candidates = filterByReceiverAndParameterTypes(decompiledDeclaration, navigationStrategy, candidates); candidates = filterByReceiverAndParameterTypes(decompiledDeclaration, candidates);
if (candidates.size() <= 1) { if (candidates.size() <= 1) {
return candidates.isEmpty() ? null : candidates.iterator().next(); return candidates.isEmpty() ? null : candidates.iterator().next();
@@ -217,8 +216,8 @@ public class JetSourceNavigationHelper {
for (Decl candidate : candidates) { for (Decl candidate : candidates) {
//noinspection unchecked //noinspection unchecked
Descr candidateDescriptor = (Descr) resolveSession.resolveToDescriptor(candidate); Descr candidateDescriptor = (Descr) resolveSession.resolveToDescriptor(candidate);
if (receiversMatch(navigationStrategy, decompiledDeclaration, candidateDescriptor) if (receiversMatch(decompiledDeclaration, candidateDescriptor)
&& valueParametersTypesMatch(navigationStrategy, decompiledDeclaration, candidateDescriptor) && valueParametersTypesMatch(decompiledDeclaration, candidateDescriptor)
&& typeParametersMatch((JetTypeParameterListOwner) decompiledDeclaration, candidateDescriptor.getTypeParameters())) { && typeParametersMatch((JetTypeParameterListOwner) decompiledDeclaration, candidateDescriptor.getTypeParameters())) {
return candidate; return candidate;
} }
@@ -288,13 +287,12 @@ public class JetSourceNavigationHelper {
@NotNull @NotNull
private static <Decl extends JetNamedDeclaration, Descr extends CallableDescriptor> List<Decl> filterByReceiverPresenceAndParametersCount( private static <Decl extends JetNamedDeclaration, Descr extends CallableDescriptor> List<Decl> filterByReceiverPresenceAndParametersCount(
final @NotNull Decl decompiledDeclaration, final @NotNull Decl decompiledDeclaration,
final @NotNull MemberNavigationStrategy<Decl, Descr> navigationStrategy,
@NotNull Collection<Decl> candidates @NotNull Collection<Decl> candidates
) { ) {
return ContainerUtil.filter(candidates, new Condition<Decl>() { return ContainerUtil.filter(candidates, new Condition<Decl>() {
@Override @Override
public boolean value(Decl candidate) { public boolean value(Decl candidate) {
return sameReceiverPresenceAndParametersCount(navigationStrategy, candidate, decompiledDeclaration); return sameReceiverPresenceAndParametersCount(candidate, decompiledDeclaration);
} }
}); });
} }
@@ -302,25 +300,24 @@ public class JetSourceNavigationHelper {
@NotNull @NotNull
private static <Decl extends JetNamedDeclaration, Descr extends CallableDescriptor> List<Decl> filterByReceiverAndParameterTypes( private static <Decl extends JetNamedDeclaration, Descr extends CallableDescriptor> List<Decl> filterByReceiverAndParameterTypes(
final @NotNull Decl decompiledDeclaration, final @NotNull Decl decompiledDeclaration,
final @NotNull MemberNavigationStrategy<Decl, Descr> navigationStrategy,
@NotNull Collection<Decl> candidates @NotNull Collection<Decl> candidates
) { ) {
return ContainerUtil.filter(candidates, new Condition<Decl>() { return ContainerUtil.filter(candidates, new Condition<Decl>() {
@Override @Override
public boolean value(Decl candidate) { public boolean value(Decl candidate) {
return receiverAndParametersShortTypesMatch(navigationStrategy, candidate, decompiledDeclaration); return receiverAndParametersShortTypesMatch(candidate, decompiledDeclaration);
} }
}); });
} }
@Nullable @Nullable
public static JetNamedDeclaration getSourceProperty(final @NotNull JetProperty decompiledProperty) { public static JetNamedDeclaration getSourceProperty(final @NotNull JetProperty decompiledProperty) {
return getSourcePropertyOrFunction(decompiledProperty, new MemberNavigationStrategy.PropertyStrategy()); return getSourcePropertyOrFunction(decompiledProperty);
} }
@Nullable @Nullable
public static JetNamedDeclaration getSourceFunction(final @NotNull JetNamedFunction decompiledFunction) { public static JetNamedDeclaration getSourceFunction(final @NotNull JetNamedFunction decompiledFunction) {
return getSourcePropertyOrFunction(decompiledFunction, new MemberNavigationStrategy.FunctionStrategy()); return getSourcePropertyOrFunction(decompiledFunction);
} }
@TestOnly @TestOnly
@@ -103,7 +103,6 @@ public class MemberMatching {
} }
static <Decl extends JetNamedDeclaration> boolean sameReceiverPresenceAndParametersCount( static <Decl extends JetNamedDeclaration> boolean sameReceiverPresenceAndParametersCount(
@NotNull MemberNavigationStrategy<Decl, ?> navigationStrategy,
@NotNull Decl a, @NotNull Decl a,
@NotNull Decl b @NotNull Decl b
) { ) {
@@ -113,7 +112,6 @@ public class MemberMatching {
} }
static <Decl extends JetNamedDeclaration> boolean receiverAndParametersShortTypesMatch( static <Decl extends JetNamedDeclaration> boolean receiverAndParametersShortTypesMatch(
@NotNull MemberNavigationStrategy<Decl, ?> navigationStrategy,
@NotNull Decl a, @NotNull Decl a,
@NotNull Decl b @NotNull Decl b
) { ) {
@@ -149,7 +147,6 @@ public class MemberMatching {
/* DECLARATION AND DESCRIPTOR STRICT MATCHING */ /* DECLARATION AND DESCRIPTOR STRICT MATCHING */
static <Decl extends JetNamedDeclaration> boolean receiversMatch( static <Decl extends JetNamedDeclaration> boolean receiversMatch(
@NotNull MemberNavigationStrategy<Decl, ?> navigationStrategy,
@NotNull Decl declaration, @NotNull Decl declaration,
@NotNull CallableDescriptor descriptor @NotNull CallableDescriptor descriptor
) { ) {
@@ -165,7 +162,6 @@ public class MemberMatching {
} }
static <Decl extends JetNamedDeclaration, Descr extends CallableDescriptor> boolean valueParametersTypesMatch( static <Decl extends JetNamedDeclaration, Descr extends CallableDescriptor> boolean valueParametersTypesMatch(
@NotNull MemberNavigationStrategy<Decl, Descr> navigationStrategy,
@NotNull Decl declaration, @NotNull Decl declaration,
@NotNull Descr descriptor @NotNull Descr descriptor
) { ) {
@@ -1,30 +0,0 @@
/*
* Copyright 2010-2013 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.libraries;
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
import org.jetbrains.jet.lang.psi.*;
interface MemberNavigationStrategy<Decl extends JetNamedDeclaration, Descr extends CallableDescriptor> {
class FunctionStrategy implements MemberNavigationStrategy<JetNamedFunction, FunctionDescriptor> {
}
class PropertyStrategy implements MemberNavigationStrategy<JetProperty, VariableDescriptor> {
}
}