mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
NULL object
This commit is contained in:
@@ -19,8 +19,11 @@ package com.intellij.psi.impl;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.psi.util.CachedValue;
|
||||
import com.intellij.psi.util.CachedValueProvider;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import static com.intellij.util.ObjectUtils.*;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
*/
|
||||
|
||||
@@ -28,9 +28,12 @@ import com.intellij.psi.util.CachedValueProvider;
|
||||
import com.intellij.psi.util.ParameterizedCachedValueProvider;
|
||||
import com.intellij.psi.util.ParameterizedCachedValue;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import static com.intellij.util.ObjectUtils.*;
|
||||
|
||||
public abstract class PsiParameterizedCachedValue<T,P> extends PsiCachedValue<T> implements ParameterizedCachedValue<T,P> {
|
||||
|
||||
private final ParameterizedCachedValueProvider<T,P> myProvider;
|
||||
|
||||
@@ -35,11 +35,12 @@ import java.lang.ref.Reference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.intellij.util.ObjectUtils.*;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
*/
|
||||
public abstract class CachedValueBase<T> {
|
||||
protected static final Object NULL = new Object();
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.CachedValueImpl");
|
||||
|
||||
private final MyTimedReference<T> myData = new MyTimedReference<T>();
|
||||
@@ -66,7 +67,7 @@ public abstract class CachedValueBase<T> {
|
||||
}
|
||||
|
||||
protected void setValue(final T value, final CachedValueProvider.Result<T> result) {
|
||||
myData.setData(computeData(value == null ? (T) NULL : value, getDependencies(result)));
|
||||
myData.setData(computeData(value == null ? (T)NULL : value, getDependencies(result)));
|
||||
if (result != null) {
|
||||
myData.setIsLocked(result.isLockValue());
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public abstract class CachedValueImpl<T> extends CachedValueBase<T> implements C
|
||||
try {
|
||||
value = getUpToDateOrNull();
|
||||
if (value != null) {
|
||||
return value == NULL ? null : value;
|
||||
return value == ObjectUtils.NULL ? null : value;
|
||||
}
|
||||
} finally {
|
||||
r.unlock();
|
||||
@@ -58,7 +58,7 @@ public abstract class CachedValueImpl<T> extends CachedValueBase<T> implements C
|
||||
try {
|
||||
value = getUpToDateOrNull();
|
||||
if (value != null) {
|
||||
return value == NULL ? null : value;
|
||||
return value == ObjectUtils.NULL ? null : value;
|
||||
}
|
||||
|
||||
CachedValueProvider.Result<T> result = myProvider.compute();
|
||||
|
||||
@@ -30,6 +30,8 @@ import com.intellij.psi.util.ParameterizedCachedValueProvider;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import static com.intellij.util.ObjectUtils.*;
|
||||
|
||||
public abstract class ParameterizedCachedValueImpl<T,P> extends CachedValueBase<T> implements ParameterizedCachedValue<T,P> {
|
||||
|
||||
private final ParameterizedCachedValueProvider<T,P> myProvider;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.intellij.openapi.util;
|
||||
|
||||
import com.intellij.util.NullableFunction;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -23,7 +24,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
* @author peter
|
||||
*/
|
||||
public class NullableLazyKey<T,H extends UserDataHolder> extends Key<T>{
|
||||
private static final Object NULL = new Object();
|
||||
private final NullableFunction<H,T> myFunction;
|
||||
|
||||
private NullableLazyKey(@NonNls String name, final NullableFunction<H, T> function) {
|
||||
@@ -36,9 +36,9 @@ public class NullableLazyKey<T,H extends UserDataHolder> extends Key<T>{
|
||||
T data = h.getUserData(this);
|
||||
if (data == null) {
|
||||
data = myFunction.fun(h);
|
||||
h.putUserData(this, data == null ? (T)NULL : data);
|
||||
h.putUserData(this, data == null ? (T)ObjectUtils.NULL : data);
|
||||
}
|
||||
return data == NULL ? null : data;
|
||||
return data == ObjectUtils.NULL ? null : data;
|
||||
}
|
||||
|
||||
public static <T,H extends UserDataHolder> NullableLazyKey<T,H> create(@NonNls String name, final NullableFunction<H, T> function) {
|
||||
|
||||
@@ -25,6 +25,8 @@ public class ObjectUtils {
|
||||
private ObjectUtils() {
|
||||
}
|
||||
|
||||
public static final Object NULL = new Object();
|
||||
|
||||
@NotNull
|
||||
public static <T> T assertNotNull(@Nullable final T t) {
|
||||
return _assertNotNull(t);
|
||||
|
||||
@@ -21,11 +21,12 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.*;
|
||||
import java.util.HashSet;
|
||||
|
||||
import static com.intellij.util.ObjectUtils.NULL;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public abstract class FactoryMap<K,V> implements Map<K, V> {
|
||||
static final Object NULL = new Object();
|
||||
protected Map<K,V> myMap;
|
||||
|
||||
protected Map<K, V> createMap() {
|
||||
|
||||
@@ -19,6 +19,8 @@ package com.intellij.util.containers;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import static com.intellij.util.ObjectUtils.NULL;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
@@ -32,15 +34,15 @@ public abstract class SoftFactoryMap<T,V> {
|
||||
if (reference != null) {
|
||||
final V v = reference.get();
|
||||
if (v != null) {
|
||||
return v == FactoryMap.NULL ? null : v;
|
||||
return v == NULL ? null : v;
|
||||
}
|
||||
}
|
||||
|
||||
final V value = create(key);
|
||||
SoftReference<V> valueRef = new SoftReference<V>(value == null ? (V)FactoryMap.NULL : value);
|
||||
SoftReference<V> valueRef = new SoftReference<V>(value == null ? (V)NULL : value);
|
||||
SoftReference<V> prevRef = myMap.putIfAbsent(key, valueRef);
|
||||
V prev = prevRef == null ? null : prevRef.get();
|
||||
return prev == null || prev == FactoryMap.NULL? value : prev;
|
||||
return prev == null || prev == NULL ? value : prev;
|
||||
}
|
||||
|
||||
public final boolean containsKey(T key) {
|
||||
|
||||
@@ -18,6 +18,8 @@ package com.intellij.util.containers;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import static com.intellij.util.ObjectUtils.NULL;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
@@ -31,15 +33,15 @@ public abstract class WeakFactoryMap<T,V> {
|
||||
if (reference != null) {
|
||||
final V v = reference.get();
|
||||
if (v != null) {
|
||||
return v == FactoryMap.NULL ? null : v;
|
||||
return v == NULL ? null : v;
|
||||
}
|
||||
}
|
||||
|
||||
final V value = create(key);
|
||||
WeakReference<V> valueRef = new WeakReference<V>(value == null ? (V)FactoryMap.NULL : value);
|
||||
WeakReference<V> valueRef = new WeakReference<V>(value == null ? (V)NULL : value);
|
||||
WeakReference<V> prevRef = myMap.putIfAbsent(key, valueRef);
|
||||
V prev = prevRef == null ? null : prevRef.get();
|
||||
return prev == null || prev == FactoryMap.NULL? value : prev;
|
||||
return prev == null || prev == NULL ? value : prev;
|
||||
}
|
||||
|
||||
public final boolean containsKey(T key) {
|
||||
|
||||
Reference in New Issue
Block a user