use of org.eclipse.ceylon.model.typechecker.model.FunctionOrValue in project ceylon by eclipse.
the class MethodDefinitionBuilder method parameter.
public MethodDefinitionBuilder parameter(Node node, Parameter param, TypedReference typedRef, List<JCAnnotation> userAnnotations, int flags, WideningRules wideningRules) {
String paramName = param.getName();
String aliasedName = Naming.getAliasedParameterName(param);
FunctionOrValue mov = CodegenUtil.findMethodOrValueForParam(param);
if (typedRef == null)
typedRef = gen.getTypedReference(mov);
long mods = 0;
if (!Decl.isNonTransientValue(mov) || !mov.isVariable() || mov.isCaptured()) {
mods |= FINAL;
}
NonWideningParam nonWideningParam = getNonWideningParam(typedRef, wideningRules);
flags |= nonWideningParam.flags;
mods |= nonWideningParam.modifiers;
return parameter(node, mods, param.getModel().getAnnotations(), userAnnotations, paramName, aliasedName, param, nonWideningParam.nonWideningDecl, nonWideningParam.nonWideningType, flags);
}
use of org.eclipse.ceylon.model.typechecker.model.FunctionOrValue in project ceylon by eclipse.
the class ParameterDefinitionBuilder method functionalParameters.
static void functionalParameters(StringBuilder sb, ParameterList pl) {
sb.append('(');
Iterator<Parameter> parameters = pl.getParameters().iterator();
while (parameters.hasNext()) {
Parameter p = parameters.next();
FunctionOrValue pm = p.getModel();
sb.append(pm.getName());
if (p.isSequenced()) {
if (p.isAtLeastOne()) {
sb.append('+');
} else {
sb.append('*');
}
}
if (pm instanceof Function) {
functionalName(sb, (Function) pm);
}
if (parameters.hasNext()) {
sb.append(',');
}
}
sb.append(')');
}
use of org.eclipse.ceylon.model.typechecker.model.FunctionOrValue in project ceylon by eclipse.
the class SmallDeclarationVisitor method setSmallType.
protected static void setSmallType(FunctionOrValue f) {
Type t = smallUnderlyingType(f.getType());
f.setType(t);
if (f instanceof Value) {
Setter s = ((Value) f).getSetter();
if (s != null) {
s.getParameter().getModel().setType(t);
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.FunctionOrValue in project ceylon by eclipse.
the class JsonPackage method loadAttribute.
FunctionOrValue loadAttribute(String name, Map<String, Object> m, Scope parent, List<TypeParameter> typeParameters) {
String metatype = (String) m.get(KEY_METATYPE);
Value d = new Value();
d.setTransient(METATYPE_GETTER.equals(metatype));
d.setName(name);
d.setContainer(parent);
d.setScope(parent);
d.setUnit(u2);
if (parent == this) {
u2.addDeclaration(d);
addMember(null);
}
setAnnotations(d, (Integer) m.remove(KEY_PACKED_ANNS), m.remove(KEY_ANNOTATIONS));
d.setDynamic(m.remove(KEY_DYNAMIC) != null);
if (m.containsKey("var")) {
d.setVariable(true);
}
@SuppressWarnings("unchecked") final Map<String, Object> ktype = (Map<String, Object>) m.get(KEY_TYPE);
d.setType(getTypeFromJson(ktype, parent instanceof Declaration ? (Declaration) parent : null, typeParameters));
@SuppressWarnings("unchecked") final Map<String, Object> smap = (Map<String, Object>) m.remove("$set");
if (smap != null) {
Setter s = new Setter();
s.setName(name);
s.setContainer(parent);
s.setScope(parent);
s.setUnit(u2);
s.setGetter(d);
d.setSetter(s);
if (parent == this) {
u2.addDeclaration(s);
addMember(null);
}
setAnnotations(s, (Integer) smap.remove(KEY_PACKED_ANNS), smap.remove(KEY_ANNOTATIONS));
s.setType(d.getType());
}
return d;
}
use of org.eclipse.ceylon.model.typechecker.model.FunctionOrValue in project ceylon by eclipse.
the class MetamodelGenerator method parameterListMap.
/**
* Create a list of maps for the parameter list. Each map will be a parameter, including
* name, type, default value (if any), and whether it's sequenced.
*/
private List<Map<String, Object>> parameterListMap(ParameterList plist, Declaration from) {
if (plist == null) {
// Possibly an anonymous class for an anonymous object
return null;
}
List<Parameter> parms = plist.getParameters();
if (parms.size() > 0) {
List<Map<String, Object>> p = new ArrayList<>(parms.size());
for (Parameter parm : parms) {
Map<String, Object> pm = new HashMap<>();
pm.put(KEY_NAME, parm.getName());
pm.put(KEY_METATYPE, METATYPE_PARAMETER);
if (parm.isSequenced()) {
pm.put("seq", 1);
}
if (parm.isDefaulted()) {
pm.put(KEY_DEFAULT, 1);
}
if (parm.isAtLeastOne()) {
pm.put("$min1", 1);
}
final FunctionOrValue parmtype = parm.getModel();
if (parmtype != null && parmtype.getDeclarationKind() == DeclarationKind.TYPE_PARAMETER) {
pm.put(KEY_TYPE, parmtype.getName());
} else {
pm.put(KEY_TYPE, typeMap(parm.getType(), from));
}
if (parm.isHidden()) {
pm.put("$hdn", 1);
}
if (parmtype instanceof Function) {
pm.put("$pt", "f");
List<List<Map<String, Object>>> _paramLists = new ArrayList<>(((Function) parmtype).getParameterLists().size());
for (ParameterList subplist : ((Function) parmtype).getParameterLists()) {
List<Map<String, Object>> params = parameterListMap(subplist, from);
if (params == null) {
params = Collections.emptyList();
}
_paramLists.add(params);
}
if (_paramLists.size() > 1 || !_paramLists.get(0).isEmpty()) {
pm.put(KEY_PARAMS, _paramLists);
}
}
// TODO do these guys need anything else?
/*if (parm.getDefaultArgument() != null) {
//This could be compiled to JS...
pm.put(ANN_DEFAULT, parm.getDefaultArgument().getSpecifierExpression().getExpression().getTerm().getText());
}*/
encodeAnnotations(parm.getModel().getAnnotations(), parm.getModel(), pm);
p.add(pm);
}
return p;
}
return null;
}
Aggregations