Search in sources :

Example 6 with ResultType

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

the class ResultImpl method getEffectiveResultType.

@Nullable
public ResultType getEffectiveResultType() {
    final GenericAttributeValue<ResultType> typeAttribute = getType();
    if (DomUtil.hasXml(typeAttribute)) {
        return typeAttribute.getValue();
    }
    final StrutsPackage strutsPackage = getParentOfType(StrutsPackage.class, true);
    return strutsPackage != null ? strutsPackage.searchDefaultResultType() : null;
}
Also used : StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage) ResultType(com.intellij.struts2.dom.struts.strutspackage.ResultType) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with ResultType

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

the class ResultTypeResolvingConverterImpl method getVariants.

@NotNull
public Collection<? extends ResultType> getVariants(final ConvertContext context) {
    final List<ResultType> results = new SmartList<>();
    final Processor<StrutsPackage> processor = strutsPackage -> {
        results.addAll(strutsPackage.getResultTypes());
        return true;
    };
    final StrutsPackageHierarchyWalker walker = new StrutsPackageHierarchyWalker(ConverterUtil.getCurrentStrutsPackage(context), processor);
    walker.walkUp();
    return results;
}
Also used : StringUtil(com.intellij.openapi.util.text.StringUtil) Collection(java.util.Collection) NonNls(org.jetbrains.annotations.NonNls) ContainerUtil(com.intellij.util.containers.ContainerUtil) StrutsPackageHierarchyWalker(com.intellij.struts2.dom.struts.strutspackage.StrutsPackageHierarchyWalker) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Comparing(com.intellij.openapi.util.Comparing) SmartList(com.intellij.util.SmartList) ResultType(com.intellij.struts2.dom.struts.strutspackage.ResultType) Processor(com.intellij.util.Processor) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage) ConverterUtil(com.intellij.struts2.dom.ConverterUtil) ResultTypeResolvingConverter(com.intellij.struts2.dom.struts.action.ResultTypeResolvingConverter) ConvertContext(com.intellij.util.xml.ConvertContext) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) Condition(com.intellij.openapi.util.Condition) StrutsPackageHierarchyWalker(com.intellij.struts2.dom.struts.strutspackage.StrutsPackageHierarchyWalker) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage) ResultType(com.intellij.struts2.dom.struts.strutspackage.ResultType) SmartList(com.intellij.util.SmartList) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with ResultType

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

the class StrutsPackageImpl method searchDefaultResultType.

@Nullable
public ResultType searchDefaultResultType() {
    if (myCachedDefaultResultType == null) {
        final PsiFile containingFile = getContainingFile();
        if (containingFile == null) {
            return null;
        }
        myCachedDefaultResultType = CachedValuesManager.getManager(containingFile.getProject()).createCachedValue(() -> {
            final Ref<ResultType> result = new Ref<>();
            final StrutsPackageHierarchyWalker walker = new StrutsPackageHierarchyWalker(this, strutsPackage -> {
                final List<ResultType> resultTypes = strutsPackage.getResultTypes();
                for (final ResultType resultType : resultTypes) {
                    final GenericAttributeValue<Boolean> defaultAttribute = resultType.getDefault();
                    if (DomUtil.hasXml(defaultAttribute) && defaultAttribute.getValue() == Boolean.TRUE) {
                        result.set(resultType);
                        return false;
                    }
                }
                return true;
            });
            walker.walkUp();
            return CachedValueProvider.Result.createSingleDependency(result.get(), PsiModificationTracker.MODIFICATION_COUNT);
        }, false);
    }
    return myCachedDefaultResultType.getValue();
}
Also used : StrutsPackageHierarchyWalker(com.intellij.struts2.dom.struts.strutspackage.StrutsPackageHierarchyWalker) GenericAttributeValue(com.intellij.util.xml.GenericAttributeValue) StrutsPackageHierarchyWalker(com.intellij.struts2.dom.struts.strutspackage.StrutsPackageHierarchyWalker) CachedValuesManager(com.intellij.psi.util.CachedValuesManager) CachedValueProvider(com.intellij.psi.util.CachedValueProvider) PsiModificationTracker(com.intellij.psi.util.PsiModificationTracker) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) BaseImpl(com.intellij.jam.model.common.BaseImpl) CachedValue(com.intellij.psi.util.CachedValue) ResultType(com.intellij.struts2.dom.struts.strutspackage.ResultType) DefaultClassRef(com.intellij.struts2.dom.struts.strutspackage.DefaultClassRef) Processor(com.intellij.util.Processor) PsiFile(com.intellij.psi.PsiFile) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) DomUtil(com.intellij.util.xml.DomUtil) DefaultClassRef(com.intellij.struts2.dom.struts.strutspackage.DefaultClassRef) Ref(com.intellij.openapi.util.Ref) PsiFile(com.intellij.psi.PsiFile) List(java.util.List) ResultType(com.intellij.struts2.dom.struts.strutspackage.ResultType) GenericAttributeValue(com.intellij.util.xml.GenericAttributeValue) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with ResultType

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

ResultType (com.intellij.struts2.dom.struts.strutspackage.ResultType)9 Nullable (org.jetbrains.annotations.Nullable)7 StrutsPackage (com.intellij.struts2.dom.struts.strutspackage.StrutsPackage)6 Processor (com.intellij.util.Processor)4 List (java.util.List)4 NotNull (org.jetbrains.annotations.NotNull)4 Ref (com.intellij.openapi.util.Ref)3 StrutsPackageHierarchyWalker (com.intellij.struts2.dom.struts.strutspackage.StrutsPackageHierarchyWalker)3 NonNls (org.jetbrains.annotations.NonNls)3 Comparing (com.intellij.openapi.util.Comparing)2 Condition (com.intellij.openapi.util.Condition)2 StringUtil (com.intellij.openapi.util.text.StringUtil)2 HasResultType (com.intellij.struts2.dom.struts.HasResultType)2 Action (com.intellij.struts2.dom.struts.action.Action)2 Result (com.intellij.struts2.dom.struts.action.Result)2 StrutsModel (com.intellij.struts2.dom.struts.model.StrutsModel)2 FtlType (com.intellij.freemarker.psi.FtlType)1 FtlFile (com.intellij.freemarker.psi.files.FtlFile)1 FtlGlobalVariableProvider (com.intellij.freemarker.psi.files.FtlGlobalVariableProvider)1 FtlXmlNamespaceType (com.intellij.freemarker.psi.files.FtlXmlNamespaceType)1