Added handy add/addAll/getList methods for list keys in CompilerConfiguration.

This commit is contained in:
Evgeny Gerashchenko
2012-07-09 15:49:08 +04:00
parent 8124e477ce
commit 4332a60b31
@@ -21,6 +21,11 @@ import com.intellij.openapi.util.UserDataHolderBase;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
/**
* @author Evgeny Gerashchenko
* @since 7/3/12
@@ -28,11 +33,33 @@ import org.jetbrains.annotations.Nullable;
public class CompilerConfiguration {
private final UserDataHolderBase holder = new UserDataHolderBase();
@Nullable
public <T> T get(@NotNull Key<T> key) {
return holder.getUserData(key);
}
@NotNull
public <T> List<T> getList(@NotNull Key<List<T>> key) {
List<T> data = holder.getUserData(key);
if (data == null) {
return Collections.emptyList();
}
else {
return Collections.unmodifiableList(data);
}
}
public <T> void put(@NotNull Key<T> key, @Nullable T value) {
holder.putUserData(key, value);
}
public <T> void add(@NotNull Key<List<T>> key, @NotNull T value) {
List<T> list = holder.putUserDataIfAbsent(key, new CopyOnWriteArrayList<T>());
list.add(value);
}
public <T> void addAll(@NotNull Key<List<T>> key, @NotNull Collection<T> value) {
List<T> list = holder.putUserDataIfAbsent(key, new CopyOnWriteArrayList<T>());
list.addAll(value);
}
}