Search in sources :

Example 1 with JavaMethod

use of org.eclipse.ceylon.model.loader.model.JavaMethod in project ceylon by eclipse.

the class Naming method quoteMethodNameIfProperty.

private static String quoteMethodNameIfProperty(Function method) {
    String name = method.getName();
    if (!method.isShared()) {
        name = suffixName(Suffix.$priv$, name);
    }
    // Toplevel methods keep their original name because their names might be mangled
    if (method instanceof LazyFunction) {
        return ((LazyFunction) method).getRealName();
    }
    // since local methods have a $getter suffix
    if (!method.isClassOrInterfaceMember())
        return name;
    // do not quote method names if we have a refined constraint
    Function refinedMethod = (Function) method.getRefinedDeclaration();
    if (refinedMethod instanceof JavaMethod) {
        return ((JavaMethod) refinedMethod).getRealName();
    }
    // get/is with at least one more letter, no parameter and non-void type
    if (((name.length() >= 4 && name.startsWith("get")) || name.length() >= 3 && name.startsWith("is")) && // not the total number of parameters
    method.getFirstParameterList().getParameters().isEmpty() && !AbstractTransformer.isAnything(method.getType()))
        return quote(name);
    // set with one parameter and void type
    if ((name.length() >= 4 && name.startsWith("set")) && // not the total number of parameters
    method.getFirstParameterList().getParameters().size() == 1 && AbstractTransformer.isAnything(method.getType()))
        return quote(name);
    return name;
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) LazyFunction(org.eclipse.ceylon.model.loader.model.LazyFunction) JavaMethod(org.eclipse.ceylon.model.loader.model.JavaMethod) LazyFunction(org.eclipse.ceylon.model.loader.model.LazyFunction)

Example 2 with JavaMethod

use of org.eclipse.ceylon.model.loader.model.JavaMethod in project ceylon by eclipse.

the class AbstractModelLoader method addMethod.

private Function addMethod(ClassOrInterface klass, MethodMirror methodMirror, ClassMirror classMirror, boolean isCeylon, boolean isOverloaded, boolean isNativeHeader, boolean isCoercedMethod) {
    JavaMethod method = new JavaMethod(methodMirror);
    String methodName = methodMirror.getName();
    method.setCoercionPoint(isCoercedMethod);
    method.setContainer(klass);
    method.setScope(klass);
    method.setRealName(methodName);
    method.setUnit(klass.getUnit());
    method.setOverloaded(isOverloaded);
    method.setVariadic(methodMirror.isVariadic());
    Type type = null;
    try {
        setMethodOrValueFlags(klass, methodMirror, method, isCeylon);
    } catch (ModelResolutionException x) {
        // collect an error in its type
        type = logModelResolutionException(x, klass, "method '" + methodMirror.getName() + "' (checking if it is an overriding method)");
    }
    if (methodName.equals("hash") || methodName.equals("string"))
        method.setName(methodName + "_method");
    else {
        String ceylonName = JvmBackendUtil.strip(methodName, isCeylon, method.isShared());
        if (!isCeylon && !JvmBackendUtil.isInitialLowerCase(ceylonName))
            ceylonName = NamingBase.getJavaBeanName(ceylonName);
        method.setName(ceylonName);
    }
    method.setDefaultedAnnotation(methodMirror.isDefault());
    // type params first
    try {
        setTypeParameters(method, methodMirror, isCeylon);
    } catch (ModelResolutionException x) {
        if (type == null) {
            type = logModelResolutionException(x, klass, "method '" + methodMirror.getName() + "' (loading type parameters)");
        }
    }
    Module module = ModelUtil.getModuleContainer(method);
    // do not log an additional error if we had one from checking if it was overriding
    if (type == null)
        type = obtainType(methodMirror.getReturnType(), methodMirror, method, module, "method '" + methodMirror.getName() + "'", klass);
    NullStatus nullPolicy = getUncheckedNullPolicy(isCeylon, methodMirror.getReturnType(), methodMirror);
    switch(nullPolicy) {
        case Optional:
            if (!isCeylon) {
                type = makeOptionalTypePreserveUnderlyingType(type, module);
            }
            break;
        case UncheckedNull:
            method.setUncheckedNullType(true);
            break;
    }
    if (type.isCached()) {
        type = type.clone();
    }
    method.setType(type);
    // now its parameters
    if (isEqualsMethod(methodMirror))
        setEqualsParameters(method, methodMirror);
    else
        setParameters(method, classMirror, methodMirror, isCeylon, klass, isCoercedMethod);
    type.setRaw(isRaw(module, methodMirror.getReturnType()));
    markDeclaredVoid(method, methodMirror);
    markUnboxed(method, methodMirror, methodMirror.getReturnType());
    markSmall(method, methodMirror.getReturnType());
    markTypeErased(method, methodMirror, methodMirror.getReturnType());
    markUntrustedType(method, methodMirror, methodMirror.getReturnType());
    method.setDeprecated(isDeprecated(methodMirror));
    setAnnotations(method, methodMirror, isNativeHeader);
    klass.addMember(method);
    ModelUtil.setVisibleScope(method);
    addLocalDeclarations(method, classMirror, methodMirror);
    return method;
}
Also used : Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) FunctionalInterfaceType(org.eclipse.ceylon.model.loader.mirror.FunctionalInterfaceType) JavaMethod(org.eclipse.ceylon.model.loader.model.JavaMethod) Module(org.eclipse.ceylon.model.typechecker.model.Module) LazyModule(org.eclipse.ceylon.model.loader.model.LazyModule)

Example 3 with JavaMethod

use of org.eclipse.ceylon.model.loader.model.JavaMethod in project ceylon by eclipse.

the class AbstractModelLoader method complete.

private void complete(AnnotationProxyMethod ctor, AnnotationProxyClass klass, LazyInterface iface) {
    ParameterList ctorpl = new ParameterList();
    ctorpl.setPositionalParametersSupported(false);
    ctor.addParameterList(ctorpl);
    List<Parameter> ctorParams = new ArrayList<Parameter>();
    for (Declaration member : iface.getMembers()) {
        boolean isValue = member.getName().equals("value");
        if (member instanceof JavaMethod) {
            JavaMethod m = (JavaMethod) member;
            Parameter ctorParam = new Parameter();
            ctorParams.add(ctorParam);
            Value value = new Value();
            ctorParam.setModel(value);
            value.setInitializerParameter(ctorParam);
            ctorParam.setDeclaration(ctor);
            value.setContainer(klass);
            value.setScope(klass);
            ctorParam.setDefaulted(m.isDefaultedAnnotation());
            value.setName(member.getName());
            ctorParam.setName(member.getName());
            value.setType(annotationParameterType(iface.getUnit(), m));
            value.setUnboxed(true);
            value.setUnit(iface.getUnit());
            if (isValue)
                ctorpl.getParameters().add(0, ctorParam);
            else
                ctorpl.getParameters().add(ctorParam);
            ctor.addMember(value);
        }
    }
    makeInteropAnnotationConstructorInvocation(ctor, klass, ctorParams);
}
Also used : ArrayList(java.util.ArrayList) 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) JavaMethod(org.eclipse.ceylon.model.loader.model.JavaMethod) 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 JavaMethod

use of org.eclipse.ceylon.model.loader.model.JavaMethod in project ceylon by eclipse.

the class Naming method getMethodNameInternal.

private static String getMethodNameInternal(TypedDeclaration decl) {
    String name;
    if (decl.isClassOrInterfaceMember() && decl instanceof Function) {
        Declaration refined = decl.getRefinedDeclaration();
        if (refined instanceof JavaMethod) {
            return ((JavaMethod) refined).getRealName();
        }
        name = quoteMethodNameIfProperty((Function) decl);
    } else {
        name = decl.getName();
    }
    if (decl.isClassMember() && "readResolve".equals(name) && Strategy.addReadResolve((Class) decl.getContainer())) {
        return quote(name);
    }
    if (decl.isClassMember() && "writeReplace".equals(name) && Strategy.useSerializationProxy((Class) decl.getContainer())) {
        return quote(name);
    }
    // ERASURE
    if (QUOTABLE_METHOD_NAMES.contains(name)) {
        return quote(name);
    } else {
        return quoteIfJavaKeyword(name);
    }
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) LazyFunction(org.eclipse.ceylon.model.loader.model.LazyFunction) JavaMethod(org.eclipse.ceylon.model.loader.model.JavaMethod) 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 5 with JavaMethod

use of org.eclipse.ceylon.model.loader.model.JavaMethod in project ceylon by eclipse.

the class AbstractModelLoader method complete.

private void complete(AnnotationProxyClass klass, LazyInterface iface) {
    ParameterList classpl = new ParameterList();
    klass.addParameterList(classpl);
    for (Declaration member : iface.getMembers()) {
        boolean isValue = member.getName().equals("value");
        if (member instanceof JavaMethod) {
            JavaMethod m = (JavaMethod) member;
            Parameter klassParam = new Parameter();
            Value value = new Value();
            klassParam.setModel(value);
            value.setInitializerParameter(klassParam);
            klassParam.setDeclaration(klass);
            value.setContainer(klass);
            value.setScope(klass);
            value.setName(member.getName());
            klassParam.setName(member.getName());
            value.setType(annotationParameterType(iface.getUnit(), m));
            value.setUnboxed(true);
            value.setUnit(iface.getUnit());
            if (isValue)
                classpl.getParameters().add(0, klassParam);
            else
                classpl.getParameters().add(klassParam);
            klass.addMember(value);
        }
    }
}
Also used : 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) JavaMethod(org.eclipse.ceylon.model.loader.model.JavaMethod) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration)

Aggregations

JavaMethod (org.eclipse.ceylon.model.loader.model.JavaMethod)6 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)4 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)4 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)4 FieldValue (org.eclipse.ceylon.model.loader.model.FieldValue)3 JavaBeanValue (org.eclipse.ceylon.model.loader.model.JavaBeanValue)3 JavaParameterValue (org.eclipse.ceylon.model.loader.model.JavaParameterValue)2 LazyClass (org.eclipse.ceylon.model.loader.model.LazyClass)2 LazyFunction (org.eclipse.ceylon.model.loader.model.LazyFunction)2 LazyValue (org.eclipse.ceylon.model.loader.model.LazyValue)2 Class (org.eclipse.ceylon.model.typechecker.model.Class)2 Function (org.eclipse.ceylon.model.typechecker.model.Function)2 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)2 Parameter (org.eclipse.ceylon.model.typechecker.model.Parameter)2 ParameterList (org.eclipse.ceylon.model.typechecker.model.ParameterList)2 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)2 Value (org.eclipse.ceylon.model.typechecker.model.Value)2 ArrayList (java.util.ArrayList)1 FunctionalInterfaceType (org.eclipse.ceylon.model.loader.mirror.FunctionalInterfaceType)1 MethodMirror (org.eclipse.ceylon.model.loader.mirror.MethodMirror)1