summaryrefslogtreecommitdiff
path: root/platform/duplicates-analysis/src/com/intellij/dupLocator/DuplicatesProfileCache.java
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2014-07-16 18:07:37 -0700
committerTor Norbye <tnorbye@google.com>2014-07-16 18:09:03 -0700
commit65f60eb9011bb2c549a6d83ae31257480368ddc5 (patch)
treede0dca03bec460e8797332e5f460400f5cf6485f /platform/duplicates-analysis/src/com/intellij/dupLocator/DuplicatesProfileCache.java
parent9ea67227e8fdcf8ed37e65bb96e32767291d0f4f (diff)
downloadidea-65f60eb9011bb2c549a6d83ae31257480368ddc5.tar.gz
Snapshot idea/138.1029 from git://git.jetbrains.org/idea/community.git
Update from idea/138.538 to idea/138.1029 Change-Id: I828f829a968439a99ec67640990c18ff7c9b58ce
Diffstat (limited to 'platform/duplicates-analysis/src/com/intellij/dupLocator/DuplicatesProfileCache.java')
-rw-r--r--platform/duplicates-analysis/src/com/intellij/dupLocator/DuplicatesProfileCache.java76
1 files changed, 76 insertions, 0 deletions
diff --git a/platform/duplicates-analysis/src/com/intellij/dupLocator/DuplicatesProfileCache.java b/platform/duplicates-analysis/src/com/intellij/dupLocator/DuplicatesProfileCache.java
new file mode 100644
index 000000000000..db9ff875e9bf
--- /dev/null
+++ b/platform/duplicates-analysis/src/com/intellij/dupLocator/DuplicatesProfileCache.java
@@ -0,0 +1,76 @@
+package com.intellij.dupLocator;
+
+import com.intellij.dupLocator.treeHash.FragmentsCollector;
+import com.intellij.lang.Language;
+import com.intellij.openapi.extensions.Extensions;
+import gnu.trove.TIntObjectHashMap;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: Eugene.Kudelevsky
+ * Date: May 18, 2009
+ * Time: 7:39:35 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class DuplicatesProfileCache {
+ private static final Map<DupInfo, TIntObjectHashMap<DuplicatesProfile>> ourProfileCache = new HashMap<DupInfo, TIntObjectHashMap<DuplicatesProfile>>();
+
+ private DuplicatesProfileCache() {
+ }
+
+ public static void clear(@NotNull DupInfo info) {
+ ourProfileCache.remove(info);
+ }
+
+ @Nullable
+ public static DuplicatesProfile getProfile(@NotNull DupInfo dupInfo, int index) {
+ TIntObjectHashMap<DuplicatesProfile> patternCache = ourProfileCache.get(dupInfo);
+ if (patternCache == null) {
+ patternCache = new TIntObjectHashMap<DuplicatesProfile>();
+ ourProfileCache.put(dupInfo, patternCache);
+ }
+ DuplicatesProfile result = patternCache.get(index);
+ if (result == null) {
+ DuplicatesProfile[] profiles = Extensions.getExtensions(DuplicatesProfile.EP_NAME);
+ DuplicatesProfile theProfile = null;
+ for (DuplicatesProfile profile : profiles) {
+ if (profile.isMyDuplicate(dupInfo, index)) {
+ theProfile = profile;
+ break;
+ }
+ }
+ result = theProfile == null ? NULL_PROFILE : theProfile;
+ patternCache.put(index, result);
+ }
+ return result == NULL_PROFILE ? null : result;
+ }
+
+ private static final DuplicatesProfile NULL_PROFILE = new DuplicatesProfile() {
+ @NotNull
+ @Override
+ public DuplocateVisitor createVisitor(@NotNull FragmentsCollector collector) {
+ return null;
+ }
+
+ @Override
+ public boolean isMyLanguage(@NotNull Language language) {
+ return false;
+ }
+
+ @NotNull
+ @Override
+ public DuplocatorState getDuplocatorState(@NotNull Language language) {
+ return null;
+ }
+
+ @Override
+ public boolean isMyDuplicate(@NotNull DupInfo info, int index) {
+ return false;
+ }
+ };
+}