Search in sources :

Example 1 with TypeMirror

use of org.eclipse.ceylon.model.loader.mirror.TypeMirror in project ceylon by eclipse.

the class AnnotationLoader method setPrimaryFromAnnotationInvocationAnnotation.

private void setPrimaryFromAnnotationInvocationAnnotation(AnnotationMirror annotationInvocationAnnotation, AnnotationInvocation ai) {
    TypeMirror annotationType = (TypeMirror) annotationInvocationAnnotation.getValue(AbstractModelLoader.CEYLON_ANNOTATION_INSTANTIATION_ANNOTATION_MEMBER);
    ClassMirror annotationClassMirror = annotationType.getDeclaredClass();
    Module module = modelLoader.findModuleForClassMirror(annotationClassMirror);
    if (annotationClassMirror.getAnnotation(AbstractModelLoader.CEYLON_METHOD_ANNOTATION) != null) {
        ai.setPrimary((Function) modelLoader.convertToDeclaration(module, annotationClassMirror, DeclarationType.VALUE));
    } else {
        ai.setPrimary((Class) modelLoader.convertToDeclaration(module, annotationClassMirror, DeclarationType.TYPE));
    }
}
Also used : TypeMirror(org.eclipse.ceylon.model.loader.mirror.TypeMirror) Module(org.eclipse.ceylon.model.typechecker.model.Module) ClassMirror(org.eclipse.ceylon.model.loader.mirror.ClassMirror)

Example 2 with TypeMirror

use of org.eclipse.ceylon.model.loader.mirror.TypeMirror in project ceylon by eclipse.

the class CeylonModelLoader method getFunctionalInterfaceType.

@Override
protected FunctionalInterfaceType getFunctionalInterfaceType(TypeMirror typeMirror) throws ModelResolutionException {
    if (typeMirror.getKind() != TypeKind.DECLARED)
        throw new ModelResolutionException("Failed to find functional interface type in " + typeMirror);
    // FIXME: possibly apply other optimisations to lighten the lookup cost? see what javac does
    Type type = ((JavacType) typeMirror).type;
    try {
        Type descriptorType = types.findDescriptorType(type);
        // Let's be honest I've no idea what this means, but it happens and Javac seems to refuse it too
        if (descriptorType.hasTag(TypeTag.FORALL))
            throw new ModelResolutionException("Failed to find functional interface type in " + typeMirror);
        MethodType methodDescriptorType = (MethodType) descriptorType;
        MethodSymbol methodSymbol = (MethodSymbol) types.findDescriptorSymbol(type.tsym);
        List<Type> parameterTypes = methodDescriptorType.getParameterTypes();
        ListBuffer<TypeMirror> mirrorParameterTypes = new ListBuffer<>();
        for (int i = 0; i < parameterTypes.size(); i++) {
            Type parameterType = parameterTypes.get(i);
            if (methodSymbol.isVarArgs() && i == parameterTypes.size() - 1)
                parameterType = ((ArrayType) parameterType).getComponentType();
            mirrorParameterTypes.add(new JavacType(parameterType));
        }
        return new FunctionalInterfaceType(new JavacMethod(new JavacClass(methodSymbol.enclClass()), methodSymbol), new JavacType(methodDescriptorType.getReturnType()), mirrorParameterTypes.toList(), methodSymbol.isVarArgs());
    } catch (Symbol.CompletionFailure err) {
        // bad luck
        throw new ModelResolutionException("Failed to find functional interface type in " + typeMirror, err);
    } catch (FunctionDescriptorLookupError err) {
        throw new ModelResolutionException("Failed to find functional interface type in " + typeMirror, err);
    }
}
Also used : JavacType(org.eclipse.ceylon.compiler.java.loader.mirror.JavacType) MethodType(org.eclipse.ceylon.langtools.tools.javac.code.Type.MethodType) FunctionalInterfaceType(org.eclipse.ceylon.model.loader.mirror.FunctionalInterfaceType) JavacMethod(org.eclipse.ceylon.compiler.java.loader.mirror.JavacMethod) CompletionFailure(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.CompletionFailure) MethodSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.MethodSymbol) TypeSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.TypeSymbol) ClassSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol) Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol) PackageSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.PackageSymbol) ListBuffer(org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer) ArrayType(org.eclipse.ceylon.langtools.tools.javac.code.Type.ArrayType) ModelResolutionException(org.eclipse.ceylon.model.loader.ModelResolutionException) MethodType(org.eclipse.ceylon.langtools.tools.javac.code.Type.MethodType) Type(org.eclipse.ceylon.langtools.tools.javac.code.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) ArrayType(org.eclipse.ceylon.langtools.tools.javac.code.Type.ArrayType) JavacType(org.eclipse.ceylon.compiler.java.loader.mirror.JavacType) FunctionalInterfaceType(org.eclipse.ceylon.model.loader.mirror.FunctionalInterfaceType) MethodSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.MethodSymbol) TypeMirror(org.eclipse.ceylon.model.loader.mirror.TypeMirror) JavacClass(org.eclipse.ceylon.compiler.java.loader.mirror.JavacClass) FunctionDescriptorLookupError(org.eclipse.ceylon.langtools.tools.javac.code.Types.FunctionDescriptorLookupError)

Example 3 with TypeMirror

use of org.eclipse.ceylon.model.loader.mirror.TypeMirror in project ceylon by eclipse.

the class JavacClass method getInterfaces.

@Override
public List<TypeMirror> getInterfaces() {
    if (interfaces == null) {
        List<TypeMirror> ret = new ArrayList<TypeMirror>(classSymbol.getInterfaces().size());
        for (Type interfce : classSymbol.getInterfaces()) ret.add(new JavacType(interfce));
        interfaces = Collections.unmodifiableList(ret);
    }
    return interfaces;
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type) TypeMirror(org.eclipse.ceylon.model.loader.mirror.TypeMirror) ArrayList(java.util.ArrayList)

Example 4 with TypeMirror

use of org.eclipse.ceylon.model.loader.mirror.TypeMirror in project ceylon by eclipse.

the class JavacType method getTypeArguments.

@Override
public List<TypeMirror> getTypeArguments() {
    if (typeArguments == null) {
        List<TypeMirror> args = new ArrayList<TypeMirror>(type.getTypeArguments().size());
        for (Type typeArg : type.getTypeArguments()) {
            args.add(new JavacType(typeArg));
        }
        typeArguments = Collections.unmodifiableList(args);
    }
    return typeArguments;
}
Also used : WildcardType(org.eclipse.ceylon.langtools.tools.javac.code.Type.WildcardType) Type(org.eclipse.ceylon.langtools.tools.javac.code.Type) ArrayType(org.eclipse.ceylon.langtools.tools.javac.code.Type.ArrayType) TypeMirror(org.eclipse.ceylon.model.loader.mirror.TypeMirror) ArrayList(java.util.ArrayList)

Example 5 with TypeMirror

use of org.eclipse.ceylon.model.loader.mirror.TypeMirror 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)

Aggregations

TypeMirror (org.eclipse.ceylon.model.loader.mirror.TypeMirror)23 FunctionalInterfaceType (org.eclipse.ceylon.model.loader.mirror.FunctionalInterfaceType)10 Type (org.eclipse.ceylon.model.typechecker.model.Type)10 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)10 ArrayList (java.util.ArrayList)7 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)6 AnnotationMirror (org.eclipse.ceylon.model.loader.mirror.AnnotationMirror)5 Type (org.eclipse.ceylon.langtools.tools.javac.code.Type)4 LazyFunction (org.eclipse.ceylon.model.loader.model.LazyFunction)4 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)4 Type (java.lang.reflect.Type)3 ClassMirror (org.eclipse.ceylon.model.loader.mirror.ClassMirror)3 TypeParameterMirror (org.eclipse.ceylon.model.loader.mirror.TypeParameterMirror)3 LazyClass (org.eclipse.ceylon.model.loader.model.LazyClass)3 LazyValue (org.eclipse.ceylon.model.loader.model.LazyValue)3 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)3 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)3 Function (org.eclipse.ceylon.model.typechecker.model.Function)3 Module (org.eclipse.ceylon.model.typechecker.model.Module)3 ParameterList (org.eclipse.ceylon.model.typechecker.model.ParameterList)3