Search in sources :

Example 6 with StrutsPackageHierarchyWalker

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

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

the class StrutsPackageImpl method searchNamespace.

@NotNull
public String searchNamespace() {
    final Ref<String> result = new Ref<>();
    final StrutsPackageHierarchyWalker walker = new StrutsPackageHierarchyWalker(this, strutsPackage -> {
        if (DomUtil.hasXml(strutsPackage.getNamespace())) {
            result.set(strutsPackage.getNamespace().getStringValue());
            return false;
        }
        return true;
    });
    walker.walkUp();
    return result.isNull() ? DEFAULT_NAMESPACE : 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) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with StrutsPackageHierarchyWalker

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

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

Aggregations

Ref (com.intellij.openapi.util.Ref)9 StrutsPackageHierarchyWalker (com.intellij.struts2.dom.struts.strutspackage.StrutsPackageHierarchyWalker)9 NotNull (org.jetbrains.annotations.NotNull)8 Nullable (org.jetbrains.annotations.Nullable)8 StrutsPackage (com.intellij.struts2.dom.struts.strutspackage.StrutsPackage)7 Processor (com.intellij.util.Processor)7 List (java.util.List)7 Condition (com.intellij.openapi.util.Condition)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 DefaultClassRef (com.intellij.struts2.dom.struts.strutspackage.DefaultClassRef)3 ResultType (com.intellij.struts2.dom.struts.strutspackage.ResultType)3 DomUtil (com.intellij.util.xml.DomUtil)3 Comparing (com.intellij.openapi.util.Comparing)2 StringUtil (com.intellij.openapi.util.text.StringUtil)2 ResultTypeResolvingConverter (com.intellij.struts2.dom.struts.action.ResultTypeResolvingConverter)2