Skip to content

Commit

Permalink
Fixed the creation order of things.
Browse files Browse the repository at this point in the history
  • Loading branch information
lexi committed Sep 25, 2014
1 parent 105ff10 commit e34a779
Showing 1 changed file with 79 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,36 +101,75 @@ public CMInfoFactory(TIS typeInfoSet) {

}

@SuppressWarnings("unchecked")
public MModelInfo<T, C> createModel() {
final CMModel<T, C> model = new CMModel<T, C>(
createModelInfoOrigin(typeInfoSet));

createBuiltinLeafInfos(model);
createEnumLeafInfos(model);
createClassInfos(model);
createElementInfos(model);
return model;

}

private void createElementInfos(final CMModel<T, C> model) {
Iterable<? extends ElementInfo<T, C>> elements = typeInfoSet
.getAllElements();
for (ElementInfo<T, C> element : elements) {
final EI ei = (EI) element;
elementInfos.put(ei, createElementInfo(ei));
}
for (ElementInfo<T, C> element : elements) {
model.addElementInfo(getElementInfo((EI) element));
}
}

private void createEnumLeafInfos(final CMModel<T, C> model) {
Collection<? extends EnumLeafInfo<T, C>> enums = typeInfoSet.enums()
.values();
for (EnumLeafInfo<T, C> enumLeafInfo : enums) {
@SuppressWarnings("unchecked")
final ELI eli = (ELI) enumLeafInfo;
enumLeafInfos.put(eli, createEnumLeafInfo(eli));
}
for (Map.Entry<ELI, MEnumLeafInfo<T, C>> entry : enumLeafInfos
.entrySet()) {
populateEnumLeafInfo(entry.getKey(), entry.getValue());
}
for (EnumLeafInfo<T, C> enumLeafInfo : enums) {
model.addEnumLeafInfo(getTypeInfo((ELI) enumLeafInfo));
}
}

private void createBuiltinLeafInfos(final CMModel<T, C> model) {
Collection<? extends BuiltinLeafInfo<T, C>> builtins = typeInfoSet
.builtins().values();
for (BuiltinLeafInfo<T, C> builtinLeafInfo : builtins) {
@SuppressWarnings("unchecked")
final BLI bli = (BLI) builtinLeafInfo;
builtinLeafInfos.put(bli, createBuiltinLeafInfo(bli));
}
for (BuiltinLeafInfo<T, C> builtinLeafInfo : builtins) {
model.addBuiltinLeafInfo(getTypeInfo((BLI) builtinLeafInfo));
}
}

private void createClassInfos(final CMModel<T, C> model) {
Collection<? extends ClassInfo<T, C>> beans = typeInfoSet.beans()
.values();

for (ClassInfo<T, C> classInfo : beans) {
model.addClassInfo(getTypeInfo((CI) classInfo));
@SuppressWarnings("unchecked")
final CI ci = (CI) classInfo;
classInfos.put(ci, createClassInfo(ci));
}

Collection<? extends EnumLeafInfo<T, C>> enums = typeInfoSet.enums()
.values();
for (EnumLeafInfo<T, C> enumLeafInfo : enums) {
model.addEnumLeafInfo(getTypeInfo((ELI) enumLeafInfo));
for (Map.Entry<CI, MClassInfo<T, C>> entry : classInfos.entrySet()) {
populateClassInfo(entry.getKey(), entry.getValue());
}

Iterable<? extends ElementInfo<T, C>> elements = typeInfoSet
.getAllElements();
for (ElementInfo<T, C> element : elements) {
model.addElementInfo(getElementInfo((EI) element));
for (ClassInfo<T, C> classInfo : beans) {
model.addClassInfo(getTypeInfo((CI) classInfo));
}
return model;

}

protected MTypeInfo<T, C> getTypeInfo(PropertyInfo<T, C> propertyInfo,
Expand Down Expand Up @@ -182,13 +221,7 @@ protected MTypeInfo<T, C> getTypeInfo(TI typeInfo) {
}

private MBuiltinLeafInfo<T, C> getTypeInfo(BLI typeInfo) {
MBuiltinLeafInfo<T, C> builtinLeafInfo = builtinLeafInfos.get(typeInfo);
if (builtinLeafInfo == null) {
builtinLeafInfo = createBuiltinLeafInfo(typeInfo);
builtinLeafInfos.put(typeInfo, builtinLeafInfo);
return builtinLeafInfo;
}
return builtinLeafInfo;
return builtinLeafInfos.get(typeInfo);
}

private MTypeInfo<T, C> getTypeInfo(EI info) {
Expand All @@ -201,53 +234,27 @@ private MTypeInfo<T, C> getTypeInfo(EI info) {
}

protected MClassInfo<T, C> getTypeInfo(CI info) {

MClassInfo<T, C> classInfo = classInfos.get(info);

if (classInfo == null) {

classInfo = createClassInfo(info);
classInfos.put(info, classInfo);

if (info.hasAttributeWildcard()) {
classInfo
.addProperty(createAnyAttributePropertyInfo(classInfo));
}

for (PropertyInfo<T, C> p : (List<? extends PropertyInfo<T, C>>) info
.getProperties()) {
classInfo.addProperty(createPropertyInfo(classInfo, (PI) p));
}
}
return classInfo;
return classInfos.get(info);
}

private MEnumLeafInfo<T, C> getTypeInfo(ELI info) {
MEnumLeafInfo<T, C> enumLeafInfo = enumLeafInfos.get(info);
if (enumLeafInfo == null) {
enumLeafInfo = createEnumLeafInfo(info);
enumLeafInfos.put(info, enumLeafInfo);
return enumLeafInfos.get(info);

@SuppressWarnings("rawtypes")
Iterable<? extends EnumConstant> _constants = info.getConstants();
@SuppressWarnings("unchecked")
final Iterable<? extends EnumConstant<T, C>> enumConstants = (Iterable<? extends EnumConstant<T, C>>) _constants;
for (EnumConstant<?, ?> enumConstant : enumConstants) {
enumLeafInfo.addEnumConstantInfo(createEnumContantInfo(
enumLeafInfo, (EC) enumConstant));
}
}
return enumLeafInfo;
}

private void populateEnumLeafInfo(ELI info, MEnumLeafInfo<T, C> enumLeafInfo) {
@SuppressWarnings("rawtypes")
Iterable<? extends EnumConstant> _constants = info.getConstants();
@SuppressWarnings("unchecked")
final Iterable<? extends EnumConstant<T, C>> enumConstants = (Iterable<? extends EnumConstant<T, C>>) _constants;
for (EnumConstant<?, ?> enumConstant : enumConstants) {
enumLeafInfo.addEnumConstantInfo(createEnumContantInfo(
enumLeafInfo, (EC) enumConstant));
}
}

protected MElementInfo<T, C> getElementInfo(EI info) {
MElementInfo<T, C> mElementInfo = elementInfos.get(info);
if (mElementInfo == null) {
mElementInfo = createElementInfo(info);
elementInfos.put(info, mElementInfo);
}
return mElementInfo;
return elementInfos.get(info);

}

Expand All @@ -258,6 +265,18 @@ protected MClassInfo<T, C> createClassInfo(CI info) {
info.isElement() ? info.getElementName() : null);
}

private void populateClassInfo(CI info, MClassInfo<T, C> classInfo) {

if (info.hasAttributeWildcard()) {
classInfo.addProperty(createAnyAttributePropertyInfo(classInfo));
}

for (PropertyInfo<T, C> p : (List<? extends PropertyInfo<T, C>>) info
.getProperties()) {
classInfo.addProperty(createPropertyInfo(classInfo, (PI) p));
}
}

protected MClassTypeInfo<T, C> createBaseTypeInfo(CI info) {
return info.getBaseClass() == null ? null : getTypeInfo((CI) info
.getBaseClass());
Expand Down

0 comments on commit e34a779

Please sign in to comment.