Search in sources :

Example 21 with Class

use of com.redhat.ceylon.model.typechecker.model.Class in project ceylon-compiler by ceylon.

the class TypeParserTests method testUnionParams.

@Test
public void testUnionParams() {
    Type type = new TypeParser(MockLoader.instance).decodeType("a|t2<b|c,t2<d,e|f>>", null, mockDefaultModule, mockPkgUnit);
    Assert.assertNotNull(type);
    TypeDeclaration declaration = type.getDeclaration();
    Assert.assertNotNull(declaration);
    Assert.assertTrue(declaration instanceof UnionType);
    UnionType union = (UnionType) declaration;
    List<Type> caseTypes = union.getCaseTypes();
    Assert.assertEquals(2, caseTypes.size());
    // a
    Assert.assertEquals("a", caseTypes.get(0).getDeclaration().getName());
    Assert.assertTrue(caseTypes.get(0).getDeclaration() instanceof Class);
    // first t2
    Type firstT2 = caseTypes.get(1);
    TypeDeclaration firstT2Declaration = firstT2.getDeclaration();
    Assert.assertNotNull(firstT2Declaration);
    Assert.assertTrue(firstT2Declaration instanceof Class);
    Assert.assertEquals("t2", firstT2Declaration.getName());
    Assert.assertEquals(2, firstT2.getTypeArgumentList().size());
    // b|c
    Type bc = firstT2.getTypeArgumentList().get(0);
    Assert.assertTrue(bc.getDeclaration() instanceof UnionType);
    Assert.assertEquals(2, bc.getDeclaration().getCaseTypes().size());
    // b
    Type b = bc.getDeclaration().getCaseTypes().get(0);
    Assert.assertEquals("b", b.getDeclaration().getName());
    Assert.assertTrue(b.getDeclaration() instanceof Class);
    // c
    Type c = bc.getDeclaration().getCaseTypes().get(1);
    Assert.assertEquals("c", c.getDeclaration().getName());
    Assert.assertTrue(c.getDeclaration() instanceof Class);
    // second t2
    Type secondT2 = firstT2.getTypeArgumentList().get(1);
    TypeDeclaration secondT2Declaration = firstT2.getDeclaration();
    Assert.assertNotNull(secondT2Declaration);
    Assert.assertTrue(secondT2Declaration instanceof Class);
    Assert.assertEquals("t2", secondT2Declaration.getName());
    Assert.assertEquals(2, secondT2.getTypeArgumentList().size());
    // d
    Type d = secondT2.getTypeArgumentList().get(0);
    Assert.assertEquals("d", d.getDeclaration().getName());
    Assert.assertTrue(d.getDeclaration() instanceof Class);
    // e|f
    Type ef = secondT2.getTypeArgumentList().get(1);
    Assert.assertTrue(ef.getDeclaration() instanceof UnionType);
    Assert.assertEquals(2, ef.getDeclaration().getCaseTypes().size());
    // e
    Type e = ef.getDeclaration().getCaseTypes().get(0);
    Assert.assertEquals("e", e.getDeclaration().getName());
    Assert.assertTrue(e.getDeclaration() instanceof Class);
    // f
    Type f = ef.getDeclaration().getCaseTypes().get(1);
    Assert.assertEquals("f", f.getDeclaration().getName());
    Assert.assertTrue(f.getDeclaration() instanceof Class);
}
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) Class(com.redhat.ceylon.model.typechecker.model.Class) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) Test(org.junit.Test)

Example 22 with Class

use of com.redhat.ceylon.model.typechecker.model.Class in project ceylon-compiler by ceylon.

the class TypeParserTests method testTuple3OrMoreAbbrev.

@Test
public void testTuple3OrMoreAbbrev() {
    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)

Example 23 with Class

use of com.redhat.ceylon.model.typechecker.model.Class in project ceylon-compiler by ceylon.

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 : 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 24 with Class

use of com.redhat.ceylon.model.typechecker.model.Class in project ceylon-compiler by ceylon.

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 : 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 25 with Class

use of com.redhat.ceylon.model.typechecker.model.Class in project ceylon-compiler by ceylon.

the class AbstractTransformer method getJavaArrayElementType.

private JCExpression getJavaArrayElementType(Type type, int flags) {
    if (type == null)
        return makeErroneous(null, "compiler bug: " + type + " is not a java array");
    type = simplifyType(type);
    if (type == null || type.getDeclaration() instanceof Class == false)
        return makeErroneous(null, "compiler bug: " + type + " is not a java array");
    Class c = (Class) type.getDeclaration();
    String name = c.getQualifiedNameString();
    if (name.equals("java.lang::ObjectArray")) {
        // fetch its type parameter
        if (type.getTypeArgumentList().size() != 1)
            return makeErroneous(null, "compiler bug: " + type + " is missing parameter type to java ObjectArray");
        Type elementType = type.getTypeArgumentList().get(0);
        if (elementType == null)
            return makeErroneous(null, "compiler bug: " + type + " has null parameter type to java ObjectArray");
        return make().TypeArray(makeJavaType(elementType, flags | JT_TYPE_ARGUMENT));
    } else if (name.equals("java.lang::ByteArray")) {
        return make().TypeArray(make().TypeIdent(TypeTags.BYTE));
    } else if (name.equals("java.lang::ShortArray")) {
        return make().TypeArray(make().TypeIdent(TypeTags.SHORT));
    } else if (name.equals("java.lang::IntArray")) {
        return make().TypeArray(make().TypeIdent(TypeTags.INT));
    } else if (name.equals("java.lang::LongArray")) {
        return make().TypeArray(make().TypeIdent(TypeTags.LONG));
    } else if (name.equals("java.lang::FloatArray")) {
        return make().TypeArray(make().TypeIdent(TypeTags.FLOAT));
    } else if (name.equals("java.lang::DoubleArray")) {
        return make().TypeArray(make().TypeIdent(TypeTags.DOUBLE));
    } else if (name.equals("java.lang::BooleanArray")) {
        return make().TypeArray(make().TypeIdent(TypeTags.BOOLEAN));
    } else if (name.equals("java.lang::CharArray")) {
        return make().TypeArray(make().TypeIdent(TypeTags.CHAR));
    } else {
        return makeErroneous(null, "compiler bug: " + type + " is an unknown java array type");
    }
}
Also used : Type(com.redhat.ceylon.model.typechecker.model.Type) ModelUtil.appliedType(com.redhat.ceylon.model.typechecker.model.ModelUtil.appliedType) Class(com.redhat.ceylon.model.typechecker.model.Class)

Aggregations

Class (com.redhat.ceylon.model.typechecker.model.Class)81 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)52 Type (com.redhat.ceylon.model.typechecker.model.Type)45 JCNewClass (com.sun.tools.javac.tree.JCTree.JCNewClass)37 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)28 TypedDeclaration (com.redhat.ceylon.model.typechecker.model.TypedDeclaration)26 Function (com.redhat.ceylon.model.typechecker.model.Function)23 IntersectionType (com.redhat.ceylon.model.typechecker.model.IntersectionType)22 UnionType (com.redhat.ceylon.model.typechecker.model.UnionType)22 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)22 TypeParser (com.redhat.ceylon.model.loader.TypeParser)21 Test (org.junit.Test)21 ClassOrInterface (com.redhat.ceylon.model.typechecker.model.ClassOrInterface)20 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)19 TypeParameter (com.redhat.ceylon.model.typechecker.model.TypeParameter)19 Value (com.redhat.ceylon.model.typechecker.model.Value)19 JCTree (com.sun.tools.javac.tree.JCTree)19 FunctionOrValue (com.redhat.ceylon.model.typechecker.model.FunctionOrValue)17 Interface (com.redhat.ceylon.model.typechecker.model.Interface)17 Parameter (com.redhat.ceylon.model.typechecker.model.Parameter)14