Search in sources :

Example 16 with Action

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

the class CreateValidationXmlIntention method getActionsWithoutValidation.

private static List<Action> getActionsWithoutValidation(final PsiClass actionClass) {
    final Project project = actionClass.getProject();
    final List<Action> actions = getActionsForClazz(project, actionClass, ModuleUtilCore.findModuleForPsiElement(actionClass));
    final List<XmlFile> files = ValidatorManager.getInstance(project).findValidationFilesFor(actionClass);
    return ContainerUtil.filter(actions, action -> {
        final String path = action.getName().getStringValue();
        for (final XmlFile file : files) {
            if (file.getName().contains(path)) {
                return false;
            }
        }
        return true;
    });
}
Also used : Project(com.intellij.openapi.project.Project) PsiElementBaseIntentionAction(com.intellij.codeInsight.intention.PsiElementBaseIntentionAction) Action(com.intellij.struts2.dom.struts.action.Action) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) XmlFile(com.intellij.psi.xml.XmlFile)

Example 17 with Action

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

the class Struts2UrlConverter method getTargetPaths.

public Collection<String> getTargetPaths(@NotNull final PsiFile sourceFile, @NotNull final WebFacet webFacet) {
    final StrutsModel combinedModel = StrutsManager.getInstance(sourceFile.getProject()).getCombinedModel(webFacet.getModule());
    if (combinedModel == null) {
        return Collections.emptyList();
    }
    final List<String> actionExtensions = StrutsConstantHelper.getActionExtensions(sourceFile);
    if (actionExtensions.isEmpty()) {
        return Collections.emptyList();
    }
    final String actionExtension = actionExtensions.get(0);
    @NonNls final ArrayList<String> list = new ArrayList<>();
    combinedModel.processActions(action -> {
        for (final Result result : action.getResults()) {
            final PathReference pathReference = result.getValue();
            if (pathReference != null) {
                final PsiElement psiElement = pathReference.resolve();
                if (psiElement != null && psiElement.equals(sourceFile)) {
                    String namespace = action.getNamespace();
                    if (!Comparing.equal(namespace, StrutsPackage.DEFAULT_NAMESPACE)) {
                        namespace += "/";
                    }
                    list.add(namespace + action.getName().getStringValue() + actionExtension);
                }
            }
        }
        return true;
    });
    return list;
}
Also used : PathReference(com.intellij.openapi.paths.PathReference) NonNls(org.jetbrains.annotations.NonNls) StrutsModel(com.intellij.struts2.dom.struts.model.StrutsModel) ArrayList(java.util.ArrayList) PsiElement(com.intellij.psi.PsiElement) Result(com.intellij.struts2.dom.struts.action.Result)

Example 18 with Action

use of com.intellij.struts2.dom.struts.action.Action 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 19 with Action

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

Action (com.intellij.struts2.dom.struts.action.Action)15 StrutsModel (com.intellij.struts2.dom.struts.model.StrutsModel)10 Result (com.intellij.struts2.dom.struts.action.Result)8 NotNull (org.jetbrains.annotations.NotNull)8 PathReference (com.intellij.openapi.paths.PathReference)5 StrutsManager (com.intellij.struts2.dom.struts.model.StrutsManager)5 Module (com.intellij.openapi.module.Module)4 PsiElement (com.intellij.psi.PsiElement)4 PsiReference (com.intellij.psi.PsiReference)3 XmlFile (com.intellij.psi.xml.XmlFile)3 XmlTag (com.intellij.psi.xml.XmlTag)3 ArrayList (java.util.ArrayList)3 PsiElementBaseIntentionAction (com.intellij.codeInsight.intention.PsiElementBaseIntentionAction)2 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)2 HasResultType (com.intellij.struts2.dom.struts.HasResultType)2 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 NonNls (org.jetbrains.annotations.NonNls)2 DomGotoRelatedItem (com.intellij.codeInsight.navigation.DomGotoRelatedItem)1