}
/** Loads an object declaration, creating it if necessary, and returns its type declaration. */
@SuppressWarnings("unchecked")
TypeDeclaration loadObject(String name, Map<String, Object> m, Scope parent, List<TypeParameter> existing) {
Value obj;
if (m.get(MetamodelGenerator.KEY_METATYPE) instanceof Value) {
obj = (Value)m.get(MetamodelGenerator.KEY_METATYPE);
} else {
obj = new Value();
m.put(MetamodelGenerator.KEY_METATYPE, obj);
obj.setName(name);
obj.setContainer(parent);
obj.setUnit(u2);
com.redhat.ceylon.compiler.typechecker.model.Class type = new com.redhat.ceylon.compiler.typechecker.model.Class();
type.setName(name);
type.setAnonymous(true);
type.setUnit(u2);
type.setContainer(parent);
if (parent == this) {
u2.addDeclaration(obj);
u2.addDeclaration(type);
}
parent.addMember(obj);
obj.setType(type.getType());
setAnnotations(obj, (Integer)m.get(MetamodelGenerator.KEY_PACKED_ANNS),
(Map<String,Object>)m.get(MetamodelGenerator.KEY_ANNOTATIONS));
setAnnotations(obj.getTypeDeclaration(), (Integer)m.remove(MetamodelGenerator.KEY_PACKED_ANNS),
(Map<String,Object>)m.remove(MetamodelGenerator.KEY_ANNOTATIONS));
if (type.getExtendedType() == null) {
if (m.containsKey("super")) {
type.setExtendedType(getTypeFromJson((Map<String,Object>)m.remove("super"),
parent instanceof Declaration ? (Declaration)parent : null, existing));
} else {
type.setExtendedType(getTypeFromJson(idobj, parent instanceof Declaration ? (Declaration)parent : null, existing));
}
}
if (m.containsKey(MetamodelGenerator.KEY_SATISFIES)) {
for (ProducedType sat : parseTypeList((List<Map<String,Object>>)m.remove(MetamodelGenerator.KEY_SATISFIES), existing)) {
Util.addToIntersection(type.getSatisfiedTypes(), sat, u2);
}
}
if (m.containsKey(MetamodelGenerator.KEY_INTERFACES)) {
for (Map.Entry<String,Map<String,Object>> inner : ((Map<String,Map<String,Object>>)m.remove(MetamodelGenerator.KEY_INTERFACES)).entrySet()) {
loadInterface(inner.getKey(), inner.getValue(), type, existing);
}
}
if (m.containsKey(MetamodelGenerator.KEY_CLASSES)) {
for (Map.Entry<String,Map<String,Object>> inner : ((Map<String,Map<String,Object>>)m.remove(MetamodelGenerator.KEY_CLASSES)).entrySet()) {
loadClass(inner.getKey(), inner.getValue(), type, existing);
}
}
if (m.containsKey(MetamodelGenerator.KEY_OBJECTS)) {
for (Map.Entry<String,Map<String,Object>> inner : ((Map<String,Map<String,Object>>)m.remove(MetamodelGenerator.KEY_OBJECTS)).entrySet()) {
loadObject(inner.getKey(), inner.getValue(), type, existing);
}
}
addAttributesAndMethods(m, type, existing);
}
return obj.getTypeDeclaration();
}