Skip to content

Commit feaf057

Browse files
committed
[Refactor]: Str Reader - Extract Object Read from Kind
Logic was duplicated when visiting both elements and time. Includes some unrelated GT view enhancements
1 parent 508ce34 commit feaf057

File tree

3 files changed

+36
-20
lines changed

3 files changed

+36
-20
lines changed

source/Magritte-Merging/MAPatchMacro.class.st

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,20 @@ MAPatchMacro >> diffStrings [
5454
^ { lhs. rhs }
5555
]
5656

57-
{ #category : #execution }
58-
MAPatchMacro >> execute [
59-
self operations do: #execute
60-
]
61-
6257
{ #category : #accessing }
63-
MAPatchMacro >> gtElementViewFor: aView [
58+
MAPatchMacro >> elementGtViewFor: aView [
6459
<gtView>
6560
^ aView explicit
6661
title: 'Element';
6762
priority: 25;
6863
stencil: [ self asElement asScrollableElement ]
6964
]
7065

66+
{ #category : #execution }
67+
MAPatchMacro >> execute [
68+
self operations do: #execute
69+
]
70+
7171
{ #category : #accessing }
7272
MAPatchMacro >> isEmptyOrNil [
7373
^ self operations isEmpty
@@ -94,6 +94,16 @@ MAPatchMacro >> operationsDescription [
9494
yourself
9595
]
9696

97+
{ #category : #accessing }
98+
MAPatchMacro >> operationsGtViewFor: aView [
99+
<gtView>
100+
101+
^ aView list
102+
title: 'Operations';
103+
priority: 35;
104+
items: [ self operations ]
105+
]
106+
97107
{ #category : #printing }
98108
MAPatchMacro >> printOn: aStream [
99109

source/Magritte-Merging/MAPatchOperation.class.st

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ MAPatchOperation >> diffStrings [
5656
^ { self field label, ': ', self oldValue asString. self field label, ': ', self newValue asString }
5757
]
5858

59+
{ #category : #accessing }
60+
MAPatchOperation >> elementGtViewFor: aView [
61+
<gtView>
62+
^ aView explicit
63+
title: 'Element';
64+
priority: 25;
65+
stencil: [ self asElement asScrollableElement ]
66+
]
67+
5968
{ #category : #execution }
6069
MAPatchOperation >> execute [
6170
self isEnabled ifFalse: [ ^ self ].
@@ -73,15 +82,6 @@ MAPatchOperation >> field: anObject [
7382
self cacheOldValue
7483
]
7584

76-
{ #category : #accessing }
77-
MAPatchOperation >> gtElementViewFor: aView [
78-
<gtView>
79-
^ aView explicit
80-
title: 'Element';
81-
priority: 25;
82-
stencil: [ self asElement asScrollableElement ]
83-
]
84-
8585
{ #category : #comparing }
8686
MAPatchOperation >> hash [
8787
^ ((self receiver hash bitXor: self field hash) bitXor: self oldValue hash) bitXor: self newValue hash

source/Magritte-Model/MAStringReader.class.st

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ MAStringReader >> nextMatchAll: aCollection on: aStream [
3434
^ true
3535
]
3636

37+
{ #category : #'visiting-description' }
38+
MAStringReader >> objectReadFromKindOf: aDescription [
39+
"This implementation can be very dangerous and might lead to a potential security hole (this is tested), since the default implementation of #readFrom: in Object evaluates the expression to find its value. Most subclasses like Number, Date, Time, ... override this implementation, but some others (like Boolean) do not."
40+
41+
self object: ([ aDescription kind readFrom: self stream ]
42+
on: Error do: [ :err | MAReadError signal: err messageText ])
43+
]
44+
3745
{ #category : #visiting }
3846
MAStringReader >> read: aStream description: aDescription [
3947
(aStream atEnd or: [ self nextMatchAll: aDescription undefined on: aStream ])
@@ -91,10 +99,8 @@ MAStringReader >> visitDurationDescription: aDescription [
9199

92100
{ #category : #'visiting-description' }
93101
MAStringReader >> visitElementDescription: aDescription [
94-
"This implementation can be very dangerous and might lead to a potential security hole (this is tested), since the default implementation of #readFrom: in Object evaluates the expression to find its value. Most subclasses like Number, Date, Time, ... override this implementation, but some others (like Boolean) do not."
95-
96-
self object: ([ aDescription kind readFrom: self stream ]
97-
on: Error do: [ :err | MAReadError signal: err messageText ])
102+
103+
self objectReadFromKindOf: aDescription
98104
]
99105

100106
{ #category : #'visiting-description' }
@@ -158,7 +164,7 @@ MAStringReader >> visitTimeDescription: aDescription [
158164
string := self contents.
159165
(string notEmpty and: [ string allSatisfy: [ :each | '0123456789: apm' includes: each ] ])
160166
ifFalse: [ MAReadError signal ].
161-
self object: (aDescription kind readFrom: string readStream)
167+
self objectReadFromKindOf: aDescription
162168
]
163169

164170
{ #category : #'visiting-description' }

0 commit comments

Comments
 (0)