Search in sources :

Example 1 with LazyInterface

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

the class Metamodel method getTypeDescriptorForProducedType.

public static TypeDescriptor getTypeDescriptorForProducedType(org.eclipse.ceylon.model.typechecker.model.Type type) {
    TypeDeclaration declaration = type.getDeclaration();
    if (type.isNothing()) {
        return TypeDescriptor.NothingType;
    }
    if (type.isUnion()) {
        TypeDescriptor[] tdArgs = getTypeDescriptorsForProducedTypes(type.getCaseTypes());
        return TypeDescriptor.union(tdArgs);
    }
    if (type.isIntersection()) {
        TypeDescriptor[] tdArgs = getTypeDescriptorsForProducedTypes(type.getSatisfiedTypes());
        return TypeDescriptor.intersection(tdArgs);
    }
    if (declaration instanceof LazyClass) {
        ReflectionClass classMirror = (ReflectionClass) ((LazyClass) declaration).classMirror;
        TypeDescriptor[] tdArgs = getTypeDescriptorsForProducedTypes(type.getTypeArgumentList());
        TypeDescriptor ret = TypeDescriptor.klass(classMirror.klass, tdArgs);
        if (type.getQualifyingType() != null)
            return TypeDescriptor.member(getTypeDescriptorForProducedType(type.getQualifyingType()), ret);
        return ret;
    }
    if (declaration instanceof LazyInterface) {
        ReflectionClass classMirror = (ReflectionClass) ((LazyInterface) declaration).classMirror;
        TypeDescriptor[] tdArgs = getTypeDescriptorsForProducedTypes(type.getTypeArgumentList());
        TypeDescriptor ret = TypeDescriptor.klass(classMirror.klass, tdArgs);
        if (type.getQualifyingType() != null)
            return TypeDescriptor.member(getTypeDescriptorForProducedType(type.getQualifyingType()), ret);
        return ret;
    }
    if (declaration instanceof FunctionOrValueInterface) {
        TypedDeclaration underlyingDeclaration = ((FunctionOrValueInterface) declaration).getUnderlyingDeclaration();
        TypeDescriptor[] tdArgs = getTypeDescriptorsForProducedTypes(type.getTypeArgumentList());
        TypeDescriptor ret;
        if (underlyingDeclaration.isToplevel()) {
            ReflectionClass classMirror;
            // type arguments
            if (underlyingDeclaration instanceof Setter)
                underlyingDeclaration = ((Setter) underlyingDeclaration).getGetter();
            if (underlyingDeclaration instanceof LazyValue)
                classMirror = (ReflectionClass) ((LazyValue) underlyingDeclaration).classMirror;
            else if (underlyingDeclaration instanceof LazyFunction)
                classMirror = (ReflectionClass) ((LazyFunction) underlyingDeclaration).classMirror;
            else
                throw Metamodel.newModelError("Unsupported underlying declaration type: " + underlyingDeclaration);
            ret = TypeDescriptor.functionOrValue(classMirror.klass, tdArgs);
        } else
            ret = TypeDescriptor.functionOrValue(underlyingDeclaration.getPrefixedName(), tdArgs);
        if (type.getQualifyingType() != null)
            return TypeDescriptor.member(getTypeDescriptorForProducedType(type.getQualifyingType()), ret);
        return ret;
    }
    if (declaration instanceof UnknownType) {
        ((UnknownType) declaration).reportErrors();
    }
    throw Metamodel.newModelError("Unsupported declaration type: " + (declaration == null ? "null" : declaration.getClass()));
}
Also used : FunctionOrValueInterface(org.eclipse.ceylon.model.loader.model.FunctionOrValueInterface) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) LazyValue(org.eclipse.ceylon.model.loader.model.LazyValue) TypeDescriptor(org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor) ReflectionClass(org.eclipse.ceylon.model.loader.impl.reflect.mirror.ReflectionClass) LazyInterface(org.eclipse.ceylon.model.loader.model.LazyInterface) Setter(org.eclipse.ceylon.model.typechecker.model.Setter) LazyFunction(org.eclipse.ceylon.model.loader.model.LazyFunction) LazyClass(org.eclipse.ceylon.model.loader.model.LazyClass) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)

Example 2 with LazyInterface

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

the class AbstractModelLoader method addInnerClassesFromAnnotation.

private void addInnerClassesFromAnnotation(ClassOrInterface klass, AnnotationMirror membersAnnotation) {
    @SuppressWarnings("unchecked") List<AnnotationMirror> members = (List<AnnotationMirror>) membersAnnotation.getValue();
    for (AnnotationMirror member : members) {
        TypeMirror javaClassMirror = (TypeMirror) member.getValue("klass");
        String javaClassName;
        // void.class is the default value, I guess it's a primitive?
        if (javaClassMirror != null && !javaClassMirror.isPrimitive()) {
            javaClassName = javaClassMirror.getQualifiedName();
        } else {
            // we get the class name as a string
            String name = (String) member.getValue("javaClassName");
            ClassMirror container = null;
            if (klass instanceof LazyClass) {
                container = ((LazyClass) klass).classMirror;
            } else if (klass instanceof LazyInterface) {
                if (((LazyInterface) klass).isCeylon())
                    container = ((LazyInterface) klass).companionClass;
                else
                    container = ((LazyInterface) klass).classMirror;
            }
            if (container == null)
                throw new ModelResolutionException("Unknown container type: " + klass + " when trying to load inner class " + name);
            javaClassName = container.getQualifiedName() + "$" + name;
        }
        Declaration innerDecl = convertToDeclaration(ModelUtil.getModuleContainer(klass), klass, javaClassName, DeclarationType.TYPE);
        if (innerDecl == null)
            throw new ModelResolutionException("Failed to load inner type " + javaClassName + " for outer type " + klass.getQualifiedNameString());
        if (shouldLinkNatives(innerDecl)) {
            initNativeHeaderMember(innerDecl);
        }
    }
}
Also used : AnnotationMirror(org.eclipse.ceylon.model.loader.mirror.AnnotationMirror) TypeMirror(org.eclipse.ceylon.model.loader.mirror.TypeMirror) LazyInterface(org.eclipse.ceylon.model.loader.model.LazyInterface) List(java.util.List) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) LazyClass(org.eclipse.ceylon.model.loader.model.LazyClass) ClassMirror(org.eclipse.ceylon.model.loader.mirror.ClassMirror)

Example 3 with LazyInterface

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

the class AbstractModelLoader method findLocalContainerFromAnnotationAndSetCompanionClass.

private Scope findLocalContainerFromAnnotationAndSetCompanionClass(Package pkg, Interface declaration, AnnotationMirror localContainerAnnotation) {
    @SuppressWarnings("unchecked") List<String> path = (List<String>) localContainerAnnotation.getValue("path");
    // we start at the package
    Scope scope = pkg;
    for (String name : path) {
        scope = (Scope) getDirectMember(scope, name);
    }
    String companionClassName = (String) localContainerAnnotation.getValue("companionClassName");
    if (companionClassName == null || companionClassName.isEmpty()) {
        declaration.setCompanionClassNeeded(false);
        return scope;
    }
    ClassMirror container;
    Scope javaClassScope;
    if (scope instanceof TypedDeclaration && ((TypedDeclaration) scope).isMember())
        javaClassScope = scope.getContainer();
    else
        javaClassScope = scope;
    if (javaClassScope instanceof LazyInterface) {
        container = ((LazyInterface) javaClassScope).companionClass;
    } else if (javaClassScope instanceof LazyClass) {
        container = ((LazyClass) javaClassScope).classMirror;
    } else if (javaClassScope instanceof LazyValue) {
        container = ((LazyValue) javaClassScope).classMirror;
    } else if (javaClassScope instanceof LazyFunction) {
        container = ((LazyFunction) javaClassScope).classMirror;
    } else if (javaClassScope instanceof SetterWithLocalDeclarations) {
        container = ((SetterWithLocalDeclarations) javaClassScope).classMirror;
    } else {
        throw new ModelResolutionException("Unknown scope class: " + javaClassScope);
    }
    String qualifiedCompanionClassName = container.getQualifiedName() + "$" + companionClassName;
    ClassMirror companionClassMirror = lookupClassMirror(pkg.getModule(), qualifiedCompanionClassName);
    if (companionClassMirror == null)
        throw new ModelResolutionException("Could not find companion class mirror: " + qualifiedCompanionClassName);
    ((LazyInterface) declaration).companionClass = companionClassMirror;
    return scope;
}
Also used : TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) LazyValue(org.eclipse.ceylon.model.loader.model.LazyValue) LazyFunction(org.eclipse.ceylon.model.loader.model.LazyFunction) ClassMirror(org.eclipse.ceylon.model.loader.mirror.ClassMirror) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) LazyInterface(org.eclipse.ceylon.model.loader.model.LazyInterface) SetterWithLocalDeclarations(org.eclipse.ceylon.model.loader.model.SetterWithLocalDeclarations) List(java.util.List) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) LazyClass(org.eclipse.ceylon.model.loader.model.LazyClass)

Example 4 with LazyInterface

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

the class AbstractModelLoader method makeLazyInterface.

protected LazyInterface makeLazyInterface(ClassMirror classMirror, boolean isNativeHeader) {
    LazyInterface iface = new LazyInterface(classMirror, this);
    iface.setSealed(classMirror.getAnnotation(CEYLON_LANGUAGE_SEALED_ANNOTATION) != null);
    iface.setDynamic(classMirror.getAnnotation(CEYLON_DYNAMIC_ANNOTATION) != null);
    if (iface.isCeylon()) {
        AnnotationMirror container = classMirror.getAnnotation(CEYLON_CONTAINER_ANNOTATION);
        if (container != null) {
            Object value = container.getValue("isStatic");
            if (value != null) {
                iface.setStatic(Boolean.TRUE.equals(value));
            }
        }
    } else {
        iface.setStatic(classMirror.getEnclosingClass() != null);
    }
    manageNativeBackend(iface, classMirror, isNativeHeader);
    return iface;
}
Also used : AnnotationMirror(org.eclipse.ceylon.model.loader.mirror.AnnotationMirror) LazyInterface(org.eclipse.ceylon.model.loader.model.LazyInterface)

Example 5 with LazyInterface

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

the class AbstractModelLoader method setInterfaceCompanionClass.

protected void setInterfaceCompanionClass(Declaration d, ClassOrInterface container, LazyPackage pkg) {
    // find its companion class in its real container
    ClassMirror containerMirror = null;
    if (container instanceof LazyClass) {
        containerMirror = ((LazyClass) container).classMirror;
    } else if (container instanceof LazyInterface) {
        // container must be a LazyInterface, as TypeAlias doesn't contain anything
        containerMirror = ((LazyInterface) container).companionClass;
        if (containerMirror == null) {
            throw new ModelResolutionException("Interface companion class for " + container.getQualifiedNameString() + " not set up");
        }
    }
    String companionName;
    if (containerMirror != null)
        companionName = containerMirror.getFlatName() + "$" + NamingBase.suffixName(NamingBase.Suffix.$impl, d.getName());
    else {
        // toplevel
        String p = pkg.getNameAsString();
        companionName = "";
        if (!p.isEmpty())
            companionName = p + ".";
        companionName += NamingBase.suffixName(NamingBase.Suffix.$impl, d.getName());
    }
    ClassMirror companionClass = lookupClassMirror(pkg.getModule(), companionName);
    if (companionClass == null) {
        ((Interface) d).setCompanionClassNeeded(false);
    }
    ((LazyInterface) d).companionClass = companionClass;
}
Also used : LazyInterface(org.eclipse.ceylon.model.loader.model.LazyInterface) LazyClass(org.eclipse.ceylon.model.loader.model.LazyClass) ClassMirror(org.eclipse.ceylon.model.loader.mirror.ClassMirror) Interface(org.eclipse.ceylon.model.typechecker.model.Interface) ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) LazyInterface(org.eclipse.ceylon.model.loader.model.LazyInterface)

Aggregations

LazyInterface (org.eclipse.ceylon.model.loader.model.LazyInterface)9 LazyClass (org.eclipse.ceylon.model.loader.model.LazyClass)8 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)7 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)6 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)5 ArrayList (java.util.ArrayList)4 LinkedList (java.util.LinkedList)4 List (java.util.List)4 ClassMirror (org.eclipse.ceylon.model.loader.mirror.ClassMirror)4 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)4 ParameterList (org.eclipse.ceylon.model.typechecker.model.ParameterList)4 AnnotationProxyClass (org.eclipse.ceylon.model.loader.model.AnnotationProxyClass)3 LazyFunction (org.eclipse.ceylon.model.loader.model.LazyFunction)3 LazyValue (org.eclipse.ceylon.model.loader.model.LazyValue)3 Class (org.eclipse.ceylon.model.typechecker.model.Class)3 Scope (org.eclipse.ceylon.model.typechecker.model.Scope)3 AnnotationMirror (org.eclipse.ceylon.model.loader.mirror.AnnotationMirror)2 MethodMirror (org.eclipse.ceylon.model.loader.mirror.MethodMirror)2 FieldValue (org.eclipse.ceylon.model.loader.model.FieldValue)2 JavaBeanValue (org.eclipse.ceylon.model.loader.model.JavaBeanValue)2