Search in sources :

Example 11 with TypeParser

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

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 : 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 12 with TypeParser

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

the class TypeParserTests method testHomoTuple2.

@Test
public void testHomoTuple2() {
    Type type = new TypeParser(MockLoader.instance).decodeType("a[2]", 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[2]", 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 13 with TypeParser

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

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 : 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 14 with TypeParser

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

the class TypeParserTests method testParams.

@Test
public void testParams() {
    Type type = new TypeParser(MockLoader.instance).decodeType("t2<b,c>", null, mockDefaultModule, mockPkgUnit);
    assertTypeWithParameters(type);
    Assert.assertTrue(type.getVarianceOverrides().isEmpty());
}
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) Test(org.junit.Test)

Example 15 with TypeParser

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

the class TypeParserTests method testTuple0To1Abbrev.

@Test
public void testTuple0To1Abbrev() {
    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 UnionType);
    Assert.assertEquals("ceylon.language::Empty|ceylon.language::Tuple<a,a,ceylon.language::Empty>", printType(type));
    Assert.assertNull(type.getQualifyingType());
}
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) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) 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