core/MetacelloToolBoxConstructor.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Mon, 10 Sep 2012 20:55:47 +0000
changeset 10 fd87600067b8
parent 1 MetacelloToolBoxConstructor.st@9e312de5f694
child 11 d354ac2af7ec
permissions -rw-r--r--
Metacello package refactoring - phase 1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
9e312de5f694 - Initial commit
jv
parents:
diff changeset
     1
"{ Package: 'stx:goodies/metacello' }"
9e312de5f694 - Initial commit
jv
parents:
diff changeset
     2
9e312de5f694 - Initial commit
jv
parents:
diff changeset
     3
MetacelloAbstractVersionConstructor subclass:#MetacelloToolBoxConstructor
9e312de5f694 - Initial commit
jv
parents:
diff changeset
     4
	instanceVariableNames:'currentSection methodSections'
9e312de5f694 - Initial commit
jv
parents:
diff changeset
     5
	classVariableNames:''
9e312de5f694 - Initial commit
jv
parents:
diff changeset
     6
	poolDictionaries:''
9e312de5f694 - Initial commit
jv
parents:
diff changeset
     7
	category:'Metacello-Core-Constructors'
9e312de5f694 - Initial commit
jv
parents:
diff changeset
     8
!
9e312de5f694 - Initial commit
jv
parents:
diff changeset
     9
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    10
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    11
!MetacelloToolBoxConstructor methodsFor:'api'!
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    12
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    13
for: attribute do: aBlock
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    14
	"conditional version support"
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    15
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    16
	| methodSection |
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    17
	methodSection := (MetacelloVersionMethodSection new)
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    18
				attribute: attribute;
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    19
				block: aBlock;
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    20
				yourself.
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    21
	currentSection ~~ nil
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    22
		ifTrue: [ currentSection addMethodSection: methodSection ]
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    23
		ifFalse: [ self methodSections add: methodSection]
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    24
!
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    25
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    26
for: attribute version: aString
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    27
	"conditional symbolicVersion support"
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    28
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    29
	self methodSections
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    30
		add:
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    31
			((MetacelloSymbolicVersionSpec new)
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    32
				attribute: attribute;
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    33
				versionString: aString;
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    34
				yourself)
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    35
! !
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    36
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    37
!MetacelloToolBoxConstructor methodsFor:'enumeration'!
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    38
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    39
methodSectionsDo: aBlock
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    40
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    41
	self methodSection: self do: aBlock
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    42
!
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    43
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    44
methodSectionsInEvaluationOrder: attributes do: aBlock
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    45
	"breadth first traversal ... to collect selected sections, then evaluate individual sections in attribute order"
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    46
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    47
	| selected |
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    48
	selected := OrderedCollection new.
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    49
	self methodSection: self inEvaluationOrder: attributes do: [:methodSection | selected add: methodSection ]. 
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    50
	attributes
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    51
		do: [ :attribute | (selected select: [ :methodSection | methodSection attribute == attribute ]) do: aBlock ].
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    52
! !
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    53
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    54
!MetacelloToolBoxConstructor methodsFor:'extraction'!
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    55
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    56
extractMethodSectionsFor: sourceVersionString
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    57
	| coll pragma |
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    58
	coll := self extractAllVersionPragmas at: sourceVersionString ifAbsent: [ ^ #() ].
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    59
	coll size > 1
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    60
		ifTrue: [ self error: 'More than one pragma defining ' , sourceVersionString printString ].
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    61
	pragma := coll at: 1.
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    62
	self evaluatePragma: pragma.
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    63
	self methodSections do: [ :methodSection | self evaluateMethodSection: methodSection version: sourceVersionString ].
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    64
!
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    65
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    66
extractSymbolicVersionSpecsFor: sourceVersionSymbol
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    67
	| coll versionSpec pragma |
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    68
	coll := self extractSymbolicVersionPragmas at: sourceVersionSymbol ifAbsent: [ ^ #() ].
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    69
	coll size > 1
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    70
		ifTrue: [ self error: 'More than one pragma defining ' , sourceVersionSymbol printString ].
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    71
	pragma := coll at: 1.
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    72
	self evaluatePragma: pragma.
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    73
	^ self methodSections
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    74
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    75
! !
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    76
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    77
!MetacelloToolBoxConstructor methodsFor:'initialization'!
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    78
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    79
reset
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    80
	super reset.	"not needed, but included for completeness"
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    81
	methodSections := nil
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    82
! !
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    83
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    84
!MetacelloToolBoxConstructor methodsFor:'private'!
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    85
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    86
evaluateMethodSection: methodSection version: sourceVersionString
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    87
	| versionSpec |
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    88
	versionSpec := self project versionSpec.
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    89
	versionSpec versionString: sourceVersionString.
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    90
	methodSection versionSpec: versionSpec.
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    91
	currentSection := methodSection.
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    92
	self with: versionSpec during: methodSection block.
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    93
	methodSection methodSections do: [ :ms | self evaluateMethodSection: ms version: sourceVersionString ]
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    94
!
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    95
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    96
methodSection: methodSection do: aBlock
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    97
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    98
	methodSection methodSections do: aBlock.
9e312de5f694 - Initial commit
jv
parents:
diff changeset
    99
	methodSection methodSections do: [ :ms | self methodSection: ms do: aBlock ]
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   100
!
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   101
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   102
methodSection: methodSection inEvaluationOrder: attributes do: aBlock
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   103
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   104
	| selected |
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   105
	selected := OrderedCollection new.
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   106
	attributes
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   107
		do: [ :attribute | 
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   108
			methodSection methodSections
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   109
				do: [ :ms | 
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   110
					attribute == ms attribute
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   111
						ifTrue: [ selected add: ms ] ] ].
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   112
	selected do: aBlock.
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   113
	attributes size == 1
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   114
		ifTrue: [ ^ self ].
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   115
	selected
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   116
		do: [ :ms | self methodSection: ms inEvaluationOrder: (attributes copyFrom: 2 to: attributes size) do: aBlock ]
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   117
!
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   118
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   119
methodSections
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   120
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   121
	methodSections == nil ifTrue: [ methodSections := OrderedCollection new ].
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   122
	^methodSections
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   123
! !
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   124
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   125
!MetacelloToolBoxConstructor class methodsFor:'documentation'!
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   126
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   127
version_SVN
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   128
    ^ '$Id::                                                                                                                        $'
9e312de5f694 - Initial commit
jv
parents:
diff changeset
   129
! !