mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
highlight and prefer members declared in the qualifier type in groovy as well
This commit is contained in:
@@ -595,7 +595,7 @@ public class JavaCompletionUtil {
|
||||
if (o instanceof PsiMember) {
|
||||
mentioned.add((PsiMember)o);
|
||||
}
|
||||
set.add(mayHighlight ? highlightIfNeeded(qualifierType, item) : item);
|
||||
set.add(mayHighlight ? highlightIfNeeded(qualifierType, item, o) : item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -658,7 +658,8 @@ public class JavaCompletionUtil {
|
||||
for (CompletionElement completionElement : processor.getResults()) {
|
||||
final LookupElement item = createLookupElement(completionElement, castTo);
|
||||
if (item != null) {
|
||||
set.add(highlightIfNeeded(castTo, castQualifier(project, item, castItem)));
|
||||
LookupElement item1 = castQualifier(project, item, castItem);
|
||||
set.add(highlightIfNeeded(castTo, item1, item1.getObject()));
|
||||
}
|
||||
}
|
||||
return castTo;
|
||||
@@ -696,11 +697,10 @@ public class JavaCompletionUtil {
|
||||
});
|
||||
}
|
||||
|
||||
private static LookupElement highlightIfNeeded(@NotNull PsiType qualifierType, @NotNull LookupElement item) {
|
||||
Object o = item.getObject();
|
||||
public static LookupElement highlightIfNeeded(PsiType qualifierType, LookupElement item, Object object) {
|
||||
if (qualifierType instanceof PsiArrayType) {
|
||||
if (o instanceof PsiField || o instanceof PsiMethod) { //length and clone()
|
||||
PsiElement parent = ((PsiElement)o).getParent();
|
||||
if (object instanceof PsiField || object instanceof PsiMethod) { //length and clone()
|
||||
PsiElement parent = ((PsiElement)object).getParent();
|
||||
if (parent instanceof PsiClass && parent.getContainingFile().getVirtualFile() == null) { //yes, they're a bit dummy
|
||||
return highlight(item);
|
||||
}
|
||||
@@ -708,8 +708,8 @@ public class JavaCompletionUtil {
|
||||
}
|
||||
else if (qualifierType instanceof PsiClassType) {
|
||||
PsiClass qualifierClass = ((PsiClassType)qualifierType).resolve();
|
||||
if (o instanceof PsiField || o instanceof PsiMethod || o instanceof PsiClass) {
|
||||
PsiElement parent = ((PsiElement)o).getParent();
|
||||
if (object instanceof PsiField || object instanceof PsiMethod || object instanceof PsiClass) {
|
||||
PsiClass parent = ((PsiMember)object).getContainingClass();
|
||||
if (parent != null && parent.equals(qualifierClass)) {
|
||||
return highlight(item);
|
||||
}
|
||||
|
||||
+2
-8
@@ -368,13 +368,7 @@ public class GroovyCompletionContributor extends CompletionContributor {
|
||||
result.restartCompletionOnPrefixChange(IS_PREFIX);
|
||||
final Map<PsiModifierListOwner, LookupElement> staticMembers = hashMap();
|
||||
final PsiElement qualifier = reference.getQualifier();
|
||||
final PsiType qualifierType;
|
||||
if (qualifier instanceof GrExpression) {
|
||||
qualifierType = ((GrExpression)qualifier).getType();
|
||||
}
|
||||
else {
|
||||
qualifierType = null;
|
||||
}
|
||||
final PsiType qualifierType = qualifier instanceof GrExpression ? ((GrExpression)qualifier).getType() : null;
|
||||
|
||||
final ElementFilter classFilter = getClassFilter(position);
|
||||
|
||||
@@ -448,7 +442,7 @@ public class GroovyCompletionContributor extends CompletionContributor {
|
||||
if (object instanceof PsiClass && !classFilter.isAcceptable(object, position)) {
|
||||
return;
|
||||
}
|
||||
result.addElement(lookupElement);
|
||||
result.addElement(JavaCompletionUtil.highlightIfNeeded(qualifierType, lookupElement, object));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
+53
@@ -110,4 +110,57 @@ for (def ch: "abc".toCharArray()) {
|
||||
print ch.toUpperCase()
|
||||
}"""
|
||||
}
|
||||
|
||||
public void testDeclaredMembersGoFirst() {
|
||||
myFixture.configureByText "a.groovy", """
|
||||
class Foo {
|
||||
def superProp
|
||||
void fromSuper() {}
|
||||
void fromSuper2() {}
|
||||
void overridden() {}
|
||||
}
|
||||
|
||||
class FooImpl extends Foo {
|
||||
def thisProp
|
||||
void overridden() {}
|
||||
void fromThis() {}
|
||||
void fromThis2() {}
|
||||
void fromThis3() {}
|
||||
void fromThis4() {}
|
||||
void fromThis5() {}
|
||||
}
|
||||
|
||||
new FooImpl().<caret>
|
||||
"""
|
||||
myFixture.completeBasic()
|
||||
assertOrderedEquals myFixture.lookupElementStrings,"""\
|
||||
fromThis
|
||||
fromThis2
|
||||
fromThis3
|
||||
fromThis4
|
||||
fromThis5
|
||||
overridden
|
||||
thisProp
|
||||
class
|
||||
equals
|
||||
fromSuper
|
||||
fromSuper2
|
||||
getProperty
|
||||
hashCode
|
||||
invokeMethod
|
||||
metaClass
|
||||
metaPropertyValues
|
||||
notify
|
||||
notifyAll
|
||||
properties
|
||||
setProperty
|
||||
superProp
|
||||
toString
|
||||
wait
|
||||
wait
|
||||
wait
|
||||
with\
|
||||
""".split('\n')
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user