PsiType (@NotNull GrReferenceExpression ref) { final GrExpression rtQualifier = ref.getQualifierExpression(); if (rtQualifier != null) { return rtQualifier.getType(); } PsiClass containingClass = null; final GrMember member = PsiTreeUtil.getParentOfType(ref, GrMember.class); if (member == null) { final PsiFile file = ref.getContainingFile(); if (file instanceof GroovyFileBase && ((GroovyFileBase)file).isScript()) { containingClass = ((GroovyFileBase)file).getScriptClass(); } else { return null; } } else if (member instanceof GrMethod) { if (!member.hasModifierProperty(PsiModifier.STATIC)) { containingClass = member.getContainingClass(); } } if (containingClass != null) { final PsiClassType categoryType = GdkMethodUtil.getCategoryType(containingClass); if (categoryType != null) { return categoryType; } return JavaPsiFacade.getElementFactory(ref.getProject()).createType(containingClass); } return null; }