use of com.intellij.structuralsearch.Matcher 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.Matcher in project intellij-community by JetBrains.
the class SSBasedInspection method buildVisitor.
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
final Map<Configuration, MatchContext> compiledOptions = SSBasedInspectionCompiledPatternsCache.getCompiledOptions(myConfigurations, holder.getProject());
if (compiledOptions.isEmpty())
return super.buildVisitor(holder, isOnTheFly);
return new PsiElementVisitor() {
final Matcher matcher = new Matcher(holder.getManager().getProject());
final PairProcessor<MatchResult, Configuration> processor = (matchResult, configuration) -> {
PsiElement element = matchResult.getMatch();
String name = configuration.getName();
LocalQuickFix fix = createQuickFix(holder.getManager().getProject(), matchResult, configuration);
holder.registerProblem(holder.getManager().createProblemDescriptor(element, name, fix, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly));
return true;
};
@Override
public void visitElement(PsiElement element) {
synchronized (LOCK) {
if (LexicalNodesFilter.getInstance().accepts(element))
return;
final SsrFilteringNodeIterator matchedNodes = new SsrFilteringNodeIterator(element);
for (Map.Entry<Configuration, MatchContext> entry : compiledOptions.entrySet()) {
Configuration configuration = entry.getKey();
MatchContext context = entry.getValue();
if (MatcherImpl.checkIfShouldAttemptToMatch(context, matchedNodes)) {
final int nodeCount = context.getPattern().getNodeCount();
try {
matcher.processMatchesInElement(context, configuration, new CountingNodeIterator(nodeCount, matchedNodes), processor);
} catch (StructuralSearchException e) {
if (myProblemsReported.add(configuration.getName())) {
// don't overwhelm the user with messages
Notifications.Bus.notify(new Notification(SSRBundle.message("structural.search.title"), SSRBundle.message("template.problem", configuration.getName()), e.getMessage(), NotificationType.ERROR), element.getProject());
}
}
matchedNodes.reset();
}
}
}
}
};
}
use of com.intellij.structuralsearch.Matcher in project intellij-community by JetBrains.
the class SSBasedInspectionCompiledPatternsCache method getCompiledOptions.
@NotNull
static Map<Configuration, MatchContext> getCompiledOptions(@NotNull List<Configuration> configurations, @NotNull Project project) {
final Map<Configuration, MatchContext> cache = ObjectUtils.notNull(project.getUserData(COMPILED_OPTIONS_KEY), new HashMap<Configuration, MatchContext>());
if (!areConfigurationsInCache(configurations, cache)) {
final Matcher matcher = new Matcher(project);
matcher.precompileOptions(configurations, cache);
project.putUserData(COMPILED_OPTIONS_KEY, cache);
}
return configurations.stream().collect(Collectors.toMap(Function.identity(), cache::get, (c1, c2) -> c2));
}
Aggregations