KT-2688 Provide mutable/immutable interfaces for Java collections
#KT-2688 fixed
This commit is contained in:
@@ -0,0 +1,140 @@
|
||||
package jet
|
||||
|
||||
public trait Collection<out E> : Iterable<E>, Hashable {
|
||||
// Query Operations
|
||||
public fun size() : Int
|
||||
public fun isEmpty() : Boolean
|
||||
public fun contains(o : Any?) : Boolean
|
||||
override fun iterator() : Iterator<E>
|
||||
public fun toArray() : Array<Any?>
|
||||
public fun <T> toArray(a : Array<out T>) : Array<T>
|
||||
|
||||
// Bulk Operations
|
||||
public fun containsAll(c : Collection<out Any?>) : Boolean
|
||||
}
|
||||
|
||||
public trait MutableCollection<E> : Collection<E>, MutableIterable<E> {
|
||||
// Query Operations
|
||||
override fun iterator() : MutableIterator<E>
|
||||
|
||||
// Modification Operations
|
||||
public fun add(e : E) : Boolean
|
||||
public fun remove(o : Any?) : Boolean
|
||||
|
||||
// Bulk Modification Operations
|
||||
public fun addAll(c : Collection<out E>) : Boolean
|
||||
public fun removeAll(c : Collection<out Any?>) : Boolean
|
||||
public fun retainAll(c : Collection<out Any?>) : Boolean
|
||||
public fun clear()
|
||||
}
|
||||
|
||||
public trait List<out E> : Collection<E> {
|
||||
// Query Operations
|
||||
override fun size() : Int
|
||||
override fun isEmpty() : Boolean
|
||||
override fun contains(o : Any?) : Boolean
|
||||
override fun iterator() : Iterator<E>
|
||||
override fun toArray() : Array<Any?>
|
||||
override fun <T> toArray(a : Array<out T>) : Array<T>
|
||||
|
||||
// Bulk Operations
|
||||
override fun containsAll(c : Collection<out Any?>) : Boolean
|
||||
|
||||
// Positional Access Operations
|
||||
public fun get(index : Int) : E
|
||||
|
||||
// Search Operations
|
||||
public fun indexOf(o : Any?) : Int
|
||||
public fun lastIndexOf(o : Any?) : Int
|
||||
|
||||
// List Iterators
|
||||
public fun listIterator() : ListIterator<E>
|
||||
public fun listIterator(index : Int) : ListIterator<E>
|
||||
|
||||
// View
|
||||
public fun subList(fromIndex : Int, toIndex : Int) : List<E>
|
||||
}
|
||||
|
||||
public trait MutableList<E> : List<E>, MutableCollection<E> {
|
||||
// Modification Operations
|
||||
override fun add(e: E) : Boolean
|
||||
override fun remove(o : Any?) : Boolean
|
||||
|
||||
// Bulk Modification Operations
|
||||
override fun addAll(c : Collection<out E>) : Boolean
|
||||
public fun addAll(index : Int, c : Collection<out E>) : Boolean
|
||||
override fun removeAll(c : Collection<out Any?>) : Boolean
|
||||
override fun retainAll(c : Collection<out Any?>) : Boolean
|
||||
override fun clear()
|
||||
|
||||
// Positional Access Operations
|
||||
public fun set(index : Int, element : E) : E
|
||||
public fun add(index : Int, element : E)
|
||||
public fun remove(index : Int) : E
|
||||
}
|
||||
|
||||
public trait Set<out E> : Collection<E> {
|
||||
// Query Operations
|
||||
override fun size() : Int
|
||||
override fun isEmpty() : Boolean
|
||||
override fun contains(o : Any?) : Boolean
|
||||
override fun iterator() : Iterator<E>
|
||||
override fun toArray() : Array<Any?>
|
||||
override fun <T> toArray(a : Array<out T>) : Array<T>
|
||||
|
||||
// Bulk Operations
|
||||
override fun containsAll(c : Collection<out Any?>) : Boolean
|
||||
}
|
||||
|
||||
public trait MutableSet<E> : Set<E>, MutableCollection<E> {
|
||||
// Query Operations
|
||||
override fun iterator() : MutableIterator<E>
|
||||
|
||||
// Modification Operations
|
||||
override fun add(e: E) : Boolean
|
||||
override fun remove(o : Any?) : Boolean
|
||||
|
||||
// Bulk Modification Operations
|
||||
override fun addAll(c : Collection<out E>) : Boolean
|
||||
override fun removeAll(c : Collection<out Any?>) : Boolean
|
||||
override fun retainAll(c : Collection<out Any?>) : Boolean
|
||||
override fun clear()
|
||||
}
|
||||
|
||||
public trait Map<K, V> {
|
||||
// Query Operations
|
||||
public fun size() : Int
|
||||
public fun isEmpty() : Boolean
|
||||
public fun containsKey(key : Any?) : Boolean
|
||||
public fun containsValue(value : Any?) : Boolean
|
||||
public fun get(key : Any?) : V?
|
||||
|
||||
// Views
|
||||
public fun keySet() : Set<K>
|
||||
public fun values() : Collection<V>
|
||||
public fun entrySet() : Set<Map.Entry<K, V>>
|
||||
|
||||
public trait Entry<out K, out V> : Hashable {
|
||||
public fun getKey() : K
|
||||
public fun getValue() : V
|
||||
}
|
||||
}
|
||||
|
||||
public trait MutableMap<K, V> : Map<K, V> {
|
||||
// Modification Operations
|
||||
public fun put(key : K, value : V) : V?
|
||||
public fun remove(key : Any?) : V?
|
||||
|
||||
// Bulk Modification Operations
|
||||
public fun putAll(m : Map<out K, out V>)
|
||||
public fun clear()
|
||||
|
||||
// Views
|
||||
override fun keySet() : MutableSet<K>
|
||||
override fun values() : MutableCollection<V>
|
||||
override fun entrySet() : MutableSet<MutableMap.MutableEntry<K, V>>
|
||||
|
||||
public trait MutableEntry<K,V> : Map.Entry<K, V>, Hashable {
|
||||
public fun setValue(value : V) : V
|
||||
}
|
||||
}
|
||||
@@ -75,3 +75,24 @@ public fun FloatIterator.iterator() : FloatIterator
|
||||
|
||||
public fun LongIterator.iterator() : LongIterator
|
||||
|
||||
public trait ListIterator<T> : Iterator<T> {
|
||||
// Query Operations
|
||||
override fun hasNext() : Boolean
|
||||
override fun next() : T
|
||||
|
||||
public fun hasPrevious() : Boolean
|
||||
public fun previous() : T
|
||||
public fun nextIndex() : Int
|
||||
public fun previousIndex() : Int
|
||||
}
|
||||
|
||||
public trait MutableListIterator<T> : ListIterator<T>, MutableIterator<T> {
|
||||
// Query Operations
|
||||
override fun hasNext() : Boolean
|
||||
override fun next() : T
|
||||
|
||||
// Modification Operations
|
||||
override fun remove()
|
||||
public fun set(e : T)
|
||||
public fun add(e : T)
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.intellij.psi.PsiFileFactory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
@@ -119,7 +120,8 @@ public class JetStandardLibrary {
|
||||
"Iterables.jet",
|
||||
"Iterators.jet",
|
||||
"Arrays.jet",
|
||||
"Enum.jet"
|
||||
"Enum.jet",
|
||||
"Collections.jet"
|
||||
);
|
||||
try {
|
||||
List<JetFile> files = new LinkedList<JetFile>();
|
||||
@@ -371,6 +373,70 @@ public class JetStandardLibrary {
|
||||
return annotationType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getCollection() {
|
||||
return getStdClassByName("Collection");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getMutableCollection() {
|
||||
return getStdClassByName("MutableCollection");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getList() {
|
||||
return getStdClassByName("List");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getMutableList() {
|
||||
return getStdClassByName("MutableList");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getListIterator() {
|
||||
return getStdClassByName("ListIterator");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getMutableListIterator() {
|
||||
return getStdClassByName("MutableListIterator");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getSet() {
|
||||
return getStdClassByName("Set");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getMutableSet() {
|
||||
return getStdClassByName("MutableSet");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getMap() {
|
||||
return getStdClassByName("Map");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getMutableMap() {
|
||||
return getStdClassByName("MutableMap");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getMapEntry() {
|
||||
ClassifierDescriptor entry = getMap().getDefaultType().getMemberScope().getClassifier(Name.identifier("Entry"));
|
||||
assert entry instanceof ClassDescriptor;
|
||||
return (ClassDescriptor) entry;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getMutableMapEntry() {
|
||||
ClassifierDescriptor entry = getMutableMap().getDefaultType().getMemberScope().getClassifier(Name.identifier("MutableEntry"));
|
||||
assert entry instanceof ClassDescriptor;
|
||||
return (ClassDescriptor) entry;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetType getPrimitiveJetType(PrimitiveType primitiveType) {
|
||||
return primitiveTypeToJetType.get(primitiveType);
|
||||
|
||||
Reference in New Issue
Block a user