Uses 1059K of libraries. Click here for Pure Java version (20836L/113K).
1 | !7 |
2 | |
3 | extend BEAObject { |
4 | bool canReactWith(BEAObject o) { |
5 | ret isInstanceOfAny(o, (Cl) reactableWithClasses()); |
6 | } |
7 | |
8 | Cl<Class<? extends BEAObject>> reactableWithClasses() { |
9 | ret singleArgumentMethodTypesSubclassing(this, "reactWith", BEAObject); |
10 | } |
11 | } |
12 | |
13 | beaConcept BInput { |
14 | S text; |
15 | |
16 | toString { ret "[\*id*/] Input " + quote(text); } |
17 | } |
18 | |
19 | beaConcept BOutput { |
20 | S text; |
21 | |
22 | toString { ret "[\*id*/] Output " + quote(text); } |
23 | } |
24 | |
25 | beaConcept BPattern { |
26 | S text; |
27 | |
28 | toString { ret "[\*id*/] " + shortDynName(this) + " " + quote(text); } |
29 | |
30 | void reactWith(BInput input) {} |
31 | |
32 | @Override Map<S, FieldMigration> _fieldMigrations() { |
33 | ret litmap(pattern := new FieldMigration("text")); |
34 | } |
35 | } |
36 | |
37 | beaConcept BStarPattern > BPattern { |
38 | void reactWith(BInput input) { |
39 | LS mapping = matchesToStringList(flexMatchIC_first(text, input.text)); |
40 | if (mapping == null) ret; |
41 | uniqPeer BEAObject(this, |
42 | type := "match", |
43 | +input, |
44 | pattern := this, |
45 | +mapping); |
46 | } |
47 | } |
48 | |
49 | beaConcept BAngleVarPattern > BPattern { |
50 | void reactWith(BInput input) { |
51 | SS mapping = flexMatchAngleBracketVarsIC_first(text, input.text); |
52 | if (mapping == null) ret; |
53 | uniqPeer BEAObject(this, |
54 | type := "match", |
55 | +input, |
56 | pattern := this, |
57 | +mapping); |
58 | } |
59 | } |
60 | |
61 | beaConcept BMatch { |
62 | new Ref<BPattern> pattern; |
63 | SS mapping; |
64 | } |
65 | |
66 | beaConcept BMatchToScenario { |
67 | void reactWith(BMatch match) { |
68 | uniqPeer(BEAObject, this, |
69 | /*fromReaction_1 := this, |
70 | fromReaction_2 := match,*/ |
71 | fromReaction := ll(this, match), |
72 | type := "scenario", |
73 | text := mapToLines(match.mapping, |
74 | (a, b) -> b + " is a " + a)); |
75 | } |
76 | } |
77 | |
78 | beaConcept BScenarioToOutput { |
79 | bool canReactWith(BEAObject o) { |
80 | ret o.typeIs("scenario"); |
81 | } |
82 | |
83 | void reactWith(BEAObject scenario) { |
84 | uniqPeer(BOutput, this, |
85 | fromReaction := ll(this, scenario), |
86 | type := "Output", |
87 | text := getString text(scenario)); |
88 | } |
89 | } |
90 | |
91 | cmodule2 > DynCRUD_v2<BEAObject> { |
92 | transient Map<S, Class<? extends BEAObject>> beaClasses = calcBEAClasses(); |
93 | |
94 | start { |
95 | print(+beaClasses); |
96 | crud.humanizeFieldNames = false; |
97 | crud.showBackRefs = true; |
98 | crud.specialFieldsForItem = a -> { |
99 | MapSO map = litorderedmap(crud.hID, str(a.id)); |
100 | S j = crud.javaClassDescForItem(a); |
101 | mapPut(map, "Class/Type", joinUniqueNemptiesCI("/", j, a.type())); |
102 | ret map; |
103 | }; |
104 | |
105 | thread { |
106 | uniq BMatchToScenario(); |
107 | uniq BScenarioToOutput(); |
108 | uniq BInput(text := "UBports community delivers 'second-largest release of Ubuntu Touch ever'"); |
109 | //uniq BPattern(text := "* delivers *"); |
110 | uniq BAngleVarPattern(text := "<company> delivers <product>"); |
111 | } |
112 | } |
113 | |
114 | afterVisualize { |
115 | tablePopupMenuFirst(table(), (menu, row) -> { |
116 | BEAObject o = getItem(row); |
117 | print("Item: " + o); |
118 | if (o == null) ret; |
119 | |
120 | Class<? extends BEAObject> targetClass = defaultCustomClass(o); |
121 | print(+targetClass); |
122 | if (targetClass != null && targetClass != _getClass(o)) pcall-short { |
123 | migrateConceptToClass(targetClass, o); |
124 | addMenuItem(menu, "Convert to " + shortName(targetClass), r { |
125 | replaceConceptAndUpdateRefs(o, migrateConceptToClass(targetClass, o)); |
126 | }); |
127 | } |
128 | |
129 | pcall { |
130 | L<BEAObject> partners = filter(list(BEAObject), |
131 | partner -> o.canReactWith(partner)); |
132 | if (nempty(partners)) |
133 | addScrollingSubMenu(menu, "React with", menu2 -> { |
134 | for (BEAObject p : partners) |
135 | addMenuItem(menu2, str(p), rThread { |
136 | call(o, 'reactWith, p); |
137 | }); |
138 | }); |
139 | } |
140 | }); |
141 | } |
142 | |
143 | // e.g. "Input" => BInput |
144 | Map<S, Class<? extends BEAObject>> calcBEAClasses() { |
145 | ret ciMapToKeys(c -> dropPrefix("B", shortClassName(c)), |
146 | listMinusItem(BEAObject, myNonAbstractClassesImplementing(BEAObject))); |
147 | } |
148 | |
149 | Class<? extends BEAObject> defaultCustomClass(BEAObject o) { |
150 | ret beaClasses.get(o.type()); |
151 | } |
152 | |
153 | <A extends BEAObject> A migrateConceptToClass(Class<A> c, BEAObject in) { |
154 | A out = unlisted(c); |
155 | for (S field : conceptFields(in)) try { |
156 | continue if eq(field, "type"); |
157 | cset(out, field, cget(in, field)); |
158 | // TODO: check Ref types |
159 | } catch e { |
160 | fail("Can't convert field " + field, e); |
161 | } |
162 | ret out; |
163 | } |
164 | } |
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
Snippet ID: | #1030723 |
Snippet name: | AGI Pattern Spike 1 v1 [OK] |
Eternal ID of this version: | #1030723/67 |
Text MD5: | e9e2a01317213c29a2f20427b8be8a6d |
Transpilation MD5: | 7e086129337e4e8821d5fe628d26d218 |
Author: | stefan |
Category: | javax |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-03-19 14:38:17 |
Source code size: | 4492 bytes / 164 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 321 / 897 |
Version history: | 66 change(s) |
Referenced in: | [show references] |