use of org.eclipse.ceylon.model.typechecker.model.Type in project ceylon by eclipse.
the class CallableBuilder method makeCallTypedMethod.
/**
* Makes the {@code call$typed()} method, using the given body.
*/
private MethodDefinitionBuilder makeCallTypedMethod(List<JCStatement> body) {
// make the method
MethodDefinitionBuilder methodBuilder = MethodDefinitionBuilder.systemMethod(gen, Naming.getCallableTypedMethodName());
methodBuilder.noAnnotations();
methodBuilder.modifiers(Flags.PRIVATE);
Type returnType = gen.getReturnTypeOfCallable(typeModel);
methodBuilder.resultType(gen.makeJavaType(returnType, JT_NO_PRIMITIVES), null);
// add all parameters
int i = 0;
for (Parameter param : paramLists.getParameters()) {
ParameterDefinitionBuilder parameterBuilder = ParameterDefinitionBuilder.systemParameter(gen, Naming.getAliasedParameterName(param));
JCExpression paramType = gen.makeJavaType(parameterTypes.get(i));
parameterBuilder.modifiers(Flags.FINAL);
parameterBuilder.type(new TransformedType(paramType));
methodBuilder.parameter(parameterBuilder);
i++;
}
// Return the call result, or null if a void method
methodBuilder.body(body);
return methodBuilder;
}
use of org.eclipse.ceylon.model.typechecker.model.Type in project ceylon by eclipse.
the class CallableBuilder method javaStaticMethodReference.
public static CallableBuilder javaStaticMethodReference(CeylonTransformer gen, Node node, Type typeModel, final Functional methodOrClass, Reference producedReference, Type expectedType) {
final ParameterList parameterList = methodOrClass.getFirstParameterList();
CallableBuilder inner = new CallableBuilder(gen, node, typeModel, parameterList);
ArrayList<Type> pt = new ArrayList<>();
for (Parameter p : methodOrClass.getFirstParameterList().getParameters()) {
pt.add(((Tree.MemberOrTypeExpression) node).getTarget().getTypedParameter(p).getType());
}
inner.parameterTypes = pt;
inner.defaultValueCall = inner.new MemberReferenceDefaultValueCall(methodOrClass);
JCExpression innerInvocation = gen.expressionGen().makeJavaStaticInvocation(gen, methodOrClass, producedReference, parameterList);
// Need to worry about boxing for Function and FunctionalParameter
if (methodOrClass instanceof TypedDeclaration) {
innerInvocation = gen.expressionGen().applyErasureAndBoxing(innerInvocation, methodOrClass.getType(), !CodegenUtil.isUnBoxed((TypedDeclaration) methodOrClass), BoxingStrategy.BOXED, methodOrClass.getType());
} else if (Strategy.isInstantiatorUntyped((Class) methodOrClass)) {
// $new method declared to return Object, so needs typecast
innerInvocation = gen.make().TypeCast(gen.makeJavaType(((Class) methodOrClass).getType()), innerInvocation);
}
List<JCStatement> innerBody = List.<JCStatement>of(gen.make().Return(innerInvocation));
inner.useDefaultTransformation(innerBody);
if (expectedType != null)
inner.checkForFunctionalInterface(expectedType);
return inner;
}
use of org.eclipse.ceylon.model.typechecker.model.Type in project ceylon by eclipse.
the class CallableBuilder method makeCallableVaryParam.
private ParameterDefinitionBuilder makeCallableVaryParam(long flags, int ii) {
Type iteratedType = gen.typeFact().getIteratedType(parameterTypes.get(parameterTypes.size() - 1));
// $call$var()'s variadic parameter is *always* erasred to Sequential
// even if it's a Variadic+ parameter
JCExpression type = gen.makeJavaType(gen.typeFact().getSequentialType(iteratedType), AbstractTransformer.JT_RAW);
ParameterDefinitionBuilder pdb = ParameterDefinitionBuilder.systemParameter(gen, getParamName(ii));
pdb.modifiers(Flags.FINAL | flags);
pdb.type(new TransformedType(type, null, gen.makeAtNonNull()));
return pdb;
}
use of org.eclipse.ceylon.model.typechecker.model.Type in project ceylon by eclipse.
the class ClassDoc method writeListOnSummary.
private void writeListOnSummary(String cssClass, String title, List<?> types) throws IOException {
if (!isEmpty(types)) {
open("div class='" + cssClass + " section'");
around("span class='title'", title);
boolean first = true;
for (Object type : types) {
if (!first) {
write(", ");
} else {
first = false;
}
if (type instanceof TypedDeclaration) {
TypedDeclaration decl = (TypedDeclaration) type;
linkRenderer().to(decl).useScope(klass).write();
} else if (type instanceof ClassOrInterface) {
ClassOrInterface coi = (ClassOrInterface) type;
linkRenderer().to(coi).useScope(klass).printAbbreviated(!isAbbreviatedType(coi)).write();
} else {
Type pt = (Type) type;
linkRenderer().to(pt).useScope(klass).printAbbreviated(!isAbbreviatedType(pt.getDeclaration())).write();
}
}
close("div");
}
}
use of org.eclipse.ceylon.model.typechecker.model.Type in project ceylon by eclipse.
the class ClassOrPackageDoc method isConstantValue.
private boolean isConstantValue(Declaration d) {
if (Decl.isValue(d)) {
Value value = (Value) d;
if (value.isShared() && !value.isVariable() && !value.isDynamicallyTyped()) {
Unit unit = value.getUnit();
Type type = value.getType();
if (type.isSequential()) {
type = unit.getSequentialElementType(type);
}
if (type.isString() || type.isInteger() || type.isFloat() || type.isCharacter()) {
return true;
}
}
}
return false;
}
Aggregations