Skip to content

Commit

Permalink
Possible fix for #3268.
Browse files Browse the repository at this point in the history
Please test as the behavior of imports is slightly changed : now in case
of multiple imports of the same model, the deepest ones in the
dependency graph are loaded before the others, correctly respecting the
hierarchy of imports. Same for the order in which the imports are
declared, which now has a semantic value : the models will be loaded in
the order they are declared.
  • Loading branch information
AlexisDrogoul committed Jan 3, 2022
1 parent dd9e554 commit 6848b16
Show file tree
Hide file tree
Showing 9 changed files with 500 additions and 409 deletions.
102 changes: 69 additions & 33 deletions msi.gama.core/src/msi/gaml/factories/ModelAssembler.java
@@ -1,12 +1,12 @@
/*******************************************************************************************************
*
* ModelAssembler.java, in msi.gama.core, is part of the source code of the
* GAMA modeling and simulation platform (v.1.8.2).
* ModelAssembler.java, in msi.gama.core, is part of the source code of the GAMA modeling and simulation platform
* (v.1.8.2).
*
* (c) 2007-2021 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
* (c) 2007-2022 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
*
********************************************************************************************************/
package msi.gaml.factories;

Expand Down Expand Up @@ -53,6 +53,7 @@
import msi.gaml.descriptions.ValidationContext;
import msi.gaml.statements.Facets;
import msi.gaml.types.Types;
import ummisco.gama.dev.utils.DEBUG;

/**
* Class ModelAssembler.
Expand All @@ -64,20 +65,32 @@
@SuppressWarnings ({ "unchecked", "rawtypes" })
public class ModelAssembler {

static {
DEBUG.ON();
}

/**
* Assemble.
*
* @param projectPath the project path
* @param modelPath the model path
* @param allModels the all models
* @param collector the collector
* @param document the document
* @param mm the mm
* @param projectPath
* the project path
* @param modelPath
* the model path
* @param allModels
* the all models
* @param collector
* the collector
* @param document
* the document
* @param mm
* the mm
* @return the model description
*/
public ModelDescription assemble(final String projectPath, final String modelPath,
final Iterable<ISyntacticElement> allModels, final ValidationContext collector, final boolean document,
final Map<String, ModelDescription> mm) {
// DEBUG.OUT("All models passed to ModelAssembler: "
// + Iterables.transform(allModels, @Nullable ISyntacticElement::getName));
final ImmutableList<ISyntacticElement> models = ImmutableList.copyOf(allModels);
final IMap<String, ISyntacticElement> speciesNodes = GamaMapFactory.create();
final IMap<String, IMap<String, ISyntacticElement>>[] experimentNodes = new IMap[1];
Expand Down Expand Up @@ -248,7 +261,8 @@ public ModelDescription assemble(final String projectPath, final String modelPat
/**
* Gets the species in hierarchical order.
*
* @param model the model
* @param model
* the model
* @return the species in hierarchical order
*/
private Iterable<SpeciesDescription> getSpeciesInHierarchicalOrder(final ModelDescription model) {
Expand Down Expand Up @@ -277,7 +291,8 @@ private Iterable<SpeciesDescription> getSpeciesInHierarchicalOrder(final ModelDe
/**
* Creates the scheduler species.
*
* @param model the model
* @param model
* the model
*/
private void createSchedulerSpecies(final ModelDescription model) {
final SpeciesDescription sd =
Expand All @@ -304,10 +319,14 @@ private void createSchedulerSpecies(final ModelDescription model) {
/**
* Adds the experiment.
*
* @param origin the origin
* @param model the model
* @param experiment the experiment
* @param cache the cache
* @param origin
* the origin
* @param model
* the model
* @param experiment
* the experiment
* @param cache
* the cache
*/
void addExperiment(final String origin, final ModelDescription model, final ISyntacticElement experiment,
final Map<String, SpeciesDescription> cache) {
Expand All @@ -323,10 +342,14 @@ void addExperiment(final String origin, final ModelDescription model, final ISyn
/**
* Adds the experiment node.
*
* @param element the element
* @param modelName the model name
* @param experimentNodes the experiment nodes
* @param collector the collector
* @param element
* the element
* @param modelName
* the model name
* @param experimentNodes
* the experiment nodes
* @param collector
* the collector
*/
void addExperimentNode(final ISyntacticElement element, final String modelName,
final Map<String, IMap<String, ISyntacticElement>> experimentNodes, final ValidationContext collector) {
Expand Down Expand Up @@ -357,9 +380,12 @@ void addExperimentNode(final ISyntacticElement element, final String modelName,
/**
* Adds the micro species.
*
* @param macro the macro
* @param micro the micro
* @param cache the cache
* @param macro
* the macro
* @param micro
* the micro
* @param cache
* the cache
*/
void addMicroSpecies(final SpeciesDescription macro, final ISyntacticElement micro,
final Map<String, SpeciesDescription> cache) {
Expand All @@ -380,9 +406,12 @@ void addMicroSpecies(final SpeciesDescription macro, final ISyntacticElement mic
/**
* Adds the species node.
*
* @param element the element
* @param speciesNodes the species nodes
* @param collector the collector
* @param element
* the element
* @param speciesNodes
* the species nodes
* @param collector
* the collector
*/
void addSpeciesNode(final ISyntacticElement element, final Map<String, ISyntacticElement> speciesNodes,
final ValidationContext collector) {
Expand Down Expand Up @@ -423,8 +452,10 @@ void complementSpecies(final SpeciesDescription species, final ISyntacticElement
/**
* Parent experiment.
*
* @param model the model
* @param micro the micro
* @param model
* the model
* @param micro
* the micro
*/
void parentExperiment(final ModelDescription model, final ISyntacticElement micro) {
// Gather the previously created species
Expand All @@ -441,10 +472,14 @@ void parentExperiment(final ModelDescription model, final ISyntacticElement micr
/**
* Parent species.
*
* @param macro the macro
* @param micro the micro
* @param model the model
* @param cache the cache
* @param macro
* the macro
* @param micro
* the micro
* @param model
* the model
* @param cache
* the cache
*/
void parentSpecies(final SpeciesDescription macro, final ISyntacticElement micro, final ModelDescription model,
final Map<String, SpeciesDescription> cache) {
Expand Down Expand Up @@ -483,7 +518,8 @@ SpeciesDescription lookupSpecies(final String name, final Map<String, SpeciesDes
/**
* Builds the model name.
*
* @param source the source
* @param source
* the source
* @return the string
*/
protected String buildModelName(final String source) {
Expand Down

0 comments on commit 6848b16

Please sign in to comment.