FInd usages of Java getter used from injected EL variable in XML

For a custom plugin, I've implemented a LanguageInjector that injects EL (ELLanguage.INSTANCE) into certain XML Attribute values.

I've also implemented ElVariablesProvider processImplicitVariables to provide the type information the EL tooling needs to locate the Java getter method that an EL variable points to.

This seems to work, and I can Cmd+Click to navigate from my EL variable "#{foo}" to MyJavaBean.getFoo(). However, the getter is shown as unused and find usages doesn't pick up the usage. What am I missing?

Except from my ElVariablesProvider.processImplicitVariables implementation:

// targetType is the qualified bean name that the el variable belongs to, e.g. "package.foo.BeanName"
final XmlAttribute targetType = renderingElement.getAttribute("targetType");
if(targetType != null) {
    final String targetTypeModelName = targetType.getValue();
    if(targetTypeModelName != null) {
        final PsiType psiTargetType = PsiImplUtil.buildTypeFromTypeString(targetTypeModelName, psiElement, psiElement.getContainingFile());
        final Project project = psiElement.getProject();
        final PsiClass declaringClass = JavaPsiFacade.getInstance(project).findClass(targetTypeModelName, GlobalSearchScope.projectScope(project));
        if(declaringClass != null) {
            PsiElement declaration = declaringClass;
            final String propertyName = psiElement.getText();
            for (String readMethodName : getPropertyReadMethodNames(propertyName)) {
                final PsiMethod[] readMethods = declaringClass.findMethodsByName(readMethodName, true);
                if(readMethods.length > 0) {
                    // found the getter that the el variable points to
                    declaration = readMethods[0];
                    break;
                }
            }
            final ELImplicitVariable elImplicitVariable = new ELImplicitVariable(psiElement, propertyName, psiTargetType, declaration, ELImplicitVariable.NESTED_RANGE);
            elElementProcessor.processVariable(elImplicitVariable);
            System.out.println(propertyName);
            return false; // processed
        }
    }
}

1 comment
Comment actions Permalink

Update:

Using com.intellij.psi.impl.source.jsp.el.impl.ELElementProcessor#processMethod seems to be a better way to address the read methods on a bean. The quick documentation and Cmd+Click works, but still no usages.

I'm thinking find usages doesn't include my file type in the use scope for performance reasons?

0

Please sign in to leave a comment.