adaptSup + tests

This commit is contained in:
Florian Steurer 2015-11-15 18:39:22 +01:00
parent c45c426011
commit be6a719433
3 changed files with 16 additions and 14 deletions

View File

@ -413,16 +413,18 @@ public class RuleSet implements IRuleSet{
newRhs = new ExtendsType(lhsType); newRhs = new ExtendsType(lhsType);
} }
else { else {
lhsFromFc = new ExtendsType(finiteClosure.getType(((SuperType) lhsType).getSuperedType())); lhsFromFc = new SuperType(finiteClosure.getType(((SuperType) lhsType).getSuperedType()));
newRhs = new ExtendsType(((SuperType) lhsType).getSuperedType()); newRhs = new ExtendsType(((SuperType) lhsType).getSuperedType());
} }
if(lhsFromFc == null) Type rhsFromFc = finiteClosure.getType(((SuperType) rhsType).getSuperedType());
if(lhsFromFc == null || rhsFromFc == null)
return Optional.empty(); return Optional.empty();
Set<Type> grArg = finiteClosure.grArg(lhsFromFc); Set<Type> smArg = finiteClosure.smArg(new SuperType(rhsFromFc));
Optional<Type> opt = grArg.stream().filter(x -> x.getName().equals(rhsType.getName())).findAny(); Optional<Type> opt = smArg.stream().filter(x -> x.getName().equals(lhsType.getName())).findAny();
if(!opt.isPresent()) if(!opt.isPresent())
return Optional.empty(); return Optional.empty();
@ -437,6 +439,7 @@ public class RuleSet implements IRuleSet{
unif.andThen(new Unifier(lhsFromFcTypeParams.get(i), lhsTypeParams.get(i))); unif.andThen(new Unifier(lhsFromFcTypeParams.get(i), lhsTypeParams.get(i)));
return Optional.of(new MPair(newLhs.apply(unif), newRhs, PairOperator.SMALLERDOTWC)); return Optional.of(new MPair(newLhs.apply(unif), newRhs, PairOperator.SMALLERDOTWC));
} }
/** /**

View File

@ -92,9 +92,7 @@ public class FiniteClosure implements IFiniteClosure {
Set<Type> result = new HashSet<Type>(); Set<Type> result = new HashSet<Type>();
Type t = inheritanceGraph.get(type).getContent(); result.add(type);
result.add(t);
smaller(type).forEach(x -> result.add(new SuperType(x))); smaller(type).forEach(x -> result.add(new SuperType(x)));
greater(type).forEach(x -> result.add(new ExtendsType(x))); greater(type).forEach(x -> result.add(new ExtendsType(x)));
@ -108,7 +106,7 @@ public class FiniteClosure implements IFiniteClosure {
Set<Type> result = new HashSet<Type>(); Set<Type> result = new HashSet<Type>();
Type t = inheritanceGraph.get(type.getExtendedType()).getContent(); Type t = type.getExtendedType();
greater(t).forEach(x -> result.add(new ExtendsType(x))); greater(t).forEach(x -> result.add(new ExtendsType(x)));
@ -122,7 +120,7 @@ public class FiniteClosure implements IFiniteClosure {
Set<Type> result = new HashSet<Type>(); Set<Type> result = new HashSet<Type>();
Type t = inheritanceGraph.get(type.getSuperedType()).getContent(); Type t = type.getSuperedType();
smaller(t).forEach(x -> result.add(new SuperType(x))); smaller(t).forEach(x -> result.add(new SuperType(x)));
@ -146,9 +144,7 @@ public class FiniteClosure implements IFiniteClosure {
Set<Type> result = new HashSet<Type>(); Set<Type> result = new HashSet<Type>();
Type t = inheritanceGraph.get(type).getContent(); result.add(type);
result.add(t);
smaller(type).forEach(x -> result.add(new ExtendsType(x))); smaller(type).forEach(x -> result.add(new ExtendsType(x)));
return result; return result;
@ -160,7 +156,7 @@ public class FiniteClosure implements IFiniteClosure {
Set<Type> result = new HashSet<Type>(); Set<Type> result = new HashSet<Type>();
Type t = inheritanceGraph.get(type.getExtendedType()).getContent(); Type t = type.getExtendedType();
result.add(t); result.add(t);
smaller(t).forEach(x -> { smaller(t).forEach(x -> {
@ -179,7 +175,7 @@ public class FiniteClosure implements IFiniteClosure {
Set<Type> result = new HashSet<Type>(); Set<Type> result = new HashSet<Type>();
Type t = inheritanceGraph.get(type.getSuperedType()).getContent(); Type t = type.getSuperedType();
result.add(t); result.add(t);
greater(t).forEach(x -> { greater(t).forEach(x -> {

View File

@ -630,9 +630,12 @@ public class RuleSetTest {
SimpleType t1 = tf.getSimpleType("Type1", "T", "U"); SimpleType t1 = tf.getSimpleType("Type1", "T", "U");
SimpleType t2 = tf.getSimpleType("Type2", "T"); SimpleType t2 = tf.getSimpleType("Type2", "T");
SimpleType t3 = tf.getSimpleType("Type3", tf.getPlaceholderType("T"), tf.getSimpleType("Integer")); SimpleType t3 = tf.getSimpleType("Type3", tf.getPlaceholderType("T"), tf.getSimpleType("Integer"));
SimpleType t32 = tf.getSimpleType("Type3", "T", "U");
SimpleType t4 = tf.getSimpleType("Object");
fcb.add(t1, t2); fcb.add(t1, t2);
fcb.add(t2, t3); fcb.add(t2, t3);
fcb.add(t32, t4);
IRuleSet rules = new RuleSet(fcb.getFiniteClosure()); IRuleSet rules = new RuleSet(fcb.getFiniteClosure());