FinalListener changes text in document directly

com.intellij.refactoring.introduceVariable.FinalListener changes text in document directly.

In my plugin, PsiModifier - final without explicit modifier

And this code work incorrectly for my case.

final int idx = modifierList.getText().indexOf(modifier);    //TODO: idx = -1
document.deleteString(textOffset + idx, textOffset + idx + modifier.length() + 1);

Can you change psi-tree not document?

On some like this

final Runnable runnable = () -> {
if (variable.hasModifierProperty(modifier)) {
variable.getModifierList().setModifierProperty(modifier, generateFinal);
}
};

 

 

2 comments
Comment actions Permalink

Hi,

the document is changed in the final listener because the live template works with document and we try to avoid excessive psi-document synchronisations. As the text changes as soon as user select checkbox, I don't see a way how to avoid problems if the popup would be shown. (I suspect that in your case it should be hidden but there is no API for that)

To the suggestions:

IDEA has some corresponding to implicit modifiers API: com.intellij.psi.augment.PsiAugmentProvider#transformModifiers. Please check if it would help you as well, otherwise please explain your task in more details.

 

Thanks,

Anna

0
Comment actions Permalink

Hi, 

thanks for answer

"he document is changed in the final listener because the live template works with document and we try to avoid excessive psi-document synchronisations" -  is this optimization?

Can you add some check before remove piace of string from document?

Like this

else {
final int idx = modifierList.getText().indexOf(modifier);
if (idx != -1) document.deleteString(textOffset + idx, textOffset + idx + modifier.length() + 1);
}

Thanks, Alexandr

0

Please sign in to leave a comment.