diff --git a/java/java-impl/src/com/intellij/codeInsight/lookup/VariableLookupItem.java b/java/java-impl/src/com/intellij/codeInsight/lookup/VariableLookupItem.java index f582048e9f82..faa20264a14d 100644 --- a/java/java-impl/src/com/intellij/codeInsight/lookup/VariableLookupItem.java +++ b/java/java-impl/src/com/intellij/codeInsight/lookup/VariableLookupItem.java @@ -45,6 +45,7 @@ import java.awt.*; * @author peter */ public class VariableLookupItem extends LookupItem implements TypedLookupItem, StaticallyImportable { + private static final String EQ = " = "; @Nullable private final MemberLookupHelper myHelper; private final Color myColor; private final String myTailText; @@ -77,7 +78,7 @@ public class VariableLookupItem extends LookupItem implements Typed String initText = initializer == null ? null : initializer.getText(); if (StringUtil.isEmpty(initText)) return null; - String prefix = var instanceof PsiEnumConstant ? "" : " = "; + String prefix = var instanceof PsiEnumConstant ? "" : EQ; String suffix = var instanceof PsiEnumConstant && ((PsiEnumConstant)var).getInitializingClass() != null ? " {...}" : ""; return StringUtil.trimLog(prefix + initText + suffix, 30); } @@ -159,7 +160,11 @@ public class VariableLookupItem extends LookupItem implements Typed presentation.setTypeText(getType().getPresentableText()); } if (myTailText != null && StringUtil.isEmpty(presentation.getTailText())) { - presentation.setTailText(myTailText, true); + if (myTailText.startsWith(EQ)) { + presentation.appendTailTextItalic(" (" + myTailText + ")", true); + } else { + presentation.setTailText(myTailText, true); + } } } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy index 2d5e29f00193..287d2964f2e6 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/JavaAutoPopupTest.groovy @@ -1448,7 +1448,7 @@ class Foo {{ def constant = myFixture.lookupElements.find { it.lookupString == 'Util.CONSTANT' } LookupElementPresentation p = ApplicationManager.application.runReadAction ({ LookupElementPresentation.renderElement(constant) } as Computable) assert p.itemText == 'Util.CONSTANT' - assert p.tailText == ' = 2 (foo)' + assert p.tailText == ' ( = 2) (foo)' assert p.typeText == 'int' type 'fo\n' diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy index 4bfd4c8b3d33..477be032ea96 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/NormalCompletionTest.groovy @@ -1707,7 +1707,8 @@ class Bar { assert LookupElementPresentation.renderElement(myFixture.lookup.items[0]).tailText == '( "x")' assert LookupElementPresentation.renderElement(myFixture.lookup.items[1]).tailText == '("y") {...}' assert !LookupElementPresentation.renderElement(myFixture.lookup.items[2]).tailText - assert LookupElementPresentation.renderElement(myFixture.lookup.items[3]).tailText == ' = 42' + assert LookupElementPresentation.renderElement(myFixture.lookup.items[3]).tailText == ' ( = 42)' + assert LookupElementPresentation.renderElement(myFixture.lookup.items[3]).tailFragments[0].italic } void testSuggestInterfaceArrayWhenObjectIsExpected() { diff --git a/platform/lang-api/src/com/intellij/codeInsight/lookup/LookupElementPresentation.java b/platform/lang-api/src/com/intellij/codeInsight/lookup/LookupElementPresentation.java index 770e51245490..4539dbeb0d11 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/lookup/LookupElementPresentation.java +++ b/platform/lang-api/src/com/intellij/codeInsight/lookup/LookupElementPresentation.java @@ -17,7 +17,6 @@ package com.intellij.codeInsight.lookup; import com.intellij.openapi.util.text.StringUtil; import com.intellij.ui.JBColor; -import com.intellij.util.Function; import com.intellij.util.SmartList; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -67,7 +66,11 @@ public class LookupElementPresentation { } public void appendTailText(@NotNull String text, boolean grayed) { - appendTailText(new TextFragment(text, grayed, null)); + appendTailText(new TextFragment(text, grayed, false, null)); + } + + public void appendTailTextItalic(@NotNull String text, boolean grayed) { + appendTailText(new TextFragment(text, grayed, true, null)); } private void appendTailText(@NotNull TextFragment fragment) { @@ -80,14 +83,14 @@ public class LookupElementPresentation { public void setTailText(@Nullable String text, boolean grayed) { clearTail(); if (text != null) { - appendTailText(new TextFragment(text, grayed, null)); + appendTailText(new TextFragment(text, grayed, false, null)); } } public void setTailText(@Nullable String text, @Nullable Color foreground) { clearTail(); if (text != null) { - appendTailText(new TextFragment(text, false, foreground)); + appendTailText(new TextFragment(text, false, false, foreground)); } } @@ -101,7 +104,7 @@ public class LookupElementPresentation { } /** - * Is equivalent to instanceof {@link com.intellij.codeInsight.lookup.RealLookupElementPresentation} check. + * Is equivalent to instanceof {@link RealLookupElementPresentation} check. * * @return whether the presentation is requested to actually render lookup element on screen, or just to estimate its width. * In the second, 'non-real' case, some heavy operations (e.g. getIcon()) can be omitted (only icon width is important) @@ -127,7 +130,7 @@ public class LookupElementPresentation { @NotNull public List getTailFragments() { - return myTail == null ? Collections.emptyList() : Collections.unmodifiableList(myTail); + return myTail == null ? Collections.emptyList() : Collections.unmodifiableList(myTail); } @Nullable @@ -147,13 +150,13 @@ public class LookupElementPresentation { @Deprecated public boolean isTailGrayed() { - return myTail != null && myTail.get(0).grayed; + return myTail != null && myTail.get(0).myGrayed; } @Nullable @Deprecated public Color getTailForeground() { - return myTail != null ? myTail.get(0).fgColor : null; + return myTail != null ? myTail.get(0).myFgColor : null; } public boolean isItemTextBold() { @@ -217,31 +220,37 @@ public class LookupElementPresentation { public static class TextFragment { public final String text; - private final boolean grayed; - @Nullable private final Color fgColor; + private final boolean myGrayed; + private final boolean myItalic; + @Nullable private final Color myFgColor; - public TextFragment(String text, boolean grayed, @Nullable Color fgColor) { + private TextFragment(String text, boolean grayed, boolean italic, @Nullable Color fgColor) { this.text = text; - this.grayed = grayed; - this.fgColor = fgColor; + myGrayed = grayed; + myItalic = italic; + myFgColor = fgColor; } @Override public String toString() { return "TextFragment{" + "text='" + text + '\'' + - ", grayed=" + grayed + - ", fgColor=" + fgColor + + ", grayed=" + myGrayed + + ", fgColor=" + myFgColor + '}'; } public boolean isGrayed() { - return grayed; + return myGrayed; + } + + public boolean isItalic() { + return myItalic; } @Nullable public Color getForegroundColor() { - return fgColor; + return myFgColor; } } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupCellRenderer.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupCellRenderer.java index 2f0d1188e08f..8e5744dcef11 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupCellRenderer.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupCellRenderer.java @@ -266,7 +266,8 @@ public class LookupCellRenderer implements ListCellRenderer { } String trimmed = trimLabelText(fragment.text, allowedWidth, fontMetrics); - myTailComponent.append(trimmed, new SimpleTextAttributes(style, getTailTextColor(isSelected, fragment, foreground, nonFocusedSelection))); + int fragmentStyle = fragment.isItalic() ? style | SimpleTextAttributes.STYLE_ITALIC : style; + myTailComponent.append(trimmed, new SimpleTextAttributes(fragmentStyle, getTailTextColor(isSelected, fragment, foreground, nonFocusedSelection))); allowedWidth -= RealLookupElementPresentation.getStringWidth(trimmed, fontMetrics); } }