private static boolean isSafeToShortenReference(final String referenceText, final PsiElement psiReference, final PsiClass refClass) {
    final PsiManager manager = refClass.getManager();
    final JavaPsiFacade facade = JavaPsiFacade.getInstance(manager.getProject());
    final PsiResolveHelper helper = facade.getResolveHelper();
    if (manager.areElementsEquivalent(refClass, helper.resolveReferencedClass(referenceText, psiReference))) {
      if (psiReference instanceof PsiJavaCodeReferenceElement) {
        PsiElement parent = psiReference.getParent();
        if (parent instanceof PsiNewExpression || parent.getParent() instanceof PsiNewExpression) return true;

        if (parent instanceof PsiTypeElement) {
          final PsiClass containingClass = refClass.getContainingClass();
          if (containingClass != null && containingClass.hasTypeParameters()) {
            if (parent.getParent() instanceof PsiInstanceOfExpression || parent.getParent() instanceof PsiPatternVariable) {
              return false;
            }
            if (!refClass.hasModifierProperty(PsiModifier.STATIC)) {
              PsiElement enclosingStaticElement = PsiUtil.getEnclosingStaticElement(psiReference, null);
              if (enclosingStaticElement != null && !PsiTreeUtil.isAncestor(enclosingStaticElement, refClass, false)) {
                return false;
              }
            }
          }
        }

        PsiElement qualifier = ((PsiJavaCodeReferenceElement)psiReference).getQualifier();
        if (qualifier instanceof PsiJavaCodeReferenceElement) {
          PsiReferenceParameterList parameterList = ((PsiJavaCodeReferenceElement)qualifier).getParameterList();
          if (parameterList != null) {
            PsiType[] typeArguments = parameterList.getTypeArguments();
            if (typeArguments.length > 0) {
              final PsiClass containingClass = refClass.getContainingClass();
              if (containingClass != null) {
                PsiTypeParameter[] classTypeParameters = containingClass.getTypeParameters();
                if (typeArguments.length != classTypeParameters.length) {
                  return false;
                }
                if (StreamEx.zip(typeArguments, classTypeParameters, 
                                 (type, typeParam) -> manager.areElementsEquivalent(typeParam, PsiUtil.resolveClassInClassTypeOnly(type)))
                  .has(false)) {
                  return false;
                }
              }
            }
          }
        }
      }
      return helper.resolveReferencedVariable(referenceText, psiReference) == null;
    }
    return false;
  }
private static boolean isSafeToShortenReference(final String referenceText, final PsiElement psiReference, final PsiClass refClass)