Skip to content

Commit d1af987

Browse files
committed
Cleaner
1 parent b31a218 commit d1af987

File tree

2 files changed

+23
-68
lines changed

2 files changed

+23
-68
lines changed
Lines changed: 18 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,33 @@
11
Class {
22
#name : 'MicParentChildrenChecker',
3-
#superclass : 'MicrodownVisitor',
3+
#superclass : 'Object',
44
#instVars : [
55
'orphanList',
6-
'badReferencingParentList',
76
'confusedKids'
87
],
98
#category : 'Microdown-ParentChildrenChecker',
109
#package : 'Microdown-ParentChildrenChecker'
1110
}
1211

1312
{ #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"
2815

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 ] ].
3326

34-
{ #category : 'visiting main API' }
35-
MicParentChildrenChecker >> childrenList: anObject [
36-
orphanList := anObject
27+
anElement children do: [ :each | self check: each ] ]
3728
]
3829

39-
{ #category : 'testing' }
30+
{ #category : 'accessing' }
4031
MicParentChildrenChecker >> confusedKids [
4132

4233
^ confusedKids
@@ -47,48 +38,17 @@ MicParentChildrenChecker >> initialize [
4738

4839
super initialize.
4940
orphanList := OrderedCollection new.
50-
badReferencingParentList := OrderedCollection new.
5141
confusedKids := OrderedCollection new
5242
]
5343

5444
{ #category : 'testing' }
5545
MicParentChildrenChecker >> isOk [
5646

57-
^ badReferencingParentList isEmpty and:
58-
( orphanList isEmpty and: [ confusedKids isEmpty ])
47+
^ confusedKids isEmpty and:
48+
(orphanList isEmpty and: [ confusedKids isEmpty ])
5949
]
6050

61-
{ #category : 'testing' }
51+
{ #category : 'accessing' }
6252
MicParentChildrenChecker >> orphanList [
6353
^orphanList
6454
]
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-
]

src/Microdown-ParentChildrenChecker/MicParentChildrenCheckerTest.class.st

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,10 @@ You can edit this file clicking on `ClySyntaxHelpMorph>>#rawMicrodownSyntax`.'.
4242
{ #category : 'tests' }
4343
MicParentChildrenCheckerTest >> testSimpleDocumentIsWellFormed [
4444

45-
| visitor |
46-
visitor := MicParentChildrenChecker new.
47-
self document accept: visitor.
48-
self assert: visitor isOk.
49-
50-
51-
52-
53-
45+
| checker |
46+
checker := MicParentChildrenChecker new.
47+
checker check: self document.
48+
self assert: checker isOk
5449
]
5550

5651
{ #category : 'tests' }
@@ -63,7 +58,7 @@ MicParentChildrenCheckerTest >> testSimpleDocumentWithOrphans [
6358
orphan basicParent: nil.
6459
self assert: orphan parent isNil.
6560

66-
visitor visit: brokenDocument.
61+
visitor check: brokenDocument.
6762

6863
self deny: visitor isOk
6964
]

0 commit comments

Comments
 (0)