Debian Codegraph @

models/UML.override

raw
1 comment
2 This is a file with custom definitions for Gaphor's data model.
3
4 Parts are separated by '%%' (no training spaces) on a line.
5 Comment parts start with 'comment' on the line below the percentage
6 symbols, 'override' is used to define a overridden variable.
7
8 Overrides may in their turn derive from other properties, in that case
9 the 'derives' keyword may be used. It's only useful to declare the
10 associations (and other derived properties) an overridden value depends
11 on, since attributes have been written anyway. Note that no smart things
12 wrt inheritance is done.
13 %%
14 header
15 from typing import Callable
16
17 from gaphor.core.modeling import UnlimitedNatural
18 %%
19 override NamedElement.qualifiedName: property
20 # defined in umloverrides.py
21 %%
22 override Association.endType(Association.memberEnd, Property.type): derived[Type]
23
24 # References the classifiers that are used as types of the ends of the
25 # association.
26
27 Association.endType = derived('endType', Type, 0, '*', lambda self: [end.type for end in self.memberEnd if end])
28
29 %%
30 override Class.extension(Extension.metaclass): property
31 # See https://www.omg.org/spec/UML/2.5/PDF, section 11.8.3.6, page 219
32 # It defines `Extension.allInstances()`, which basically means we have to query the element factory.
33
34 # TODO: use those as soon as Extension.metaclass can be used.
35 #Class.extension = derived('extension', Extension, 0, '*', class_extension, Extension.metaclass)
36
37 Class.extension = property(lambda self: self.model.lselect(lambda e: e.isKindOf(Extension) and self is e.metaclass), doc=\
38 """References the Extensions that specify additional properties of the
39 metaclass. The property is derived from the extensions whose memberEnds
40 are typed by the Class.""")
41 %%
42 override Extension.metaclass(Extension.ownedEnd, Association.memberEnd): property
43 # defined in umloverrides.py
44 %%
45 override Classifier.inheritedMember: derivedunion[NamedElement]
46 Classifier.inheritedMember = derivedunion('inheritedMember', NamedElement, 0, '*')
47 %%
48 override Classifier.general(Generalization.general): derived[Classifier]
49 Classifier.general = derived('general', Classifier, 0, '*', lambda self: [g.general for g in self.generalization])
50 %%
51 override Class.superClass: derived[Classifier]
52 Class.superClass = Classifier.general
53 %%
54 override Namespace.importedMember: derivedunion[PackageableElement]
55 Namespace.importedMember = derivedunion('importedMember', PackageableElement, 0, '*')
56 %%
57 override Property.isComposite(Property.aggregation): derived[bool]
58 Property.isComposite = derived('isComposite', bool, 0, 1, lambda obj: [obj.aggregation == 'composite'])
59 %%
60 override Property.navigability(Property.opposite, Property.association): derived[bool | None]
61 # defined in umloverrides.py
62 %%
63 override Operation.type: derivedunion[DataType]
64 Operation.type = derivedunion('type', DataType, 0, 1)
65 %%
66 override Lifeline.parse: Callable[[Lifeline, str], None]
67 # defined in umloverrides.py
68 %%
69 override Lifeline.render: Callable[[Lifeline], str]
70 # defined in umloverrides.py
71 %%
72 override Component.provided: property
73 # defined in umloverrides.py
74 %%
75 override Component.required: property
76 # defined in umloverrides.py
77 %%
78 override Message.messageKind: property
79 # defined in umloverrides.py
80 %%
81 override StructuredClassifier.part: property
82 StructuredClassifier.part = property(lambda self: tuple(a for a in self.ownedAttribute if a.isComposite), doc="""
83 Properties owned by a classifier by composition.
84 """)
85 %%
86 override ExecutionSpecification.start(ExecutionSpecification.executionOccurrenceSpecification): relation_one[ExecutionOccurrenceSpecification]
87 ExecutionSpecification.start = derived('start', OccurrenceSpecification, 0, 1,
88 lambda obj: [eos for i, eos in enumerate(obj.executionOccurrenceSpecification) if i == 0])
89 %%
90 override ExecutionSpecification.finish(ExecutionSpecification.executionOccurrenceSpecification): relation_one[ExecutionOccurrenceSpecification]
91 ExecutionSpecification.finish = derived('finish', OccurrenceSpecification, 0, 1,
92 lambda obj: [eos for i, eos in enumerate(obj.executionOccurrenceSpecification) if i == 1])