private static boolean isQualifiedStaticMethodWithUnnecessaryQualifier(
      GrReferenceExpression ref) {
    if (ref.getQualifier() == null) return false;

    final PsiElement resolved = ref.resolve();
    if (!(resolved instanceof PsiMember)) return false;
    if (!((PsiMember) resolved).hasModifierProperty(PsiModifier.STATIC)) return false;

    PsiElement copyResolved;
    final PsiElement parent = ref.getParent();
    if (parent instanceof GrMethodCall) {
      final GrMethodCall copy = (GrMethodCall) parent.copy();
      GrReferenceExpression invoked = (GrReferenceExpression) copy.getInvokedExpression();
      assert invoked != null;

      invoked.setQualifier(null);

      copyResolved = ((GrReferenceExpression) copy.getInvokedExpression()).resolve();
    } else {
      final GrReferenceExpression copy = (GrReferenceExpression) ref.copy();
      copy.setQualifier(null);
      copyResolved = copy.resolve();
    }
    return ref.getManager().areElementsEquivalent(copyResolved, resolved);
  }
  private static boolean canBeSimplified(PsiElement element) {
    if (PsiTreeUtil.getParentOfType(element, PsiComment.class) != null) return false;

    if (element instanceof GrCodeReferenceElement) {
      if (PsiTreeUtil.getParentOfType(element, GrImportStatement.class, GrPackageDefinition.class)
          != null) return false;
    } else if (element instanceof GrReferenceExpression) {
      if (!PsiImplUtil.seemsToBeQualifiedClassName((GrReferenceExpression) element)) return false;
    } else {
      return false;
    }

    final GrReferenceElement ref = (GrReferenceElement) element;
    if (ref.getQualifier() == null) return false;
    if (!(ref.getContainingFile() instanceof GroovyFileBase)) return false;

    final PsiElement resolved = ref.resolve();
    if (!(resolved instanceof PsiClass)) return false;

    final String name = ((PsiClass) resolved).getName();
    if (name == null) return false;

    final GroovyPsiElementFactory factory =
        GroovyPsiElementFactory.getInstance(element.getProject());
    final GrReferenceExpression shortedRef =
        factory.createReferenceExpressionFromText(name, element);
    final GroovyResolveResult resolveResult = shortedRef.advancedResolve();

    if (element.getManager().areElementsEquivalent(resolved, resolveResult.getElement())) {
      return true;
    }

    final PsiClass containingClass = ((PsiClass) resolved).getContainingClass();
    if (containingClass != null
        && !GroovyCodeStyleSettingsFacade.getInstance(containingClass.getProject())
            .insertInnerClassImports()) {
      return false;
    }

    return resolveResult.getElement() == null
        || !resolveResult.isAccessible()
        || !resolveResult.isStaticsOK();
  }