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");
}
}
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);
}
}
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();
}
}
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();
}
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;
}
}
Aggregations