Search in sources :

Example 1 with SmartPsiPointer

use of com.intellij.structuralsearch.plugin.util.SmartPsiPointer in project intellij-community by JetBrains.

the class GlobalMatchingVisitor method processNoSubstitutionMatch.

private static void processNoSubstitutionMatch(List<PsiElement> matchedNodes, MatchResultImpl result) {
    boolean complexMatch = matchedNodes.size() > 1;
    final PsiElement match = matchedNodes.get(0);
    if (!complexMatch) {
        result.setMatchRef(new SmartPsiPointer(match));
        result.setMatchImage(match.getText());
    } else {
        for (final PsiElement matchStatement : matchedNodes) {
            result.getMatches().add(new MatchResultImpl(MatchResult.LINE_MATCH, matchStatement.getText(), new SmartPsiPointer(matchStatement), true));
        }
        result.setMatchRef(new SmartPsiPointer(match));
        result.setMatchImage(match.getText());
        result.setName(MatchResult.MULTI_LINE_MATCH);
    }
}
Also used : SmartPsiPointer(com.intellij.structuralsearch.plugin.util.SmartPsiPointer) PsiElement(com.intellij.psi.PsiElement)

Example 2 with SmartPsiPointer

use of com.intellij.structuralsearch.plugin.util.SmartPsiPointer in project intellij-community by JetBrains.

the class SubstitutionHandler method createMatch.

private MatchResultImpl createMatch(final PsiElement match, int start, int end) {
    final String image = match == null ? null : StructuralSearchUtil.getProfileByPsiElement(match).getText(match, start, end);
    final SmartPsiPointer ref = new SmartPsiPointer(match);
    final MatchResultImpl result = myNestedResult == null ? new MatchResultImpl(name, image, ref, start, end, target) : myNestedResult;
    if (myNestedResult != null) {
        myNestedResult.setName(name);
        myNestedResult.setMatchImage(image);
        myNestedResult.setMatchRef(ref);
        myNestedResult.setStart(start);
        myNestedResult.setEnd(end);
        myNestedResult.setTarget(target);
        myNestedResult = null;
    }
    return result;
}
Also used : SmartPsiPointer(com.intellij.structuralsearch.plugin.util.SmartPsiPointer) MatchResultImpl(com.intellij.structuralsearch.impl.matcher.MatchResultImpl)

Example 3 with SmartPsiPointer

use of com.intellij.structuralsearch.plugin.util.SmartPsiPointer 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

SmartPsiPointer (com.intellij.structuralsearch.plugin.util.SmartPsiPointer)3 MatchResultImpl (com.intellij.structuralsearch.impl.matcher.MatchResultImpl)2 PsiElement (com.intellij.psi.PsiElement)1 MatchResult (com.intellij.structuralsearch.MatchResult)1