What is PsiReference.bindToElement for?

I don't know if I understand what bindToElement is for. In theory it
sounds like it should change the text of the reference to point to the
new item. However, I feel that there must be more to it, because won't
the change to text cause a PSI tree change, which will cause the
references to be re-computed and reference providers re-queried? If so,
why is bindToElement necessary if the newly bound reference will be
overwritten immediately on reparse?

4 comments

As I understand it, it doesn't change the text of the reference but can bind an invalid reference to a newly created PsiElement, for example.
Perhaps you missed the javadoc?:

/**
Changes the reference so that it starts to point to the specified element. This is called, for example, by the "Create Class from New" quickfix, to bind the (invalid) reference on which the quickfix was called to the newly created class.

@param element the element which should become the target of the reference.
@return the new underlying element of the reference.
@throws IncorrectOperationException if the rebind cannot be handled for some reason.
*/
PsiElement bindToElement(PsiElement element) throws IncorrectOperationException;

Bas

0

I read the javadoc, and I thought I understood it, then I started trying to
implement the method, and I realized the semantics seem too vague for me to
implement it. I don't understand when it will be called for my custom language,
so I don't know what it should do.

Bas Leijdekkers wrote:

As I understand it, it doesn't change the text of the reference but can bind an invalid reference to a newly created PsiElement, for example.
Perhaps you missed the javadoc?:

/**
Changes the reference so that it starts to point to the specified element. This is called, for example, by the "Create Class from New" quickfix, to bind the (invalid) reference on which the quickfix was called to the newly created class.

@param element the element which should become the target of the reference.
@return the new underlying element of the reference.
@throws IncorrectOperationException if the rebind cannot be handled for some reason.
*/
PsiElement bindToElement(PsiElement element) throws IncorrectOperationException;

Bas

0

Keith, you got it incredibly right, the use case of this method to be called
is just move refactoring, but the problem you've mentioned is indeed making
the reference (possibly) invalid,
but no one cares as it (and others queried from the same psi element) are by
happy coincidence not used later in the refactoring.

Eugene.

"Keith Lea" <keith@cs.oswego.edu> wrote in message
news:djj7dq$nmf$1@is.intellij.net...
>I don't know if I understand what bindToElement is for. In theory it sounds
>like it should change the text of the reference to point to the new item.
>However, I feel that there must be more to it, because won't the change to
>text cause a PSI tree change, which will cause the references to be
>re-computed and reference providers re-queried? If so, why is bindToElement
>necessary if the newly bound reference will be overwritten immediately on
>reparse?


0

Okay cool, thanks, it makes more sense now. I wonder if you could write
something like this in the javadoc.

Eugene Vigdorchik (JetBrains) wrote:

Keith, you got it incredibly right, the use case of this method to be called
is just move refactoring, but the problem you've mentioned is indeed making
the reference (possibly) invalid,
but no one cares as it (and others queried from the same psi element) are by
happy coincidence not used later in the refactoring.

Eugene.

"Keith Lea" <keith@cs.oswego.edu> wrote in message
news:djj7dq$nmf$1@is.intellij.net...

>>I don't know if I understand what bindToElement is for. In theory it sounds
>>like it should change the text of the reference to point to the new item.
>>However, I feel that there must be more to it, because won't the change to
>>text cause a PSI tree change, which will cause the references to be
>>re-computed and reference providers re-queried? If so, why is bindToElement
>>necessary if the newly bound reference will be overwritten immediately on
>>reparse?


0

Please sign in to leave a comment.