Change representation of extension functions
This commit is contained in:
@@ -76,6 +76,11 @@ public final class JetDescriptorIconProvider {
|
||||
return PlatformIcons.PACKAGE_OPEN_ICON;
|
||||
}
|
||||
if (descriptor instanceof FunctionDescriptor) {
|
||||
FunctionDescriptor functionDescriptor = (FunctionDescriptor) descriptor;
|
||||
if (functionDescriptor.getReceiverParameter().exists()) {
|
||||
return JetIcons.EXTENSION_FUNCTION;
|
||||
}
|
||||
|
||||
return descriptor.getContainingDeclaration() instanceof ClassDescriptor ?
|
||||
PlatformIcons.METHOD_ICON : JetIcons.FUNCTION;
|
||||
}
|
||||
@@ -103,11 +108,11 @@ public final class JetDescriptorIconProvider {
|
||||
}
|
||||
|
||||
if (descriptor instanceof LocalVariableDescriptor) {
|
||||
return ((LocalVariableDescriptor)descriptor).isVar() ? JetIcons.VAR : JetIcons.VAL;
|
||||
return ((VariableDescriptor) descriptor).isVar() ? JetIcons.VAR : JetIcons.VAL;
|
||||
}
|
||||
|
||||
if (descriptor instanceof PropertyDescriptor) {
|
||||
return ((PropertyDescriptor)descriptor).isVar() ? JetIcons.FIELD_VAR : JetIcons.FIELD_VAL;
|
||||
return ((VariableDescriptor) descriptor).isVar() ? JetIcons.FIELD_VAR : JetIcons.FIELD_VAL;
|
||||
}
|
||||
|
||||
if (descriptor instanceof TypeParameterDescriptorImpl) {
|
||||
|
||||
@@ -50,6 +50,10 @@ public class JetIconProvider extends IconProvider {
|
||||
return (flags & Iconable.ICON_FLAG_OPEN) != 0 ? PlatformIcons.PACKAGE_OPEN_ICON : PlatformIcons.PACKAGE_ICON;
|
||||
}
|
||||
if (psiElement instanceof JetNamedFunction) {
|
||||
if (((JetFunction) psiElement).getReceiverTypeRef() != null) {
|
||||
return JetIcons.EXTENSION_FUNCTION;
|
||||
}
|
||||
|
||||
return PsiTreeUtil.getParentOfType(psiElement, JetNamedDeclaration.class) instanceof JetClass
|
||||
? PlatformIcons.METHOD_ICON
|
||||
: JetIcons.FUNCTION;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.jet.plugin;
|
||||
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.util.PlatformIcons;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
@@ -31,6 +32,7 @@ public interface JetIcons {
|
||||
Icon OBJECT = IconLoader.getIcon("/org/jetbrains/jet/plugin/icons/object.png");
|
||||
Icon TRAIT = IconLoader.getIcon("/org/jetbrains/jet/plugin/icons/trait.png");
|
||||
Icon FUNCTION = IconLoader.getIcon("/org/jetbrains/jet/plugin/icons/function.png");
|
||||
Icon EXTENSION_FUNCTION = PlatformIcons.FUNCTION_ICON;
|
||||
Icon LAMBDA = IconLoader.getIcon("/org/jetbrains/jet/plugin/icons/lambda.png");
|
||||
Icon VAR = IconLoader.getIcon("/org/jetbrains/jet/plugin/icons/variable.png");
|
||||
Icon VAL = IconLoader.getIcon("/org/jetbrains/jet/plugin/icons/value.png");
|
||||
|
||||
@@ -54,19 +54,22 @@ public final class DescriptorLookupConverter {
|
||||
|
||||
LookupElementBuilder element = LookupElementBuilder.create(
|
||||
new JetLookupObject(descriptor, bindingContext, declaration), descriptor.getName().getName());
|
||||
|
||||
String presentableText = descriptor.getName().getName();
|
||||
String typeText = "";
|
||||
String tailText = "";
|
||||
boolean tailTextGrayed = false;
|
||||
boolean tailTextGrayed = true;
|
||||
|
||||
if (descriptor instanceof FunctionDescriptor) {
|
||||
FunctionDescriptor functionDescriptor = (FunctionDescriptor) descriptor;
|
||||
JetType returnType = functionDescriptor.getReturnType();
|
||||
typeText = DescriptorRenderer.TEXT.renderType(returnType);
|
||||
tailText = DescriptorRenderer.TEXT.renderFunctionParameters(functionDescriptor);
|
||||
presentableText += DescriptorRenderer.TEXT.renderFunctionParameters(functionDescriptor);
|
||||
|
||||
boolean extensionFunction = functionDescriptor.getReceiverParameter().exists();
|
||||
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
||||
if (extensionFunction && containingDeclaration != null) {
|
||||
if (containingDeclaration != null && extensionFunction) {
|
||||
tailText += " for " + DescriptorRenderer.TEXT.renderType(functionDescriptor.getReceiverParameter().getType());
|
||||
tailText += " in " + DescriptorUtils.getFQName(containingDeclaration);
|
||||
}
|
||||
|
||||
@@ -94,7 +97,7 @@ public final class DescriptorLookupConverter {
|
||||
typeText = DescriptorRenderer.TEXT.render(descriptor);
|
||||
}
|
||||
|
||||
element = element.setTailText(tailText, tailTextGrayed).setTypeText(typeText);
|
||||
element = element.setTailText(tailText, tailTextGrayed).setTypeText(typeText).setPresentableText(presentableText);
|
||||
element = element.setIcon(JetDescriptorIconProvider.getIcon(descriptor, Iconable.ICON_FLAG_VISIBILITY));
|
||||
|
||||
return element;
|
||||
|
||||
@@ -22,6 +22,8 @@ import com.intellij.navigation.ItemPresentationProvider;
|
||||
import com.intellij.openapi.editor.colors.TextAttributesKey;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeReference;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.plugin.JetIconProvider;
|
||||
import org.jetbrains.jet.util.QualifiedNamesUtil;
|
||||
|
||||
@@ -46,7 +48,14 @@ public class JetFunctionPresenter implements ItemPresentationProvider<JetNamedFu
|
||||
|
||||
@Override
|
||||
public String getLocationString() {
|
||||
return String.format("(in %s)", QualifiedNamesUtil.withoutLastSegment(JetPsiUtil.getFQName(function)));
|
||||
FqName name = JetPsiUtil.getFQName(function);
|
||||
if (name != null) {
|
||||
JetTypeReference typeRef = function.getReturnTypeRef();
|
||||
String extensionLocation = typeRef != null ? "for " + typeRef.getText() + " " : "";
|
||||
return String.format("(%sin %s)", extensionLocation, QualifiedNamesUtil.withoutLastSegment(name));
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -9,6 +9,6 @@ fun firstFun() {
|
||||
|
||||
// RUNTIME: 1
|
||||
// TIME: 1
|
||||
// EXIST: toLinkedList~() in kotlin
|
||||
// EXIST: toLinkedList~() in kotlin.nullable
|
||||
// EXIST: toLinkedList@toLinkedList()~for java.lang.Iterable<T> in kotlin
|
||||
// EXIST: toLinkedList@toLinkedList()~for T? in kotlin.nullable
|
||||
// NUMBER: 2
|
||||
@@ -4,4 +4,4 @@ fun some() {
|
||||
tes<caret>
|
||||
}
|
||||
|
||||
// EXIST: test~(a : jet.Int)
|
||||
// EXIST: test@test(a : jet.Int)
|
||||
@@ -29,6 +29,8 @@ import org.jetbrains.jet.testing.InTextDirectivesUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Extract a number of statements about completion from the given text. Those statements
|
||||
@@ -39,13 +41,21 @@ import java.util.List;
|
||||
public class ExpectedCompletionUtils {
|
||||
|
||||
public static class CompletionProposal {
|
||||
public static final Pattern PATTERN = Pattern.compile("([^~@]*)(@([^~]*))?(~(.*))?");
|
||||
public static final int LOOKUP_STRING_GROUP_INDEX = 1;
|
||||
public static final int PRESENTABLE_STRING_GROUP_INDEX = 3;
|
||||
public static final int TAIL_TEXT_STRING_GROUP_INDEX = 5;
|
||||
|
||||
public static final String TAIL_FLAG = "~";
|
||||
public static final String PRESENTABLE_FLAG = "@";
|
||||
|
||||
private final String lookupString;
|
||||
private final String presenterText;
|
||||
private final String tailString;
|
||||
|
||||
public CompletionProposal(@NotNull String lookupString, @Nullable String tailString) {
|
||||
public CompletionProposal(@NotNull String lookupString, @Nullable String presenterText, @Nullable String tailString) {
|
||||
this.lookupString = lookupString;
|
||||
this.presenterText = presenterText != null ? presenterText.trim() : null;
|
||||
this.tailString = tailString != null ? tailString.trim() : null;
|
||||
}
|
||||
|
||||
@@ -56,16 +66,27 @@ public class ExpectedCompletionUtils {
|
||||
}
|
||||
}
|
||||
|
||||
if (proposal.presenterText != null) {
|
||||
if (!proposal.presenterText.equals(presenterText)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return lookupString.equals(proposal.lookupString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (tailString != null) {
|
||||
return lookupString + TAIL_FLAG + tailString;
|
||||
StringBuilder result = new StringBuilder(lookupString);
|
||||
if (presenterText != null) {
|
||||
result.append(PRESENTABLE_FLAG).append(presenterText);
|
||||
}
|
||||
|
||||
return lookupString;
|
||||
if (tailString != null) {
|
||||
result.append(TAIL_FLAG).append(tailString);
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,15 +124,11 @@ public class ExpectedCompletionUtils {
|
||||
public static CompletionProposal[] processProposalAssertions(String prefix, String fileText) {
|
||||
List<CompletionProposal> proposals = new ArrayList<CompletionProposal>();
|
||||
for (String proposalStr : InTextDirectivesUtils.findListWithPrefix(prefix, fileText)) {
|
||||
int tailChar = proposalStr.indexOf(CompletionProposal.TAIL_FLAG);
|
||||
|
||||
if (tailChar > 0) {
|
||||
proposals.add(new CompletionProposal(proposalStr.substring(0, tailChar),
|
||||
proposalStr.substring(tailChar + 1, proposalStr.length())));
|
||||
}
|
||||
else {
|
||||
proposals.add(new CompletionProposal(proposalStr, null));
|
||||
}
|
||||
Matcher matcher = CompletionProposal.PATTERN.matcher(proposalStr);
|
||||
matcher.find();
|
||||
proposals.add(new CompletionProposal(matcher.group(CompletionProposal.LOOKUP_STRING_GROUP_INDEX),
|
||||
matcher.group(CompletionProposal.PRESENTABLE_STRING_GROUP_INDEX),
|
||||
matcher.group(CompletionProposal.TAIL_TEXT_STRING_GROUP_INDEX)));
|
||||
}
|
||||
|
||||
return ArrayUtil.toObjectArray(proposals, CompletionProposal.class);
|
||||
@@ -162,7 +179,7 @@ public class ExpectedCompletionUtils {
|
||||
if (items != null) {
|
||||
for (LookupElement item : items) {
|
||||
item.renderElement(presentation);
|
||||
result.add(new ExpectedCompletionUtils.CompletionProposal(item.getLookupString(), presentation.getTailText()));
|
||||
result.add(new ExpectedCompletionUtils.CompletionProposal(item.getLookupString(), presentation.getItemText(), presentation.getTailText()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user