Supported multi-reference in imports (SAM interfaces are resolved as both functions and classes).
This commit is contained in:
@@ -87,14 +87,15 @@ public class MapPlatformClassToKotlinFix extends JetIntentionAction<JetReference
|
|||||||
if (diagnostic.getFactory() != Errors.PLATFORM_CLASS_MAPPED_TO_KOTLIN) continue;
|
if (diagnostic.getFactory() != Errors.PLATFORM_CLASS_MAPPED_TO_KOTLIN) continue;
|
||||||
JetReferenceExpression refExpr = getImportOrUsageFromDiagnostic(diagnostic);
|
JetReferenceExpression refExpr = getImportOrUsageFromDiagnostic(diagnostic);
|
||||||
if (refExpr == null) continue;
|
if (refExpr == null) continue;
|
||||||
DeclarationDescriptor descriptor = context.get(BindingContext.REFERENCE_TARGET, refExpr);
|
ClassDescriptor descriptor = resolveToClass(refExpr, context);
|
||||||
if (descriptor == null || !(descriptor.equals(platformClass))) continue;
|
if (descriptor == null || !(descriptor.equals(platformClass))) continue;
|
||||||
JetImportDirective imp = PsiTreeUtil.getParentOfType(refExpr, JetImportDirective.class);
|
JetImportDirective imp = PsiTreeUtil.getParentOfType(refExpr, JetImportDirective.class);
|
||||||
if (imp == null) {
|
if (imp == null) {
|
||||||
JetUserType type = PsiTreeUtil.getParentOfType(refExpr, JetUserType.class);
|
JetUserType type = PsiTreeUtil.getParentOfType(refExpr, JetUserType.class);
|
||||||
if (type == null) continue;
|
if (type == null) continue;
|
||||||
usages.add(type);
|
usages.add(type);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
imports.add(imp);
|
imports.add(imp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -193,9 +194,8 @@ public class MapPlatformClassToKotlinFix extends JetIntentionAction<JetReference
|
|||||||
|
|
||||||
Project project = diagnostic.getPsiFile().getProject();
|
Project project = diagnostic.getPsiFile().getProject();
|
||||||
BindingContext context = KotlinCacheManager.getInstance(project).getDeclarationsFromProject().getBindingContext();
|
BindingContext context = KotlinCacheManager.getInstance(project).getDeclarationsFromProject().getBindingContext();
|
||||||
DeclarationDescriptor descriptor = context.get(BindingContext.REFERENCE_TARGET, typeExpr);
|
ClassDescriptor platformClass = resolveToClass(typeExpr, context);
|
||||||
if (descriptor == null || !(descriptor instanceof ClassDescriptor)) return null;
|
if (platformClass == null) return null;
|
||||||
ClassDescriptor platformClass = (ClassDescriptor) descriptor;
|
|
||||||
|
|
||||||
assert diagnostic.getFactory() == Errors.PLATFORM_CLASS_MAPPED_TO_KOTLIN;
|
assert diagnostic.getFactory() == Errors.PLATFORM_CLASS_MAPPED_TO_KOTLIN;
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@@ -206,4 +206,22 @@ public class MapPlatformClassToKotlinFix extends JetIntentionAction<JetReference
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private static ClassDescriptor resolveToClass(@NotNull JetReferenceExpression referenceExpression, @NotNull BindingContext context) {
|
||||||
|
DeclarationDescriptor descriptor = context.get(BindingContext.REFERENCE_TARGET, referenceExpression);
|
||||||
|
Collection<? extends DeclarationDescriptor> ambiguousTargets =
|
||||||
|
context.get(BindingContext.AMBIGUOUS_REFERENCE_TARGET, referenceExpression);
|
||||||
|
if (descriptor instanceof ClassDescriptor) {
|
||||||
|
return (ClassDescriptor) descriptor;
|
||||||
|
}
|
||||||
|
else if (ambiguousTargets != null) {
|
||||||
|
for (DeclarationDescriptor target : ambiguousTargets) {
|
||||||
|
if (target instanceof ClassDescriptor) {
|
||||||
|
return (ClassDescriptor) target;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user