Class CompositionOperator
java.lang.Object
ca.mcscert.jpipe.operators.CompositionOperator
- Direct Known Subclasses:
AssembleOperator, RefineOperator
Base class for all composition operators. Owns the partition + two-phase
(create-then-link) algorithm via the Template Method pattern.
Subclasses provide three hooks:
equivalenceRelation(List, Map)— decides which elements belong to the same groupmergeFunction(List, Map)— creates the merged element for each group and populates theAliasRegistrycreateResultModel(String, SourceLocation, List, Map)— emits the command that declares the result model
Operators are stateless: the same instance can be reused for multiple
apply(String, List, Map) calls with different arguments.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadditionalCommands(String resultName, List<JustificationModel<?>> sources, AliasRegistry aliases, Map<String, String> args) Returns additional commands to append after Phase 2 edge reconstruction.Applies this operator tosourcesand returns the complete list of commands needed to build the result model namedresultName.apply(String resultName, List<JustificationModel<?>> sources, Map<String, String> arguments, SourceLocation location) Applies this operator tosourcesand returns the complete list of commands needed to build the result model namedresultName.apply(String resultName, List<JustificationModel<?>> sources, Map<String, String> arguments, SourceLocation location, Map<String, SourceLocation> knownLocations) Applies this operator tosourcesand returns the complete list of commands needed to build the result model namedresultName.protected abstract CommandcreateResultModel(String name, SourceLocation location, List<JustificationModel<?>> sources, Map<String, String> arguments) Returns the command that creates the result model (typicallyCreateJustificationorCreateTemplate).protected abstract EquivalenceRelationequivalenceRelation(List<JustificationModel<?>> sources, Map<String, String> arguments) Returns the equivalence relation to use for partitioning elements fromsourcesandarguments.protected abstract MergeFunctionmergeFunction(List<JustificationModel<?>> sources, Map<String, String> arguments) Returns the merge function to use for creating result elements fromsourcesandarguments.Declares which argument keys this operator requires.resultKind(List<JustificationModel<?>> sources, Map<String, String> args)
-
Constructor Details
-
CompositionOperator
public CompositionOperator()
-
-
Method Details
-
requiredArguments
Declares which argument keys this operator requires. The framework validates their presence at the start ofapply(String, List, Map)and throwsInvalidOperatorCallExceptionlisting any missing keys. Default: empty set (no required arguments). -
resultKind
Returns theModelKindof the model produced by this operator for the givensourcesandargs. Defaults toModelKind.JUSTIFICATION. Override in subclasses whose result kind depends on the input models (e.g. an operator that produces aTemplatewhen any source is aTemplate). -
equivalenceRelation
protected abstract EquivalenceRelation equivalenceRelation(List<JustificationModel<?>> sources, Map<String, String> arguments) Returns the equivalence relation to use for partitioning elements fromsourcesandarguments. -
mergeFunction
protected abstract MergeFunction mergeFunction(List<JustificationModel<?>> sources, Map<String, String> arguments) Returns the merge function to use for creating result elements fromsourcesandarguments. -
createResultModel
protected abstract Command createResultModel(String name, SourceLocation location, List<JustificationModel<?>> sources, Map<String, String> arguments) Returns the command that creates the result model (typicallyCreateJustificationorCreateTemplate).- Parameters:
location- the source location of the operator call; forwarded to the creation command so the result model appears in the symbol table.sources- the source models being composed; provided so operators can choose the result model type (e.g.TemplatevsJustification) based on the source types.
-
additionalCommands
protected List<Command> additionalCommands(String resultName, List<JustificationModel<?>> sources, AliasRegistry aliases, Map<String, String> args) Returns additional commands to append after Phase 2 edge reconstruction. Override to inject synthesized elements and their edges that have no counterpart in any source model. Default: empty. -
apply
public final List<Command> apply(String resultName, List<JustificationModel<?>> sources, Map<String, String> arguments) Applies this operator tosourcesand returns the complete list of commands needed to build the result model namedresultName. UsesSourceLocation.UNKNOWNfor the result model's location.- Throws:
InvalidOperatorCallException- if any key declared byrequiredArguments()is absent fromarguments
-
apply
public final List<Command> apply(String resultName, List<JustificationModel<?>> sources, Map<String, String> arguments, SourceLocation location) Applies this operator tosourcesand returns the complete list of commands needed to build the result model namedresultName.- Parameters:
location- source location of the operator call; forwarded tocreateResultModel(String, SourceLocation, List, Map)so the result model is registered in the symbol table.- Throws:
InvalidOperatorCallException- if any key declared byrequiredArguments()is absent fromarguments
-
apply
public final List<Command> apply(String resultName, List<JustificationModel<?>> sources, Map<String, String> arguments, SourceLocation location, Map<String, SourceLocation> knownLocations) Applies this operator tosourcesand returns the complete list of commands needed to build the result model namedresultName.- Parameters:
location- source location of the operator call; forwarded tocreateResultModel(String, SourceLocation, List, Map)so the result model is registered in the symbol table.knownLocations- location registry of the compilation unit (keyed as"modelName/elementId"); used to attach each source element's original location to its copy in the result model.- Throws:
InvalidOperatorCallException- if any key declared byrequiredArguments()is absent fromarguments
-