Search in sources :

Example 31 with TypeParser

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

the class TypeParserTests method testTuple2OrMoreAbbrev.

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

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

the class TypeParserTests method testParamsVariance3.

@Test
public void testParamsVariance3() {
    Type type = new TypeParser(MockLoader.instance).decodeType("t2<in b,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(SiteVariance.IN, varianceOverrides.get(tps.get(0)));
    Assert.assertEquals(null, 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 33 with TypeParser

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

the class TypeParserTests method testOptionalAbbrev.

@Test
public void testOptionalAbbrev() {
    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::Null|a", printType(type));
    Assert.assertNull(type.getQualifyingType());
    type = new TypeParser(MockLoader.instance).decodeType("pkg::u&pkg::v?", null, mockDefaultModule, mockPkgUnit);
    Assert.assertNotNull(type);
    declaration = type.getDeclaration();
    Assert.assertNotNull(declaration);
    Assert.assertTrue(declaration instanceof IntersectionType);
    Assert.assertEquals("pkg::u&<ceylon.language::Null|pkg::v>", printType(type));
    Assert.assertNull(type.getQualifyingType());
    type = new TypeParser(MockLoader.instance).decodeType("pkg::u|pkg::v[]?", null, mockDefaultModule, mockPkgUnit);
    Assert.assertNotNull(type);
    declaration = type.getDeclaration();
    Assert.assertNotNull(declaration);
    Assert.assertTrue(declaration instanceof UnionType);
    Assert.assertEquals("pkg::u|ceylon.language::Null|ceylon.language::Sequential<pkg::v>", printType(type));
    Assert.assertNull(type.getQualifyingType());
}
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) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) Test(org.junit.Test)

Example 34 with TypeParser

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

the class TypeParserTests method testSpreadCallableAbbrev.

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

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

the class TypeParserTests method testQualified.

@Test
public void testQualified() {
    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("a.b", declaration.getQualifiedNameString());
    Type qualifyingType = type.getQualifyingType();
    Assert.assertNotNull(qualifyingType);
    TypeDeclaration qualifyingDeclaration = qualifyingType.getDeclaration();
    Assert.assertNotNull(qualifyingDeclaration);
    Assert.assertTrue(qualifyingDeclaration instanceof Class);
    Assert.assertEquals("a", qualifyingDeclaration.getName());
}
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