Search in sources :

Example 21 with TypeParser

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

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 : Type(org.eclipse.ceylon.model.typechecker.model.Type) IntersectionType(org.eclipse.ceylon.model.typechecker.model.IntersectionType) UnionType(org.eclipse.ceylon.model.typechecker.model.UnionType) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) TypeParser(org.eclipse.ceylon.model.loader.TypeParser) SiteVariance(org.eclipse.ceylon.model.typechecker.model.SiteVariance) Test(org.junit.Test)

Example 22 with TypeParser

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

the class TypeParserTests method testTuple1Abbrev.

@Test
public void testTuple1Abbrev() {
    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 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 23 with TypeParser

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

the class TypeParserTests method testOptionalEntry.

@Test
public void testOptionalEntry() {
    Type type = new TypeParser(MockLoader.instance).decodeType("<ceylon.language::Boolean->a>?", null, mockDefaultModule, mockPkgUnit);
    Assert.assertNotNull(type);
    TypeDeclaration declaration = type.getDeclaration();
    Assert.assertNotNull(declaration);
    Assert.assertTrue(declaration instanceof UnionType);
    Assert.assertEquals("ceylon.language::Null|ceylon.language::Entry<ceylon.language::Boolean,a>", 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)

Example 24 with TypeParser

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

the class TypeParserTests method testPackageQualified.

@Test
public void testPackageQualified() {
    Type type = new TypeParser(MockLoader.instance).decodeType("pkg::v", null, mockDefaultModule, mockPkgUnit);
    Assert.assertNotNull(type);
    TypeDeclaration declaration = type.getDeclaration();
    Assert.assertNotNull(declaration);
    Assert.assertTrue(declaration instanceof Class);
    Assert.assertEquals("pkg::v", declaration.getQualifiedNameString());
    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 25 with TypeParser

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

the class TypeParserTests method testTuple1To3StarAbbrev.

// [a,b=,c+] it not allowed (for good reason)
@Test
public void testTuple1To3StarAbbrev() {
    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 Class);
    Assert.assertEquals("ceylon.language::Tuple", declaration.getQualifiedNameString());
    Assert.assertEquals("ceylon.language::Tuple<a|b|c,a,ceylon.language::Empty|ceylon.language::Tuple<b|c,b,ceylon.language::Sequential<c>>>", 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) Class(org.eclipse.ceylon.model.typechecker.model.Class) 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