How to enable refactoring of definitions in custom XML language (like Ant target/property)

Ant build editor allows renaming targets and properties. As far as I know the
only way to allow rename is for an element to implement PsiNamedElement. As I'm
annotating custom XML format, I don't have direct access to what the XmlTag
implements.

(It sounds like maybe this is what ElementManipulator is for, but when I
register an ElementManipulator, its method is never called.)

How can I create renamable elements in an XML file?

Thanks,
-Keith

13 comments
Comment actions Permalink

Your references should resolve to implementation of PsiNamedElement

Keith Lea wrote:

Ant build editor allows renaming targets and properties. As far as I
know the only way to allow rename is for an element to implement
PsiNamedElement. As I'm annotating custom XML format, I don't have
direct access to what the XmlTag implements.

(It sounds like maybe this is what ElementManipulator is for, but when I
register an ElementManipulator, its method is never called.)

How can I create renamable elements in an XML file?

Thanks,
-Keith



--
Best regards,
Maxim Mossienko
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0
Comment actions Permalink

Maxim, the definitions are simply XML tags, and their names are not what
XmlTag.getName() returns (as with ant properties), so this won't work, right?

Maxim Mossienko wrote:

Your references should resolve to implementation of PsiNamedElement

Keith Lea wrote:

>> Ant build editor allows renaming targets and properties. As far as I
>> know the only way to allow rename is for an element to implement
>> PsiNamedElement. As I'm annotating custom XML format, I don't have
>> direct access to what the XmlTag implements.
>>
>> (It sounds like maybe this is what ElementManipulator is for, but when
>> I register an ElementManipulator, its method is never called.)
>>
>> How can I create renamable elements in an XML file?
>>
>> Thanks,
>> -Keith


0
Comment actions Permalink

I'm probably unclear. For example:

I want $[someName] to resolve to the , and I want to be able to click on either "someName" and Refactor->]]>Rename.

Keith Lea wrote:

Maxim, the definitions are simply XML tags, and their names are not what
XmlTag.getName() returns (as with ant properties), so this won't work,
right?

Maxim Mossienko wrote:

>> Your references should resolve to implementation of PsiNamedElement
>>
>> Keith Lea wrote:
>>
>>> Ant build editor allows renaming targets and properties. As far as I
>>> know the only way to allow rename is for an element to implement
>>> PsiNamedElement. As I'm annotating custom XML format, I don't have
>>> direct access to what the XmlTag implements.
>>>
>>> (It sounds like maybe this is what ElementManipulator is for, but
>>> when I register an ElementManipulator, its method is never called.)
>>>
>>> How can I create renamable elements in an XML file?
>>>
>>> Thanks,
>>> -Keith
>>
>>
>>
>>

0
Comment actions Permalink

Your references could resolve to XmlAttributeValue ("someName")

Keith Lea wrote:

I'm probably unclear. For example:

<document>
<definition name="someName" />
<use ref="$[someName]" />
</document>

I want $[someName] to resolve to the <definition>, and I want to be able
to click on either "someName" and Refactor->Rename.

Keith Lea wrote:

>> Maxim, the definitions are simply XML tags, and their names are not
>> what XmlTag.getName() returns (as with ant properties), so this won't
>> work, right?
>>
>> Maxim Mossienko wrote:
>>
>>> Your references should resolve to implementation of PsiNamedElement
>>>
>>> Keith Lea wrote:
>>>
>>>> Ant build editor allows renaming targets and properties. As far as I
>>>> know the only way to allow rename is for an element to implement
>>>> PsiNamedElement. As I'm annotating custom XML format, I don't have
>>>> direct access to what the XmlTag implements.
>>>>
>>>> (It sounds like maybe this is what ElementManipulator is for, but
>>>> when I register an ElementManipulator, its method is never called.)
>>>>
>>>> How can I create renamable elements in an XML file?
>>>>
>>>> Thanks,
>>>> -Keith
>>>
>>>
>>>
>>>
>>>


--
Best regards,
Maxim Mossienko
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0
Comment actions Permalink

I do this now, but there are two issues:
1. When I return XmlAttributeValues in getVariants(), the completion list shows
up as empty
2. Highlight Usages in File works, but Find Usages doesn't ("cannot find
usages"), and Refactor->Rename does nothing (it's enabled in the menu, but
clicking does nothing)

What do you think I'm doing wrong?

Maxim Mossienko wrote:

Your references could resolve to XmlAttributeValue ("someName")

Keith Lea wrote:

>> I'm probably unclear. For example:
>>
>> >> >> >> >> >> I want $[someName] to resolve to the , and I want to be >> able to click on either "someName" and Refactor->Rename. >> >> Keith Lea wrote: >> >>> Maxim, the definitions are simply XML tags, and their names are not >>> what XmlTag.getName() returns (as with ant properties), so this won't >>> work, right? >>> >>> Maxim Mossienko wrote: >>> >>>> Your references should resolve to implementation of PsiNamedElement >>>> >>>> Keith Lea wrote: >>>> >>>>> Ant build editor allows renaming targets and properties. As far as >>>>> I know the only way to allow rename is for an element to implement >>>>> PsiNamedElement. As I'm annotating custom XML format, I don't have >>>>> direct access to what the XmlTag implements. >>>>> >>>>> (It sounds like maybe this is what ElementManipulator is for, but >>>>> when I register an ElementManipulator, its method is never called.) >>>>> >>>>> How can I create renamable elements in an XML file? >>>>> >>>>> Thanks, >>>>> -Keith >>>> >>>> >>>> >>>> >>>> >>>>]]>


0
Comment actions Permalink

Keith Lea wrote:

I'm probably unclear. For example:

<document>
<definition name="someName" />
<use ref="$[someName]" />
</document>

I want $[someName] to resolve to the <definition>, and I want to be able
to click on either "someName" and Refactor->Rename.


Keith, you can take a look at the XSLT part of my XPathView plugin. Simply create a
mock-PsiNamedElement implementation using PsiLightElement to resolve the reference to. To
be able to rename the definition, just create a PsiReference that points to the definition
itself.

Sascha

0
Comment actions Permalink

I guess this is the way to go in 5.0; the next release is going to provide a
more straight way of embedding custom languages in XML.

Eugene.

"Sascha Weinreuter" <sascha.weinreuter@NOSPAM-cit.de> wrote in message
news:de2ks3$nf0$1@is.intellij.net...

Keith Lea wrote:

I'm probably unclear. For example:

>

<document>
<definition name="someName" />
<use ref="$[someName]" />
</document>

>

I want $[someName] to resolve to the <definition>, and I want to be able
to click on either "someName" and Refactor->Rename.

>

Keith, you can take a look at the XSLT part of my XPathView plugin. Simply

create a

mock-PsiNamedElement implementation using PsiLightElement to resolve the

reference to. To

be able to rename the definition, just create a PsiReference that points

to the definition

itself.

>

Sascha



0
Comment actions Permalink

By next release, do you mean 5.5/6.0, or 5.0.1? :) How long do you estimate it
will be until these features start making way into the EAP? My team badly wants
a plugin for our custom XML web template language, and right now the API is so
close that it only needs some tweaks, to be much more useful than it is now.
(You can see my posts from earlier this week about what would help, in terms of
features or documentation.)

I don't know if you plan to redesign the API around XML, or if you plan to
design new XML language API. I don't want you to implement something in an ugly
way just for my team's unfortunately designed XML language. I think if you plan
to wait months or a year for 5.5 or 6.0 to include such features, when they
could be hacked together through slight modifications of existing API for a
5.0.x release, many people will be missing out on a lot of features (and the
competition will continue to provide better XML experience for popular
components ssuch as Hibernate and WebWork)

Maybe in the mean time you can help me with an exception. When I try making
definition a reference to LightPsiElement of itself, I get this exception, and I
don't know what I do wrong:
java.lang.NullPointerException
at com.intellij.psi.impl.source.xml.XmlTagImpl.getReferences(XmlTagImpl.java:115)
at
com.intellij.codeInsight.daemon.impl.analysis.XmlHighlightVisitor.a(XmlHighlightVisitor.java:316)
at
com.intellij.codeInsight.daemon.impl.analysis.XmlHighlightVisitor.a(XmlHighlightVisitor.java:78)
at
com.intellij.codeInsight.daemon.impl.analysis.XmlHighlightVisitor.visitXmlToken(XmlHighlightVisitor.java:207)
at com.intellij.psi.impl.source.xml.XmlTokenImpl.accept(XmlTokenImpl.java:5)
at
com.intellij.codeInsight.daemon.impl.analysis.HighlightVisitorImpl.visitXmlElement(HighlightVisitorImpl.java:181)
at com.intellij.psi.XmlElementVisitor.visitXmlToken(XmlElementVisitor.java:58)
at com.intellij.psi.impl.source.xml.XmlTokenImpl.accept(XmlTokenImpl.java:5)
at
com.intellij.codeInsight.daemon.impl.analysis.HighlightVisitorImpl.visit(HighlightVisitorImpl.java:154)
at
com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass$1.run(GeneralHighlightingPass.java:18)
at
com.intellij.psi.impl.PsiManagerImpl.performActionWithFormatterDisabled(PsiManagerImpl.java:473)
at
com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.a(GeneralHighlightingPass.java:57)
at
com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.doCollectInformation(GeneralHighlightingPass.java:78)
at
com.intellij.codeInsight.daemon.impl.TextEditorHighlightingPass.collectInformation(TextEditorHighlightingPass.java:8)
at com.intellij.codeInsight.daemon.impl.UpdateThread$2.run(UpdateThread.java:9)
at
com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:284)
at com.intellij.codeInsight.daemon.impl.UpdateThread.a(UpdateThread.java:14)
at
com.intellij.codeInsight.daemon.impl.UpdateThread.access$100(UpdateThread.java:35)
at com.intellij.codeInsight.daemon.impl.UpdateThread$1.run(UpdateThread.java:2)
at
com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressManagerImpl.java:41)
at com.intellij.codeInsight.daemon.impl.UpdateThread.run(UpdateThread.java:45)


Eugene Vigdorchik (JetBrains) wrote:

I guess this is the way to go in 5.0; the next release is going to provide a
more straight way of embedding custom languages in XML.

Eugene.

"Sascha Weinreuter" <sascha.weinreuter@NOSPAM-cit.de> wrote in message
news:de2ks3$nf0$1@is.intellij.net...

>>Keith Lea wrote:
>>
>>>I'm probably unclear. For example:
>>>
>>> >>> >>> >>> >>> >>>I want $[someName] to resolve to the , and I want to be able >>>to click on either "someName" and Refactor->Rename. >> >>]]>Keith, you can take a look at the XSLT part of my XPathView plugin. Simply


create a

>>mock-PsiNamedElement implementation using PsiLightElement to resolve the


reference to. To

>>be able to rename the definition, just create a PsiReference that points


to the definition

>>itself.
>>
>>Sascha


0
Comment actions Permalink

Well, I'm not sure about the timeframe, still it seems to me now, that the
changes needed for
this to work are not so dramatically huge, we are almost there:
the limitation now is indeed find usages/rename working with PsiNamedElement
only which is not the case
for embedded language. To overcome this it would be sufficient (at least it
seems now, when it is over midnight in Spb:)
to let FindUsagesHelper.canFindUsages() return true for non PsiNamedElement,
but introduce additional method to get the word
to search (this should be indeed compatible with WordScanner). Moreover this
method could have a default implementation working with
PsiNamedElement only, so introducing this won't break existing plugins.
Still it is a change in openapi, and I don't know if it is ok in 5.0.2

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

By next release, do you mean 5.5/6.0, or 5.0.1? :) How long do you

estimate it

will be until these features start making way into the EAP? My team badly

wants

a plugin for our custom XML web template language, and right now the API

is so

close that it only needs some tweaks, to be much more useful than it is

now.

(You can see my posts from earlier this week about what would help, in

terms of

features or documentation.)

>

I don't know if you plan to redesign the API around XML, or if you plan to
design new XML language API. I don't want you to implement something in an

ugly

way just for my team's unfortunately designed XML language. I think if you

plan

to wait months or a year for 5.5 or 6.0 to include such features, when

they

could be hacked together through slight modifications of existing API for

a

5.0.x release, many people will be missing out on a lot of features (and

the

competition will continue to provide better XML experience for popular
components ssuch as Hibernate and WebWork)

>

Maybe in the mean time you can help me with an exception. When I try

making

definition a reference to LightPsiElement of itself, I get this exception,

and I

don't know what I do wrong:
java.lang.NullPointerException
at

com.intellij.psi.impl.source.xml.XmlTagImpl.getReferences(XmlTagImpl.java:11
5)

at

>
com.intellij.codeInsight.daemon.impl.analysis.XmlHighlightVisitor.a(XmlHighl
ightVisitor.java:316)

at

>
com.intellij.codeInsight.daemon.impl.analysis.XmlHighlightVisitor.a(XmlHighl
ightVisitor.java:78)

at

>
com.intellij.codeInsight.daemon.impl.analysis.XmlHighlightVisitor.visitXmlTo
ken(XmlHighlightVisitor.java:207)

at

com.intellij.psi.impl.source.xml.XmlTokenImpl.accept(XmlTokenImpl.java:5)

at

>
com.intellij.codeInsight.daemon.impl.analysis.HighlightVisitorImpl.visitXmlE
lement(HighlightVisitorImpl.java:181)

at

com.intellij.psi.XmlElementVisitor.visitXmlToken(XmlElementVisitor.java:58)

at

com.intellij.psi.impl.source.xml.XmlTokenImpl.accept(XmlTokenImpl.java:5)

at

>
com.intellij.codeInsight.daemon.impl.analysis.HighlightVisitorImpl.visit(Hig
hlightVisitorImpl.java:154)

at

>
com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass$1.run(GeneralHi
ghlightingPass.java:18)

at

>
com.intellij.psi.impl.PsiManagerImpl.performActionWithFormatterDisabled(PsiM
anagerImpl.java:473)

at

>
com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.a(GeneralHighli
ghtingPass.java:57)

at

>
com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.doCollectInform
ation(GeneralHighlightingPass.java:78)

at

>
com.intellij.codeInsight.daemon.impl.TextEditorHighlightingPass.collectInfor
mation(TextEditorHighlightingPass.java:8)

at

com.intellij.codeInsight.daemon.impl.UpdateThread$2.run(UpdateThread.java:9)

at

>
com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(Applicat
ionImpl.java:284)

at

com.intellij.codeInsight.daemon.impl.UpdateThread.a(UpdateThread.java:14)

at

>
com.intellij.codeInsight.daemon.impl.UpdateThread.access$100(UpdateThread.ja
va:35)

at

com.intellij.codeInsight.daemon.impl.UpdateThread$1.run(UpdateThread.java:2)

at

>
com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressMa
nagerImpl.java:41)

at

com.intellij.codeInsight.daemon.impl.UpdateThread.run(UpdateThread.java:45)
>
>

Eugene Vigdorchik (JetBrains) wrote:

I guess this is the way to go in 5.0; the next release is going to

provide a

more straight way of embedding custom languages in XML.

>

Eugene.

>

"Sascha Weinreuter" <sascha.weinreuter@NOSPAM-cit.de> wrote in message
news:de2ks3$nf0$1@is.intellij.net...

>
>>Keith Lea wrote:
>>
>>>I'm probably unclear. For example:
>>>
>>><document>
>>> <definition name="someName" />
>>> <use ref="$[someName]" />
>>></document>
>>>
>>>I want $[someName] to resolve to the <definition>, and I want to be

able

>>>to click on either "someName" and Refactor->Rename.
>>
>>Keith, you can take a look at the XSLT part of my XPathView plugin.

Simply

>

create a

>
>>mock-PsiNamedElement implementation using PsiLightElement to resolve the
>

reference to. To

>
>>be able to rename the definition, just create a PsiReference that points
>

to the definition

>
>>itself.
>>
>>Sascha
>
>
>



0
Comment actions Permalink

any progress on this? maybe for 5.1 ;) ?

this would save me a lot of work and refactoring..

0
Comment actions Permalink

I wish I could say yes, but unfortunately I have to say no, not for 5.1:(

0
Comment actions Permalink

how about DEMETRA then ;)

0
Comment actions Permalink

Hi there,

I have a very similiar use to case to the original poster. Is there now a way to do this as of IntelliJ 12? :)

0

Please sign in to leave a comment.