Search in sources :

Example 1 with InterceptorOrStackBase

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

the class JamDefaultInterceptorRefTest method checkResolve.

private static void checkResolve(@NotNull final JamDefaultInterceptorRef jamDefaultInterceptorRef, @NotNull final String interceptorName) {
    final InterceptorOrStackBase interceptorOrStackBase = jamDefaultInterceptorRef.getValue().getValue();
    assertNotNull(interceptorOrStackBase);
    assertEquals(interceptorName, interceptorOrStackBase.getName().getStringValue());
}
Also used : InterceptorOrStackBase(com.intellij.struts2.dom.struts.strutspackage.InterceptorOrStackBase)

Example 2 with InterceptorOrStackBase

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

the class InterceptorRefResolveConverterImpl method fromString.

public InterceptorOrStackBase fromString(@Nullable @NonNls final String name, final ConvertContext context) {
    if (name == null) {
        return null;
    }
    final Condition<InterceptorOrStackBase> nameCondition = interceptorOrStackBase -> name.equals(interceptorOrStackBase.getName().getStringValue());
    final Ref<InterceptorOrStackBase> resolveResult = new Ref<>();
    final Processor<StrutsPackage> processor = strutsPackage -> {
        final InterceptorOrStackBase result = ContainerUtil.find(getAllInterceptors(strutsPackage), nameCondition);
        if (result != null) {
            resolveResult.set(result);
            return false;
        }
        return true;
    };
    final StrutsPackageHierarchyWalker walker = new StrutsPackageHierarchyWalker(ConverterUtil.getCurrentStrutsPackage(context), processor);
    walker.walkUp();
    return resolveResult.get();
}
Also used : Collection(java.util.Collection) NonNls(org.jetbrains.annotations.NonNls) InterceptorOrStackBase(com.intellij.struts2.dom.struts.strutspackage.InterceptorOrStackBase) ContainerUtil(com.intellij.util.containers.ContainerUtil) StrutsPackageHierarchyWalker(com.intellij.struts2.dom.struts.strutspackage.StrutsPackageHierarchyWalker) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) SmartList(com.intellij.util.SmartList) Processor(com.intellij.util.Processor) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage) ConverterUtil(com.intellij.struts2.dom.ConverterUtil) InterceptorRefResolveConverter(com.intellij.struts2.dom.struts.strutspackage.InterceptorRefResolveConverter) 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) Ref(com.intellij.openapi.util.Ref) InterceptorOrStackBase(com.intellij.struts2.dom.struts.strutspackage.InterceptorOrStackBase) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage)

Example 3 with InterceptorOrStackBase

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

the class InterceptorRefInStackParamNameCustomConverter method getCustomReferences.

@NotNull
@Override
public PsiReference[] getCustomReferences(final XmlAttributeValue nameAttributeValue, final DomElement paramsElement) {
    if (!(paramsElement instanceof InterceptorRef)) {
        return PsiReference.EMPTY_ARRAY;
    }
    InterceptorRef interceptorRef = (InterceptorRef) paramsElement;
    final InterceptorOrStackBase value = interceptorRef.getName().getValue();
    if (!(value instanceof InterceptorStack)) {
        return PsiReference.EMPTY_ARRAY;
    }
    final String text = nameAttributeValue.getValue();
    final boolean hasDot = StringUtil.containsChar(text, '.');
    final int idx = hasDot ? text.indexOf('.') : text.length();
    final String refName = text.substring(0, idx);
    final InterceptorStack stack = (InterceptorStack) value;
    final InterceptorRef resolvedInterceptorRef = ContainerUtil.find(stack.getInterceptorRefs(), ref -> Comparing.strEqual(refName, ref.getName().getStringValue()));
    final List<PsiReference> customReferences = new ArrayList<>(2);
    customReferences.add(new InterceptorRefPsiReference(nameAttributeValue, TextRange.from(1, idx), resolvedInterceptorRef, stack));
    if (resolvedInterceptorRef == null) {
        return ArrayUtil.toObjectArray(customReferences, PsiReference.class);
    }
    final String propertyText = text.substring(idx + 1, text.length());
    final PsiClass paramsClass = resolvedInterceptorRef.getParamsClass();
    final BeanPropertyPathReferenceSet beanPropertyPathReferenceSet = new BeanPropertyPathReferenceSet(propertyText, nameAttributeValue, idx + 2, '.', paramsClass, false);
    Collections.addAll(customReferences, beanPropertyPathReferenceSet.getPsiReferences());
    return ArrayUtil.toObjectArray(customReferences, PsiReference.class);
}
Also used : InterceptorOrStackBase(com.intellij.struts2.dom.struts.strutspackage.InterceptorOrStackBase) InterceptorStack(com.intellij.struts2.dom.struts.strutspackage.InterceptorStack) ArrayList(java.util.ArrayList) PsiClass(com.intellij.psi.PsiClass) PsiReference(com.intellij.psi.PsiReference) InterceptorRef(com.intellij.struts2.dom.struts.strutspackage.InterceptorRef) BeanPropertyPathReferenceSet(com.intellij.struts2.reference.common.BeanPropertyPathReferenceSet) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with InterceptorOrStackBase

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

the class InterceptorRefResolveConverterImpl method getVariants.

@NotNull
public Collection<? extends InterceptorOrStackBase> getVariants(final ConvertContext context) {
    final List<InterceptorOrStackBase> results = new SmartList<>();
    final Processor<StrutsPackage> processor = strutsPackage -> {
        final List<InterceptorOrStackBase> allInterceptors = getAllInterceptors(strutsPackage);
        results.addAll(allInterceptors);
        return true;
    };
    final StrutsPackageHierarchyWalker walker = new StrutsPackageHierarchyWalker(ConverterUtil.getCurrentStrutsPackage(context), processor);
    walker.walkUp();
    return results;
}
Also used : Collection(java.util.Collection) NonNls(org.jetbrains.annotations.NonNls) InterceptorOrStackBase(com.intellij.struts2.dom.struts.strutspackage.InterceptorOrStackBase) ContainerUtil(com.intellij.util.containers.ContainerUtil) StrutsPackageHierarchyWalker(com.intellij.struts2.dom.struts.strutspackage.StrutsPackageHierarchyWalker) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) SmartList(com.intellij.util.SmartList) Processor(com.intellij.util.Processor) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage) ConverterUtil(com.intellij.struts2.dom.ConverterUtil) InterceptorRefResolveConverter(com.intellij.struts2.dom.struts.strutspackage.InterceptorRefResolveConverter) 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) InterceptorOrStackBase(com.intellij.struts2.dom.struts.strutspackage.InterceptorOrStackBase) List(java.util.List) SmartList(com.intellij.util.SmartList) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage) SmartList(com.intellij.util.SmartList) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with InterceptorOrStackBase

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

InterceptorOrStackBase (com.intellij.struts2.dom.struts.strutspackage.InterceptorOrStackBase)6 NotNull (org.jetbrains.annotations.NotNull)4 StrutsPackage (com.intellij.struts2.dom.struts.strutspackage.StrutsPackage)3 Condition (com.intellij.openapi.util.Condition)2 Ref (com.intellij.openapi.util.Ref)2 ConverterUtil (com.intellij.struts2.dom.ConverterUtil)2 InterceptorRefResolveConverter (com.intellij.struts2.dom.struts.strutspackage.InterceptorRefResolveConverter)2 InterceptorStack (com.intellij.struts2.dom.struts.strutspackage.InterceptorStack)2 StrutsPackageHierarchyWalker (com.intellij.struts2.dom.struts.strutspackage.StrutsPackageHierarchyWalker)2 Processor (com.intellij.util.Processor)2 SmartList (com.intellij.util.SmartList)2 ContainerUtil (com.intellij.util.containers.ContainerUtil)2 ConvertContext (com.intellij.util.xml.ConvertContext)2 Collection (java.util.Collection)2 List (java.util.List)2 NonNls (org.jetbrains.annotations.NonNls)2 Nullable (org.jetbrains.annotations.Nullable)2 PsiClass (com.intellij.psi.PsiClass)1 PsiReference (com.intellij.psi.PsiReference)1 Interceptor (com.intellij.struts2.dom.struts.strutspackage.Interceptor)1