use of org.eclipse.ceylon.model.typechecker.model.Function in project ceylon by eclipse.
the class BoxingVisitor method visit.
@Override
public void visit(QualifiedMemberExpression that) {
super.visit(that);
// handle errors gracefully
if (that.getDeclaration() == null)
return;
if (that.getMemberOperator() instanceof Tree.SafeMemberOp) {
TypedDeclaration decl = (TypedDeclaration) that.getDeclaration();
if (CodegenUtil.isRaw(decl))
CodegenUtil.markRaw(that);
if (CodegenUtil.hasTypeErased(decl))
CodegenUtil.markTypeErased(that);
if (CodegenUtil.hasUntrustedType(decl) || hasTypeParameterWithConstraintsOutsideScope(decl.getType(), that.getScope()))
CodegenUtil.markUntrustedType(that);
// we must be boxed, since safe member op "?." returns an optional type
// return;
} else if (that.getMemberOperator() instanceof Tree.MemberOp && Decl.isValueTypeDecl(that.getPrimary()) && CodegenUtil.isUnBoxed(that.getPrimary())) {
// it's unboxed if it's an unboxable type or it's declared void
if (Decl.isValueTypeDecl((TypedDeclaration) that.getDeclaration()) || (that.getDeclaration() instanceof Function && ((Function) that.getDeclaration()).isDeclaredVoid()))
CodegenUtil.markUnBoxed(that);
if (CodegenUtil.isRaw((TypedDeclaration) that.getDeclaration()))
CodegenUtil.markRaw(that);
if (CodegenUtil.hasTypeErased((TypedDeclaration) that.getDeclaration()))
CodegenUtil.markTypeErased(that);
} else {
propagateFromDeclaration(that, (TypedDeclaration) that.getDeclaration());
}
// be (ex: <String>), and in that case we will generate a proper Sequential<String> which is not raw at all
if (that.getMemberOperator() instanceof Tree.SpreadOp) {
// find the return element type
Type elementType = that.getTarget().getType();
CodegenUtil.markTypeErased(that, hasErasure(elementType));
}
if (ExpressionTransformer.isSuperOrSuperOf(that.getPrimary())) {
// if the target is an interface whose type arguments have been turned to raw, make this expression
// as erased
Reference target = that.getTarget();
if (target != null && target.getQualifyingType() != null && target.getQualifyingType().getDeclaration() instanceof Interface) {
if (isRaw(target.getQualifyingType())) {
CodegenUtil.markTypeErased(that);
} else // See note in ClassTransformer.makeDelegateToCompanion for a similar test
{
TypeDeclaration declaration = target.getQualifyingType().getDeclaration();
if (needsRawCastForMixinSuperCall(declaration, target.getType()))
CodegenUtil.markTypeErased(that);
}
}
}
Type primaryType;
if (that.getPrimary() instanceof Tree.Package || that.getTarget() == null) {
primaryType = that.getPrimary().getTypeModel();
} else {
primaryType = that.getTarget().getQualifyingType();
}
if (primaryType != null && (isRaw(primaryType) || willEraseToSequence(primaryType)) && that.getTarget() != null && that.getTarget().getDeclaration() instanceof TypedDeclaration && CodegenUtil.containsTypeParameter(((TypedDeclaration) that.getTarget().getDeclaration()).getType())) {
CodegenUtil.markTypeErased(that);
}
if (isRaw(primaryType) && that.getTypeModel().getDeclaration().isParameterized()) {
CodegenUtil.markRaw(that);
}
}
use of org.eclipse.ceylon.model.typechecker.model.Function in project ceylon by eclipse.
the class CallableBuilder method getParameterTypesFromParameterModels.
private java.util.List<Type> getParameterTypesFromParameterModels() {
java.util.List<Type> parameterTypes = new ArrayList<Type>(numParams);
// get them from our declaration
for (Parameter p : paramLists.getParameters()) {
Type pt;
FunctionOrValue pm = p.getModel();
if (pm instanceof Function && ((Function) pm).isParameter())
pt = gen.getTypeForFunctionalParameter((Function) pm);
else
pt = p.getType();
parameterTypes.add(pt);
}
return parameterTypes;
}
use of org.eclipse.ceylon.model.typechecker.model.Function in project ceylon by eclipse.
the class ClassDoc method writeMethods.
private void writeMethods() throws IOException {
if (methods.isEmpty()) {
return;
}
openTable(null, "Methods", 2, true);
for (Entry<String, SortedSet<Function>> entry : methods.entrySet()) {
int index = 1;
for (Function f : entry.getValue()) {
String id = null;
if (index > 1) {
id = entry.getKey() + "_" + index;
}
doc(id, entry.getKey(), f);
index++;
}
}
closeTable();
}
use of org.eclipse.ceylon.model.typechecker.model.Function in project ceylon by eclipse.
the class AnnotationInvocationVisitor method annoClass.
public static Class annoClass(Tree.InvocationExpression invocation) {
Declaration declaration = ((Tree.BaseMemberOrTypeExpression) invocation.getPrimary()).getDeclaration();
Set<Declaration> ctors = new HashSet<Declaration>();
while (declaration instanceof Function) {
if (!ctors.add(declaration)) {
throw new BugException(invocation, "recursive annotation constructor");
}
declaration = ((AnnotationInvocation) ((Function) declaration).getAnnotationConstructor()).getPrimary();
}
if (declaration instanceof Class) {
return (Class) declaration;
} else {
throw new BugException(invocation, "invocation primary has unexpected declaration: " + declaration);
}
}
use of org.eclipse.ceylon.model.typechecker.model.Function in project ceylon by eclipse.
the class AnnotationInvocationVisitor method transformConstructor.
private static JCAnnotation transformConstructor(ExpressionTransformer exprGen, Tree.InvocationExpression invocation, AnnotationInvocation ai, org.eclipse.ceylon.langtools.tools.javac.util.List<AnnotationFieldName> fieldPath) {
Map<Parameter, ListBuffer<JCExpression>> args = new LinkedHashMap<Parameter, ListBuffer<JCExpression>>();
List<Parameter> classParameters = ai.getClassParameters();
// The class parameter's we've not yet figured out the value for
ArrayList<Parameter> unbound = new ArrayList<Parameter>(classParameters);
for (Parameter classParameter : classParameters) {
for (AnnotationArgument argument : ai.findAnnotationArgumentForClassParameter(invocation, new HashSet<Function>(), classParameter)) {
JCExpression expr = transformConstructorArgument(exprGen, invocation, classParameter, argument, fieldPath);
appendArgument(args, classParameter, expr);
unbound.remove(classParameter);
}
}
outer: for (Parameter classParameter : new ArrayList<>(unbound)) {
// Defaulted argument
if (ai.isInstantiation()) {
if (classParameter.isDefaulted()) {
// That's OK, we'll pick up the default argument from
// the Java Annotation type
unbound.remove(classParameter);
continue outer;
}
} else {
Function ac2 = (Function) ai.getPrimary();
AnnotationInvocation i = (AnnotationInvocation) ac2.getAnnotationConstructor();
for (AnnotationArgument aa : i.getAnnotationArguments()) {
if (aa.getParameter().equals(classParameter)) {
appendArgument(args, classParameter, aa.getTerm().makeAnnotationArgumentValue(exprGen, i, org.eclipse.ceylon.langtools.tools.javac.util.List.<AnnotationFieldName>of(aa)));
unbound.remove(classParameter);
continue outer;
}
}
}
if (Strategy.hasEmptyDefaultArgument(classParameter)) {
appendArgument(args, classParameter, exprGen.make().NewArray(null, null, org.eclipse.ceylon.langtools.tools.javac.util.List.<JCExpression>nil()));
unbound.remove(classParameter);
continue outer;
}
}
for (Parameter classParameter : unbound) {
appendArgument(args, classParameter, exprGen.makeErroneous(invocation, "compiler bug: unbound annotation class parameter " + classParameter.getName()));
}
ListBuffer<JCExpression> assignments = new ListBuffer<JCExpression>();
for (Map.Entry<Parameter, ListBuffer<JCExpression>> entry : args.entrySet()) {
ListBuffer<JCExpression> exprs = entry.getValue();
if (exprs.size() == 1) {
assignments.append(makeArgument(exprGen, invocation, entry.getKey(), exprs.first()));
} else {
assignments.append(makeArgument(exprGen, invocation, entry.getKey(), exprGen.make().NewArray(null, null, exprs.toList())));
}
}
JCAnnotation annotation = exprGen.at(invocation).Annotation(ai.makeAnnotationType(exprGen), assignments.toList());
return annotation;
}
Aggregations