Search in sources :

Example 1 with MethodMirror

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

the class AnnotationLoader method loadAnnotationConstructorDefaultedParameter.

private AnnotationTerm loadAnnotationConstructorDefaultedParameter(LazyFunction method, MethodMirror meth, Parameter ctorParam, AnnotationConstructorParameter acp) {
    // Find the method mirror for the DPM
    for (MethodMirror mm : method.classMirror.getDirectMethods()) {
        if (mm.getName().equals(Naming.getDefaultedParamMethodName(method, ctorParam))) {
            // Create the appropriate AnnotationTerm
            if (mm.getAnnotation(AbstractModelLoader.CEYLON_ANNOTATION_INSTANTIATION_ANNOTATION) != null) {
                // If the DPM has a @AnnotationInstantiation
                // then it must be an invocation term so recurse
                InvocationAnnotationTerm invocationTerm = new InvocationAnnotationTerm();
                invocationTerm.setInstantiation(loadAnnotationInvocation(method, mm, meth));
                return invocationTerm;
            } else {
                return loadLiteralAnnotationTerm(method, ctorParam, mm);
            }
        }
    }
    return null;
}
Also used : MethodMirror(org.eclipse.ceylon.model.loader.mirror.MethodMirror) InvocationAnnotationTerm(org.eclipse.ceylon.compiler.java.codegen.InvocationAnnotationTerm)

Example 2 with MethodMirror

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

the class JavacClass method getDirectMethods.

@Override
public List<MethodMirror> getDirectMethods() {
    if (methods == null) {
        List<MethodMirror> ret = new LinkedList<MethodMirror>();
        for (Symbol sym : classSymbol.getEnclosedElements()) {
            if (sym instanceof MethodSymbol && (sym.flags() & Flags.PRIVATE) == 0) {
                ret.add(new JavacMethod(this, (MethodSymbol) sym));
            }
        }
        methods = Collections.unmodifiableList(ret);
    }
    return methods;
}
Also used : MethodMirror(org.eclipse.ceylon.model.loader.mirror.MethodMirror) MethodSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.MethodSymbol) VarSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.VarSymbol) MethodSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.MethodSymbol) Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol) ClassSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol) LinkedList(java.util.LinkedList)

Example 3 with MethodMirror

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

the class AbstractModelLoader method setSealedFromConstructorMods.

private void setSealedFromConstructorMods(Declaration decl, final List<MethodMirror> constructors) {
    boolean effectivelySealed = true;
    for (MethodMirror ctor : constructors) {
        if (ctor.isPublic() || ctor.isProtected()) {
            effectivelySealed = false;
            break;
        }
    }
    if (effectivelySealed && decl instanceof Class) {
        Class type = (Class) decl;
        type.setSealed(effectivelySealed);
        if (type.getOverloads() != null) {
            for (Declaration oload : type.getOverloads()) {
                ((Class) oload).setSealed(effectivelySealed);
            }
        }
    }
}
Also used : MethodMirror(org.eclipse.ceylon.model.loader.mirror.MethodMirror) AnnotationProxyClass(org.eclipse.ceylon.model.loader.model.AnnotationProxyClass) LazyClass(org.eclipse.ceylon.model.loader.model.LazyClass) Class(org.eclipse.ceylon.model.typechecker.model.Class) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration)

Example 4 with MethodMirror

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

the class AbstractModelLoader method markVariable.

private void markVariable(LazyValue value) {
    String setterName = NamingBase.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(setterName) && (!toplevel || m.isStatic()) && m.getParameters().size() == 1) {
            value.setVariable(true);
        }
    }
}
Also used : MethodMirror(org.eclipse.ceylon.model.loader.mirror.MethodMirror)

Example 5 with MethodMirror

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

the class AbstractModelLoader method loadFunctionCoercionParameter.

@SuppressWarnings("incomplete-switch")
private Function loadFunctionCoercionParameter(Declaration decl, String paramName, TypeMirror typeMirror, Module moduleScope, Scope scope) {
    Function method = new Function();
    method.setName(paramName);
    method.setUnit(decl.getUnit());
    try {
        FunctionalInterfaceType functionalInterfaceType = getFunctionalInterfaceType(typeMirror);
        MethodMirror functionalMethod = functionalInterfaceType.getMethod();
        Type returnType = obtainType(moduleScope, functionalInterfaceType.getReturnType(), scope, TypeLocation.TOPLEVEL);
        switch(getUncheckedNullPolicy(false, functionalInterfaceType.getReturnType(), functionalMethod)) {
            case Optional:
            case UncheckedNull:
                returnType = makeOptionalTypePreserveUnderlyingType(returnType, moduleScope);
                break;
        }
        method.setType(returnType);
        ParameterList pl = new ParameterList();
        // List<VariableMirror> functionalParameters = functionalMethod.getParameters();
        List<TypeMirror> parameterTypes = functionalInterfaceType.getParameterTypes();
        Map<String, Integer> used = new HashMap<String, Integer>();
        for (TypeMirror parameterType : parameterTypes) {
            String name;
            if (parameterTypes.size() == 1) {
                name = "it";
            } else {
                switch(parameterType.getKind()) {
                    case ARRAY:
                        name = "array";
                        break;
                    case BOOLEAN:
                        name = "boolean";
                        break;
                    case CHAR:
                        name = "character";
                        break;
                    case BYTE:
                        name = "byte";
                        break;
                    case INT:
                    case LONG:
                    case SHORT:
                        name = "integer";
                        break;
                    case FLOAT:
                    case DOUBLE:
                        name = "float";
                        break;
                    case DECLARED:
                        String typeName = parameterType.getDeclaredClass().getName();
                        int first = typeName.codePointAt(0);
                        name = String.valueOf(Character.toChars(Character.toLowerCase(first))) + typeName.substring(Character.charCount(first));
                        break;
                    default:
                        name = "arg";
                }
                Integer count = used.get(name);
                if (count == null) {
                    used.put(name, 1);
                } else {
                    int next = count + 1;
                    used.put(name, next);
                    name += next;
                }
            }
            Type modelParameterType = obtainType(moduleScope, parameterType, scope, TypeLocation.TOPLEVEL);
            Parameter p = new Parameter();
            Value v = new Value();
            p.setName(name);
            v.setName(name);
            v.setContainer(method);
            v.setScope(method);
            p.setModel(v);
            v.setInitializerParameter(p);
            // Java parameters are all optional unless primitives or annotated as such
            switch(getUncheckedNullPolicy(false, parameterType, functionalMethod)) {
                case Optional:
                    modelParameterType = makeOptionalTypePreserveUnderlyingType(modelParameterType, moduleScope);
                    break;
                case UncheckedNull:
                    v.setUncheckedNullType(true);
                    break;
            }
            v.setType(modelParameterType);
            pl.getParameters().add(p);
            method.addMember(v);
        }
        method.addParameterList(pl);
    } catch (ModelResolutionException x) {
        method.setType(logModelResolutionException(x, scope, "Failure to turn functional interface to Callable type"));
    }
    return method;
}
Also used : FunctionalInterfaceType(org.eclipse.ceylon.model.loader.mirror.FunctionalInterfaceType) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Function(org.eclipse.ceylon.model.typechecker.model.Function) LazyFunction(org.eclipse.ceylon.model.loader.model.LazyFunction) MethodMirror(org.eclipse.ceylon.model.loader.mirror.MethodMirror) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) FunctionalInterfaceType(org.eclipse.ceylon.model.loader.mirror.FunctionalInterfaceType) TypeMirror(org.eclipse.ceylon.model.loader.mirror.TypeMirror) 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) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter)

Aggregations

MethodMirror (org.eclipse.ceylon.model.loader.mirror.MethodMirror)15 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)6 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)6 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)6 AnnotationProxyClass (org.eclipse.ceylon.model.loader.model.AnnotationProxyClass)4 LazyClass (org.eclipse.ceylon.model.loader.model.LazyClass)4 Class (org.eclipse.ceylon.model.typechecker.model.Class)4 LinkedList (java.util.LinkedList)3 FieldValue (org.eclipse.ceylon.model.loader.model.FieldValue)3 JavaBeanValue (org.eclipse.ceylon.model.loader.model.JavaBeanValue)3 LazyFunction (org.eclipse.ceylon.model.loader.model.LazyFunction)3 LazyValue (org.eclipse.ceylon.model.loader.model.LazyValue)3 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 AnnotationMirror (org.eclipse.ceylon.model.loader.mirror.AnnotationMirror)2 ClassMirror (org.eclipse.ceylon.model.loader.mirror.ClassMirror)2 FunctionalInterfaceType (org.eclipse.ceylon.model.loader.mirror.FunctionalInterfaceType)2 TypeMirror (org.eclipse.ceylon.model.loader.mirror.TypeMirror)2