Package com.redhat.ceylon.compiler.loader.mirror

Examples of com.redhat.ceylon.compiler.loader.mirror.ClassMirror


        Package pkg = Decl.getPackage(model);
        if(pkg == null)
            return;
        String pkgName = Util.quoteJavaKeywords(pkg.getNameAsString());
        String qualifiedName = Naming.toplevelClassName(pkgName, model);
        ClassMirror classMirror = loader.lookupClassMirror(pkg.getModule(), qualifiedName);
        if(classMirror == null)
            node.addError("native declaration not found");
    }
View Full Code Here


                    module = getLanguageModule();
                }
                String cacheKey = cacheKeyByModule(module, name);
                // we use containsKey to be able to cache null results
                if(classMirrorCache.containsKey(cacheKey)) {
                    ClassMirror cachedMirror = classMirrorCache.get(cacheKey);
                    if (cachedMirror != null || ! searchAgain(module, name)) {
                        return cachedMirror;
                    }
                }
                ClassMirror mirror = lookupNewClassMirror(module, name);
                // we even cache null results
                classMirrorCache.put(cacheKey, mirror);
                return mirror;
            }finally{
                timer.stopIgnore(TIMER_MODEL_LOADER_CATEGORY);
View Full Code Here

    enum ClassType {
        ATTRIBUTE, METHOD, OBJECT, CLASS, INTERFACE;
    }
   
    private ClassMirror loadClass(Module module, String pkgName, String className) {
        ClassMirror moduleClass = null;
        try{
            loadPackage(module, pkgName, false);
            moduleClass = lookupClassMirror(module, className);
        }catch(Exception x){
            logVerbose("[Failed to complete class "+className+"]");
View Full Code Here

            case CEYLON: module = getLanguageModule(); break;
            case JDK : module = getJDKBaseModule(); break;
            }
            return convertToDeclaration(module, typeName, declarationType);
        }
        ClassMirror classMirror = type.getDeclaredClass();
        Module module = findModuleForClassMirror(classMirror);
        if(isImported(moduleScope, module)){
            return convertToDeclaration(module, typeName, declarationType);
        }else{
            logVerbose("Declaration is not from an imported module: "+typeName);
View Full Code Here

        }
    }

    private 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() + "$" + Naming.suffixName(Naming.Suffix.$impl, d.getName());
        else{
            // toplevel
            String p = pkg.getNameAsString();
            companionName = "";
            if(!p.isEmpty())
                companionName =  p + ".";
            companionName +=  Naming.suffixName(Naming.Suffix.$impl, d.getName());
        }
        ClassMirror companionClass = lookupClassMirror(pkg.getModule(), companionName);
        if(companionClass == null){
            ((Interface)d).setCompanionClassNeeded(false);
        }
        ((LazyInterface)d).companionClass = companionClass;
    }
View Full Code Here

            MethodMirror method = classMirror.getEnclosingMethod();
            if(method == null)
                return null;
           
            // see where that method belongs
            ClassMirror enclosingClass = method.getEnclosingClass();
            while(enclosingClass.isAnonymous()){
                // this gives us the method in which the anonymous class is, which should be the one we're looking for
                method = enclosingClass.getEnclosingMethod();
                if(method == null)
                    return null;
                // and the method's containing class
                enclosingClass = method.getEnclosingClass();
            }
           
            // if we are in a setter class, the attribute is declared in the getter class, so look for its declaration there
            TypeMirror getterClass = (TypeMirror) getAnnotationValue(enclosingClass, CEYLON_SETTER_ANNOTATION, "getterClass");
            boolean isSetter = false;
            // we use void.class as default value
            if(getterClass != null && !getterClass.isPrimitive()){
                enclosingClass = getterClass.getDeclaredClass();
                isSetter = true;
            }
           
            String javaClassName = enclosingClass.getQualifiedName();
           
            // make sure we don't go looking in companion classes
            if(javaClassName.endsWith(Naming.Suffix.$impl.name()))
                javaClassName = javaClassName.substring(0, javaClassName.length() - 5);
           
View Full Code Here

        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 LazyMethod){
            container = ((LazyMethod) 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;
    }
View Full Code Here

                    return convertToDeclaration(modules.getLanguageModule(), "ceylon.language.Throwable", declarationType);
                } else if ("java.lang.Exception".equals(typeName)) {
                    // FIXME: this being here is highly dubious
                    return convertToDeclaration(modules.getLanguageModule(), "ceylon.language.Exception", declarationType);
                }
                ClassMirror classMirror;
                try{
                    classMirror = lookupClassMirror(module, typeName);
                }catch(NoClassDefFoundError x){
                    // FIXME: this may not be the best thing to do. If the class is not there we don't know what type of declaration
                    // to return, but perhaps if we use annotation scanner rather than reflection we can figure it out, at least
                    // in cases where the supertype is missing, which throws in reflection at class load.
                    return logModelResolutionException(x.getMessage(), null, "Unable to load type "+typeName).getDeclaration();
                }
                if (classMirror == null) {
                    // special case when bootstrapping because we may need to pull the decl from the typechecked model
                    if(isBootstrap && typeName.startsWith(CEYLON_LANGUAGE+".")){
                        Declaration languageDeclaration = findLanguageModuleDeclarationForBootstrap(typeName);
                        if(languageDeclaration != null)
                            return languageDeclaration;
                    }

                    throw new ModelResolutionException("Failed to resolve "+typeName);
                }
                // we only allow source loading when it's java code we're compiling in the same go
                // (well, technically before the ceylon code)
                if(classMirror.isLoadedFromSource() && !classMirror.isJavaSource())
                    return null;
                return convertToDeclaration(module, classMirror, declarationType);
            }finally{
                timer.stopIgnore(TIMER_MODEL_LOADER_CATEGORY);
            }
View Full Code Here

                : quotedQualifiedName + "." + Naming.PACKAGE_DESCRIPTOR_CLASS_NAME;
        logVerbose("[Trying to look up package from "+className+"]");
        Module module = pkg.getModule();
        if(module == null)
            throw new RuntimeException("Assertion failed: module is null for package "+pkg.getNameAsString());
        ClassMirror packageClass = loadClass(module, quotedQualifiedName, className);
        if(packageClass == null){
            logVerbose("[Failed to complete "+className+"]");
            // missing: leave it private
            return;
        }
        // did we compile it from source or class?
        if(packageClass.isLoadedFromSource()){
            // must have come from source, in which case we walked it and
            // loaded its values already
            logVerbose("[We are compiling the package "+className+"]");
            return;
        }
View Full Code Here

            String pkgName = module.getNameAsString();
            if(pkgName.isEmpty())
                return false;
            String moduleClassName = pkgName + "." + Naming.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 + "." + Naming.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;
            }
            if(moduleClass != null){
                // load its module annotation
                return loadCompiledModule(module, moduleClass, moduleClassName);
View Full Code Here

TOP

Related Classes of com.redhat.ceylon.compiler.loader.mirror.ClassMirror

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.