Class ResolutionContext<M extends IModel>
java.lang.Object
net.ssehub.easy.basics.modelManagement.ResolutionContext<M>
- Type Parameters:
M- the specific model type
Defines an internal class representing the context of a model import resolution.
- Author:
- Holger Eichelberger
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate List<ModelImport<M>> private IRestrictionEvaluationContextprivate Mprivate Stringprivate URIprivate IModelRepository<M> private booleanprivate ModelImport<M> -
Constructor Summary
ConstructorsConstructorDescriptionResolutionContext(String modelName, URI baseUri, IModelRepository<M> repository, IRestrictionEvaluationContext evaluationContext) Creates a resolution context for resolving a model by name.ResolutionContext(M model, URI modelUri, List<ModelInfo<M>> inProgress, IModelRepository<M> repository, IRestrictionEvaluationContext evaluationContext) Creates a resolution context.ResolutionContext(M model, URI modelUri, ResolutionContext<M> context) Creates a resolution context. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddConflict(ModelImport<M> conflict) Adds a single conflict to the conflict set of this resolution context.static <M extends IModel>
List<ModelImport<M>> addConflicts(List<ModelImport<M>> conflicts, List<ModelImport<M>> toAdd) Adds the giventoAddconflicts toconflicts.voidaddConflicts(ResolutionContext<M> context) Adds all conflicts of the givencontext.private voidCollects/caches the model location prefixes for filtering.private voidcollectLocationPrefixes(List<String> result, ModelLocations.Location location) Collect location prefixes.booleanconsiderLoading(boolean isTransitiveEnabled) Returns whether model loading shall be considered.private voidenumerateDependent(ModelLocations.Location location, List<String> results, Set<ModelLocations.Location> done) Enumerate the dependent locations in terms of model paths.voidfilterByLocation(ModelLocations.Location location) Filters the contained models by bylocation, i.e., removes modes that are not located withinlocation.filterByLocations(List<VersionedModelInfos<M>> list) Filterslistby the relevant locations for this resolution context.private ModelImport<M> getConflict(String modelName, Version version) Returns the first conflict the described model has with the conflict import statements collected in this context.getConflict(M model) Returns the first conflictmodeland its (recursive) imports have with the conflict import statements collected in this context.private ModelImport<M> getConflict(M model, Set<M> done) Returns the first conflictmodeland its (recursive) imports have with the conflict import statements collected in this context.Returns the evaluation context for version restrictions.getModel()Returns the model defining the context.Returns the name of the model to resolve.Returns the model paths.Returns the model repository.Returns the URI tomodel.Returns the actual import for resolution.booleanisConflict(ModelInfo<M> info) Returns whetherinfohas a conflict with the conflict import statements collected in this context.booleanisInProjectFolder(ModelInfo<M> info) Returns whetherinfois in a project folder relevant for this resolution context.booleanReturns whether loadinginfowould cause in infinite loop in type resolution as it is currently being processed in the same resolution context.booleanReturns whether this is a top-level or a recursively used context.private voidInitializes the conflicts set if required.voidsetToResolve(ModelImport<M> toResolve) Changes the actual import for resolution.
-
Field Details
-
modelName
-
repository
-
model
-
toResolve
-
modelUri
-
inProgress
-
evaluationContext
-
conflicts
-
topLevel
private boolean topLevel -
modelLocationPrefixes
-
-
Constructor Details
-
ResolutionContext
Creates a resolution context.- Parameters:
model- the model for which the import resolution happensmodelUri- the URI tomodel(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 happensmodelUri- the URI tomodel(may be null)inProgress- the models being processed at once withmodel(may be null)repository- the model repositoryevaluationContext- 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 resolvebaseUri- the URI where to start the resolution from (may be a model URI)repository- the model repositoryevaluationContext- 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
Changes the actual import for resolution.- Parameters:
toResolve- the actual import
-
getToResolve
Returns the actual import for resolution.- Returns:
- the actual import
-
getModelURI
Returns the URI tomodel.- Returns:
- the URI (may be null)
-
getModel
Returns the model defining the context.- Returns:
- the model
-
getModelName
Returns the name of the model to resolve.- Returns:
- the name of the model
-
getModelRepository
Returns the model repository.- Returns:
- the model repository
-
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 enumerateresults- the resulting model paths (modified as a side effect)done- the already processed locations in order to avoid cycles
-
isLoop
Returns whether loadinginfowould 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:
trueif it would cause a loop,falseelse
-
getEvaluationContext
Returns the evaluation context for version restrictions.- Returns:
- the evaluation context
-
lazyInitConflicts
private void lazyInitConflicts()Initializes the conflicts set if required. -
addConflicts
Adds all conflicts of the givencontext.- 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 giventoAddconflicts toconflicts.conflictsmay be null and is created then lazily.- Type Parameters:
M- the type of models- Parameters:
conflicts- the conflicts set to add thetoAddconflicts totoAdd- the conflicts to be added- Returns:
conflictsif not null, a new list otherwise
-
addConflict
Adds a single conflict to the conflict set of this resolution context.- Parameters:
conflict- the conflict
-
getConflict
Returns the first conflictmodeland 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
Returns the first conflictmodeland its (recursive) imports have with the conflict import statements collected in this context.- Parameters:
model- the model information to search for (may be nulldone- 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 modelversion- 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
Returns whetherinfohas a conflict with the conflict import statements collected in this context.- Parameters:
info- the model information to search for- Returns:
- if
contextimplies conflicts onmodel - Throws:
RestrictionEvaluationException- in case of evaluation problems
-
isTopLevel
public boolean isTopLevel()Returns whether this is a top-level or a recursively used context.- Returns:
truefor top-level,falseelse
-
considerLoading
public boolean considerLoading(boolean isTransitiveEnabled) Returns whether model loading shall be considered.- Parameters:
isTransitiveEnabled- whether transitive loading is enabled- Returns:
truefor loading,falseelse
-
collectLocationPrefixes
Collect location prefixes.- Parameters:
result- the prefixeslocation- the location to turn into prefixes
-
filterByLocations
Filterslistby the relevant locations for this resolution context.- Parameters:
list- the list of versioned model infos- Returns:
- the filtered copy of
listorlistif there is nothing to filter
-
filterByLocation
Filters the contained models by bylocation, i.e., removes modes that are not located withinlocation.- Parameters:
location- the location that shall be used as base/required location
-
isInProjectFolder
Returns whetherinfois in a project folder relevant for this resolution context.- Parameters:
info- the model info to check for- Returns:
trueif in project folder or there is no project folder,falseif there are project folders butinfois in none
-