Search in sources :

Example 16 with StrutsModel

use of com.intellij.struts2.dom.struts.model.StrutsModel 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 17 with StrutsModel

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

the class StrutsConstantManagerImpl method getConvertedValue.

@Override
@Nullable
public <T> T getConvertedValue(@NotNull final PsiElement context, @NotNull final StrutsConstantKey<T> strutsConstantKey) {
    final PsiFile containingFile = context.getContainingFile();
    final StrutsModel strutsModel = getStrutsModel(containingFile);
    if (strutsModel == null) {
        return null;
    }
    final String stringValue = getStringValue(containingFile, strutsModel, strutsConstantKey.getKey());
    if (stringValue == null) {
        return null;
    }
    final Converter<T> converter = findConverter(context, strutsConstantKey);
    if (converter == null) {
        //noinspection unchecked
        return (T) stringValue;
    }
    final DomFileElement<StrutsRoot> first = strutsModel.getRoots().iterator().next();
    final ConvertContext convertContext = ConvertContextFactory.createConvertContext(first);
    //noinspection unchecked
    return converter.fromString(stringValue, convertContext);
}
Also used : StrutsModel(com.intellij.struts2.dom.struts.model.StrutsModel) PsiFile(com.intellij.psi.PsiFile) ConvertContext(com.intellij.util.xml.ConvertContext) StrutsRoot(com.intellij.struts2.dom.struts.StrutsRoot) Nullable(org.jetbrains.annotations.Nullable)

Example 18 with StrutsModel

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

the class StrutsConstantManagerImpl method getStrutsModel.

/**
   * Determines best matching StrutsModel.
   *
   * @param psiFile Context file.
   * @return {@code null} if no model could be determined.
   */
@Nullable
private static StrutsModel getStrutsModel(final PsiFile psiFile) {
    final StrutsManager strutsManager = StrutsManager.getInstance(psiFile.getProject());
    final StrutsModel model;
    if (psiFile instanceof XmlFile && strutsManager.isStruts2ConfigFile((XmlFile) psiFile)) {
        model = strutsManager.getModelByFile((XmlFile) psiFile);
    } else {
        model = strutsManager.getCombinedModel(psiFile);
    }
    return model;
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) StrutsManager(com.intellij.struts2.dom.struts.model.StrutsManager) StrutsModel(com.intellij.struts2.dom.struts.model.StrutsModel) Nullable(org.jetbrains.annotations.Nullable)

Example 19 with StrutsModel

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

the class ResultTypeConverter method convertString.

@Override
protected ResultType convertString(@Nullable final String s, final ConvertContext convertContext) {
    if (StringUtil.isEmpty(s)) {
        return null;
    }
    final StrutsModel strutsModel = ConverterUtil.getStrutsModelOrCombined(convertContext);
    if (strutsModel == null) {
        return null;
    }
    final List<ResultType> resultTypes = ContainerUtil.concat(strutsModel.getStrutsPackages(), RESULT_TYPE_GETTER);
    return ContainerUtil.find(resultTypes, resultType -> Comparing.strEqual(s, resultType.getName().getStringValue()));
}
Also used : StrutsModel(com.intellij.struts2.dom.struts.model.StrutsModel) ResultType(com.intellij.struts2.dom.struts.strutspackage.ResultType)

Example 20 with StrutsModel

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

Aggregations

StrutsModel (com.intellij.struts2.dom.struts.model.StrutsModel)24 StrutsManager (com.intellij.struts2.dom.struts.model.StrutsManager)10 Action (com.intellij.struts2.dom.struts.action.Action)8 NotNull (org.jetbrains.annotations.NotNull)8 Module (com.intellij.openapi.module.Module)6 PsiElement (com.intellij.psi.PsiElement)6 PsiFile (com.intellij.psi.PsiFile)6 Nullable (org.jetbrains.annotations.Nullable)6 XmlFile (com.intellij.psi.xml.XmlFile)5 PathReference (com.intellij.openapi.paths.PathReference)4 PsiReference (com.intellij.psi.PsiReference)4 Result (com.intellij.struts2.dom.struts.action.Result)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 PsiClass (com.intellij.psi.PsiClass)3 StrutsRoot (com.intellij.struts2.dom.struts.StrutsRoot)3 ArrayList (java.util.ArrayList)3 NavigationItem (com.intellij.navigation.NavigationItem)2 ModuleUtilCore (com.intellij.openapi.module.ModuleUtilCore)2 PsiManager (com.intellij.psi.PsiManager)2 XmlTag (com.intellij.psi.xml.XmlTag)2