Search in sources :

Example 41 with Type

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

the class UnknownTypeCollector method collectUnknownTypesResolved.

private void collectUnknownTypesResolved(Type type, Map<Declaration, Declaration> visited) {
    if (type != null) {
        collectUnknownTypes(type, visited);
        List<Type> typeArguments = type.getTypeArgumentList();
        // cheaper c-for than foreach
        for (int i = 0, l = typeArguments.size(); i < l; i++) {
            Type tl = typeArguments.get(i);
            collectUnknownTypesResolved(tl, visited);
        }
    }
}
Also used : UnknownType(com.redhat.ceylon.model.typechecker.model.UnknownType) Type(com.redhat.ceylon.model.typechecker.model.Type)

Example 42 with Type

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

the class CeylonEnter method resetClassSymbol.

/**
     * This resets a ClassSymbol recursively, for bootstrap
     */
private void resetClassSymbol(ClassSymbol classSymbol) {
    // look for inner classes
    if (classSymbol.members_field != null) {
        for (Symbol member : classSymbol.getEnclosedElements()) {
            if (member instanceof ClassSymbol) {
                resetClassSymbol((ClassSymbol) member);
            }
        }
    }
    // reset its type, we need to keep it
    com.sun.tools.javac.code.Type.ClassType classType = (ClassType) classSymbol.type;
    classType.all_interfaces_field = null;
    classType.interfaces_field = null;
    classType.supertype_field = null;
    classType.typarams_field = null;
    // reset its members and completer
    classSymbol.members_field = null;
    classSymbol.completer = null;
    classSymbol.attributes_field = List.nil();
}
Also used : ClassType(com.sun.tools.javac.code.Type.ClassType) Type(com.redhat.ceylon.model.typechecker.model.Type) ClassType(com.sun.tools.javac.code.Type.ClassType) ClassSymbol(com.sun.tools.javac.code.Symbol.ClassSymbol) Symbol(com.sun.tools.javac.code.Symbol) PackageSymbol(com.sun.tools.javac.code.Symbol.PackageSymbol) ClassSymbol(com.sun.tools.javac.code.Symbol.ClassSymbol) ClassType(com.sun.tools.javac.code.Type.ClassType)

Example 43 with Type

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

the class TypeParserTests method assertTypeWithParameters.

private void assertTypeWithParameters(Type type) {
    Assert.assertNotNull(type);
    TypeDeclaration declaration = type.getDeclaration();
    Assert.assertNotNull(declaration);
    Assert.assertTrue(declaration instanceof Class);
    Assert.assertEquals("t2", declaration.getName());
    List<Type> tal = type.getTypeArgumentList();
    Assert.assertEquals(2, tal.size());
    Assert.assertEquals("b", tal.get(0).getDeclaration().getName());
    Assert.assertTrue(tal.get(0).getDeclaration() instanceof Class);
    Assert.assertEquals("c", tal.get(1).getDeclaration().getName());
    Assert.assertTrue(tal.get(1).getDeclaration() instanceof Class);
}
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) Class(com.redhat.ceylon.model.typechecker.model.Class) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration)

Example 44 with Type

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

the class TypeParserTests method testCallableAbbrev.

@Test
public void testCallableAbbrev() {
    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 Interface);
    Assert.assertEquals("ceylon.language::Callable", declaration.getQualifiedNameString());
    Assert.assertEquals("a(b)", type.asString());
    Assert.assertNull(type.getQualifyingType());
    type = new TypeParser(MockLoader.instance).decodeType("a(b,pkg::u*)", null, mockPkgModule, mockPkgUnit);
    Assert.assertNotNull(type);
    declaration = type.getDeclaration();
    Assert.assertNotNull(declaration);
    Assert.assertTrue(declaration instanceof Interface);
    Assert.assertEquals("ceylon.language::Callable", declaration.getQualifiedNameString());
    Assert.assertEquals("ceylon.language::Callable<a,ceylon.language::Tuple<b|pkg::u,b,ceylon.language::Sequential<pkg::u>>>", printType(type));
    Assert.assertNull(type.getQualifyingType());
    type = new TypeParser(MockLoader.instance).decodeType("a(b=,pkg::u*)", null, mockPkgModule, mockPkgUnit);
    Assert.assertNotNull(type);
    declaration = type.getDeclaration();
    Assert.assertNotNull(declaration);
    Assert.assertTrue(declaration instanceof Interface);
    Assert.assertEquals("ceylon.language::Callable", declaration.getQualifiedNameString());
    Assert.assertEquals("ceylon.language::Callable<a,ceylon.language::Empty|ceylon.language::Tuple<b|pkg::u,b,ceylon.language::Sequential<pkg::u>>>", 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) 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 45 with Type

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

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

Aggregations

Type (com.redhat.ceylon.model.typechecker.model.Type)237 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)98 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)87 TypeParameter (com.redhat.ceylon.model.typechecker.model.TypeParameter)56 JCTree (com.sun.tools.javac.tree.JCTree)53 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)51 ModelUtil.appliedType (com.redhat.ceylon.model.typechecker.model.ModelUtil.appliedType)46 Class (com.redhat.ceylon.model.typechecker.model.Class)45 ClassOrInterface (com.redhat.ceylon.model.typechecker.model.ClassOrInterface)43 TypedDeclaration (com.redhat.ceylon.model.typechecker.model.TypedDeclaration)41 IntersectionType (com.redhat.ceylon.model.typechecker.model.IntersectionType)37 UnionType (com.redhat.ceylon.model.typechecker.model.UnionType)37 Test (org.junit.Test)37 TypeParser (com.redhat.ceylon.model.loader.TypeParser)36 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)34 Function (com.redhat.ceylon.model.typechecker.model.Function)33 Interface (com.redhat.ceylon.model.typechecker.model.Interface)30 JCTypeParameter (com.sun.tools.javac.tree.JCTree.JCTypeParameter)30 TypedReference (com.redhat.ceylon.model.typechecker.model.TypedReference)29 ArrayList (java.util.ArrayList)28