Search in sources :

Example 16 with TypeParser

use of org.eclipse.ceylon.model.loader.TypeParser in project ceylon by eclipse.

the class TypeParserTests method testHomoTuple1.

@Test
public void testHomoTuple1() {
    Type type = new TypeParser(MockLoader.instance).decodeType("a[1]", 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]", type.asString());
    Assert.assertNull(type.getQualifyingType());
}
Also used : Type(org.eclipse.ceylon.model.typechecker.model.Type) IntersectionType(org.eclipse.ceylon.model.typechecker.model.IntersectionType) UnionType(org.eclipse.ceylon.model.typechecker.model.UnionType) TypeParser(org.eclipse.ceylon.model.loader.TypeParser) Class(org.eclipse.ceylon.model.typechecker.model.Class) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Test(org.junit.Test)

Example 17 with TypeParser

use of org.eclipse.ceylon.model.loader.TypeParser in project ceylon by eclipse.

the class TypeParserTests method testUnionParams.

@Test
public void testUnionParams() {
    Type type = new TypeParser(MockLoader.instance).decodeType("a|t2<b|c,t2<d,e|f>>", null, mockDefaultModule, mockPkgUnit);
    Assert.assertNotNull(type);
    TypeDeclaration declaration = type.getDeclaration();
    Assert.assertNotNull(declaration);
    Assert.assertTrue(declaration instanceof UnionType);
    UnionType union = (UnionType) declaration;
    List<Type> caseTypes = union.getCaseTypes();
    Assert.assertEquals(2, caseTypes.size());
    // a
    Assert.assertEquals("a", caseTypes.get(0).getDeclaration().getName());
    Assert.assertTrue(caseTypes.get(0).getDeclaration() instanceof Class);
    // first t2
    Type firstT2 = caseTypes.get(1);
    TypeDeclaration firstT2Declaration = firstT2.getDeclaration();
    Assert.assertNotNull(firstT2Declaration);
    Assert.assertTrue(firstT2Declaration instanceof Class);
    Assert.assertEquals("t2", firstT2Declaration.getName());
    Assert.assertEquals(2, firstT2.getTypeArgumentList().size());
    // b|c
    Type bc = firstT2.getTypeArgumentList().get(0);
    Assert.assertTrue(bc.getDeclaration() instanceof UnionType);
    Assert.assertEquals(2, bc.getDeclaration().getCaseTypes().size());
    // b
    Type b = bc.getDeclaration().getCaseTypes().get(0);
    Assert.assertEquals("b", b.getDeclaration().getName());
    Assert.assertTrue(b.getDeclaration() instanceof Class);
    // c
    Type c = bc.getDeclaration().getCaseTypes().get(1);
    Assert.assertEquals("c", c.getDeclaration().getName());
    Assert.assertTrue(c.getDeclaration() instanceof Class);
    // second t2
    Type secondT2 = firstT2.getTypeArgumentList().get(1);
    TypeDeclaration secondT2Declaration = firstT2.getDeclaration();
    Assert.assertNotNull(secondT2Declaration);
    Assert.assertTrue(secondT2Declaration instanceof Class);
    Assert.assertEquals("t2", secondT2Declaration.getName());
    Assert.assertEquals(2, secondT2.getTypeArgumentList().size());
    // d
    Type d = secondT2.getTypeArgumentList().get(0);
    Assert.assertEquals("d", d.getDeclaration().getName());
    Assert.assertTrue(d.getDeclaration() instanceof Class);
    // e|f
    Type ef = secondT2.getTypeArgumentList().get(1);
    Assert.assertTrue(ef.getDeclaration() instanceof UnionType);
    Assert.assertEquals(2, ef.getDeclaration().getCaseTypes().size());
    // e
    Type e = ef.getDeclaration().getCaseTypes().get(0);
    Assert.assertEquals("e", e.getDeclaration().getName());
    Assert.assertTrue(e.getDeclaration() instanceof Class);
    // f
    Type f = ef.getDeclaration().getCaseTypes().get(1);
    Assert.assertEquals("f", f.getDeclaration().getName());
    Assert.assertTrue(f.getDeclaration() instanceof Class);
}
Also used : UnionType(org.eclipse.ceylon.model.typechecker.model.UnionType) Type(org.eclipse.ceylon.model.typechecker.model.Type) IntersectionType(org.eclipse.ceylon.model.typechecker.model.IntersectionType) UnionType(org.eclipse.ceylon.model.typechecker.model.UnionType) TypeParser(org.eclipse.ceylon.model.loader.TypeParser) Class(org.eclipse.ceylon.model.typechecker.model.Class) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Test(org.junit.Test)

Example 18 with TypeParser

use of org.eclipse.ceylon.model.loader.TypeParser in project ceylon by eclipse.

the class TypeParserTests method testSequentialAbbrev.

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

Example 19 with TypeParser

use of org.eclipse.ceylon.model.loader.TypeParser in project ceylon by eclipse.

the class TypeParserTests method testNonEmptyIterableAbbrev.

@Test
public void testNonEmptyIterableAbbrev() {
    Type type = new TypeParser(MockLoader.instance).decodeType("{a+}", null, mockDefaultModule, mockPkgUnit);
    Assert.assertNotNull(type);
    TypeDeclaration declaration = type.getDeclaration();
    Assert.assertNotNull(declaration);
    Assert.assertTrue(declaration instanceof Interface);
    Assert.assertEquals("ceylon.language::Iterable", declaration.getQualifiedNameString());
    Assert.assertEquals("{a+}", type.asString());
    Assert.assertNull(type.getQualifyingType());
}
Also used : Type(org.eclipse.ceylon.model.typechecker.model.Type) IntersectionType(org.eclipse.ceylon.model.typechecker.model.IntersectionType) UnionType(org.eclipse.ceylon.model.typechecker.model.UnionType) TypeParser(org.eclipse.ceylon.model.loader.TypeParser) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Interface(org.eclipse.ceylon.model.typechecker.model.Interface) ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) Test(org.junit.Test)

Example 20 with TypeParser

use of org.eclipse.ceylon.model.loader.TypeParser in project ceylon by eclipse.

the class TypeParserTests method testIterableAbbrev.

@Test
public void testIterableAbbrev() {
    try {
        new TypeParser(MockLoader.instance).decodeType("{a}", null, mockDefaultModule, mockPkgUnit);
        Assert.fail();
    } catch (TypeParserException e) {
        Assert.assertEquals("org.eclipse.ceylon.model.loader.TypeParserException: Expected multiplicity in abbreviated Iterable type: 2", e.toString());
    }
}
Also used : TypeParser(org.eclipse.ceylon.model.loader.TypeParser) TypeParserException(org.eclipse.ceylon.model.loader.TypeParserException) Test(org.junit.Test)

Aggregations

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