}
protected void addModule(ModuleStateHolder moduleStateHolder, ModificationExtractor calculator,
ModuleDefinition moduleDefinition) {
RootModuleDefinition oldRootDefinition = moduleStateHolder.cloneRootModuleDefinition();
RootModuleDefinition newRootDefinition = moduleStateHolder.cloneRootModuleDefinition();
ModuleDefinition parent = moduleDefinition.getParentDefinition();
if (moduleDefinition instanceof RootModuleDefinition) {
newRootDefinition = (RootModuleDefinition) moduleDefinition;
}
else {
ModuleDefinition newParent = null;
if (parent == null) {
newParent = newRootDefinition;
}
else {
String parentName = parent.getName();
newParent = newRootDefinition.findChildDefinition(parentName, true);
if (newParent == null) {
throw new InvalidStateException("Unable to find parent module '" + parentName + "' in " + newRootDefinition);
}
}