Search in sources :

Example 1 with JavaMethod

use of com.redhat.ceylon.model.loader.model.JavaMethod in project ceylon-compiler by ceylon.

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 : LazyFunction(com.redhat.ceylon.model.loader.model.LazyFunction) Function(com.redhat.ceylon.model.typechecker.model.Function) JavaMethod(com.redhat.ceylon.model.loader.model.JavaMethod) Class(com.redhat.ceylon.model.typechecker.model.Class) LazyClass(com.redhat.ceylon.model.loader.model.LazyClass) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration)

Example 2 with JavaMethod

use of com.redhat.ceylon.model.loader.model.JavaMethod in project ceylon-compiler by ceylon.

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")) && 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")) && method.getFirstParameterList().getParameters().size() == 1 && AbstractTransformer.isAnything(method.getType()))
        return quote(name);
    return name;
}
Also used : LazyFunction(com.redhat.ceylon.model.loader.model.LazyFunction) Function(com.redhat.ceylon.model.typechecker.model.Function) JavaMethod(com.redhat.ceylon.model.loader.model.JavaMethod) LazyFunction(com.redhat.ceylon.model.loader.model.LazyFunction)

Aggregations

JavaMethod (com.redhat.ceylon.model.loader.model.JavaMethod)2 LazyFunction (com.redhat.ceylon.model.loader.model.LazyFunction)2 Function (com.redhat.ceylon.model.typechecker.model.Function)2 LazyClass (com.redhat.ceylon.model.loader.model.LazyClass)1 Class (com.redhat.ceylon.model.typechecker.model.Class)1 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)1 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)1 TypedDeclaration (com.redhat.ceylon.model.typechecker.model.TypedDeclaration)1