Language Injection refactoring tests

Hi all,

I am currently injecting a custom language into an XmlAttribute, and providing RefactoringSupport for introduce variable.
When introduce variable is triggered, I update the Dom within the same PsiFile to add a new property, and I also update the injected language to point to this new value.

My implementation is working great, however the LanguageInjection behaves oddly within my unit tests
For instance when I call invoke on my RefactoringActionHandler, psiFile.findElementAt does not return my language PsiElement - but instead an XmlAttribute.

This is somewhat confusing, as if I call InjectedLanguageUtil.findInjectedPsiNoCommit(myFixture.getFile(), editor.getSelectionModel().getSelectionStart()); - then this correctly shows my injected language file!
Unfortunately I can't make use of the findInjectedPsiNoCommit language file either, as I still need to perform the Dom manipulation

I would love to get some tests up and running for this, so any help is definitely much appreciated :)

Cheers
Alan

2 comments

As an update to this; I habve been looking around for plugins which implement similiar functionality, and i have found that the xpath/xslt plugin implements a similiar requirement.
However looking through the plugin, I can't see any tests for the introduce variable refactoring...

Perhaps this isn't possible to test within the current testing framework? I would love to hear your thoughts on this :)

-- Edit - The maven plugin offers similiar functionality but seems to have no tests for this either, how curious!

0

I have successfully been able to provide a JUnit test for this now. It was important to note the difference between the two possible PsiFiles and treat them appropiately.

Edit -- For anyone passing by; Both XmlUtil.getContainingFile(injectedPsiFIile) and InjectedLanguageUtil.getTopLevelEditor(injectedEditor) are useful for getting the topmost PsiFile from an injected PsiFile :)

0

Please sign in to leave a comment.