public static @Nullable PsiType getClassReferenceFromExpression(@NotNull PsiElement expression) {

    if (expression instanceof GrReferenceExpression) {
      if (org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil.isThisReference(expression)) return null;

      PsiElement resolved = ((GrReferenceExpression)expression).resolve();
      if (resolved instanceof PsiClass) {
        return TypesUtil.createType((PsiClass)resolved);
      }
    }

    if (expression instanceof GrBuiltinTypeClassExpression) {
      return ((GrBuiltinTypeClassExpression)expression).getPrimitiveType();
    }

    if (expression instanceof GrIndexProperty) {
      if (((GrIndexProperty)expression).getArgumentList().getAllArguments().length != 0) return null;
      PsiType arrayTypeBase = getClassReferenceFromExpression(((GrIndexProperty)expression).getInvokedExpression());
      return arrayTypeBase == null ? null : arrayTypeBase.createArrayType();
    }
    return null;
  }
public static @Nullable PsiType getClassReferenceFromExpression(@NotNull PsiElement expression)