Examples of MethodMirror


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

        // we get a @LocalContainer annotation for local interfaces
        if(localContainerAnnotation != null){
            methodDecl = (LocalDeclarationContainer) findLocalContainerFromAnnotationAndSetCompanionClass(pkg, (Interface) declaration, localContainerAnnotation);
        }else{
            // all the other cases stay where they belong
            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);
           
            // find the enclosing declaration
            Declaration enclosingClassDeclaration = convertToDeclaration(pkg.getModule(), javaClassName, DeclarationType.TYPE);
            if(enclosingClassDeclaration instanceof ClassOrInterface){
                ClassOrInterface containerDecl = (ClassOrInterface) enclosingClassDeclaration;
                // now find the method's declaration
                // FIXME: find the proper overload if any
                if(method.isConstructor()){
                    methodDecl = (LocalDeclarationContainer) containerDecl;
                }else{
                    String name = method.getName();
                    // this is only for error messages
                    String type;
                    // lots of special cases
                    if(isStringAttribute(method)){
                        name = "string";
                        type = "attribute";
                    }else if(isHashAttribute(method)){
                        name = "hash";
                        type = "attribute";
                    }else if(isGetter(method)) {
                        // simple attribute
                        name = getJavaAttributeName(name);
                        type = "attribute";
                    }else if(isSetter(method)) {
                        // simple attribute
                        name = getJavaAttributeName(name);
                        type = "attribute setter";
                        isSetter = true;
                    }else{
                        type = "method";
                    }
                    // strip any escaping or private suffix
                    // it can be foo$priv$canonical so get rid of that one first
                    if (name.endsWith(Naming.Suffix.$canonical$.toString())) {
                        name = name.substring(0, name.length()-11);
                    }
                    name = Util.strip(name, true, method.isPublic() || method.isProtected() || method.isDefaultAccess());

                    methodDecl = (LocalDeclarationContainer) containerDecl.getDirectMember(name, null, false);

                    if(methodDecl == null)
                        throw new ModelResolutionException("Failed to load outer "+type+" " + name
                                + " for local type " + classMirror.getQualifiedName().toString());

                    // if it's a setter we wanted, let's get it
                    if(isSetter){
                        LocalDeclarationContainer setter = (LocalDeclarationContainer) ((Value)methodDecl).getSetter();
                        if(setter == null)
                            throw new ModelResolutionException("Failed to load outer "+type+" " + name
                                    + " for local type " + classMirror.getQualifiedName().toString());
                        methodDecl = setter;
                    }
                }
            }else if(enclosingClassDeclaration instanceof LazyMethod){
                // local and toplevel methods
                methodDecl = (LazyMethod)enclosingClassDeclaration;
            }else if(enclosingClassDeclaration instanceof LazyValue){
                // local and toplevel attributes
                if(enclosingClassDeclaration.isToplevel() && method.getName().equals(Naming.Unfix.set_.name()))
                    isSetter = true;
                if(isSetter){
                    LocalDeclarationContainer setter = (LocalDeclarationContainer) ((LazyValue)enclosingClassDeclaration).getSetter();
                    if(setter == null)
                        throw new ModelResolutionException("Failed to toplevel attribute setter " + enclosingClassDeclaration.getName()
View Full Code Here

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

                    if (!constructors.isEmpty()) {
                        if (constructors.size() > 1) {
                            decl = makeOverloadedConstructor(constructors, classMirror, decls, isCeylon);
                        } else {
                            // single constructor
                            MethodMirror constructor = constructors.get(0);
                            // if the class and constructor have different visibility, we pretend there's an overload of one
                            // if it's a ceylon class we don't care that they don't match sometimes, like for inner classes
                            // where the constructor is protected because we want to use an accessor, in this case the class
                            // visibility is to be used
                            if(isCeylon || getJavaVisibility(classMirror) == getJavaVisibility(constructor)){
View Full Code Here

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

        synchronized(getLock()){
            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$")) {
View Full Code Here

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

            addInnerClasses(klass, classMirror);
        }

        // Java classes with multiple constructors get turned into multiple Ceylon classes
        // Here we get the specific constructor that was assigned to us (if any)
        MethodMirror constructor = null;
        if (klass instanceof LazyClass) {
            constructor = ((LazyClass)klass).getConstructor();
        }
           
        // Turn a list of possibly overloaded methods into a map
        // 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
View Full Code Here

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

                if(decl.isActual()){
                    Declaration refined = klass.getRefinedMember(decl.getName(), getSignature(decl), false);
                    decl.setRefinedDeclaration(refined);
                }
            }else{ // Method or Value
                MethodMirror methodMirror;
                if(decl instanceof JavaBeanValue)
                    methodMirror = ((JavaBeanValue) decl).mirror;
                else if(decl instanceof JavaMethod)
                    methodMirror = ((JavaMethod) decl).mirror;
                else
                    throw new ModelResolutionException("Unknown type of declaration: "+decl+": "+decl.getClass().getName());
               
                decl.setRefinedDeclaration(decl);
                // For Ceylon interfaces we rely on annotation
                if(klass instanceof LazyInterface
                        && ((LazyInterface)klass).isCeylon()){
                    boolean actual = methodMirror.getAnnotation(CEYLON_LANGUAGE_ACTUAL_ANNOTATION) != null;
                    decl.setActual(actual);
                    if(actual){
                        Declaration refined = klass.getRefinedMember(decl.getName(), getSignature(decl), false);
                        decl.setRefinedDeclaration(refined);
                    }
                }else{
                    if(isOverridingMethod(methodMirror)){
                        decl.setActual(true);
                        Declaration refined = klass.getRefinedMember(decl.getName(), getSignature(decl), false);
                        decl.setRefinedDeclaration(refined);
                    }
                }
               
                // now that we know the refined declaration, we can check for reified type param support
                // for Ceylon methods
                if(decl instanceof JavaMethod && Decl.isCeylon(klass)){
                    if(!methodMirror.getTypeParameters().isEmpty()
                            // because this requires the refined decl, we defer this check until we've set it, to not trigger
                            // lazy loading just to check.
                            && AbstractTransformer.supportsReified(decl)){
                        checkReifiedTypeDescriptors(methodMirror.getTypeParameters().size(),
                                container.getQualifiedNameString(), methodMirror, false);
                    }
                }
            }
        }
View Full Code Here

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

    @Override
    public void complete(LazyValue value)  {
        synchronized(getLock()){
            timer.startIgnore(TIMER_MODEL_LOADER_CATEGORY);
            try{
                MethodMirror meth = null;
                String getterName = Naming.getGetterName(value);
                String setterName = Naming.getSetterName(value);
                boolean toplevel = value.isToplevel();
                for (MethodMirror m : value.classMirror.getDirectMethods()) {
                    // Do not skip members marked with @Ignore, because the getter is supposed to be ignored

                    if (m.getName().equals(getterName)
                            && (!toplevel || m.isStatic())
                            && m.getParameters().size() == 0) {
                        meth = m;
                    }
                    if (m.getName().equals(setterName)
                            && (!toplevel || m.isStatic())
                            && m.getParameters().size() == 1) {
                        value.setVariable(true);
                    }
                }
                if(meth == null || meth.getReturnType() == null){
                    value.setType(logModelResolutionError(value.getContainer(), "Error while resolving toplevel attribute "+value.getQualifiedNameString()+": getter method missing"));
                    return;
                }

                value.setType(obtainType(meth.getReturnType(), meth, null, Decl.getModuleContainer(value.getContainer()), VarianceLocation.INVARIANT,
                        "toplevel attribute", value));

                setValueTransientLateFlags(value, meth, true);
                setAnnotations(value, meth);
                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();
View Full Code Here

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

    @Override
    public void complete(LazyMethod method)  {
        synchronized(getLock()){
            timer.startIgnore(TIMER_MODEL_LOADER_CATEGORY);
            try{
                MethodMirror meth = null;
                String lookupName = method.getName();
                for(MethodMirror m : method.classMirror.getDirectMethods()){
                    // We skip members marked with @Ignore
                    if(m.getAnnotation(CEYLON_IGNORE_ANNOTATION) != null)
                        continue;

                    if(Util.strip(m.getName()).equals(lookupName)){
                        meth = m;
                        break;
                    }
                }
                if(meth == null || meth.getReturnType() == null){
                    method.setType(logModelResolutionError(method.getContainer(), "Error while resolving toplevel method "+method.getQualifiedNameString()+": static method missing"));
                    return;
                }
                // only check the static mod for toplevel classes
                if(!method.classMirror.isLocalClass() && !meth.isStatic()){
                    method.setType(logModelResolutionError(method.getContainer(), "Error while resolving toplevel method "+method.getQualifiedNameString()+": method is not static"));
                    return;
                }

                // save the method name
                method.setRealMethodName(meth.getName());

                // save the method
                method.setMethodMirror(meth);

                // type params first
                setTypeParameters(method, meth, true);

                method.setType(obtainType(meth.getReturnType(), meth, method, Decl.getModuleContainer(method), VarianceLocation.COVARIANT,
                        "toplevel method", method));
                method.setDeclaredVoid(meth.isDeclaredVoid());
                markDeclaredVoid(method, meth);
                markUnboxed(method, meth, meth.getReturnType());
                markTypeErased(method, meth, meth.getReturnType());
                markUntrustedType(method, meth, meth.getReturnType());

             // now its parameters
                setParameters(method, meth, true /* toplevel methods are always Ceylon */, method);
               
                method.setAnnotation(meth.getAnnotation(CEYLON_LANGUAGE_ANNOTATION_ANNOTATION) != null);
                setAnnotations(method, meth);

                setAnnotationConstructor(method, meth);

                addLocalDeclarations(method, method.classMirror, method.classMirror);
View Full Code Here

Examples of kilim.mirrors.MethodMirror

            return METHOD_NOT_PAUSABLE; // constructors are not pausable.
        }
        className = className.replace('/', '.');
        try {
            ClassMirror cl = mirrors.classForName(className);
            MethodMirror m = findMethod(cl, methodName, desc);
            if (m != null) {
                for (ClassMirror c: m.getExceptionTypes()) {
                    if (NOT_PAUSABLE.isAssignableFrom(c)) {
                        return METHOD_NOT_PAUSABLE;
                    }
                    if (PAUSABLE.isAssignableFrom(c)) {
                        return PAUSABLE_METHOD_FOUND;
View Full Code Here

Examples of kilim.mirrors.MethodMirror

         return ret;
    }
   
    private MethodMirror findMethod(ClassMirror cl, String methodName, String desc) {
        if (cl == null) return null;
        MethodMirror m = findMethodInHierarchy(cl, methodName, desc);
        if (m == null) {
            cl = mirrors.mirror(Object.class);
            for (MethodMirror om : cl.getDeclaredMethods()) {
                if (om.getName().equals(methodName) && om.getMethodDescriptor().equals(desc)) {
                    return om;
View Full Code Here

Examples of kilim.mirrors.MethodMirror

        }

        if (OBJECT.equals(cl))
            return null;

        MethodMirror m = findMethodInHierarchy(cl.getSuperclass(), methodName, desc);
        if (m != null)
            return m;
        for (ClassMirror ifcl : cl.getInterfaces()) {
            m = findMethodInHierarchy(ifcl, methodName, desc);
            if (m != null)
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.