Dynamically create DOM elements in DomExtender?

Answered

I'm working on an XML DOM plugin that requires dynamically adding child elements to the DOM based on an external data source found at runtime (in my case, annotations on classes that map to XML tags). These can't be DomElement classes found on disk because they're only discoverable at runtime. The information I retrieve at runtime tells me what kinds of attributes and children the element should support and other validation logic I need to enforce.

I've already implemented a DomExtender, but what's the best way to go about creating DomElements with custom validation at runtime? Should I look at using some like java.lang.reflect.Proxy to create my custom DOM elements at runtime, or is there a better / built-in way in IntelliJ to dynamically create these elements and their validation logic?

1 comment
Comment actions Permalink
Official comment

You definitely shouldn't use Proxy to create your dom elements. You can create an arbitrary DOM children hierarchy by using DomExtender to create its root, then to create its children, then the children of the children etc. AntDomExtender is an example, that creates the structure based on JVM reflection information, passed from parents to children via ELEMENT_IMPL_CLASS_KEY user data.

Please sign in to leave a comment.