Create from usage: Fixed a bug where extension methods could not be added properly.
This commit is contained in:
@@ -502,9 +502,12 @@ public class CreateMethodFromUsageFix extends CreateFromUsageFixBase {
|
|||||||
ownerClassDescriptor = (ClassDescriptor) ownerTypeDescriptor;
|
ownerClassDescriptor = (ClassDescriptor) ownerTypeDescriptor;
|
||||||
receiverType = ownerClassDescriptor.getDefaultType();
|
receiverType = ownerClassDescriptor.getDefaultType();
|
||||||
PsiElement typeDeclaration = BindingContextUtils.classDescriptorToDeclaration(currentFileContext, ownerClassDescriptor);
|
PsiElement typeDeclaration = BindingContextUtils.classDescriptorToDeclaration(currentFileContext, ownerClassDescriptor);
|
||||||
assert typeDeclaration != null;
|
if (typeDeclaration != null && typeDeclaration instanceof JetClass) {
|
||||||
ownerClass = (JetClass) typeDeclaration;
|
ownerClass = (JetClass) typeDeclaration;
|
||||||
isExtension = !ownerClass.isWritable();
|
isExtension = !ownerClass.isWritable();
|
||||||
|
} else {
|
||||||
|
isExtension = true;
|
||||||
|
}
|
||||||
isUnit = returnType.isType() && isUnit(returnType.getType());
|
isUnit = returnType.isType() && isUnit(returnType.getType());
|
||||||
|
|
||||||
// figure out type substitutions for type parameters
|
// figure out type substitutions for type parameters
|
||||||
@@ -565,7 +568,15 @@ public class CreateMethodFromUsageFix extends CreateFromUsageFixBase {
|
|||||||
BindingContext containingFileContext = currentFile.equals(containingFile)
|
BindingContext containingFileContext = currentFile.equals(containingFile)
|
||||||
? currentFileContext
|
? currentFileContext
|
||||||
: AnalyzerFacadeWithCache.analyzeFileWithCache(containingFile).getBindingContext();
|
: AnalyzerFacadeWithCache.analyzeFileWithCache(containingFile).getBindingContext();
|
||||||
JetScope scope = getScope(isExtension ? containingFile : ownerClass, containingFileContext);
|
JetScope scope;
|
||||||
|
if (isExtension) {
|
||||||
|
NamespaceDescriptor namespaceDescriptor = currentFileContext.get(BindingContext.FILE_TO_NAMESPACE, containingFile);
|
||||||
|
assert namespaceDescriptor != null;
|
||||||
|
scope = namespaceDescriptor.getMemberScope();
|
||||||
|
} else {
|
||||||
|
assert ownerClassDescriptor instanceof MutableClassDescriptor;
|
||||||
|
scope = ((MutableClassDescriptor) ownerClassDescriptor).getScopeForMemberResolution();
|
||||||
|
}
|
||||||
|
|
||||||
// build templates
|
// build templates
|
||||||
PsiDocumentManager.getInstance(project).commitAllDocuments();
|
PsiDocumentManager.getInstance(project).commitAllDocuments();
|
||||||
@@ -851,20 +862,6 @@ public class CreateMethodFromUsageFix extends CreateFromUsageFixBase {
|
|||||||
return newTypes;
|
return newTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private static JetScope getScope(@NotNull PsiElement owner, @NotNull BindingContext context) {
|
|
||||||
DeclarationDescriptor ownerDescriptor = context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, owner);
|
|
||||||
assert ownerDescriptor != null;
|
|
||||||
if (ownerDescriptor instanceof NamespaceDescriptor) {
|
|
||||||
NamespaceDescriptor namespaceDescriptor = (NamespaceDescriptor) ownerDescriptor;
|
|
||||||
return namespaceDescriptor.getMemberScope();
|
|
||||||
} else {
|
|
||||||
assert ownerDescriptor instanceof MutableClassDescriptor;
|
|
||||||
MutableClassDescriptor classDescriptor = (MutableClassDescriptor) ownerDescriptor;
|
|
||||||
return classDescriptor.getScopeForMemberResolution();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static String renderTypeShort(JetType type) {
|
private static String renderTypeShort(JetType type) {
|
||||||
return DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(type);
|
return DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(type);
|
||||||
|
|||||||
Reference in New Issue
Block a user