Prevent rename refactoring

I'm defining references and usages for my custom language plugin. Since I cannot rename those consistently I would like to disable the "rename refactoring" operation for these elements.

My initial approach was to have


return false, but this only prevents inline editing, not renaming in general. I still get a popup and default renaming.

My second guess was to implement a specific


but there seems to be no method that decides on renaming or not.

What's the proposed way of disabling rename refactoring? (Merely ignoring the rename operation in <element>.setName() seems broken.)


Comment actions Permalink

The easiest solution is to use the <vetoRenameCondition> extension point. Extensions for this EP are implementations of Condition<PsiElement> that return true if renaming the element should be forbidden.

Comment actions Permalink

Hello Lars,

multiple RenameHandler's can be defined. Custom handlers are iterated until in one of them

public final boolean isAvailableOnDataContext(final DataContext dataContext) 

returns true. If none of the custom handlers return true, then default handler is checked & invoked.

So to disable rename you could add a RenameHandler,
make its isAvailableOnDataContext return true,
and override its

public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file, final DataContext dataContext)


public void invoke(@NotNull final Project project, @NotNull final PsiElement[] elements, final DataContext dataContext)

to empty body { }

This might work.

Comment actions Permalink

Thanks, very simple and works beautifully.

For the benefit of others, here's some example code: link
And here's the list of extension points, seems there's an extension for everything: link (scroll down to "How to Get the Extension Points List?")


Comment actions Permalink

Thanks for your suggestion ... but the veto extension point works and is really simple to set up.

Comment actions Permalink

you are welcome.

I had written that reply before I saw Dmitry's message.

ah well, 2 answers are better than no answer ;)

Someone else might need to tweak rename. That reply could give them some ideas.


Please sign in to leave a comment.