mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
refactoring: reduce number of type parameters in ForwardIndexAccessor (apply again)
GitOrigin-RevId: 6eeca141a82b66f20f974b4b3c7f04c9cf862c95
This commit is contained in:
committed by
intellij-monorepo-bot
parent
628b44b1cb
commit
078031394e
+1
-1
@@ -38,7 +38,7 @@ public class TestFilesIndex extends MapReduceIndex<Integer, Void, UsedSources> {
|
||||
@Nullable
|
||||
Collection<Integer> getTestDataFor(int testId) throws IOException {
|
||||
ForwardIndex forwardIndex = getForwardIndexMap();
|
||||
KeyCollectionForwardIndexAccessor<Integer, Void, UsedSources> forwardIndexAccessor = (KeyCollectionForwardIndexAccessor<Integer, Void, UsedSources>)getForwardIndexAccessor();
|
||||
KeyCollectionForwardIndexAccessor<Integer, Void> forwardIndexAccessor = (KeyCollectionForwardIndexAccessor<Integer, Void>)getForwardIndexAccessor();
|
||||
return forwardIndexAccessor.deserializeData(forwardIndex.get(testId));
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.indexing.FileContent;
|
||||
import com.intellij.util.indexing.ID;
|
||||
import com.intellij.util.indexing.impl.InputData;
|
||||
import com.intellij.util.indexing.impl.InputDataDiffBuilder;
|
||||
import com.intellij.util.indexing.impl.forward.AbstractForwardIndexAccessor;
|
||||
import com.intellij.util.io.DataExternalizer;
|
||||
@@ -19,7 +20,7 @@ import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
class StubUpdatingForwardIndexAccessor extends AbstractForwardIndexAccessor<Integer, SerializedStubTree, IndexedStubs , FileContent> {
|
||||
class StubUpdatingForwardIndexAccessor extends AbstractForwardIndexAccessor<Integer, SerializedStubTree, IndexedStubs> {
|
||||
StubUpdatingForwardIndexAccessor() {super(new DataExternalizer<IndexedStubs>() {
|
||||
private volatile boolean myEnsuredStubElementTypesLoaded;
|
||||
|
||||
@@ -68,10 +69,10 @@ class StubUpdatingForwardIndexAccessor extends AbstractForwardIndexAccessor<Inte
|
||||
}
|
||||
});}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IndexedStubs convertToDataType(@Nullable Map<Integer, SerializedStubTree> map,
|
||||
@Nullable FileContent content) {
|
||||
return getIndexedStubs(map);
|
||||
public IndexedStubs convertToDataType(@NotNull InputData<Integer, SerializedStubTree> data) {
|
||||
return getIndexedStubs(data.getKeyValues());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.util.indexing;
|
||||
|
||||
import com.intellij.util.indexing.impl.InputData;
|
||||
import com.intellij.util.indexing.impl.InputDataDiffBuilder;
|
||||
import com.intellij.util.indexing.impl.MapInputDataDiffBuilder;
|
||||
import com.intellij.util.indexing.impl.forward.AbstractMapForwardIndexAccessor;
|
||||
@@ -13,8 +14,8 @@ import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
class HashIdForwardIndexAccessor<Key, Value, Input>
|
||||
extends AbstractMapForwardIndexAccessor<Key, Value, Integer, Input>
|
||||
implements IntForwardIndexAccessor<Key, Value, Input> {
|
||||
extends AbstractMapForwardIndexAccessor<Key, Value, Integer>
|
||||
implements IntForwardIndexAccessor<Key, Value> {
|
||||
private final UpdatableSnapshotInputMappingIndex<Key, Value, Input> mySnapshotInputMappingIndex;
|
||||
|
||||
HashIdForwardIndexAccessor(@NotNull UpdatableSnapshotInputMappingIndex<Key, Value, Input> snapshotInputMappingIndex) {
|
||||
@@ -35,12 +36,13 @@ class HashIdForwardIndexAccessor<Key, Value, Input>
|
||||
}
|
||||
|
||||
@Override
|
||||
public int convertToInt(@Nullable Map<Key, Value> map, @Nullable Input content) {
|
||||
try {
|
||||
return mySnapshotInputMappingIndex.getHashId(content);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
public int serializeIndexedDataToInt(@NotNull InputData<Key, Value> data) {
|
||||
return data == InputData.empty() ? 0 : ((HashedInputData)data).getHashId();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Integer convertToDataType(@NotNull InputData<Key, Value> data) {
|
||||
return serializeIndexedDataToInt(data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.util.indexing;
|
||||
|
||||
import com.intellij.util.indexing.impl.InputData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class HashedInputData<Key, Value> extends InputData<Key, Value> {
|
||||
private final int myHashId;
|
||||
|
||||
protected HashedInputData(@NotNull Map<Key, Value> values, int hashId) {
|
||||
super(values);
|
||||
myHashId = hashId;
|
||||
}
|
||||
|
||||
public int getHashId() {
|
||||
return myHashId;
|
||||
}
|
||||
}
|
||||
@@ -26,10 +26,10 @@ public class SharedMapForwardIndex implements ForwardIndex {
|
||||
|
||||
// only verification purpose
|
||||
@Nullable
|
||||
private final AbstractForwardIndexAccessor<?, ?, ?, ?> myAccessor;
|
||||
private final AbstractForwardIndexAccessor<?, ?, ?> myAccessor;
|
||||
|
||||
public SharedMapForwardIndex(@NotNull IndexExtension<?, ?, ?> extension,
|
||||
@Nullable AbstractForwardIndexAccessor<?, ?, ?, ?> accessor,
|
||||
@Nullable AbstractForwardIndexAccessor<?, ?, ?> accessor,
|
||||
@Nullable File verificationIndexStorageFile,
|
||||
boolean verificationIndexHasChunks) throws IOException {
|
||||
myIndexId = (ID<?, ?>)extension.getName();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.util.indexing;
|
||||
|
||||
import com.intellij.util.indexing.impl.InputData;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -12,5 +13,5 @@ import java.util.Map;
|
||||
@ApiStatus.Experimental
|
||||
public interface SnapshotInputMappingIndex<Key, Value, Input> extends Closeable {
|
||||
@Nullable
|
||||
Map<Key, Value> readData(@NotNull Input content) throws IOException;
|
||||
InputData<Key, Value> readData(@NotNull Input content) throws IOException;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.intellij.util.CompressionUtil;
|
||||
import com.intellij.util.ExceptionUtil;
|
||||
import com.intellij.util.SystemProperties;
|
||||
import com.intellij.util.indexing.impl.DebugAssertions;
|
||||
import com.intellij.util.indexing.impl.InputData;
|
||||
import com.intellij.util.indexing.impl.forward.AbstractForwardIndexAccessor;
|
||||
import com.intellij.util.indexing.impl.forward.PersistentMapBasedForwardIndex;
|
||||
import com.intellij.util.io.*;
|
||||
@@ -70,12 +71,13 @@ class SnapshotInputMappings<Key, Value, Input> implements UpdatableSnapshotInput
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Map<Key, Value> readData(@NotNull Input content) throws IOException {
|
||||
public InputData<Key, Value> readData(@NotNull Input content) throws IOException {
|
||||
Map<Key, Value> data = null;
|
||||
int hashId = 0;
|
||||
|
||||
if (doReadSavedPersistentData) {
|
||||
if (myContents == null || !myContents.isBusyReading() || DebugAssertions.EXTRA_SANITY_CHECKS) { // avoid blocking read, we can calculate index value
|
||||
int hashId = getHashId(content);
|
||||
hashId = getHashId(content);
|
||||
ByteArraySequence bytes = readContents(hashId);
|
||||
|
||||
if (bytes != null) {
|
||||
@@ -96,25 +98,32 @@ class SnapshotInputMappings<Key, Value, Input> implements UpdatableSnapshotInput
|
||||
}
|
||||
}
|
||||
}
|
||||
return data;
|
||||
return data == null ? null : new HashedInputData<>(data, hashId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putData(@Nullable Input content, @NotNull Map<Key, Value> data) throws IOException {
|
||||
int hashId = getHashId(content);
|
||||
boolean saved = savePersistentData(data, hashId);
|
||||
public InputData<Key, Value> putData(@Nullable Input content, @NotNull InputData<Key, Value> data) throws IOException {
|
||||
int hashId;
|
||||
InputData<Key, Value> result;
|
||||
if (data instanceof HashedInputData) {
|
||||
hashId = ((HashedInputData<Key, Value>)data).getHashId();
|
||||
result = data;
|
||||
} else {
|
||||
hashId = getHashId(content);
|
||||
result = hashId == 0 ? InputData.empty() : new HashedInputData<>(data.getKeyValues(), hashId);
|
||||
}
|
||||
boolean saved = savePersistentData(data.getKeyValues(), hashId);
|
||||
if (DebugAssertions.EXTRA_SANITY_CHECKS) {
|
||||
if (saved) {
|
||||
try {
|
||||
myIndexingTrace.put(hashId, getContentDebugData(content) +
|
||||
"," +
|
||||
ExceptionUtil.getThrowableText(new Throwable()));
|
||||
myIndexingTrace.put(hashId, getContentDebugData(content) + "," + ExceptionUtil.getThrowableText(new Throwable()));
|
||||
}
|
||||
catch (IOException ex) {
|
||||
LOG.error(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -123,8 +132,7 @@ class SnapshotInputMappings<Key, Value, Input> implements UpdatableSnapshotInput
|
||||
return "[" + content.getFile().getPath() + ";" + content.getFileType().getName() + ";" + content.getCharset() + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHashId(@Nullable Input content) throws IOException {
|
||||
private int getHashId(@Nullable Input content) throws IOException {
|
||||
return content == null ? 0 : getHashOfContent((FileContent) content);
|
||||
}
|
||||
|
||||
|
||||
+2
-3
@@ -1,6 +1,7 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.util.indexing;
|
||||
|
||||
import com.intellij.util.indexing.impl.InputData;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -13,9 +14,7 @@ public interface UpdatableSnapshotInputMappingIndex<Key, Value, Input> extends S
|
||||
@NotNull
|
||||
Map<Key, Value> readData(int hashId) throws IOException;
|
||||
|
||||
void putData(@NotNull Input content, @NotNull Map<Key, Value> data) throws IOException;
|
||||
|
||||
int getHashId(@Nullable Input content) throws IOException;
|
||||
InputData<Key, Value> putData(@NotNull Input content, @NotNull InputData<Key, Value> data) throws IOException;
|
||||
|
||||
void flush() throws IOException;
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ public class VfsAwareMapReduceIndex<Key, Value, Input> extends MapReduceIndex<Ke
|
||||
protected VfsAwareMapReduceIndex(@NotNull IndexExtension<Key, Value, Input> extension,
|
||||
@NotNull IndexStorage<Key, Value> storage,
|
||||
@Nullable ForwardIndex forwardIndexMap,
|
||||
@Nullable ForwardIndexAccessor<Key, Value, ?, Input> forwardIndexAccessor,
|
||||
@Nullable ForwardIndexAccessor<Key, Value> forwardIndexAccessor,
|
||||
@Nullable SnapshotInputMappingIndex<Key, Value, Input> snapshotInputMappings) {
|
||||
super(extension, storage, forwardIndexMap, forwardIndexAccessor, null);
|
||||
SharedIndicesData.registerIndex((ID<Key, Value>)myIndexId, extension);
|
||||
@@ -89,10 +89,10 @@ public class VfsAwareMapReduceIndex<Key, Value, Input> extends MapReduceIndex<Ke
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected Map<Key, Value> mapInput(@Nullable Input content) {
|
||||
Map<Key, Value> data;
|
||||
protected InputData<Key, Value> mapInput(@Nullable Input content) {
|
||||
InputData<Key, Value> data;
|
||||
boolean containsSnapshotData = true;
|
||||
if (mySnapshotInputMappings != null && !myInMemoryMode.get() && content != null) {
|
||||
if (mySnapshotInputMappings != null && content != null) {
|
||||
try {
|
||||
data = mySnapshotInputMappings.readData(content);
|
||||
if (data != null) {
|
||||
@@ -108,7 +108,7 @@ public class VfsAwareMapReduceIndex<Key, Value, Input> extends MapReduceIndex<Ke
|
||||
data = super.mapInput(content);
|
||||
if (!containsSnapshotData) {
|
||||
try {
|
||||
((UpdatableSnapshotInputMappingIndex)mySnapshotInputMappings).putData(content, data);
|
||||
return ((UpdatableSnapshotInputMappingIndex)mySnapshotInputMappings).putData(content, data);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
@@ -140,13 +140,13 @@ public class VfsAwareMapReduceIndex<Key, Value, Input> extends MapReduceIndex<Ke
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateForwardIndex(int inputId, @NotNull Map<Key, Value> data, @Nullable Object forwardIndexData) throws IOException {
|
||||
protected void updateForwardIndex(int inputId, @NotNull InputData<Key, Value> data) throws IOException {
|
||||
if (myInMemoryMode.get()) {
|
||||
synchronized (myInMemoryKeysAndValues) {
|
||||
myInMemoryKeysAndValues.put(inputId, data);
|
||||
myInMemoryKeysAndValues.put(inputId, data.getKeyValues());
|
||||
}
|
||||
} else {
|
||||
super.updateForwardIndex(inputId, data, forwardIndexData);
|
||||
super.updateForwardIndex(inputId, data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,7 +248,7 @@ public class VfsAwareMapReduceIndex<Key, Value, Input> extends MapReduceIndex<Ke
|
||||
}
|
||||
if (getForwardIndexAccessor() instanceof AbstractMapForwardIndexAccessor) {
|
||||
ByteArraySequence serializedInputData = getForwardIndexMap().get(fileId);
|
||||
AbstractMapForwardIndexAccessor<Key, Value, ?, Input> forwardIndexAccessor = (AbstractMapForwardIndexAccessor<Key, Value, ?, Input>)getForwardIndexAccessor();
|
||||
AbstractMapForwardIndexAccessor<Key, Value, ?> forwardIndexAccessor = (AbstractMapForwardIndexAccessor<Key, Value, ?>)getForwardIndexAccessor();
|
||||
return forwardIndexAccessor.convertToInputDataMap(serializedInputData);
|
||||
}
|
||||
// in future we will get rid of forward index for SingleEntryFileBasedIndexExtension
|
||||
@@ -319,7 +319,7 @@ public class VfsAwareMapReduceIndex<Key, Value, Input> extends MapReduceIndex<Ke
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static <Key, Value, Input> ForwardIndexAccessor<Key, Value, ?, Input> getForwardIndexAccessor(@NotNull IndexExtension<Key, Value, Input> indexExtension) {
|
||||
private static <Key, Value> ForwardIndexAccessor<Key, Value> getForwardIndexAccessor(@NotNull IndexExtension<Key, Value, ?> indexExtension) {
|
||||
if (!shouldCreateForwardIndex(indexExtension)) return null;
|
||||
return new MapForwardIndexAccessor<>(new InputMapExternalizer<>(indexExtension));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.util.indexing.impl;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
public class InputData<Key, Value> {
|
||||
private static final InputData EMPTY = new InputData<>(Collections.emptyMap());
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <Key, Value> InputData<Key, Value> empty() {
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private final Map<Key, Value> myKeyValues;
|
||||
|
||||
protected InputData(@NotNull Map<Key, Value> values) {
|
||||
myKeyValues = values;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Map<Key, Value> getKeyValues() {
|
||||
return myKeyValues;
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,7 @@ public abstract class MapReduceIndex<Key,Value, Input> implements InvertedIndex<
|
||||
protected final ForwardIndex<Key, Value> myForwardIndex;
|
||||
//new
|
||||
private final com.intellij.util.indexing.impl.forward.ForwardIndex myForwardIndexMap;
|
||||
private final ForwardIndexAccessor<Key, Value, ?, Input> myForwardIndexAccessor;
|
||||
private final ForwardIndexAccessor<Key, Value> myForwardIndexAccessor;
|
||||
|
||||
private final ReentrantReadWriteLock myLock = createLock();
|
||||
private final boolean myUseIntForwardIndex;
|
||||
@@ -85,7 +85,7 @@ public abstract class MapReduceIndex<Key,Value, Input> implements InvertedIndex<
|
||||
protected MapReduceIndex(@NotNull IndexExtension<Key, Value, Input> extension,
|
||||
@NotNull IndexStorage<Key, Value> storage,
|
||||
@Nullable com.intellij.util.indexing.impl.forward.ForwardIndex forwardIndexMap,
|
||||
@Nullable ForwardIndexAccessor<Key, Value, ?, Input> forwardIndexAccessor,
|
||||
@Nullable ForwardIndexAccessor<Key, Value> forwardIndexAccessor,
|
||||
@Nullable ForwardIndex<Key, Value> forwardIndex) {
|
||||
myIndexId = extension.getName();
|
||||
myExtension = extension;
|
||||
@@ -102,7 +102,7 @@ public abstract class MapReduceIndex<Key,Value, Input> implements InvertedIndex<
|
||||
protected MapReduceIndex(@NotNull IndexExtension<Key, Value, Input> extension,
|
||||
@NotNull IndexStorage<Key, Value> storage,
|
||||
@Nullable com.intellij.util.indexing.impl.forward.ForwardIndex forwardIndex,
|
||||
@Nullable ForwardIndexAccessor<Key, Value, ?, Input> forwardIndexAccessor) {
|
||||
@Nullable ForwardIndexAccessor<Key, Value> forwardIndexAccessor) {
|
||||
this(extension, storage, forwardIndex, forwardIndexAccessor, null);
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ public abstract class MapReduceIndex<Key,Value, Input> implements InvertedIndex<
|
||||
return myForwardIndexMap;
|
||||
}
|
||||
|
||||
public ForwardIndexAccessor<Key, Value, ?, Input> getForwardIndexAccessor() {
|
||||
public ForwardIndexAccessor<Key, Value> getForwardIndexAccessor() {
|
||||
return myForwardIndexAccessor;
|
||||
}
|
||||
|
||||
@@ -266,26 +266,19 @@ public abstract class MapReduceIndex<Key,Value, Input> implements InvertedIndex<
|
||||
|
||||
@NotNull
|
||||
protected UpdateData<Key, Value> calculateUpdateData(final int inputId, @Nullable Input content) {
|
||||
final Map<Key, Value> data = mapInput(content);
|
||||
Object forwardIndexData;
|
||||
if (myForwardIndexAccessor != null) {
|
||||
forwardIndexData = myForwardIndexAccessor.convertToDataType(data, content);
|
||||
} else {
|
||||
forwardIndexData = null;
|
||||
}
|
||||
return createUpdateData(data,
|
||||
final InputData<Key, Value> data = mapInput(content);
|
||||
return createUpdateData(data.getKeyValues(),
|
||||
() -> getKeysDiffBuilder(inputId),
|
||||
() -> updateForwardIndex(inputId, data, forwardIndexData));
|
||||
() -> updateForwardIndex(inputId, data));
|
||||
}
|
||||
|
||||
protected void updateForwardIndex(int inputId, @NotNull Map<Key, Value> data, @Nullable Object forwardIndexData) throws IOException {
|
||||
if (myForwardIndex != null) myForwardIndex.putInputData(inputId, data);
|
||||
protected void updateForwardIndex(int inputId, @NotNull InputData<Key, Value> data) throws IOException {
|
||||
if (myForwardIndex != null) myForwardIndex.putInputData(inputId, data.getKeyValues());
|
||||
if (myForwardIndexMap != null) {
|
||||
if (myUseIntForwardIndex) {
|
||||
((IntForwardIndex)myForwardIndexMap).putInt(inputId, (Integer)forwardIndexData);
|
||||
((IntForwardIndex)myForwardIndexMap).putInt(inputId, ((IntForwardIndexAccessor<Key, Value>)myForwardIndexAccessor).serializeIndexedDataToInt(data));
|
||||
} else {
|
||||
//noinspection unchecked
|
||||
myForwardIndexMap.put(inputId, ((ForwardIndexAccessor)myForwardIndexAccessor).serializeIndexedData(forwardIndexData));
|
||||
myForwardIndexMap.put(inputId, myForwardIndexAccessor.serializeIndexedData(data));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -313,14 +306,14 @@ public abstract class MapReduceIndex<Key,Value, Input> implements InvertedIndex<
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected Map<Key, Value> mapInput(@Nullable Input content) {
|
||||
protected InputData<Key, Value> mapInput(@Nullable Input content) {
|
||||
if (content == null) {
|
||||
return Collections.emptyMap();
|
||||
return InputData.empty();
|
||||
}
|
||||
Map<Key, Value> data = myIndexer.map(content);
|
||||
checkValuesHaveProperEqualsAndHashCode(data, myIndexId, myValueExternalizer);
|
||||
checkCanceled();
|
||||
return data;
|
||||
return new InputData<>(data);
|
||||
}
|
||||
|
||||
public abstract void checkCanceled();
|
||||
|
||||
+10
-1
@@ -5,6 +5,7 @@ import com.intellij.openapi.util.ThreadLocalCachedByteArray;
|
||||
import com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream;
|
||||
import com.intellij.openapi.util.io.ByteArraySequence;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.indexing.impl.InputData;
|
||||
import com.intellij.util.indexing.impl.InputDataDiffBuilder;
|
||||
import com.intellij.util.io.DataExternalizer;
|
||||
import com.intellij.util.io.DataOutputStream;
|
||||
@@ -18,7 +19,7 @@ import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
@ApiStatus.Experimental
|
||||
public abstract class AbstractForwardIndexAccessor<Key, Value, DataType, Input> implements ForwardIndexAccessor<Key, Value, DataType, Input> {
|
||||
public abstract class AbstractForwardIndexAccessor<Key, Value, DataType> implements ForwardIndexAccessor<Key, Value> {
|
||||
@NotNull
|
||||
private final DataExternalizer<DataType> myDataTypeExternalizer;
|
||||
|
||||
@@ -40,8 +41,16 @@ public abstract class AbstractForwardIndexAccessor<Key, Value, DataType, Input>
|
||||
return createDiffBuilder(inputId, deserializeData(sequence));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public abstract DataType convertToDataType(@NotNull InputData<Key, Value> data);
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ByteArraySequence serializeIndexedData(@NotNull InputData<Key, Value> data) throws IOException {
|
||||
return serializeIndexedData(convertToDataType(data));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ByteArraySequence serializeIndexedData(@Nullable DataType data) throws IOException {
|
||||
if (data == null) return null;
|
||||
return serializeToByteSeq(data, myDataTypeExternalizer, getBufferInitialSize(data));
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class AbstractMapForwardIndexAccessor<Key, Value, DataType, Input> extends AbstractForwardIndexAccessor<Key, Value, DataType, Input> {
|
||||
public abstract class AbstractMapForwardIndexAccessor<Key, Value, DataType> extends AbstractForwardIndexAccessor<Key, Value, DataType> {
|
||||
public AbstractMapForwardIndexAccessor(@NotNull DataExternalizer<DataType> externalizer) {
|
||||
super(externalizer);
|
||||
}
|
||||
|
||||
+5
-11
@@ -2,32 +2,26 @@
|
||||
package com.intellij.util.indexing.impl.forward;
|
||||
|
||||
import com.intellij.openapi.util.io.ByteArraySequence;
|
||||
import com.intellij.util.indexing.impl.InputData;
|
||||
import com.intellij.util.indexing.impl.InputDataDiffBuilder;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <DataType> should not hold strong reference to Input because it may lead to OOMs
|
||||
*/
|
||||
public interface ForwardIndexAccessor<Key, Value, DataType, Input> {
|
||||
@ApiStatus.Experimental
|
||||
public interface ForwardIndexAccessor<Key, Value> {
|
||||
/**
|
||||
* creates a diff builder for given inputId.
|
||||
*/
|
||||
@NotNull
|
||||
InputDataDiffBuilder<Key, Value> getDiffBuilder(int inputId, @Nullable ByteArraySequence sequence) throws IOException;
|
||||
|
||||
/**
|
||||
* convert mapped key-values and input to a data type before it will be serialized
|
||||
*/
|
||||
DataType convertToDataType(@Nullable Map<Key, Value> map, @Nullable Input content);
|
||||
|
||||
/**
|
||||
* serialize indexed data to forward index format.
|
||||
*/
|
||||
@Nullable
|
||||
ByteArraySequence serializeIndexedData(@Nullable DataType data) throws IOException;
|
||||
ByteArraySequence serializeIndexedData(@NotNull InputData<Key, Value> data) throws IOException;
|
||||
}
|
||||
+5
-12
@@ -2,6 +2,7 @@
|
||||
package com.intellij.util.indexing.impl.forward;
|
||||
|
||||
import com.intellij.openapi.util.io.ByteArraySequence;
|
||||
import com.intellij.util.indexing.impl.InputData;
|
||||
import com.intellij.util.indexing.impl.InputDataDiffBuilder;
|
||||
import com.intellij.util.io.EnumeratorIntegerDescriptor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -10,22 +11,17 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
public interface IntForwardIndexAccessor<Key, Value, Input> extends ForwardIndexAccessor<Key, Value, Integer, Input> {
|
||||
public interface IntForwardIndexAccessor<Key, Value> extends ForwardIndexAccessor<Key, Value> {
|
||||
@NotNull
|
||||
@Override
|
||||
default InputDataDiffBuilder<Key, Value> getDiffBuilder(int inputId, @Nullable ByteArraySequence sequence) throws IOException {
|
||||
return getDiffBuilderFromInt(inputId, sequence == null ? 0 : AbstractForwardIndexAccessor.deserializeFromByteSeq(sequence, EnumeratorIntegerDescriptor.INSTANCE));
|
||||
}
|
||||
|
||||
@Override
|
||||
default Integer convertToDataType(@Nullable Map<Key, Value> map, @Nullable Input content) {
|
||||
return convertToInt(map, content);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
default ByteArraySequence serializeIndexedData(@Nullable Integer data) throws IOException {
|
||||
return data == null ? null : AbstractForwardIndexAccessor.serializeToByteSeq(data, EnumeratorIntegerDescriptor.INSTANCE, 8);
|
||||
default ByteArraySequence serializeIndexedData(@NotNull InputData<Key, Value> data) throws IOException {
|
||||
return AbstractForwardIndexAccessor.serializeToByteSeq(serializeIndexedDataToInt(data), EnumeratorIntegerDescriptor.INSTANCE, 8);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,8 +30,5 @@ public interface IntForwardIndexAccessor<Key, Value, Input> extends ForwardIndex
|
||||
@NotNull
|
||||
InputDataDiffBuilder<Key, Value> getDiffBuilderFromInt(int inputId, int value) throws IOException;
|
||||
|
||||
/**
|
||||
* convert mapped key-values and input to a data type before it will be serialized
|
||||
*/
|
||||
int convertToInt(@Nullable Map<Key, Value> map, @Nullable Input content);
|
||||
int serializeIndexedDataToInt(@NotNull InputData<Key, Value> data);
|
||||
}
|
||||
|
||||
+9
-4
@@ -5,6 +5,7 @@ import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.indexing.IndexExtension;
|
||||
import com.intellij.util.indexing.IndexId;
|
||||
import com.intellij.util.indexing.impl.CollectionInputDataDiffBuilder;
|
||||
import com.intellij.util.indexing.impl.InputData;
|
||||
import com.intellij.util.indexing.impl.InputDataDiffBuilder;
|
||||
import com.intellij.util.indexing.impl.InputIndexDataExternalizer;
|
||||
import com.intellij.util.io.DataExternalizer;
|
||||
@@ -13,16 +14,18 @@ import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@ApiStatus.Experimental
|
||||
public class KeyCollectionForwardIndexAccessor<Key, Value, Input> extends AbstractForwardIndexAccessor<Key, Value, Collection<Key>, Input> {
|
||||
public class KeyCollectionForwardIndexAccessor<Key, Value> extends AbstractForwardIndexAccessor<Key, Value, Collection<Key>> {
|
||||
public KeyCollectionForwardIndexAccessor(@NotNull DataExternalizer<Collection<Key>> externalizer) {
|
||||
super(externalizer);
|
||||
}
|
||||
|
||||
public KeyCollectionForwardIndexAccessor(@NotNull IndexExtension<Key, Value, Input> extension) {
|
||||
public KeyCollectionForwardIndexAccessor(@NotNull IndexExtension<Key, Value, ?> extension) {
|
||||
this(extension.getKeyDescriptor(), extension.getName());
|
||||
}
|
||||
|
||||
@@ -35,9 +38,11 @@ public class KeyCollectionForwardIndexAccessor<Key, Value, Input> extends Abstra
|
||||
return new CollectionInputDataDiffBuilder<>(inputId, keys);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Collection<Key> convertToDataType(@Nullable Map<Key, Value> map, @Nullable Input content) {
|
||||
return ContainerUtil.isEmpty(map) ? null : map.keySet();
|
||||
public Collection<Key> convertToDataType(@NotNull InputData<Key, Value> data) {
|
||||
Set<Key> keys = data.getKeyValues().keySet();
|
||||
return keys.isEmpty() ? null : keys;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+6
-4
@@ -1,13 +1,15 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.util.indexing.impl.forward;
|
||||
|
||||
import com.intellij.util.indexing.impl.InputData;
|
||||
import com.intellij.util.io.DataExternalizer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
public class MapForwardIndexAccessor<Key, Value, Input> extends AbstractMapForwardIndexAccessor<Key, Value, Map<Key, Value>, Input> {
|
||||
public class MapForwardIndexAccessor<Key, Value, Input> extends AbstractMapForwardIndexAccessor<Key, Value, Map<Key, Value>> {
|
||||
public MapForwardIndexAccessor(@NotNull DataExternalizer<Map<Key, Value>> externalizer) {
|
||||
super(externalizer);
|
||||
}
|
||||
@@ -22,9 +24,9 @@ public class MapForwardIndexAccessor<Key, Value, Input> extends AbstractMapForwa
|
||||
protected int getBufferInitialSize(@NotNull Map<Key, Value> map) {
|
||||
return 4 * map.size();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Map<Key, Value> convertToDataType(@Nullable Map<Key, Value> map, @Nullable Input content) {
|
||||
return map;
|
||||
public Map<Key, Value> convertToDataType(@NotNull InputData<Key, Value> data) {
|
||||
return data.getKeyValues();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user