Search in sources :

Example 1 with ParamsElement

use of com.intellij.struts2.dom.params.ParamsElement 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)

Example 2 with ParamsElement

use of com.intellij.struts2.dom.params.ParamsElement in project intellij-plugins by JetBrains.

the class Struts2ModelInspection method shouldCheckResolveProblems.

protected boolean shouldCheckResolveProblems(final GenericDomValue value) {
    final Converter converter = value.getConverter();
    // we roll our own checking for "class" in Struts2ModelInspectionVisitor
    if (converter instanceof ExtendableClassConverter) {
        return false;
    }
    // hack for STRPL-85: suppress <param>-highlighting within <result> for certain result-types
    if (converter instanceof ParamNameConverter) {
        final Result result = DomUtil.getParentOfType(value, Result.class, false);
        if (result != null) {
            final ResultType resultType = result.getEffectiveResultType();
            if (resultType == null) {
                // error
                return false;
            }
            final String resultTypeValue = resultType.getName().getStringValue();
            if (resultTypeValue != null && ResultTypeResolver.isChainOrRedirectType(resultTypeValue)) {
                return false;
            }
        }
    }
    final String stringValue = value.getStringValue();
    // suppress <action> "method" when using wildcards
    if (converter instanceof ActionMethodConverter && ConverterUtil.hasWildcardReference(stringValue)) {
        return false;
    }
    // suppress <result> path
    if (converter instanceof StrutsPathReferenceConverter) {
        if (stringValue == null) {
            return false;
        }
        // nested <param>-tags are present
        if (!((ParamsElement) value).getParams().isEmpty()) {
            return false;
        }
        // unsupported result-type
        final ResultType resultType = ((HasResultType) value).getEffectiveResultType();
        if (resultType == null) {
            return false;
        }
        if (!ResultTypeResolver.hasResultTypeContributor(resultType.getName().getStringValue())) {
            return false;
        }
        // suppress paths with wildcard reference
        if (ConverterUtil.hasWildcardReference(stringValue)) {
            final Action action = DomUtil.getParentOfType(value, Action.class, true);
            return action != null && !action.isWildcardMapping();
        }
        // "${actionProperty}"
        if (StringUtil.startsWith(stringValue, "${")) {
            return false;
        }
        // global URLs
        if (URLUtil.containsScheme(stringValue)) {
            return false;
        }
    }
    return true;
}
Also used : ParamNameConverter(com.intellij.struts2.dom.params.ParamNameConverter) Action(com.intellij.struts2.dom.struts.action.Action) HasResultType(com.intellij.struts2.dom.struts.HasResultType) ParamsElement(com.intellij.struts2.dom.params.ParamsElement) ActionMethodConverter(com.intellij.struts2.dom.struts.action.ActionMethodConverter) StrutsPathReferenceConverter(com.intellij.struts2.dom.struts.action.StrutsPathReferenceConverter) ExtendableClassConverter(com.intellij.struts2.dom.ExtendableClassConverter) ParamNameConverter(com.intellij.struts2.dom.params.ParamNameConverter) HasResultType(com.intellij.struts2.dom.struts.HasResultType) ResultType(com.intellij.struts2.dom.struts.strutspackage.ResultType) StrutsPathReferenceConverter(com.intellij.struts2.dom.struts.action.StrutsPathReferenceConverter) ActionMethodConverter(com.intellij.struts2.dom.struts.action.ActionMethodConverter) ExtendableClassConverter(com.intellij.struts2.dom.ExtendableClassConverter) Result(com.intellij.struts2.dom.struts.action.Result)

Example 3 with ParamsElement

use of com.intellij.struts2.dom.params.ParamsElement in project intellij-plugins by JetBrains.

the class ParamNameConverterImpl method createReferences.

@NotNull
public PsiReference[] createReferences(final GenericDomValue<List<BeanProperty>> listGenericDomValue, final PsiElement psiElement, final ConvertContext convertContext) {
    final DomElement paramsElement = findEnclosingTag(convertContext);
    if (paramsElement == null) {
        return PsiReference.EMPTY_ARRAY;
    }
    for (ParamNameCustomConverter customConverter : Extensions.getExtensions(EP_NAME)) {
        final PsiReference[] customReferences = customConverter.getCustomReferences((XmlAttributeValue) psiElement, paramsElement);
        if (customReferences.length > 0) {
            return customReferences;
        }
    }
    final PsiClass rootPsiClass = findBeanPropertyClass(paramsElement);
    return new BeanPropertyPathReferenceSet(psiElement, rootPsiClass, false).getPsiReferences();
}
Also used : DomElement(com.intellij.util.xml.DomElement) PsiClass(com.intellij.psi.PsiClass) PsiReference(com.intellij.psi.PsiReference) BeanPropertyPathReferenceSet(com.intellij.struts2.reference.common.BeanPropertyPathReferenceSet) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with ParamsElement

use of com.intellij.struts2.dom.params.ParamsElement in project intellij-plugins by JetBrains.

the class ResultParamNameCustomConverter method getCustomReferences.

@NotNull
@Override
public PsiReference[] getCustomReferences(XmlAttributeValue nameAttributeValue, DomElement paramsElement) {
    if (!(paramsElement instanceof Result)) {
        return PsiReference.EMPTY_ARRAY;
    }
    Result result = (Result) paramsElement;
    Action action = DomUtil.getParentOfType(result, Action.class, true);
    assert action != null;
    return new PsiReference[] { new MergingBeanPropertyPathReference(nameAttributeValue, action, result) };
}
Also used : Action(com.intellij.struts2.dom.struts.action.Action) PsiReference(com.intellij.psi.PsiReference) Result(com.intellij.struts2.dom.struts.action.Result) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PsiReference (com.intellij.psi.PsiReference)3 NotNull (org.jetbrains.annotations.NotNull)3 PsiClass (com.intellij.psi.PsiClass)2 Action (com.intellij.struts2.dom.struts.action.Action)2 Result (com.intellij.struts2.dom.struts.action.Result)2 BeanPropertyPathReferenceSet (com.intellij.struts2.reference.common.BeanPropertyPathReferenceSet)2 ExtendableClassConverter (com.intellij.struts2.dom.ExtendableClassConverter)1 ParamNameConverter (com.intellij.struts2.dom.params.ParamNameConverter)1 ParamsElement (com.intellij.struts2.dom.params.ParamsElement)1 HasResultType (com.intellij.struts2.dom.struts.HasResultType)1 ActionMethodConverter (com.intellij.struts2.dom.struts.action.ActionMethodConverter)1 StrutsPathReferenceConverter (com.intellij.struts2.dom.struts.action.StrutsPathReferenceConverter)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 ResultType (com.intellij.struts2.dom.struts.strutspackage.ResultType)1 DomElement (com.intellij.util.xml.DomElement)1 ArrayList (java.util.ArrayList)1