Search in sources :

Example 1 with DuplicateFilteringResultSink

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;
}
Also used : DuplicateFilteringResultSink(com.intellij.structuralsearch.plugin.util.DuplicateFilteringResultSink) Computable(com.intellij.openapi.util.Computable)

Example 2 with DuplicateFilteringResultSink

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);
}
Also used : LocalSearchScope(com.intellij.psi.search.LocalSearchScope) DuplicateFilteringResultSink(com.intellij.structuralsearch.plugin.util.DuplicateFilteringResultSink)

Aggregations

DuplicateFilteringResultSink (com.intellij.structuralsearch.plugin.util.DuplicateFilteringResultSink)2 Computable (com.intellij.openapi.util.Computable)1 LocalSearchScope (com.intellij.psi.search.LocalSearchScope)1