mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
for expected class types insert the parentheses
This commit is contained in:
+9
-7
@@ -86,7 +86,7 @@ class JavaClassNameInsertHandler implements InsertHandler<JavaPsiClassReferenceE
|
||||
}
|
||||
}
|
||||
|
||||
if (completingRawConstructor(context, item) && !JavaCompletionUtil.hasAccessibleInnerClass(psiClass, file)) {
|
||||
if (shouldInsertParentheses(psiClass, position)) {
|
||||
if (ConstructorInsertHandler.insertParentheses(context, item, psiClass, false)) {
|
||||
AutoPopupController.getInstance(project).autoPopupParameterInfo(editor, null);
|
||||
}
|
||||
@@ -125,22 +125,24 @@ class JavaClassNameInsertHandler implements InsertHandler<JavaPsiClassReferenceE
|
||||
|
||||
}
|
||||
|
||||
private static boolean completingRawConstructor(InsertionContext context, JavaPsiClassReferenceElement item) {
|
||||
final PsiJavaCodeReferenceElement ref = PsiTreeUtil.findElementOfClassAtOffset(context.getFile(), context.getStartOffset(), PsiJavaCodeReferenceElement.class, false);
|
||||
private static boolean shouldInsertParentheses(PsiClass psiClass, PsiElement position) {
|
||||
final PsiJavaCodeReferenceElement ref = PsiTreeUtil.getParentOfType(position, PsiJavaCodeReferenceElement.class);
|
||||
final PsiElement prevElement = FilterPositionUtil.searchNonSpaceNonCommentBack(ref);
|
||||
if (prevElement != null && prevElement.getParent() instanceof PsiNewExpression) {
|
||||
PsiTypeParameter[] typeParameters = item.getObject().getTypeParameters();
|
||||
final PsiClassType classType = JavaPsiFacade.getElementFactory(position.getProject()).createType(psiClass);
|
||||
|
||||
for (ExpectedTypeInfo info : ExpectedTypesProvider.getExpectedTypes((PsiExpression)prevElement.getParent(), true)) {
|
||||
final PsiType type = info.getType();
|
||||
|
||||
if (info.isArrayTypeInfo()) {
|
||||
return false;
|
||||
}
|
||||
if (typeParameters.length > 0 && type instanceof PsiClassType && !((PsiClassType)type).isRaw()) {
|
||||
return false;
|
||||
|
||||
if (type instanceof PsiClassType && ((PsiClassType)type).rawType().isAssignableFrom(classType)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return !JavaCompletionUtil.hasAccessibleInnerClass(psiClass, position);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
class Foo {
|
||||
{
|
||||
Zzoo.Impl l = new Zz<caret>
|
||||
}
|
||||
}
|
||||
|
||||
interface Zzoo {
|
||||
void run();
|
||||
|
||||
class Impl implements Zzoo {}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
class Foo {
|
||||
{
|
||||
Zzoo.Impl l = new Zzoo<caret>
|
||||
}
|
||||
}
|
||||
|
||||
interface Zzoo {
|
||||
void run();
|
||||
|
||||
class Impl implements Zzoo {}
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
class Foo {
|
||||
{
|
||||
Zzoo l = new Zzoo<caret>
|
||||
Zzoo l = new Zzoo()<caret>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
class Foooo {
|
||||
interface Bar {}
|
||||
}
|
||||
|
||||
class Bar {
|
||||
{
|
||||
Foooo c = new Fooo<caret>
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
class Foooo {
|
||||
interface Bar {}
|
||||
}
|
||||
|
||||
class Bar {
|
||||
{
|
||||
Foooo c = new Foooo()<caret>
|
||||
}
|
||||
}
|
||||
+6
-15
@@ -663,6 +663,7 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase {
|
||||
}
|
||||
|
||||
public void testClassNameWithInner() throws Throwable { doTest() }
|
||||
public void testClassNameWithInner2() throws Throwable { doTest() }
|
||||
|
||||
public void testClassNameWithInstanceInner() throws Throwable { doTest('\n') }
|
||||
|
||||
@@ -805,23 +806,13 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase {
|
||||
|
||||
public void testPrimitiveMethodParameter() throws Throwable { doTest(); }
|
||||
|
||||
public void testQualifyInnerMembers() throws Throwable {
|
||||
configure()
|
||||
selectItem myItems[0]
|
||||
checkResult()
|
||||
}
|
||||
public void testNewExpectedClassParens() throws Throwable { doTest(); }
|
||||
|
||||
public void testSuggestExpectedTypeMembers() throws Throwable {
|
||||
configure()
|
||||
selectItem myItems[0]
|
||||
checkResult()
|
||||
}
|
||||
public void testQualifyInnerMembers() throws Throwable { doTest('\n') }
|
||||
|
||||
public void testSuggestExpectedTypeMembersInCall() throws Throwable {
|
||||
configure()
|
||||
selectItem myItems[0]
|
||||
checkResult();
|
||||
}
|
||||
public void testSuggestExpectedTypeMembers() throws Throwable { doTest('\n') }
|
||||
|
||||
public void testSuggestExpectedTypeMembersInCall() throws Throwable { doTest('\n') }
|
||||
|
||||
public void testClassNameWithInnersTab() throws Throwable { doTest('\t') }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user