Search in sources :

Example 16 with MatchingHandler

use of com.intellij.structuralsearch.impl.matcher.handlers.MatchingHandler in project intellij-community by JetBrains.

the class XmlMatchingVisitor method visitXmlTag.

@Override
public void visitXmlTag(XmlTag tag) {
    final XmlTag another = (XmlTag) myMatchingVisitor.getElement();
    final boolean isTypedVar = myMatchingVisitor.getMatchContext().getPattern().isTypedVar(tag.getName());
    myMatchingVisitor.setResult((matches(tag.getName(), another.getName()) || isTypedVar) && myMatchingVisitor.matchInAnyOrder(tag.getAttributes(), another.getAttributes()));
    if (myMatchingVisitor.getResult()) {
        final XmlTagChild[] contentChildren = tag.getValue().getChildren();
        if (contentChildren.length > 0) {
            PsiElement[] patternNodes = contentChildren;
            PsiElement[] matchedNodes = another.getValue().getChildren();
            if (contentChildren.length != 1) {
                patternNodes = filterOutWhitespace(patternNodes);
                matchedNodes = filterOutWhitespace(matchedNodes);
            }
            final boolean result = myMatchingVisitor.matchSequentially(new ArrayBackedNodeIterator(patternNodes), new ArrayBackedNodeIterator(matchedNodes));
            myMatchingVisitor.setResult(result);
        }
    }
    if (myMatchingVisitor.getResult() && isTypedVar) {
        final PsiElement[] children = another.getChildren();
        if (children.length > 1) {
            MatchingHandler handler = myMatchingVisitor.getMatchContext().getPattern().getHandler(tag.getName());
            myMatchingVisitor.setResult(((SubstitutionHandler) handler).handle(children[1], myMatchingVisitor.getMatchContext()));
        }
    }
}
Also used : MatchingHandler(com.intellij.structuralsearch.impl.matcher.handlers.MatchingHandler) ArrayBackedNodeIterator(com.intellij.dupLocator.iterators.ArrayBackedNodeIterator) PsiElement(com.intellij.psi.PsiElement)

Example 17 with MatchingHandler

use of com.intellij.structuralsearch.impl.matcher.handlers.MatchingHandler in project intellij-community by JetBrains.

the class CompiledPattern method getHandler.

public MatchingHandler getHandler(PsiElement node) {
    if (node == last) {
        return lastHandler;
    }
    MatchingHandler handler = handlers.get(node);
    if (handler == null) {
        handler = new SimpleHandler();
        setHandler(node, handler);
    }
    last = node;
    lastHandler = handler;
    return handler;
}
Also used : MatchingHandler(com.intellij.structuralsearch.impl.matcher.handlers.MatchingHandler) SimpleHandler(com.intellij.structuralsearch.impl.matcher.handlers.SimpleHandler)

Example 18 with MatchingHandler

use of com.intellij.structuralsearch.impl.matcher.handlers.MatchingHandler in project intellij-community by JetBrains.

the class GlobalMatchingVisitor method handleTypedElement.

public final boolean handleTypedElement(final PsiElement typedElement, final PsiElement match) {
    MatchingHandler handler = matchContext.getPattern().getHandler(typedElement);
    final MatchingHandler initialHandler = handler;
    if (handler instanceof DelegatingHandler) {
        handler = ((DelegatingHandler) handler).getDelegate();
    }
    assert handler instanceof SubstitutionHandler : handler != null ? handler.getClass() : "null" + ' ' + (initialHandler != null ? initialHandler.getClass() : "null");
    return ((SubstitutionHandler) handler).handle(match, matchContext);
}
Also used : DelegatingHandler(com.intellij.structuralsearch.impl.matcher.handlers.DelegatingHandler) SubstitutionHandler(com.intellij.structuralsearch.impl.matcher.handlers.SubstitutionHandler) MatchingHandler(com.intellij.structuralsearch.impl.matcher.handlers.MatchingHandler)

Aggregations

MatchingHandler (com.intellij.structuralsearch.impl.matcher.handlers.MatchingHandler)18 SubstitutionHandler (com.intellij.structuralsearch.impl.matcher.handlers.SubstitutionHandler)8 ArrayBackedNodeIterator (com.intellij.dupLocator.iterators.ArrayBackedNodeIterator)3 TopLevelMatchingHandler (com.intellij.structuralsearch.impl.matcher.handlers.TopLevelMatchingHandler)3 NodeIterator (com.intellij.dupLocator.iterators.NodeIterator)2 PsiElement (com.intellij.psi.PsiElement)2 LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)1 LexicalNodesFilter (com.intellij.structuralsearch.impl.matcher.filters.LexicalNodesFilter)1 DelegatingHandler (com.intellij.structuralsearch.impl.matcher.handlers.DelegatingHandler)1 MatchPredicate (com.intellij.structuralsearch.impl.matcher.handlers.MatchPredicate)1 SimpleHandler (com.intellij.structuralsearch.impl.matcher.handlers.SimpleHandler)1 HierarchyNodeIterator (com.intellij.structuralsearch.impl.matcher.iterators.HierarchyNodeIterator)1 SsrFilteringNodeIterator (com.intellij.structuralsearch.impl.matcher.iterators.SsrFilteringNodeIterator)1 CollectingMatchResultSink (com.intellij.structuralsearch.plugin.util.CollectingMatchResultSink)1 NotNull (org.jetbrains.annotations.NotNull)1