java completion: show initializers for non-imported fields (IDEA-226639)

GitOrigin-RevId: c1aff6352023ed3a953ab8e32e1d1a34d8fcd8ae
This commit is contained in:
Peter Gromov
2020-01-08 18:34:42 +00:00
committed by intellij-monorepo-bot
parent ee0505a5dc
commit 680f4703db
4 changed files with 45 additions and 14 deletions
@@ -85,7 +85,7 @@ public class MemberLookupHelper {
: myMember instanceof PsiMethod
? getMethodParameterString((PsiMethod)myMember, substitutor)
: "";
presentation.clearTail();
presentation.appendTailText(params, false);
if (myShouldImport && StringUtil.isNotEmpty(className)) {
presentation.appendTailText(" in " + className + location, true);
@@ -1,7 +1,8 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInsight.lookup;
import com.intellij.codeInsight.*;
import com.intellij.codeInsight.AutoPopupController;
import com.intellij.codeInsight.TailType;
import com.intellij.codeInsight.completion.*;
import com.intellij.codeInsight.daemon.impl.JavaColorProvider;
import com.intellij.codeInsight.daemon.impl.analysis.HighlightControlFlowUtil;
@@ -135,6 +136,13 @@ public class VariableLookupItem extends LookupItem<PsiVariable> implements Typed
presentation.setIcon(DefaultLookupItemRenderer.getRawIcon(this, presentation.isReal()));
presentation.setStrikeout(JavaElementLookupRenderer.isToStrikeout(this));
if (myTailText != null) {
if (myTailText.startsWith(EQ)) {
presentation.appendTailTextItalic(" (" + myTailText + ")", true);
} else {
presentation.setTailText(myTailText, true);
}
}
if (myHelper != null) {
myHelper.renderElement(presentation, qualify, true, getSubstitutor());
}
@@ -143,13 +151,6 @@ public class VariableLookupItem extends LookupItem<PsiVariable> implements Typed
} else {
presentation.setTypeText(getType().getPresentableText());
}
if (myTailText != null && StringUtil.isEmpty(presentation.getTailText())) {
if (myTailText.startsWith(EQ)) {
presentation.appendTailTextItalic(" (" + myTailText + ")", true);
} else {
presentation.setTailText(myTailText, true);
}
}
}
@Override
@@ -0,0 +1,22 @@
import static E.FIELD3;
class X {
{
FIELD<caret>
}
}
enum E {
FIELD1( "x"),
FIELD2("y") {
public String toString() {
return super.toString();
}
},
FIELD3 {};
E(String s) {
}
public static final int FIELD4 = 42;
}
@@ -1706,11 +1706,19 @@ class Bar {
void testShowVarInitializers() {
configure()
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]).tailFragments[0].italic
myFixture.assertPreferredCompletionItems 0, 'FIELD1', 'FIELD2', 'FIELD3', 'FIELD4'
def items = myFixture.lookup.items
assert items.collect { LookupElementPresentation.renderElement(it).tailText } == ['( "x")', '("y") {...}', null, ' ( = 42)']
assert LookupElementPresentation.renderElement(items[3]).tailFragments[0].italic
}
void testShowNonImportedVarInitializers() {
configure()
myFixture.assertPreferredCompletionItems 1, 'Field', 'FIELD1', 'FIELD2', 'FIELD3', 'FIELD4'
def fieldItems = myFixture.lookup.items[1..4]
assert fieldItems.collect { LookupElementPresentation.renderElement(it).tailText } == ['( "x") in E', '("y") {...} in E', null, ' ( = 42) in E']
assert LookupElementPresentation.renderElement(fieldItems[3]).tailFragments[0].italic
assert !LookupElementPresentation.renderElement(fieldItems[3]).tailFragments[1].italic
}
void testSuggestInterfaceArrayWhenObjectIsExpected() {