Search in sources :

Example 26 with TypeParser

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

the class TypeParserTests method testParamsVariance1.

@Test
public void testParamsVariance1() {
    Type type = new TypeParser(MockLoader.instance).decodeType("t2<in b,out c>", null, mockDefaultModule, mockPkgUnit);
    assertTypeWithParameters(type);
    Map<TypeParameter, SiteVariance> varianceOverrides = type.getVarianceOverrides();
    Assert.assertNotNull(varianceOverrides);
    Assert.assertEquals(2, varianceOverrides.size());
    List<TypeParameter> tps = type.getDeclaration().getTypeParameters();
    Assert.assertEquals(SiteVariance.IN, 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 27 with TypeParser

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

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 : 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) Test(org.junit.Test)

Example 28 with TypeParser

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

the class TypeParserTests method testEntryAbbrev.

@Test
public void testEntryAbbrev() {
    Type type = new TypeParser(MockLoader.instance).decodeType(" a -> b ", null, mockDefaultModule, mockDefaultUnit);
    Assert.assertNotNull(type);
    TypeDeclaration declaration = type.getDeclaration();
    Assert.assertNotNull(declaration);
    Assert.assertTrue(declaration instanceof Class);
    Assert.assertEquals("ceylon.language::Entry", declaration.getQualifiedNameString());
    Assert.assertEquals("ceylon.language::Entry<a,b>", printType(type));
    Assert.assertNull(type.getQualifyingType());
    type = new TypeParser(MockLoader.instance).decodeType("pkg::u|pkg::v->b", null, mockPkgModule, mockPkgUnit);
    Assert.assertNotNull(type);
    declaration = type.getDeclaration();
    Assert.assertNotNull(declaration);
    Assert.assertTrue(declaration instanceof Class);
    Assert.assertEquals("ceylon.language::Entry", declaration.getQualifiedNameString());
    Assert.assertEquals("ceylon.language::Entry<pkg::u|pkg::v,b>", 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) Class(com.redhat.ceylon.model.typechecker.model.Class) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) Test(org.junit.Test)

Example 29 with TypeParser

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

the class TypeParserTests method testPossiblyEmptyIterableAbbrev.

@Test
public void testPossiblyEmptyIterableAbbrev() {
    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 : 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 30 with TypeParser

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

the class TypeParserTests method testTuple3Abbrev.

@Test
public void testTuple3Abbrev() {
    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("[a, b, c]", 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)

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