Class ResolutionContext<M extends IModel>

java.lang.Object
net.ssehub.easy.basics.modelManagement.ResolutionContext<M>
Type Parameters:
M - the specific model type

class ResolutionContext<M extends IModel> extends Object
Defines an internal class representing the context of a model import resolution.
Author:
Holger Eichelberger
  • Field Details

  • Constructor Details

    • ResolutionContext

      public ResolutionContext(M model, URI modelUri, ResolutionContext<M> context)
      Creates a resolution context.
      Parameters:
      model - the model for which the import resolution happens
      modelUri - the URI to model (may be null)
      context - the parent contexts
    • ResolutionContext

      public ResolutionContext(M model, URI modelUri, List<ModelInfo<M>> inProgress, IModelRepository<M> repository, IRestrictionEvaluationContext evaluationContext)
      Creates a resolution context.
      Parameters:
      model - the model for which the import resolution happens
      modelUri - the URI to model (may be null)
      inProgress - the models being processed at once with model (may be null)
      repository - the model repository
      evaluationContext - the context for evaluating import restrictions (variable definitions... interpreted locally)
      See Also:
    • ResolutionContext

      public ResolutionContext(String modelName, URI baseUri, IModelRepository<M> repository, IRestrictionEvaluationContext evaluationContext)
      Creates a resolution context for resolving a model by name.
      Parameters:
      modelName - the name of the model to resolve
      baseUri - the URI where to start the resolution from (may be a model URI)
      repository - the model repository
      evaluationContext - the context for evaluating import restrictions (variable definitions... interpreted locally)
      See Also:
  • Method Details

    • collectLocationPrefixes

      private void collectLocationPrefixes()
      Collects/caches the model location prefixes for filtering.
    • setToResolve

      public void setToResolve(ModelImport<M> toResolve)
      Changes the actual import for resolution.
      Parameters:
      toResolve - the actual import
    • getToResolve

      public ModelImport<M> getToResolve()
      Returns the actual import for resolution.
      Returns:
      the actual import
    • getModelURI

      public URI getModelURI()
      Returns the URI to model.
      Returns:
      the URI (may be null)
    • getModel

      public M getModel()
      Returns the model defining the context.
      Returns:
      the model
    • getModelName

      public String getModelName()
      Returns the name of the model to resolve.
      Returns:
      the name of the model
    • getModelRepository

      public IModelRepository<M> getModelRepository()
      Returns the model repository.
      Returns:
      the model repository
    • getModelPaths

      public List<String> getModelPaths()
      Returns the model paths.
      Returns:
      the model paths
    • enumerateDependent

      private void enumerateDependent(ModelLocations.Location location, List<String> results, Set<ModelLocations.Location> done)
      Enumerate the dependent locations in terms of model paths.
      Parameters:
      location - the location to enumerate
      results - the resulting model paths (modified as a side effect)
      done - the already processed locations in order to avoid cycles
    • isLoop

      public boolean isLoop(ModelInfo<M> info)
      Returns whether loading info would cause in infinite loop in type resolution as it is currently being processed in the same resolution context.
      Parameters:
      info - the information object to be checked
      Returns:
      true if it would cause a loop, false else
    • getEvaluationContext

      public IRestrictionEvaluationContext getEvaluationContext()
      Returns the evaluation context for version restrictions.
      Returns:
      the evaluation context
    • lazyInitConflicts

      private void lazyInitConflicts()
      Initializes the conflicts set if required.
    • addConflicts

      public void addConflicts(ResolutionContext<M> context)
      Adds all conflicts of the given context.
      Parameters:
      context - the context to consider
    • addConflicts

      public static <M extends IModel> List<ModelImport<M>> addConflicts(List<ModelImport<M>> conflicts, List<ModelImport<M>> toAdd)
      Adds the given toAdd conflicts to conflicts. conflicts may be null and is created then lazily.
      Type Parameters:
      M - the type of models
      Parameters:
      conflicts - the conflicts set to add the toAdd conflicts to
      toAdd - the conflicts to be added
      Returns:
      conflicts if not null, a new list otherwise
    • addConflict

      public void addConflict(ModelImport<M> conflict)
      Adds a single conflict to the conflict set of this resolution context.
      Parameters:
      conflict - the conflict
    • getConflict

      public ModelImport<M> getConflict(M model) throws RestrictionEvaluationException
      Returns the first conflict model and its (recursive) imports have with the conflict import statements collected in this context.
      Parameters:
      model - the model information to search for
      Returns:
      the first conflict or null if there is none
      Throws:
      RestrictionEvaluationException - in case of evaluation problems
    • getConflict

      private ModelImport<M> getConflict(M model, Set<M> done) throws RestrictionEvaluationException
      Returns the first conflict model and its (recursive) imports have with the conflict import statements collected in this context.
      Parameters:
      model - the model information to search for (may be null
      done - the models visited so far (cycle check)
      Returns:
      the first conflict or null if there is none
      Throws:
      RestrictionEvaluationException - in case of evaluation problems
    • getConflict

      private ModelImport<M> getConflict(String modelName, Version version) throws RestrictionEvaluationException
      Returns the first conflict the described model has with the conflict import statements collected in this context.
      Parameters:
      modelName - the name of the model
      version - the version of the model (may be null)
      Returns:
      the first conflict or null if there is none
      Throws:
      RestrictionEvaluationException - in case of evaluation problems
    • isConflict

      public boolean isConflict(ModelInfo<M> info) throws RestrictionEvaluationException
      Returns whether info has a conflict with the conflict import statements collected in this context.
      Parameters:
      info - the model information to search for
      Returns:
      if context implies conflicts on model
      Throws:
      RestrictionEvaluationException - in case of evaluation problems
    • isTopLevel

      public boolean isTopLevel()
      Returns whether this is a top-level or a recursively used context.
      Returns:
      true for top-level, false else
    • considerLoading

      public boolean considerLoading(boolean isTransitiveEnabled)
      Returns whether model loading shall be considered.
      Parameters:
      isTransitiveEnabled - whether transitive loading is enabled
      Returns:
      true for loading, false else
    • collectLocationPrefixes

      private void collectLocationPrefixes(List<String> result, ModelLocations.Location location)
      Collect location prefixes.
      Parameters:
      result - the prefixes
      location - the location to turn into prefixes
    • filterByLocations

      public List<VersionedModelInfos<M>> filterByLocations(List<VersionedModelInfos<M>> list)
      Filters list by the relevant locations for this resolution context.
      Parameters:
      list - the list of versioned model infos
      Returns:
      the filtered copy of list or list if there is nothing to filter
    • filterByLocation

      public void filterByLocation(ModelLocations.Location location)
      Filters the contained models by by location, i.e., removes modes that are not located within location.
      Parameters:
      location - the location that shall be used as base/required location
    • isInProjectFolder

      public boolean isInProjectFolder(ModelInfo<M> info)
      Returns whether info is in a project folder relevant for this resolution context.
      Parameters:
      info - the model info to check for
      Returns:
      true if in project folder or there is no project folder, false if there are project folders but info is in none