boolean (PsiElement position) { //Closure cl={String x, <caret>... if (position == null) return false; if (position instanceof PsiWhiteSpace || position.getNode().getElementType() == GroovyTokenTypes.mNLS) { position = FilterPositionUtil.searchNonSpaceNonCommentBack(position); } boolean hasCommas = false; while (position != null) { PsiElement parent = position.getParent(); if (parent instanceof GrVariable) { PsiElement prev = FilterPositionUtil.searchNonSpaceNonCommentBack(parent); hasCommas = prev != null && prev.getNode().getElementType() == GroovyTokenTypes.mCOMMA; } if (parent instanceof GrClosableBlock) { PsiElement sibling = position.getPrevSibling(); while (sibling != null) { if (sibling instanceof GrParameterList) { return hasCommas; } boolean isComma = sibling instanceof LeafPsiElement && GroovyTokenTypes.mCOMMA == ((LeafPsiElement)sibling).getElementType(); hasCommas |= isComma; if (isComma || sibling instanceof PsiWhiteSpace || sibling instanceof PsiErrorElement || sibling instanceof GrVariableDeclaration || sibling instanceof GrReferenceExpression && !((GrReferenceExpression)sibling).isQualified() ) { sibling = sibling.getPrevSibling(); } else { return false; } } return false; } position = parent; } return false; } @Nullable public static PsiType getQualifierType(@Nullable PsiElement qualifier) { PsiType qualifierType = qualifier instanceof GrExpression ? ((GrExpression)qualifier).getType() : null; if (ResolveUtil.resolvesToClass(qualifier)) { PsiType type = ResolveUtil.unwrapClassType(qualifierType); if (type != null) { qualifierType = type; } } return qualifierType; } static boolean canResolveToPackage(@NotNull PsiElement qualifier) { return qualifier instanceof GrReferenceExpression && resolvePackageFqn((GrReferenceElement<?>)qualifier) != null; } }