Search in sources :

Example 1 with TypeParser

use of com.redhat.ceylon.model.loader.TypeParser in project ceylon-compiler by ceylon.

the class TypeParserTests method testCallableAbbrev.

@Test
public void testCallableAbbrev() {
    Type type = new TypeParser(MockLoader.instance).decodeType("a(b)", null, mockDefaultModule, mockPkgUnit);
    Assert.assertNotNull(type);
    TypeDeclaration declaration = type.getDeclaration();
    Assert.assertNotNull(declaration);
    Assert.assertTrue(declaration instanceof Interface);
    Assert.assertEquals("ceylon.language::Callable", declaration.getQualifiedNameString());
    Assert.assertEquals("a(b)", type.asString());
    Assert.assertNull(type.getQualifyingType());
    type = new TypeParser(MockLoader.instance).decodeType("a(b,pkg::u*)", null, mockPkgModule, mockPkgUnit);
    Assert.assertNotNull(type);
    declaration = type.getDeclaration();
    Assert.assertNotNull(declaration);
    Assert.assertTrue(declaration instanceof Interface);
    Assert.assertEquals("ceylon.language::Callable", declaration.getQualifiedNameString());
    Assert.assertEquals("ceylon.language::Callable<a,ceylon.language::Tuple<b|pkg::u,b,ceylon.language::Sequential<pkg::u>>>", printType(type));
    Assert.assertNull(type.getQualifyingType());
    type = new TypeParser(MockLoader.instance).decodeType("a(b=,pkg::u*)", null, mockPkgModule, mockPkgUnit);
    Assert.assertNotNull(type);
    declaration = type.getDeclaration();
    Assert.assertNotNull(declaration);
    Assert.assertTrue(declaration instanceof Interface);
    Assert.assertEquals("ceylon.language::Callable", declaration.getQualifiedNameString());
    Assert.assertEquals("ceylon.language::Callable<a,ceylon.language::Empty|ceylon.language::Tuple<b|pkg::u,b,ceylon.language::Sequential<pkg::u>>>", printType(type));
    Assert.assertNull(type.getQualifyingType());
}
Also used : IntersectionType(com.redhat.ceylon.model.typechecker.model.IntersectionType) Type(com.redhat.ceylon.model.typechecker.model.Type) UnionType(com.redhat.ceylon.model.typechecker.model.UnionType) TypeParser(com.redhat.ceylon.model.loader.TypeParser) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) Interface(com.redhat.ceylon.model.typechecker.model.Interface) ClassOrInterface(com.redhat.ceylon.model.typechecker.model.ClassOrInterface) Test(org.junit.Test)

Example 2 with TypeParser

use of com.redhat.ceylon.model.loader.TypeParser in project ceylon-compiler by ceylon.

the class TypeParserTests method testParamsVariance2.

@Test
public void testParamsVariance2() {
    Type type = new TypeParser(MockLoader.instance).decodeType("t2<b,out c>", null, mockDefaultModule, mockPkgUnit);
    assertTypeWithParameters(type);
    Map<TypeParameter, SiteVariance> varianceOverrides = type.getVarianceOverrides();
    Assert.assertNotNull(varianceOverrides);
    Assert.assertEquals(1, varianceOverrides.size());
    List<TypeParameter> tps = type.getDeclaration().getTypeParameters();
    Assert.assertEquals(null, varianceOverrides.get(tps.get(0)));
    Assert.assertEquals(SiteVariance.OUT, varianceOverrides.get(tps.get(1)));
}
Also used : IntersectionType(com.redhat.ceylon.model.typechecker.model.IntersectionType) Type(com.redhat.ceylon.model.typechecker.model.Type) UnionType(com.redhat.ceylon.model.typechecker.model.UnionType) TypeParameter(com.redhat.ceylon.model.typechecker.model.TypeParameter) TypeParser(com.redhat.ceylon.model.loader.TypeParser) SiteVariance(com.redhat.ceylon.model.typechecker.model.SiteVariance) Test(org.junit.Test)

Example 3 with TypeParser

use of com.redhat.ceylon.model.loader.TypeParser in project ceylon-compiler by ceylon.

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);
}
Also used : UnionType(com.redhat.ceylon.model.typechecker.model.UnionType) IntersectionType(com.redhat.ceylon.model.typechecker.model.IntersectionType) Type(com.redhat.ceylon.model.typechecker.model.Type) UnionType(com.redhat.ceylon.model.typechecker.model.UnionType) TypeParser(com.redhat.ceylon.model.loader.TypeParser) IntersectionType(com.redhat.ceylon.model.typechecker.model.IntersectionType) Class(com.redhat.ceylon.model.typechecker.model.Class) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) Test(org.junit.Test)

Example 4 with TypeParser

use of com.redhat.ceylon.model.loader.TypeParser in project ceylon-compiler by ceylon.

the class TypeParserTests method testTuple2Abbrev.

@Test
public void testTuple2Abbrev() {
    Type type = new TypeParser(MockLoader.instance).decodeType("[a,b]", null, mockDefaultModule, mockPkgUnit);
    Assert.assertNotNull(type);
    TypeDeclaration declaration = type.getDeclaration();
    Assert.assertNotNull(declaration);
    Assert.assertTrue(declaration instanceof Class);
    Assert.assertEquals("ceylon.language::Tuple", declaration.getQualifiedNameString());
    Assert.assertEquals("[a, b]", type.asString());
    Assert.assertNull(type.getQualifyingType());
}
Also used : IntersectionType(com.redhat.ceylon.model.typechecker.model.IntersectionType) Type(com.redhat.ceylon.model.typechecker.model.Type) UnionType(com.redhat.ceylon.model.typechecker.model.UnionType) TypeParser(com.redhat.ceylon.model.loader.TypeParser) Class(com.redhat.ceylon.model.typechecker.model.Class) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) Test(org.junit.Test)

Example 5 with TypeParser

use of com.redhat.ceylon.model.loader.TypeParser in project ceylon-compiler by ceylon.

the class TypeParserTests method testQualifiedAndParameterised.

@Test
public void testQualifiedAndParameterised() {
    Type type = new TypeParser(MockLoader.instance).decodeType("t2<a,b>.t2<c,d>", null, mockDefaultModule, mockPkgUnit);
    Assert.assertNotNull(type);
    TypeDeclaration declaration = type.getDeclaration();
    Assert.assertNotNull(declaration);
    Assert.assertTrue(declaration instanceof Class);
    Assert.assertEquals("t2.t2", declaration.getQualifiedNameString());
    Assert.assertEquals(2, type.getTypeArgumentList().size());
    // c
    Type c = type.getTypeArgumentList().get(0);
    Assert.assertEquals("c", c.getDeclaration().getName());
    Assert.assertTrue(c.getDeclaration() instanceof Class);
    // d
    Type d = type.getTypeArgumentList().get(1);
    Assert.assertEquals("d", d.getDeclaration().getName());
    Assert.assertTrue(d.getDeclaration() instanceof Class);
    Type qualifyingType = type.getQualifyingType();
    Assert.assertNotNull(qualifyingType);
    TypeDeclaration qualifyingDeclaration = qualifyingType.getDeclaration();
    Assert.assertNotNull(qualifyingDeclaration);
    Assert.assertTrue(qualifyingDeclaration instanceof Class);
    Assert.assertEquals("t2", qualifyingDeclaration.getName());
    Assert.assertEquals(2, qualifyingType.getTypeArgumentList().size());
    // a
    Type a = qualifyingType.getTypeArgumentList().get(0);
    Assert.assertEquals("a", a.getDeclaration().getName());
    Assert.assertTrue(a.getDeclaration() instanceof Class);
    // b
    Type b = qualifyingType.getTypeArgumentList().get(1);
    Assert.assertEquals("b", b.getDeclaration().getName());
    Assert.assertTrue(b.getDeclaration() instanceof Class);
}
Also used : IntersectionType(com.redhat.ceylon.model.typechecker.model.IntersectionType) Type(com.redhat.ceylon.model.typechecker.model.Type) UnionType(com.redhat.ceylon.model.typechecker.model.UnionType) TypeParser(com.redhat.ceylon.model.loader.TypeParser) Class(com.redhat.ceylon.model.typechecker.model.Class) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) Test(org.junit.Test)

Aggregations

TypeParser (com.redhat.ceylon.model.loader.TypeParser)37 Test (org.junit.Test)37 IntersectionType (com.redhat.ceylon.model.typechecker.model.IntersectionType)36 Type (com.redhat.ceylon.model.typechecker.model.Type)36 UnionType (com.redhat.ceylon.model.typechecker.model.UnionType)36 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)32 Class (com.redhat.ceylon.model.typechecker.model.Class)21 ClassOrInterface (com.redhat.ceylon.model.typechecker.model.ClassOrInterface)8 Interface (com.redhat.ceylon.model.typechecker.model.Interface)8 SiteVariance (com.redhat.ceylon.model.typechecker.model.SiteVariance)3 TypeParameter (com.redhat.ceylon.model.typechecker.model.TypeParameter)3 TypeParserException (com.redhat.ceylon.model.loader.TypeParserException)1