Adjusting AttributeValue content of an Reference in XML


I'm trying to implement XML DOM converter, however it is not clear to me how I can modify the String value of an attribute value before and after the resolution happens.


I have an XML file called MyItem.xml that contains a reference to the file itself via the name AttributeValue. However the name should be without the xml extension.

<item name="MyItem"/>


I've created DOM model

@Convert(value = MyFileReferenceConverter.class)
GenericAttributeValue<XmlFile> getName();

and a custom converter that adds the necessary extension.

public class MyFileReferenceConverter extends PathReferenceConverter {

public PsiReference[] createReferences(final GenericDomValue genericDomValue, final PsiElement element, final ConvertContext context) {
String text = ((XmlAttributeValue) element).getValue() + ".xml";
FileReferenceSet referenceSet = new FileReferenceSet(text, element, 1, null, true);
return new PsiReference[]{referenceSet.getLastReference()};



This seems to work nicely, however when I rename the file to e.g. OtherItem.xml, the contents becomes

<item name="OtherItem.xml"/>

Is there a way to remove the suffix when the file is renamed?


I was also confused by the fact that the fromString/toString methods in PathReferenceConverter were never called by anyone, but maybe that's only when used directly from my own plugin?

1 comment
Comment actions Permalink

Create plain com.intellij.util.xml.CustomReferenceConverter returning above FileReferenceSet but with custom FileReference created via com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet#createFileReference overriding FileReference#handleElementRename to strip extension


Please sign in to leave a comment.