From c47704ab8686a92d4a6d2c6c0d496f3b0bd84e09 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Sat, 29 Dec 2012 14:29:52 +0400 Subject: [PATCH] Got rid of code duplication. --- .../libraries/JetSourceNavigationHelper.java | 41 ++++++++----------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/libraries/JetSourceNavigationHelper.java b/idea/src/org/jetbrains/jet/plugin/libraries/JetSourceNavigationHelper.java index 3f2d32be00d..1ccc2c83b6a 100644 --- a/idea/src/org/jetbrains/jet/plugin/libraries/JetSourceNavigationHelper.java +++ b/idea/src/org/jetbrains/jet/plugin/libraries/JetSourceNavigationHelper.java @@ -160,29 +160,11 @@ public class JetSourceNavigationHelper { if (bindingContextAndNamespaceDescriptor == null) return null; BindingContext bindingContext = bindingContextAndNamespaceDescriptor.first; NamespaceDescriptor namespaceDescriptor = bindingContextAndNamespaceDescriptor.second; - if (receiverType == null) { - // non-extension member - for (Descr candidate : navigationStrategy.getCandidateDescriptors(namespaceDescriptor.getMemberScope(), entityNameAsName)) { - if (candidate.getReceiverParameter() == null) { - if (navigationStrategy.declarationAndDescriptorMatch(decompiledDeclaration, candidate)) { - return (JetDeclaration) BindingContextUtils.descriptorToDeclaration(bindingContext, candidate); - } - } - } - } - else { - // extension member - String expectedTypeString = receiverType.getText(); - for (Descr candidate : navigationStrategy.getCandidateDescriptors(namespaceDescriptor.getMemberScope(), entityNameAsName)) { - ReceiverParameterDescriptor receiverParameter = candidate.getReceiverParameter(); - if (receiverParameter != null) { - String thisReceiverType = DescriptorRenderer.TEXT.renderType(receiverParameter.getType()); - if (expectedTypeString.equals(thisReceiverType)) { - if (navigationStrategy.declarationAndDescriptorMatch(decompiledDeclaration, candidate)) { - return (JetDeclaration) BindingContextUtils.descriptorToDeclaration(bindingContext, candidate); - } - } - } + + for (Descr candidate : navigationStrategy.getCandidateDescriptors(namespaceDescriptor.getMemberScope(), entityNameAsName)) { + if (receiversMatch(receiverType, candidate.getReceiverParameter()) + && navigationStrategy.declarationAndDescriptorMatch(decompiledDeclaration, candidate)) { + return (JetDeclaration) BindingContextUtils.descriptorToDeclaration(bindingContext, candidate); } } } @@ -220,6 +202,19 @@ public class JetSourceNavigationHelper { return null; } + private static boolean receiversMatch( + @Nullable JetTypeReference receiverTypeRef, + @Nullable ReceiverParameterDescriptor receiverParameter + ) { + if (receiverTypeRef == null && receiverParameter == null) { + return true; + } + if (receiverTypeRef != null && receiverParameter != null) { + return receiverTypeRef.getText().equals(DescriptorRenderer.TEXT.renderType(receiverParameter.getType())); + } + return false; + } + @Nullable public static JetDeclaration getSourceProperty(final @NotNull JetProperty decompiledProperty) { return getSourcePropertyOrFunction(decompiledProperty, new PropertyNavigationStrategy());