Skip to content

Commit

Permalink
Use render with short types names in completion lookup elements
Browse files Browse the repository at this point in the history
  • Loading branch information
goodwinnk committed Apr 18, 2014
1 parent f6276cc commit 962044f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
Expand Up @@ -64,39 +64,38 @@ public static LookupElement createLookupElement(@NotNull KotlinCodeAnalyzer anal
String presentableText = descriptor.getName().asString();
String typeText = "";
String tailText = "";
boolean tailTextGrayed = true;

if (descriptor instanceof FunctionDescriptor) {
FunctionDescriptor functionDescriptor = (FunctionDescriptor) descriptor;
JetType returnType = functionDescriptor.getReturnType();
typeText = DescriptorRenderer.TEXT.renderType(returnType);
presentableText += DescriptorRenderer.TEXT.renderFunctionParameters(functionDescriptor);
typeText = returnType != null ? DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(returnType) : "";
presentableText += DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderFunctionParameters(functionDescriptor);

boolean extensionFunction = functionDescriptor.getReceiverParameter() != null;
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
if (containingDeclaration != null && extensionFunction) {
tailText += " for " + DescriptorRenderer.TEXT.renderType(functionDescriptor.getReceiverParameter().getType());
tailText += " for " + DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(functionDescriptor.getReceiverParameter().getType());
tailText += " in " + DescriptorUtils.getFqName(containingDeclaration);
}
}
else if (descriptor instanceof VariableDescriptor) {
JetType outType = ((VariableDescriptor) descriptor).getType();
typeText = DescriptorRenderer.TEXT.renderType(outType);
typeText = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(outType);
}
else if (descriptor instanceof ClassDescriptor) {
DeclarationDescriptor declaredIn = descriptor.getContainingDeclaration();
assert declaredIn != null;
tailText = " (" + DescriptorUtils.getFqName(declaredIn) + ")";
tailTextGrayed = true;
}
else {
typeText = DescriptorRenderer.TEXT.render(descriptor);
typeText = DescriptorRenderer.SHORT_NAMES_IN_TYPES.render(descriptor);
}

element = element.withInsertHandler(getInsertHandler(descriptor));
element = element.withTailText(tailText, tailTextGrayed).withTypeText(typeText).withPresentableText(presentableText);
element = element.withTailText(tailText, true).withTypeText(typeText).withPresentableText(presentableText);
element = element.withIcon(JetDescriptorIconProvider.getIcon(descriptor, Iconable.ICON_FLAG_VISIBILITY));
element = element.withStrikeoutness(KotlinBuiltIns.getInstance().isDeprecated(descriptor));

return element;
}

Expand Down Expand Up @@ -138,7 +137,9 @@ private static LookupElement createJavaLookupElementIfPossible(@NotNull PsiEleme
if (containingClass != null && !JavaResolverPsiUtils.isCompiledKotlinClassOrPackageClass(containingClass)) {
if (declaration instanceof PsiMethod) {
InsertHandler<LookupElement> handler = getInsertHandler(descriptor);
assert handler != null: "Special kotlin handler is expected for function: " + declaration.getText() + " and descriptor" + DescriptorRenderer.TEXT.render(descriptor);
assert handler != null:
"Special kotlin handler is expected for function: " + declaration.getText() +
" and descriptor: " + DescriptorRenderer.TEXT.render(descriptor);

return new JavaMethodCallElementWithCustomHandler(declaration).setInsertHandler(handler);
}
Expand Down
Expand Up @@ -4,4 +4,4 @@ fun some() {
tes<caret>
}

// EXIST: { lookupString:"test", itemText:"test(a: kotlin.Int)" }
// EXIST: { lookupString:"test", itemText:"test(a: Int)" }
Expand Up @@ -8,5 +8,5 @@ fun firstFun() {
}

// INVOCATION_COUNT: 1
// EXIST: { lookupString:"toLinkedList", itemText:"toLinkedList()", tailText:" for kotlin.Iterable<T> in kotlin" }
// EXIST: { lookupString:"toLinkedList", itemText:"toLinkedList()", tailText:" for Iterable<T> in kotlin" }
// NUMBER: 1
4 changes: 2 additions & 2 deletions idea/testData/completion/smart/ClassObjectMembers.kt
Expand Up @@ -14,8 +14,8 @@ fun foo(){
val k : K = <caret>
}

// EXIST: { lookupString:"K.foo", itemText:"K.foo", tailText:" (sample)", typeText:"sample.K" }
// EXIST: { lookupString:"K.bar", itemText:"K.bar()", tailText:" (sample)", typeText:"sample.K" }
// EXIST: { lookupString:"K.foo", itemText:"K.foo", tailText:" (sample)", typeText:"K" }
// EXIST: { lookupString:"K.bar", itemText:"K.bar()", tailText:" (sample)", typeText:"K" }
// ABSENT: K.x
// ABSENT: K.kk
// ABSENT: K.privateVal
Expand Up @@ -13,7 +13,7 @@ fun foo(){
val k : K? = <caret>
}

// EXIST: { lookupString:"K.foo", itemText:"K.foo", tailText:" (sample)", typeText:"sample.K" }
// EXIST: { lookupString:"K.bar", itemText:"K.bar()", tailText:" (sample)", typeText:"sample.K" }
// EXIST: { lookupString:"K.foo", itemText:"K.foo", tailText:" (sample)", typeText:"K" }
// EXIST: { lookupString:"K.bar", itemText:"K.bar()", tailText:" (sample)", typeText:"K" }
// ABSENT: K.x
// EXIST: { lookupString:"K.kk", itemText:"K.kk", tailText:" (sample)", typeText:"sample.K?" }
// EXIST: { lookupString:"K.kk", itemText:"K.kk", tailText:" (sample)", typeText:"K?" }

0 comments on commit 962044f

Please sign in to comment.