public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
    if (isReferenceTo(element)) return getElement();

    final String newName;
    if (element instanceof PsiClass) {
      PsiClass psiClass = (PsiClass) element;
      final boolean jvmFormat =
          Boolean.TRUE.equals(JavaClassReferenceProvider.JVM_FORMAT.getValue(getOptions()));
      newName = jvmFormat ? ClassUtil.getJVMClassName(psiClass) : psiClass.getQualifiedName();
    } else if (element instanceof PsiPackage) {
      PsiPackage psiPackage = (PsiPackage) element;
      newName = psiPackage.getQualifiedName();
    } else {
      throw new IncorrectOperationException("Cannot bind to " + element);
    }
    assert newName != null;

    TextRange range =
        new TextRange(
            myJavaClassReferenceSet.getReference(0).getRangeInElement().getStartOffset(),
            getRangeInElement().getEndOffset());
    final ElementManipulator<PsiElement> manipulator = getManipulator(getElement());
    if (manipulator != null) {
      final PsiElement finalElement = manipulator.handleContentChange(getElement(), range, newName);
      range = new TextRange(range.getStartOffset(), range.getStartOffset() + newName.length());
      myJavaClassReferenceSet.reparse(finalElement, range);
      return finalElement;
    }
    return element;
  }
 public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
   final ElementManipulator<PsiElement> manipulator = getManipulator(getElement());
   if (manipulator != null) {
     final PsiElement element =
         manipulator.handleContentChange(getElement(), getRangeInElement(), newElementName);
     myRange =
         new TextRange(
             getRangeInElement().getStartOffset(),
             getRangeInElement().getStartOffset() + newElementName.length());
     return element;
   }
   throw new IncorrectOperationException(
       "Manipulator for this element is not defined: " + getElement());
 }
 @Override
 public PsiElement bindToElement(@NotNull final PsiElement element)
     throws IncorrectOperationException {
   if (!(element instanceof PsiPackage)) {
     throw new IncorrectOperationException("Cannot bind to " + element);
   }
   final String newName = ((PsiPackage) element).getQualifiedName();
   final TextRange range =
       new TextRange(
           getReferenceSet().getReference(0).getRangeInElement().getStartOffset(),
           getRangeInElement().getEndOffset());
   final ElementManipulator<PsiElement> manipulator =
       ElementManipulators.getManipulator(getElement());
   return manipulator.handleContentChange(getElement(), range, newName);
 }