Building a Stub-Index on XML Tag

已回答

To speed up the LineMarkerProvider on large XML files in my plugin, I would like to implement a stub index on a special XML Tag. I thought using the XmlTagStub and the XmlStubBasedTagElementType is a good idea, but somehow i'm not getting further with it and I would really appreciate some help here (other than the link to the stub-index documentation). Following (in very simple way):

Some Xml structure in foo.xml

<MethodDefinition name="firstMethodName">....</MethodDefinition>

The same xml tag with the same name in boo.xml

<MethodDefinition name="firstMethodName">....</MethodDefinition>

What i'd need is a stub-index with the key firstMethodName and the 2 references to the MethodDefinition XmlTag as values. 

So the first question is, if that is even possible? I could'nt find any example on this. 

 

So far I've tried to register a stubElementTypeHolder in my plugin.xml

<stubElementTypeHolder class="com.myplugin.stubs.MethodDefinitionTypeHolder"/>

Which looks like 

public interface MethodDefinitionTypeHolder{

IStubElementType METHOD_DEFINITION = new XmlStubBasedTagElementType("MethodDefinition", MyLanguage.INSTANCE);
}

The stub index in the plugin.xml

<stubIndex implementation="com.myplugin.stubs.MethodDefinitionIndex"/>

...with the code:

public class MethodDefinitionIndex extends StringStubIndexExtension<XmlTag> {
private static final StubIndexKey<String, XmlTag> KEY = StubIndexKey.createIndexKey("methoddefinition.index");

@NotNull
@Override
public StubIndexKey<String, XmlTag> getKey() {
return KEY;
}
}

 

This is where i did so far and unfortunately I can't get any further. I miss the part, where my XML is parsed, (in the createStub method of XmlStubBasedTagElementType?). Or should I define my own XmlTagStub like MethodDefinitionStub and use that, or just implement my own IStubElementType (maybe as subclass of the XmlStubBasedTagElementType)?

Any hints or examples how to implement somthing like this?

Any help would be appreciated, thanks in advance.

Zsolt.

0

Please try introducing a custom FileBasedIndex that stores relevant data for the XML Tags you're interested in https://www.jetbrains.org/intellij/sdk/docs/basics/indexing_and_psi_stubs/file_based_indexes.html

Using DOM API might be much easier http://www.jetbrains.org/intellij/sdk/docs/reference_guide/frameworks_and_external_apis/xml_dom_api.html and should usually be fast enough, you can add @Stubbed to use "XML stubs" behind the scenes.

0

Yann, thank you for you answer!

Yes, i have the FileBasedIndex already, mapping the XML Tags to the files, which of course is a big help to parse only the files which I need.

I'll check the DOM API, maybe this could be a solution. 

Thanks again!

Zs.

0

请先登录再写评论。