From 0cd9c2d9a86505114c6b8978fbdd0b5e3fbb139d Mon Sep 17 00:00:00 2001 From: Jack Zhou Date: Sun, 21 Apr 2013 14:20:36 -0400 Subject: [PATCH] Create from usage: Fixed an overly restrictive assertion. --- .../plugin/quickfix/CreateMethodFromUsageFix.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/CreateMethodFromUsageFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/CreateMethodFromUsageFix.java index 9c4f3efe800..1c8397aa7b5 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/CreateMethodFromUsageFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/CreateMethodFromUsageFix.java @@ -570,8 +570,7 @@ public class CreateMethodFromUsageFix extends CreateFromUsageFixBase { if (possibleClassDescriptor != null) { String className = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(possibleClassDescriptor.getDefaultType()); DeclarationDescriptor namespaceDescriptor = possibleClassDescriptor.getContainingDeclaration(); - assert namespaceDescriptor instanceof NamespaceDescriptor; - String namespace = ((NamespaceDescriptor) namespaceDescriptor).getFqName().getFqName(); + String namespace = renderDescriptor(namespaceDescriptor, true); String option = className + " (" + namespace + ")"; options.add(option); optionToTypeMap.put(option, ownerTypeCandidate); @@ -1025,14 +1024,16 @@ public class CreateMethodFromUsageFix extends CreateFromUsageFixBase { if (declarationDescriptor instanceof TypeParameterDescriptor) { String replacement = typeParameterNameMap.get(declarationDescriptor); return replacement == null ? declarationDescriptor.getName().getName() : replacement; - } else if (declarationDescriptor instanceof ClassDescriptor) { - return fq ? DescriptorUtils.getFQName(declarationDescriptor).getFqName() : declarationDescriptor.getName().getName(); } else { - assert false : "unexpected descriptor in type"; - return null; + return fq ? DescriptorUtils.getFQName(declarationDescriptor).getFqName() : declarationDescriptor.getName().getName(); } } + @NotNull + private static String renderDescriptor(@NotNull DeclarationDescriptor declarationDescriptor, boolean fq) { + return renderDescriptor(declarationDescriptor, Collections.emptyMap(), fq); + } + private static String renderType(@NotNull JetType type, @NotNull Map typeParameterNameMap, boolean fq) { List projections = type.getArguments(); DeclarationDescriptor declarationDescriptor = type.getConstructor().getDeclarationDescriptor();