public static void expand(@NotNull PsiJavaCodeReferenceElement ref, PsiImportStaticStatement staticImport) {
    PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(ref.getProject());
    PsiClass targetClass = staticImport.resolveTargetClass();
    assert targetClass != null;
    if (ref instanceof PsiReferenceExpression) {
      ((PsiReferenceExpression)ref).setQualifierExpression(elementFactory.createReferenceExpression(targetClass));
    }
    else if (ref instanceof PsiImportStaticReferenceElement) {
      ref.replace(
        Objects.requireNonNull(elementFactory.createImportStaticStatement(targetClass, ref.getText()).getImportReference()));
    }
    else {
      ref.replace(elementFactory.createReferenceFromText(targetClass.getQualifiedName() + "." + ref.getText(), ref));
    }
  }
public static void expand(@NotNull PsiJavaCodeReferenceElement ref, PsiImportStaticStatement staticImport)