mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
prefer new X() to new X[] when vararg is expected (groovy)
This commit is contained in:
+8
@@ -18,6 +18,7 @@ package org.jetbrains.plugins.groovy.lang.completion.weighers;
|
||||
import com.intellij.codeInsight.completion.CompletionLocation;
|
||||
import com.intellij.codeInsight.completion.CompletionWeigher;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.PsiTypeLookupItem;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.light.LightElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
@@ -77,6 +78,12 @@ public class GrKindWeigher extends CompletionWeigher {
|
||||
if (o instanceof PsiVariable && !(o instanceof PsiField)) {
|
||||
return NotQualifiedKind.local;
|
||||
}
|
||||
|
||||
PsiTypeLookupItem item = element.as(PsiTypeLookupItem.CLASS_CONDITION_KEY);
|
||||
if (item != null && item.getBracketsCount() > 0) {
|
||||
return NotQualifiedKind.arrayType;
|
||||
}
|
||||
|
||||
if (isPriorityKeyword(o)) return NotQualifiedKind.local;
|
||||
if (isLightElement(o)) return NotQualifiedKind.unknown;
|
||||
if (o instanceof PsiMember) {
|
||||
@@ -139,6 +146,7 @@ public class GrKindWeigher extends CompletionWeigher {
|
||||
}
|
||||
|
||||
private static enum NotQualifiedKind {
|
||||
arrayType,
|
||||
innerClass,
|
||||
unknown,
|
||||
accessor,
|
||||
|
||||
+4
@@ -28,6 +28,10 @@ abstract public class GroovyCompletionTestBase extends LightCodeInsightFixtureTe
|
||||
protected void doSmartTest() {
|
||||
myFixture.configureByFile(getTestName(false) + ".groovy");
|
||||
myFixture.complete(CompletionType.SMART);
|
||||
checkResult();
|
||||
}
|
||||
|
||||
protected void checkResult() {
|
||||
myFixture.checkResultByFile(getTestName(false) + "_after.groovy", true);
|
||||
}
|
||||
|
||||
|
||||
+6
@@ -90,6 +90,12 @@ public class GroovySmartCompletionTest extends GroovyCompletionTestBase {
|
||||
public void testEnumMembersInAssignment() {doSmartCompletion "IN_STOCK", "NOWHERE", "ORDERED" }
|
||||
public void testEnumMembersInAssignmentInsideEnum() {doSmartCompletion "IN_STOCK", "NOWHERE", "ORDERED", "next", "previous" }
|
||||
|
||||
public void testPreferVarargElement() {
|
||||
doSmartCompletion "Foo", "Foo"
|
||||
myFixture.type('\n')
|
||||
checkResult()
|
||||
}
|
||||
|
||||
void testNativeList() {doSmartCompletion('a1', 'a2')};
|
||||
|
||||
public void testMembersImportStatically() {
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
def foo(Foo... args) {}
|
||||
|
||||
class Foo {}
|
||||
|
||||
foo(new <caret>)
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
def foo(Foo... args) {}
|
||||
|
||||
class Foo {}
|
||||
|
||||
foo(new Foo()<caret>)
|
||||
Reference in New Issue
Block a user