use of org.eclipse.ceylon.model.typechecker.model.IntersectionType in project ceylon by eclipse.
the class TypeHierarchyVisitor method visitDAGNode.
private void visitDAGNode(TypeDeclaration declaration, List<Type> sortedDag, Set<TypeDeclaration> visited, List<TypeDeclaration> stackOfProcessedType, Node errorReporter) {
if (declaration == null) {
return;
}
if (checkCyclicInheritance(declaration, stackOfProcessedType, errorReporter)) {
// stop the cycle here but try and process the rest
return;
}
if (visited.contains(declaration)) {
return;
}
visited.add(declaration);
Type type = getOrBuildType(declaration);
stackOfProcessedType.add(declaration);
org.eclipse.ceylon.model.typechecker.model.Type extendedType = declaration.getExtendedType();
if (extendedType != null) {
visitDAGNode(extendedType.getDeclaration(), sortedDag, visited, stackOfProcessedType, errorReporter);
}
for (org.eclipse.ceylon.model.typechecker.model.Type superSatisfiedType : declaration.getSatisfiedTypes()) {
if (superSatisfiedType != null) {
visitDAGNode(superSatisfiedType.getDeclaration(), sortedDag, visited, stackOfProcessedType, errorReporter);
}
}
for (org.eclipse.ceylon.model.typechecker.model.Type superSatisfiedType : declaration.getBrokenSupertypes()) {
TypeDeclaration typeDec = superSatisfiedType.getDeclaration();
if (!(typeDec instanceof UnionType) && !(typeDec instanceof IntersectionType)) {
visitDAGNode(typeDec, sortedDag, visited, stackOfProcessedType, errorReporter);
}
}
stackOfProcessedType.remove(stackOfProcessedType.size() - 1);
sortedDag.add(type);
}
use of org.eclipse.ceylon.model.typechecker.model.IntersectionType in project ceylon by eclipse.
the class TypeParserTests method testIntersectionAndUnion.
@Test
public void testIntersectionAndUnion() {
Type type = new TypeParser(MockLoader.instance).decodeType("a&b|c", null, mockDefaultModule, mockPkgUnit);
Assert.assertNotNull(type);
TypeDeclaration declaration = type.getDeclaration();
Assert.assertNotNull(declaration);
Assert.assertTrue(declaration instanceof UnionType);
UnionType union = (UnionType) declaration;
List<Type> unionTypes = union.getCaseTypes();
Assert.assertEquals(2, unionTypes.size());
Assert.assertTrue(unionTypes.get(0).getDeclaration() instanceof IntersectionType);
IntersectionType intersection = (IntersectionType) unionTypes.get(0).getDeclaration();
List<Type> intersectionTypes = intersection.getSatisfiedTypes();
Assert.assertEquals(2, intersectionTypes.size());
Assert.assertEquals("a", intersectionTypes.get(0).getDeclaration().getName());
Assert.assertTrue(intersectionTypes.get(0).getDeclaration() instanceof Class);
Assert.assertEquals("b", intersectionTypes.get(1).getDeclaration().getName());
Assert.assertTrue(intersectionTypes.get(1).getDeclaration() instanceof Class);
Assert.assertEquals("c", unionTypes.get(1).getDeclaration().getName());
Assert.assertTrue(unionTypes.get(1).getDeclaration() instanceof Class);
}
use of org.eclipse.ceylon.model.typechecker.model.IntersectionType in project ceylon by eclipse.
the class RefinementVisitor method checkRefinedMemberTypeAssignable.
private void checkRefinedMemberTypeAssignable(Reference refiningMember, Reference refinedMember, Node that, Declaration refined, Declaration refining) {
Unit unit = that.getUnit();
Type refiningType = refiningMember.getType();
Type refinedType = refinedMember.getType();
if (!isTypeUnknown(refinedType)) {
if (that instanceof Tree.LocalModifier) {
// infer the type of an actual member
// by taking the intersection of all
// members it refines
// NOTE: feature not blessed by the spec!
TypedDeclaration td = (TypedDeclaration) refining;
Tree.LocalModifier mod = (Tree.LocalModifier) that;
Type t;
t = isTypeUnknown(refiningType) ? refinedType : intersectionType(refinedType, refiningType, unit);
td.setType(t);
mod.setTypeModel(t);
return;
}
checkAssignableIgnoringNull(refiningType, refinedType, that, refined, "type of member must be assignable to type of refined member " + message(refined), 9000);
checkSmallRefinement(that, refiningMember.getDeclaration(), refinedMember.getDeclaration());
}
}
use of org.eclipse.ceylon.model.typechecker.model.IntersectionType in project ceylon by eclipse.
the class DeclarationVisitor method visit.
public void visit(Tree.IntersectionType that) {
super.visit(that);
if (inExtends) {
final List<Tree.StaticType> sts = that.getStaticTypes();
Type t = new LazyType(unit) {
@Override
public TypeDeclaration initDeclaration() {
List<Type> types = new ArrayList<Type>(sts.size());
for (Tree.StaticType st : sts) {
Type t = st.getTypeModel();
if (t != null) {
types.add(t);
}
}
IntersectionType it = new IntersectionType(unit);
it.setSatisfiedTypes(types);
return it;
}
@Override
public Map<TypeParameter, Type> initTypeArguments() {
return emptyMap();
}
};
that.setTypeModel(t);
}
}
use of org.eclipse.ceylon.model.typechecker.model.IntersectionType in project ceylon by eclipse.
the class TypeParserTests method testComplexQualified.
@Test
public void testComplexQualified() {
Type type = new TypeParser(MockLoader.instance).decodeType("<pkg::u&pkg::v>.w", null, mockDefaultModule, mockPkgUnit);
Assert.assertNotNull(type);
TypeDeclaration declaration = type.getDeclaration();
Assert.assertNotNull(declaration);
Assert.assertTrue(declaration instanceof Class);
Assert.assertEquals("pkg::v.w", declaration.getQualifiedNameString());
Type qualifyingType = type.getQualifyingType();
Assert.assertNotNull(qualifyingType);
TypeDeclaration qualifyingDeclaration = qualifyingType.getDeclaration();
Assert.assertNotNull(qualifyingDeclaration);
Assert.assertTrue(qualifyingDeclaration instanceof IntersectionType);
Assert.assertEquals("u&v", qualifyingDeclaration.getName());
}
Aggregations