Search in sources :

Example 1 with NodeIterator

use of com.intellij.dupLocator.iterators.NodeIterator in project intellij-community by JetBrains.

the class StructuralSearchProfileBase method checkReplacementPattern.

@Override
public void checkReplacementPattern(Project project, ReplaceOptions options) {
    final CompiledPattern compiledPattern = PatternCompiler.compilePattern(project, options.getMatchOptions());
    if (compiledPattern == null) {
        return;
    }
    final NodeIterator it = compiledPattern.getNodes();
    if (!it.hasNext()) {
        return;
    }
    final PsiElement root = it.current().getParent();
    if (!checkOptionalChildren(root) || !checkErrorElements(root)) {
        throw new UnsupportedPatternException(": Partial and expression patterns are not supported");
    }
}
Also used : FilteringNodeIterator(com.intellij.dupLocator.iterators.FilteringNodeIterator) NodeIterator(com.intellij.dupLocator.iterators.NodeIterator) SsrFilteringNodeIterator(com.intellij.structuralsearch.impl.matcher.iterators.SsrFilteringNodeIterator) CompiledPattern(com.intellij.structuralsearch.impl.matcher.CompiledPattern)

Example 2 with NodeIterator

use of com.intellij.dupLocator.iterators.NodeIterator in project intellij-community by JetBrains.

the class GlobalMatchingVisitor method matchContext.

/**
   * Descents the tree in depth finding matches
   *
   * @param elements the element for which the sons are looked for match
   */
public void matchContext(final NodeIterator elements) {
    if (matchContext == null) {
        return;
    }
    final CompiledPattern pattern = matchContext.getPattern();
    final NodeIterator patternNodes = pattern.getNodes().clone();
    final MatchResultImpl saveResult = matchContext.hasResult() ? matchContext.getResult() : null;
    final List<PsiElement> saveMatchedNodes = matchContext.getMatchedNodes();
    try {
        matchContext.setResult(null);
        matchContext.setMatchedNodes(null);
        if (!patternNodes.hasNext())
            return;
        final MatchingHandler firstMatchingHandler = pattern.getHandler(patternNodes.current());
        for (; elements.hasNext(); elements.advance()) {
            final PsiElement elementNode = elements.current();
            boolean matched = firstMatchingHandler.matchSequentially(patternNodes, elements, matchContext);
            if (matched) {
                MatchingHandler matchingHandler = matchContext.getPattern().getHandler(Configuration.CONTEXT_VAR_NAME);
                if (matchingHandler != null) {
                    matched = ((SubstitutionHandler) matchingHandler).handle(elementNode, matchContext);
                }
            }
            final List<PsiElement> matchedNodes = matchContext.getMatchedNodes();
            if (matched) {
                dispatchMatched(matchedNodes, matchContext.getResult());
            }
            matchContext.setMatchedNodes(null);
            matchContext.setResult(null);
            patternNodes.reset();
            if (matchedNodes != null && matchedNodes.size() > 0 && matched) {
                elements.rewind();
            }
        }
    } finally {
        matchContext.setResult(saveResult);
        matchContext.setMatchedNodes(saveMatchedNodes);
    }
}
Also used : NodeIterator(com.intellij.dupLocator.iterators.NodeIterator) MatchingHandler(com.intellij.structuralsearch.impl.matcher.handlers.MatchingHandler) PsiElement(com.intellij.psi.PsiElement)

Example 3 with NodeIterator

use of com.intellij.dupLocator.iterators.NodeIterator in project intellij-community by JetBrains.

the class JavaCompilingVisitor method visitDocTag.

@Override
public void visitDocTag(PsiDocTag psiDocTag) {
    super.visitDocTag(psiDocTag);
    NodeIterator sons = new DocValuesIterator(psiDocTag.getFirstChild());
    while (sons.hasNext()) {
        myCompilingVisitor.setHandler(sons.current(), new DocDataHandler());
        sons.advance();
    }
}
Also used : NodeIterator(com.intellij.dupLocator.iterators.NodeIterator) DocValuesIterator(com.intellij.structuralsearch.impl.matcher.iterators.DocValuesIterator)

Example 4 with NodeIterator

use of com.intellij.dupLocator.iterators.NodeIterator in project intellij-community by JetBrains.

the class JavaStructuralSearchProfile method checkSearchPattern.

@Override
public void checkSearchPattern(Project project, MatchOptions options) {
    ValidatingVisitor visitor = new ValidatingVisitor();
    final CompiledPattern compiledPattern = PatternCompiler.compilePattern(project, options);
    final int nodeCount = compiledPattern.getNodeCount();
    final NodeIterator nodes = compiledPattern.getNodes();
    while (nodes.hasNext()) {
        final PsiElement current = nodes.current();
        visitor.setCurrent((nodeCount == 1 && (current instanceof PsiExpressionStatement || current instanceof PsiDeclarationStatement)) ? current : null);
        current.accept(visitor);
        nodes.advance();
    }
    nodes.reset();
}
Also used : NodeIterator(com.intellij.dupLocator.iterators.NodeIterator)

Example 5 with NodeIterator

use of com.intellij.dupLocator.iterators.NodeIterator in project intellij-community by JetBrains.

the class JavaMatchingVisitor method checkMatchWithinHierarchy.

private boolean checkMatchWithinHierarchy(PsiElement el2, SubstitutionHandler handler, PsiElement context) {
    boolean includeInterfaces = true;
    boolean includeClasses = true;
    final PsiElement contextParent = context.getParent();
    if (contextParent instanceof PsiReferenceList) {
        final PsiElement grandParentContext = contextParent.getParent();
        if (grandParentContext instanceof PsiClass) {
            final PsiClass psiClass = (PsiClass) grandParentContext;
            if (contextParent == psiClass.getExtendsList()) {
                includeInterfaces = psiClass.isInterface();
            } else if (contextParent == psiClass.getImplementsList()) {
                includeClasses = false;
            }
        }
    }
    // is type2 is (strict) subtype of type
    final NodeIterator node = new HierarchyNodeIterator(el2, includeClasses, includeInterfaces);
    if (handler.isStrictSubtype()) {
        node.advance();
    }
    final boolean notPredicate = handler.getPredicate() instanceof NotPredicate;
    while (node.hasNext() && !handler.validate(node.current(), 0, -1, myMatchingVisitor.getMatchContext())) {
        if (notPredicate)
            return false;
        node.advance();
    }
    if (node.hasNext()) {
        handler.addResult(el2, 0, -1, myMatchingVisitor.getMatchContext());
        return true;
    } else {
        return false;
    }
}
Also used : NodeIterator(com.intellij.dupLocator.iterators.NodeIterator) ArrayBackedNodeIterator(com.intellij.dupLocator.iterators.ArrayBackedNodeIterator) HierarchyNodeIterator(com.intellij.structuralsearch.impl.matcher.iterators.HierarchyNodeIterator) HierarchyNodeIterator(com.intellij.structuralsearch.impl.matcher.iterators.HierarchyNodeIterator) NotPredicate(com.intellij.structuralsearch.impl.matcher.predicates.NotPredicate)

Aggregations

NodeIterator (com.intellij.dupLocator.iterators.NodeIterator)6 ArrayBackedNodeIterator (com.intellij.dupLocator.iterators.ArrayBackedNodeIterator)2 MatchingHandler (com.intellij.structuralsearch.impl.matcher.handlers.MatchingHandler)2 SsrFilteringNodeIterator (com.intellij.structuralsearch.impl.matcher.iterators.SsrFilteringNodeIterator)2 FilteringNodeIterator (com.intellij.dupLocator.iterators.FilteringNodeIterator)1 PsiElement (com.intellij.psi.PsiElement)1 CompiledPattern (com.intellij.structuralsearch.impl.matcher.CompiledPattern)1 TopLevelMatchingHandler (com.intellij.structuralsearch.impl.matcher.handlers.TopLevelMatchingHandler)1 DocValuesIterator (com.intellij.structuralsearch.impl.matcher.iterators.DocValuesIterator)1 HierarchyNodeIterator (com.intellij.structuralsearch.impl.matcher.iterators.HierarchyNodeIterator)1 NotPredicate (com.intellij.structuralsearch.impl.matcher.predicates.NotPredicate)1