Search in sources :

Example 1 with HasResultType

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

the class ExceptionMappingResultResolveConverter method getVariants.

@NotNull
public Collection<? extends HasResultType> getVariants(final ConvertContext context) {
    final DomElement invocationElement = context.getInvocationElement();
    final Action action = invocationElement.getParentOfType(Action.class, true);
    if (action == null) {
        return Collections.emptySet();
    }
    final List<HasResultType> variants = new ArrayList<>();
    // Action-local first
    variants.addAll(action.getResults());
    final StrutsPackage strutsPackage = action.getStrutsPackage();
    final GlobalResults globalResults = strutsPackage.getGlobalResults();
    variants.addAll(globalResults.getResults());
    return variants;
}
Also used : DomElement(com.intellij.util.xml.DomElement) HasResultType(com.intellij.struts2.dom.struts.HasResultType) GlobalResults(com.intellij.struts2.dom.struts.strutspackage.GlobalResults) ArrayList(java.util.ArrayList) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with HasResultType

use of com.intellij.struts2.dom.struts.HasResultType 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 HasResultType

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

the class StrutsResultContributor method getNamespace.

/**
   * Gets the current namespace for the given element.
   *
   * @param psiElement Current element.
   * @return {@code null} on XML errors or if {@link #matchesResultType(String)} returns {@code false}.
   */
@Nullable
protected final String getNamespace(@NotNull final PsiElement psiElement) {
    final DomElement resultElement = DomUtil.getDomElement(psiElement);
    if (resultElement == null) {
        // XML syntax error
        return null;
    }
    assert resultElement instanceof HasResultType : "not instance of HasResultType: " + resultElement + ", text: " + psiElement.getText();
    final ResultType effectiveResultType = ((HasResultType) resultElement).getEffectiveResultType();
    if (effectiveResultType == null) {
        return null;
    }
    final String resultType = effectiveResultType.getName().getStringValue();
    if (resultType == null || !matchesResultType(resultType)) {
        return null;
    }
    final StrutsPackage strutsPackage = resultElement.getParentOfType(StrutsPackage.class, true);
    if (strutsPackage == null) {
        // XML syntax error
        return null;
    }
    return strutsPackage.searchNamespace();
}
Also used : DomElement(com.intellij.util.xml.DomElement) HasResultType(com.intellij.struts2.dom.struts.HasResultType) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage) HasResultType(com.intellij.struts2.dom.struts.HasResultType) ResultType(com.intellij.struts2.dom.struts.strutspackage.ResultType) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

HasResultType (com.intellij.struts2.dom.struts.HasResultType)3 ResultType (com.intellij.struts2.dom.struts.strutspackage.ResultType)2 StrutsPackage (com.intellij.struts2.dom.struts.strutspackage.StrutsPackage)2 DomElement (com.intellij.util.xml.DomElement)2 ExtendableClassConverter (com.intellij.struts2.dom.ExtendableClassConverter)1 ParamNameConverter (com.intellij.struts2.dom.params.ParamNameConverter)1 ParamsElement (com.intellij.struts2.dom.params.ParamsElement)1 Action (com.intellij.struts2.dom.struts.action.Action)1 ActionMethodConverter (com.intellij.struts2.dom.struts.action.ActionMethodConverter)1 Result (com.intellij.struts2.dom.struts.action.Result)1 StrutsPathReferenceConverter (com.intellij.struts2.dom.struts.action.StrutsPathReferenceConverter)1 GlobalResults (com.intellij.struts2.dom.struts.strutspackage.GlobalResults)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1