-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathname_association_ends.py
More file actions
75 lines (58 loc) · 2.83 KB
/
Copy pathname_association_ends.py
File metadata and controls
75 lines (58 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"""
Modelio Jython Script to name all AssociationEnd elements with meaningful names
Process OwnedEnd on each Class node
"""
from org.modelio.metamodel.uml.statik import Class, Association, AssociationEnd
if elt is None or not isinstance(elt, Class):
print("Error: Please select any node to identify the package.")
else:
parent_package = elt.getOwner()
print("Processing AssociationEnd names in package: " + parent_package.getName())
print("=" * 60)
# Find all classes in the package
classes = []
for element in parent_package.getOwnedElement():
if isinstance(element, Class):
classes.append(element)
print("Found " + str(len(classes)) + " classes to process")
# Start transaction
transaction = session.createTransaction("Name Association Ends")
try:
unnamed_count = 0
named_count = 0
print("Processing " + str(len(classes)) + " classes and their AssociationEnd elements...")
print("Naming strategy: outgoing='to_<target>', incoming='from_<source>'")
print()
print("PROCESSING ALL OWNED ENDS:")
for cls in classes:
owned_ends = cls.getOwnedEnd()
for i, end in enumerate(owned_ends):
current_name = end.getName()
# Only process unnamed ends
if not current_name or current_name.strip() == "":
source = end.getSource() if hasattr(end, 'getSource') else None
target = end.getTarget() if hasattr(end, 'getTarget') else None
owner = end.getOwner() if hasattr(end, 'getOwner') else None
if source and target:
source_name = source.getName()
target_name = target.getName()
# Determine if this is an outgoing or incoming end
if owner == source:
# This is an outgoing end from source
new_name = "to_" + target_name
else:
# This is an incoming end to target
new_name = "from_" + source_name
end.setName(new_name)
unnamed_count += 1
transaction.commit()
print("\n" + "=" * 60)
print("SUMMARY")
print(" - Unnamed AssociationEnd elements named: " + str(unnamed_count))
print(" - Total processed: " + str(unnamed_count))
print("\nSuccess! All unnamed AssociationEnd elements have been named.")
except Exception as e:
transaction.rollback()
print("Error: " + str(e))
import traceback
traceback.print_exc()