JavaCompilerCore/test/unify/FiniteClosureBuilder.java

84 lines
2.7 KiB
Java
Raw Normal View History

2015-11-07 16:21:17 +01:00
package unify;
import java.util.HashSet;
import java.util.Set;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
2015-12-27 00:29:23 +01:00
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
2016-03-17 16:54:43 +01:00
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
2016-04-01 18:21:51 +02:00
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
2015-11-07 16:21:17 +01:00
public class FiniteClosureBuilder {
private Set<UnifyPair> pairs = new HashSet<>();
2015-11-07 16:21:17 +01:00
2016-03-17 16:54:43 +01:00
public void add(UnifyType sub, UnifyType sup) {
pairs.add(new UnifyPair(sub, sup, PairOperator.SMALLER));
2015-11-07 16:21:17 +01:00
}
public IFiniteClosure getFiniteClosure() {
2015-11-08 21:23:20 +01:00
return new FiniteClosure(pairs);
}
public void clear() {
2015-11-07 16:21:17 +01:00
pairs = new HashSet<>();
}
public IFiniteClosure getCollectionExample() {
TypeFactory tf = new TypeFactory();
2016-04-01 18:21:51 +02:00
2016-03-26 14:09:45 +01:00
/* Collection */
2015-11-07 16:21:17 +01:00
2016-03-17 16:54:43 +01:00
UnifyType collection = tf.getSimpleType("Collection");
UnifyType set = tf.getSimpleType("Set", "T");
2016-03-28 01:01:46 +02:00
//Type sortedSet = tf.getSimpleType("SortedSet", "T"); Sorted set bei den Unit-Tests vergessen
// nachträgliches einfügen zu aufwendig
2016-03-17 16:54:43 +01:00
UnifyType TreeSet = tf.getSimpleType("TreeSet", "T");
UnifyType hashSet = tf.getSimpleType("HashSet", "T");
UnifyType linkedHashSet = tf.getSimpleType("LinkedHashSet", "T");
UnifyType queue = tf.getSimpleType("Queue", "T");
UnifyType deque = tf.getSimpleType("Deque", "T");
UnifyType linkedList = tf.getSimpleType("LinkedList", "T");
UnifyType list = tf.getSimpleType("List", "T");
UnifyType vector = tf.getSimpleType("Vector", "T");
UnifyType stack = tf.getSimpleType("Stack", "T");
2016-04-01 18:21:51 +02:00
UnifyType arrayList = tf.getSimpleType("ArrayList", "T");
2015-11-07 16:21:17 +01:00
add(set, collection);
2016-03-28 01:01:46 +02:00
//add(sortedSet, set);
add(TreeSet, set);
2015-11-07 16:21:17 +01:00
add(hashSet, set);
add(linkedHashSet, set);
add(queue, collection);
add(deque, queue);
add(linkedList, deque);
add(list, collection);
add(linkedList, list);
add(vector, list);
add(arrayList, list);
add(stack, vector);
2016-03-26 14:09:45 +01:00
/* Map */
2016-04-01 18:21:51 +02:00
UnifyType map = tf.getSimpleType("Map", "K", "V");
UnifyType sortedMap = tf.getSimpleType("SortedMap", "K", "V");
UnifyType navigableMap = tf.getSimpleType("NavigableMap", "K", "V");
UnifyType treeMap = tf.getSimpleType("TreeMap", "K", "V");
UnifyType hashMap = tf.getSimpleType("HashMap", "K", "V");
UnifyType hashtable = tf.getSimpleType("Hashtable", "K", "V");
UnifyType linkedHashMap = tf.getSimpleType("LinkedHashMap", "K", "V");
2016-03-26 14:09:45 +01:00
add(sortedMap, map);
add(hashMap, map);
add(hashtable, map);
add(navigableMap, sortedMap);
add(treeMap, navigableMap);
add(linkedHashMap, hashMap);
2015-11-08 21:23:20 +01:00
IFiniteClosure fc = getFiniteClosure();
clear();
return fc;
2015-11-07 16:21:17 +01:00
}
}