diff --git a/platform/structuralsearch/source/META-INF/structuralsearch.xml b/platform/structuralsearch/source/META-INF/structuralsearch.xml
index 72e24e15ee0f..96611ee2e9dc 100644
--- a/platform/structuralsearch/source/META-INF/structuralsearch.xml
+++ b/platform/structuralsearch/source/META-INF/structuralsearch.xml
@@ -12,9 +12,6 @@
-
-
diff --git a/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/MatcherImpl.java b/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/MatcherImpl.java
index f95c18c746df..8f92555dd019 100644
--- a/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/MatcherImpl.java
+++ b/platform/structuralsearch/source/com/intellij/structuralsearch/impl/matcher/MatcherImpl.java
@@ -38,9 +38,7 @@ import com.intellij.util.indexing.FileBasedIndex;
import org.jetbrains.annotations.NotNull;
import java.lang.ref.SoftReference;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
+import java.util.*;
/**
* This class makes program structure tree matching:
@@ -193,10 +191,11 @@ public class MatcherImpl {
options.setScope(scope);
}
- public CompiledOptions precompileOptions(List configurations) {
- final List> contexts = new ArrayList>();
-
+ public void precompileOptions(List configurations, final Map out) {
for (final Configuration configuration : configurations) {
+ if (out.containsKey(configuration)) {
+ continue;
+ }
final MatchContext matchContext = new MatchContext();
matchContext.setMatcher(visitor);
final MatchOptions matchOptions = configuration.getMatchOptions();
@@ -206,16 +205,15 @@ public class MatcherImpl {
@Override
public void run() {
try {
- CompiledPattern compiledPattern = PatternCompiler.compilePattern(project, matchOptions);
+ final CompiledPattern compiledPattern = PatternCompiler.compilePattern(project, matchOptions);
matchContext.setPattern(compiledPattern);
- contexts.add(Pair.create(matchContext, configuration));
+ out.put(configuration, matchContext);
}
catch (UnsupportedPatternException ignored) {}
catch (MalformedPatternException ignored) {}
}
});
}
- return new CompiledOptions(contexts);
}
Project getProject() {
diff --git a/platform/structuralsearch/source/com/intellij/structuralsearch/inspection/highlightTemplate/SSBasedInspection.java b/platform/structuralsearch/source/com/intellij/structuralsearch/inspection/highlightTemplate/SSBasedInspection.java
index 10a88a45ca13..8e0d4935bfef 100644
--- a/platform/structuralsearch/source/com/intellij/structuralsearch/inspection/highlightTemplate/SSBasedInspection.java
+++ b/platform/structuralsearch/source/com/intellij/structuralsearch/inspection/highlightTemplate/SSBasedInspection.java
@@ -23,9 +23,7 @@ import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.InvalidDataException;
-import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.WriteExternalException;
-import com.intellij.profile.codeInspection.InspectionProfileManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.structuralsearch.MatchResult;
@@ -41,7 +39,6 @@ import com.intellij.structuralsearch.plugin.replace.impl.Replacer;
import com.intellij.structuralsearch.plugin.replace.ui.ReplaceConfiguration;
import com.intellij.structuralsearch.plugin.ui.Configuration;
import com.intellij.structuralsearch.plugin.ui.ConfigurationManager;
-import com.intellij.structuralsearch.plugin.ui.SearchContext;
import com.intellij.util.PairProcessor;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
@@ -59,7 +56,7 @@ public class SSBasedInspection extends LocalInspectionTool {
private static final Object LOCK = new Object(); // hack to avoid race conditions in SSR
static final String SHORT_NAME = "SSBasedInspection";
- private List myConfigurations = new ArrayList();
+ private final List myConfigurations = new ArrayList();
private final Set myProblemsReported = new HashSet(1);
@Override
@@ -96,13 +93,12 @@ public class SSBasedInspection extends LocalInspectionTool {
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
- final MatcherImpl.CompiledOptions compiledOptions =
- SSBasedInspectionCompiledPatternsCache.getCompiledOptions(holder.getProject());
+ final Map compiledOptions =
+ SSBasedInspectionCompiledPatternsCache.getCompiledOptions(myConfigurations, holder.getProject());
- if (compiledOptions == null) return super.buildVisitor(holder, isOnTheFly);
+ if (compiledOptions.isEmpty()) return super.buildVisitor(holder, isOnTheFly);
return new PsiElementVisitor() {
- final List> contexts = compiledOptions.getMatchContexts();
final Matcher matcher = new Matcher(holder.getManager().getProject());
final PairProcessor processor = new PairProcessor() {
@Override
@@ -122,9 +118,8 @@ public class SSBasedInspection extends LocalInspectionTool {
synchronized (LOCK) {
if (LexicalNodesFilter.getInstance().accepts(element)) return;
final SsrFilteringNodeIterator matchedNodes = new SsrFilteringNodeIterator(element);
- for (Pair pair : contexts) {
- Configuration configuration = pair.second;
- MatchContext context = pair.first;
+ for (Configuration configuration : myConfigurations) {
+ final MatchContext context = compiledOptions.get(configuration);
if (MatcherImpl.checkIfShouldAttemptToMatch(context, matchedNodes)) {
final int nodeCount = context.getPattern().getNodeCount();
@@ -179,23 +174,12 @@ public class SSBasedInspection extends LocalInspectionTool {
@Override
@Nullable
public JComponent createOptionsPanel() {
- return new SSBasedInspectionOptions(myConfigurations){
- @Override
- public void configurationsChanged(final SearchContext searchContext) {
- super.configurationsChanged(searchContext);
- SSBasedInspectionCompiledPatternsCache.precompileConfigurations(searchContext.getProject(), SSBasedInspection.this);
- InspectionProfileManager.getInstance().fireProfileChanged(null);
- }
- }.getComponent();
+ return new SSBasedInspectionOptions(myConfigurations).getComponent();
}
@TestOnly
- public void setConfigurations(final List configurations, final Project project) {
- myConfigurations = configurations;
- SSBasedInspectionCompiledPatternsCache.setCompiledOptions(project, configurations);
- }
-
- public List getConfigurations() {
- return myConfigurations;
+ public void setConfigurations(@NotNull final List configurations, @NotNull final Project project) {
+ myConfigurations.clear();
+ myConfigurations.addAll(configurations);
}
}
diff --git a/platform/structuralsearch/source/com/intellij/structuralsearch/inspection/highlightTemplate/SSBasedInspectionCompiledPatternsCache.java b/platform/structuralsearch/source/com/intellij/structuralsearch/inspection/highlightTemplate/SSBasedInspectionCompiledPatternsCache.java
index 49b55f8be24c..f8add2370037 100644
--- a/platform/structuralsearch/source/com/intellij/structuralsearch/inspection/highlightTemplate/SSBasedInspectionCompiledPatternsCache.java
+++ b/platform/structuralsearch/source/com/intellij/structuralsearch/inspection/highlightTemplate/SSBasedInspectionCompiledPatternsCache.java
@@ -1,84 +1,50 @@
package com.intellij.structuralsearch.inspection.highlightTemplate;
-import com.intellij.codeInspection.InspectionProfile;
-import com.intellij.codeInspection.ex.InspectionToolWrapper;
-import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
-import com.intellij.openapi.startup.StartupActivity;
import com.intellij.openapi.util.Key;
-import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
import com.intellij.structuralsearch.Matcher;
-import com.intellij.structuralsearch.impl.matcher.MatcherImpl;
+import com.intellij.structuralsearch.impl.matcher.MatchContext;
import com.intellij.structuralsearch.plugin.ui.Configuration;
+import com.intellij.util.ObjectUtils;
import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-import org.jetbrains.annotations.TestOnly;
-import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
/**
* @author Eugene.Kudelevsky
*/
-public class SSBasedInspectionCompiledPatternsCache implements StartupActivity {
- private static final Key COMPILED_OPTIONS_KEY = Key.create("SSR_INSPECTION_COMPILED_OPTIONS_KEY");
+public class SSBasedInspectionCompiledPatternsCache {
- @Override
- public void runActivity(@NotNull final Project project) {
- ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
- @Override
- public void run() {
- precompileConfigurations(project, null);
+ private static final Key