Skip to content

Commit

Permalink
refactor: Rename basic Accessors to make their roles clearer
Browse files Browse the repository at this point in the history
This commit performs the following renames:

- RoleTagAccessor to Containment
- AttrProxyAccessor to Association
- LinkAccessor to Allocation
- ReferenceSearchingAccessor to Backref

It also deprecates the DirectProxyAccessor in favor of Containment
(previously known as "RoleTagAccessor").

The old names of these Accessors will still be available at runtime
until the end of v0.6.x.
  • Loading branch information
Wuestengecko committed Nov 14, 2024
1 parent 04a553d commit 4dd6b8b
Show file tree
Hide file tree
Showing 24 changed files with 261 additions and 298 deletions.
2 changes: 1 addition & 1 deletion capellambse/extensions/filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class FilteringCriterion(m.ModelElement):

_xmltag = "ownedFilteringCriteria"

filtered_objects = m.ReferenceSearchingAccessor[m.ModelElement](
filtered_objects = m.Backref[m.ModelElement](
(), "filtering_criteria", aslist=m.MixedElementList
)

Expand Down
8 changes: 4 additions & 4 deletions capellambse/extensions/pvmt/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,18 +265,18 @@ class ManagedDomain(m.ModelElement):
version = property(
lambda self: self.property_values.by_name("version").value
)
types = m.RoleTagAccessor(
types = m.Containment(
"ownedEnumerationPropertyTypes",
mm.capellacore.EnumerationPropertyType,
)
groups = m.RoleTagAccessor(
groups = m.Containment(
"ownedPropertyValueGroups",
mm.capellacore.PropertyValueGroup,
aslist=m.ElementList,
mapkey="name",
alternate=ManagedGroup,
)
enumeration_property_types = m.RoleTagAccessor(
enumeration_property_types = m.Containment(
"ownedEnumerationPropertyTypes",
mm.capellacore.EnumerationPropertyType,
aslist=m.ElementList,
Expand Down Expand Up @@ -319,7 +319,7 @@ class PVMTConfiguration(m.ModelElement):
def __init__(self, *_args, **_kw) -> None:
raise TypeError("Use 'model.pvmt' to access PVMT configuration")

domains = m.RoleTagAccessor(
domains = m.Containment(
"ownedPropertyValuePkgs",
mm.capellacore.PropertyValuePkg,
aslist=m.ElementList,
Expand Down
6 changes: 3 additions & 3 deletions capellambse/extensions/reqif/_capellareq.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CapellaModule(rq.ReqIFElement):

folders = m.DirectProxyAccessor(rq.Folder, aslist=m.ElementList)
requirements = m.DirectProxyAccessor(rq.Requirement, aslist=m.ElementList)
type = m.AttrProxyAccessor(rq.ModuleType, "moduleType")
type = m.Association(rq.ModuleType, "moduleType")
attributes = rq.AttributeAccessor()

def to_reqif(
Expand Down Expand Up @@ -94,8 +94,8 @@ class CapellaOutgoingRelation(rq.AbstractRequirementsRelation):

_xmltag = "ownedExtensions"

source = m.AttrProxyAccessor(rq.Requirement, "target")
target = m.AttrProxyAccessor(m.ModelElement, "source")
source = m.Association(rq.Requirement, "target")
target = m.Association(m.ModelElement, "source")


@m.xtype_handler(None)
Expand Down
20 changes: 9 additions & 11 deletions capellambse/extensions/reqif/_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ class AttributeDefinition(ReqIFElement):

_xmltag = "ownedAttributes"

data_type = m.AttrProxyAccessor(DataTypeDefinition, "definitionType")
data_type = m.Association(DataTypeDefinition, "definitionType")


class AbstractRequirementsAttribute(m.ModelElement):
_xmltag = "ownedAttributes"

definition = m.AttrProxyAccessor(AttributeDefinition, "definition")
definition = m.Association(AttributeDefinition, "definition")

value: t.Any

Expand Down Expand Up @@ -223,9 +223,7 @@ class AttributeDefinitionEnumeration(ReqIFElement):

_xmltag = "ownedAttributes"

data_type = m.AttrProxyAccessor(
EnumerationDataTypeDefinition, "definitionType"
)
data_type = m.Association(EnumerationDataTypeDefinition, "definitionType")
multi_valued = m.BoolPOD("multiValued")
"""Whether to allow setting multiple values on this attribute."""

Expand All @@ -234,11 +232,11 @@ class AttributeDefinitionEnumeration(ReqIFElement):
class EnumerationValueAttribute(AbstractRequirementsAttribute):
"""An enumeration attribute."""

definition = m.AttrProxyAccessor(
definition = m.Association(
AttributeDefinitionEnumeration, # type: ignore[arg-type]
"definition",
)
values = m.AttrProxyAccessor(EnumValue, "values", aslist=m.ElementList)
values = m.Association(EnumValue, "values", aslist=m.ElementList)

@property
def value(self):
Expand Down Expand Up @@ -296,7 +294,7 @@ class Requirement(ReqIFElement):
foreign_id = m.IntPOD("ReqIFForeignID")
text = m.HTMLStringPOD("ReqIFText")
attributes = AttributeAccessor()
type = m.AttrProxyAccessor(RequirementType, "requirementType")
type = m.Association(RequirementType, "requirementType")

relations: m.Accessor[AbstractRequirementsRelation]
related: m.Accessor[m.ModelElement]
Expand All @@ -315,9 +313,9 @@ class Folder(Requirement):
class AbstractRequirementsRelation(ReqIFElement):
_required_attrs = frozenset({"source", "target"})

type = m.AttrProxyAccessor(RelationType, "relationType")
source = m.AttrProxyAccessor(Requirement, "source")
target = m.AttrProxyAccessor(m.ModelElement, "target")
type = m.Association(RelationType, "relationType")
source = m.Association(Requirement, "source")
target = m.Association(m.ModelElement, "target")

def _short_repr_(self) -> str:
direction = ""
Expand Down
2 changes: 1 addition & 1 deletion capellambse/metamodel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
m.set_accessor(
capellacommon.State,
"functions",
m.ReferenceSearchingAccessor(
m.Backref(
(
oa.OperationalActivity,
sa.SystemFunction,
Expand Down
36 changes: 13 additions & 23 deletions capellambse/metamodel/capellacommon.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,11 @@ class AbstractStateMode(m.ModelElement):
class State(AbstractStateMode):
"""A state."""

entries = m.AttrProxyAccessor(
m.ModelElement, "entry", aslist=m.MixedElementList
)
do_activity = m.AttrProxyAccessor(
entries = m.Association(m.ModelElement, "entry", aslist=m.MixedElementList)
do_activity = m.Association(
m.ModelElement, "doActivity", aslist=m.MixedElementList
)
exits = m.AttrProxyAccessor(
m.ModelElement, "exit", aslist=m.MixedElementList
)
exits = m.Association(m.ModelElement, "exit", aslist=m.MixedElementList)

incoming_transitions = m.Accessor
outgoing_transitions = m.Accessor
Expand Down Expand Up @@ -110,15 +106,15 @@ class StateTransition(m.ModelElement):

_xmltag = "ownedTransitions"

source = m.AttrProxyAccessor(m.ModelElement, "source")
destination = m.AttrProxyAccessor(m.ModelElement, "target")
triggers = m.AttrProxyAccessor(
source = m.Association(m.ModelElement, "source")
destination = m.Association(m.ModelElement, "target")
triggers = m.Association(
m.ModelElement, "triggers", aslist=m.MixedElementList
)
effects = m.AttrProxyAccessor(
effects = m.Association(
m.ModelElement, "effect", aslist=m.MixedElementList
)
guard = m.AttrProxyAccessor(capellacore.Constraint, "guard")
guard = m.Association(capellacore.Constraint, "guard")


@m.xtype_handler(None)
Expand All @@ -138,7 +134,7 @@ def name(self) -> str: # type: ignore[override]
m.set_accessor(
AbstractStateMode,
"realized_states",
m.LinkAccessor(
m.Allocation(
None, # FIXME fill in tag
AbstractStateRealization,
aslist=m.ElementList,
Expand All @@ -159,9 +155,7 @@ def name(self) -> str: # type: ignore[override]
m.set_accessor(
cls,
"realizing_states",
m.ReferenceSearchingAccessor(
cls, "realized_states", aslist=m.ElementList
),
m.Backref(cls, "realized_states", aslist=m.ElementList),
)

for cls in [
Expand All @@ -177,9 +171,7 @@ def name(self) -> str: # type: ignore[override]
m.set_accessor(
cls,
"incoming_transitions",
m.ReferenceSearchingAccessor(
StateTransition, "destination", aslist=m.ElementList
),
m.Backref(StateTransition, "destination", aslist=m.ElementList),
)
for cls in [
State,
Expand All @@ -193,15 +185,13 @@ def name(self) -> str: # type: ignore[override]
m.set_accessor(
cls,
"outgoing_transitions",
m.ReferenceSearchingAccessor(
StateTransition, "source", aslist=m.ElementList
),
m.Backref(StateTransition, "source", aslist=m.ElementList),
)

m.set_accessor(
Region,
"states",
m.RoleTagAccessor(AbstractStateMode._xmltag, aslist=m.ElementList),
m.Containment(AbstractStateMode._xmltag, aslist=m.ElementList),
)
m.set_accessor(
Region, "modes", m.DirectProxyAccessor(Mode, aslist=m.ElementList)
Expand Down
14 changes: 6 additions & 8 deletions capellambse/metamodel/capellacore.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Constraint(m.ModelElement):

_xmltag = "ownedConstraints"

constrained_elements = m.AttrProxyAccessor(
constrained_elements = m.Association(
m.ModelElement,
"constrainedElements",
aslist=m.MixedElementList,
Expand Down Expand Up @@ -56,7 +56,7 @@ class PropertyValue(m.ModelElement):
EnumerationPropertyType, aslist=m.ElementList
)

value: m.BasePOD | m.AttrProxyAccessor
value: m.BasePOD | m.Association


@m.xtype_handler(None)
Expand Down Expand Up @@ -91,8 +91,8 @@ class StringPropertyValue(PropertyValue):
class EnumerationPropertyValue(PropertyValue):
"""An enumeration property value."""

type = m.AttrProxyAccessor(EnumerationPropertyType, "type")
value = m.AttrProxyAccessor(EnumerationPropertyLiteral, "value")
type = m.Association(EnumerationPropertyType, "type")
value = m.Association(EnumerationPropertyLiteral, "value")


@m.xtype_handler(None)
Expand Down Expand Up @@ -186,12 +186,10 @@ class PropertyValuePkg(m.ModelElement):
m.set_accessor(
m.ModelElement,
"applied_property_values",
m.AttrProxyAccessor(None, "appliedPropertyValues", aslist=m.ElementList),
m.Association(None, "appliedPropertyValues", aslist=m.ElementList),
)
m.set_accessor(
m.ModelElement,
"applied_property_value_groups",
m.AttrProxyAccessor(
None, "appliedPropertyValueGroups", aslist=m.ElementList
),
m.Association(None, "appliedPropertyValueGroups", aslist=m.ElementList),
)
4 changes: 2 additions & 2 deletions capellambse/metamodel/capellamodeller.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SystemEngineering(m.ModelElement):
[source:MIL-STD 499B standard]
"""

architectures = m.RoleTagAccessor(
architectures = m.Containment(
"ownedArchitectures", m.ModelElement, aslist=m.ElementList
)

Expand Down Expand Up @@ -87,7 +87,7 @@ def pa(self) -> pa.PhysicalArchitecture:

@m.xtype_handler(None)
class Project(m.ModelElement):
model_roots = m.RoleTagAccessor(
model_roots = m.Containment(
"ownedModelRoots", SystemEngineering, aslist=m.ElementList
)

Expand Down
32 changes: 14 additions & 18 deletions capellambse/metamodel/cs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Part(m.ModelElement):

_xmltag = "ownedParts"

type = m.AttrProxyAccessor(m.ModelElement, "abstractType")
type = m.Association(m.ModelElement, "abstractType")

deployed_parts: m.Accessor

Expand All @@ -31,7 +31,7 @@ class Part(m.ModelElement):
class ExchangeItemAllocation(m.ModelElement):
"""An allocation of an ExchangeItem to an Interface."""

item = m.AttrProxyAccessor(information.ExchangeItem, "allocatedItem")
item = m.Association(information.ExchangeItem, "allocatedItem")


@m.xtype_handler(None)
Expand Down Expand Up @@ -72,7 +72,7 @@ class PhysicalLink(PhysicalPort):
ends = m.PhysicalLinkEndsAccessor(
PhysicalPort, "linkEnds", aslist=m.ElementList
)
exchanges = m.LinkAccessor[fa.ComponentExchange](
exchanges = m.Allocation[fa.ComponentExchange](
"ownedComponentExchangeAllocations",
fa.ComponentExchangeAllocation,
aslist=m.ElementList,
Expand All @@ -92,13 +92,13 @@ class PhysicalPath(m.ModelElement):

_xmltag = "ownedPhysicalPath"

involved_items = m.LinkAccessor[m.ModelElement](
involved_items = m.Allocation[m.ModelElement](
None, # FIXME fill in tag
"org.polarsys.capella.core.data.cs:PhysicalPathInvolvement",
aslist=m.MixedElementList,
attr="involved",
)
exchanges = m.LinkAccessor[fa.ComponentExchange](
exchanges = m.Allocation[fa.ComponentExchange](
None, # FIXME fill in tag
"org.polarsys.capella.core.data.fa:ComponentExchangeAllocation",
aslist=m.ElementList,
Expand Down Expand Up @@ -126,27 +126,27 @@ class Component(m.ModelElement):
)
ports = m.DirectProxyAccessor(fa.ComponentPort, aslist=m.ElementList)
physical_ports = m.DirectProxyAccessor(PhysicalPort, aslist=m.ElementList)
parts = m.ReferenceSearchingAccessor(Part, "type", aslist=m.ElementList)
parts = m.Backref(Part, "type", aslist=m.ElementList)
physical_paths = m.DirectProxyAccessor(PhysicalPath, aslist=m.ElementList)
physical_links = m.DirectProxyAccessor(PhysicalLink, aslist=m.ElementList)
exchanges = m.DirectProxyAccessor(
fa.ComponentExchange, aslist=m.ElementList
)

related_exchanges = m.ReferenceSearchingAccessor(
related_exchanges = m.Backref(
fa.ComponentExchange,
"source.owner",
"target.owner",
aslist=m.ElementList,
)

realized_components = m.LinkAccessor["Component"](
realized_components = m.Allocation["Component"](
"ownedComponentRealizations",
"org.polarsys.capella.core.data.cs:ComponentRealization",
aslist=m.ElementList,
attr="targetElement",
)
realizing_components = m.ReferenceSearchingAccessor["Component"](
realizing_components = m.Backref["Component"](
(), "realized_components", aslist=m.ElementList
)

Expand Down Expand Up @@ -189,7 +189,7 @@ class ComponentArchitecture(m.ModelElement):
m.set_accessor(
Part,
"deployed_parts",
m.LinkAccessor(
m.Allocation(
"ownedDeploymentLinks",
"org.polarsys.capella.core.data.pa.deployment:PartDeploymentLink",
aslist=m.ElementList,
Expand All @@ -200,24 +200,20 @@ class ComponentArchitecture(m.ModelElement):
m.set_accessor(
PhysicalPort,
"links",
m.ReferenceSearchingAccessor(PhysicalLink, "ends", aslist=m.ElementList),
m.Backref(PhysicalLink, "ends", aslist=m.ElementList),
)
m.set_accessor(
PhysicalLink,
"physical_paths",
m.ReferenceSearchingAccessor(
PhysicalPath, "involved_items", aslist=m.ElementList
),
m.Backref(PhysicalPath, "involved_items", aslist=m.ElementList),
)
m.set_accessor(
fa.ComponentExchange,
"allocating_physical_link",
m.ReferenceSearchingAccessor(PhysicalLink, "exchanges"),
m.Backref(PhysicalLink, "exchanges"),
)
m.set_accessor(
fa.ComponentExchange,
"allocating_physical_paths",
m.ReferenceSearchingAccessor(
PhysicalPath, "exchanges", aslist=m.ElementList
),
m.Backref(PhysicalPath, "exchanges", aslist=m.ElementList),
)
Loading

0 comments on commit 4dd6b8b

Please sign in to comment.