Added handy add/addAll/getList methods for list keys in CompilerConfiguration.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user