1
1
Class {
2
2
#name : ' MicParentChildrenChecker' ,
3
- #superclass : ' MicrodownVisitor ' ,
3
+ #superclass : ' Object ' ,
4
4
#instVars : [
5
5
' orphanList' ,
6
- ' badReferencingParentList' ,
7
6
' confusedKids'
8
7
],
9
8
#category : ' Microdown-ParentChildrenChecker' ,
10
9
#package : ' Microdown-ParentChildrenChecker'
11
10
}
12
11
13
12
{ #category : ' visiting main API' }
14
- MicParentChildrenChecker >> addChild: aChild [
15
- orphanList add: aChild .
16
- ]
17
-
18
- { #category : ' visiting main API' }
19
- MicParentChildrenChecker >> addParent: aParent [
20
- badReferencingParentList add: aParent .
21
- ]
22
-
23
- { #category : ' testing' }
24
- MicParentChildrenChecker >> badReferencingParentList [
25
-
26
- ^ badReferencingParentList
27
- ]
13
+ MicParentChildrenChecker >> check: anElement [
14
+ " Check if the parent of the element correctly includes this element as a child"
28
15
29
- { #category : ' visiting main API' }
30
- MicParentChildrenChecker >> childrenList [
31
- ^ orphanList
32
- ]
16
+ anElement parent
17
+ ifNil: [
18
+ anElement class = MicRootBlock
19
+ ifFalse: [ orphanList add: anElement ]
20
+ ifTrue: [ anElement children do: [ :each | self check: each ] ] ]
21
+ ifNotNil: [ :p | " We cannot identify bad parent that are refered by child not in the children
22
+ list, because by construction the algo only considers the children of an element).
23
+ (p children includes: anElement) ifFalse: [ self addParent: p ]."
24
+ p children do: [ :child |
25
+ child parent = p ifFalse: [ confusedKids add: child ] ].
33
26
34
- { #category : ' visiting main API' }
35
- MicParentChildrenChecker >> childrenList: anObject [
36
- orphanList := anObject
27
+ anElement children do: [ :each | self check: each ] ]
37
28
]
38
29
39
- { #category : ' testing ' }
30
+ { #category : ' accessing ' }
40
31
MicParentChildrenChecker >> confusedKids [
41
32
42
33
^ confusedKids
@@ -47,48 +38,17 @@ MicParentChildrenChecker >> initialize [
47
38
48
39
super initialize.
49
40
orphanList := OrderedCollection new .
50
- badReferencingParentList := OrderedCollection new .
51
41
confusedKids := OrderedCollection new
52
42
]
53
43
54
44
{ #category : ' testing' }
55
45
MicParentChildrenChecker >> isOk [
56
46
57
- ^ badReferencingParentList isEmpty and :
58
- ( orphanList isEmpty and : [ confusedKids isEmpty ])
47
+ ^ confusedKids isEmpty and :
48
+ (orphanList isEmpty and : [ confusedKids isEmpty ])
59
49
]
60
50
61
- { #category : ' testing ' }
51
+ { #category : ' accessing ' }
62
52
MicParentChildrenChecker >> orphanList [
63
53
^ orphanList
64
54
]
65
-
66
- { #category : ' visiting main API' }
67
- MicParentChildrenChecker >> parentsList [
68
- ^ badReferencingParentList
69
- ]
70
-
71
- { #category : ' visiting main API' }
72
- MicParentChildrenChecker >> parentsList: anObject [
73
- badReferencingParentList := anObject
74
- ]
75
-
76
- { #category : ' visiting main API' }
77
- MicParentChildrenChecker >> visit: anElement [
78
- " Check if the parent of the element correctly includes this element as a child"
79
-
80
- anElement parent
81
- ifNil: [
82
- anElement class = MicRootBlock
83
- ifFalse: [ orphanList add: anElement ]
84
- ifTrue: [ anElement children do: [ :each | self visit: each ] ] ]
85
- ifNotNil: [ :p |
86
- " We cannot identify bad parent that are refered by child not in the children
87
- list, because by construction the algo only considers the children of an element).
88
- (p children includes: anElement) ifFalse: [ self addParent: p ]."
89
-
90
- p children do: [ :child |
91
- child parent = p ifFalse: [ confusedKids addChild: child ] ].
92
-
93
- anElement children do: [ :each | self visit: each ] ]
94
- ]
0 commit comments