Search in sources :

Example 6 with ClassMirror

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

the class AbstractModelLoader method findModuleClass.

protected ClassMirror findModuleClass(Module module, String pkgName) {
    String moduleClassName = pkgName + "." + NamingBase.MODULE_DESCRIPTOR_CLASS_NAME;
    logVerbose("[Trying to look up module from " + moduleClassName + "]");
    ClassMirror moduleClass = loadClass(module, pkgName, moduleClassName);
    if (moduleClass == null) {
        // perhaps we have an old module?
        String oldModuleClassName = pkgName + "." + NamingBase.OLD_MODULE_DESCRIPTOR_CLASS_NAME;
        logVerbose("[Trying to look up older module descriptor from " + oldModuleClassName + "]");
        ClassMirror oldModuleClass = loadClass(module, pkgName, oldModuleClassName);
        // keep it only if it has a module annotation, otherwise it could be a normal value
        if (oldModuleClass != null && oldModuleClass.getAnnotation(CEYLON_MODULE_ANNOTATION) != null)
            moduleClass = oldModuleClass;
    }
    return moduleClass;
}
Also used : ClassMirror(org.eclipse.ceylon.model.loader.mirror.ClassMirror)

Example 7 with ClassMirror

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

the class AbstractModelLoader method isRaw.

private boolean isRaw(Module module, TypeMirror type) {
    // See https://github.com/ceylon/ceylon-compiler/issues/1085
    switch(type.getKind()) {
        // arrays are never raw
        case ARRAY:
        case BOOLEAN:
        case BYTE:
        case CHAR:
        case DOUBLE:
        case ERROR:
        case FLOAT:
        case INT:
        case LONG:
        case NULL:
        case SHORT:
        case TYPEVAR:
        case VOID:
        case WILDCARD:
            return false;
        case DECLARED:
            ClassMirror klass = type.getDeclaredClass();
            if (klass.isJavaSource()) {
                // I suppose this should work
                return type.isRaw();
            }
            List<String> path = new LinkedList<String>();
            String pkgName = klass.getPackage().getQualifiedName();
            String unquotedPkgName = unquotePackageName(klass.getPackage());
            String qualifiedName = klass.getQualifiedName();
            String relativeName = pkgName.isEmpty() ? qualifiedName : qualifiedName.substring(pkgName.length() + 1);
            for (String name : relativeName.split("[\\$\\.]")) {
                if (!name.isEmpty()) {
                    path.add(name);
                }
            }
            if (path.size() > 1) {
                // find the proper class mirror for the container
                klass = loadClass(module, pkgName, new StringBuilder(pkgName).append('.').append(path.get(0)).toString());
                if (klass == null)
                    return false;
            }
            if (!path.isEmpty() && klass.isLoadedFromSource()) {
                // we need to find its model
                Scope scope = packagesByName.get(cacheKeyByModule(module, unquotedPkgName));
                if (scope == null)
                    return false;
                for (String name : path) {
                    Declaration decl = scope.getDirectMember(name, null, false);
                    if (decl == null)
                        return false;
                    // if we get a value, we want its type
                    if (JvmBackendUtil.isValue(decl) && ((Value) decl).getTypeDeclaration().getName().equals(name))
                        decl = ((Value) decl).getTypeDeclaration();
                    if (decl instanceof TypeDeclaration == false)
                        return false;
                    scope = (TypeDeclaration) decl;
                }
                TypeDeclaration typeDecl = (TypeDeclaration) scope;
                return typeDecl.isParameterized() && type.getTypeArguments().isEmpty();
            }
            try {
                return type.isRaw();
            } catch (Exception x) {
                // it will be logged somewhere else
                return false;
            }
        default:
            return false;
    }
}
Also used : Scope(org.eclipse.ceylon.model.typechecker.model.Scope) JavaParameterValue(org.eclipse.ceylon.model.loader.model.JavaParameterValue) Value(org.eclipse.ceylon.model.typechecker.model.Value) FieldValue(org.eclipse.ceylon.model.loader.model.FieldValue) LazyValue(org.eclipse.ceylon.model.loader.model.LazyValue) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) JavaBeanValue(org.eclipse.ceylon.model.loader.model.JavaBeanValue) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) ClassMirror(org.eclipse.ceylon.model.loader.mirror.ClassMirror) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) LinkedList(java.util.LinkedList) RepositoryException(org.eclipse.ceylon.model.cmr.RepositoryException) IOException(java.io.IOException)

Example 8 with ClassMirror

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

Example 9 with ClassMirror

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

the class RuntimeModelLoader method lazyLoadModuleForPackage.

private Module lazyLoadModuleForPackage(String pkgName) {
    if (lazyLoadedModulesByPackage.containsKey(pkgName)) {
        return lazyLoadedModulesByPackage.get(pkgName);
    }
    Module module;
    if (pkgName.isEmpty()) {
        module = modules.getDefaultModule();
    } else {
        // pretend it's the default module trying to load a new module? not sure what
        // to do here
        Module loadByModule = modules.getDefaultModule();
        ClassMirror moduleClass = findModuleClass(loadByModule, pkgName);
        if (moduleClass != null) {
            String name = getAnnotationStringValue(moduleClass, CEYLON_MODULE_ANNOTATION, "name");
            String version = getAnnotationStringValue(moduleClass, CEYLON_MODULE_ANNOTATION, "version");
            module = findOrCreateModule(name, version);
            loadCompiledModule(module);
            // damnit, make it import the default module, otherwise it won't be able to see non-ceylon modules
            module.addImport(new ModuleImport(null, modules.getDefaultModule(), false, false));
        // FIXME: do other things like what RuntimeModuleManager does?
        } else {
            // try parent package
            int lastDot = pkgName.lastIndexOf('.');
            String parentPackage;
            if (lastDot == -1)
                parentPackage = "";
            else
                parentPackage = pkgName.substring(0, lastDot);
            module = lazyLoadModuleForPackage(parentPackage);
        }
    }
    // cache module and return
    lazyLoadedModulesByPackage.put(pkgName, module);
    return module;
}
Also used : ModuleImport(org.eclipse.ceylon.model.typechecker.model.ModuleImport) LazyModule(org.eclipse.ceylon.model.loader.model.LazyModule) Module(org.eclipse.ceylon.model.typechecker.model.Module) ClassMirror(org.eclipse.ceylon.model.loader.mirror.ClassMirror)

Example 10 with ClassMirror

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

the class JvmBackendUtil method getMirrorName.

public static String getMirrorName(AnnotatedMirror mirror) {
    String name;
    AnnotationMirror annot = mirror.getAnnotation(CEYLON_NAME_ANNOTATION);
    if (annot != null) {
        name = (String) annot.getValue();
    } else {
        name = mirror.getName();
        name = name.isEmpty() ? name : stripLeadingDollar(name);
        if (mirror instanceof ClassMirror && isInitialLowerCase(name) && name.endsWith("_") && mirror.getAnnotation(CEYLON_CEYLON_ANNOTATION) != null) {
            name = name.substring(0, name.length() - 1);
        }
    }
    return name;
}
Also used : AnnotationMirror(org.eclipse.ceylon.model.loader.mirror.AnnotationMirror) ClassMirror(org.eclipse.ceylon.model.loader.mirror.ClassMirror)

Aggregations

ClassMirror (org.eclipse.ceylon.model.loader.mirror.ClassMirror)16 Module (org.eclipse.ceylon.model.typechecker.model.Module)7 LazyModule (org.eclipse.ceylon.model.loader.model.LazyModule)5 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)5 LinkedList (java.util.LinkedList)4 LazyClass (org.eclipse.ceylon.model.loader.model.LazyClass)4 LazyInterface (org.eclipse.ceylon.model.loader.model.LazyInterface)4 LazyValue (org.eclipse.ceylon.model.loader.model.LazyValue)4 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)4 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 AnnotationMirror (org.eclipse.ceylon.model.loader.mirror.AnnotationMirror)3 TypeMirror (org.eclipse.ceylon.model.loader.mirror.TypeMirror)3 LazyFunction (org.eclipse.ceylon.model.loader.model.LazyFunction)3 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)3 ParameterList (org.eclipse.ceylon.model.typechecker.model.ParameterList)3 IOException (java.io.IOException)2 MethodMirror (org.eclipse.ceylon.model.loader.mirror.MethodMirror)2 FieldValue (org.eclipse.ceylon.model.loader.model.FieldValue)2