Search in sources :

Example 91 with Module

use of org.eclipse.ceylon.model.typechecker.model.Module in project ceylon by eclipse.

the class AbstractModelLoader method getRepeatableContainer.

public Interface getRepeatableContainer(Class c) {
    if (c instanceof AnnotationProxyClass) {
        AnnotationMirror mirror = ((AnnotationProxyClass) c).iface.classMirror.getAnnotation("java.lang.annotation.Repeatable");
        if (mirror != null) {
            TypeMirror m = (TypeMirror) mirror.getValue();
            Module module = findModuleForClassMirror(m.getDeclaredClass());
            return (Interface) convertDeclaredTypeToDeclaration(module, m, DeclarationType.TYPE);
        }
    }
    return null;
}
Also used : AnnotationMirror(org.eclipse.ceylon.model.loader.mirror.AnnotationMirror) TypeMirror(org.eclipse.ceylon.model.loader.mirror.TypeMirror) AnnotationProxyClass(org.eclipse.ceylon.model.loader.model.AnnotationProxyClass) Module(org.eclipse.ceylon.model.typechecker.model.Module) LazyModule(org.eclipse.ceylon.model.loader.model.LazyModule) Interface(org.eclipse.ceylon.model.typechecker.model.Interface) ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) LazyInterface(org.eclipse.ceylon.model.loader.model.LazyInterface)

Example 92 with Module

use of org.eclipse.ceylon.model.typechecker.model.Module in project ceylon by eclipse.

the class AbstractModelLoader method addInnerClassesFromMirror.

private void addInnerClassesFromMirror(ClassOrInterface klass, ClassMirror classMirror) {
    boolean isJDK = isFromJDK(classMirror);
    Module module = ModelUtil.getModule(klass);
    for (ClassMirror innerClass : classMirror.getDirectInnerClasses()) {
        // We skip members marked with @Ignore
        if (innerClass.getAnnotation(CEYLON_IGNORE_ANNOTATION) != null)
            continue;
        // We skip anonymous inner classes
        if (innerClass.isAnonymous())
            continue;
        // We skip private classes, otherwise the JDK has a ton of unresolved things
        if (isJDK && !innerClass.isPublic())
            continue;
        // convert it
        convertToDeclaration(module, klass, innerClass, DeclarationType.TYPE);
    // no need to set its container as that's now handled by convertToDeclaration
    }
}
Also used : Module(org.eclipse.ceylon.model.typechecker.model.Module) LazyModule(org.eclipse.ceylon.model.loader.model.LazyModule) ClassMirror(org.eclipse.ceylon.model.loader.mirror.ClassMirror)

Example 93 with Module

use of org.eclipse.ceylon.model.typechecker.model.Module in project ceylon by eclipse.

the class AbstractModelLoader method getJavaAnnotationExtendedType.

private Type getJavaAnnotationExtendedType(ClassOrInterface klass, ClassMirror classMirror) {
    TypeDeclaration constrainedAnnotation = (TypeDeclaration) convertNonPrimitiveTypeToDeclaration(getLanguageModule(), CEYLON_CONSTRAINED_ANNOTATION_TYPE, klass, DeclarationType.TYPE);
    AnnotationMirror target = classMirror.getAnnotation("java.lang.annotation.Target");
    Set<Type> types = new HashSet<Type>();
    if (target != null) {
        @SuppressWarnings("unchecked") List<String> values = (List<String>) target.getValue();
        for (String value : values) {
            switch(value) {
                case "TYPE":
                    TypeDeclaration decl = (TypeDeclaration) convertNonPrimitiveTypeToDeclaration(getLanguageModule(), CEYLON_CLASS_OR_INTERFACE_DECLARATION_TYPE, klass, DeclarationType.TYPE);
                    types.add(decl.getType());
                    decl = (TypeDeclaration) convertNonPrimitiveTypeToDeclaration(getLanguageModule(), CEYLON_ALIAS_DECLARATION_TYPE, klass, DeclarationType.TYPE);
                    types.add(decl.getType());
                    break;
                case "ANNOTATION_TYPE":
                    decl = (TypeDeclaration) convertNonPrimitiveTypeToDeclaration(getLanguageModule(), CEYLON_CLASS_OR_INTERFACE_DECLARATION_TYPE, klass, DeclarationType.TYPE);
                    types.add(decl.getType());
                    break;
                case "CONSTRUCTOR":
                    decl = (TypeDeclaration) convertNonPrimitiveTypeToDeclaration(getLanguageModule(), CEYLON_CONSTRUCTOR_DECLARATION_TYPE, klass, DeclarationType.TYPE);
                    types.add(decl.getType());
                    if (!values.contains("TYPE")) {
                        decl = (TypeDeclaration) convertNonPrimitiveTypeToDeclaration(getLanguageModule(), CEYLON_CLASS_WITH_INIT_DECLARATION_TYPE, klass, DeclarationType.TYPE);
                        types.add(decl.getType());
                    }
                    break;
                case "METHOD":
                // method annotations may be applied to shared members which are turned into getter methods
                case "PARAMETER":
                    decl = (TypeDeclaration) convertNonPrimitiveTypeToDeclaration(getLanguageModule(), CEYLON_FUNCTION_OR_VALUE_DECLARATION_TYPE, klass, DeclarationType.TYPE);
                    types.add(decl.getType());
                    break;
                case "FIELD":
                case "LOCAL_VARIABLE":
                    decl = (TypeDeclaration) convertNonPrimitiveTypeToDeclaration(getLanguageModule(), CEYLON_VALUE_DECLARATION_TYPE, klass, DeclarationType.TYPE);
                    types.add(decl.getType());
                    break;
                case "PACKAGE":
                    decl = (TypeDeclaration) convertNonPrimitiveTypeToDeclaration(getLanguageModule(), CEYLON_PACKAGE_DECLARATION_TYPE, klass, DeclarationType.TYPE);
                    types.add(decl.getType());
                    break;
                default:
            }
        }
    }
    Module module = ModelUtil.getModuleContainer(klass);
    Type annotatedType;
    if (types.size() == 1)
        annotatedType = types.iterator().next();
    else if (types.isEmpty()) {
        TypeDeclaration decl;
        if (target == null) {
            // default is anything
            decl = (TypeDeclaration) convertNonPrimitiveTypeToDeclaration(getLanguageModule(), CEYLON_ANNOTATED_TYPE, klass, DeclarationType.TYPE);
        } else {
            // we either had an empty set which means cannot be used as annotation in Java (only as annotation member)
            // or that we only had unmappable targets
            decl = typeFactory.getNothingDeclaration();
        }
        annotatedType = decl.getType();
    } else {
        List<Type> list = new ArrayList<Type>(types.size());
        list.addAll(types);
        annotatedType = union(list, getUnitForModule(module));
    }
    Type constrainedType = constrainedAnnotation.appliedType(null, Arrays.asList(klass.getType(), getOptionalType(klass.getType(), module), annotatedType));
    return constrainedType;
}
Also used : AnnotationMirror(org.eclipse.ceylon.model.loader.mirror.AnnotationMirror) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) FunctionalInterfaceType(org.eclipse.ceylon.model.loader.mirror.FunctionalInterfaceType) List(java.util.List) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Module(org.eclipse.ceylon.model.typechecker.model.Module) LazyModule(org.eclipse.ceylon.model.loader.model.LazyModule) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) HashSet(java.util.HashSet)

Example 94 with Module

use of org.eclipse.ceylon.model.typechecker.model.Module in project ceylon by eclipse.

the class AbstractModelLoader method loadLanguageModuleAndPackage.

protected Module loadLanguageModuleAndPackage() {
    Module languageModule = findOrCreateModule(CEYLON_LANGUAGE, null);
    addModuleToClassPath(languageModule, null);
    Package languagePackage = findOrCreatePackage(languageModule, CEYLON_LANGUAGE);
    typeFactory.setPackage(languagePackage);
    // make sure the language module has its real dependencies added, because we need them in the classpath
    // otherwise we will get errors on the Util and Metamodel calls we insert
    // WARNING! Make sure this list is always the same as the one in /ceylon-runtime/dist/repo/ceylon/language/_version_/module.xml
    // Note that we lie about the module exports: we pretend they're not imported at compile-time
    // while they are at run-time (in the module.xml file), so that users don't get these imports
    // visible in all their modules.
    languageModule.addImport(new ModuleImport(null, findOrCreateModule("org.eclipse.ceylon.common", Versions.CEYLON_VERSION_NUMBER), false, false, Backend.Java));
    languageModule.addImport(new ModuleImport(null, findOrCreateModule("org.eclipse.ceylon.model", Versions.CEYLON_VERSION_NUMBER), false, false, Backend.Java));
    return languageModule;
}
Also used : ModuleImport(org.eclipse.ceylon.model.typechecker.model.ModuleImport) LazyPackage(org.eclipse.ceylon.model.loader.model.LazyPackage) Package(org.eclipse.ceylon.model.typechecker.model.Package) Module(org.eclipse.ceylon.model.typechecker.model.Module) LazyModule(org.eclipse.ceylon.model.loader.model.LazyModule)

Example 95 with Module

use of org.eclipse.ceylon.model.typechecker.model.Module in project ceylon by eclipse.

the class AbstractModelLoader method propertiesMatch.

private boolean propertiesMatch(ClassOrInterface klass, MethodMirror getter, MethodMirror setter) {
    // only add the setter if it has the same visibility as the getter
    if (setter.isPublic() && getter.isPublic() || setter.isProtected() && getter.isProtected() || setter.isDefaultAccess() && getter.isDefaultAccess() || (!setter.isPublic() && !getter.isPublic() && !setter.isProtected() && !getter.isProtected() && !setter.isDefaultAccess() && !getter.isDefaultAccess())) {
        Module module = ModelUtil.getModuleContainer(klass);
        VariableMirror setterParam = setter.getParameters().get(0);
        Type paramType = obtainType(setterParam.getType(), setterParam, klass, module, "setter '" + setter.getName() + "'", klass);
        Type returnType = obtainType(getter.getReturnType(), getter, klass, module, "getter '" + getter.getName() + "'", klass);
        // only add the setter if it has exactly the same type as the getter
        if (paramType.isExactly(returnType)) {
            return true;
        }
    }
    return false;
}
Also used : Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) FunctionalInterfaceType(org.eclipse.ceylon.model.loader.mirror.FunctionalInterfaceType) VariableMirror(org.eclipse.ceylon.model.loader.mirror.VariableMirror) Module(org.eclipse.ceylon.model.typechecker.model.Module) LazyModule(org.eclipse.ceylon.model.loader.model.LazyModule)

Aggregations

Module (org.eclipse.ceylon.model.typechecker.model.Module)113 LazyModule (org.eclipse.ceylon.model.loader.model.LazyModule)37 Package (org.eclipse.ceylon.model.typechecker.model.Package)26 ModuleImport (org.eclipse.ceylon.model.typechecker.model.ModuleImport)25 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)20 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)19 ArrayList (java.util.ArrayList)18 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)16 File (java.io.File)14 Type (org.eclipse.ceylon.model.typechecker.model.Type)14 HashMap (java.util.HashMap)9 HashSet (java.util.HashSet)9 FunctionalInterfaceType (org.eclipse.ceylon.model.loader.mirror.FunctionalInterfaceType)9 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)9 Test (org.junit.Test)9 Value (org.eclipse.ceylon.model.typechecker.model.Value)8 LinkedList (java.util.LinkedList)7 List (java.util.List)7 Backends (org.eclipse.ceylon.common.Backends)7 ClassMirror (org.eclipse.ceylon.model.loader.mirror.ClassMirror)7