Search in sources :

Example 1 with NotPredicate

use of com.intellij.structuralsearch.impl.matcher.predicates.NotPredicate 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)

Example 2 with NotPredicate

use of com.intellij.structuralsearch.impl.matcher.predicates.NotPredicate in project intellij-community by JetBrains.

the class MatchingHandler method findRegExpPredicate.

private static MatchPredicate findRegExpPredicate(MatchPredicate start) {
    if (start == null)
        return null;
    if (start instanceof RegExpPredicate)
        return start;
    if (start instanceof BinaryPredicate) {
        BinaryPredicate binary = (BinaryPredicate) start;
        final MatchPredicate result = findRegExpPredicate(binary.getFirst());
        if (result != null)
            return result;
        return findRegExpPredicate(binary.getSecond());
    } else if (start instanceof NotPredicate) {
        return null;
    }
    return null;
}
Also used : RegExpPredicate(com.intellij.structuralsearch.impl.matcher.predicates.RegExpPredicate) BinaryPredicate(com.intellij.structuralsearch.impl.matcher.predicates.BinaryPredicate) NotPredicate(com.intellij.structuralsearch.impl.matcher.predicates.NotPredicate)

Aggregations

NotPredicate (com.intellij.structuralsearch.impl.matcher.predicates.NotPredicate)2 ArrayBackedNodeIterator (com.intellij.dupLocator.iterators.ArrayBackedNodeIterator)1 NodeIterator (com.intellij.dupLocator.iterators.NodeIterator)1 HierarchyNodeIterator (com.intellij.structuralsearch.impl.matcher.iterators.HierarchyNodeIterator)1 BinaryPredicate (com.intellij.structuralsearch.impl.matcher.predicates.BinaryPredicate)1 RegExpPredicate (com.intellij.structuralsearch.impl.matcher.predicates.RegExpPredicate)1