use of com.intellij.structuralsearch.MatchResult 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);
}
}
}
use of com.intellij.structuralsearch.MatchResult in project intellij-community by JetBrains.
the class ScriptSupport method buildVariableMap.
private static Map<String, Object> buildVariableMap(@NotNull MatchResult result, @NotNull Map<String, Object> out) {
final String name = result.getName();
if (name != null && !result.isMultipleMatch()) {
final Object value = out.get(name);
final PsiElement match = StructuralSearchUtil.getPresentableElement(result.getMatch());
if (value == null) {
out.put(name, match);
} else if (value instanceof List) {
@SuppressWarnings("unchecked") final List<PsiElement> list = (List<PsiElement>) value;
list.add(match);
} else if (value instanceof PsiElement) {
final List<PsiElement> list = new ArrayList<>();
list.add((PsiElement) value);
list.add(match);
out.put(name, list);
} else {
throw new AssertionError();
}
}
if (result.hasSons()) {
for (MatchResult son : result.getAllSons()) {
buildVariableMap(son, out);
}
}
return out;
}
Aggregations