From 59665345ab6abd0c12e9d96f4417469f36322cdb Mon Sep 17 00:00:00 2001 From: "alexey.afanasiev" Date: Tue, 21 Feb 2017 16:53:31 +0300 Subject: [PATCH] IDEA-124950 Good code is red: Reference to array class is not detected correctly --- .../expressions/path/GrIndexPropertyImpl.java | 26 ++----------------- .../groovy/lang/resolve/ResolveUtil.java | 2 +- .../lang/resolve/TypeInferenceTest.groovy | 7 +++++ 3 files changed, 10 insertions(+), 25 deletions(-) diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/path/GrIndexPropertyImpl.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/path/GrIndexPropertyImpl.java index 43a48de113fc..03603f3826df 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/path/GrIndexPropertyImpl.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/path/GrIndexPropertyImpl.java @@ -71,9 +71,9 @@ public class GrIndexPropertyImpl extends GrExpressionImpl implements GrIndexProp // return not null in case of String[], int[], double[][] @Nullable private PsiType inferArrayType() { - PsiType arrayTypeBase = getClassReferenceFromExpression(this.getInvokedExpression()); + PsiType arrayTypeBase = getClassReferenceFromExpression(this); if (arrayTypeBase == null) return null; - return TypesUtil.createJavaLangClassType(arrayTypeBase.createArrayType(), this.getProject(), this.getResolveScope()); + return TypesUtil.createJavaLangClassType(arrayTypeBase, this.getProject(), this.getResolveScope()); } private PsiType inferType(@Nullable Boolean isSetter) { @@ -97,28 +97,6 @@ public class GrIndexPropertyImpl extends GrExpressionImpl implements GrIndexProp final PsiManager manager = getManager(); final GlobalSearchScope resolveScope = getResolveScope(); - if (argTypes.length == 0) { - PsiType arrType = null; - if (selected instanceof GrBuiltinTypeClassExpression) { - arrType = ((GrBuiltinTypeClassExpression)selected).getPrimitiveType(); - } - - if (selected instanceof GrReferenceExpression) { - final PsiElement resolved = ((GrReferenceExpression)selected).resolve(); - if (resolved instanceof PsiClass) { - String qname = ((PsiClass)resolved).getQualifiedName(); - if (qname != null) { - arrType = TypesUtil.createTypeByFQClassName(qname, this); - } - } - } - - if (arrType != null) { - final PsiArrayType param = arrType.createArrayType(); - return TypesUtil.createJavaLangClassType(param, getProject(), resolveScope); - } - } - if (PsiImplUtil.isSimpleArrayAccess(thisType, argTypes, this, isSetter != null ? isSetter.booleanValue() : PsiUtil.isLValue(this))) { return TypesUtil.boxPrimitiveType(((PsiArrayType)thisType).getComponentType(), manager, resolveScope); } diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.java index 9520531bdeca..1a3ee1a27049 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/resolve/ResolveUtil.java @@ -1069,8 +1069,8 @@ public class ResolveUtil { } if (expression instanceof GrIndexProperty) { + if (((GrIndexProperty)expression).getExpressionArguments().length != 0) return null; PsiType arrayTypeBase = getClassReferenceFromExpression(((GrIndexProperty)expression).getInvokedExpression()); - return arrayTypeBase == null ? null : arrayTypeBase.createArrayType(); } return null; diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/TypeInferenceTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/TypeInferenceTest.groovy index 6648b5f477fb..870b99f5dc02 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/TypeInferenceTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/TypeInferenceTest.groovy @@ -713,6 +713,13 @@ def foo(List list) { doExprTest 'double[][][].class', 'java.lang.Class' } + void testClassExpressionsWithArguments() { + doExprTest 'String[1]', 'java.lang.Object' + doExprTest 'String[1][]', 'java.lang.Object' + doExprTest 'String[1][].class', 'java.lang.Class' + doExprTest 'int[][1].class', 'java.lang.Class' + } + void 'test list literal type'() { doExprTest '[]', 'java.util.List' doExprTest '[null]', 'java.util.List'