UsageProvider in a large framework for different filetypes

Answered

Hi guys. Again, i'm working on a plugin for APACHE ERP OFBiz.
I've worked out some references, and now i'd like to use the FindUsagesProvider.
Here is my problem : as far as i understand the documentation, the usages provider uses the caches that's built when importing project, wich is made according to filetype.
But the usages i'm trying to get can occur in multiple fileTypes for a single element.

Here is an example :
This would be a service definition in an XML file :


<service name="createMarketingCampaign" default-entity-name="MarketingCampaign" engine="entity-auto" invoke="create" auth="true">
<description>Create a MarketingCampaign record</description>
<permission-service service-name="marketingPermissionService" main-action="CREATE"/>
<auto-attributes include="pk" mode="OUT" optional="false"/>
<auto-attributes include="nonpk" mode="IN" optional="true"/>
</service>

And the name of this service could be called in an other xml file, but also in a java or groovy file :

<event type="service" path="" invoke="createMarketingCampaign"/>

or

Map<String, Object> serviceResult = dispatcher.runSync("createMarketingCampaign", context);

We also implemented in the plugin some of the dom description.

What would be the best way to achieve the usages search  for this example ? given that references towards the definition are functional.

5 comments
Comment actions Permalink

If your custom PsiReference from code place(s) -> XML declaration (e.g., "name" attribute) are working fully and the names in code vs XML do not differ, you won't need to implement anything special AFAIU.

0
Comment actions Permalink

This would have been my thought, but it doesn't work :

References towards définition works, but not the find usages :

Here is the code i tried :

package org.apache.ofbiz.reference.usages

import com.intellij.lang.HelpID
import com.intellij.lang.findUsages.FindUsagesProvider
import com.intellij.psi.PsiElement
import org.jetbrains.annotations.NotNull

class ServicesUsages implements FindUsagesProvider {

@Override
boolean canFindUsagesFor(@NotNull PsiElement psiElement) {
return true
}

@Override
String getHelpId(@NotNull PsiElement psiElement) {
return HelpID.FIND_OTHER_USAGES;
}

@Override
String getType(@NotNull PsiElement psiElement) {
return "Service"
}

@Override
String getDescriptiveName(@NotNull PsiElement psiElement) {
return psiElement.getText()
}

@Override
String getNodeText(@NotNull PsiElement psiElement, boolean b) {
return getDescriptiveName(psiElement)
}
}
<lang.findUsagesProvider language="XML" implementationClass="org.apache.ofbiz.reference.usages.ServicesUsages" />

 

0
Comment actions Permalink

The attribute defining the ID in the XML must be annotated with com.intellij.util.xml.NameValue

0
Comment actions Permalink

It is :

interface ServiceDefFile extends DomElement {

@SubTagList("service")
List<Service> getServices()

interface Service extends DomElement {

@NameValue
@Stubbed
@Attribute("name")
GenericAttributeValue<String> getName()
// ...

0
Comment actions Permalink

Please disable your custom

lang.findUsagesProvider
0

Please sign in to leave a comment.