IndexId as a class, not an interface (immutability of getName() method)

This commit is contained in:
Dmitry Batkovich
2017-04-18 19:17:53 +03:00
parent 4695e20357
commit 14d6261ea5
6 changed files with 37 additions and 75 deletions
@@ -18,7 +18,6 @@ package com.intellij.index;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.indexing.*;
import com.intellij.util.indexing.impl.BasicIndexId;
import com.intellij.util.indexing.impl.IndexStorage;
import com.intellij.util.indexing.impl.MapBasedForwardIndex;
import com.intellij.util.indexing.impl.MapReduceIndex;
@@ -48,7 +47,7 @@ public class StringIndex {
final PersistentHashMap<Integer, Collection<String>> inputIndex,
boolean failOnRebuildRequest)
throws IOException {
BasicIndexId<String, String> id = BasicIndexId.create(testName + "string_index");
IndexId<String, String> id = IndexId.create(testName + "string_index");
IndexExtension<String, String, PathContentPair> extension = new IndexExtension<String, String, PathContentPair>() {
@NotNull
@Override
@@ -17,7 +17,6 @@ package org.jetbrains.jps.backwardRefs.index;
import com.intellij.openapi.util.io.DataInputOutputUtilRt;
import com.intellij.util.indexing.*;
import com.intellij.util.indexing.impl.BasicIndexId;
import com.intellij.util.io.DataExternalizer;
import com.intellij.util.io.DataInputOutputUtil;
import com.intellij.util.io.KeyDescriptor;
@@ -38,10 +37,10 @@ public class CompilerIndices {
//TODO manage version separately
public final static int VERSION = 4;
public final static IndexId<LightRef, Integer> BACK_USAGES = BasicIndexId.create("back.refs");
public final static IndexId<LightRef, Collection<LightRef>> BACK_HIERARCHY = BasicIndexId.create("back.hierarchy");
public final static IndexId<LightRef, Void> BACK_CLASS_DEF = BasicIndexId.create("back.class.def");
public final static IndexId<SignatureData, Collection<LightRef>> BACK_MEMBER_SIGN = BasicIndexId.create("back.member.sign");
public final static IndexId<LightRef, Integer> BACK_USAGES = IndexId.create("back.refs");
public final static IndexId<LightRef, Collection<LightRef>> BACK_HIERARCHY = IndexId.create("back.hierarchy");
public final static IndexId<LightRef, Void> BACK_CLASS_DEF = IndexId.create("back.class.def");
public final static IndexId<SignatureData, Collection<LightRef>> BACK_MEMBER_SIGN = IndexId.create("back.member.sign");
public static List<IndexExtension<?, ?, CompiledFileData>> getIndices() {
return Arrays.asList(createBackwardClassDefinitionExtension(),
@@ -31,12 +31,11 @@ import java.io.*;
* @author Eugene Zhuravlev
* Date: Feb 12, 2008
*/
public class ID<K, V> implements IndexId<K,V> {
public class ID<K, V> extends IndexId<K,V> {
private static final ConcurrentIntObjectMap<ID> ourRegistry = ContainerUtil.createConcurrentIntObjectMap();
private static final TObjectIntHashMap<String> ourNameToIdRegistry = new TObjectIntHashMap<String>();
static final int MAX_NUMBER_OF_INDICES = Short.MAX_VALUE;
private final String myName;
private final short myUniqueId;
static {
@@ -77,19 +76,13 @@ public class ID<K, V> implements IndexId<K,V> {
}
}
@NotNull
@Override
public String getName() {
return myName;
}
private static File getEnumFile() {
final File indexFolder = PathManager.getIndexRoot();
return new File(indexFolder, "indices.enum");
}
protected ID(String name) {
myName = name;
super(name);
myUniqueId = stringToId(name);
final ID old = ourRegistry.put(myUniqueId, this);
@@ -18,10 +18,36 @@ package com.intellij.util.indexing;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
@SuppressWarnings("unused")
@ApiStatus.Experimental
public interface IndexId<K, V> {
public class IndexId<K, V> {
@NotNull
private final String myName;
protected IndexId(@NotNull String name) {myName = name;}
@NotNull
String getName();
public final String getName() {
return myName;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
IndexId<?, ?> id = (IndexId<?, ?>)o;
if (!myName.equals(id.myName)) return false;
return true;
}
@Override
public int hashCode() {
return myName.hashCode();
}
public static <K, V> IndexId<K, V> create(String name) {
return new IndexId<K, V>(name);
}
}
@@ -1,55 +0,0 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.util.indexing.impl;
import com.intellij.util.indexing.IndexId;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
@ApiStatus.Experimental
public class BasicIndexId<K, V> implements IndexId<K,V> {
@NotNull
private final String myName;
private BasicIndexId(@NotNull String name) {myName = name;}
@NotNull
@Override
public String getName() {
return myName;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
BasicIndexId<?, ?> id = (BasicIndexId<?, ?>)o;
if (!myName.equals(id.myName)) return false;
return true;
}
@Override
public int hashCode() {
return myName.hashCode();
}
public static <K, V> BasicIndexId<K, V> create(String name) {
return new BasicIndexId<K, V>(name);
}
}
@@ -59,7 +59,7 @@ public class VcsLogFullDetailsIndex<T> implements Disposable {
@NotNull FatalErrorHandler fatalErrorHandler,
@NotNull Disposable disposableParent)
throws IOException {
myID = BasicIndexId.create(name);
myID = IndexId.create(name);
myName = name;
myLogId = logId;
myIndexer = indexer;