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

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


            timer.startIgnore(TIMER_MODEL_LOADER_CATEGORY);
            completeLazyAlias(alias, alias.classMirror, CEYLON_ALIAS_ANNOTATION);

            // Find the instantiator method
            MethodMirror instantiator = null;
            ClassMirror instantiatorClass = alias.isToplevel() ? alias.classMirror : alias.classMirror.getEnclosingClass();
            for (MethodMirror method : instantiatorClass.getDirectMethods()) {
                // If we're finding things based on their name, shouldn't we
                // we using Naming to do it?
                if (method.getName().equals(alias.getName() + "$aliased$")) {
                    instantiator = method;
                    break;
View Full Code Here


        // of lists that contain methods with the same name
        Map<String, List<MethodMirror>> methods = new LinkedHashMap<String, List<MethodMirror>>();
        collectMethods(classMirror.getDirectMethods(), methods, isCeylon, isFromJDK);

        if(isCeylon && klass instanceof LazyInterface && CodegenUtil.isCompanionClassNeeded(klass)){
            ClassMirror companionClass = ((LazyInterface)klass).companionClass;
            if(companionClass != null)
                collectMethods(companionClass.getDirectMethods(), methods, isCeylon, isFromJDK);
            else
                logWarning("CompanionClass missing for "+klass);
        }

        // Add the methods
        for(List<MethodMirror> methodMirrors : methods.values()){
            boolean isOverloaded = isMethodOverloaded(methodMirrors);
           
            List<Declaration> overloads = (isOverloaded) ? new ArrayList<Declaration>(methodMirrors.size()) : null;
            for (MethodMirror methodMirror : methodMirrors) {
                String methodName = methodMirror.getName();
                // same tests as in isMethodOverloaded()
                if(methodMirror.isConstructor() || isInstantiator(methodMirror)) {
                    break;
                } else if(isGetter(methodMirror)) {
                    // simple attribute
                    addValue(klass, methodMirror, getJavaAttributeName(methodName), isCeylon);
                } else if(isSetter(methodMirror)) {
                    // We skip setters for now and handle them later
                    variables.put(methodMirror, methodMirrors);
                } else if(isHashAttribute(methodMirror)) {
                    // ERASURE
                    // Un-erasing 'hash' attribute from 'hashCode' method
                    addValue(klass, methodMirror, "hash", isCeylon);
                } else if(isStringAttribute(methodMirror)) {
                    // ERASURE
                    // Un-erasing 'string' attribute from 'toString' method
                    addValue(klass, methodMirror, "string", isCeylon);
                } else if(!methodMirror.getName().equals("hash")
                        && !methodMirror.getName().equals("string")){
                    // normal method
                    Method m = addMethod(klass, methodMirror, classMirror, isCeylon, isOverloaded);
                    if (isOverloaded) {
                        overloads.add(m);
                    }
                }
            }
           
            if (overloads != null && !overloads.isEmpty()) {
                // We create an extra "abstraction" method for overloaded methods
                Method abstractionMethod = addMethod(klass, methodMirrors.get(0), classMirror, false, false);
                abstractionMethod.setAbstraction(true);
                abstractionMethod.setOverloads(overloads);
                abstractionMethod.setType(newUnknownType());
            }
        }

        for(FieldMirror fieldMirror : classMirror.getDirectFields()){
            // We skip members marked with @Ignore
            if(fieldMirror.getAnnotation(CEYLON_IGNORE_ANNOTATION) != null)
                continue;
            if(isCeylon && fieldMirror.isStatic())
                continue;
            // FIXME: temporary, because some private classes from the jdk are
            // referenced in private methods but not available
            if(isFromJDK && !fieldMirror.isPublic())
                continue;
            String name = fieldMirror.getName();
            // skip the field if "we've already got one"
            boolean conflicts = klass.getDirectMember(name, null, false) != null
                    || "equals".equals(name)
                    || "string".equals(name)
                    || "hash".equals(name);
            if (!conflicts) {
                addValue(klass, fieldMirror.getName(), fieldMirror, isCeylon);
            }
        }

        // Having loaded methods and values, we can now set the constructor parameters
        if(constructor != null
                && (!(klass instanceof LazyClass) || !((LazyClass)klass).isAnonymous()))
            setParameters((Class)klass, constructor, isCeylon, klass);
        // Now marry-up attributes and parameters)
        if (klass instanceof Class) {
            for (Declaration m : klass.getMembers()) {
                if (Decl.isValue(m)) {
                    Value v = (Value)m;
                    Parameter p = ((Class)klass).getParameter(v.getName());
                    if (p != null) {
                        p.setHidden(true);
                    }
                }
            }
        }

        // Now mark all Values for which Setters exist as variable
        for(Entry<MethodMirror, List<MethodMirror>> setterEntry : variables.entrySet()){
            MethodMirror setter = setterEntry.getKey();
            String name = getJavaAttributeName(setter.getName());
            // make sure we handle private postfixes
            name = Util.strip(name, isCeylon, setter.isPublic());
            Declaration decl = klass.getMember(name, null, false);
            boolean foundGetter = false;
            // skip Java fields, which we only get if there is no getter method, in that case just add the setter method
            if (decl instanceof Value && decl instanceof FieldValue == false) {
                Value value = (Value)decl;
                VariableMirror setterParam = setter.getParameters().get(0);
                ProducedType paramType = obtainType(setterParam.getType(), setterParam, klass, Decl.getModuleContainer(klass), VarianceLocation.INVARIANT,
                        "setter '"+setter.getName()+"'", klass);
                // only add the setter if it has exactly the same type as the getter
                if(paramType.isExactly(value.getType())){
                    foundGetter = true;
                    value.setVariable(true);
                    if(decl instanceof JavaBeanValue)
                        ((JavaBeanValue)decl).setSetterName(setter.getName());
                    if(value.isTransient()){
                        // must be a real setter
                        makeSetter(value, null);
                    }
                }else
                    logVerbose("Setter parameter type for "+name+" does not match corresponding getter type, adding setter as a method");
            }
           
            if(!foundGetter){
                // it was not a setter, it was a method, let's add it as such
                addMethod(klass, setter, classMirror, isCeylon, false);
            }
        }

        // In some cases, where all constructors are ignored, we can end up with no constructor, so
        // pretend we have one which takes no parameters (eg. ceylon.language.String).
        if(klass instanceof Class
                && !((Class) klass).isAbstraction()
                && !klass.isAnonymous()
                && ((Class) klass).getParameterList() == null){
            ((Class) klass).setParameterList(new ParameterList());
        }
       
        setExtendedType(klass, classMirror);
        setSatisfiedTypes(klass, classMirror);
        setCaseTypes(klass, classMirror);
        setAnnotations(klass, classMirror);
       
        // local declarations come last, because they need all members to be completed first
        if(!klass.isAlias()){
            ClassMirror containerMirror = classMirror;
            if(klass instanceof LazyInterface){
                ClassMirror companionClass = ((LazyInterface) klass).companionClass;
                if(companionClass != null)
                    containerMirror = companionClass;
            }
            addLocalDeclarations((LazyContainer) klass, containerMirror, classMirror);
        }
View Full Code Here

        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(0, klass.getName());
                }
            }
            if(path.size() > 1){
                // find the proper class mirror for the container
                klass = loadClass(module, pkgName, path.get(0));
                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){
View Full Code Here

                markUnboxed(value, meth, meth.getReturnType());

                TypeMirror setterClass = (TypeMirror) getAnnotationValue(value.classMirror, CEYLON_ATTRIBUTE_ANNOTATION, "setterClass");
                // void.class is the default value, I guess it's a primitive?
                if(setterClass != null && !setterClass.isPrimitive()){
                    ClassMirror setterClassMirror = setterClass.getDeclaredClass();
                    value.setVariable(true);
                    SetterWithLocalDeclarations setter = makeSetter(value, setterClassMirror);
                    // adding local scopes should be done last, when we have the setter, because it may be needed by container chain
                    addLocalDeclarations(value, value.classMirror, value.classMirror);
                    addLocalDeclarations(setter, setterClassMirror, setterClassMirror);
View Full Code Here

        }
    }
    private void setPrimaryFromAnnotationInvocationAnnotation(AnnotationMirror annotationInvocationAnnotation,
            AnnotationInvocation ai) {
        TypeMirror annotationType = (TypeMirror)annotationInvocationAnnotation.getValue(CEYLON_ANNOTATION_INSTANTIATION_ANNOTATION_MEMBER);
        ClassMirror annotationClassMirror = annotationType.getDeclaredClass();
        Module module = findModuleForClassMirror(annotationClassMirror);
        if (annotationClassMirror.getAnnotation(CEYLON_METHOD_ANNOTATION) != null) {
            ai.setPrimary((Method)convertToDeclaration(module, annotationClassMirror, DeclarationType.VALUE));
        } else {
            ai.setPrimary((Class)convertToDeclaration(module, annotationClassMirror, DeclarationType.TYPE));
        }
    }
View Full Code Here

                }catch(ModelResolutionException x){
                    String classPackageName = unquotePackageName(classMirror.getPackage());
                    if(JDKUtils.isJDKAnyPackage(classPackageName)){
                        if(iface.getKind() == TypeKind.DECLARED){
                            // check if it's a JDK thing
                            ClassMirror ifaceClass = iface.getDeclaredClass();
                            String ifacePackageName = unquotePackageName(ifaceClass.getPackage());
                            if(JDKUtils.isOracleJDKAnyPackage(ifacePackageName)){
                                // just log and ignore it
                                logMissingOracleType(iface.getQualifiedName());
                                continue;
                            }
View Full Code Here

    }
   
    @Override
    public ClassMirror lookupNewClassMirror(Module module, String name) {
        synchronized(getLock()){
            ClassMirror classMirror = lookupNewClassMirror(name);
            if(classMirror == null)
                return null;
            Module classMirrorModule = findModuleForClassMirror(classMirror);
            if(classMirrorModule == null){
                logVerbose("Found a class mirror with no module");
View Full Code Here

            if (d != null) {
                return d;
            }

            String className = getQualifiedName(pkgName, name);
            ClassMirror classSymbol = modelLoader.lookupClassMirror(module, className);

            // only get it from the classpath if we're not compiling it, unless
            // it happens to be a java source
            if(classSymbol != null && (!classSymbol.isLoadedFromSource() || classSymbol.isJavaSource())) {
                d = modelLoader.convertToDeclaration(module, className, DeclarationType.VALUE);
                if (d instanceof Class) {
                    Class c = (Class) d;
                    if (c.isAbstraction() && signature != null) {
                        ArrayList<Declaration> list = new ArrayList<Declaration>(c.getOverloads());
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.