return makeTopLevelValueOrFunctionLiteral(expr);
}else if(expr.getWantsDeclaration()){
return makeMemberValueOrFunctionDeclarationLiteral(expr, declaration);
}else{
// get its produced ref
ProducedReference producedReference = expr.getTarget();
// it's a member we get from its container type
ProducedType containerType = producedReference.getQualifyingType();
// if we have no container type it means we have an object member
boolean objectMember = containerType == null;
JCExpression memberCall;
if(objectMember){
// We don't care about the type args for the cast, nor for the reified container expr, because
// we take the real reified container type from the container instance, and that one has the type
// arguments
containerType = ((Class)declaration.getContainer()).getType();
}
JCExpression typeCall = makeTypeLiteralCall(containerType, false, expr.getTypeModel());
// make sure we cast it to ClassOrInterface
TypeDeclaration classOrInterfaceDeclaration = (TypeDeclaration) typeFact().getLanguageModuleModelDeclaration("ClassOrInterface");
JCExpression classOrInterfaceTypeExpr = makeJavaType(
classOrInterfaceDeclaration.getProducedReference(null, Arrays.asList(containerType)).getType());
typeCall = make().TypeCast(classOrInterfaceTypeExpr, typeCall);
// we will need a TD for the container
// Note that we don't use Basic for the container for object members, because that's not how we represent
// anonymous types.
JCExpression reifiedContainerExpr = makeReifiedTypeArgument(containerType);
// make a raw call and cast
if(declaration instanceof Method){
// we need to get types for each type argument
JCExpression closedTypesExpr;
if(expr.getTypeArgumentList() != null)
closedTypesExpr = getClosedTypesSequential(expr.getTypeArgumentList().getTypeModels());
else
closedTypesExpr = null;
// we also need type descriptors for ret and args
ProducedType callableType = producedReference.getFullType();
JCExpression reifiedReturnTypeExpr = makeReifiedTypeArgument(typeFact().getCallableReturnType(callableType));
JCExpression reifiedArgumentsExpr = makeReifiedTypeArgument(typeFact().getCallableTuple(callableType));
List<JCExpression> arguments;
if(closedTypesExpr != null)
arguments = List.of(reifiedContainerExpr, reifiedReturnTypeExpr, reifiedArgumentsExpr,
ceylonLiteral(declaration.getName()), closedTypesExpr);
else
arguments = List.of(reifiedContainerExpr, reifiedReturnTypeExpr, reifiedArgumentsExpr,
ceylonLiteral(declaration.getName()));
memberCall = make().Apply(null, makeSelect(typeCall, "getMethod"), arguments);
}else if(declaration instanceof Value){
JCExpression reifiedGetExpr = makeReifiedTypeArgument(producedReference.getType());
String getterName = "getAttribute";
ProducedType ptype;
if(!((Value)declaration).isVariable())
ptype = typeFact().getNothingDeclaration().getType();
else
ptype = producedReference.getType();
JCExpression reifiedSetExpr = makeReifiedTypeArgument(ptype);
memberCall = make().Apply(null, makeSelect(typeCall, getterName), List.of(reifiedContainerExpr, reifiedGetExpr, reifiedSetExpr,
ceylonLiteral(declaration.getName())));
}else{