Anvil
Explanation

What the metamodel does not tell you

A query operation reads the model through the Open API, and the API's declared shape and the tool's behaviour part company in places. A derived union the metamodel declares may hold nothing. A containment that looks like it reaches further stops early. Two operations that appear interchangeable answer different questions.

Each fact below is measured against a live model by the named test, which is why it is stated rather than inferred. Bytecode inference about framework dispatch is a hypothesis; these are measurements. A new operation under query/ that touches one of these shapes follows the reading recorded here.

Two operations on Classifier disagree about inheritance, on purpose

Classifier.attribute is the derived union that Class.ownedAttribute and DataType.ownedAttribute both subset. The tool populates it, it carries a classifier's ports, and it stops at owned members.

ClassifierHelper.collectInheritedPureAttributes(classifier, result, true, true) answers the opposite pair: it reaches a parent's members and excludes ports.

Classifier.usedTypes reads the union, because a used type is reached through an owned attribute. Classifier.flowProperties reads the collector, because an interface block that specialises another carries the parent's flow properties. Neither is the house rule, and a new operation on Classifier states which one it follows. StructureAndTypingSemanticsTest measures all three halves of the union's behaviour.

An inherited member is reached through ClassifierHelper, not a derived union

collectInheritedPureAttributes(classifier, result, true, true) answers owned and inherited attributes with ports excluded and private members included, which is what lets Classifier.flowProperties report a parent interface block's flow properties.

directedFeatures runs four collectors — pure attributes, ports, operations and receptions — because «DirectedFeature» extends Feature and may sit on any of them.

A type answers what it types, through an index the tool maintains

Type._typedElementOfType is the reverse of TypedElement.type. It is populated inside the session that sets a type and reads the same after that session closes, so Type.typedElements costs one read rather than a scan of the model.

It crosses containment: a type reports properties owned by classifiers unrelated to it, and ports alongside them. The index is the tool's rather than the model's, so it reaches the open project and the projects it uses, and no further.

Three unrelated concerns are all called direction

The profile stores two of them as enumeration literals read by name:

CarrierWhere it livesValues
Parametera metamodel attributein out inout return
A flow propertythe «FlowProperty» tag directionin out inout
A directed featurethe «DirectedFeature» tag featureDirectionprovided required providedRequired

No name in query/ folds two literals together, and a caller wanting everything flowing inward composes the union at the call site. A flow property whose direction nobody set holds no value at all, so it reaches flowProperties and no literal variant. FlowSemanticsTest measures that.

A conjugated port reverses what its type stores; a conjugated interface block is what it stores

Port.isConjugated is a flag on the port, and the type it references is unchanged, so a caller asking a conjugated port for its inward flow is asking the type for out.

A conjugated interface block is a second block whose flow properties were reversed at creation and never synchronised, so a query reads it as stored and reverses nothing. «ConjugatedInterfaceBlock» never enters a query: such a block may be authored by hand with no stereotype applied, and an implementation reading the stereotype would answer nothing for it. FlowQueriesIntegrationTest measures all four combinations, the doubly-reversed one included.

A connector's shape is recorded in ConnectorEnd.partWithPort

Exactly one end leaving partWithPort empty is a delegation — a context's own boundary port joined to a port inside one of its parts. Neither end leaving it empty is an assembly. ConnectorSemanticsTest measures that an API-set partWithPort survives session close, read back exactly as written, and pins what Connector.kind answers on the same two connectors: delegation for the delegation-shaped one, assembly for the assembly-shaped one.

Connector.isDelegation reads partWithPort. Connector.kind is a separate question, and no test here exercises their disagreement, so a reviewer replacing one read with the other changes an operation whose disagreement case nothing measures.

A port answers the connector ends that name it, and a delegation's two ports face the same way

ConnectableElement.end is the reverse of ConnectorEnd.role, and it is populated for a connector built through the Open API. A traversal from a port therefore costs one read rather than a scan of a context's ownedConnector, and a port named by several connectors answers all of them. The traversal crosses a containment boundary: from a boundary port it reaches a port joined by a connector owned by a part's own type, not by the starting context.

The facing decides direction. On an assembly the two ports face each other, so an out port sends and an in port receives. On a delegation both ports face outward from the context, so the boundary end's facing is reversed before the same rule applies. Without that reversal both ends face out, neither qualifies as the unique sender, and fromPort and toPort both answer null.

ConnectorQueriesIntegrationTest measures five shapes against the live model: an assembly's ordinary out-to-in reading, its two null-answering shapes (INOUT on both ends, and no flow on either), and both delegation polarities. The connector owned by a part's own type is exercised on the outward delegation. Every other combination in the direction table is pinned at the unit layer alone, by ConnectivityQueriesTest.

A CallBehaviorAction's pins cannot be authored

Action.input and Action.output are UML derived unions. Adding to input or output does nothing; so does writing to the concrete argument or result containment, and so does setting owner explicitly. CATIA Magic synchronizes an action's pins from the invoked behavior's own ownedParameter at session close, so a test or a plugin that authors pins directly gets an action with no pins and no error.

The way to get pins is to give the called behavior typed parameters and let the tool derive them. Because the derivation happens at session close, wiring an ObjectFlow between two derived pins needs a second session, which is what ActivityEdgeQueriesIntegrationTest does.

A submachine state's contents are outside its owner's containment

State.submachine references a StateMachine; it does not own it, and State.region is empty on such a state. A traversal walking region.subvertex therefore reports a submachine state itself and nothing inside it, which is what State.allSubStates and StateMachine.allStates do. StateMachineQueriesIntegrationTest builds a submachine state, reads back both submachine and the empty region, and asserts both closures stop there.

Activity.node carries the same hazard, read the other way: assuming a containment reaches further than it does.

Asked for a state machine diagram under a Class, CATIA Magic does not put it there

CATIA Magic creates a second StateMachine under the class, names it after the class, and owns the diagram under that machine instead. Class.ownedDiagram therefore never receives such a diagram through the tool's own creation path, and stateMachineDiagrams reaches it through ownedBehavior. A name set on the diagram at creation does not survive either: ClassQueriesIntegrationTest gives the diagram an explicit name at creation and asserts it reads back as the new machine's own name.

Class.stateMachineDiagrams still reads ownedDiagram, as a defensive case rather than an additive one.

A diagram query names the constant for the kind it is named after

Class.stateMachineDiagrams names DiagramTypeConstants.UML_STATECHART_DIAGRAM, because it is named for a UML kind and the SysML state machine diagram is a subtype isTypeOf reports.

Class.internalBlockDiagrams names SysMLConstants.SYSML_INTERNAL_BLOCK_DIAGRAM, because UML declares no internal block diagram and its nearest UML kind — the composite structure diagram — is wider. The SysML type is a subtype of it and not the reverse, so reading the UML constant would report a plain UML composite structure diagram that the operation's name does not promise.

The two also differ in what they read: the tool parks a state machine diagram under a machine it creates and owns an internal block diagram under the block itself, so only the first unions ownedBehavior in.

A new OpaqueExpression already carries a language

createOpaqueExpressionInstance() returns an expression whose language holds English. UML pairs language and body by index, so code that adds its own language and body to a fresh expression produces [English, OCL2.0] against a single body. The body then pairs with English, and the tool raises no error.

Code that writes an expression clears both lists before adding to them, which is what ElementFactory.createConstraint does. ElementFactoryTest asserts that a created constraint's specification holds exactly the caller's language and body. createOpaqueBehaviorInstance() carries no such default: its language and body start empty.

  • How query operations work — the two halves of a binding, the guards that hold them together, and why the library is append-only
  • contributing/add-a-query-operation.md in the repository — writing one
  • Anvil: create model elements — the session rules a fixture builds under

On this page