use of com.intellij.structuralsearch.plugin.util.DuplicateFilteringResultSink in project intellij-community by JetBrains.
the class MatcherImpl method prepareMatching.
private CompiledPattern prepareMatching(final MatchResultSink sink, final MatchOptions options) {
CompiledPattern savedPattern = null;
if (matchContext.getOptions() == options && matchContext.getPattern() != null && matchContext.getOptions().hashCode() == matchContext.getPattern().getOptionsHashStamp()) {
savedPattern = matchContext.getPattern();
}
matchContext.clear();
matchContext.setSink(new DuplicateFilteringResultSink(sink));
matchContext.setOptions(options);
matchContext.setMatcher(visitor);
visitor.setMatchContext(matchContext);
CompiledPattern compiledPattern = savedPattern;
if (compiledPattern == null) {
synchronized (lastMatchDataLock) {
final LastMatchData data = com.intellij.reference.SoftReference.dereference(lastMatchData);
if (data != null && options == data.lastOptions) {
compiledPattern = data.lastPattern;
}
lastMatchData = null;
}
if (compiledPattern == null) {
compiledPattern = ApplicationManager.getApplication().runReadAction(new Computable<CompiledPattern>() {
@Override
public CompiledPattern compute() {
return PatternCompiler.compilePattern(project, options);
}
});
}
}
cacheCompiledPattern(options, compiledPattern);
return compiledPattern;
}
use of com.intellij.structuralsearch.plugin.util.DuplicateFilteringResultSink in project intellij-community by JetBrains.
the class MatcherImpl method configureOptions.
private void configureOptions(MatchContext context, final Configuration configuration, PsiElement psiFile, final PairProcessor<MatchResult, Configuration> processor) {
if (psiFile == null)
return;
LocalSearchScope scope = new LocalSearchScope(psiFile);
matchContext.clear();
matchContext.setMatcher(visitor);
MatchOptions options = context.getOptions();
matchContext.setOptions(options);
matchContext.setPattern(context.getPattern());
matchContext.setShouldRecursivelyMatch(context.shouldRecursivelyMatch());
visitor.setMatchContext(matchContext);
matchContext.setSink(new DuplicateFilteringResultSink(new DefaultMatchResultSink() {
@Override
public void newMatch(MatchResult result) {
processor.process(result, configuration);
}
}));
options.setScope(scope);
}
Aggregations