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;
}
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;
}
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);
}
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);
}
}
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);
}
}
}
Aggregations