use of com.intellij.structuralsearch.MatchResult in project intellij-community by JetBrains.
the class SubstitutionHandler method removeLastResults.
private void removeLastResults(int numberOfResults, MatchContext context) {
if (numberOfResults == 0)
return;
final MatchResultImpl substitution = context.getResult().findSon(name);
if (substitution != null) {
final List<PsiElement> matchedNodes = context.getMatchedNodes();
if (substitution.hasSons()) {
final List<MatchResult> sons = substitution.getMatches();
while (numberOfResults > 0) {
--numberOfResults;
final MatchResult matchResult = sons.remove(sons.size() - 1);
if (matchedNodes != null)
matchedNodes.remove(matchResult.getMatch());
}
if (sons.isEmpty()) {
context.getResult().removeSon(name);
}
} else {
final MatchResultImpl matchResult = context.getResult().removeSon(name);
if (matchedNodes != null)
matchedNodes.remove(matchResult.getMatch());
}
}
}
use of com.intellij.structuralsearch.MatchResult in project intellij-community by JetBrains.
the class ReplacementBuilder method process.
String process(MatchResult match, ReplacementInfoImpl replacementInfo, FileType type) {
if (parameterizations == null) {
return replacement;
}
final StringBuilder result = new StringBuilder(replacement);
final HashMap<String, MatchResult> matchMap = new HashMap<>();
fill(match, matchMap);
final StructuralSearchProfile profile = StructuralSearchUtil.getProfileByFileType(type);
assert profile != null;
int offset = 0;
for (final ParameterInfo info : parameterizations) {
MatchResult r = matchMap.get(info.getName());
if (info.isReplacementVariable()) {
offset = Replacer.insertSubstitution(result, offset, info, generateReplacement(info, match));
} else if (r != null) {
offset = profile.handleSubstitution(info, r, result, offset, matchMap);
} else {
offset = profile.handleNoSubstitution(info, offset, result);
}
}
replacementInfo.variableMap = matchMap;
return result.toString();
}
use of com.intellij.structuralsearch.MatchResult in project intellij-community by JetBrains.
the class MatchResultImpl method clear.
public void clear() {
if (matchRef != null) {
matchRef.clear();
matchRef = null;
}
if (matches != null) {
for (final MatchResult match : matches) {
((MatchResultImpl) match).clear();
}
matches = null;
}
name = null;
matchImage = null;
}
use of com.intellij.structuralsearch.MatchResult in project intellij-community by JetBrains.
the class GuavaOptionalConversionUtil method simplifyParameterPattern.
static String simplifyParameterPattern(PsiMethodCallExpression methodCall) {
final PsiExpressionList argumentList = methodCall.getArgumentList();
final PsiExpression[] expressions = argumentList.getExpressions();
if (expressions.length == 1) {
final PsiExpression expression = expressions[0];
Matcher matcher = new Matcher(methodCall.getProject());
final MatchOptions options = new MatchOptions();
options.setFileType(StdFileTypes.JAVA);
final List<MatchResult> results = matcher.testFindMatches(expression.getText(), GuavaOptionalConversionRule.OPTIONAL_CONVERTOR_PATTERN, options, false);
if (!results.isEmpty()) {
final MatchResult result = results.get(0);
if (result.getStart() == 0 && result.getEnd() == -1) {
return GuavaOptionalConversionRule.OPTIONAL_CONVERTOR_PATTERN;
}
}
}
return "$o$";
}
use of com.intellij.structuralsearch.MatchResult in project intellij-community by JetBrains.
the class ReplacementContext method getNewName2PatternNameMap.
public Map<String, String> getNewName2PatternNameMap() {
Map<String, String> newNameToSearchPatternNameMap = new HashMap<>(1);
final Map<String, MatchResult> variableMap = replacementInfo.getVariableMap();
if (variableMap != null) {
for (String s : variableMap.keySet()) {
final MatchResult matchResult = replacementInfo.getVariableMap().get(s);
PsiElement match = matchResult.getMatch();
match = StructuralSearchUtil.getParentIfIdentifier(match);
if (match instanceof PsiNamedElement) {
final String name = ((PsiNamedElement) match).getName();
newNameToSearchPatternNameMap.put(name, s);
}
}
}
return newNameToSearchPatternNameMap;
}
Aggregations