Search in sources :

Example 1 with JavaDocMatchingStrategy

use of com.intellij.structuralsearch.impl.matcher.strategies.JavaDocMatchingStrategy in project intellij-community by JetBrains.

the class JavaCompilingVisitor method visitCodeBlock.

@Override
public void visitCodeBlock(PsiCodeBlock block) {
    myCompilingVisitor.setCodeBlockLevel(myCompilingVisitor.getCodeBlockLevel() + 1);
    MatchingStrategy strategy = null;
    for (PsiElement el = block.getFirstChild(); el != null; el = el.getNextSibling()) {
        if (GlobalCompilingVisitor.getFilter().accepts(el)) {
            if (el instanceof PsiWhiteSpace) {
                myCompilingVisitor.addLexicalNode(el);
            }
        } else {
            el.accept(this);
            if (myCompilingVisitor.getCodeBlockLevel() == 1) {
                MatchingStrategy newstrategy = findStrategy(el);
                final MatchingHandler matchingHandler = myCompilingVisitor.getContext().getPattern().getHandler(el);
                myCompilingVisitor.getContext().getPattern().setHandler(el, new TopLevelMatchingHandler(matchingHandler));
                if (strategy == null || (strategy instanceof JavaDocMatchingStrategy)) {
                    strategy = newstrategy;
                } else {
                    if (strategy.getClass() != newstrategy.getClass()) {
                        if (!(strategy instanceof CommentMatchingStrategy)) {
                            throw new UnsupportedPatternException(SSRBundle.message("different.strategies.for.top.level.nodes.error.message"));
                        }
                        strategy = newstrategy;
                    }
                }
            }
        }
    }
    if (myCompilingVisitor.getCodeBlockLevel() == 1) {
        if (strategy == null) {
            // this should happen only for error patterns
            strategy = ExprMatchingStrategy.getInstance();
        }
        myCompilingVisitor.getContext().getPattern().setStrategy(strategy);
    }
    myCompilingVisitor.setCodeBlockLevel(myCompilingVisitor.getCodeBlockLevel() - 1);
}
Also used : UnsupportedPatternException(com.intellij.structuralsearch.UnsupportedPatternException) JavaDocMatchingStrategy(com.intellij.structuralsearch.impl.matcher.strategies.JavaDocMatchingStrategy) CommentMatchingStrategy(com.intellij.structuralsearch.impl.matcher.strategies.CommentMatchingStrategy) ExprMatchingStrategy(com.intellij.structuralsearch.impl.matcher.strategies.ExprMatchingStrategy) JavaDocMatchingStrategy(com.intellij.structuralsearch.impl.matcher.strategies.JavaDocMatchingStrategy) MatchingStrategy(com.intellij.structuralsearch.impl.matcher.strategies.MatchingStrategy) CommentMatchingStrategy(com.intellij.structuralsearch.impl.matcher.strategies.CommentMatchingStrategy)

Aggregations

UnsupportedPatternException (com.intellij.structuralsearch.UnsupportedPatternException)1 CommentMatchingStrategy (com.intellij.structuralsearch.impl.matcher.strategies.CommentMatchingStrategy)1 ExprMatchingStrategy (com.intellij.structuralsearch.impl.matcher.strategies.ExprMatchingStrategy)1 JavaDocMatchingStrategy (com.intellij.structuralsearch.impl.matcher.strategies.JavaDocMatchingStrategy)1 MatchingStrategy (com.intellij.structuralsearch.impl.matcher.strategies.MatchingStrategy)1