receiverType parameter.
This commit is contained in:
@@ -140,9 +140,9 @@ public class JetSourceNavigationHelper {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static <Decl extends JetDeclaration, Descr extends CallableDescriptor> JetDeclaration
|
private static <Decl extends JetDeclaration, Descr extends CallableDescriptor> JetDeclaration
|
||||||
getSourcePropertyOrFunction(final @NotNull Decl decompiledDeclaration,
|
getSourcePropertyOrFunction(
|
||||||
JetTypeReference receiverType,
|
final @NotNull Decl decompiledDeclaration,
|
||||||
NavigationStrategy<Decl, Descr> navigationStrategy
|
NavigationStrategy<Decl, Descr> navigationStrategy
|
||||||
) {
|
) {
|
||||||
String entityName = decompiledDeclaration.getName();
|
String entityName = decompiledDeclaration.getName();
|
||||||
if (entityName == null) {
|
if (entityName == null) {
|
||||||
@@ -151,6 +151,8 @@ public class JetSourceNavigationHelper {
|
|||||||
|
|
||||||
Name entityNameAsName = Name.identifier(entityName);
|
Name entityNameAsName = Name.identifier(entityName);
|
||||||
|
|
||||||
|
JetTypeReference receiverType = navigationStrategy.getReceiverType(decompiledDeclaration);
|
||||||
|
|
||||||
PsiElement declarationContainer = decompiledDeclaration.getParent();
|
PsiElement declarationContainer = decompiledDeclaration.getParent();
|
||||||
if (declarationContainer instanceof JetFile) {
|
if (declarationContainer instanceof JetFile) {
|
||||||
Pair<BindingContext, NamespaceDescriptor> bindingContextAndNamespaceDescriptor =
|
Pair<BindingContext, NamespaceDescriptor> bindingContextAndNamespaceDescriptor =
|
||||||
@@ -159,7 +161,7 @@ public class JetSourceNavigationHelper {
|
|||||||
BindingContext bindingContext = bindingContextAndNamespaceDescriptor.first;
|
BindingContext bindingContext = bindingContextAndNamespaceDescriptor.first;
|
||||||
NamespaceDescriptor namespaceDescriptor = bindingContextAndNamespaceDescriptor.second;
|
NamespaceDescriptor namespaceDescriptor = bindingContextAndNamespaceDescriptor.second;
|
||||||
if (receiverType == null) {
|
if (receiverType == null) {
|
||||||
// non-extension property
|
// non-extension member
|
||||||
for (Descr candidate : navigationStrategy.getCandidateDescriptors(namespaceDescriptor.getMemberScope(), entityNameAsName)) {
|
for (Descr candidate : navigationStrategy.getCandidateDescriptors(namespaceDescriptor.getMemberScope(), entityNameAsName)) {
|
||||||
if (candidate.getReceiverParameter() == null) {
|
if (candidate.getReceiverParameter() == null) {
|
||||||
if (navigationStrategy.declarationAndDescriptorMatch(decompiledDeclaration, candidate)) {
|
if (navigationStrategy.declarationAndDescriptorMatch(decompiledDeclaration, candidate)) {
|
||||||
@@ -169,7 +171,7 @@ public class JetSourceNavigationHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// extension property
|
// extension member
|
||||||
String expectedTypeString = receiverType.getText();
|
String expectedTypeString = receiverType.getText();
|
||||||
for (Descr candidate : navigationStrategy.getCandidateDescriptors(namespaceDescriptor.getMemberScope(), entityNameAsName)) {
|
for (Descr candidate : navigationStrategy.getCandidateDescriptors(namespaceDescriptor.getMemberScope(), entityNameAsName)) {
|
||||||
ReceiverParameterDescriptor receiverParameter = candidate.getReceiverParameter();
|
ReceiverParameterDescriptor receiverParameter = candidate.getReceiverParameter();
|
||||||
@@ -221,18 +223,20 @@ public class JetSourceNavigationHelper {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static JetDeclaration getSourceProperty(final @NotNull JetProperty decompiledProperty) {
|
public static JetDeclaration getSourceProperty(final @NotNull JetProperty decompiledProperty) {
|
||||||
return getSourcePropertyOrFunction(decompiledProperty, decompiledProperty.getReceiverTypeRef(), new PropertyNavigationStrategy());
|
return getSourcePropertyOrFunction(decompiledProperty, new PropertyNavigationStrategy());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static JetDeclaration getSourceFunction(final @NotNull JetFunction decompiledFunction) {
|
public static JetDeclaration getSourceFunction(final @NotNull JetFunction decompiledFunction) {
|
||||||
return getSourcePropertyOrFunction(decompiledFunction, decompiledFunction.getReceiverTypeRef(), new FunctionNavigationStrategy());
|
return getSourcePropertyOrFunction(decompiledFunction, new FunctionNavigationStrategy());
|
||||||
}
|
}
|
||||||
|
|
||||||
private interface NavigationStrategy<Decl extends JetDeclaration, Descr extends CallableDescriptor> {
|
private interface NavigationStrategy<Decl extends JetDeclaration, Descr extends CallableDescriptor> {
|
||||||
boolean declarationAndDescriptorMatch(Decl declaration, Descr descriptor);
|
boolean declarationAndDescriptorMatch(Decl declaration, Descr descriptor);
|
||||||
|
|
||||||
Collection<Descr> getCandidateDescriptors(JetScope scope, Name name);
|
Collection<Descr> getCandidateDescriptors(JetScope scope, Name name);
|
||||||
|
|
||||||
|
@Nullable JetTypeReference getReceiverType(@NotNull Decl declaration);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class FunctionNavigationStrategy implements NavigationStrategy<JetFunction, FunctionDescriptor> {
|
private static class FunctionNavigationStrategy implements NavigationStrategy<JetFunction, FunctionDescriptor> {
|
||||||
@@ -271,6 +275,12 @@ public class JetSourceNavigationHelper {
|
|||||||
public Collection<FunctionDescriptor> getCandidateDescriptors(JetScope scope, Name name) {
|
public Collection<FunctionDescriptor> getCandidateDescriptors(JetScope scope, Name name) {
|
||||||
return scope.getFunctions(name);
|
return scope.getFunctions(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public JetTypeReference getReceiverType(@NotNull JetFunction declaration) {
|
||||||
|
return declaration.getReceiverTypeRef();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class PropertyNavigationStrategy implements NavigationStrategy<JetProperty, VariableDescriptor> {
|
private static class PropertyNavigationStrategy implements NavigationStrategy<JetProperty, VariableDescriptor> {
|
||||||
@@ -283,5 +293,11 @@ public class JetSourceNavigationHelper {
|
|||||||
public Collection<VariableDescriptor> getCandidateDescriptors(JetScope scope, Name name) {
|
public Collection<VariableDescriptor> getCandidateDescriptors(JetScope scope, Name name) {
|
||||||
return scope.getProperties(name);
|
return scope.getProperties(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public JetTypeReference getReceiverType(@NotNull JetProperty declaration) {
|
||||||
|
return declaration.getReceiverTypeRef();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user