conditions to match reference provider

Hi all,  
I'm  stich at condition for mathcing reference provider.

I managed to match content of xml attribute  by name:

xmlAttributeValue().withLocalName("receiver")



and now I'm trying to constrain this condition to  certain tag defined as dom elemement:

  xmlAttributeValue().withLocalName("receiver").and(domElement().withParent(FooBar.class))


and (surprize!)  this does not work as intendet.   Is there some desrcription abot condition mathing?
( sources are bare of comments )

10 comments

Something like this should work:

xmlAttributeValue()
      .withLocalName("receiver")
      .withSuperParent(2, DomPatterns.withDom(domElement(FooBar.class)

0

Hi Pribluda,

Could you post your sample XML, what you're trying to match, and what your DomElement interfaces look like? :)

Could it also be that your parent DomElement is actually a SuperParent for instance?

For example, here is an example of matching the XmlAttributeValue "value" if it has a super domElement parent of a BlueprintBean

Example of matched XML :

<bean id="foo" >
    <argument value="${hello.world}" />
    <property name="quux" value="${hello.world}" />
</bean>


Example of the pattern used



                xmlAttributeValue()
                        .withLocalName("value")
                        .withSuperParent(3, withDom(domElement(BlueprintBean.class)))
Alan
0

My XML:


   <link_in type="http" trigger="blamblam" receiver="StartMEssage"/>


And automagically generated interface:


public interface Link_in extends DomElement {

.....
     /**
      * Returns the value of the receiver child.
      * @return the value of the receiver child.
      */
     @NotNull
     GenericAttributeValue<String> getReceiver();


}



So I like to reference to attribute value  of this tag defined by interface.  And while we are at it,  I'd like to navigate  to some other corresponding
tag ( so I shall return proper PSI element from my reference provicder?  right?  )  and provide error if no such tag  is found.   Is PsiReferenceContributor proper tool for this?

PS: My first name is Konstantin %)

0

Solved.

Proper condition was:


xmlAttributeValue().withLocalName("receiver").withSuperParent(2,xmlTag().withLocalName("link_in").withNamespace(NAMESPACE_URI));

0

Depending on your DOM and @Namespace definitions there, this might differ in the future when you change one place. I'd use DomPatterns if possible to make sure any changes in DOM are reflected here.

0

It did not worked with DomPatterns ,  despite declared namespace on generated interface.

0

Did you call com.intellij.util.xml.DomFileDescription#registerNamespacePolicy in your DomFileDescription?

0

Namespace policy is registered.     Shall I put key of namespace policy into @Namespace annotation or uri on interface?

0

@Namespace takes the key which is then registered in com.intellij.util.xml.DomFileDescription#registerNamespacePolicy with the corresponding URI(s).
See com.intellij.struts2.dom.struts.Struts2DomFileDescription and com.intellij.struts2.dom.struts.StrutsRoot as example.

0

OK,  not I'm slowly groking my problem.   You have to assure reachability of all the elements from root elelemt
with proper @Subag annotations  - otherwise DOM does not work properlyand does not know subtag classes.

Also,  need to check generated dom classes and adjust manually  

0

Please sign in to leave a comment.