Search in sources :

Example 16 with StrutsPackage

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

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

the class StrutsPackageImpl method searchDefaultClassRef.

@Nullable
public DefaultClassRef searchDefaultClassRef() {
    final Ref<DefaultClassRef> result = new Ref<>();
    final StrutsPackageHierarchyWalker walker = new StrutsPackageHierarchyWalker(this, strutsPackage -> {
        if (DomUtil.hasXml(strutsPackage.getDefaultClassRef())) {
            result.set(strutsPackage.getDefaultClassRef());
            return false;
        }
        return true;
    });
    walker.walkUp();
    return result.get();
}
Also used : StrutsPackageHierarchyWalker(com.intellij.struts2.dom.struts.strutspackage.StrutsPackageHierarchyWalker) DefaultClassRef(com.intellij.struts2.dom.struts.strutspackage.DefaultClassRef) Ref(com.intellij.openapi.util.Ref) DefaultClassRef(com.intellij.struts2.dom.struts.strutspackage.DefaultClassRef) Nullable(org.jetbrains.annotations.Nullable)

Example 18 with StrutsPackage

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

Example 19 with StrutsPackage

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

the class StrutsModelImpl method getAllInterceptorsAndStacks.

@NotNull
public Set<InterceptorOrStackBase> getAllInterceptorsAndStacks() {
    final Set<InterceptorOrStackBase> interceptorOrStackBases = new HashSet<>();
    for (final StrutsPackage strutsPackage : getStrutsPackages()) {
        final List<InterceptorStack> interceptorList = strutsPackage.getInterceptorStacks();
        interceptorOrStackBases.addAll(interceptorList);
        final List<Interceptor> interceptors = strutsPackage.getInterceptors();
        interceptorOrStackBases.addAll(interceptors);
    }
    return interceptorOrStackBases;
}
Also used : InterceptorOrStackBase(com.intellij.struts2.dom.struts.strutspackage.InterceptorOrStackBase) InterceptorStack(com.intellij.struts2.dom.struts.strutspackage.InterceptorStack) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage) Interceptor(com.intellij.struts2.dom.struts.strutspackage.Interceptor) HashSet(java.util.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

StrutsPackage (com.intellij.struts2.dom.struts.strutspackage.StrutsPackage)17 Nullable (org.jetbrains.annotations.Nullable)11 NotNull (org.jetbrains.annotations.NotNull)10 Ref (com.intellij.openapi.util.Ref)9 StrutsPackageHierarchyWalker (com.intellij.struts2.dom.struts.strutspackage.StrutsPackageHierarchyWalker)9 Processor (com.intellij.util.Processor)7 List (java.util.List)7 Condition (com.intellij.openapi.util.Condition)6 ResultType (com.intellij.struts2.dom.struts.strutspackage.ResultType)6 SmartList (com.intellij.util.SmartList)6 ContainerUtil (com.intellij.util.containers.ContainerUtil)6 ConvertContext (com.intellij.util.xml.ConvertContext)6 Collection (java.util.Collection)6 NonNls (org.jetbrains.annotations.NonNls)6 ConverterUtil (com.intellij.struts2.dom.ConverterUtil)4 StrutsModel (com.intellij.struts2.dom.struts.model.StrutsModel)3 DefaultClassRef (com.intellij.struts2.dom.struts.strutspackage.DefaultClassRef)3 InterceptorOrStackBase (com.intellij.struts2.dom.struts.strutspackage.InterceptorOrStackBase)3 InterceptorStack (com.intellij.struts2.dom.struts.strutspackage.InterceptorStack)3 DomUtil (com.intellij.util.xml.DomUtil)3