Search in sources :

Example 1 with InterceptorRef

use of com.intellij.struts2.dom.struts.strutspackage.InterceptorRef in project intellij-plugins by JetBrains.

the class InterceptorRefInStackParamNameCustomConverter method getCustomReferences.

@NotNull
@Override
public PsiReference[] getCustomReferences(final XmlAttributeValue nameAttributeValue, final DomElement paramsElement) {
    if (!(paramsElement instanceof InterceptorRef)) {
        return PsiReference.EMPTY_ARRAY;
    }
    InterceptorRef interceptorRef = (InterceptorRef) paramsElement;
    final InterceptorOrStackBase value = interceptorRef.getName().getValue();
    if (!(value instanceof InterceptorStack)) {
        return PsiReference.EMPTY_ARRAY;
    }
    final String text = nameAttributeValue.getValue();
    final boolean hasDot = StringUtil.containsChar(text, '.');
    final int idx = hasDot ? text.indexOf('.') : text.length();
    final String refName = text.substring(0, idx);
    final InterceptorStack stack = (InterceptorStack) value;
    final InterceptorRef resolvedInterceptorRef = ContainerUtil.find(stack.getInterceptorRefs(), ref -> Comparing.strEqual(refName, ref.getName().getStringValue()));
    final List<PsiReference> customReferences = new ArrayList<>(2);
    customReferences.add(new InterceptorRefPsiReference(nameAttributeValue, TextRange.from(1, idx), resolvedInterceptorRef, stack));
    if (resolvedInterceptorRef == null) {
        return ArrayUtil.toObjectArray(customReferences, PsiReference.class);
    }
    final String propertyText = text.substring(idx + 1, text.length());
    final PsiClass paramsClass = resolvedInterceptorRef.getParamsClass();
    final BeanPropertyPathReferenceSet beanPropertyPathReferenceSet = new BeanPropertyPathReferenceSet(propertyText, nameAttributeValue, idx + 2, '.', paramsClass, false);
    Collections.addAll(customReferences, beanPropertyPathReferenceSet.getPsiReferences());
    return ArrayUtil.toObjectArray(customReferences, PsiReference.class);
}
Also used : InterceptorOrStackBase(com.intellij.struts2.dom.struts.strutspackage.InterceptorOrStackBase) InterceptorStack(com.intellij.struts2.dom.struts.strutspackage.InterceptorStack) ArrayList(java.util.ArrayList) PsiClass(com.intellij.psi.PsiClass) PsiReference(com.intellij.psi.PsiReference) InterceptorRef(com.intellij.struts2.dom.struts.strutspackage.InterceptorRef) BeanPropertyPathReferenceSet(com.intellij.struts2.reference.common.BeanPropertyPathReferenceSet) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PsiClass (com.intellij.psi.PsiClass)1 PsiReference (com.intellij.psi.PsiReference)1 InterceptorOrStackBase (com.intellij.struts2.dom.struts.strutspackage.InterceptorOrStackBase)1 InterceptorRef (com.intellij.struts2.dom.struts.strutspackage.InterceptorRef)1 InterceptorStack (com.intellij.struts2.dom.struts.strutspackage.InterceptorStack)1 BeanPropertyPathReferenceSet (com.intellij.struts2.reference.common.BeanPropertyPathReferenceSet)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1