// No interfaces are implemented
JavaTypeName[] interfaces = JavaDefinitionBuilder.EMPTY_TYPE_NAME_ARRAY;
// Now instantiate the java class representation.
JavaTypeName tagDCTypeName = CALToJavaNames.createTypeNameForTagDCFromType(typeConstructor, module);
JavaClassRep tagDCClassRep = new JavaClassRep(tagDCTypeName, className, classModifiers, interfaces);
// Add the body of the class.
// private final int tag;
JavaFieldDeclaration tagField = new JavaFieldDeclaration (Modifier.PRIVATE | Modifier.FINAL, JavaTypeName.INT, "tag", null);
tagDCClassRep.addFieldDeclaration(tagField);
// public TagDC(int tagVal) {this.tag = tagVal;}
JavaConstructor javaConstructor = new JavaConstructor(Modifier.PUBLIC, new String[]{"tagVal"}, new JavaTypeName[]{JavaTypeName.INT}, "TagDC");
tagDCClassRep.addConstructor(javaConstructor);
Assignment tagAssign = new Assignment (new JavaField.Instance(null, "tag", JavaTypeName.INT), METHODVAR_TAGVAL);
javaConstructor.addStatement(new ExpressionStatement(tagAssign));
// public final int getArity() {return 0;}
int modifiers = Modifier.PUBLIC | Modifier.FINAL;
JavaTypeName returnType = JavaTypeName.INT;
JavaMethod javaMethod = new JavaMethod(modifiers, returnType, "getArity");
tagDCClassRep.addMethod(javaMethod);
javaMethod.addStatement(new ReturnStatement(LiteralWrapper.make(Integer.valueOf(0))));
// public final int getOrdinalValue(){return tag;}
modifiers = Modifier.PUBLIC | Modifier.FINAL;
returnType = JavaTypeName.INT;
javaMethod = new JavaMethod(modifiers, returnType, "getOrdinalValue");
tagDCClassRep.addMethod(javaMethod);
javaMethod.addStatement(new ReturnStatement(new JavaField.Instance(null, "tag", JavaTypeName.INT)));
// public final String getModuleName() ...
modifiers = Modifier.PUBLIC | Modifier.FINAL;
returnType = JavaTypeName.STRING;
javaMethod = new JavaMethod(modifiers, returnType, "getModuleName");
tagDCClassRep.addMethod(javaMethod);
javaMethod.addStatement(new ReturnStatement(LiteralWrapper.make (typeConstructor.getName().getModuleName().toSourceText())));
// public final String getUnqualifiedName() ...
modifiers = Modifier.PUBLIC | Modifier.FINAL;
returnType = JavaTypeName.STRING;
javaMethod = new JavaMethod(modifiers, returnType, "getUnqualifiedName");
tagDCClassRep.addMethod(javaMethod);
SwitchStatement sw = new SwitchStatement (new JavaField.Instance(null, "tag", JavaTypeName.INT));
for (int i = 0, nDCs = dataConsList.size(); i < nDCs; ++i) {
DataConstructor dc = dataConsList.get (i);
sw.addCase(new SwitchStatement.IntCaseGroup(dc.getOrdinal(), new ReturnStatement (LiteralWrapper.make(dc.getName().getUnqualifiedName()))));
}
javaMethod.addStatement (sw);
javaMethod.addStatement(new ReturnStatement(LiteralWrapper.make ("Unknown data constructor")));
// public final String getQualfiedName() ...
modifiers = Modifier.PUBLIC | Modifier.FINAL;
returnType = JavaTypeName.STRING;
javaMethod = new JavaMethod(modifiers, returnType, "getQualifiedName");
tagDCClassRep.addMethod(javaMethod);
sw = new SwitchStatement (new JavaField.Instance(null, "tag", JavaTypeName.INT));
for (int i = 0, nDCs = dataConsList.size(); i < nDCs; ++i) {
DataConstructor dc = dataConsList.get (i);
sw.addCase(new SwitchStatement.IntCaseGroup(dc.getOrdinal(), new ReturnStatement (LiteralWrapper.make(dc.getName().getQualifiedName()))));
}