@Override
  @NotNull
  protected BaseInspectionVisitor buildVisitor() {
    return new BaseInspectionVisitor() {
      @Override
      public void visitReferenceExpression(@NotNull GrReferenceExpression refExpr) {
        super.visitReferenceExpression(refExpr);

        if (PsiUtil.isThisOrSuperRef(refExpr)) return;

        GroovyResolveResult resolveResult = refExpr.advancedResolve();

        PsiElement resolved = resolveResult.getElement();
        if (resolved != null) {
          if (GrHighlightUtil.isDeclarationAssignment(refExpr) || resolved instanceof PsiPackage) return;
        }
        else {
          GrExpression qualifier = refExpr.getQualifierExpression();
          if (qualifier == null && GrHighlightUtil.isDeclarationAssignment(refExpr)) return;
        }

        final PsiType refExprType = refExpr.getType();
        if (refExprType == null) {
          if (resolved != null) {
            registerError(refExpr);
          }
        }
        else if (refExprType instanceof PsiClassType && ((PsiClassType)refExprType).resolve() == null) {
          registerError(refExpr);
        }
      }
    };
  }
@Override
  @NotNull
  protected BaseInspectionVisitor buildVisitor()