Search in sources :

Example 11 with Result

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

the class GoToPackageSymbolProvider method addNames.

protected void addNames(@NotNull final Module module, final Set<String> result) {
    final StrutsModel strutsModel = StrutsManager.getInstance(module.getProject()).getCombinedModel(module);
    if (strutsModel == null) {
        return;
    }
    final Set<String> packageNames = ContainerUtil.map2Set(strutsModel.getStrutsPackages(), STRUTS_PACKAGE_NAME_FUNCTION);
    result.addAll(packageNames);
}
Also used : StrutsModel(com.intellij.struts2.dom.struts.model.StrutsModel)

Example 12 with Result

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

the class GotoRelatedActionProvider method getItems.

@NotNull
@Override
public List<? extends GotoRelatedItem> getItems(@NotNull final PsiElement psiElement) {
    PsiFile psiFile = psiElement.getContainingFile();
    if (psiFile == null)
        return Collections.emptyList();
    final PsiFile containingFile = psiFile.getOriginalFile();
    final String filename = containingFile.getName();
    final String extension = FileUtilRt.getExtension(filename);
    if (!SUPPORTED_EXTENSIONS.contains(extension)) {
        return Collections.emptyList();
    }
    final StrutsManager strutsManager = StrutsManager.getInstance(psiElement.getProject());
    final StrutsModel strutsModel = strutsManager.getCombinedModel(psiElement);
    if (strutsModel == null) {
        return Collections.emptyList();
    }
    final List<PsiFile> allFiles = containingFile.getViewProvider().getAllFiles();
    final Set<Action> actions = new HashSet<>();
    final List<GotoRelatedItem> items = new ArrayList<>();
    strutsModel.processActions(action -> {
        for (final Result result : action.getResults()) {
            final PathReference pathReference = result.getValue();
            if (pathReference == null) {
                continue;
            }
            final String path = pathReference.getPath();
            if (!path.endsWith(filename)) {
                continue;
            }
            final PsiElement resolve = pathReference.resolve();
            if (ContainerUtil.find(allFiles, resolve) == null) {
                continue;
            }
            if (!actions.contains(action)) {
                items.add(new DomGotoRelatedItem(action));
                actions.add(action);
            }
            final PsiClass actionClass = action.searchActionClass();
            if (actionClass == null) {
                continue;
            }
            final PsiMethod actionMethod = action.searchActionMethod();
            items.add(new GotoRelatedItem(actionMethod != null ? actionMethod : actionClass));
        }
        return true;
    });
    return items;
}
Also used : PathReference(com.intellij.openapi.paths.PathReference) Action(com.intellij.struts2.dom.struts.action.Action) PsiMethod(com.intellij.psi.PsiMethod) StrutsManager(com.intellij.struts2.dom.struts.model.StrutsManager) PsiClass(com.intellij.psi.PsiClass) Result(com.intellij.struts2.dom.struts.action.Result) DomGotoRelatedItem(com.intellij.codeInsight.navigation.DomGotoRelatedItem) StrutsModel(com.intellij.struts2.dom.struts.model.StrutsModel) PsiFile(com.intellij.psi.PsiFile) DomGotoRelatedItem(com.intellij.codeInsight.navigation.DomGotoRelatedItem) GotoRelatedItem(com.intellij.navigation.GotoRelatedItem) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with Result

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

the class StrutsDataModel method updateDataModel.

private void updateDataModel() {
    final StrutsModel model = StrutsManager.getInstance(myProject).getModelByFile(myFile);
    if (model == null) {
        return;
    }
    for (final StrutsPackage strutsPackage : model.getStrutsPackages()) {
        for (final Action action : strutsPackage.getActions()) {
            final ActionNode actionNode = new ActionNode(action, action.getName().getStringValue());
            addNode(actionNode);
            for (final Result result : action.getResults()) {
                final PathReference pathReference = result.getValue();
                final String path = pathReference != null ? pathReference.getPath() : UNKNOWN;
                final ResultNode resultNode = new ResultNode(result, path);
                addNode(resultNode);
                final String resultName = result.getName().getStringValue();
                addEdge(new BasicStrutsEdge(actionNode, resultNode, resultName != null ? resultName : Result.DEFAULT_NAME));
            }
        }
    }
}
Also used : PathReference(com.intellij.openapi.paths.PathReference) Action(com.intellij.struts2.dom.struts.action.Action) BasicStrutsEdge(com.intellij.struts2.graph.beans.BasicStrutsEdge) ResultNode(com.intellij.struts2.graph.beans.ResultNode) StrutsModel(com.intellij.struts2.dom.struts.model.StrutsModel) ActionNode(com.intellij.struts2.graph.beans.ActionNode) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage) Result(com.intellij.struts2.dom.struts.action.Result)

Example 14 with Result

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

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

Aggregations

NotNull (org.jetbrains.annotations.NotNull)10 Result (com.intellij.struts2.dom.struts.action.Result)9 Action (com.intellij.struts2.dom.struts.action.Action)8 StrutsModel (com.intellij.struts2.dom.struts.model.StrutsModel)8 PathReference (com.intellij.openapi.paths.PathReference)6 Ref (com.intellij.openapi.util.Ref)6 StrutsPackage (com.intellij.struts2.dom.struts.strutspackage.StrutsPackage)6 StrutsPackageHierarchyWalker (com.intellij.struts2.dom.struts.strutspackage.StrutsPackageHierarchyWalker)6 Nullable (org.jetbrains.annotations.Nullable)6 Processor (com.intellij.util.Processor)5 List (java.util.List)5 NonNls (org.jetbrains.annotations.NonNls)5 ResultType (com.intellij.struts2.dom.struts.strutspackage.ResultType)4 Condition (com.intellij.openapi.util.Condition)3 DefaultClassRef (com.intellij.struts2.dom.struts.strutspackage.DefaultClassRef)3 SmartList (com.intellij.util.SmartList)3 ContainerUtil (com.intellij.util.containers.ContainerUtil)3 ConvertContext (com.intellij.util.xml.ConvertContext)3 Collection (java.util.Collection)3 NavigationItem (com.intellij.navigation.NavigationItem)2