Java 类com.intellij.util.keyFMap.KeyFMap 实例源码

项目:intellij-ce-playground    文件:ExportableUserDataHolderBase.java   
@NotNull
public final Map<Key, Object> exportUserData() {
  final Map<Key, Object> result = new HashMap<Key, Object>();

  KeyFMap map = getUserMap();
  Key[] keys = map.getKeys();

  for (Key<?> k : keys) {
    final Object data = map.get(k);
    if (data != null) {
      result.put(k, data);
    }
  }

  return result;
}
项目:intellij-ce-playground    文件:UserDataInterner.java   
private static int computeHashCode(KeyFMap object) {
  if (object instanceof OneElementFMap) {
    return ((OneElementFMap)object).getKey().hashCode() * 31 + System.identityHashCode(((OneElementFMap)object).getValue());
  }
  if (object instanceof PairElementsFMap) {
    PairElementsFMap map = (PairElementsFMap)object;
    return (map.getKey1().hashCode() * 31 + map.getKey2().hashCode()) * 31 +
           System.identityHashCode(map.getValue1()) + System.identityHashCode(map.getValue2());
  }
  if (object instanceof ArrayBackedFMap) {
    int hc = Arrays.hashCode(((ArrayBackedFMap)object).getKeyIds());
    for (Object o : ((ArrayBackedFMap)object).getValues()) {
      hc = hc * 31 + System.identityHashCode(o);
    }
    return hc;
  }
  return 0;
}
项目:consulo    文件:UserDataInterner.java   
private static int computeHashCode(KeyFMap object) {
  if (object instanceof OneElementFMap) {
    return ((OneElementFMap)object).getKey().hashCode() * 31 + System.identityHashCode(((OneElementFMap)object).getValue());
  }
  if (object instanceof PairElementsFMap) {
    PairElementsFMap map = (PairElementsFMap)object;
    return (map.getKey1().hashCode() * 31 + map.getKey2().hashCode()) * 31 +
           System.identityHashCode(map.getValue1()) + System.identityHashCode(map.getValue2());
  }
  if (object instanceof ArrayBackedFMap) {
    int hc = Arrays.hashCode(((ArrayBackedFMap)object).getKeyIds());
    for (Object o : ((ArrayBackedFMap)object).getValues()) {
      hc = hc * 31 + System.identityHashCode(o);
    }
    return hc;
  }
  return 0;
}
项目:intellij-ce-playground    文件:VirtualDirectoryImpl.java   
static void checkLeaks(KeyFMap newMap) {
  for (Key key : newMap.getKeys()) {
    if (key != null && newMap.get(key) instanceof PsiCachedValue) {
      throw new AssertionError("Don't store CachedValue in VFS user data, since it leads to memory leaks");
    }
  }
}
项目:intellij-ce-playground    文件:VfsData.java   
KeyFMap getUserMap(VirtualFileSystemEntry file, int id) {
  Object o = myObjectArray.get(getOffset(id));
  if (!(o instanceof KeyFMap)) {
    throw reportDeadFileAccess(file);
  }
  return (KeyFMap)o;
}
项目:intellij-ce-playground    文件:UserDataInterner.java   
static KeyFMap internUserData(@NotNull KeyFMap map) {
  if (shouldIntern(map)) {
    MapReference key = new MapReference(map);
    synchronized (ourCache) {
      KeyFMap cached = SoftReference.dereference(ourCache.get(key));
      if (cached != null) return cached;

      ourCache.put(key, key);
    }
    return map;
  }
  return map;
}
项目:intellij-ce-playground    文件:UserDataHolderBase.java   
@Override
public <T> void putUserData(@NotNull Key<T> key, @Nullable T value) {
  while (true) {
    KeyFMap map = getUserMap();
    KeyFMap newMap = value == null ? map.minus(key) : map.plus(key, value);
    if (newMap == map || changeUserMap(map, newMap)) {
      break;
    }
  }
}
项目:intellij-ce-playground    文件:UserDataHolderBase.java   
public <T> void putCopyableUserData(@NotNull Key<T> key, T value) {
  while (true) {
    KeyFMap map = getUserMap();
    KeyFMap copyableMap = map.get(COPYABLE_USER_MAP_KEY);
    if (copyableMap == null) {
      copyableMap = KeyFMap.EMPTY_MAP;
    }
    KeyFMap newCopyableMap = value == null ? copyableMap.minus(key) : copyableMap.plus(key, value);
    KeyFMap newMap = newCopyableMap.isEmpty() ? map.minus(COPYABLE_USER_MAP_KEY) : map.plus(COPYABLE_USER_MAP_KEY, newCopyableMap);
    if (newMap == map || changeUserMap(map, newMap)) {
      return;
    }
  }
}
项目:intellij-ce-playground    文件:UserDataHolderBase.java   
@Override
public <T> boolean replace(@NotNull Key<T> key, @Nullable T oldValue, @Nullable T newValue) {
  while (true) {
    KeyFMap map = getUserMap();
    if (map.get(key) != oldValue) {
      return false;
    }
    KeyFMap newMap = newValue == null ? map.minus(key) : map.plus(key, newValue);
    if (newMap == map || changeUserMap(map, newMap)) {
      return true;
    }
  }
}
项目:intellij-ce-playground    文件:UserDataHolderBase.java   
@Override
@NotNull
public <T> T putUserDataIfAbsent(@NotNull final Key<T> key, @NotNull final T value) {
  while (true) {
    KeyFMap map = getUserMap();
    T oldValue = map.get(key);
    if (oldValue != null) {
      return oldValue;
    }
    KeyFMap newMap = map.plus(key, value);
    if (newMap == map || changeUserMap(map, newMap)) {
      return value;
    }
  }
}
项目:tools-idea    文件:UserDataHolderBase.java   
@Override
public <T> void putUserData(@NotNull Key<T> key, @Nullable T value) {
  while (true) {
    KeyFMap map = myUserMap;
    KeyFMap newMap = value == null ? map.minus(key) : map.plus(key, value);
    if (newMap == map || updater.compareAndSet(this, map, newMap)) {
      break;
    }
  }
}
项目:tools-idea    文件:UserDataHolderBase.java   
public <T> void putCopyableUserData(Key<T> key, T value) {
  while (true) {
    KeyFMap map = myUserMap;
    KeyFMap copyableMap = map.get(COPYABLE_USER_MAP_KEY);
    if (copyableMap == null) {
      copyableMap = KeyFMap.EMPTY_MAP;
    }
    KeyFMap newCopyableMap = value == null ? copyableMap.minus(key) : copyableMap.plus(key, value);
    KeyFMap newMap = newCopyableMap.isEmpty() ? map.minus(COPYABLE_USER_MAP_KEY) : map.plus(COPYABLE_USER_MAP_KEY, newCopyableMap);
    if (newMap == map || updater.compareAndSet(this, map, newMap)) {
      return;
    }
  }
}
项目:tools-idea    文件:UserDataHolderBase.java   
@Override
public <T> boolean replace(@NotNull Key<T> key, @Nullable T oldValue, @Nullable T newValue) {
  while (true) {
    KeyFMap map = myUserMap;
    if (map.get(key) != oldValue) {
      return false;
    }
    KeyFMap newMap = newValue == null ? map.minus(key) : map.plus(key, newValue);
    if (newMap == map || updater.compareAndSet(this, map, newMap)) {
      return true;
    }
  }
}
项目:tools-idea    文件:UserDataHolderBase.java   
@Override
@NotNull
public <T> T putUserDataIfAbsent(@NotNull final Key<T> key, @NotNull final T value) {
  while (true) {
    KeyFMap map = myUserMap;
    T oldValue = map.get(key);
    if (oldValue != null) {
      return oldValue;
    }
    KeyFMap newMap = map.plus(key, value);
    if (newMap == map || updater.compareAndSet(this, map, newMap)) {
      return value;
    }
  }
}
项目:consulo    文件:VirtualDirectoryImpl.java   
static void checkLeaks(KeyFMap newMap) {
  for (Key key : newMap.getKeys()) {
    if (key != null && newMap.get(key) instanceof PsiCachedValue) {
      throw new AssertionError("Don't store CachedValue in VFS user data, since it leads to memory leaks");
    }
  }
}
项目:consulo    文件:VfsData.java   
KeyFMap getUserMap(VirtualFileSystemEntry file, int id) {
  Object o = myObjectArray.get(getOffset(id));
  if (!(o instanceof KeyFMap)) {
    throw reportDeadFileAccess(file);
  }
  return (KeyFMap)o;
}
项目:consulo    文件:UserDataInterner.java   
static KeyFMap internUserData(@Nonnull KeyFMap map) {
  if (shouldIntern(map)) {
    MapReference key = new MapReference(map);
    synchronized (ourCache) {
      KeyFMap cached = SoftReference.dereference(ourCache.get(key));
      if (cached != null) return cached;

      ourCache.put(key, key);
    }
    return map;
  }
  return map;
}
项目:consulo    文件:UserDataHolderBase.java   
@Override
public <T> void putUserData(@Nonnull Key<T> key, @Nullable T value) {
  while (true) {
    KeyFMap map = getUserMap();
    KeyFMap newMap = value == null ? map.minus(key) : map.plus(key, value);
    if (newMap == map || changeUserMap(map, newMap)) {
      break;
    }
  }
}
项目:consulo    文件:UserDataHolderBase.java   
public <T> void putCopyableUserData(Key<T> key, T value) {
  while (true) {
    KeyFMap map = getUserMap();
    KeyFMap copyableMap = map.get(COPYABLE_USER_MAP_KEY);
    if (copyableMap == null) {
      copyableMap = KeyFMap.EMPTY_MAP;
    }
    KeyFMap newCopyableMap = value == null ? copyableMap.minus(key) : copyableMap.plus(key, value);
    KeyFMap newMap = newCopyableMap.isEmpty() ? map.minus(COPYABLE_USER_MAP_KEY) : map.plus(COPYABLE_USER_MAP_KEY, newCopyableMap);
    if (newMap == map || changeUserMap(map, newMap)) {
      return;
    }
  }
}
项目:consulo    文件:UserDataHolderBase.java   
@Override
public <T> boolean replace(@Nonnull Key<T> key, @Nullable T oldValue, @Nullable T newValue) {
  while (true) {
    KeyFMap map = getUserMap();
    if (map.get(key) != oldValue) {
      return false;
    }
    KeyFMap newMap = newValue == null ? map.minus(key) : map.plus(key, newValue);
    if (newMap == map || changeUserMap(map, newMap)) {
      return true;
    }
  }
}
项目:consulo    文件:UserDataHolderBase.java   
@Override
@Nonnull
public <T> T putUserDataIfAbsent(@Nonnull final Key<T> key, @Nonnull final T value) {
  while (true) {
    KeyFMap map = getUserMap();
    T oldValue = map.get(key);
    if (oldValue != null) {
      return oldValue;
    }
    KeyFMap newMap = map.plus(key, value);
    if (newMap == map || changeUserMap(map, newMap)) {
      return value;
    }
  }
}
项目:intellij-ce-playground    文件:VirtualDirectoryImpl.java   
@Override
protected void setUserMap(@NotNull KeyFMap map) {
  myData.myUserMap = map;
}
项目:intellij-ce-playground    文件:VirtualDirectoryImpl.java   
@NotNull
@Override
protected KeyFMap getUserMap() {
  return myData.myUserMap;
}
项目:intellij-ce-playground    文件:VirtualDirectoryImpl.java   
@Override
protected boolean changeUserMap(KeyFMap oldMap, KeyFMap newMap) {
  checkLeaks(newMap);
  return myData.changeUserMap(oldMap, UserDataInterner.internUserData(newMap));
}
项目:intellij-ce-playground    文件:VfsData.java   
void setUserMap(int fileId, @NotNull KeyFMap map) {
  myObjectArray.set(getOffset(fileId), map);
}
项目:intellij-ce-playground    文件:VfsData.java   
boolean changeUserMap(int fileId, KeyFMap oldMap, KeyFMap newMap) {
  return myObjectArray.compareAndSet(getOffset(fileId), oldMap, newMap);
}
项目:intellij-ce-playground    文件:VfsData.java   
boolean changeUserMap(KeyFMap oldMap, KeyFMap newMap) {
  return updater.compareAndSet(this, oldMap, newMap);
}
项目:intellij-ce-playground    文件:UserDataInterner.java   
private static boolean shouldIntern(@NotNull KeyFMap map) {
  return map instanceof OneElementFMap || 
         map instanceof PairElementsFMap ||
         map instanceof ArrayBackedFMap && ((ArrayBackedFMap)map).getKeyIds().length <= 5;
}
项目:intellij-ce-playground    文件:UserDataInterner.java   
MapReference(KeyFMap referent) {
  super(referent);
  myHash = computeHashCode(referent);
}
项目:intellij-ce-playground    文件:VirtualFileImpl.java   
@Override
protected void setUserMap(@NotNull KeyFMap map) {
  mySegment.setUserMap(myId, map);
}
项目:intellij-ce-playground    文件:VirtualFileImpl.java   
@NotNull
@Override
protected KeyFMap getUserMap() {
  return mySegment.getUserMap(this, myId);
}
项目:intellij-ce-playground    文件:VirtualFileImpl.java   
@Override
protected boolean changeUserMap(KeyFMap oldMap, KeyFMap newMap) {
  VirtualDirectoryImpl.checkLeaks(newMap);
  return mySegment.changeUserMap(myId, oldMap, UserDataInterner.internUserData(newMap));
}
项目:intellij-ce-playground    文件:UserDataHolderBase.java   
@TestOnly
public String getUserDataString() {
  final KeyFMap userMap = getUserMap();
  final KeyFMap copyableMap = getUserData(COPYABLE_USER_MAP_KEY);
  return userMap + (copyableMap == null ? "" : copyableMap.toString());
}
项目:intellij-ce-playground    文件:UserDataHolderBase.java   
@NotNull
protected KeyFMap getUserMap() {
  return myUserMap;
}
项目:intellij-ce-playground    文件:UserDataHolderBase.java   
protected boolean changeUserMap(KeyFMap oldMap, KeyFMap newMap) {
  return updater.compareAndSet(this, oldMap, newMap);
}
项目:intellij-ce-playground    文件:UserDataHolderBase.java   
public <T> T getCopyableUserData(@NotNull Key<T> key) {
  KeyFMap map = getUserData(COPYABLE_USER_MAP_KEY);
  //noinspection unchecked,ConstantConditions
  return map == null ? null : map.get(key);
}
项目:intellij-ce-playground    文件:UserDataHolderBase.java   
protected void clearUserData() {
  setUserMap(KeyFMap.EMPTY_MAP);
}
项目:intellij-ce-playground    文件:UserDataHolderBase.java   
protected void setUserMap(@NotNull KeyFMap map) {
  myUserMap = map;
}
项目:tools-idea    文件:UserDataHolderBase.java   
@TestOnly
public String getUserDataString() {
  final KeyFMap userMap = myUserMap;
  final KeyFMap copyableMap = getUserData(COPYABLE_USER_MAP_KEY);
  return userMap.toString() + (copyableMap == null ? "" : copyableMap.toString());
}
项目:tools-idea    文件:UserDataHolderBase.java   
public <T> T getCopyableUserData(Key<T> key) {
  KeyFMap map = getUserData(COPYABLE_USER_MAP_KEY);
  //noinspection unchecked,ConstantConditions
  return map == null ? null : map.get(key);
}