DOM Validation and error reporting

Hi there,

Is there a way to make use of validation within DOM attributes?

I am wanting to add validation to DOM elements within blueprint xml, which is similiar to Spring's bean definitions, an example looks like this:

    <bean id="foo" >
        <property name="simpleProperty" value="Hello World" />
    </bean>

Were the property name should have the relevant setter available, for instance setSimpleProperty(). If the bean does not have the required setter then it should indicate with red text or a message saying that the property doesn't exist for dependecy injection.

Is there a preferred way to do this? :)

Cheers

8 comments

Hi Alan,

You should create your own inspection which checks target files and ensures that attributes have appropriate values.

That's how spring plugin does that.

Denis

0

Hello Alan,

simplify specify a @Converter resolving to property of enclosing <bean> "class". Highlighting will be provided by instance of BasicDomElementsInspection for your DOM (see http://confluence.jetbrains.com/display/IDEADEV/Accessing+XML+through+IntelliJ+IDEA+DOM for details).

Actually there's an existing RFE to support blueprint: http://youtrack.jetbrains.com/issue/IDEA-103997

HTH,
Yann

0

Hi Yann,

I couldn't find any information about BasicDomElementsInspectionon that page, but i do see a 'TODO: DomExtender, DomInspection' at the top of the page mentioning to add it. I'll start looking through some of the existing plugins and try to find out how that works, thanks :)

I have a small question regarding @Converter though; Currently I'm making use of @Referencing, following the struts2 plugin code for 'Action'.
Is @Converter the preferred way of doing this?

    @Attribute("name")
    @NotNull
    @Required(nonEmpty = true, value = true)
    @Referencing(BeanPropertyResolver.class)
    GenericAttributeValue<String> getName();


Reading @Referencing, it suggesteded to me that it would highlight an unresolved reference as an error, based on the soft() value of the annotation, but that doesn't seem to be the case. Maybe I have misunderstood the comment on the annotation class?
I have tried implementing EmptyResolveMessageProvider too, but the getUnresolvedMessagePattern method didn't seem to get called :(

For reference, this is the code that I currently have


I would love to hear any feedback on this, as I'd really like to improve on my plugin :)

Thanks,
Alan

0

Hi Dennis,

Thanks for your reply; I wasn't able to find the Spring plugin in the github repos unfortunately.
It would be great to see the sourcecode for the Spring plugin as the the Blueprint XML is indeed very similiar to Spring's.

I had tried searching the forums to see where the source was, but i believe it's no longer open source?

Alan

0

Spring support is a part of IJ Ultimate Edition which is closed-source, sorry

Denis

0

Hi,

please see org.jetbrains.idea.devkit.inspections.PluginXmlDomInspection from DevKit plugin as reference for providing your own DOM inspection. This will highlight all "standard" DOM annotations and converters automatically.

@Converter always uses com.intellij.util.xml.Converter whereas @Referencing returns custom PsiReferences via com.intellij.util.xml.CustomReferenceConverter, which is needed for more sophisticated references/variants in some cases. A Converter can additionally implement CustomReferenceProvider. Unresolved message/highlighting will be provided when Converter#fromString returns null.

For your plugin: if you don't need to support nested bean properties ("name.subproperty.realproperty") I would suggest using @Converter and resolving to PsiMethod directly. Otherwise you can take Struts2 com.intellij.struts2.dom.BeanPropertyPathConverterBase as example (it's a bit more complicated than your case, as the class to resolve properties against can be changed dynamically according to DOM structure/tag).

0

Yann,

Thank you for your help :)

It would be great if powerful features like these were documented better to help beginners

Cheers,
Alan

0

We will try to improve existing documentation, please let us know if you encounter any other areas which are hard to get.

0

Please sign in to leave a comment.