//this class extends "mx.resources.ResourceBundle"
IResolvedQualifiersReference resourceBundleReference = ReferenceFactory.packageQualifiedReference(
project.getWorkspace(), project.getResourceBundleClass());
//Create constructor instruction list
InstructionList constructorInstructionList = new InstructionList();
constructorInstructionList.addInstruction(ABCConstants.OP_getlocal0);
constructorInstructionList.addInstruction(ABCConstants.OP_pushstring, locale);
constructorInstructionList.addInstruction(ABCConstants.OP_pushstring, bundleName);
constructorInstructionList.addInstruction(ABCConstants.OP_constructsuper, 2);
constructorInstructionList.addInstruction(ABCConstants.OP_returnvoid);
IResolvedQualifiersReference mainClassRef = ReferenceFactory.packageQualifiedReference(
project.getWorkspace(), qualifiedClassName);
ClassGeneratorHelper classGen = new ClassGeneratorHelper(project, emitter,
mainClassRef.getMName(),
(ClassDefinition)resourceBundleReference.resolve(project),
Collections.<Name> emptyList(), Collections.<Name> emptyList(),
constructorInstructionList, true);
//Create method body for getContents
InstructionList bodyInstructionList = new InstructionList();
bodyInstructionList.addInstruction(ABCConstants.OP_getlocal0);
bodyInstructionList.addInstruction(ABCConstants.OP_pushscope);
//Create key value pair entries "key":"value"
int entryCount = 0;
for (int i = 0; i < fileNode.getChildCount(); i++)
{
IASNode node = fileNode.getChild(i);
if (node instanceof ResourceBundleEntryNode)
{
entryCount++;
ResourceBundleEntryNode entryNode = (ResourceBundleEntryNode)node;
//push key
bodyInstructionList.addInstruction(ABCConstants.OP_pushstring, entryNode.getKeyNode().getValue());
//push value
ExpressionNodeBase valueNode = entryNode.getValueNode();
switch (valueNode.getNodeID())
{
case LiteralStringID:
bodyInstructionList.addInstruction(ABCConstants.OP_pushstring,
((LiteralNode)valueNode).getValue());
break;
case ClassReferenceID:
ClassReferenceNode crn = (ClassReferenceNode)valueNode;
if (crn.getName() != null)
{
IResolvedQualifiersReference refClass = ReferenceFactory.packageQualifiedReference(project.getWorkspace(), crn.getName());
if (refClass.resolve(project, crn.getASScope(), DependencyType.EXPRESSION, true) == null)
{
ICompilerProblem problem = new UnresolvedClassReferenceProblem(crn, crn.getName());
problems.add(problem);
}
}
String className = crn.getName();
if(className == null)
{
bodyInstructionList.addInstruction(ABCConstants.OP_pushnull);
}
else
{
IResolvedQualifiersReference classRef = ReferenceFactory.packageQualifiedReference(
project.getWorkspace(), className);
bodyInstructionList.addInstruction(ABCConstants.OP_getlex, classRef.getMName());
}
break;
case EmbedID:
EmbedNode embedNode = (EmbedNode)valueNode;
try
{
String name = embedNode.getName(project, problems);
IResolvedQualifiersReference embedClassRef = ReferenceFactory.packageQualifiedReference(
project.getWorkspace(), name);
bodyInstructionList.addInstruction(ABCConstants.OP_getlex, embedClassRef.getMName());
}
catch (InterruptedException ex)
{
problems.add(new CodegenInternalProblem(embedNode, ex));
}
break;
default:
//This shouldn't happen. Should we handle this case by collecting a problem?
}
}
}
bodyInstructionList.addInstruction(ABCConstants.OP_newobject, entryCount);
bodyInstructionList.addInstruction(ABCConstants.OP_returnvalue);
Name getContentsMethodName = new Name(ABCConstants.CONSTANT_Qname,
new Nsset(classGen.getProtectedNamespace()), "getContent");
//Create getContents method