/** This method encodes the type parameters of a Tuple in the same way
* as a parameter list for runtime. */
private static void encodeTupleAsParameterListForRuntime(ProducedType _tuple, boolean nameAndMetatype, GenerateJsVisitor gen) {
gen.out("[");
int pos = 1;
TypeDeclaration tdecl = _tuple.getDeclaration();
while (!(gen.getTypeUtils().empty.equals(tdecl) || tdecl instanceof TypeParameter)) {
if (pos > 1) gen.out(",");
gen.out("{");
pos++;
if (nameAndMetatype) {
gen.out(MetamodelGenerator.KEY_NAME, ":'p", Integer.toString(pos), "',");
gen.out(MetamodelGenerator.KEY_METATYPE, ":'", MetamodelGenerator.METATYPE_PARAMETER, "',");
}
gen.out(MetamodelGenerator.KEY_TYPE, ":");
if (gen.getTypeUtils().tuple.equals(tdecl) || (tdecl.getCaseTypeDeclarations() != null
&& tdecl.getCaseTypeDeclarations().size()==2
&& tdecl.getCaseTypeDeclarations().contains(gen.getTypeUtils().tuple))) {
if (gen.getTypeUtils().tuple.equals(tdecl)) {
metamodelTypeNameOrList(gen.getCurrentPackage(), _tuple.getTypeArgumentList().get(1), gen);
_tuple = _tuple.getTypeArgumentList().get(2);
} else {
//Handle union types for defaulted parameters
for (ProducedType mt : _tuple.getCaseTypes()) {
if (gen.getTypeUtils().tuple.equals(mt.getDeclaration())) {
metamodelTypeNameOrList(gen.getCurrentPackage(), mt.getTypeArgumentList().get(1), gen);
_tuple = mt.getTypeArgumentList().get(2);
break;
}
}
gen.out(",", MetamodelGenerator.KEY_DEFAULT,":1");
}
} else if (tdecl.inherits(gen.getTypeUtils().sequential)) {
ProducedType _t2 = _tuple.getSupertype(gen.getTypeUtils().sequential);
//Handle Sequence, for nonempty variadic parameters
metamodelTypeNameOrList(gen.getCurrentPackage(), _t2.getTypeArgumentList().get(0), gen);
gen.out(",seq:1");
_tuple = gen.getTypeUtils().empty.getType();
} else if (tdecl instanceof UnionType) {
metamodelTypeNameOrList(gen.getCurrentPackage(), _tuple, gen);
tdecl = gen.getTypeUtils().empty; _tuple=null;
} else {
gen.out("\n/*WARNING3! Tuple is actually ", _tuple.getProducedTypeQualifiedName(), ", ", tdecl.getName(),"*/");
if (pos > 100) {
break;
}
}
gen.out("}");