Search in sources :

Example 6 with MatchResultImpl

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

the class SubstitutionHandler method addResult.

public void addResult(PsiElement match, int start, int end, MatchContext context) {
    if (totalMatchedOccurs == -1) {
        final MatchResultImpl matchResult = context.getResult();
        final MatchResultImpl substitution = matchResult.findSon(name);
        if (substitution == null) {
            matchResult.addSon(createMatch(match, start, end));
        } else if (maxOccurs > 1) {
            final MatchResultImpl result = createMatch(match, start, end);
            if (!substitution.isMultipleMatch()) {
                // adding intermediate node to contain all multiple matches
                final MatchResultImpl sonresult = new MatchResultImpl(substitution.getName(), substitution.getMatchImage(), substitution.getMatchRef(), substitution.getStart(), substitution.getEnd(), target);
                substitution.setMatchRef(new SmartPsiPointer(match == null ? null : match));
                substitution.setMultipleMatch(true);
                if (substitution.isScopeMatch()) {
                    substitution.setScopeMatch(false);
                    sonresult.setScopeMatch(true);
                    for (MatchResult r : substitution.getAllSons()) sonresult.addSon((MatchResultImpl) r);
                    substitution.clearMatches();
                }
                substitution.addSon(sonresult);
            }
            substitution.addSon(result);
        }
    }
}
Also used : MatchResultImpl(com.intellij.structuralsearch.impl.matcher.MatchResultImpl) SmartPsiPointer(com.intellij.structuralsearch.plugin.util.SmartPsiPointer) MatchResult(com.intellij.structuralsearch.MatchResult)

Aggregations

MatchResultImpl (com.intellij.structuralsearch.impl.matcher.MatchResultImpl)6 PsiElement (com.intellij.psi.PsiElement)3 MatchResult (com.intellij.structuralsearch.MatchResult)2 CompiledPattern (com.intellij.structuralsearch.impl.matcher.CompiledPattern)2 SmartPsiPointer (com.intellij.structuralsearch.plugin.util.SmartPsiPointer)2 HashSet (java.util.HashSet)2 FindProgressIndicator (com.intellij.find.FindProgressIndicator)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 UsageInfo (com.intellij.usageView.UsageInfo)1 Alarm (com.intellij.util.Alarm)1