Search in sources :

Example 6 with TypeParser

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

the class TypeParserTests method testSequenceAbbrev.

@Test
public void testSequenceAbbrev() {
    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::Sequence", 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 7 with TypeParser

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

the class TypeParserTests method testIntersectionAndUnion.

@Test
public void testIntersectionAndUnion() {
    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 UnionType);
    UnionType union = (UnionType) declaration;
    List<Type> unionTypes = union.getCaseTypes();
    Assert.assertEquals(2, unionTypes.size());
    Assert.assertTrue(unionTypes.get(0).getDeclaration() instanceof IntersectionType);
    IntersectionType intersection = (IntersectionType) unionTypes.get(0).getDeclaration();
    List<Type> intersectionTypes = intersection.getSatisfiedTypes();
    Assert.assertEquals(2, intersectionTypes.size());
    Assert.assertEquals("a", intersectionTypes.get(0).getDeclaration().getName());
    Assert.assertTrue(intersectionTypes.get(0).getDeclaration() instanceof Class);
    Assert.assertEquals("b", intersectionTypes.get(1).getDeclaration().getName());
    Assert.assertTrue(intersectionTypes.get(1).getDeclaration() instanceof Class);
    Assert.assertEquals("c", unionTypes.get(1).getDeclaration().getName());
    Assert.assertTrue(unionTypes.get(1).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) IntersectionType(org.eclipse.ceylon.model.typechecker.model.IntersectionType) Class(org.eclipse.ceylon.model.typechecker.model.Class) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Test(org.junit.Test)

Example 8 with TypeParser

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

the class TypeParserTests method testCallableOfEntry.

@Test
public void testCallableOfEntry() {
    Type type = new TypeParser(MockLoader.instance).decodeType("ceylon.language::Boolean(ceylon.language::Nothing->ceylon.language::Nothing)", null, mockDefaultModule, mockPkgUnit);
    Assert.assertNotNull(type);
    TypeDeclaration declaration = type.getDeclaration();
    Assert.assertNotNull(declaration);
    Assert.assertTrue(declaration instanceof Interface);
    Assert.assertEquals("ceylon.language::Callable<ceylon.language::Boolean,ceylon.language::Tuple<ceylon.language::Entry<ceylon.language::Nothing,ceylon.language::Nothing>,ceylon.language::Entry<ceylon.language::Nothing,ceylon.language::Nothing>,ceylon.language::Empty>>", 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 9 with TypeParser

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

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

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

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 : 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