@SuppressWarnings("unchecked")
Interface loadInterface(String name, Map<String, Object> m, Scope parent, final List<TypeParameter> existing) {
//Check if it's been loaded first
//It hasn't been loaded, so create it
Interface t;
m.remove(MetamodelGenerator.KEY_NAME);
if (m.get(MetamodelGenerator.KEY_METATYPE) instanceof Interface) {
t = (Interface)m.get(MetamodelGenerator.KEY_METATYPE);
if (m.size() <= 3) {
//it's been loaded
return t;
}
} else {
if (m.containsKey("$alias")) {
t = new InterfaceAlias();
} else {
t = new Interface();
}
t.setContainer(parent);
t.setName(name);
t.setUnit(u2);
if (parent == this) {
u2.addDeclaration(t);
}
parent.addMember(t);
m.put(MetamodelGenerator.KEY_METATYPE, t);
setAnnotations(t, (Integer)m.remove(MetamodelGenerator.KEY_PACKED_ANNS),
(Map<String,Object>)m.remove(MetamodelGenerator.KEY_ANNOTATIONS));
}
if (m.remove(MetamodelGenerator.KEY_DYNAMIC) != null) {
t.setDynamic(true);
}
List<TypeParameter> tparms = t.getTypeParameters();
List<Map<String,Object>> listOfMaps = (List<Map<String,Object>>)m.get(MetamodelGenerator.KEY_TYPE_PARAMS);
if (listOfMaps != null && (tparms == null || tparms.size() < listOfMaps.size())) {
tparms = parseTypeParameters(listOfMaps, t, existing);
m.remove(MetamodelGenerator.KEY_TYPE_PARAMS);
}
final List<TypeParameter> allparms = JsonPackage.merge(tparms, existing);
//All interfaces extend Object, except aliases
if (t.getExtendedType() == null) {
if (t.isAlias()) {
t.setExtendedType(getTypeFromJson((Map<String,Object>)m.remove("$alias"),
parent instanceof Declaration ? (Declaration)parent : null, allparms));
} else {
t.setExtendedType(getTypeFromJson(objclass,
parent instanceof Declaration ? (Declaration)parent : null, null));
}
}
if (m.containsKey(MetamodelGenerator.KEY_SELF_TYPE)) {
for (TypeParameter _tp : tparms) {
if (_tp.getName().equals(m.get(MetamodelGenerator.KEY_SELF_TYPE))) {
t.setSelfType(_tp.getType());
_tp.setSelfTypedDeclaration(t);
}
}
m.remove(MetamodelGenerator.KEY_SELF_TYPE);
}
if (m.containsKey("of") && t.getCaseTypes() == null) {
t.setCaseTypes(parseTypeList((List<Map<String,Object>>)m.remove("of"), allparms));
}
if (m.containsKey(MetamodelGenerator.KEY_SATISFIES)) {
for (ProducedType s : parseTypeList((List<Map<String,Object>>)m.remove(MetamodelGenerator.KEY_SATISFIES), allparms)) {
Util.addToIntersection(t.getSatisfiedTypes(), s, u2);
}
}
addAttributesAndMethods(m, t, allparms);
return t;
}