SystemOrganization addCategory: #'Refactoring-Tests-Core'! SystemOrganization addCategory: #'Refactoring-Tests-Core-Data'! Model subclass: #RBClassToRename instanceVariableNames: 'rewriteRule builder class' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core-Data'! RBClassToRename class instanceVariableNames: 'notUsed'! RBClassToRename class instanceVariableNames: 'notUsed'! !RBClassToRename methodsFor: 'performing' stamp: ''! method1 ^self method2! ! !RBClassToRename methodsFor: 'performing' stamp: ''! method2 ^self method1! ! RBClassToRename subclass: #RBSubclassOfClassToRename instanceVariableNames: 'rewriteRule1' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core-Data'! !RBSubclassOfClassToRename methodsFor: 'accessing' stamp: ''! calls ^self rewriteRule1: self name , self rewriteRule1! ! !RBSubclassOfClassToRename methodsFor: 'accessing' stamp: ''! calls1 ^self rewriteRule1: (self rewriteRule1: self calls)! ! !RBSubclassOfClassToRename methodsFor: 'accessing' stamp: ''! name ^rewriteRule1! ! !RBSubclassOfClassToRename methodsFor: 'performing' stamp: 'lr 2/26/2009 14:51'! reference ^ RBClassToRename new! ! !RBSubclassOfClassToRename methodsFor: 'accessing' stamp: ''! rewriteRule1 ^rewriteRule1! ! !RBSubclassOfClassToRename methodsFor: 'accessing' stamp: ''! rewriteRule1: anObject ^rewriteRule1 := anObject! ! !RBSubclassOfClassToRename methodsFor: 'performing' stamp: 'lr 2/26/2009 14:51'! symbolReference ^ #RBClassToRename! ! TestCase subclass: #RBParserTest instanceVariableNames: 'currentSelector classSearches' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBParserTest methodsFor: 'accessing' stamp: 'lr 2/26/2009 14:51'! buildArgumentSearch self createArgumentSearchWith: 'aSmalllintContext' selectors: #(#checkMethod: #checkClass: ) inClass: RBBasicLintRuleTest! ! !RBParserTest methodsFor: 'accessing' stamp: 'lr 2/26/2009 14:51'! buildMessageSearch self createSearchWith: '``@receiver -> ``@arg' selectors: #(#superSends #superSends ) inClass: RBTransformationRuleTest! ! !RBParserTest methodsFor: 'accessing' stamp: 'lr 2/26/2009 14:51'! buildMethodArgumentSearch "Two argument methods" self createMethodSearchWith: '`arg1: `arg1 `arg2: `arg2 | `@temps | `@.Stmts' selectors: #( #subclassOf:overrides: #createMatcherFor:method: #createParseTreeRule:name: ) inClass: RBBasicLintRuleTest class! ! !RBParserTest methodsFor: 'accessing' stamp: 'lr 2/26/2009 14:51'! buildMethodSearch "Simple forwarders" self createMethodSearchWith: '`@methodName: `@args ^`@object `@methodName: `@args' selectors: #(#problemCount #isEmpty ) inClass: RBTransformationRuleTest! ! !RBParserTest methodsFor: 'accessing' stamp: 'lr 2/26/2009 14:51'! buildMethodTitleSearch self createMethodSearchWith: 'initialize | `@temps | `@.Stmts' selectors: #(#initialize ) inClass: RBBasicLintRuleTest! ! !RBParserTest methodsFor: 'accessing' stamp: 'lr 11/2/2009 00:14'! buildSimpleLiteralSearch | search | search := RBParseTreeSearcher new. search matchesAnyTreeOf: (Array with: (RBParser parseExpression: '#(''bugs'' ''possible bugs'' ''unnecessary code'' ''intention revealing'' ''miscellaneous'')')) do: [ :aNode :answer | answer remove: self currentSelector ifAbsent: [ self error: 'failed' ]; yourself ]. search answer: #(#protocols ) asBag. (classSearches at: RBBasicLintRuleTest class ifAbsentPut: [ Set new ]) add: search! ! !RBParserTest methodsFor: 'accessing' stamp: 'lr 2/26/2009 14:51'! buildSimpleVariableSearch self createSearchWith: 'result' selectors: #( #checkClass: #checkMethod: #isEmpty #problemCount #resetResult #resetResult #resetResult #result #result: #resultClass: #viewResults ) inClass: RBBasicLintRuleTest! ! !RBParserTest methodsFor: 'accessing' stamp: 'lr 2/26/2009 14:51'! buildStatementSearch "Two or more statements" self createSearchWith: '| `@temps | ``@.Stmts1. ``.Stmt1. ``@.Stmts2. ``.Stmt2. ``@.Stmts3' selectors: #( #checkMethod: #rewriteUsing: #viewResults #superSends ) inClass: RBTransformationRuleTest! ! !RBParserTest methodsFor: 'accessing' stamp: ''! compare: anObject to: anotherObject self assert: anObject hash = anotherObject hash. self assert: anObject = anotherObject! ! !RBParserTest methodsFor: 'accessing' stamp: 'lr 11/2/2009 00:14'! createArgumentSearchWith: aCodeString selectors: selectorCollection inClass: aClass | search | search := RBParseTreeSearcher new. search matchesAnyArgumentOf: (Array with: aCodeString) do: [:aNode :answer | answer remove: self currentSelector ifAbsent: [self error: 'failed']; yourself]. search answer: selectorCollection asBag. (classSearches at: aClass ifAbsentPut: [Set new]) add: search! ! !RBParserTest methodsFor: 'accessing' stamp: 'lr 11/2/2009 00:14'! createMethodSearchWith: aCodeString selectors: selectorCollection inClass: aClass | search | search := RBParseTreeSearcher new. search matchesAnyMethodOf: (Array with: aCodeString) do: [:aNode :answer | answer remove: self currentSelector ifAbsent: [self error: 'failed']; yourself]. search answer: selectorCollection asBag. (classSearches at: aClass ifAbsentPut: [Set new]) add: search! ! !RBParserTest methodsFor: 'accessing' stamp: 'lr 11/2/2009 00:14'! createSearchWith: aCodeString selectors: selectorCollection inClass: aClass | search | search := RBParseTreeSearcher new. search matches: aCodeString do: [:aNode :answer | answer remove: self currentSelector ifAbsent: [self error: 'failed']; yourself]. search answer: selectorCollection asBag. (classSearches at: aClass ifAbsentPut: [Set new]) add: search! ! !RBParserTest methodsFor: 'accessing' stamp: ''! currentSelector ^currentSelector! ! !RBParserTest methodsFor: 'private' stamp: 'lr 11/1/2009 20:38'! parseError: each RBParser parseExpression: each first onError: [:string :pos | ^self assert: pos = each last]. self error: 'Parser didn''t fail'! ! !RBParserTest methodsFor: 'accessing' stamp: ''! setUp super setUp. classSearches := Dictionary new. self buildMethodSearch; buildSimpleVariableSearch; buildSimpleLiteralSearch; buildMessageSearch; buildStatementSearch; buildArgumentSearch; buildMethodTitleSearch; buildMethodArgumentSearch! ! !RBParserTest methodsFor: 'tests' stamp: ''! testAllSearches classSearches keysAndValuesDo: [:class :searches | class selectors do: [:sel | currentSelector := sel. searches do: [:each | each executeTree: (class parseTreeFor: sel) initialAnswer: each answer]]]. classSearches do: [:searches | searches do: [:each | self assert: each answer isEmpty]]! ! !RBParserTest methodsFor: 'tests' stamp: 'lr 11/1/2009 20:44'! testArray | tree | #(('{}' 0 0) ('{.}' 0 1) ('{..}' 0 2) ('{foo. bar}' 2 1) ('{foo. bar.}' 2 2) ('{foo. bar. .}' 2 3) ('{. foo. bar}' 2 2) ('{foo.. bar}' 2 2)) do: [ :each | tree := RBParser parseExpression: each first. self assert: tree statements size = each second. self assert: tree periods size = each last. self assert: tree left = 1. self assert: tree right = each first size ]! ! !RBParserTest methodsFor: 'tests' stamp: 'lr 10/27/2009 14:31'! testBestNodeFor | tree | tree := self treeWithReallyEverything. tree nodesDo: [:each | each sourceInterval isEmpty ifFalse: [self assert: ((tree bestNodeFor: each sourceInterval) = each or: [each parent isCascade and: [each parent messages last = each]])]]! ! !RBParserTest methodsFor: 'tests' stamp: 'lr 11/2/2009 00:14'! testBlockRewrites | rewriter tree | tree := RBParser parseMethod: 'method: asdf ^asdf + self foo + asdf'. rewriter := RBParseTreeRewriter new. rewriter replace: 'asdf' with: 'fdsa' when: [:aNode | aNode parent parent isReturn]. rewriter replace: 'self foo' withValueFrom: [:aNode | RBVariableNode named: aNode selector asString]. rewriter replaceArgument: 'asdf' withValueFrom: [:aNode | RBVariableNode named: 'xxx'] when: [:aNode | false]. rewriter executeTree: tree. self compare: tree to: (RBParser parseMethod: 'method: asdf ^asdf + foo + fdsa')! ! !RBParserTest methodsFor: 'tests' stamp: ''! testCascadeReplacement | cascade | cascade := RBParser parseExpression: 'self foo; bar; baz'. (cascade messages at: 2) replaceWith: (RBParser parseExpression: 'self bar: 2'). self compare: cascade to: (RBParser parseExpression: 'self foo; bar: 2; baz')! ! !RBParserTest methodsFor: 'tests' stamp: 'lr 2/26/2009 14:51'! testComparingTrees | class | class := RBBasicLintRuleTest class. class selectors do: [ :each | self compare: (class parseTreeFor: each) to: (class parseTreeFor: each) ]! ! !RBParserTest methodsFor: 'tests' stamp: 'lr 3/7/2010 13:35'! testCopy | tree class | tree := self treeWithReallyEverything. self compare: tree to: tree copy. class := RBBasicLintRuleTest class. class selectors do: [ :each | tree := class parseTreeFor: each. self compare: tree to: tree copy ]! ! !RBParserTest methodsFor: 'tests' stamp: 'lr 3/7/2010 13:35'! testCopyInContext | tree class | tree := self treeWithReallyEverything. self compare: tree to: (tree copyInContext: Dictionary new). class := RBBasicLintRuleTest class. class selectors do: [ :each | tree := class parseTreeFor: each. self compare: tree to: (tree copyInContext: Dictionary new) ]! ! !RBParserTest methodsFor: 'tests' stamp: 'ms 4/1/2007 12:11'! testCreationProtocol | messageNode | self compare: (RBMessageNode receiver: (RBVariableNode named: 'self') selector: #+ arguments: (Array with: (RBLiteralNode value: 0))) to: (RBParser parseExpression: 'self + 0'). messageNode := RBMessageNode receiver: (RBVariableNode named: 'self') selector: #foo. self compare: (RBMethodNode selector: #bar body: (RBSequenceNode statements: (OrderedCollection with: (RBCascadeNode messages: (OrderedCollection with: messageNode with: messageNode))))) to: (RBParser parseMethod: 'bar self foo; foo')! ! !RBParserTest methodsFor: 'tests' stamp: 'lr 3/7/2010 13:52'! testEqualToWithMapping | tree class | tree := self treeWithReallyEverything. self assert: (tree equalTo: tree withMapping: Dictionary new). class := RBBasicLintRuleTest class. class selectors do: [ :each | tree := class parseTreeFor: each. self assert: (tree equalTo: tree withMapping: Dictionary new) ]! ! !RBParserTest methodsFor: 'tests' stamp: 'nk 2/23/2005 15:58'! testEquivalentExceptRenaming #(('a 3-4' 'a 4-3' false ) ('a #[3 4]' 'a #(3 4)' false ) ('a variable1 ~~ "comment" variable2' 'a variable1 ~~ variable2' true ) ('a variable1' 'a variable2' false ) ('a [:a :b | a + b]' 'a [:b :a | a + b]' false ) ('a | a b | a + b' 'a | b a | a + b' true ) ('a | a | a msg1; msg2' 'a | b | b msg2; msg2' false ) ('a c' 'a d' true ) ('a | a b | a := b. ^b msg1' 'a | a b | b := a. ^a msg1' true ) ('a | a b | a := b. ^b msg1: a' 'a | a b | b := a. ^b msg1: a' false ) ('a: b b + 4' 'a: e e + 4' true ) ('a: b b + 4' 'b: b b + 4' false ) ('a: b b: c b + c' 'a: c b: b c + b' true ) ('a: a b: b a + b' 'a: b b: a a + b' false ) ) do: [:each | self assert: ((RBParser parseMethod: each first) equalTo: (RBParser parseMethod: (each at: 2)) exceptForVariables: #('c' )) == each last ]! ! !RBParserTest methodsFor: 'tests' stamp: 'lr 2/26/2009 14:51'! testFormatter | class | class := RBBasicLintRuleTest class. class selectors do: [ :each | self compare: (class parseTreeFor: each) to: (RBParser parseMethod: (class parseTreeFor: each) printString) ]! ! !RBParserTest methodsFor: 'tests' stamp: 'lr 11/1/2009 21:59'! testIntervals | tree | tree := self treeWithReallyEverything. tree nodesDo: [:each | (each parent isNil or: [each parent isCascade not and: [ each parent isLiteral not]]) ifTrue: [| newNode source | source := tree source copyFrom: each start to: each stop. each isPragma ifFalse: [ newNode := each isMethod ifTrue: [RBParser parseMethod: source] ifFalse: [RBParser parseExpression: source]. self compare: each to: newNode]]]! ! !RBParserTest methodsFor: 'tests' stamp: 'TestRunner 11/2/2009 21:21'! testIsA | nodes types | nodes := Bag new. types := Set new. #(#(#isAssignment 1) #(#isBlock 1) #(#isCascade 1) #(#isLiteral 2) #(#isMessage 3) #(#isMethod 1) #(#isReturn 1) #(#isSequence 2) #(#isValue 15) #(#isVariable 7) #(#isUsed 10) #(#isDirectlyUsed 9) #(#hasParentheses 1) #(#isBinary 0) #(#isPrimitive 0) #(#isImmediate 10) #(#isWrite 1) #(#isRead 3)) do: [:each | each last timesRepeat: [nodes add: each first]. types add: each first]. self treeWithEverything nodesDo: [:each | types do: [:sel | ((each respondsTo: sel) and: [each perform: sel]) ifTrue: [nodes remove: sel]]]. self assert: nodes isEmpty! ! !RBParserTest methodsFor: 'tests' stamp: 'lr 11/1/2009 20:36'! testLiteralArray | tree collection | tree := RBParser parseExpression: '#( a #b #''c'' . + - 1 -2 3.4 #true true #false false #nil nil "comment" ''string'' #[ 1 2 3 ] #(1 2 3))'. collection := OrderedCollection new. collection add: #a; add: #b; add: #c; add: #'.'; add: #+; add: #-; add: 1; add: -2; add: 3.4; add: #true; add: true; add: #false; add: false; add: #nil; add: nil; add: 'string'; add: #[1 2 3]; add: #(1 2 3). tree value with: collection do: [ :token :value | self assert: token value = value ]! ! !RBParserTest methodsFor: 'tests' stamp: 'lr 11/1/2009 20:40'! testLiteralIntevals | tree | tree := RBParser parseExpression: '#(#a b #( c ))'. self assert: tree contents first start = 3. self assert: tree contents first stop = 4. self assert: tree contents last contents first start = 11! ! !RBParserTest methodsFor: 'tests' stamp: 'lr 3/7/2010 13:39'! testMatchInContext | tree class | tree := self treeWithReallyEverything. self assert: (tree match: tree inContext: Dictionary new). class := RBBasicLintRuleTest class. class selectors do: [ :each | tree := class parseTreeFor: each. self assert: (tree match: tree inContext: Dictionary new) ]! ! !RBParserTest methodsFor: 'tests' stamp: ''! testMethodPatterns #(#('+ a ^self + a' #+) #('foo ^self foo' #foo) #('foo: a bar: b ^a + b' #foo:bar:)) do: [:each | self assert: (RBParser parseMethodPattern: each first) == each last]! ! !RBParserTest methodsFor: 'tests' stamp: 'md 2/26/2006 14:48'! testModifying | tree | tree := RBParser parseMethod: 'foo: a bar: b | c | self first. self second. a + b + c'. self deny: tree lastIsReturn. self deny: (tree body statements at: 2) isUsed. self assert: tree body statements last arguments first isUsed. self assert: (tree isLast: tree body statements last). self deny: (tree isLast: tree body statements first). self assert: (tree defines: 'a'). self deny: (tree defines: 'c'). self assert: (tree body defines: 'c'). self deny: (tree body defines: 'a'). tree addReturn; selector: #bar:foo:. (tree body) addTemporaryNamed: 'd'; removeTemporaryNamed: 'c'. self compare: tree to: (RBParser parseMethod: 'bar: a foo: b | d | self first. self second. ^a + b + c'). self assert: ((tree argumentNames asSet) removeAll: #('a' 'b'); yourself) isEmpty. self assert: ((tree allDefinedVariables asSet) removeAll: #('a' 'b' 'd'); yourself) isEmpty. tree := RBParser parseExpression: 'self foo: 0'. tree selector: #+. self compare: tree to: (RBParser parseExpression: 'self + 0'). self should: [tree selector: #foo] raise: TestResult error.! ! !RBParserTest methodsFor: 'tests' stamp: 'lr 11/2/2009 00:14'! testMultimatch | rewriter count | count := 0. rewriter := RBParseTreeRewriter new. rewriter replace: '``@object at: ``@foo' with: '``@object foo: ``@foo' when: [:aNode | (count := count + 1) == 2]. self compare: (rewriter executeTree: (RBParser parseExpression: 'self at: (bar at: 3)'); tree) to: (RBParser parseExpression: 'self at: (bar foo: 3)')! ! !RBParserTest methodsFor: 'tests' stamp: 'lr 11/1/2009 20:50'! testNodesDo | size | size := 0. self treeWithEverything nodesDo: [:e | size := size + 1]. self assert: size = 19! ! !RBParserTest methodsFor: 'tests' stamp: 'lr 12/16/2009 19:16'! testNumberParsing | numbers node | numbers := #(('1' 1) ('-1' -1) ('123' 123) ('123' 123) ('-123' -123) ('1.1' 1.1) ('-1.1' -1.1) ('1.23' 1.23) ('-1.23' -1.23) ('1e3' 1e3) ('1d3' 1d3) ('1q3' 1q3) ('-1e3' -1e3) ('1e-3' 1e-3) ('-1e-3' -1e-3) ('2r1e8' 2r1e8) ('-2r1e8' -2r1e8) ('2r1e-8' 2r1e-8) ('-2r1e-8' -2r1e-8) ('0.50s2' 0.50s2) ('0.500s3' 0.500s3) ('0.050s3' 0.050s3)). numbers do: [ :spec | node := RBParser parseExpression: spec first. self assert: node token source = spec first. self assert: node value = spec second ]! ! !RBParserTest methodsFor: 'tests' stamp: 'lr 12/16/2009 09:22'! testNumberRadixParsing 2 to: 32 do: [ :radix | | radixString | radixString := radix printString, 'r'. 0 to: 72 do: [ :i | self assert: (RBParser parseExpression: (radixString, (i radix: radix))) value = i ] ]! ! !RBParserTest methodsFor: 'tests' stamp: 'lr 5/26/2010 19:03'! testParents (Array with: self treeWithEverything with: self treeWithReallyEverything) do: [ :tree | (Array with: tree with: tree copy) do: [ :root | root nodesDo: [ :node | node children do: [ :each | (each parent isMessage and: [ each parent isCascaded ]) ifFalse: [ self assert: each parent == node. self assert: each methodNode == root ] ] ] ] ]! ! !RBParserTest methodsFor: 'tests' stamp: 'lr 11/1/2009 20:38'! testParserErrors #(#('self foo. + 3' 11) #('#(' 3) #('self 0' 6) #('self asdf;;asfd' 11)) do: [:each | self parseError: each]! ! !RBParserTest methodsFor: 'tests' stamp: 'lr 10/27/2009 15:53'! testParsingLiteralMessages self assert: (RBParser parseExpression: 'nil self nil') isMessage. self assert: (RBParser parseExpression: 'self true') isMessage. self assert: (RBParser parseExpression: 'self false') isMessage. self assert: (RBParser parseExpression: 'self -1') isMessage. self assert: (RBParser parseMethod: 'nil') isMethod. self assert: (RBParser parseMethod: 'true') isMethod. self assert: (RBParser parseMethod: 'false') isMethod! ! !RBParserTest methodsFor: 'tests' stamp: 'lr 11/2/2009 00:14'! testPatternCascade | rewriter | rewriter := RBParseTreeRewriter new. rewriter replace: 'self `;messages; foo: 4; `;messages1' with: 'self `;messages1; bar: 4; `;messages'. self compare: (rewriter executeTree: (RBParser parseExpression: 'self foo; printString; foo: 4; bar. self foo: 4'); tree) to: (RBParser parseExpression: 'self bar; bar: 4; foo; printString. self foo:4')! ! !RBParserTest methodsFor: 'tests' stamp: 'ms 4/1/2007 12:32'! testPositions | blockNode | blockNode := RBParser parseExpression: '[:a :b | ]'. self assert: blockNode left = 1. self assert: blockNode right = 10. self assert: blockNode bar = 8. self assert: blockNode sourceInterval = (1 to: 10). self assert: blockNode size = 1. "test dummy collection protocol" blockNode printString. "coverage" self deny: (blockNode isLast: (RBVariableNode named: 'b')). self compare: blockNode to: (RBBlockNode arguments: (OrderedCollection with: (RBVariableNode named: 'a') with: (RBVariableNode named: 'b')) body: (RBSequenceNode statements: OrderedCollection new)). ! ! !RBParserTest methodsFor: 'tests' stamp: 'lr 11/16/2009 22:19'! testPragmas | tree node | #( ('foo ' #foo ()) ('foo ' #foo: (1)) ('foo ' #foo: (1.2)) ('foo ' #foo: (-3)) ('foo ' #foo: (a)) ('foo ' #foo: (a)) ('foo ' #foo: ($a)) ('foo ' #foo: ('bar')) ('foo ' #foo: (true)) ('foo ' #foo: (false)) ('foo ' #foo: (nil)) ('foo ' #foo: ((1 2))) ('foo ' #foo:bar: (1 2))) do: [ :each | tree := RBParser parseMethod: each first. self assert: (tree pragmas size = 1). node := tree pragmas first. self assert: node selector = each second. 1 to: node arguments size do: [ :i | self assert: (node arguments at: i) value = (each last at: i) ]. self assert: (each first at: node start) = $<. self assert: (each first at: node stop) = $> ]! ! !RBParserTest methodsFor: 'tests' stamp: 'ms 4/1/2007 13:49'! testPrimitives self assert: (Object parseTreeFor: #basicAt:) isPrimitive. #(('foo ^true' false ) ('foo ^true' false ) (' foo ^true' true ) ) do: [:each | self assert: (RBParser parseMethod: each first) isPrimitive = each last]! ! !RBParserTest methodsFor: 'tests' stamp: ''! testQuerying | tree aNode arg1Node bNode | tree := RBParser parseMethod: ('test: a` | b |` b := (self foo: a; bar) baz.` b := super test: b.` ^[:arg1 | self foa1 + (super foo: arg1 foo: a foo: b)]' copyReplaceAll: '`' with: (String with: (Character value: 13))). self assert: tree selfMessages asSortedCollection asArray = #(#bar #foa1 #foo:). self assert: tree superMessages asSortedCollection asArray = #(#foo:foo:foo: #test:). aNode := tree whichNodeIsContainedBy: (112 to: 112). self assert: aNode name = 'a'. bNode := tree whichNodeIsContainedBy: (119 to: 119). self assert: bNode name = 'b'. arg1Node := tree whichNodeIsContainedBy: (102 to: 105). self assert: arg1Node name = 'arg1'. self assert: (arg1Node statementNode isMessage and: [arg1Node statementNode selector = #+]). self assert: (arg1Node whoDefines: 'arg1') isBlock. self assert: (aNode whoDefines: 'a') isMethod. self assert: (aNode whoDefines: 'b') isSequence. self assert: (tree whichNodeIsContainedBy: (91 to: 119)) selector = #foo:foo:foo:. self assert: (tree whichNodeIsContainedBy: (69 to: 121)) isBlock. self assert: (tree whichNodeIsContainedBy: (69 to: 118)) isNil. self assert: aNode blockVariables asSortedCollection asArray = #('arg1'). self assert: aNode temporaryVariables asSortedCollection asArray = #('b'). self assert: tree allDefinedVariables asSortedCollection asArray = #('a' 'arg1' 'b'). self assert: tree allArgumentVariables asSortedCollection asArray = #('a' 'arg1'). self assert: tree allTemporaryVariables asSortedCollection asArray = #('b')! ! !RBParserTest methodsFor: 'tests' stamp: 'nk 2/23/2005 15:58'! testReadBeforeWritten #(('a ifTrue: [^self]' true ) ('self foo. a := b' false ) ('condition ifTrue: [a := b] ifFalse: [self foo: a]' true ) ('condition ifTrue: [a := b] ifFalse: [self foo]. a isNil' true ) ('condition ifTrue: [a := b]. a := c' false ) ('[a := b] whileFalse: [a isNil]' false ) ('self foo: b' false ) ) do: [:each | self assert: ((RBReadBeforeWrittenTester readBeforeWritten: #('a' ) in: (RBParser parseExpression: each first)) includes: 'a') == each last. self assert: (RBReadBeforeWrittenTester isVariable: 'a' readBeforeWrittenIn: (RBParser parseExpression: each first)) = each last]. #('| temp read written written1 | read ifTrue: [^self]. written1 := self foo ifFalse: [written := true] ifTrue: [written := false]. [temp := true] whileTrue: [temp notNil & written]. ^temp' '| read written | self foo ifTrue: [written := true] ifFalse: [written := false]. self foo ifTrue: [read := true]. ^read' '| read written | self foo do: [:i | i]. [| i | i := 1. i == 1] whileFalse: [read notNil]' '| written | [written := 2] whileFalse. self do: [:each | | read | each & read]' '| read | self do: [:each | read := each]. self do: [:each | each & read]' ) do: [:each | | read | read := RBReadBeforeWrittenTester variablesReadBeforeWrittenIn: (RBParser parseExpression: each). self assert: (read size = 1 and: [read includes: 'read'])]! ! !RBParserTest methodsFor: 'tests' stamp: ''! testReadBeforeWritten1 self assert: (RBReadBeforeWrittenTester variablesReadBeforeWrittenIn: (RBParser parseMethod: 'addAll: aCollection "Answer aCollection, having added all elements of aCollection to the receiver. Fail if aCollection is not a kind of Collection." | newSize elementsSize growSize | (newSize := aCollection size * 2) > elements size ifTrue: [self rehash: newSize]. elementsSize := elements size. growSize := elementsSize // 2. aCollection do: [:newObject | | hashIndex element | newObject == nil ifFalse: [hashIndex := self hashIndexFor: newObject. [(element := elements at: hashIndex) == nil ifTrue: [elements at: hashIndex put: newObject. (elementCount := elementCount + 1) > growSize ifTrue: [self expand. elementsSize := elements size. growSize := elementsSize // 2]. true] ifFalse: [element == newObject]] whileFalse: [(hashIndex := hashIndex + 1) > elementsSize ifTrue: [hashIndex := 1]]]]. ^aCollection')) isEmpty! ! !RBParserTest methodsFor: 'tests' stamp: 'lr 11/2/2009 00:14'! testReplacingNodes | tree search block | tree := RBParser parseMethod: '+ a | a b | self ifTrue: [a] ifFalse: [b := c]. a := b. [:b :c :a | a foo: a; foo1: a; foo2: a foo: b]. {a. b}. ^a'. search := RBParseTreeSearcher new. block := [:aNode :answer | aNode replaceWith: (RBVariableNode named: 'q')]. search matches: 'a' do: block; matchesArgument: 'a' do: block. search executeTree: tree. self assert: tree = (RBParser parseMethod: '+ q | q b | self ifTrue: [q] ifFalse: [b := c]. q := b. [:b :c :q | q foo: q; foo1: q; foo2: q foo: b]. {q. b}. ^q'). self assert: tree removeDeadCode = (RBParser parseMethod: '+ q | q b | self ifTrue: [] ifFalse: [b := c]. q := b. {q. b}. ^q')! ! !RBParserTest methodsFor: 'tests' stamp: 'lr 5/30/2010 12:15'! testRewriteMethods "#('source' 'target' 'source pattern' 'target pattern')" #(#('arg1: a arg2: b | temp1 temp2 | self stmt1 ifTrue: [^a]. self arg1: a arg2: b' 'arg2: a arg1: b | temp1 temp2 | self stmt1 ifTrue: [^a]. self arg2: b arg2: a' '`arg1: `var1 `arg2: `var2 | `@temps | ``@.stmts. self `arg1: `var1 `arg2: `var2. `@.stmts1' '`arg2: `var1 `arg1: `var2 | `@temps | ``@.stmts. self `arg2: `var2 `arg2: `var1. `@.stmts1') #('arg1: a arg2: b | temp1 temp2 | self stmt1. self arg1: a arg2: b' 'arg1: a arg2: b | temp1 temp2 | [self stmt1] repeat' '`@args: `@vars | `@temps | `@.stmts. self `@args: `@vars' '`@args: `@vars | `@temps | [`@.stmts] repeat') #('+ a | temps | ^self primitiveValue' '- a | temps | ^self primitiveValue' '+ `temp | `@tmps | `@.stmts' '- `temp | `@tmps | `@.stmts') #('a self stmt1. self stmt2' 'a self stmt1. self stmt2' 'b | `@temps | `@.stmts' 'c | `@temps | `@.stmts') #('a ' 'a ' 'a <`sel1: `#arg1 `sel2: `#arg2>' 'a <`sel2: `#arg2 `sel1: `#arg1>') #('a self foo' 'b self foo' 'a `@.stmts' 'b `@.stmts')) do: [:each | | rewrite | rewrite := RBParseTreeRewriter new. rewrite replaceMethod: (each at: 3) with: each last. self compare: (RBParser parseMethod: (rewrite executeTree: (RBParser parseMethod: each first); tree) formattedCode) to: (RBParser parseMethod: (each at: 2)). rewrite := RBParseTreeRewriter new. rewrite replaceTree: (RBParser parseRewriteMethod: (each at: 3)) withTree: (RBParser parseRewriteMethod: each last). self compare: (RBParser parseMethod: (rewrite executeTree: (RBParser parseMethod: each first); tree) formattedCode) to: (RBParser parseMethod: (each at: 2))]! ! !RBParserTest methodsFor: 'tests' stamp: 'lr 5/30/2010 11:45'! testRewrites "#('source' 'target' 'source pattern' 'target pattern')" #(('[:c | |a| a foo1; foo2]' '[:c | |a| b foo1; foo2]' 'a' 'b' ) ('self foo: 1. bar foo1 foo: 2. (self foo: a) foo: (b foo: c)' 'self bar: 1. bar foo1 bar: 2. (self bar: a) bar: (b bar: c)' '``@rcvr foo: ``@arg1' '``@rcvr bar: ``@arg1' ) ('3 + 4' '4 + 4' '3' '4' ) ('a := self a' 'b := self a' 'a' 'b' ) ('^self at: 1 put: 2' '^self put: 1 put: 2' '^`@rcvr `at: `@arg1 put: `@arg2' '^`@rcvr put: `@arg1 put: `@arg2' ) ('1 + 2 + 3' '0 + 0 + 0' '`#literal' '0' ) ('1 + 2 + 3. 3 foo: 4' '3 + (2 + 1). 4 foo: 3' '``@rcvr `msg: ``@arg' '``@arg `msg: ``@rcvr' ) ('self foo: a bar: b. 1 foo: a bar: b' '2 foo: a bar: b. 1 foo: a bar: b' 'self `@msg: `@args' '2 `@msg: `@args' ) ('a := b. a := c + d' 'b := a. a := c + d' '`var1 := `var2' '`var2 := `var1' ) ('^self foo value: 1' 'self return: (self foo value: 1)' '^`@anything' 'self return: `@anything' ) ('self first; second. self first; second. self a. self b' '2 timesRepeat: [self first; second]. self a. self b' '`.Stmt1. `.Stmt1. `@.stmts' '2 timesRepeat: [`.Stmt1]. `@.stmts' ) ('[:a | self a: 1 c: 2; b]' '[:a | self d: 2 e: 1; f. self halt]' '`@rcvr `msg1: `@arg1 `msg2: `@arg2; `msg' '`@rcvr d: `@arg2 e: `@arg1; f. self halt' ) ) do: [:each | | rewrite | rewrite := RBParseTreeRewriter new. rewrite replace: (each at: 3) with: each last. self compare: (RBParser parseExpression: (rewrite executeTree: (RBParser parseExpression: each first); tree) formattedCode) to: (RBParser parseExpression: (each at: 2))]! ! !RBParserTest methodsFor: 'tests' stamp: 'lr 11/2/2009 00:14'! testSearching | searcher | searcher := RBParseTreeSearcher new. searcher matches: '``@rcv at: ``@arg `sel: ``@arg1' do: [:aNode :answer | answer + 1]. self assert: (searcher executeTree: (RBParser parseExpression: 'self at: 1 put: 2; at: 2 ifAbsent: []; ifAbsent: 2 at: 1; at: 4; foo') initialAnswer: 0) = 2. searcher := RBParseTreeSearcher new. searcher matches: '``@rcv `at: ``@arg1 `at: ``@arg2' do: [:aNode :answer | answer + 1]. self assert: (searcher executeTree: (RBParser parseExpression: 'self at: 1 at: 3; at: 1 put: 32; at: 2; foo; at: 1 at: 1 at: 2') initialAnswer: 0) = 1. searcher := RBParseTreeSearcher new. searcher matchesMethod: 'at: `object `put: `o1 ``@rcv `put: 1' do: [:aNode :answer | true]. self assert: (searcher executeTree: (RBParser parseMethod: 'at: a put: b self foo put: 1') initialAnswer: false)! ! !RBParserTest methodsFor: 'tests' stamp: 'lr 11/1/2009 20:32'! testStatements | tree | #(('' 0 0) ('.' 0 1) ('| bar |' 0 0) ('| bar | .' 0 1) ('| bar | ..' 0 2) ('foo. bar' 2 1) ('foo. bar.' 2 2) ('foo. bar. .' 2 3) ('. foo. bar' 2 2)) do: [ :each | tree := RBParser parseExpression: each first. self assert: tree statements size = each second. self assert: tree periods size = each last ]! ! !RBParserTest methodsFor: 'tests' stamp: 'lr 4/21/2010 16:12'! testSymbolLiteral | tree | #(('# foo' #foo) ('#"bar"foo' #foo) ('##foo' #foo) ('###foo' #foo) ('#foo:' #foo:) ('#foo::' #'foo::') ('#foo::bar' #'foo::bar') ('#foo::bar:' #'foo::bar:') ('#foo::bar::' #'foo::bar::')) do: [ :pair | tree := RBParser parseExpression: pair first. self assert: tree value = pair second. self assert: tree start = 1. self assert: tree stop = pair first size ]. #(('#1' 1) ('#12' 12) ('#12.3' 12.3) ('# 1' 1) ('##1' 1) ('#"bar"1' 1)) do: [ :pair | tree := RBParser parseExpression: pair first. self assert: tree value = pair second. self assert: tree start > 1. self assert: tree stop = pair first size ]! ! !RBParserTest methodsFor: 'tests' stamp: 'lr 4/29/2010 21:22'! testSymbolNumber | tree | #(('#1' 1) ('#12' 12) ('#12.3' 12.3) ('# 1' 1) ('##1' 1) ('#"bar"1' 1)) do: [ :pair | tree := RBParser parseExpression: pair first. self assert: tree value = pair second. self assert: tree start > 1. self assert: tree stop = pair first size ]! ! !RBParserTest methodsFor: 'private' stamp: ''! treeWithEverything ^RBParser parseMethod: 'method: arg1 | temps | temps := #(10). temps foo; foo. ^(temps collect: [:e | ])'! ! !RBParserTest methodsFor: 'private' stamp: 'lr 12/19/2009 18:31'! treeWithReallyEverything ^ RBParser parseMethod: 'method: arg1 | temps | temps := #[ 1 2 3 ]. temps := #(true false nil 1 1.2 $a foo #foo ''foo'' #() #(1 2) #[] #[1 2]). { 1 negated. 1 + 2. 1 raisedTo: 2 }. temps foo; foo: self. ^ (temps collect: [:e | | btemps | ((e isNil)) ])'! ! TestCase subclass: #RBRefactoringBrowserTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! RBRefactoringBrowserTest subclass: #RBClassTest instanceVariableNames: 'objectClass newClass messageNodeClass' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBClassTest methodsFor: 'set up' stamp: 'bh 11/8/2000 14:12'! setUp | st | super setUp. st := RBNamespace new. objectClass := st classNamed: #Object. messageNodeClass := st classNamed: #RBMessageNode. st defineClass: 'Object subclass: #SomeClassName instanceVariableNames: ''instanceVariable1 instanceVariable2'' classVariableNames: ''ClassVariable1'' poolDictionaries: ''TextConstants'' category: #''Refactory-Testing'''. newClass := st classNamed: #SomeClassName! ! !RBClassTest methodsFor: 'method tests' stamp: ''! testDefinesClassVariable self deny: (objectClass definesClassVariable: #ClassVariable1). self assert: (objectClass definesClassVariable: self objectClassVariable). self assert: (newClass definesClassVariable: #ClassVariable1). self deny: (messageNodeClass definesClassVariable: #ClassVariable1). self assert: (messageNodeClass definesClassVariable: self objectClassVariable)! ! !RBClassTest methodsFor: 'method tests' stamp: ''! testDefinesInstanceVariable self deny: (objectClass definesInstanceVariable: 'instanceVariable1'). self assert: (newClass definesInstanceVariable: 'instanceVariable1'). self deny: (messageNodeClass definesInstanceVariable: 'instanceVariable1'). self assert: (messageNodeClass definesInstanceVariable: 'parent'). self assert: (messageNodeClass definesInstanceVariable: 'selector')! ! !RBClassTest methodsFor: 'method tests' stamp: ''! testDefinesMethod self assert: (objectClass definesMethod: #printString). self assert: (newClass definesMethod: #printString). self assert: (messageNodeClass definesMethod: #printString)! ! !RBClassTest methodsFor: 'method tests' stamp: 'bh 4/3/2000 22:22'! testDefinesPoolDictionary self deny: (objectClass definesPoolDictionary: #OpcodePool). self assert: (newClass definesPoolDictionary: #TextConstants). self deny: (messageNodeClass definesPoolDictionary: #OpcodePool). self assert: ((RBNamespace new classNamed: #Text) definesPoolDictionary: #TextConstants)! ! !RBClassTest methodsFor: 'method tests' stamp: 'lr 10/26/2009 22:09'! testHierarchy | meta | meta := objectClass theMetaClass. self assert: (objectClass withAllSubclasses includes: meta). self assert: (meta withAllSuperclasses includes: objectClass)! ! RBRefactoringBrowserTest subclass: #RBNamespaceTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBNamespaceTest methodsFor: 'class tests' stamp: ''! testAllClassesDo | model classes | classes := 0. model := RBNamespace new. model allClassesDo: [:each | each name = #Object ifTrue: [each allSubclasses]. classes := classes + 1]. BrowserEnvironment new classesDo: [:each | classes := classes - 1]. self assert: classes = 0! ! !RBNamespaceTest methodsFor: 'class tests' stamp: 'lr 7/1/2008 11:11'! testCommentChange | st cl | st := RBNamespace new. cl := st classNamed: self class name. self assert: cl comment isString. cl comment: 'a comment'. self assert: cl comment = 'a comment'. self assert: st changes changes size = 1. self assert: st changes changes first comment = 'a comment'. cl comment: nil. self assert: cl comment isNil. self assert: st changes changes size = 2. self assert: st changes changes last comment isNil! ! !RBNamespaceTest methodsFor: 'class tests' stamp: ''! testDefineClassAfterDeletedChange | st | st := RBNamespace new. st removeClassNamed: self class name. self deny: (st includesClassNamed: self class name). st defineClass: self class definition. self assert: (st includesClassNamed: self class name). self assert: (st classNamed: self class name) notNil! ! !RBNamespaceTest methodsFor: 'class tests' stamp: 'bh 11/8/2000 14:13'! testDefineClassChange | st | st := RBNamespace new. st defineClass: 'RefactoringBrowserTest subclass: #SmalltalkTestXXX instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Testing'''. self assert: (st includesClassNamed: #SmalltalkTestXXX). self assert: (st classNamed: #SmalltalkTestXXX) notNil! ! !RBNamespaceTest methodsFor: 'class tests' stamp: ''! testImplementors | st | st := RBNamespace new. self assert: ((st allImplementorsOf: #printString) includes: (st classNamed: #Object)). (st classNamed: #Object) removeMethod: #printString. self deny: ((st allImplementorsOf: #printString) includes: (st classNamed: #Object))! ! !RBNamespaceTest methodsFor: 'class tests' stamp: ''! testIncludesClass self assert: (RBNamespace new includesClassNamed: #Object). self deny: (RBNamespace new includesClassNamed: #Object1). self deny: ((RBNamespace onEnvironment: (ClassEnvironment onEnvironment: BrowserEnvironment new classes: (Array with: Object))) includesClassNamed: #OrderedCollection)! ! !RBNamespaceTest methodsFor: 'class tests' stamp: 'bh 9/17/2001 02:03'! testModelImplementorsSenders | model class modelImps refs found | model := RBNamespace new. model defineClass: 'Object subclass: #Asdf instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Testing'''. class := model classNamed: #Asdf. class compile: 'storeOn: aStream ^super storeOn: aStream' classified: #(#printing). modelImps := model allImplementorsOf: #storeOn:. self assert: (modelImps includes: class). self assert: modelImps size - 1 = (BrowserEnvironment new implementorsOf: #storeOn:) numberSelectors. refs := BrowserEnvironment new referencesTo: #storeOn:. found := false. model allReferencesTo: #storeOn: do: [:each | each modelClass = class ifTrue: [found := true] ifFalse: [self assert: (refs includesSelector: each selector in: each modelClass realClass)]]. self assert: found ! ! !RBNamespaceTest methodsFor: 'class tests' stamp: 'bh 11/8/2000 14:13'! testRedefineClassChange | st | st := RBNamespace new. st defineClass: 'nil subclass: #Object instanceVariableNames: ''a'' classVariableNames: ''A'' poolDictionaries: ''TextConstants'' category: #''Refactory-Testing'''. self assert: (st includesClassNamed: #Object). self assert: (st classNamed: #Object) notNil! ! !RBNamespaceTest methodsFor: 'class tests' stamp: 'lr 3/17/2010 18:52'! testReferencesPrintOn | hasFoundObject hasFoundSelf smalltalk | hasFoundObject := false. hasFoundSelf := false. smalltalk := RBNamespace new. smalltalk allReferencesTo: #printOn: do: [ :each | hasFoundObject := hasFoundObject or: [ each selector = #fullPrintString and: [each modelClass = (smalltalk classNamed: #Object) ] ]. hasFoundSelf := hasFoundSelf or: [ each selector = #testReferencesPrintOn and: [ each modelClass = (smalltalk classNamed: self class name) ] ] ]. self assert: hasFoundObject. self assert: hasFoundSelf! ! !RBNamespaceTest methodsFor: 'class tests' stamp: 'lr 3/17/2010 18:50'! testReferencesPrintOnAfterAddition | hasFoundObject hasFoundSelf smalltalk | hasFoundObject := false. hasFoundSelf := false. smalltalk := RBNamespace new. (smalltalk classNamed: #Object) compile: 'someTestReference self printOn: nil' classified: #(testing). (smalltalk classNamed: self class name) compile: 'someTestReference ^ #printOn:' classified: #(testing). smalltalk allReferencesTo: #printOn: do: [ :each | hasFoundObject := hasFoundObject or: [ each selector = #someTestReference and: [ each modelClass = (smalltalk classNamed: #Object) ] ]. hasFoundSelf := hasFoundSelf or: [ each selector = #someTestReference and: [ each modelClass = (smalltalk classNamed: self class name) ] ] ]. self assert: hasFoundObject. self assert: hasFoundSelf! ! !RBNamespaceTest methodsFor: 'class tests' stamp: 'lr 3/17/2010 18:51'! testReferencesPrintOnAfterRemove | hasFoundObject hasFoundSelf smalltalk | hasFoundObject := false. hasFoundSelf := false. smalltalk := RBNamespace new. (smalltalk classNamed: #Object) removeMethod: #printString. (smalltalk classNamed: self class name) removeMethod: #testReferencesPrintOnAfterRemove. smalltalk allReferencesTo: #printOn: do: [ :each | hasFoundObject := hasFoundObject or: [ each selector = #printString and: [ each modelClass = (smalltalk classNamed: #Object) ] ]. hasFoundSelf := hasFoundSelf or: [ each selector = #testReferencesPrintOnAfterRemove and: [ each modelClass = (smalltalk classNamed: self class name) ] ] ]. self deny: hasFoundObject. self deny: hasFoundSelf! ! !RBNamespaceTest methodsFor: 'class tests' stamp: ''! testRemoveClassChange | st | st := RBNamespace new. st removeClassNamed: self class name. self deny: (st includesClassNamed: self class name). self assert: (st classNamed: self class name) isNil! ! !RBNamespaceTest methodsFor: 'class tests' stamp: ''! testReparentSuperclassChange | st superclass subclasses | st := RBNamespace new. superclass := st classFor: TestCase superclass. subclasses := TestCase subclasses collect: [:each | st classFor: each]. st reparentClasses: subclasses to: superclass. subclasses do: [:each | self assert: each superclass = superclass]! ! !RBNamespaceTest methodsFor: 'class tests' stamp: 'bh 4/3/2000 15:47'! testRoots | model | model := RBNamespace new. self assert: (model rootClasses asSortedCollection: [:a :b | a name < b name]) asArray = ((Class rootsOfTheWorld collect: [:each | model classFor: each]) asSortedCollection: [:a :b | a name < b name]) asArray! ! !RBRefactoringBrowserTest class methodsFor: 'testing' stamp: 'lr 10/27/2009 14:01'! isAbstract ^ self name = #RBRefactoringBrowserTest! ! !RBRefactoringBrowserTest methodsFor: 'private' stamp: ''! convertInterval: anInterval for: aString "Convert the interval to ignore differences in end of line conventions." ^anInterval! ! !RBRefactoringBrowserTest methodsFor: 'private' stamp: ''! executeRefactoring: aRefactoring aRefactoring primitiveExecute. RBParser parseExpression: aRefactoring storeString! ! !RBRefactoringBrowserTest methodsFor: 'private' stamp: ''! objectClassVariable ^Object classPool keys detect: [:each | true]! ! !RBRefactoringBrowserTest methodsFor: 'private' stamp: 'md 8/2/2005 23:36'! proceedThroughWarning: aBlock aBlock on: RefactoringWarning do: [:ex | ex resume]! ! RBRefactoringBrowserTest subclass: #RBRefactoringTest instanceVariableNames: 'manager changeSet model' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! RBRefactoringTest subclass: #RBAbstractClassVariableTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBAbstractClassVariableTest methodsFor: 'set up' stamp: 'md 7/25/2005 15:17'! setUp super setUp. model := Compiler evaluate: self abstractVariableTestData.! ! !RBAbstractClassVariableTest methodsFor: 'tests' stamp: 'lr 11/2/2009 00:15'! testAbstractClassVariable | refactoring meta class | refactoring := AbstractClassVariableRefactoring variable: 'RecursiveSelfRule' class: RBTransformationRuleTest. self executeRefactoring: refactoring. class := refactoring model classNamed: #RBTransformationRuleTest. meta := class theMetaClass. self assert: (meta parseTreeFor: #recursiveSelfRule) = (RBParser parseMethod: 'recursiveSelfRule ^RecursiveSelfRule'). self assert: (meta parseTreeFor: #recursiveSelfRule:) = (RBParser parseMethod: 'recursiveSelfRule: anObject RecursiveSelfRule := anObject'). self assert: (meta parseTreeFor: #nuke) = (RBParser parseMethod: 'nuke self recursiveSelfRule: nil'). self assert: (meta parseTreeFor: #initializeAfterLoad1) = (RBParser parseMethod: 'initializeAfterLoad1 self recursiveSelfRule: RBParseTreeSearcher new. self recursiveSelfRule addMethodSearches: #(''`@methodName: `@args | `@temps | self `@methodName: `@args'' ''`@methodName: `@args | `@temps | ^self `@methodName: `@args'') -> [:aNode :answer | true]'). self assert: (class parseTreeFor: #checkMethod:) = (RBParser parseMethod: 'checkMethod: aSmalllintContext class := aSmalllintContext selectedClass. (rewriteRule executeTree: aSmalllintContext parseTree) ifTrue: [(self class recursiveSelfRule executeTree: rewriteRule tree initialAnswer: false) ifFalse: [builder compile: rewriteRule tree printString in: class classified: aSmalllintContext protocols]]')! ! !RBAbstractClassVariableTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testInheritedName self shouldFail: (AbstractClassVariableRefactoring variable: #DependentsFields class: RBBasicLintRuleTest)! ! !RBAbstractClassVariableTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testMetaClassFailure self shouldFail: (AbstractClassVariableRefactoring variable: #RecursiveSelfRule class: RBTransformationRuleTest class)! ! !RBAbstractClassVariableTest methodsFor: 'tests' stamp: 'lr 10/26/2009 22:09'! testModelAbstractClassVariable | refactoring meta class | class := model classNamed: #Foo. meta := class theMetaClass. refactoring := AbstractClassVariableRefactoring model: model variable: 'ClassVarName1' class: class. self executeRefactoring: refactoring. self assert: (meta parseTreeFor: #classVarName1) = (RBParser parseMethod: 'classVarName1 ^ClassVarName1'). self assert: (meta parseTreeFor: #classVarName1:) = (RBParser parseMethod: 'classVarName1: anObject ^ClassVarName1 := anObject'). self assert: (meta parseTreeFor: #foo) = (RBParser parseMethod: 'foo ^self classVarName1: self classVarName1 * self classVarName1 * self classVarName1'). self assert: (class parseTreeFor: #classVarName1) = (RBParser parseMethod: 'classVarName1 ^self class classVarName1'). self assert: (class parseTreeFor: #classVarName1:) = (RBParser parseMethod: 'classVarName1: anObject ^self class classVarName1: anObject'). self assert: (class parseTreeFor: #asdf) = (RBParser parseMethod: 'asdf ^self classVarName1: (self class classVarName1: self class classVarName1 + 1)'). self assert: ((model classNamed: #Bar) parseTreeFor: #foo) = (RBParser parseMethod: 'foo instVarName1 := instVarName1 + instVarName2 + self class classVarName1'). self assert: ((model classNamed: #Bar) parseTreeFor: #foo) = (RBParser parseMethod: 'foo instVarName1 := instVarName1 + instVarName2 + self class classVarName1')! ! !RBAbstractClassVariableTest methodsFor: 'tests' stamp: 'lr 10/26/2009 22:09'! testModelAbstractClassVariableOverridenMethodsInSubclass | refactoring meta class | class := model classNamed: #Foo. meta := class theMetaClass. refactoring := AbstractClassVariableRefactoring model: model variable: 'ClassVarName2' class: class. self executeRefactoring: refactoring. self assert: (meta parseTreeFor: #classVarName21) = (RBParser parseMethod: 'classVarName21 ^ClassVarName2'). self assert: (meta parseTreeFor: #classVarName21:) = (RBParser parseMethod: 'classVarName21: anObject ClassVarName2 := anObject')! ! !RBAbstractClassVariableTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testNonExistantName self shouldFail: (AbstractClassVariableRefactoring variable: #Foo class: RBBasicLintRuleTest)! ! RBRefactoringTest subclass: #RBAbstractInstanceVariableTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBAbstractInstanceVariableTest methodsFor: 'set up' stamp: 'md 7/25/2005 15:17'! setUp super setUp. model := Compiler evaluate: self abstractVariableTestData.! ! !RBAbstractInstanceVariableTest methodsFor: 'tests' stamp: 'lr 11/2/2009 00:15'! testAbstractInstanceVariable | refactoring class | refactoring := AbstractInstanceVariableRefactoring variable: 'class' class: RBTransformationRuleTest. self executeRefactoring: refactoring. class := refactoring model classNamed: #RBTransformationRuleTest. self assert: (class parseTreeFor: #class1) = (RBParser parseMethod: 'class1 ^class'). self assert: (class parseTreeFor: #class:) = (RBParser parseMethod: 'class: anObject class := anObject'). self assert: (class parseTreeFor: #superSends) = (RBParser parseMethod: 'superSends | rule | rule := RBParseTreeRewriter new. rule addSearch: ''super `@message: ``@args'' -> ( [:aNode | (self class1 withAllSubclasses detect: [:each | each includesSelector: aNode selector] ifNone: [nil]) isNil] -> ''self `@message: ``@args''). self rewriteUsing: rule'). self assert: (class parseTreeFor: #checkMethod:) = (RBParser parseMethod: 'checkMethod: aSmalllintContext self class: aSmalllintContext selectedClass. (rewriteRule executeTree: aSmalllintContext parseTree) ifTrue: [(RecursiveSelfRule executeTree: rewriteRule tree initialAnswer: false) ifFalse: [builder compile: rewriteRule tree printString in: self class1 classified: aSmalllintContext protocols]]')! ! !RBAbstractInstanceVariableTest methodsFor: 'tests' stamp: ''! testAbstractWithAssignmentUsed | refactoring class | class := model classNamed: #Foo. refactoring := AbstractInstanceVariableRefactoring model: model variable: 'instVarName2' class: class. self executeRefactoring: refactoring. self assert: (class parseTreeFor: #foo) = (RBParser parseMethod: 'foo ^self instVarName21: 3'). self assert: (class parseTreeFor: #instVarName2:) = (RBParser parseMethod: 'instVarName2: anObject self instVarName21: anObject'). self assert: (class parseTreeFor: #instVarName21:) = (RBParser parseMethod: 'instVarName21: anObject ^instVarName2 := anObject'). self assert: (class parseTreeFor: #instVarName2) = (RBParser parseMethod: 'instVarName2 ^instVarName2'). self assert: ((model classNamed: #Bar) parseTreeFor: #foo) = (RBParser parseMethod: 'foo instVarName1 := instVarName1 + self instVarName2 + ClassVarName1')! ! !RBAbstractInstanceVariableTest methodsFor: 'tests' stamp: ''! testAbstractWithDefaultNamesUsed | refactoring class | class := model classNamed: #Foo. refactoring := AbstractInstanceVariableRefactoring model: model variable: 'instVarName1' class: class. self executeRefactoring: refactoring. self assert: (class parseTreeFor: #bar) = (RBParser parseMethod: 'bar "Add one to instVarName1" self instVarName11: self instVarName11 + 1'). self assert: (class parseTreeFor: #instVarName11:) = (RBParser parseMethod: 'instVarName11: anObject instVarName1 := anObject'). self assert: (class parseTreeFor: #instVarName11) = (RBParser parseMethod: 'instVarName11 ^instVarName1'). self assert: ((model classNamed: #Bar) parseTreeFor: #foo) = (RBParser parseMethod: 'foo self instVarName11: self instVarName11 + instVarName2 + ClassVarName1')! ! !RBAbstractInstanceVariableTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testInheritedName self shouldFail: (AbstractInstanceVariableRefactoring variable: 'name' class: RBBasicLintRuleTest)! ! !RBAbstractInstanceVariableTest methodsFor: 'tests' stamp: ''! testMetaclassInstanceVariables | refactoring class | class := model metaclassNamed: #Foo. class addInstanceVariable: 'foo'. class compile: 'zzz ^foo := foo + foo * 2' classified: #(#testing). refactoring := AbstractInstanceVariableRefactoring model: model variable: 'foo' class: class. self executeRefactoring: refactoring. self assert: (class parseTreeFor: #foo1) = (RBParser parseMethod: 'foo1 ^foo'). self assert: (class parseTreeFor: #foo:) = (RBParser parseMethod: 'foo: anObject ^foo := anObject'). self assert: (class parseTreeFor: #zzz) = (RBParser parseMethod: 'zzz ^self foo: self foo1 + self foo1 * 2')! ! !RBAbstractInstanceVariableTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testNonExistantName self shouldFail: (AbstractInstanceVariableRefactoring variable: 'foo' class: RBBasicLintRuleTest)! ! RBRefactoringTest subclass: #RBAddClassTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBAddClassTest methodsFor: 'set up' stamp: 'md 7/25/2005 15:17'! setUp super setUp. model := Compiler evaluate: self abstractVariableTestData.! ! !RBAddClassTest methodsFor: 'tests' stamp: 'lr 10/26/2009 22:09'! testAddClass | refactoring newClass superClass classTest | refactoring := AddClassRefactoring addClass: #FooTest superclass: RBRefactoringTest subclasses: (Array with: self class) category: #'Refactory-Testing'. self executeRefactoring: refactoring. newClass := refactoring model classNamed: #FooTest. superClass := refactoring model classNamed: #RBRefactoringTest. classTest := refactoring model classNamed: self class name. self assert: newClass superclass = superClass. self assert: (superClass subclasses includes: newClass). self assert: newClass theMetaClass superclass = superClass theMetaClass. self assert: (superClass theMetaClass subclasses includes: newClass theMetaClass). self assert: classTest superclass = newClass. self assert: (newClass subclasses includes: classTest). self assert: classTest theMetaClass superclass = newClass theMetaClass. self assert: (newClass theMetaClass subclasses includes: classTest theMetaClass)! ! !RBAddClassTest methodsFor: 'failure tests' stamp: ''! testExistingName self shouldFail: (AddClassRefactoring addClass: #Object superclass: self class subclasses: #() category: #'Refactory-Testing')! ! !RBAddClassTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testInvalidSubclass self shouldFail: (AddClassRefactoring addClass: #Foo superclass: RBCompositeLintRuleTest subclasses: (Array with: RBBasicLintRuleTest) category: #'Refactory-Tesing')! ! !RBAddClassTest methodsFor: 'failure tests' stamp: ''! testMetaClassFailure self shouldFail: (AddClassRefactoring addClass: #Foo superclass: self class class subclasses: #() category: #'Refactory-Testing')! ! !RBAddClassTest methodsFor: 'tests' stamp: 'lr 10/26/2009 22:09'! testModelAddClass | refactoring newClass superClass subclass | subclass := model classNamed: #Bar. superClass := model classNamed: #Foo. refactoring := AddClassRefactoring model: model addClass: #FooTest superclass: superClass subclasses: (Array with: subclass) category: #'Refactory-Testing'. self executeRefactoring: refactoring. newClass := model classNamed: #FooTest. self assert: newClass superclass = superClass. self assert: (superClass subclasses includes: newClass). self assert: newClass theMetaClass superclass = superClass theMetaClass. self assert: (superClass theMetaClass subclasses includes: newClass theMetaClass). self assert: subclass superclass = newClass. self assert: (newClass subclasses includes: subclass). self assert: subclass theMetaClass superclass = newClass theMetaClass. self assert: (newClass theMetaClass subclasses includes: subclass theMetaClass)! ! !RBAddClassTest methodsFor: 'failure tests' stamp: ''! testModelExistingName | refactoring | refactoring := AddClassRefactoring model: model addClass: #Foo superclass: Object subclasses: #() category: #'Refactory-Testing'. self shouldFail: refactoring! ! !RBAddClassTest methodsFor: 'failure tests' stamp: ''! testModelInvalidSubclass | refactoring | refactoring := AddClassRefactoring model: model addClass: #Foo2 superclass: Object subclasses: (Array with: (model classNamed: #Bar)) category: #'Refactory-Tesing'. self shouldFail: refactoring! ! RBRefactoringTest subclass: #RBAddClassVariableTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBAddClassVariableTest methodsFor: 'set up' stamp: 'md 7/25/2005 15:17'! setUp super setUp. model := Compiler evaluate: self abstractVariableTestData.! ! !RBAddClassVariableTest methodsFor: 'tests' stamp: 'lr 2/26/2009 14:51'! testAddClassVariable | refactoring | refactoring := AddClassVariableRefactoring variable: 'Asdf' class: RBTransformationRuleTest. self executeRefactoring: refactoring. self assert: ((refactoring model classNamed: #RBTransformationRuleTest) directlyDefinesClassVariable: #Asdf)! ! !RBAddClassVariableTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testAlreadyExistingName self shouldFail: (AddClassVariableRefactoring variable: #RecursiveSelfRule class: RBTransformationRuleTest); shouldFail: (AddClassVariableRefactoring variable: self objectClassVariable class: RBTransformationRuleTest)! ! !RBAddClassVariableTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testMetaClassFailure self shouldFail: (AddClassVariableRefactoring variable: #VariableName class: RBTransformationRuleTest class)! ! !RBAddClassVariableTest methodsFor: 'failure tests' stamp: 'lr 10/26/2009 22:09'! testMetaclass | refactoring | refactoring := AddClassVariableRefactoring variable: #ClassVarName3 class: (model classNamed: #Object) theMetaClass. refactoring model: model. self shouldFail: refactoring! ! !RBAddClassVariableTest methodsFor: 'tests' stamp: ''! testModelAddClassVariable | refactoring | refactoring := AddClassVariableRefactoring model: model variable: #ClassVarName3 class: (model classNamed: #Bar). self executeRefactoring: refactoring. self assert: ((model classNamed: #Bar) directlyDefinesClassVariable: #ClassVarName3)! ! !RBAddClassVariableTest methodsFor: 'failure tests' stamp: ''! testModelAlreadyExistingName | refactoring | refactoring := AddClassVariableRefactoring model: model variable: #ClassVarName2 class: (model classNamed: #Bar). self shouldFail: refactoring! ! !RBAddClassVariableTest methodsFor: 'failure tests' stamp: 'lr 10/26/2009 22:09'! testModelMetaclass | refactoring | refactoring := AddClassVariableRefactoring model: model variable: #ClassVarName3 class: (model classNamed: #Bar) theMetaClass. self shouldFail: refactoring! ! RBRefactoringTest subclass: #RBAddInstanceVariableTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBAddInstanceVariableTest methodsFor: 'set up' stamp: 'md 7/25/2005 15:17'! setUp super setUp. model := Compiler evaluate: self abstractVariableTestData.! ! !RBAddInstanceVariableTest methodsFor: 'tests' stamp: 'lr 2/26/2009 14:51'! testAddInstanceVariable | refactoring | refactoring := AddInstanceVariableRefactoring variable: 'asdf' class: RBTransformationRuleTest. self executeRefactoring: refactoring. self assert: ((refactoring model classNamed: #RBTransformationRuleTest) directlyDefinesInstanceVariable: 'asdf')! ! !RBAddInstanceVariableTest methodsFor: 'tests' stamp: 'bh 11/8/2000 14:07'! testAddToModel | refactoring | model := RBNamespace new. model name: 'Add instance variable'. model defineClass: 'Object subclass: #FOOBAR instanceVariableNames: ''fdsa'' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''. refactoring := AddInstanceVariableRefactoring model: model variable: 'asdf' class: (model classNamed: #FOOBAR). self executeRefactoring: refactoring. self assert: ((refactoring model classNamed: #FOOBAR) directlyDefinesInstanceVariable: 'asdf')! ! !RBAddInstanceVariableTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testAlreadyExistingName self shouldFail: (AddInstanceVariableRefactoring variable: 'class' class: RBTransformationRuleTest); shouldFail: (AddInstanceVariableRefactoring variable: 'name' class: RBTransformationRuleTest)! ! !RBAddInstanceVariableTest methodsFor: 'failure tests' stamp: ''! testModelAlreadyExistingName | refactoring | refactoring := AddInstanceVariableRefactoring model: model variable: 'instVarName1' class: (model classNamed: #Bar). self shouldFail: refactoring! ! !RBAddInstanceVariableTest methodsFor: 'failure tests' stamp: ''! testModelMetaclassAlreadyExistingName | refactoring | (model metaclassNamed: #Foo) addInstanceVariable: 'instVarName1'. refactoring := AddInstanceVariableRefactoring model: model variable: 'instVarName1' class: (model classNamed: #Bar). self shouldFail: refactoring! ! !RBAddInstanceVariableTest methodsFor: 'failure tests' stamp: 'bh 11/8/2000 14:07'! testNewExistingName | refactoring | model := RBNamespace new. model name: 'Add instance variable'. model defineClass: 'Object subclass: #FOOBAR instanceVariableNames: ''asdf'' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''. refactoring := AddInstanceVariableRefactoring model: model variable: 'asdf' class: (model classNamed: #FOOBAR). self shouldFail: refactoring! ! !RBAddInstanceVariableTest methodsFor: 'failure tests' stamp: 'bh 11/8/2000 14:07'! testNewHierarchyExistingName | refactoring | model := RBNamespace new. model name: 'Add instance variable'. model defineClass: 'Object subclass: #FOOBAR instanceVariableNames: ''asdf'' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''. model defineClass: 'FOOBAR subclass: #BARFOO instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: ''Refactory-Test data'''. refactoring := AddInstanceVariableRefactoring model: model variable: 'asdf' class: (model classNamed: #BARFOO). self shouldFail: refactoring! ! RBRefactoringTest subclass: #RBAddMethodTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBAddMethodTest methodsFor: 'set up' stamp: 'md 7/25/2005 15:17'! setUp super setUp. model := Compiler evaluate: self abstractVariableTestData.! ! !RBAddMethodTest methodsFor: 'tests' stamp: 'lr 2/26/2009 14:51'! testAddMethod | refactoring | refactoring := AddMethodRefactoring addMethod: 'printString1 ^super printString' toClass: RBBasicLintRuleTest inProtocols: #(#accessing ). self executeRefactoring: refactoring. self assert: ((refactoring model classNamed: #RBBasicLintRuleTest) parseTreeFor: #printString1) = (RBParser parseMethod: 'printString1 ^super printString')! ! !RBAddMethodTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testBadMethod self shouldFail: (AddMethodRefactoring addMethod: 'asdf ^super ^printString' toClass: RBBasicLintRuleTest inProtocols: #(#accessing ))! ! !RBAddMethodTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testExistingSelector self shouldFail: (AddMethodRefactoring addMethod: 'printString ^super printString' toClass: RBBasicLintRuleTest inProtocols: #(#accessing ))! ! !RBAddMethodTest methodsFor: 'tests' stamp: ''! testModelAddMethod | refactoring class | class := model metaclassNamed: #Bar. refactoring := AddMethodRefactoring model: model addMethod: 'printString1 ^super printString' toClass: class inProtocols: #(#accessing). self executeRefactoring: refactoring. self assert: (class parseTreeFor: #printString1) = (RBParser parseMethod: 'printString1 ^super printString')! ! !RBAddMethodTest methodsFor: 'failure tests' stamp: ''! testModelExistingSelector | refactoring | refactoring := AddMethodRefactoring model: model addMethod: 'classVarName1 ^super printString' toClass: (model classNamed: #Bar) inProtocols: #(#accessing). self shouldFail: refactoring! ! !RBAddMethodTest methodsFor: 'failure tests' stamp: ''! testModelInheritedSelector | refactoring | refactoring := AddMethodRefactoring model: model addMethod: 'printString ^super printString' toClass: (model classNamed: #Bar) inProtocols: #(#accessing). self shouldFail: refactoring! ! RBRefactoringTest subclass: #RBAddParameterTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBAddParameterTest methodsFor: 'set up' stamp: 'md 7/25/2005 15:17'! setUp super setUp. model := Compiler evaluate: self abstractVariableTestData.! ! !RBAddParameterTest methodsFor: 'tests' stamp: 'lr 2/26/2009 15:07'! testAddParameterForTwoArgumentMessage | refactoring class | refactoring := AddParameterRefactoring addParameterToMethod: ('called:' , 'on:') asSymbol in: RBRefactoryTestDataApp newSelector: #called:bar:on: initializer: '#(1.0)'. self executeRefactoring: refactoring. class := refactoring model classNamed: #RBRefactoryTestDataApp. self assert: (class parseTreeFor: #called:bar:on:) = (RBParser parseMethod: 'called: anObject bar: aBlock on: anObject1 Transcript show: anObject printString; cr. aBlock value'). self assert: (class parseTreeFor: #caller) = (RBParser parseMethod: 'caller | anObject | anObject := 5. self called: anObject + 1 bar: [^anObject] on: #(1.0)'). self deny: (class directlyDefinesMethod: ('called:' , 'on:') asSymbol)! ! !RBAddParameterTest methodsFor: 'tests' stamp: 'lr 2/26/2009 15:07'! testAddParameterThatReferencesGlobalAndLiteral | refactoring class | refactoring := AddParameterRefactoring addParameterToMethod: ('test' , 'Foo:') asSymbol in: RBRefactoryTestDataApp newSelector: #testFoo:bar: initializer: 'OrderedCollection new: 5'. self executeRefactoring: refactoring. class := refactoring model classNamed: #RBRefactoryTestDataApp. self assert: (class parseTreeFor: #testFoo:bar:) = (RBParser parseMethod: 'testFoo: anObject bar: anObject1 ^self class + anObject'). self assert: (class parseTreeFor: #callFoo) = (RBParser parseMethod: 'callFoo ^self testFoo: 5 bar: (OrderedCollection new: 5)'). self deny: (class directlyDefinesMethod: ('test' , 'Foo:') asSymbol)! ! !RBAddParameterTest methodsFor: 'tests' stamp: 'lr 2/26/2009 15:07'! testAddParameterThatReferencesModelGlobal | refactoring class | refactoring := AddParameterRefactoring model: model addParameterToMethod: ('test' , 'Foo:') asSymbol in: RBRefactoryTestDataApp newSelector: #testFoo:bar: initializer: 'Bar new'. self executeRefactoring: refactoring. class := refactoring model classNamed: #RBRefactoryTestDataApp. self assert: (class parseTreeFor: #testFoo:bar:) = (RBParser parseMethod: 'testFoo: anObject bar: anObject1 ^self class + anObject'). self assert: (class parseTreeFor: #callFoo) = (RBParser parseMethod: 'callFoo ^self testFoo: 5 bar: (Bar new)'). self deny: (class directlyDefinesMethod: ('test' , 'Foo:') asSymbol)! ! !RBAddParameterTest methodsFor: 'tests' stamp: 'lr 2/26/2009 15:07'! testAddParameterThatReferencesSelf | refactoring class | refactoring := AddParameterRefactoring addParameterToMethod: ('test' , 'Foo:') asSymbol in: RBRefactoryTestDataApp newSelector: #testFoo:bar: initializer: 'self printString'. self executeRefactoring: refactoring. class := refactoring model classNamed: #RBRefactoryTestDataApp. self assert: (class parseTreeFor: #testFoo:bar:) = (RBParser parseMethod: 'testFoo: anObject bar: anObject1 ^self class + anObject'). self assert: (class parseTreeFor: #callFoo) = (RBParser parseMethod: 'callFoo ^self testFoo: 5 bar: (self printString)'). self deny: (class directlyDefinesMethod: ('test' , 'Foo:') asSymbol)! ! !RBAddParameterTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testBadInitializationCode self shouldFail: (AddParameterRefactoring addParameterToMethod: #name in: RBLintRuleTest newSelector: #name: initializer: 'foo:'); shouldFail: (AddParameterRefactoring addParameterToMethod: #name in: RBLintRuleTest newSelector: #name: initializer: 'foo')! ! !RBAddParameterTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testModelBadInitializationCode | refactoring | model removeClassNamed: #Refactoring. refactoring := AddParameterRefactoring model: model addParameterToMethod: #name1 in: RBLintRuleTest newSelector: #name1: initializer: 'AddParameterRefactoring new'. self shouldFail: refactoring! ! !RBAddParameterTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testModelNonExistantName | refactoring | (model classNamed: #RBLintRuleTest) removeMethod: #name. refactoring := AddParameterRefactoring model: model addParameterToMethod: #name in: RBLintRuleTest newSelector: #nameNew: initializer: 'nil'. self shouldFail: refactoring! ! !RBAddParameterTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testNonExistantName self shouldFail: (AddParameterRefactoring addParameterToMethod: #name1 in: RBLintRuleTest newSelector: #name1: initializer: 'nil')! ! !RBAddParameterTest methodsFor: 'failure tests' stamp: ''! testPrimitiveMethods | refactoring | (model classNamed: #Object) compile: 'foo ^#() primitiveFailed' classified: #(#accessing). refactoring := AddParameterRefactoring model: model addParameterToMethod: #foo in: Object newSelector: #foo123124321s: initializer: '1'. self shouldFail: refactoring. refactoring := AddParameterRefactoring addParameterToMethod: #at: in: Object newSelector: #at:foo: initializer: '1'. self shouldFail: refactoring. ! ! RBRefactoringTest subclass: #RBChildrenToSiblingsTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBChildrenToSiblingsTest methodsFor: 'set up' stamp: 'lr 2/26/2009 16:47'! setUp super setUp. model := Compiler evaluate: self childrenToSiblingTestData! ! !RBChildrenToSiblingsTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testBadName self shouldFail: (ChildrenToSiblingsRefactoring name: #'Obje ct' class: RBLintRuleTest subclasses: (Array with: RBBasicLintRuleTest with: RBCompositeLintRuleTest))! ! !RBChildrenToSiblingsTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testExistingName self shouldFail: (ChildrenToSiblingsRefactoring name: #Object class: RBLintRuleTest subclasses: (Array with: RBBasicLintRuleTest with: RBCompositeLintRuleTest)); shouldFail: (ChildrenToSiblingsRefactoring name: #Processor class: RBLintRuleTest subclasses: (Array with: RBBasicLintRuleTest with: RBCompositeLintRuleTest))! ! !RBChildrenToSiblingsTest methodsFor: 'failure tests' stamp: 'lr 9/4/2010 17:27'! testInvalidSubclass self shouldFail: (ChildrenToSiblingsRefactoring name: #Foo class: RBLintRuleTest subclasses: (Array with: RBBasicLintRuleTest with: RBCompositeLintRuleTest))! ! !RBChildrenToSiblingsTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testMetaClassFailure self shouldFail: (ChildrenToSiblingsRefactoring name: #Foo class: RBLintRuleTest class subclasses: (Array with: RBBasicLintRuleTest class with: RBCompositeLintRuleTest class))! ! !RBChildrenToSiblingsTest methodsFor: 'tests' stamp: 'lr 10/26/2009 22:09'! testModelChildrenToSibling | refactoring class subclass superclass | class := model classNamed: #ConcreteSuperclass. subclass := model classNamed: #ConcreteSubclass. refactoring := ChildrenToSiblingsRefactoring model: model name: #AbstractSuperclass class: class subclasses: (Array with: subclass). self executeRefactoring: refactoring. superclass := refactoring model classNamed: #AbstractSuperclass. self assert: class superclass = superclass. self assert: class theMetaClass superclass = superclass theMetaClass. self assert: subclass superclass = superclass. self assert: subclass theMetaClass superclass = superclass theMetaClass. self assert: (superclass parseTreeFor: #same) = (RBParser parseMethod: 'same ^self initialize isKindOf: AbstractSuperclass'). self assert: (superclass parseTreeFor: #different) = (RBParser parseMethod: 'different self subclassResponsibility'). self assert: (superclass parseTreeFor: #initialize) = (RBParser parseMethod: 'initialize instVarName1 := instVarName2 := ClassVarName1 := ClassVarName2 := 0'). self assert: (superclass directlyDefinesInstanceVariable: 'instVarName1'). self assert: (superclass directlyDefinesInstanceVariable: 'instVarName2'). self assert: (superclass directlyDefinesClassVariable: 'ClassVarName1'). self assert: (superclass directlyDefinesClassVariable: 'ClassVarName2'). self assert: (superclass theMetaClass directlyDefinesInstanceVariable: 'classInstVarName1'). self assert: (superclass theMetaClass parseTreeFor: #foo) = (RBParser parseMethod: 'foo ^classInstVarName1 + ClassVarName1 + ClassVarName2'). self assert: (superclass theMetaClass parseTreeFor: #new) = (RBParser parseMethod: 'new ^super new initialize'). self assert: (superclass theMetaClass parseTreeFor: #bar) = (RBParser parseMethod: 'bar self subclassResponsibility'). self deny: (class directlyDefinesInstanceVariable: 'instVarName1'). self deny: (class directlyDefinesInstanceVariable: 'instVarName2'). self deny: (class directlyDefinesClassVariable: 'ClassVarName1'). self deny: (class directlyDefinesClassVariable: 'ClassVarName2'). self deny: (class theMetaClass directlyDefinesInstanceVariable: 'classInstVarName1'). self deny: (class directlyDefinesMethod: #same). self deny: (class directlyDefinesMethod: #initialize). self deny: (class theMetaClass directlyDefinesMethod: #new). self assert: (class parseTreeFor: #different) = (RBParser parseMethod: 'different ^instVarName1 + instVarName2'). self assert: (class theMetaClass parseTreeFor: #bar) = (RBParser parseMethod: 'bar ^self printString')! ! RBRefactoringTest subclass: #RBCreateAccessorsForVariableTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBCreateAccessorsForVariableTest methodsFor: 'set up' stamp: 'md 7/25/2005 15:17'! setUp super setUp. model := Compiler evaluate: self abstractVariableTestData.! ! !RBCreateAccessorsForVariableTest methodsFor: 'tests' stamp: 'lr 2/26/2009 14:51'! testExistingInstanceVariableAccessors | ref | ref := CreateAccessorsForVariableRefactoring variable: 'name' class: RBLintRuleTest classVariable: false. self executeRefactoring: ref. self assert: ref changes changes isEmpty. self assert: ref setterMethod == #name:. self assert: ref getterMethod == #name! ! !RBCreateAccessorsForVariableTest methodsFor: 'tests' stamp: 'lr 2/26/2009 14:51'! testNewClassVariableAccessors | ref class | ref := CreateAccessorsForVariableRefactoring variable: 'Foo1' class: RBLintRuleTest classVariable: true. self executeRefactoring: ref. class := ref model metaclassNamed: #RBLintRuleTest. self deny: ref changes changes isEmpty. self assert: ref setterMethod == #foo1:. self assert: ref getterMethod == #foo1. self assert: (class parseTreeFor: #foo1) = (RBParser parseMethod: 'foo1 ^Foo1'). self assert: (class parseTreeFor: #foo1:) = (RBParser parseMethod: 'foo1: anObject Foo1 := anObject')! ! !RBCreateAccessorsForVariableTest methodsFor: 'tests' stamp: 'lr 2/26/2009 14:51'! testNewInstanceVariableAccessors | ref class | ref := CreateAccessorsForVariableRefactoring variable: 'foo1' class: RBLintRuleTest classVariable: false. self executeRefactoring: ref. class := ref model classNamed: #RBLintRuleTest. self deny: ref changes changes isEmpty. self assert: ref setterMethod == #foo1:. self assert: ref getterMethod == #foo1. self assert: (class parseTreeFor: #foo1) = (RBParser parseMethod: 'foo1 ^foo1'). self assert: (class parseTreeFor: #foo1:) = (RBParser parseMethod: 'foo1: anObject foo1 := anObject')! ! !RBCreateAccessorsForVariableTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testNonExistantName self shouldFail: (CreateAccessorsForVariableRefactoring variable: #Foo class: RBBasicLintRuleTest classVariable: true); shouldFail: (CreateAccessorsForVariableRefactoring variable: 'foo' class: RBBasicLintRuleTest classVariable: true)! ! RBRefactoringTest subclass: #RBExtractMethodTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBExtractMethodTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 15:07'! testBadInterval self shouldFail: (ExtractMethodRefactoring extract: (self convertInterval: (24 to: 30) for: (RBRefactoryTestDataApp sourceCodeAt: #testMethod)) from: #testMethod in: RBRefactoryTestDataApp); shouldFail: (ExtractMethodRefactoring extract: (self convertInterval: (80 to: 147) for: (RBBasicLintRuleTest class sourceCodeAt: #subclassOf:overrides:)) from: #subclassOf:overrides: in: RBBasicLintRuleTest class)! ! !RBExtractMethodTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testExtractFailure self shouldFail: (ExtractMethodRefactoring extract: (self convertInterval: (80 to: 269) for: (RBBasicLintRuleTest class sourceCodeAt: #subclassOf:overrides:)) from: #subclassOf:overrides: in: RBBasicLintRuleTest class); shouldFail: (ExtractMethodRefactoring extract: (self convertInterval: (53 to: 56) for: (RBBasicLintRuleTest class sourceCodeAt: #subclassOf:overrides:)) from: #subclassOf:overrides: in: RBBasicLintRuleTest class); shouldFail: (ExtractMethodRefactoring extract: (self convertInterval: (77 to: 222) for: (RBBasicLintRuleTest class sourceCodeAt: #subclassResponsibilityNotDefined)) from: #subclassResponsibilityNotDefined in: RBBasicLintRuleTest class)! ! !RBExtractMethodTest methodsFor: 'tests' stamp: 'TestRunner 11/3/2009 09:18'! testExtractMethodAtEndOfMethodThatNeedsReturn | refactoring class | refactoring := ExtractMethodRefactoring extract: (self convertInterval: (52 to: 133) for: (RBLintRuleTest sourceCodeAt: #openEditor)) from: #openEditor in: RBLintRuleTest. self setupMethodNameFor: refactoring toReturn: #foo:. self executeRefactoring: refactoring. class := refactoring model classNamed: #RBLintRuleTest. self assert: (class parseTreeFor: #openEditor) = (RBParser parseMethod: 'openEditor | rules | rules := self failedRules. ^self foo: rules'). self assert: (class parseTreeFor: #foo:) = (RBParser parseMethod: 'foo: rules rules isEmpty ifTrue: [^self]. rules size == 1 ifTrue: [^rules first viewResults]')! ! !RBExtractMethodTest methodsFor: 'tests' stamp: 'lr 11/2/2009 00:15'! testExtractMethodThatMovesTemporaryVariable | refactoring class | refactoring := ExtractMethodRefactoring extract: (self convertInterval: (22 to: 280) for: (RBTransformationRuleTest sourceCodeAt: #superSends)) from: #superSends in: RBTransformationRuleTest. self setupMethodNameFor: refactoring toReturn: #foo. self executeRefactoring: refactoring. class := refactoring model classNamed: #RBTransformationRuleTest. self assert: (class parseTreeFor: #superSends) = (RBParser parseMethod: 'superSends | rule | rule := self foo. self rewriteUsing: rule'). self assert: (class parseTreeFor: #foo) = (RBParser parseMethod: 'foo | rule | rule := RBParseTreeRewriter new. rule addSearch: ''super `@message: ``@args'' -> ( [:aNode | (class withAllSubclasses detect: [:each | each includesSelector: aNode selector] ifNone: [nil]) isNil] -> ''self `@message: ``@args''). ^rule')! ! !RBExtractMethodTest methodsFor: 'tests' stamp: 'lr 2/26/2009 14:51'! testExtractMethodThatNeedsArgument | refactoring class | refactoring := ExtractMethodRefactoring extract: (self convertInterval: (145 to: 343) for: (RBTransformationRuleTest sourceCodeAt: #checkMethod:)) from: #checkMethod: in: RBTransformationRuleTest. self setupMethodNameFor: refactoring toReturn: #foo:. self executeRefactoring: refactoring. class := refactoring model classNamed: #RBTransformationRuleTest. self assert: (class parseTreeFor: #checkMethod:) = (RBParser parseMethod: 'checkMethod: aSmalllintContext class := aSmalllintContext selectedClass. (rewriteRule executeTree: aSmalllintContext parseTree) ifTrue: [self foo: aSmalllintContext]'). self assert: (class parseTreeFor: #foo:) = (RBParser parseMethod: 'foo: aSmalllintContext (RecursiveSelfRule executeTree: rewriteRule tree initialAnswer: false) ifFalse: [builder compile: rewriteRule tree printString in: class classified: aSmalllintContext protocols]')! ! !RBExtractMethodTest methodsFor: 'tests' stamp: 'lr 2/26/2009 14:51'! testExtractMethodThatNeedsTemporaryVariable | refactoring class | refactoring := ExtractMethodRefactoring extract: (self convertInterval: (78 to: 197) for: (RBLintRuleTest sourceCodeAt: #displayName)) from: #displayName in: RBLintRuleTest. self setupMethodNameFor: refactoring toReturn: #foo:. self executeRefactoring: refactoring. class := refactoring model classNamed: #RBLintRuleTest. self assert: (class parseTreeFor: #displayName) = (RBParser parseMethod: 'displayName | nameStream | nameStream := WriteStream on: (String new: 64). self foo: nameStream. ^nameStream contents'). self assert: (class parseTreeFor: #foo:) = (RBParser parseMethod: 'foo: nameStream nameStream nextPutAll: self name; nextPutAll: '' (''. self problemCount printOn: nameStream. nameStream nextPut: $).')! ! !RBExtractMethodTest methodsFor: 'tests' stamp: ''! testModelExtractMethodWithTemporariesSelected | class refactoring | model := RBNamespace new. class := model classNamed: self class name. class compile: 'foo [| temp | temp := 5. temp * temp] value' classified: #(#accessing). refactoring := ExtractMethodRefactoring model: model extract: (6 to: 36) from: #foo in: class. self setupMethodNameFor: refactoring toReturn: #foobar. self executeRefactoring: refactoring. self assert: (class parseTreeFor: #foo) = (RBParser parseMethod: 'foo [self foobar] value'). self assert: (class parseTreeFor: #foobar) = (RBParser parseMethod: 'foobar |temp | temp := 5. ^temp * temp')! ! !RBExtractMethodTest methodsFor: 'tests' stamp: 'bh 9/16/2001 21:06'! testModelExtractMethodWithTemporaryAssigned | class refactoring | model := RBNamespace new. class := model classNamed: self class name. class compile: 'foo | temp bar | bar := 5. temp := bar * bar. Transcript show: temp printString; cr. ^temp * temp' classified: #(#accessing). refactoring := ExtractMethodRefactoring model: model extract: (26 to: 102) from: #foo in: class. self setupMethodNameFor: refactoring toReturn: #foobar. self executeRefactoring: refactoring. self assert: (class parseTreeFor: #foo) = (RBParser parseMethod: 'foo | temp | temp := self foobar. ^temp * temp'). self assert: ((class parseTreeFor: #foobar) = (RBParser parseMethod: 'foobar | bar temp | bar := 5. temp := bar * bar. Transcript show: temp printString; cr. ^temp.')) | ((class parseTreeFor: #foobar) = (RBParser parseMethod: 'foobar | temp bar | bar := 5. temp := bar * bar. Transcript show: temp printString; cr. ^temp.'))! ! !RBExtractMethodTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testNonExistantSelector self shouldFail: (ExtractMethodRefactoring extract: (10 to: 20) from: #checkClass1: in: RBBasicLintRuleTest)! ! RBRefactoringTest subclass: #RBExtractMethodToComponentTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBExtractMethodToComponentTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 15:07'! testBadInterval self shouldFail: (ExtractMethodToComponentRefactoring extract: (self convertInterval: (24 to: 30) for: (RBRefactoryTestDataApp sourceCodeAt: #testMethod)) from: #testMethod in: RBRefactoryTestDataApp); shouldFail: (ExtractMethodToComponentRefactoring extract: (self convertInterval: (80 to: 147) for: (RBBasicLintRuleTest class sourceCodeAt: #subclassOf:overrides:)) from: #subclassOf:overrides: in: RBBasicLintRuleTest class)! ! !RBExtractMethodToComponentTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testExtractFailure self shouldFail: (ExtractMethodToComponentRefactoring extract: (self convertInterval: (80 to: 269) for: (RBBasicLintRuleTest class sourceCodeAt: #subclassOf:overrides:)) from: #subclassOf:overrides: in: RBBasicLintRuleTest class); shouldFail: (ExtractMethodToComponentRefactoring extract: (self convertInterval: (53 to: 56) for: (RBBasicLintRuleTest class sourceCodeAt: #subclassOf:overrides:)) from: #subclassOf:overrides: in: RBBasicLintRuleTest class); shouldFail: (ExtractMethodToComponentRefactoring extract: (self convertInterval: (77 to: 222) for: (RBBasicLintRuleTest class sourceCodeAt: #subclassResponsibilityNotDefined)) from: #subclassResponsibilityNotDefined in: RBBasicLintRuleTest class)! ! !RBExtractMethodToComponentTest methodsFor: 'tests' stamp: 'TestRunner 11/3/2009 09:17'! testExtractMethodAtEndOfMethodThatNeedsReturn | refactoring class selectorsSize | refactoring := ExtractMethodToComponentRefactoring extract: (self convertInterval: (52 to: 133) for: (RBLintRuleTest sourceCodeAt: #openEditor)) from: #openEditor in: RBLintRuleTest. self setupMethodNameFor: refactoring toReturn: #foo:. self setupSelfArgumentNameFor: refactoring toReturn: 'asdf'. self setupVariableToMoveToFor: refactoring toReturn: 'rules'. self setupVariableTypesFor: refactoring toReturn: (Array with: (refactoring model classNamed: #Collection)). class := refactoring model classNamed: #RBLintRuleTest. selectorsSize := class selectors size. self proceedThroughWarning: [ self executeRefactoring: refactoring ]. self assert: (class parseTreeFor: #openEditor) = (RBParser parseMethod: 'openEditor | rules | rules := self failedRules. ^rules foo: self'). self assert: ((refactoring model classNamed: #Collection) parseTreeFor: #foo:) = (RBParser parseMethod: 'foo: asdf self isEmpty ifTrue: [^asdf]. self size == 1 ifTrue: [^self first viewResults]. ^asdf'). self assert: class selectors size = selectorsSize! ! !RBExtractMethodToComponentTest methodsFor: 'tests' stamp: 'TestRunner 11/3/2009 09:13'! testMoveWithoutSelfReference | refactoring class selectorsSize | refactoring := ExtractMethodToComponentRefactoring extract: (self convertInterval: (118 to: 286) for: (RBReadBeforeWrittenTester sourceCodeAt: #copyDictionary:)) from: #copyDictionary: in: RBReadBeforeWrittenTester. self setupMethodNameFor: refactoring toReturn: #copyWithAssociations. self setupVariableToMoveToFor: refactoring toReturn: 'aDictionary'. self setupVariableTypesFor: refactoring toReturn: (Array with: (refactoring model classNamed: #Dictionary)). class := refactoring model classNamed: #RBReadBeforeWrittenTester. selectorsSize := class selectors size. self executeRefactoring: refactoring. self assert: (class parseTreeFor: #copyDictionary:) = (RBParser parseMethod: 'copyDictionary: aDictionary ^aDictionary copyWithAssociations'). self assert: ((refactoring model classNamed: #Dictionary) parseTreeFor: #copyWithAssociations) = (RBParser parseMethod: 'copyWithAssociations | newDictionary | newDictionary := Dictionary new: self size. self keysAndValuesDo: [:key :value | newDictionary at: key put: value]. ^newDictionary'). self assert: class selectors size = selectorsSize! ! !RBExtractMethodToComponentTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testNonExistantSelector self shouldFail: (ExtractMethodToComponentRefactoring extract: (10 to: 20) from: #checkClass1: in: RBBasicLintRuleTest)! ! RBRefactoringTest subclass: #RBExtractToTemporaryTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBExtractToTemporaryTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 15:07'! testBadInterval self shouldFail: (ExtractToTemporaryRefactoring extract: (self convertInterval: (24 to: 30) for: (RBRefactoryTestDataApp sourceCodeAt: #testMethod)) to: 'asdf' from: #testMethod in: RBRefactoryTestDataApp); shouldFail: (ExtractToTemporaryRefactoring extract: (self convertInterval: (14 to: 105) for: (RBRefactoryTestDataApp sourceCodeAt: #testMethod1)) to: 'asdf' from: #testMethod1 in: RBRefactoryTestDataApp); shouldFail: (ExtractToTemporaryRefactoring extract: (self convertInterval: (61 to: 101) for: (RBRefactoryTestDataApp sourceCodeAt: #noMoveDefinition)) to: 'asdf' from: #noMoveDefinition in: RBRefactoryTestDataApp)! ! !RBExtractToTemporaryTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 15:07'! testBadName self shouldFail: (ExtractToTemporaryRefactoring extract: (self convertInterval: (14 to: 23) for: (RBRefactoryTestDataApp sourceCodeAt: #testMethod)) to: 'a sdf' from: #testMethod in: RBRefactoryTestDataApp)! ! !RBExtractToTemporaryTest methodsFor: 'tests' stamp: 'lr 2/26/2009 15:07'! testExtractToTemporaryForLastStatementInBlock | refactoring | refactoring := ExtractToTemporaryRefactoring extract: (self convertInterval: (52 to: 73) for: (RBRefactoryTestDataApp sourceCodeAt: #caller2)) to: 'temp' from: #caller2 in: RBRefactoryTestDataApp. self executeRefactoring: refactoring. self assert: ((refactoring model classNamed: #RBRefactoryTestDataApp) parseTreeFor: #caller2) = (RBParser parseMethod: 'caller2 ^(1 to: 10) inject: 1 into: [:sum :each | | temp | temp := sum * (self foo: each). temp]')! ! !RBExtractToTemporaryTest methodsFor: 'tests' stamp: 'lr 2/26/2009 15:07'! testExtractToTemporaryInsideBlock | refactoring | refactoring := ExtractToTemporaryRefactoring extract: (self convertInterval: (133 to: 141) for: (RBRefactoryTestDataApp sourceCodeAt: #noMoveDefinition)) to: 'asdf' from: #noMoveDefinition in: RBRefactoryTestDataApp. self executeRefactoring: refactoring. self assert: ((refactoring model classNamed: #RBRefactoryTestDataApp) parseTreeFor: #noMoveDefinition) = (RBParser parseMethod: 'noMoveDefinition | temp | ^(self collect: [:each | temp := each printString. temp , temp]) select: [:each | | asdf | asdf := each size. temp := asdf + temp]')! ! !RBExtractToTemporaryTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 15:07'! testNonExistantSelector self shouldFail: (ExtractToTemporaryRefactoring extract: (14 to: 23) to: 'asdf' from: #checkClass1: in: RBRefactoryTestDataApp)! ! RBRefactoringTest subclass: #RBInlineAllMethodTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBInlineAllMethodTest methodsFor: 'tests' stamp: 'lr 2/26/2009 15:07'! testInlineMethodWithMultipleSendersInMethod | refactoring | refactoring := InlineAllSendersRefactoring sendersOf: #caller2 in: RBRefactoryTestDataApp. self executeRefactoring: refactoring. self assert: ((refactoring model classNamed: #RBRefactoryTestDataApp) parseTreeFor: #inlineLast) = (RBParser parseMethod: 'inlineLast 5 = 3 ifTrue: [^self caller] ifFalse: [^(1 to: 10) inject: 1 into: [:sum :each | sum * (self foo: each)]] '). self assert: ((refactoring model classNamed: #RBRefactoryTestDataApp) parseTreeFor: #multipleCalls) = (RBParser parseMethod: 'multipleCalls (1 to: 10) inject: 1 into: [:sum :each | sum * (self foo: each)]. (1 to: 10) inject: 1 into: [:sum1 :each1 | sum1 * (self foo: each1)]')! ! !RBInlineAllMethodTest methodsFor: 'tests' stamp: ''! testRecursiveMethod | class | model := RBNamespace new. class := model classNamed: self class name. class compile: 'foo ^self foo' classified: #(#accessing); compile: 'bar ^self foo' classified: #(#accessing). self executeRefactoring: (InlineAllSendersRefactoring model: model sendersOf: #foo in: class). self assert: (class parseTreeFor: #foo) = (RBParser parseMethod: 'foo ^self foo'). self assert: (class parseTreeFor: #bar) = (RBParser parseMethod: 'bar ^self foo')! ! RBRefactoringTest subclass: #RBInlineMethodFromComponentTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBInlineMethodFromComponentTest methodsFor: 'tests' stamp: 'lr 2/26/2009 15:07'! testInlineComponentIntoCascadedMessage | refactoring | self proceedThroughWarning: [ refactoring := InlineMethodFromComponentRefactoring inline: (self convertInterval: (35 to: 79) for: (RBRefactoryTestDataApp sourceCodeAt: #inlineComponent)) inMethod: #inlineComponent forClass: RBRefactoryTestDataApp. (refactoring model classNamed: #Behavior) compile: 'hasImmediateInstances ^self format = 0' classified: #(#accessing ). self setupInlineExpressionFor: refactoring toReturn: false. self executeRefactoring: refactoring ]. self assert: ((refactoring model classNamed: #RBRefactoryTestDataApp) parseTreeFor: #inlineComponent) = (RBParser parseMethod: 'inlineComponent | a aBehavior | a := 5. aBehavior := a class. aBehavior superclass. aBehavior format = 0. ^aBehavior yourself')! ! !RBInlineMethodFromComponentTest methodsFor: 'tests' stamp: 'lr 2/26/2009 15:07'! testInlineComponentMethodMax | refactoring | self proceedThroughWarning: [ | class | refactoring := InlineMethodFromComponentRefactoring inline: (self convertInterval: (47 to: 58) for: (RBRefactoryTestDataApp sourceCodeAt: #inlineMax)) inMethod: #inlineMax forClass: RBRefactoryTestDataApp. self setupInlineExpressionFor: refactoring toReturn: true. class := refactoring model classNamed: #Magnitude. class compile: 'max: aMagnitude "Answer the receiver or the argument, whichever has the greater magnitude." self > aMagnitude ifTrue: [^self] ifFalse: [^aMagnitude]' classified: #(#accessing ). self setupImplementorToInlineFor: refactoring toReturn: class. self executeRefactoring: refactoring ]. self assert: ((refactoring model classNamed: #RBRefactoryTestDataApp) parseTreeFor: #inlineMax) = (RBParser parseMethod: 'inlineMax | x y q | x := 5. y := 10. q := x + 1 > y ifTrue: [x + 1] ifFalse: [y]. ^q')! ! !RBInlineMethodFromComponentTest methodsFor: 'tests' stamp: 'lr 2/26/2009 15:07'! testInlineEmptyComponentMethod | refactoring | self proceedThroughWarning: [ refactoring := InlineMethodFromComponentRefactoring inline: (self convertInterval: (35 to: 91) for: (RBRefactoryTestDataApp sourceCodeAt: #inlineComponent)) inMethod: #inlineComponent forClass: RBRefactoryTestDataApp. self setupInlineExpressionFor: refactoring toReturn: false. self executeRefactoring: refactoring ]. self assert: ((refactoring model classNamed: #RBRefactoryTestDataApp) parseTreeFor: #inlineComponent) = (RBParser parseMethod: 'inlineComponent | a anObject | a := 5. anObject := a class. anObject superclass. anObject hasImmediateInstances. ^anObject')! ! !RBInlineMethodFromComponentTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 15:07'! testInlineMethodFromComponentFailure self shouldFail: (InlineMethodFromComponentRefactoring inline: (self convertInterval: (50 to: 64) for: (RBRefactoryTestDataApp sourceCodeAt: #inlineFailed)) inMethod: #inlineFailed forClass: RBRefactoryTestDataApp)! ! !RBInlineMethodFromComponentTest methodsFor: 'tests' stamp: ''! testModelInlineMethodWithSameVariableNames | class refactoring | model := RBNamespace new. class := model classNamed: self class name. class compile: 'a9: a b9: b ^self + a + b' classified: #(#accessing). (model classNamed: #Object) compile: 'foo | a b c | a := InlineMethodFromComponentTest new. b := 1. c := 2. ^a a9: b b9: c' classified: #(#accessing). self proceedThroughWarning: [refactoring := InlineMethodFromComponentRefactoring model: model inline: (72 to: 84) inMethod: #foo forClass: (model classNamed: #Object). self setupInlineExpressionFor: refactoring toReturn: false. self executeRefactoring: refactoring]. self assert: ((refactoring model classNamed: #Object) parseTreeFor: #foo) = (RBParser parseMethod: 'foo | a b c | a := InlineMethodFromComponentTest new. b := 1. c := 2. ^a + b + c')! ! !RBInlineMethodFromComponentTest methodsFor: 'tests' stamp: ''! testModelInlineMethodWithSameVariableNames1 | class refactoring | model := RBNamespace new. class := model classNamed: #Rectangle. class compile: 'rectangleRelativeTo: aRectangle ^self origin extent: aRectangle extent' classified: #(#accessing). (model classNamed: #Object) compile: 'foo | aRectangle temp | aRectangle := 0@0 corner: 1@1. temp := aRectangle. ^aRectangle rectangleRelativeTo: temp' classified: #(#accessing). self proceedThroughWarning: [refactoring := InlineMethodFromComponentRefactoring model: model inline: (77 to: 112) inMethod: #foo forClass: (model classNamed: #Object). self setupInlineExpressionFor: refactoring toReturn: false. self setupImplementorToInlineFor: refactoring toReturn: class. self executeRefactoring: refactoring]. self assert: ((refactoring model classNamed: #Object) parseTreeFor: #foo) = (RBParser parseMethod: 'foo | aRectangle temp | aRectangle := 0@0 corner: 1@1. temp := aRectangle. ^aRectangle origin extent: temp extent')! ! !RBInlineMethodFromComponentTest methodsFor: 'tests' stamp: ''! testModelInlineMethodWithSameVariableNames2 | class refactoring | model := RBNamespace new. class := model classNamed: self class name. class compile: 'a9: a b9: b ^self + a + b' classified: #(#accessing). (model classNamed: #Object) compile: 'foo | a b c | a := InlineMethodFromComponentTest new. b := 1. c := 2. ^c a9: b b9: a' classified: #(#accessing). self proceedThroughWarning: [refactoring := InlineMethodFromComponentRefactoring model: model inline: (72 to: 84) inMethod: #foo forClass: (model classNamed: #Object). self setupInlineExpressionFor: refactoring toReturn: false. self executeRefactoring: refactoring]. self assert: ((refactoring model classNamed: #Object) parseTreeFor: #foo) = (RBParser parseMethod: 'foo | a b c | a := InlineMethodFromComponentTest new. b := 1. c := 2. ^c + b + a')! ! RBRefactoringTest subclass: #RBInlineMethodTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBInlineMethodTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 15:07'! testBadInterval self shouldFail: (InlineMethodRefactoring inline: (self convertInterval: (13 to: 23) for: (RBRefactoryTestDataApp sourceCodeAt: #testMethod)) inMethod: #testMethod forClass: RBRefactoryTestDataApp); shouldFail: (InlineMethodRefactoring inline: (self convertInterval: (14 to: 17) for: (RBRefactoryTestDataApp sourceCodeAt: #testMethod)) inMethod: #testMethod forClass: RBRefactoryTestDataApp); shouldFail: (InlineMethodRefactoring inline: (self convertInterval: (24 to: 30) for: (RBRefactoryTestDataApp sourceCodeAt: #testMethod)) inMethod: #testMethod forClass: RBRefactoryTestDataApp); shouldFail: (InlineMethodRefactoring inline: (self convertInterval: (1 to: 30) for: (RBRefactoryTestDataApp sourceCodeAt: #testMethod)) inMethod: #testMethod forClass: RBRefactoryTestDataApp)! ! !RBInlineMethodTest methodsFor: 'tests' stamp: 'lr 2/26/2009 14:51'! testInlineMethod | refactoring | refactoring := InlineMethodRefactoring inline: (self convertInterval: (455 to: 504) for: (RBBasicLintRuleTest class sourceCodeAt: #sentNotImplementedInApplication)) inMethod: #sentNotImplementedInApplication forClass: RBBasicLintRuleTest class. self executeRefactoring: refactoring. self assert: ((refactoring model metaclassNamed: #RBBasicLintRuleTest) parseTreeFor: #sentNotImplementedInApplication) = (RBParser parseMethod: 'sentNotImplementedInApplication | detector | detector := self new. detector name: ''Messages sent but not implemented in application''. detector methodBlock: [:context :result | | message class block | message := context messages detect: [:each | (context isItem: each in: context application) not] ifNone: [nil]. class := context selectedClass. block := [:each | | app methodApp root | app := context application. ((class canUnderstand: each) ifTrue: [root := app rootApplication. methodApp := ((class whichClassIncludesSelector: each) compiledMethodAt: each) application rootApplication. methodApp == root or: [root isBasedOn: methodApp]] ifFalse: [false]) not]. message isNil ifTrue: [message := context selfMessages detect: block ifNone: [nil]]. message isNil ifTrue: [class := class superclass. class isNil ifTrue: [context superMessages isEmpty ifFalse: [message := context superMessages asArray first]] ifFalse: [message := context superMessages detect: block ifNone: [nil]]]. message notNil ifTrue: [result addSearchString: message. result addClass: context selectedClass selector: context selector]]. ^detector')! ! !RBInlineMethodTest methodsFor: 'tests' stamp: 'lr 2/26/2009 15:07'! testInlineMethod1 | refactoring | refactoring := InlineMethodRefactoring inline: (self convertInterval: (39 to: 84) for: (RBRefactoryTestDataApp sourceCodeAt: #caller)) inMethod: #caller forClass: RBRefactoryTestDataApp. self setupInlineExpressionFor: refactoring toReturn: false. self executeRefactoring: refactoring. self assert: ((refactoring model classNamed: #RBRefactoryTestDataApp) parseTreeFor: #caller) = (RBParser parseMethod: 'caller | anObject anObject1 | anObject := 5. anObject1 := anObject + 1. Transcript show: anObject1 printString; cr. ^anObject')! ! !RBInlineMethodTest methodsFor: 'tests' stamp: 'lr 2/26/2009 15:07'! testInlineMethod2 | refactoring | refactoring := InlineMethodRefactoring inline: (self convertInterval: (40 to: 120) for: (RBRefactoryTestDataApp sourceCodeAt: #caller1)) inMethod: #caller1 forClass: RBRefactoryTestDataApp. self setupInlineExpressionFor: refactoring toReturn: false. self executeRefactoring: refactoring. self assert: ((refactoring model classNamed: #RBRefactoryTestDataApp) parseTreeFor: #caller1) = (RBParser parseMethod: 'caller1 | anObject each1 anObject1 | anObject := 5. anObject1 := anObject + 1. each1 := anObject1 printString. Transcript show: each1; cr. [:each | each printString. ^anObject] value: each1')! ! !RBInlineMethodTest methodsFor: 'tests' stamp: 'lr 2/26/2009 15:07'! testInlineMethod3 | refactoring | refactoring := InlineMethodRefactoring inline: (self convertInterval: (58 to: 73) for: (RBRefactoryTestDataApp sourceCodeAt: #caller2)) inMethod: #caller2 forClass: RBRefactoryTestDataApp. self setupInlineExpressionFor: refactoring toReturn: false. self executeRefactoring: refactoring. self assert: ((refactoring model classNamed: #RBRefactoryTestDataApp) parseTreeFor: #caller2) = (RBParser parseMethod: 'caller2 ^(1 to: 10) inject: 1 into: [:sum :each | sum * ((1 to: 10) inject: each into: [:sum1 :each1 | sum1 + each1])] ')! ! !RBInlineMethodTest methodsFor: 'tests' stamp: 'lr 2/26/2009 15:07'! testInlineMethod4 | refactoring | refactoring := InlineMethodRefactoring inline: (self convertInterval: (31 to: 112) for: (RBRefactoryTestDataApp sourceCodeAt: #inlineJunk)) inMethod: #inlineJunk forClass: RBRefactoryTestDataApp. self setupInlineExpressionFor: refactoring toReturn: false. self executeRefactoring: refactoring. self assert: ((refactoring model classNamed: #RBRefactoryTestDataApp) parseTreeFor: #inlineJunk) = (RBParser parseMethod: 'inlineJunk | asdf bar1 baz1 asdf1 | bar1 := [:each | | temp | temp := each. temp , temp] value: self. baz1 := bar1 + bar1. asdf1 := baz1 + bar1. asdf := asdf1. ^asdf foo: [:bar | | baz | baz := bar. baz * baz]')! ! !RBInlineMethodTest methodsFor: 'tests' stamp: 'lr 2/26/2009 15:07'! testInlineMethod5 | refactoring | refactoring := InlineMethodRefactoring inline: (self convertInterval: (53 to: 64) for: (RBRefactoryTestDataApp sourceCodeAt: #inlineLast)) inMethod: #inlineLast forClass: RBRefactoryTestDataApp. self executeRefactoring: refactoring. self assert: ((refactoring model classNamed: #RBRefactoryTestDataApp) parseTreeFor: #inlineLast) = (RBParser parseMethod: 'inlineLast 5 = 3 ifTrue: [^self caller] ifFalse: [^ (1 to: 10) inject: 1 into: [:sum :each | sum * (self foo: each)]]')! ! !RBInlineMethodTest methodsFor: 'tests' stamp: 'md 7/25/2005 18:14'! testInlineMethodForSuperSend | refactoring | model := Compiler evaluate: self inlineMethodTestData. (model classNamed: #RenameVariableChange) removeMethod: #executeNotifying:. refactoring := InlineMethodRefactoring model: model inline: (self convertInterval: (102 to: 131) for: ((model classNamed: #RenameInstanceVariableChange) sourceCodeFor: #executeNotifying:)) inMethod: #executeNotifying: forClass: (model classNamed: #RenameInstanceVariableChange). self executeRefactoring: refactoring. self assert: ((model classNamed: #RenameInstanceVariableChange) parseTreeFor: #executeNotifying:) = (RBParser parseMethod: 'executeNotifying: aBlock | undo undos undo1 | self addNewVariable. self copyOldValuesToNewVariable. undos := changes collect: [:each | each executeNotifying: aBlock]. undo1 := self copy. undo1 changes: undos reverse. undo := undo1. self removeOldVariable. ^undo')! ! !RBInlineMethodTest methodsFor: 'failure tests' stamp: 'md 7/25/2005 18:14'! testInlineMethodForSuperSendThatAlsoSendsSuper | refactoring | model := Compiler evaluate: self inlineMethodTestData. refactoring := InlineMethodRefactoring inline: (102 to: 131) inMethod: #executeNotifying: forClass: (model classNamed: #RenameInstanceVariableChange). self shouldFail: refactoring! ! !RBInlineMethodTest methodsFor: 'tests' stamp: 'lr 2/26/2009 15:07'! testInlineRecursiveCascadedMethod | refactoring | refactoring := InlineMethodRefactoring inline: (self convertInterval: (33 to: 62) for: (RBRefactoryTestDataApp sourceCodeAt: #inlineMethod)) inMethod: #inlineMethod forClass: RBRefactoryTestDataApp. self executeRefactoring: refactoring. self assert: ((refactoring model classNamed: #RBRefactoryTestDataApp) parseTreeFor: #inlineMethod) = (RBParser parseMethod: 'inlineMethod | temp temp1 | self foo. temp1 := self foo; inlineMethod; bar. temp := self bar. ^temp')! ! !RBInlineMethodTest methodsFor: 'tests' stamp: ''! testModelInlineRecursiveMethod | refactoring class | class := model classNamed: #Object. class compile: 'foo self bar. self foo. self bar' classified: #(#accessing). refactoring := InlineMethodRefactoring model: model inline: (15 to: 23) inMethod: #foo forClass: class. self executeRefactoring: refactoring. self assert: (class parseTreeFor: #foo) = (RBParser parseMethod: 'foo self bar. self bar. self foo. self bar. self bar')! ! !RBInlineMethodTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 15:07'! testNonExistantSelector self shouldFail: (InlineMethodRefactoring inline: (14 to: 17) inMethod: #checkClass1: forClass: RBRefactoryTestDataApp)! ! !RBInlineMethodTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testOverriden self shouldWarn: (InlineMethodRefactoring inline: (self convertInterval: (15 to: 26) for: (RBLintRuleTest sourceCodeAt: #failedRules)) inMethod: #failedRules forClass: RBLintRuleTest)! ! !RBInlineMethodTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 15:07'! testPrimitive self shouldFail: (InlineMethodRefactoring inline: (self convertInterval: (14 to: 23) for: (RBRefactoryTestDataApp sourceCodeAt: #testMethod)) inMethod: #testMethod forClass: RBRefactoryTestDataApp)! ! !RBInlineMethodTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testReturn self shouldFail: (InlineMethodRefactoring inline: (self convertInterval: (418 to: 485) for: (RBBasicLintRuleTest class sourceCodeAt: #utilityMethods)) inMethod: #utilityMethods forClass: RBBasicLintRuleTest class)! ! RBRefactoringTest subclass: #RBInlineParameterTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBInlineParameterTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 15:07'! testInlineBlockFailure self shouldFail: (InlineParameterRefactoring inlineParameter: 'aBlock' in: RBRefactoryTestDataApp selector: ('inline' , 'Foo:') asSymbol)! ! !RBInlineParameterTest methodsFor: 'tests' stamp: 'lr 2/26/2009 15:07'! testInlineLiteralArray | refactoring class | refactoring := InlineParameterRefactoring inlineParameter: 'aSymbol' in: RBRefactoryTestDataApp selector: ('inline' , 'ParameterMethod:') asSymbol. self executeRefactoring: refactoring. class := refactoring model classNamed: #RBRefactoryTestDataApp. self assert: (class parseTreeFor: #inlineParameterMethod) = (RBParser parseMethod: 'inlineParameterMethod | aSymbol | aSymbol := #(asdf). ^aSymbol isSymbol'). self assert: (class parseTreeFor: #sendInlineParameterMethod) = (RBParser parseMethod: 'sendInlineParameterMethod ^self inlineParameterMethod'). self deny: (class directlyDefinesMethod: ('inline' , 'ParameterMethod:') asSymbol)! ! RBRefactoringTest subclass: #RBInlineTemporaryTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBInlineTemporaryTest methodsFor: 'tests' stamp: 'lr 2/26/2009 15:07'! testInlineTemporary | refactoring | refactoring := InlineTemporaryRefactoring inline: (self convertInterval: (24 to: 72) for: (RBRefactoryTestDataApp sourceCodeAt: #inlineMethod)) from: #inlineMethod in: RBRefactoryTestDataApp. self executeRefactoring: refactoring. self assert: ((refactoring model classNamed: #RBRefactoryTestDataApp) parseTreeFor: #inlineMethod) = (RBParser parseMethod: 'inlineMethod ^self foo; inlineMethod; bar')! ! !RBInlineTemporaryTest methodsFor: 'tests' stamp: 'lr 2/26/2009 15:07'! testInlineTemporaryBadInterval self shouldFail: (InlineTemporaryRefactoring inline: (self convertInterval: (29 to: 100) for: (RBRefactoryTestDataApp sourceCodeAt: #moveDefinition)) from: #moveDefinition in: RBRefactoryTestDataApp)! ! !RBInlineTemporaryTest methodsFor: 'tests' stamp: 'lr 2/26/2009 15:07'! testInlineTemporaryMutlipleAssignment self shouldFail: (InlineTemporaryRefactoring inline: (self convertInterval: (60 to: 83) for: (RBRefactoryTestDataApp sourceCodeAt: #moveDefinition)) from: #moveDefinition in: RBRefactoryTestDataApp)! ! !RBInlineTemporaryTest methodsFor: 'tests' stamp: 'lr 2/26/2009 15:07'! testInlineTemporaryReadBeforeWritten self shouldFail: (InlineTemporaryRefactoring inline: (self convertInterval: (48 to: 56) for: (RBRefactoryTestDataApp sourceCodeAt: #inlineTemporary)) from: #inlineTemporary in: RBRefactoryTestDataApp)! ! RBRefactoringTest subclass: #RBMoveMethodTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBMoveMethodTest methodsFor: 'tests' stamp: 'lr 10/26/2009 22:09'! testMoveMethodIntoArgument | refactoring class | self proceedThroughWarning: [ refactoring := MoveMethodRefactoring selector: #checkMethod: class: RBTransformationRuleTest variable: 'aSmalllintContext'. self setupSelfArgumentNameFor: refactoring toReturn: 'transformationRule'. self setupVariableTypesFor: refactoring toReturn: (Array with: (refactoring model classNamed: #SmalllintContext)). self setupMethodNameFor: refactoring toReturn: #foo:. self executeRefactoring: refactoring ]. class := refactoring model classNamed: #RBTransformationRuleTest. self assert: (class parseTreeFor: #checkMethod:) = (RBParser parseMethod: 'checkMethod: aSmalllintContext aSmalllintContext foo: self'). self assert: ((refactoring model classNamed: #SmalllintContext) parseTreeFor: #foo:) = (RBParser parseMethod: 'foo: transformationRule transformationRule class: self selectedClass. (transformationRule rewriteRule executeTree: self parseTree) ifTrue: [(transformationRule class recursiveSelfRule executeTree: transformationRule rewriteRule tree initialAnswer: false) ifFalse: [transformationRule builder compile: transformationRule rewriteRule tree printString in: transformationRule class1 classified: self protocols]]'). self assert: (class parseTreeFor: #class1) = (RBParser parseMethod: 'class1 ^class'). self assert: (class parseTreeFor: #class:) = (RBParser parseMethod: 'class: anObject class := anObject'). self assert: (class theMetaClass parseTreeFor: #recursiveSelfRule:) = (RBParser parseMethod: 'recursiveSelfRule: anObject RecursiveSelfRule := anObject'). self assert: (class theMetaClass parseTreeFor: #recursiveSelfRule) = (RBParser parseMethod: 'recursiveSelfRule ^RecursiveSelfRule'). self assert: (class parseTreeFor: #builder) = (RBParser parseMethod: 'builder ^builder'). self assert: (class parseTreeFor: #builder:) = (RBParser parseMethod: 'builder: anObject builder := anObject'). self assert: (class parseTreeFor: #rewriteRule) = (RBParser parseMethod: 'rewriteRule ^rewriteRule'). self assert: (class parseTreeFor: #rewriteRule:) = (RBParser parseMethod: 'rewriteRule: anObject rewriteRule := anObject')! ! !RBMoveMethodTest methodsFor: 'tests' stamp: 'lr 11/2/2009 00:14'! testMoveMethodIntoClassVariable | refactoring class | self proceedThroughWarning: [ refactoring := MoveMethodRefactoring selector: #checkMethod: class: RBTransformationRuleTest variable: 'RecursiveSelfRule'. self setupSelfArgumentNameFor: refactoring toReturn: 'transformationRule'. self setupVariableTypesFor: refactoring toReturn: (Array with: (refactoring model classNamed: #RBParseTreeSearcher)). self setupMethodNameFor: refactoring toReturn: #foo:foo: withArguments: #('transformationRule' 'aSmalllintContext' ). self executeRefactoring: refactoring ]. class := refactoring model classNamed: #RBTransformationRuleTest. self assert: (class parseTreeFor: #checkMethod:) = (RBParser parseMethod: 'checkMethod: aSmalllintContext RecursiveSelfRule foo: self foo: aSmalllintContext'). self assert: ((refactoring model classNamed: #RBParseTreeSearcher) parseTreeFor: #foo:foo:) = (RBParser parseMethod: 'foo: transformationRule foo: aSmalllintContext transformationRule class: aSmalllintContext selectedClass. (transformationRule rewriteRule executeTree: aSmalllintContext parseTree) ifTrue: [(self executeTree: transformationRule rewriteRule tree initialAnswer: false) ifFalse: [transformationRule builder compile: transformationRule rewriteRule tree printString in: transformationRule class1 classified: aSmalllintContext protocols]]'). self assert: (class parseTreeFor: #class1) = (RBParser parseMethod: 'class1 ^class'). self assert: (class parseTreeFor: #class:) = (RBParser parseMethod: 'class: anObject class := anObject'). self assert: (class parseTreeFor: #builder) = (RBParser parseMethod: 'builder ^builder'). self assert: (class parseTreeFor: #builder:) = (RBParser parseMethod: 'builder: anObject builder := anObject'). self assert: (class parseTreeFor: #rewriteRule) = (RBParser parseMethod: 'rewriteRule ^rewriteRule'). self assert: (class parseTreeFor: #rewriteRule:) = (RBParser parseMethod: 'rewriteRule: anObject rewriteRule := anObject')! ! !RBMoveMethodTest methodsFor: 'tests' stamp: 'lr 11/2/2009 00:14'! testMoveMethodIntoInstanceVariable | refactoring class | self proceedThroughWarning: [ refactoring := MoveMethodRefactoring selector: #checkMethod: class: RBTransformationRuleTest variable: 'rewriteRule'. self setupSelfArgumentNameFor: refactoring toReturn: 'transformationRule'. self setupVariableTypesFor: refactoring toReturn: (Array with: (refactoring model classNamed: #RBParseTreeRewriter)). self setupMethodNameFor: refactoring toReturn: #foo:foo: withArguments: #('transformationRule' 'aSmalllintContext' ). self executeRefactoring: refactoring ]. class := refactoring model classNamed: #RBTransformationRuleTest. self assert: (class parseTreeFor: #checkMethod:) = (RBParser parseMethod: 'checkMethod: aSmalllintContext rewriteRule foo: self foo: aSmalllintContext'). self assert: ((refactoring model classNamed: #RBParseTreeRewriter) parseTreeFor: #foo:foo:) = (RBParser parseMethod: 'foo: transformationRule foo: aSmalllintContext transformationRule class: aSmalllintContext selectedClass. (self executeTree: aSmalllintContext parseTree) ifTrue: [(transformationRule class recursiveSelfRule executeTree: self tree initialAnswer: false) ifFalse: [transformationRule builder compile: self tree printString in: transformationRule class1 classified: aSmalllintContext protocols]]'). self assert: (class parseTreeFor: #class1) = (RBParser parseMethod: 'class1 ^class'). self assert: (class parseTreeFor: #class:) = (RBParser parseMethod: 'class: anObject class := anObject'). self assert: (class theMetaClass parseTreeFor: #recursiveSelfRule:) = (RBParser parseMethod: 'recursiveSelfRule: anObject RecursiveSelfRule := anObject'). self assert: (class theMetaClass parseTreeFor: #recursiveSelfRule) = (RBParser parseMethod: 'recursiveSelfRule ^RecursiveSelfRule'). self assert: (class parseTreeFor: #builder) = (RBParser parseMethod: 'builder ^builder'). self assert: (class parseTreeFor: #builder:) = (RBParser parseMethod: 'builder: anObject builder := anObject')! ! !RBMoveMethodTest methodsFor: 'tests' stamp: 'TestRunner 11/3/2009 10:27'! testMoveMethodThatReferencesPoolDictionary | refactoring class | self proceedThroughWarning: [ refactoring := MoveMethodRefactoring selector: #junk class: RBLintRuleTest variable: 'RefactoryTestDataApp'. self setupSelfArgumentNameFor: refactoring toReturn: 'transformationRule'. self setupVariableTypesFor: refactoring toReturn: (Array with: (refactoring model classNamed: 'RBRefactoryTestDataApp class' asSymbol)). self setupMethodNameFor: refactoring toReturn: #junk1. self executeRefactoring: refactoring ]. class := refactoring model classNamed: #RBLintRuleTest. self assert: (class parseTreeFor: #junk) = (RBParser parseMethod: 'junk ^RefactoryTestDataApp junk1'). self assert: ((refactoring model metaclassNamed: #RBRefactoryTestDataApp) parseTreeFor: #junk1) = (RBParser parseMethod: 'junk1 ^RBRefactoryTestDataApp printString copyFrom: 1 to: CR'). self assert: (class directlyDefinesPoolDictionary: 'TextConstants' asSymbol)! ! !RBMoveMethodTest methodsFor: 'failure tests' stamp: ''! testMovePrimitiveMethod | refactoring | (model classNamed: #Object) compile: 'foo ^#() primitiveFailed' classified: #(#accessing). refactoring := MoveMethodRefactoring model: model selector: #foo class: Object variable: 'OrderedCollection'. self shouldFail: refactoring! ! RBRefactoringTest subclass: #RBMoveVariableDefinitionTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBMoveVariableDefinitionTest methodsFor: 'tests' stamp: 'lr 2/26/2009 15:07'! testMoveDefinition | refactoring | refactoring := MoveVariableDefinitionRefactoring bindTight: (self convertInterval: (19 to: 22) for: (RBRefactoryTestDataApp sourceCodeAt: #moveDefinition)) in: RBRefactoryTestDataApp selector: #moveDefinition. self executeRefactoring: refactoring. self assert: ((refactoring model classNamed: #RBRefactoryTestDataApp) parseTreeFor: #moveDefinition) = (RBParser parseMethod: 'moveDefinition ^(self collect: [:each | | temp | temp := each printString. temp , temp]) select: [:each | | temp | temp := each size. temp odd]')! ! !RBMoveVariableDefinitionTest methodsFor: 'tests' stamp: 'lr 2/26/2009 15:07'! testMoveDefinitionIntoBlockThatIsAReceiverOfACascadedMessage | refactoring | refactoring := MoveVariableDefinitionRefactoring bindTight: (self convertInterval: (48 to: 58) for: (RBRefactoryTestDataApp sourceCodeAt: #referencesConditionFor:)) in: RBRefactoryTestDataApp selector: #referencesConditionFor:. self executeRefactoring: refactoring. self assert: ((refactoring model classNamed: #RBRefactoryTestDataApp) parseTreeFor: #referencesConditionFor:) = (RBParser parseMethod: 'referencesConditionFor: aClass | environment | ^(RBCondition withBlock: [| association |association := Smalltalk associationAt: aClass name ifAbsent: [self refactoringError: ''Could not find class'']. environment := (self environment referencesTo: association) | (self environment referencesTo: aClass name). environment isEmpty]) errorMacro: aClass , '' is referenced.Browse references?''; errorBlock: [environment openEditor]; yourself')! ! !RBMoveVariableDefinitionTest methodsFor: 'tests' stamp: 'lr 2/26/2009 15:07'! testNoMoveDefinition self shouldFail: (MoveVariableDefinitionRefactoring bindTight: (self convertInterval: (21 to: 24) for: (RBRefactoryTestDataApp sourceCodeAt: #moveDefinition)) in: RBRefactoryTestDataApp selector: #noMoveDefinition)! ! !RBMoveVariableDefinitionTest methodsFor: 'tests' stamp: 'lr 2/26/2009 14:51'! testNonExistantName self shouldFail: (MoveVariableDefinitionRefactoring bindTight: (1 to: 10) in: RBLintRuleTest selector: #name1); shouldFail: (MoveVariableDefinitionRefactoring bindTight: (self convertInterval: (44 to: 54) for: (RBLintRuleTest sourceCodeAt: #displayName)) in: RBLintRuleTest selector: #displayName); shouldFail: (MoveVariableDefinitionRefactoring bindTight: (self convertInterval: (16 to: 25) for: (RBLintRuleTest sourceCodeAt: #displayName)) in: RBLintRuleTest selector: #displayName)! ! RBRefactoringTest subclass: #RBProtectInstanceVariableTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBProtectInstanceVariableTest methodsFor: 'tests' stamp: 'lr 2/26/2009 14:51'! testProtectInstanceVariable | refactoring class | refactoring := ProtectInstanceVariableRefactoring variable: 'rewrite' , 'Rule1' class: RBSubclassOfClassToRename. self executeRefactoring: refactoring. class := refactoring model classNamed: #RBSubclassOfClassToRename. self assert: (class parseTreeFor: #calls1) = (RBParser parseMethod: 'calls1 ^rewriteRule1 := (rewriteRule1 := self calls)'). self assert: (class parseTreeFor: #calls) = (RBParser parseMethod: 'calls ^rewriteRule1 := rewriteRule1 , rewriteRule1'). self deny: (class directlyDefinesMethod: ('rewrite' , 'Rule1') asSymbol). self deny: (class directlyDefinesMethod: ('rewrite' , 'Rule1:') asSymbol)! ! !RBProtectInstanceVariableTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testVariableNotDefined | refactoring | refactoring := ProtectInstanceVariableRefactoring variable: 'rewrite' class: RBSubclassOfClassToRename. self shouldFail: refactoring! ! RBRefactoringTest subclass: #RBPullUpClassVariableTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBPullUpClassVariableTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testMetaClassFailure self shouldFail: (PullUpClassVariableRefactoring variable: #RecursiveSelfRule class: RBLintRuleTest class)! ! !RBPullUpClassVariableTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testNonExistantName self shouldFail: (PullUpClassVariableRefactoring variable: #Foo class: RBLintRuleTest)! ! !RBPullUpClassVariableTest methodsFor: 'tests' stamp: 'lr 2/26/2009 14:51'! testPullUpClassVariable | refactoring | refactoring := PullUpClassVariableRefactoring variable: #RecursiveSelfRule class: RBLintRuleTest. self executeRefactoring: refactoring. self assert: ((refactoring model classNamed: #RBLintRuleTest) directlyDefinesClassVariable: #RecursiveSelfRule). self deny: ((refactoring model classNamed: #RBTransformationRuleTest) directlyDefinesClassVariable: #RecursiveSelfRule)! ! RBRefactoringTest subclass: #RBPullUpInstanceVariableTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBPullUpInstanceVariableTest methodsFor: 'tests' stamp: 'lr 2/26/2009 14:51'! testPullUpInstVar | refactoring | self proceedThroughWarning: [ refactoring := PullUpInstanceVariableRefactoring variable: 'result' class: RBLintRuleTest. self executeRefactoring: refactoring ]. self assert: ((refactoring model classNamed: #RBLintRuleTest) directlyDefinesInstanceVariable: 'result'). self deny: ((refactoring model classNamed: #RBBasicLintRuleTest) directlyDefinesInstanceVariable: 'result')! ! !RBPullUpInstanceVariableTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testPullUpVariableNotDefined self shouldFail: (PullUpInstanceVariableRefactoring variable: 'notDefinedVariable' class: RBLintRuleTest)! ! RBRefactoringTest subclass: #RBPullUpMethodTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBPullUpMethodTest methodsFor: 'tests' stamp: 'lr 7/17/2010 23:27'! testPullUpAndCopyDown | class | model defineClass: 'Object subclass: #SomeClass instanceVariableNames: '''' classVariableNames: ''Foo'' poolDictionaries: '''' category: #''Refactory-Test data'''. model defineClass: 'SomeClass subclass: #Subclass instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''. model defineClass: 'Subclass subclass: #Foo1 instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''. model defineClass: 'Subclass subclass: #Foo2 instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''. class := model classNamed: #Foo1. class compile: 'yourself ^1' classified: #(#accessing). self executeRefactoring: (PullUpMethodRefactoring model: model pullUp: #(#yourself) from: class). self assert: (class superclass parseTreeFor: #yourself) = (RBParser parseMethod: 'yourself ^1'). self deny: (class directlyDefinesMethod: #yourself). class := model classNamed: #Foo2. self assert: (class directlyDefinesMethod: #yourself). self assert: (class parseTreeFor: #yourself) = ((model classNamed: #Object) parseTreeFor: #yourself)! ! !RBPullUpMethodTest methodsFor: 'failure tests' stamp: 'lr 7/17/2010 23:27'! testPullUpClassMethod | class | class := model classNamed: #Object. class addClassVariable: #Foo. class theMetaClass compile: 'foo ^Foo' classified: #(#accessing ). self shouldFail: (PullUpMethodRefactoring model: model pullUp: #(#foo ) from: class theMetaClass)! ! !RBPullUpMethodTest methodsFor: 'tests' stamp: 'lr 7/17/2010 23:27'! testPullUpMethodWithCopyOverriddenMethodsDown | refactoring | self proceedThroughWarning: [ refactoring := PullUpMethodRefactoring pullUp: #(#isComposite ) from: RBCompositeLintRuleTest. self executeRefactoring: refactoring ]. self assert: ((refactoring model classNamed: #RBBasicLintRuleTest) parseTreeFor: #isComposite) = (RBParser parseMethod: 'isComposite ^false'). self assert: ((refactoring model classNamed: ('RBFoo' , 'LintRuleTest') asSymbol) parseTreeFor: #isComposite) = (RBParser parseMethod: 'isComposite ^false'). self assert: ((refactoring model classNamed: #RBLintRuleTest) parseTreeFor: #isComposite) = (RBParser parseMethod: 'isComposite ^true'). self deny: ((refactoring model classNamed: #RBCompositeLintRuleTest) directlyDefinesMethod: #isComposite)! ! !RBPullUpMethodTest methodsFor: 'failure tests' stamp: 'lr 7/17/2010 23:27'! testPullUpReferencesInstVar self shouldFail: (PullUpMethodRefactoring pullUp: #(#checkClass: ) from: RBBasicLintRuleTest)! ! !RBPullUpMethodTest methodsFor: 'failure tests' stamp: 'lr 7/17/2010 23:27'! testPullUpWithInvalidSuperSend | class | model defineClass: 'Object subclass: #SomeClass instanceVariableNames: '''' classVariableNames: ''Foo'' poolDictionaries: '''' category: #''Refactory-Test data'''. model defineClass: 'SomeClass subclass: #Subclass instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''. model defineClass: 'Subclass subclass: #Foo1 instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''. model defineClass: 'Subclass subclass: #Foo2 instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''. (model classNamed: #Foo2) compile: 'yourself ^super yourself + 1' classified: #(#accessing). class := model classNamed: #Foo1. class compile: 'yourself ^1' classified: #(#accessing). self shouldFail: (PullUpMethodRefactoring model: model pullUp: #(#yourself) from: class)! ! !RBPullUpMethodTest methodsFor: 'failure tests' stamp: 'lr 7/17/2010 23:27'! testPullUpWithMethodThatCannotBePushedDown model defineClass: 'Object subclass: #SomeClass instanceVariableNames: '''' classVariableNames: ''Foo'' poolDictionaries: '''' category: #''Refactory-Test data'''. (model classNamed: #SomeClass) compile: 'yourself ^54' classified: #(#accessing). self shouldFail: (PullUpMethodRefactoring model: model pullUp: #(#yourself) from: (model classNamed: #SomeClass))! ! !RBPullUpMethodTest methodsFor: 'failure tests' stamp: 'lr 7/17/2010 23:28'! testPullUpWithSuperSendThatCannotBeCopiedDown | class | model defineClass: 'Object subclass: #SomeClass instanceVariableNames: '''' classVariableNames: ''Foo'' poolDictionaries: '''' category: #''Refactory-Test data'''. (model classNamed: #Object) compile: 'foo ^3' classified: #(#accessing). model defineClass: 'SomeClass subclass: #Subclass instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''. (model classNamed: #Subclass) compile: 'foo ^super foo' classified: #(#accessing). model defineClass: 'Subclass subclass: #Foo1 instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''. model defineClass: 'Subclass subclass: #Foo2 instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''. (class := model classNamed: #Foo2) compile: 'foo ^1' classified: #(#accessing). self shouldFail: (PullUpMethodRefactoring model: model pullUp: #(#foo) from: class)! ! RBRefactoringTest subclass: #RBPushDownClassVariableTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBPushDownClassVariableTest methodsFor: 'failure tests' stamp: 'bh 11/8/2000 14:09'! testModelNonExistantName model defineClass: 'Object subclass: #SomeClass instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''. self shouldFail: (PushDownClassVariableRefactoring model: model variable: #Foo class: (model classNamed: #SomeClass))! ! !RBPushDownClassVariableTest methodsFor: 'failure tests' stamp: 'bh 11/8/2000 14:09'! testModelPushDownToMultipleSubclassesFailure model defineClass: 'Object subclass: #SomeClass instanceVariableNames: '''' classVariableNames: ''Foo'' poolDictionaries: '''' category: #''Refactory-Test data'''. model defineClass: 'SomeClass subclass: #Subclass instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''. (model classNamed: #Subclass) compile: 'foo ^Foo' classified: #(#accessing). model defineClass: 'SomeClass subclass: #AnotherSubclass instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''. (model metaclassNamed: #AnotherSubclass) compile: 'bar ^Foo' classified: #(#accessing). self shouldFail: (PushDownClassVariableRefactoring model: model variable: #Foo class: (model classNamed: #SomeClass))! ! !RBPushDownClassVariableTest methodsFor: 'tests' stamp: 'bh 11/8/2000 14:09'! testModelPushDownVariable | class | model defineClass: 'Object subclass: #SomeClass instanceVariableNames: '''' classVariableNames: ''Foo'' poolDictionaries: '''' category: #''Refactory-Test data'''. model defineClass: 'SomeClass subclass: #Subclass instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''. class := model classNamed: #Subclass. class compile: 'foo ^Foo' classified: #(#accessing). self executeRefactoring: (PushDownClassVariableRefactoring model: model variable: #Foo class: class superclass). self deny: (class superclass directlyDefinesClassVariable: #Foo). self assert: (class directlyDefinesClassVariable: #Foo)! ! !RBPushDownClassVariableTest methodsFor: 'tests' stamp: 'lr 10/26/2009 22:08'! testModelPushDownVariableToClassDownTwoLevels | class | model defineClass: 'Object subclass: #SomeClass instanceVariableNames: '''' classVariableNames: ''Foo'' poolDictionaries: '''' category: #''Refactory-Test data'''. model defineClass: 'SomeClass subclass: #Subclass instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''. model defineClass: 'Subclass subclass: #AnotherSubclass instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''. class := model metaclassNamed: #AnotherSubclass. class compile: 'bar ^Foo' classified: #(#accessing ). class := class theNonMetaClass. self executeRefactoring: (PushDownClassVariableRefactoring model: model variable: #Foo class: class superclass superclass). self deny: (class superclass superclass directlyDefinesClassVariable: #Foo). self deny: (class superclass directlyDefinesClassVariable: #Foo). self assert: (class directlyDefinesClassVariable: #Foo)! ! !RBPushDownClassVariableTest methodsFor: 'tests' stamp: 'bh 11/8/2000 14:10'! testModelPushDownVariableToMultipleClassesInSameHierarchy | class | model defineClass: 'Object subclass: #SomeClass instanceVariableNames: '''' classVariableNames: ''Foo'' poolDictionaries: '''' category: #''Refactory-Test data'''. model defineClass: 'SomeClass subclass: #Subclass instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''. class := model classNamed: #Subclass. class compile: 'foo ^Foo' classified: #(#accessing). model defineClass: 'Subclass subclass: #AnotherSubclass instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''. (model metaclassNamed: #AnotherSubclass) compile: 'bar ^Foo' classified: #(#accessing). self executeRefactoring: (PushDownClassVariableRefactoring model: model variable: #Foo class: class superclass). self deny: (class superclass directlyDefinesClassVariable: #Foo). self assert: (class directlyDefinesClassVariable: #Foo)! ! !RBPushDownClassVariableTest methodsFor: 'tests' stamp: 'bh 11/8/2000 14:10'! testModelRemoveUnusedVariable model defineClass: 'Object subclass: #SomeClass instanceVariableNames: '''' classVariableNames: ''Foo'' poolDictionaries: '''' category: #''Refactory-Test data'''. self assert: ((model classNamed: #SomeClass) directlyDefinesVariable: #Foo). model defineClass: 'SomeClass subclass: #Subclass instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''. self executeRefactoring: (PushDownClassVariableRefactoring model: model variable: #Foo class: (model classNamed: #SomeClass)). self deny: ((model classNamed: #SomeClass) directlyDefinesVariable: #Foo). self deny: ((model classNamed: #Subclass) directlyDefinesVariable: #Foo)! ! !RBPushDownClassVariableTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testNonExistantName self shouldFail: (PushDownClassVariableRefactoring variable: #Foo class: RBBasicLintRuleTest)! ! !RBPushDownClassVariableTest methodsFor: 'tests' stamp: 'lr 2/26/2009 14:51'! testPushDownClassVariable | refactoring | refactoring := PushDownClassVariableRefactoring variable: #Foo1 class: RBLintRuleTest. self assert: ((refactoring model classNamed: #RBLintRuleTest) directlyDefinesClassVariable: #Foo1). self executeRefactoring: refactoring. (refactoring model classNamed: #RBLintRuleTest) withAllSubclasses do: [ :each | self deny: (each directlyDefinesClassVariable: #Foo1) ]! ! RBRefactoringTest subclass: #RBPushDownInstanceVariableTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBPushDownInstanceVariableTest methodsFor: 'tests' stamp: 'bh 11/8/2000 14:10'! testModelPushDownToMetaclass model defineClass: 'Object subclass: #SomeClass instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''. (model metaclassNamed: #SomeClass) addInstanceVariable: 'foo'. model defineClass: 'SomeClass subclass: #Subclass instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''. (model metaclassNamed: #Subclass) compile: 'foo ^foo' classified: #(#accessing). self executeRefactoring: (PushDownInstanceVariableRefactoring model: model variable: 'foo' class: (model metaclassNamed: #SomeClass)). self deny: ((model metaclassNamed: #SomeClass) directlyDefinesVariable: 'foo'). self assert: ((model metaclassNamed: #Subclass) directlyDefinesVariable: 'foo')! ! !RBPushDownInstanceVariableTest methodsFor: 'tests' stamp: 'bh 11/8/2000 14:10'! testModelPushDownToMultipleSubclasses model defineClass: 'Object subclass: #SomeClass instanceVariableNames: ''foo'' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''. model defineClass: 'SomeClass subclass: #Subclass instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''. (model classNamed: #Subclass) compile: 'foo ^foo' classified: #(#accessing). model defineClass: 'SomeClass subclass: #AnotherSubclass instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''. (model classNamed: #AnotherSubclass) compile: 'bar ^foo' classified: #(#accessing). self executeRefactoring: (PushDownInstanceVariableRefactoring model: model variable: 'foo' class: (model classNamed: #SomeClass)). self deny: ((model classNamed: #SomeClass) directlyDefinesVariable: 'foo'). self assert: ((model classNamed: #Subclass) directlyDefinesVariable: 'foo'). self assert: ((model classNamed: #AnotherSubclass) directlyDefinesVariable: 'foo')! ! !RBPushDownInstanceVariableTest methodsFor: 'tests' stamp: 'bh 11/8/2000 14:10'! testModelRemoveUnusedVariable model defineClass: 'Object subclass: #SomeClass instanceVariableNames: ''foo'' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''. model defineClass: 'SomeClass subclass: #Subclass instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''. self executeRefactoring: (PushDownInstanceVariableRefactoring model: model variable: 'foo' class: (model classNamed: #SomeClass)). self deny: ((model classNamed: #SomeClass) directlyDefinesVariable: 'foo'). self deny: ((model classNamed: #Subclass) directlyDefinesVariable: 'foo')! ! !RBPushDownInstanceVariableTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testNonExistantName self shouldFail: (PushDownInstanceVariableRefactoring variable: 'foo' class: RBBasicLintRuleTest)! ! !RBPushDownInstanceVariableTest methodsFor: 'tests' stamp: 'lr 2/26/2009 14:51'! testPushDownInstanceVariable | refactoring | refactoring := PushDownInstanceVariableRefactoring variable: 'foo1' class: RBLintRuleTest. self executeRefactoring: refactoring. (refactoring model classNamed: #RBLintRuleTest) withAllSubclasses do: [ :each | self deny: (each directlyDefinesInstanceVariable: 'foo1') ]! ! RBRefactoringTest subclass: #RBPushDownMethodTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBPushDownMethodTest methodsFor: 'tests' stamp: 'lr 2/26/2009 14:51'! testPushDownMethod | refactoring class | refactoring := PushDownMethodRefactoring pushDown: #(#name: ) from: RBLintRuleTest. self executeRefactoring: refactoring. class := refactoring model classNamed: #RBLintRuleTest. self deny: (class directlyDefinesMethod: #name:). class subclasses do: [ :each | self assert: (each parseTreeFor: #name:) = (RBParser parseMethod: 'name: aString name := aString') ]! ! !RBPushDownMethodTest methodsFor: 'failure tests' stamp: ''! testPushDownMethodOnNonAbstractClass | refactoring | refactoring := PushDownMethodRefactoring pushDown: #(#yourself) from: Object. self shouldFail: refactoring! ! !RBPushDownMethodTest methodsFor: 'tests' stamp: 'lr 2/26/2009 14:51'! testPushDownMethodThatReferencesPoolDictionary | refactoring class parseTree | parseTree := RBLintRuleTest parseTreeFor: #junk. self proceedThroughWarning: [ refactoring := PushDownMethodRefactoring pushDown: #(#junk ) from: RBLintRuleTest. self executeRefactoring: refactoring ]. class := refactoring model classNamed: #RBLintRuleTest. self deny: (class directlyDefinesMethod: #junk). class subclasses do: [ :each | self assert: (each parseTreeFor: #junk) = parseTree. self assert: (each directlyDefinesPoolDictionary: 'TextConstants' asSymbol) ]! ! !RBPushDownMethodTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testPushDownNonExistantMenu | refactoring | refactoring := PushDownMethodRefactoring pushDown: #(#someMethodThatDoesNotExist ) from: RBLintRuleTest. self shouldFail: refactoring! ! !RBRefactoringTest methodsFor: 'private' stamp: 'md 7/25/2005 15:15'! abstractVariableTestData ^' | model | (model := RBNamespace onEnvironment: ((ClassEnvironment onEnvironment: BrowserEnvironment new) classes: (#(#Bar #Foo) inject: OrderedCollection new into: [:sum :each | | class | class := Smalltalk at: each ifAbsent: [nil]. class notNil ifTrue: [sum add: class]. sum]) , (#(#Bar #Foo) inject: OrderedCollection new into: [:sum :each | | class | class := Smalltalk at: each ifAbsent: [nil]. class notNil ifTrue: [sum add: class class]. sum])) not) name: ''Test''. #(''Object subclass: #Foo instanceVariableNames: ''''instVarName1 instVarName2 '''' classVariableNames: ''''ClassVarName1 ClassVarName2 '''' poolDictionaries: '''''''' category: ''''Testing'''''' ''Foo subclass: #Bar instanceVariableNames: '''''''' classVariableNames: '''''''' poolDictionaries: '''''''' category: ''''Testing'''''') do: [:each | model defineClass: each]. #(#(#Bar #(#(''instVarName1 ^1242321'' #tests) #(''foo instVarName1 := instVarName1 + instVarName2 + ClassVarName1'' #tests))) #(#Foo #(#(''foo ^instVarName2 := 3'' #tests) #(''bar "Add one to instVarName1" instVarName1 := instVarName1 + 1'' #tests) #(''classVarName1 ^ClassVarName1'' #tests) #(''instVarName1: anObject ^anObject'' #tests) #(''asdf ^self classVarName1: (ClassVarName1 := ClassVarName1 + 1)'' #tests) #(''instVarName2 ^instVarName2'' #tests) #(''instVarName2: anObject instVarName2 := anObject'' #tests) #(''classVarName1: anObject ^ClassVarName1 := anObject'' #tests))) #(''Bar class'' #(#(''classVarName2: anObject ClassVarName2 := anObject'' #tests) #(''classVarName2 ^ClassVarName2'' #tests))) #(''Foo class'' #(#(''foo ^ClassVarName1 := ClassVarName1 * ClassVarName1 * ClassVarName1'' #tests)))) do: [:each | | class | class := model classNamed: each first. each last do: [:meth | class compile: meth first classified: meth last]]. model '! ! !RBRefactoringTest methodsFor: 'private' stamp: 'lr 2/26/2009 16:48'! childrenToSiblingTestData ^' | m | (m:= RBNamespace onEnvironment: ((ClassEnvironment onEnvironment: BrowserEnvironment new) classes: (#(#ConcreteSubclass #ConcreteSuperclass #NoMoveSubclass) inject: OrderedCollection new into: [:sum :each | | class | class := Smalltalk at: each ifAbsent: [nil]. class notNil ifTrue: [sum add: class]. sum]) , (#(#ConcreteSubclass #ConcreteSuperclass #NoMoveSubclass) inject: OrderedCollection new into: [:sum :each | | class | class := Smalltalk at: each ifAbsent: [nil]. class notNil ifTrue: [sum add: class class]. sum])) not) name: ''Test''. #(''ConcreteSuperclass subclass: #NoMoveSubclass instanceVariableNames: '''''''' classVariableNames: '''''''' poolDictionaries: '''''''' category: ''''Testing'''''' ''Object subclass: #ConcreteSuperclass instanceVariableNames: ''''instVarName1 instVarName2 '''' classVariableNames: ''''ClassVarName1 ClassVarName2 '''' poolDictionaries: '''''''' category: ''''Testing'''''' ''ConcreteSuperclass subclass: #ConcreteSubclass instanceVariableNames: '''''''' classVariableNames: '''''''' poolDictionaries: '''''''' category: ''''Testing'''''') do: [:each | m defineClass: each]. (m metaclassNamed: #ConcreteSuperclass) addInstanceVariable: ''classInstVarName1''. #(#(#ConcreteSubclass #(#(''initialize super initialize. instVarName1 := nil'' #everyone) #(''different ^0'' #everyone))) #(#ConcreteSuperclass #(#(''same ^self initialize isKindOf: ConcreteSuperclass'' #''one def'') #(''different ^instVarName1 + instVarName2'' #everyone) #(''initialize instVarName1 := instVarName2 := ClassVarName1 := ClassVarName2 := 0'' #everyone))) #(#NoMoveSubclass #(#(''same ^123'' #''one def''))) #(''ConcreteSubclass class'' #(#(''bar ^self storeString'' #testing))) #(''ConcreteSuperclass class'' #(#(''foo ^classInstVarName1 + ClassVarName1 + ClassVarName2'' #testing) #(''new ^super new initialize'' #testing) #(''bar ^self printString'' #testing))) #(''NoMoveSubclass class'' #())) do: [:each | | class | class := m classNamed: each first. each last do: [:meth | class compile: meth first classified: meth last]]. m '! ! !RBRefactoringTest methodsFor: 'private' stamp: 'md 7/25/2005 18:45'! inlineMethodTestData ^ ' | m | (m := RBNamespace onEnvironment: ((ClassEnvironment onEnvironment: BrowserEnvironment new) classes: (#(#RenameClassVariableChange #VariableCompositeRefactoryChange #RenameInstanceVariableChange #CompositeRefactoryChange #RenameVariableChange #RefactoryChange) inject: OrderedCollection new into: [:sum :each | | class | class := Smalltalk at: each ifAbsent: [nil]. class notNil ifTrue: [sum add: class]. sum]) , (#() inject: OrderedCollection new into: [:sum :each | | class | class := Smalltalk at: each ifAbsent: [nil]. class notNil ifTrue: [sum add: class class]. sum])) not) name: ''Test''. #(''Object subclass: #RefactoryChange instanceVariableNames: ''''name '''' classVariableNames: '''''''' poolDictionaries: '''''''' category: ''''Refactory-Support'''''' ''RefactoryChange subclass: #CompositeRefactoryChange instanceVariableNames: ''''changes '''' classVariableNames: '''''''' poolDictionaries: '''''''' category: ''''Refactory-Support'''''' ''CompositeRefactoryChange subclass: #VariableCompositeRefactoryChange instanceVariableNames: ''''className isMeta '''' classVariableNames: '''''''' poolDictionaries: '''''''' category: ''''Refactory-Support'''''' ''VariableCompositeRefactoryChange subclass: #RenameVariableChange instanceVariableNames: ''''oldName newName '''' classVariableNames: '''''''' poolDictionaries: '''''''' category: ''''Refactory-Support'''''' ''RenameVariableChange subclass: #RenameClassVariableChange instanceVariableNames: '''''''' classVariableNames: '''''''' poolDictionaries: '''''''' category: ''''Refactory-Support'''''' ''RenameVariableChange subclass: #RenameInstanceVariableChange instanceVariableNames: '''''''' classVariableNames: '''''''' poolDictionaries: '''''''' category: ''''Refactory-Support'''''') do: [:each | m defineClass: each]. #(#(#RenameClassVariableChange #(#(''removeOldVariable (RemoveClassVariableChange remove: oldName from: self changeClass) execute'' #private) #(''addNewVariable (AddClassVariableChange add: newName to: self changeClass) execute'' #private) #(''executeNotifying: aBlock | undo | self addNewVariable. self copyOldValuesToNewVariable. undo := super executeNotifying: aBlock. self removeOldVariable. ^undo'' #private) #(''copyOldValuesToNewVariable | oldValue | oldValue := self changeClass classPool at: oldName ifAbsent: []. self changeClass at: newName asSymbol put: oldValue'' #private))) #(#VariableCompositeRefactoryChange #(#(''displayClassName ^isMeta ifTrue: [self changeClassName , '''' class''''] ifFalse: [self changeClassName asString]'' #printing) #(''isMeta ^isMeta'' #private) #(''changeClass: aBehavior isMeta := aBehavior isMeta. className := isMeta ifTrue: [aBehavior soleInstance name] ifFalse: [aBehavior name]'' #accessing) #(''hash ^self changeClassName hash'' #comparing) #(''changeClassName: aSymbol className := aSymbol. isMeta isNil ifTrue: [isMeta := false]'' #accessing) #(''changeClass | class | class := Smalltalk at: self changeClassName ifAbsent: [^nil]. ^isMeta ifTrue: [class class] ifFalse: [class]'' #accessing) #(''printOn: aStream aStream nextPutAll: self displayString'' #printing) #(''changeClassName ^className'' #accessing) #(''= aRefactoryClassChange self class = aRefactoryClassChange class ifFalse: [^false]. ^className = aRefactoryClassChange changeClassName and: [isMeta = aRefactoryClassChange isMeta]'' #comparing))) #(#RenameInstanceVariableChange #(#(''removeOldVariable (RemoveInstanceVariableChange remove: oldName from: self changeClass) execute'' #private) #(''addNewVariable (AddInstanceVariableChange add: newName to: self changeClass) execute'' #private) #(''executeNotifying: aBlock | undo | self addNewVariable. self copyOldValuesToNewVariable. undo := super executeNotifying: aBlock. self removeOldVariable. ^undo'' #private) #(''copyOldValuesToNewVariable | newIndex oldIndex | oldIndex := self changeClass allInstVarNames indexOf: oldName asString. newIndex := self changeClass allInstVarNames indexOf: newName asString. self changeClass withAllSubclasses do: [:each | each allInstances do: [:inst | each instVarAt: newIndex put: (each instVarAt: oldIndex)]]'' #private))) #(#CompositeRefactoryChange #(#(''compile: source in: class ^self addChange: (AddMethodChange compile: source in: class)'' #''refactory-changes'') #(''addClassVariable: variableName to: aClass ^self addChange: (AddClassVariableChange add: variableName to: aClass)'' #''refactory-changes'') #(''addChangeFirst: aRefactoryChange changes addFirst: aRefactoryChange. ^aRefactoryChange'' #accessing) #(''removeChange: aChange changes remove: aChange ifAbsent: []'' #''private-inspector accessing'') #(''addPool: aPoolVariable to: aClass ^self addChange: (AddPoolVariableChange add: aPoolVariable to: aClass)'' #''refactory-changes'') #(''initialize super initialize. changes := OrderedCollection new'' #''initialize-release'') #(''defineClass: aString ^self addChange: (AddClassChange definition: aString)'' #''refactory-changes'') #(''changeForClass: aRBClass selector: aSelector changes reverseDo: [:each | | change | change := each changeForClass: aRBClass selector: aSelector. change notNil ifTrue: [^change]]. ^nil'' #accessing) #(''removeInstanceVariable: variableName from: aClass ^self addChange: (RemoveInstanceVariableChange remove: variableName from: aClass)'' #''refactory-changes'') #(''printOn: aStream aStream nextPutAll: name'' #printing) #(''inspect RefactoryBuilderInspector openOn: self'' #''user interface'') #(''flattenOnto: aCollection changes do: [:each | each flattenOnto: aCollection]'' #private) #(''hash ^changes size'' #comparing) #(''= aRefactoryBuilder self class = aRefactoryBuilder class ifFalse: [^false]. changes size = aRefactoryBuilder changes size ifFalse: [^false]. changes with: aRefactoryBuilder changes do: [:each :change | each = change ifFalse: [^false]]. ^true'' #comparing) #(''renameClass: class to: newName ^self addChange: (RenameClassChange rename: class name to: newName)'' #''refactory-changes'') #(''renameChangesForClass: aClassName to: newClassName ^(self copy) changes: (self changes collect: [:each | each renameChangesForClass: aClassName to: newClassName]); yourself'' #accessing) #(''postCopy super postCopy. changes := changes collect: [:each | each copy]'' #copying) #(''changes: aCollection changes := aCollection'' #''private-inspector accessing'') #(''addInstanceVariable: variableName to: aClass ^self addChange: (AddInstanceVariableChange add: variableName to: aClass)'' #''refactory-changes'') #(''compile: source in: class classified: aProtocol ^self addChange: (AddMethodChange compile: source in: class classified: aProtocol)'' #''refactory-changes'') #(''changeForMetaclass: aSymbol selector: aSelector changes reverseDo: [:each | | change | change := each changeForMetaclass: aSymbol selector: aSelector. change notNil ifTrue: [^change]]. ^nil'' #accessing) #(''removeClassVariable: variableName from: aClass ^self addChange: (RemoveClassVariableChange remove: variableName from: aClass)'' #''refactory-changes'') #(''executeNotifying: aBlock | undos undo | undos := changes collect: [:each | each executeNotifying: aBlock]. undo := self copy. undo changes: undos reverse. ^undo'' #private) #(''changes ^changes'' #''private-inspector accessing'') #(''removeMethod: aSelector from: aClass ^self addChange: (RemoveMethodChange remove: aSelector from: aClass)'' #''refactory-changes'') #(''removeClass: aClass ^self addChange: (RemoveClassChange removeClassName: aClass)'' #''refactory-changes'') #(''addChange: aRefactoryChange changes add: aRefactoryChange. ^aRefactoryChange'' #accessing) #(''changesSize ^changes inject: 0 into: [:sum :each | sum + each changesSize]'' #accessing) #(''displayString ^super displayString asText allBold'' #printing) #(''problemCount ^self changesSize'' #accessing))) #(#RenameVariableChange #(#(''oldName: aString oldName := aString'' #private) #(''executeNotifying: aBlock | undo | undo := super executeNotifying: aBlock. undo oldName: newName; newName: oldName. ^undo'' #private) #(''newName: aString newName := aString'' #private) #(''changeString ^''''Rename '''' , oldName , '''' to '''' , newName'' #printing))) #(#RefactoryChange #(#(''flattenedChanges | changes | changes := OrderedCollection new. self flattenOnto: changes. ^changes'' #private) #(''name: aString name := aString'' #''initialize-release'') #(''initialize'' #''initialize-release'') #(''changeForMetaclass: aSymbol selector: aSelector ^nil'' #accessing) #(''changeString ^self class name'' #printing) #(''changeForClass: aRBClass selector: aSelector ^nil'' #accessing) #(''executeWithMessage: aString | tally controller m done | m := 0 asValue. done := 0. tally := self changesSize. controller := aString isNil ifTrue: [nil] ifFalse: [ProgressWidgetView progressOpenOn: m label: aString]. m value: 0. ^ [self executeNotifying: [done := done + 1. m value: done asFloat / tally]] ensure: [controller notNil ifTrue: [controller closeAndUnschedule]]'' #''performing-changes'') #(''executeNotifying: aBlock self subclassResponsibility'' #private) #(''changes ^Array with: self'' #accessing) #(''execute ^self executeNotifying: []'' #''performing-changes'') #(''inspect ^((CompositeRefactoryChange new) changes: (Array with: self); yourself) inspect'' #''user interface'') #(''flattenOnto: aCollection aCollection add: self'' #private) #(''name ^name isNil ifTrue: [self changeString] ifFalse: [name]'' #accessing) #(''changesSize ^1'' #accessing) #(''displayString ^name isNil ifTrue: [self changeString] ifFalse: [name]'' #printing) #(''renameChangesForClass: aClassName to: newClassName "We are in the middle of performing a rename operation. If we stored the class name, we need to change the class name to the new name to perform the compiles." self subclassResponsibility'' #accessing)))) do: [:each | | class | class := m classNamed: each first. each last do: [:meth | class compile: meth first classified: meth last]]. m '! ! !RBRefactoringTest methodsFor: 'set up' stamp: ''! setUp | assoc | super setUp. assoc := RefactoringManager classPool associationAt: #Instance ifAbsent: [RefactoringManager classPool associationAt: 'Instance']. manager := assoc value. assoc value: nil. model := RBNamespace new! ! !RBRefactoringTest methodsFor: 'set up' stamp: ''! setupImplementorToInlineFor: aRefactoring toReturn: anObject | options | options := aRefactoring options copy. options at: #implementorToInline put: [:ref :imps | anObject]. aRefactoring options: options! ! !RBRefactoringTest methodsFor: 'set up' stamp: ''! setupInlineExpressionFor: aRefactoring toReturn: aBoolean | options | options := aRefactoring options copy. options at: #inlineExpression put: [:ref :string | aBoolean]. aRefactoring options: options! ! !RBRefactoringTest methodsFor: 'set up' stamp: ''! setupMethodNameFor: aRefactoring toReturn: aSelector | options | options := aRefactoring options copy. options at: #methodName put: [:ref :aMethodName | aMethodName selector: aSelector; yourself]. aRefactoring options: options! ! !RBRefactoringTest methodsFor: 'set up' stamp: ''! setupMethodNameFor: aRefactoring toReturn: aSelector withArguments: stringCollection | options | options := aRefactoring options copy. options at: #methodName put: [:ref :aMethodName | aMethodName selector: aSelector; arguments: stringCollection; yourself]. aRefactoring options: options! ! !RBRefactoringTest methodsFor: 'set up' stamp: ''! setupSelfArgumentNameFor: aRefactoring toReturn: aString | options | options := aRefactoring options copy. options at: #selfArgumentName put: [:ref | aString]. aRefactoring options: options! ! !RBRefactoringTest methodsFor: 'set up' stamp: ''! setupVariableToMoveToFor: aRefactoring toReturn: aString | options | options := aRefactoring options copy. options at: #selectVariableToMoveTo put: [:ref :class :selector | aString]. aRefactoring options: options! ! !RBRefactoringTest methodsFor: 'set up' stamp: ''! setupVariableTypesFor: aRefactoring toReturn: anObject | options | options := aRefactoring options copy. options at: #variableTypes put: [:ref :ignore1 :ignore2 | anObject]. aRefactoring options: options! ! !RBRefactoringTest methodsFor: 'private' stamp: ''! shouldFail: aRefactoring self proceedThroughWarning: [self should: [self executeRefactoring: aRefactoring] raise: RefactoringError]! ! !RBRefactoringTest methodsFor: 'private' stamp: ''! shouldWarn: aRefactoring self should: [self executeRefactoring: aRefactoring] raise: RefactoringWarning! ! !RBRefactoringTest methodsFor: 'set up' stamp: ''! tearDown super tearDown. RefactoringManager instance release. (RefactoringManager classPool associationAt: #Instance ifAbsent: [RefactoringManager classPool associationAt: 'Instance']) value: manager! ! !RBRefactoringTest methodsFor: 'tests' stamp: 'bh 4/2/2000 22:28'! testConditions | condition newCondition | condition := RBCondition new type: #false block: [false] errorString: 'false'. condition errorMacro: '<1?true:false>'. self deny: condition check. self assert: condition errorString = 'false'. self assert: condition not check. self assert: condition printString = 'false'. self assert: condition not printString = 'NOT false'. self deny: (condition not & condition) check. self assert: (condition not & condition) printString = 'NOT false & false'. self assert: (condition & condition) not check. self assert: (condition | condition not) check. self deny: (newCondition := condition | condition) check. self assert: newCondition errorString = 'false AND false'. self assert: (condition not | condition not) check. self deny: (newCondition := condition & condition) check. self assert: newCondition errorString = 'false'. self assert: (condition not & condition not) check. self assert: (condition & condition) errorString = 'false OR false'! ! !RBRefactoringTest methodsFor: 'tests' stamp: 'lr 1/20/2010 09:00'! testPrintRefactoringManager self assert: RefactoringManager instance printString isString! ! RBRefactoringTest subclass: #RBRemoveClassTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBRemoveClassTest methodsFor: 'failure tests' stamp: ''! testBadName self shouldFail: (RemoveClassRefactoring classNames: #(#RecursiveSelfRule))! ! !RBRemoveClassTest methodsFor: 'tests' stamp: 'lr 8/7/2009 17:14'! testRemoveClass | refactoring | refactoring := RemoveClassRefactoring classNames: (Array with: ('RBFoo' , 'LintRuleTest') asSymbol). self executeRefactoring: refactoring. self assert: (refactoring model classNamed: ('RBFoo' , 'LintRuleTest') asSymbol) isNil. self assert: (refactoring model classNamed: #RBTransformationRuleTest) superclass = (refactoring model classNamed: #RBLintRuleTest)! ! !RBRemoveClassTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testRemoveReferenced self shouldFail: (RemoveClassRefactoring classNames: #(#RBBasicLintRuleTest ))! ! RBRefactoringTest subclass: #RBRemoveClassVariableTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBRemoveClassVariableTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testNonExistantName self shouldFail: (RemoveClassVariableRefactoring variable: #RecursiveSelfRule1 class: RBTransformationRuleTest)! ! !RBRemoveClassVariableTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testReferencedVariable self shouldFail: (RemoveClassVariableRefactoring variable: #RecursiveSelfRule class: RBTransformationRuleTest)! ! !RBRemoveClassVariableTest methodsFor: 'tests' stamp: 'lr 2/26/2009 14:51'! testRemoveClassVar | refactoring class | refactoring := RemoveClassVariableRefactoring variable: 'Foo1' class: RBLintRuleTest. class := refactoring model classNamed: #RBLintRuleTest. self assert: (class definesClassVariable: 'Foo1'). self executeRefactoring: refactoring. self deny: (class definesClassVariable: 'Foo1')! ! RBRefactoringTest subclass: #RBRemoveInstanceVariableTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBRemoveInstanceVariableTest methodsFor: 'tests' stamp: 'bh 11/8/2000 14:13'! testModelRemoveInstanceVariable | class | model defineClass: 'nil subclass: #Object instanceVariableNames: ''foo1'' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''. class := model classNamed: #Object. self assert: (class definesInstanceVariable: 'foo1'). self executeRefactoring: (RemoveInstanceVariableRefactoring model: model variable: 'foo1' class: class). self deny: (class definesInstanceVariable: 'foo1')! ! !RBRemoveInstanceVariableTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testNonExistantName self shouldFail: (RemoveInstanceVariableRefactoring variable: 'name1' class: RBLintRuleTest)! ! !RBRemoveInstanceVariableTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testReferencedVariable self shouldFail: (RemoveInstanceVariableRefactoring variable: 'name' class: RBLintRuleTest)! ! !RBRemoveInstanceVariableTest methodsFor: 'tests' stamp: 'lr 2/26/2009 14:51'! testRemoveInstVar | refactoring class | refactoring := RemoveInstanceVariableRefactoring variable: 'foo1' class: RBLintRuleTest. class := refactoring model classNamed: #RBLintRuleTest. self assert: (class definesInstanceVariable: 'foo1'). self executeRefactoring: refactoring. self deny: (class definesInstanceVariable: 'foo1')! ! RBRefactoringTest subclass: #RBRemoveMethodTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBRemoveMethodTest methodsFor: 'accessing' stamp: 'TestRunner 1/3/2010 12:35'! expectedFailures ^ #(testRemoveSameMethodButSendsSuper)! ! !RBRemoveMethodTest methodsFor: 'tests' stamp: ''! testModelRecursiveMethodThatIsNotReferencedFromOtherMethods | class otherClass | class := model classNamed: #Object. class compile: 'someMethodThatIsNotReferenced ^2' classified: #(#accessing). self assert: (class definesMethod: #someMethodThatIsNotReferenced). otherClass := model metaclassNamed: self class superclass name. otherClass compile: 'someMethodThatIsNotReferenced ^3 someMethodThatIsNotReferenced' classified: #(#accessing). model removeClassNamed: self class name. self executeRefactoring: (RemoveMethodRefactoring model: model removeMethods: #(#someMethodThatIsNotReferenced) from: class). self deny: (class definesMethod: #someMethodThatIsNotReferenced)! ! !RBRemoveMethodTest methodsFor: 'tests' stamp: 'lr 2/26/2009 15:07'! testRemoveMethod | refactoring selectors | selectors := Array with: ('selectorNot' , 'Referenced') asSymbol. refactoring := RemoveMethodRefactoring removeMethods: selectors from: RBRefactoryTestDataApp. self assert: ((refactoring model classNamed: #RBRefactoryTestDataApp) directlyDefinesMethod: selectors first). self executeRefactoring: refactoring. self deny: ((refactoring model classNamed: #RBRefactoryTestDataApp) directlyDefinesMethod: selectors first)! ! !RBRemoveMethodTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testRemoveReferenced self shouldFail: (RemoveMethodRefactoring removeMethods: #(#checkClass: ) from: RBBasicLintRuleTest)! ! !RBRemoveMethodTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testRemoveSameMethodButSendsSuper self shouldWarn: (RemoveMethodRefactoring removeMethods: #(#new ) from: RBBasicLintRuleTest class)! ! RBRefactoringTest subclass: #RBRemoveParameterTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBRemoveParameterTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testNonExistantName self shouldFail: (RemoveParameterRefactoring removeParameter: 'asdf' in: RBBasicLintRuleTest selector: #checkClass:); shouldFail: (RemoveParameterRefactoring removeParameter: 'aSmalllintContext' in: RBBasicLintRuleTest selector: #checkClass1:)! ! !RBRemoveParameterTest methodsFor: 'failure tests' stamp: ''! testPrimitiveMethods | refactoring | (model classNamed: #Object) compile: 'foo123: a ^#() primitiveFailed' classified: #(#accessing). refactoring := RemoveParameterRefactoring model: model removeParameter: 'a' in: Object selector: #foo123:. self shouldFail: refactoring! ! !RBRemoveParameterTest methodsFor: 'tests' stamp: 'lr 2/26/2009 15:07'! testRemoveParameter | refactoring class | refactoring := RemoveParameterRefactoring removeParameter: 'anArg' in: RBRefactoryTestDataApp selector: ('rename' , 'ThisMethod:') asSymbol. self executeRefactoring: refactoring. class := refactoring model classNamed: #RBRefactoryTestDataApp. self assert: (class parseTreeFor: #renameThisMethod) = (RBParser parseMethod: 'renameThisMethod ^self'). self assert: (class parseTreeFor: #callMethod) = (RBParser parseMethod: 'callMethod ^(self renameThisMethod)'). self deny: (class directlyDefinesMethod: ('rename' , 'ThisMethod:') asSymbol)! ! RBRefactoringTest subclass: #RBRenameClassTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBRenameClassTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testBadName self shouldFail: (RenameClassRefactoring rename: RBLintRuleTest to: self objectClassVariable); shouldFail: (RenameClassRefactoring rename: RBLintRuleTest to: #'Ob ject')! ! !RBRenameClassTest methodsFor: 'failure tests' stamp: ''! testExistingName self shouldFail: (RenameClassRefactoring rename: self class to: #Object)! ! !RBRenameClassTest methodsFor: 'failure tests' stamp: ''! testMetaClassFailure self shouldFail: (RenameClassRefactoring rename: self class class to: #Foo)! ! !RBRenameClassTest methodsFor: 'tests' stamp: 'bh 11/8/2000 14:13'! testModelRenameClass | refactoring class | model defineClass: 'Object subclass: #Foo instanceVariableNames: ''a'' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''. class := model classNamed: #Foo. class compile: 'foo ^Object' classified: #(#accessing); compile: 'objectName ^#(Object)' classified: #(#accessing). refactoring := RenameClassRefactoring model: model rename: Object to: #Thing. self executeRefactoring: refactoring. self assert: (model includesClassNamed: #Thing). self deny: (model includesClassNamed: #Object). self assert: (class parseTreeFor: #foo) = (RBParser parseMethod: 'foo ^Thing'). self assert: (class parseTreeFor: #objectName) = (RBParser parseMethod: 'objectName ^#(Thing)'). self assert: class superclass name = #Thing! ! !RBRenameClassTest methodsFor: 'tests' stamp: 'lr 3/19/2010 13:34'! testModelRenameSequenceClass model defineClass: 'Object subclass: #Foo1 instanceVariableNames: '''' classVariableNames: '''' poolDictionaries: '''' category: #''Refactory-Test data'''. (model classNamed: #Foo1) compile: 'foo ^ Foo1' classified: #(accessing); compile: 'objectName ^ #(Foo1)' classified: #(accessing). self executeRefactoring: (RenameClassRefactoring model: model rename: (model classNamed: #Foo1) to: #Foo2). self executeRefactoring: (RenameClassRefactoring model: model rename: (model classNamed: #Foo2) to: #Foo3). self deny: (model includesClassNamed: #Foo1). self deny: (model includesClassNamed: #Foo2). self assert: (model includesClassNamed: #Foo3). self assert: ((model classNamed: #Foo3) parseTreeFor: #foo) = (RBParser parseMethod: 'foo ^ Foo3'). self assert: ((model classNamed: #Foo3) parseTreeFor: #objectName) = (RBParser parseMethod: 'objectName ^ #(Foo3)')! ! !RBRenameClassTest methodsFor: 'tests' stamp: 'lr 8/7/2009 17:13'! testRenameClass | refactoring class | refactoring := RenameClassRefactoring rename: (Smalltalk at: ('RBClass' , 'ToRename') asSymbol) to: 'RBNew' , 'ClassName' asSymbol. self executeRefactoring: refactoring. self assert: ((refactoring model classNamed: ('RBNew' , 'ClassName') asSymbol) parseTreeFor: #method1) = (RBParser parseMethod: 'method1 ^self method2'). self deny: (refactoring model includesClassNamed: ('RBClass' , 'ToRename') asSymbol). class := refactoring model classNamed: ('RBSubclass' , 'OfClassToRename') asSymbol. self assert: class superclass = (refactoring model classNamed: ('RBNew' , 'ClassName') asSymbol). self assert: (class parseTreeFor: #symbolReference) = (RBParser parseMethod: 'symbolReference ^#RBNewClassName'). self assert: (class parseTreeFor: #reference) = (RBParser parseMethod: 'reference ^RBNewClassName new')! ! RBRefactoringTest subclass: #RBRenameClassVariableTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBRenameClassVariableTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testAlreadyExistingName self shouldFail: (RenameClassVariableRefactoring rename: #RecursiveSelfRule to: self objectClassVariable in: RBTransformationRuleTest)! ! !RBRenameClassVariableTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testMetaClassFailure self shouldFail: (RenameClassVariableRefactoring rename: #RecursiveSelfRule to: #Foo in: RBTransformationRuleTest class)! ! !RBRenameClassVariableTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testNonExistantName self shouldFail: (RenameClassVariableRefactoring rename: #foo to: #newFoo in: RBBasicLintRuleTest)! ! !RBRenameClassVariableTest methodsFor: 'tests' stamp: 'lr 11/2/2009 00:15'! testRenameClassVar | refactoring class | refactoring := RenameClassVariableRefactoring rename: #RecursiveSelfRule to: #RSR in: RBTransformationRuleTest. self executeRefactoring: refactoring. class := refactoring model classNamed: #RBTransformationRuleTest. self assert: (class directlyDefinesClassVariable: #RSR). self deny: (class directlyDefinesClassVariable: #RecursiveSelfRule). self assert: (class theMetaClass parseTreeFor: #initializeAfterLoad1) = (RBParser parseMethod: 'initializeAfterLoad1 RSR := RBParseTreeSearcher new. RSR addMethodSearches: #(''`@methodName: `@args | `@temps | self `@methodName: `@args'' ''`@methodName: `@args | `@temps | ^self `@methodName: `@args'') -> [:aNode :answer | true]'). self assert: (class theMetaClass parseTreeFor: #nuke) = (RBParser parseMethod: 'nuke RSR := nil'). self assert: (class parseTreeFor: #checkMethod:) = (RBParser parseMethod: 'checkMethod: aSmalllintContext class := aSmalllintContext selectedClass. (rewriteRule executeTree: aSmalllintContext parseTree) ifTrue: [(RSR executeTree: rewriteRule tree initialAnswer: false) ifFalse: [builder compile: rewriteRule tree printString in: class classified: aSmalllintContext protocols]]')! ! RBRefactoringTest subclass: #RBRenameInstanceVariableTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBRenameInstanceVariableTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testAlreadyExistingName self shouldFail: (RenameInstanceVariableRefactoring rename: 'classBlock' to: 'name' in: RBBasicLintRuleTest)! ! !RBRenameInstanceVariableTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testNonExistantName self shouldFail: (RenameInstanceVariableRefactoring rename: 'foo' to: 'newFoo' in: RBBasicLintRuleTest)! ! !RBRenameInstanceVariableTest methodsFor: 'tests' stamp: 'lr 2/26/2009 14:51'! testRenameInstVar | refactoring class | refactoring := RenameInstanceVariableRefactoring rename: 'classBlock' to: 'asdf' in: RBBasicLintRuleTest. self executeRefactoring: refactoring. class := refactoring model classNamed: #RBBasicLintRuleTest. self assert: (class directlyDefinesInstanceVariable: 'asdf'). self deny: (class directlyDefinesInstanceVariable: 'classBlock'). self assert: (class parseTreeFor: #checkClass:) = (RBParser parseMethod: 'checkClass: aSmalllintContext ^asdf value: aSmalllintContext value: result'). self assert: (class parseTreeFor: #classBlock:) = (RBParser parseMethod: 'classBlock: aBlock asdf := aBlock testMethod1'). self assert: (class parseTreeFor: #initialize) = (RBParser parseMethod: 'initialize super initialize. asdf := [:context :aResult | ]. methodBlock := [:context :aResult | ]. self resultClass: SelectorEnvironment.')! ! RBRefactoringTest subclass: #RBRenameMethodTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBRenameMethodTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testExistingSelector self shouldFail: (RenameMethodRefactoring renameMethod: #checkClass: in: RBBasicLintRuleTest to: #runOnEnvironment: permutation: (1 to: 1))! ! !RBRenameMethodTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testMultipleSelectors self shouldWarn: (RenameMethodRefactoring renameMethod: #checkClass: in: RBBasicLintRuleTest to: #foo: permutation: (1 to: 1))! ! !RBRenameMethodTest methodsFor: 'tests' stamp: 'lr 2/26/2009 15:07'! testRenamePermuteArgs | refactoring class | refactoring := RenameMethodRefactoring renameMethod: ('rename:' , 'two:') asSymbol in: RBRefactoryTestDataApp to: ('rename:' , 'two:') asSymbol permutation: #(2 1 ). self executeRefactoring: refactoring. class := refactoring model classNamed: #RBRefactoryTestDataApp. self assert: (class parseTreeFor: ('rename:' , 'two:') asSymbol) = (RBParser parseMethod: 'rename: argumentMethod two: this ^self printString, this, argumentMethod'). self assert: (class parseTreeFor: #exampleCall) = (RBParser parseMethod: 'exampleCall ^self rename: 2 two: 1')! ! !RBRenameMethodTest methodsFor: 'tests' stamp: 'md 3/15/2006 17:29'! testRenamePrimitive | refactoring count | count := 0. model allReferencesTo: #basicAt:put: do: [:method | count := count + 1]. refactoring := RenameMethodRefactoring model: model renameMethod: #basicAt:put: in: Object to: ('at:' , 'bar:') asSymbol permutation: (1 to: 2). self proceedThroughWarning: [self executeRefactoring: refactoring]. model allReferencesTo: #basicAt:put: do: [:method | count := count - 1. self assert: method source isNil]. model allReferencesTo: ('at:' , 'bar:') asSymbol do: [:method | count := count - 1]. self assert: count = 0! ! !RBRenameMethodTest methodsFor: 'tests' stamp: 'lr 2/26/2009 15:07'! testRenameTestMethod | refactoring class | refactoring := RenameMethodRefactoring renameMethod: ('rename' , 'ThisMethod:') asSymbol in: RBRefactoryTestDataApp to: #renameThisMethod2: permutation: (1 to: 1). self executeRefactoring: refactoring. class := refactoring model classNamed: #RBRefactoryTestDataApp. self assert: (class parseTreeFor: #renameThisMethod2:) = (RBParser parseMethod: 'renameThisMethod2: anArg ^self'). self assert: (class parseTreeFor: #callMethod) = (RBParser parseMethod: 'callMethod ^(self renameThisMethod2: 5)'). self assert: (class parseTreeFor: #symbolReference) = (RBParser parseMethod: 'symbolReference ^ #(#renameThisMethod2: #(4 #renameThisMethod2:))'). self deny: (class directlyDefinesMethod: ('rename' , 'ThisMethod:') asSymbol)! ! !RBRenameMethodTest methodsFor: 'tests' stamp: 'lr 2/26/2009 15:07'! testRenameTestMethod1 | refactoring class | refactoring := RenameMethodRefactoring renameMethod: ('test' , 'Method1') asSymbol in: RBRefactoryTestDataApp to: #testMethod2 permutation: (1 to: 0). self executeRefactoring: refactoring. class := refactoring model classNamed: #RBRefactoryTestDataApp. self assert: (class parseTreeFor: #testMethod2) = (RBParser parseMethod: 'testMethod2 ^self testMethod2 , ([:each | each testMethod2] value: #(#(#testMethod2) 2 #testMethod2))'). self assert: ((refactoring model classNamed: #RBBasicLintRuleTest) parseTreeFor: #classBlock:) = (RBParser parseMethod: 'classBlock: aBlock classBlock := aBlock testMethod2'). self deny: (class directlyDefinesMethod: ('test' , 'Method1') asSymbol)! ! RBRefactoringTest subclass: #RBRenameTemporaryTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBRenameTemporaryTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 15:07'! testBadInterval self shouldFail: (RenameTemporaryRefactoring renameTemporaryFrom: (self convertInterval: (14 to: 17) for: (RBRefactoryTestDataApp sourceCodeAt: #testMethod)) to: 'asdf' in: RBRefactoryTestDataApp selector: #testMethod)! ! !RBRenameTemporaryTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testBadName self shouldFail: (RenameTemporaryRefactoring renameTemporaryFrom: (self convertInterval: (15 to: 19) for: (RBLintRuleTest sourceCodeAt: #openEditor)) to: 'name' in: RBLintRuleTest selector: #openEditor); shouldFail: (RenameTemporaryRefactoring renameTemporaryFrom: (self convertInterval: (15 to: 19) for: (RBLintRuleTest sourceCodeAt: #openEditor)) to: 'rules' in: RBLintRuleTest selector: #openEditor); shouldFail: (RenameTemporaryRefactoring renameTemporaryFrom: (self convertInterval: (15 to: 19) for: (RBLintRuleTest sourceCodeAt: #openEditor)) to: 'DependentFields' in: RBLintRuleTest selector: #openEditor); shouldFail: (RenameTemporaryRefactoring renameTemporaryFrom: (self convertInterval: (15 to: 19) for: (RBLintRuleTest sourceCodeAt: #openEditor)) to: 'a b' in: RBLintRuleTest selector: #openEditor)! ! !RBRenameTemporaryTest methodsFor: 'failure tests' stamp: ''! testModelBadName | class | model := RBNamespace new. class := model classNamed: #Object. class compile: 'aMethod: temp1 ^[| temp2 | temp2 := [:temp3 | temp3 = 5] value: 5. temp2] value' classified: #(#accessing). self shouldFail: (RenameTemporaryRefactoring renameTemporaryFrom: (20 to: 24) to: 'temp3' in: class selector: #aMethod:); shouldFail: (RenameTemporaryRefactoring renameTemporaryFrom: (20 to: 24) to: 'temp1' in: class selector: #aMethod:)! ! !RBRenameTemporaryTest methodsFor: 'tests' stamp: 'lr 8/7/2009 18:03'! testRenameTemporary | refactoring | refactoring := RenameTemporaryRefactoring renameTemporaryFrom: (self convertInterval: (15 to: 19) for: (RBLintRuleTest sourceCodeAt: #openEditor)) to: 'asdf' in: RBLintRuleTest selector: #openEditor. self executeRefactoring: refactoring. self assert: ((refactoring model classNamed: #RBLintRuleTest) parseTreeFor: #openEditor) = (RBParser parseMethod: 'openEditor | asdf | asdf := self failedRules. asdf isEmpty ifTrue: [^self]. asdf size == 1 ifTrue: [^asdf first viewResults]')! ! RBRefactoringTest subclass: #RBTemporaryToInstanceVariableTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBTemporaryToInstanceVariableTest methodsFor: 'set up' stamp: 'md 7/25/2005 15:17'! setUp super setUp. model := Compiler evaluate: self abstractVariableTestData.! ! !RBTemporaryToInstanceVariableTest methodsFor: 'failure tests' stamp: 'lr 2/26/2009 14:51'! testNonExistantName self shouldFail: (TemporaryToInstanceVariableRefactoring class: RBBasicLintRuleTest selector: #checkClass: variable: 'asdf'); shouldFail: (TemporaryToInstanceVariableRefactoring class: RBBasicLintRuleTest selector: #checkClass1: variable: 'aSmalllintContext')! ! !RBTemporaryToInstanceVariableTest methodsFor: 'failure tests' stamp: ''! testRedefinedTemporary | class | class := model classNamed: #Foo. class compile: 'someMethod | instVarName1 | instVarName1 := 4. ^instVarName1' classified: #(#accessing). self shouldFail: (TemporaryToInstanceVariableRefactoring class: class selector: #someMethod variable: 'instVarName1')! ! !RBTemporaryToInstanceVariableTest methodsFor: 'tests' stamp: 'lr 2/26/2009 14:51'! testTemporaryToInstanceVariable | refactoring class | refactoring := TemporaryToInstanceVariableRefactoring class: RBLintRuleTest selector: #displayName variable: 'nameStream'. self executeRefactoring: refactoring. class := refactoring model classNamed: #RBLintRuleTest. self assert: (class parseTreeFor: #displayName) = (RBParser parseMethod: 'displayName nameStream := WriteStream on: (String new: 64). nameStream nextPutAll: self name; nextPutAll: '' (''. self problemCount printOn: nameStream. nameStream nextPut: $). ^nameStream contents'). self assert: (class directlyDefinesInstanceVariable: 'nameStream')! ! RBRefactoringBrowserTest subclass: #RBVariableTypeTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core'! !RBVariableTypeTest methodsFor: 'tests' stamp: 'lr 2/26/2009 14:51'! testBasicLintRuleTypes | typer types | typer := RefactoryTyper new. types := typer guessTypesFor: 'classBlock' in: RBBasicLintRuleTest. "self assert: types size = 1." self assert: ([ ] class withAllSuperclasses detect: [ :each | types includes: (typer model classFor: each) ] ifNone: [ nil ]) notNil. types := typer typesFor: 'methodBlock' in: (typer model classFor: RBBasicLintRuleTest). "self should: [types size = 2]." self assert: ([ ] class withAllSuperclasses detect: [ :each | types includes: (typer model classFor: each) ] ifNone: [ nil ]) notNil. "self should: [types includes: MessageChannel]." typer printString! ! !RBVariableTypeTest methodsFor: 'tests' stamp: 'TestRunner 12/19/2009 18:59'! testCompositeLintRuleTypes | typer types | typer := RefactoryTyper new runOn: RBCompositeLintRuleTest. types := typer guessTypesFor: 'rules'. self assert: (types includes: (typer model classFor: Collection)). types := typer typesFor: '-rules-'. self assert: (types includes: (typer model classFor: RBLintRuleTest)). self assert: (typer guessTypesFor: 'asdf') isEmpty. typer printString! ! !RBVariableTypeTest methodsFor: 'tests' stamp: 'lr 8/7/2009 13:08'! testLintRuleTypes | typer types | typer := RefactoryTyper new. types := typer guessTypesFor: 'name' in: RBLintRuleTest. self assert: types size = 1. self assert: (types includes: (typer model classFor: String))! ! !RBVariableTypeTest methodsFor: 'tests' stamp: ''! testParseTreeTypes | types model | model := RBNamespace new. types := RefactoryTyper typesFor: 'foo' in: (RBParser parseExpression: 'foo printString; testBasicLintRuleTypes; testParseTreeTypes') model: model. self assert: types size = 1. self assert: (types includes: (model classFor: self class))! ! Object subclass: #RBLintRuleTest instanceVariableNames: 'name foo1' classVariableNames: 'Foo1' poolDictionaries: 'TextConstants' category: 'Refactoring-Tests-Core-Data'! RBLintRuleTest subclass: #RBBasicLintRuleTest instanceVariableNames: 'classBlock methodBlock result' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core-Data'! !RBBasicLintRuleTest class methodsFor: 'possible bugs' stamp: ''! abstractClass | detector subclassResponsibilitySymbol | detector := self new. detector name: 'References an abstract class'. detector resultClass: ClassEnvironment. subclassResponsibilitySymbol := 'subclassResponsibility' asSymbol. detector classBlock: [:context :result | (context selectedClass whichSelectorsReferTo: subclassResponsibilitySymbol) isEmpty ifFalse: [(context uses: (Smalltalk associationAt: context selectedClass name ifAbsent: [nil])) ifTrue: [result addClass: context selectedClass]]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'possible bugs' stamp: ''! addRemoveDependents | detector | detector := self new. detector resultClass: ClassEnvironment. detector name: 'Number of addDependent: messages > removeDependent:'. detector classBlock: [:context :result | | count | count := 0. ((Set withAll: (context selectedClass whichSelectorsReferTo: #addDependent:)) addAll: (context selectedClass whichSelectorsReferTo: #removeDependent:); yourself) do: [:sel | (context selectedClass compiledMethodAt: sel) messagesDo: [:each | each == #addDependent: ifTrue: [count := count + 1]. each == #removeDependent: ifTrue: [count := count - 1]]]. count > 0 ifTrue: [result addClass: context selectedClass]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'miscellaneous' stamp: 'lr 11/19/2009 14:47'! assignmentInBlock ^self createParseTreeRule: #( '`@cursor showWhile: [| `@temps | `@.Statements1. `var := `@object]' '`@cursor showWhile: [| `@temps | `@.Statements1. ^`@object]' '[| `@temps | `@.Statements. `var := `@object] ensure: `@block' '[| `@temps | `@.Statements. ^`@object] ensure: `@block' '[| `@temps | `@.Statements. `var := `@object] ifCurtailed: `@block' '[| `@temps | `@.Statements. ^`@object] ifCurtailed: `@block' ) name: 'Unnecessary assignment or return in block'! ! !RBBasicLintRuleTest class methodsFor: 'intention revealing' stamp: ''! assignmentInIfTrue ^self createParseTreeRule: #('`@boolean ifTrue: [| `@temps1 | `@.Statements1. `var := `@object1] ifFalse: [| `@temps2 | `@.Statements2. `var := `@object2]' '`@boolean ifFalse: [| `@temps1 | `@.Statements1. `var := `@object1] ifTrue: [| `@temps2 | `@.Statements2. `var := `@object2]') name: 'Assignment to same variable and end of ifTrue:ifFalse: blocks'! ! !RBBasicLintRuleTest class methodsFor: 'intention revealing' stamp: ''! atIfAbsent ^self createParseTreeRule: #('`@object at: `@atArg ifAbsent: [| `@temps | `@.Statements. `@object at: `@atArg put: `@putArg]' '`@object at: `@atArg ifAbsent: [| `@temps | `@.Statements. `@object at: `@atArg put: `@putArg. `@.xStatements1. `@putArg]') name: 'Uses at:ifAbsent: instead of at:ifAbsentPut:'! ! !RBBasicLintRuleTest class methodsFor: 'miscellaneous' stamp: ''! badMessage | detector badMessages | detector := self new. detector name: 'Sends "questionable" message'. badMessages := self badSelectors. detector classBlock: [:context :result | | selectors | selectors := badMessages inject: Set new into: [:set :each | set addAll: (context selectedClass whichSelectorsReferTo: each); yourself]. selectors do: [:each | result addClass: context selectedClass selector: each]. selectors isEmpty ifFalse: [result searchStrings: badMessages]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'private' stamp: ''! badSelectors ^#(#become: #isKindOf: #changeClassToThatOf: #respondsTo: #isMemberOf: #performMethod: #performMethod:arguments: #performMethod:with: #performMethod:with:with: #performMethod:with:with:with: #allOwners #allOwnersWeakly: #firstOwner #instVarAt: #instVarAt:put: #nextInstance #nextObject #ownerAfter: #primBecome: #halt)! ! !RBBasicLintRuleTest class methodsFor: 'bugs' stamp: ''! booleanPrecedence ^self createParseTreeRule: #('`@object1 | `@object2 = `@object3' '`@object1 | `@object2 == `@object3' '`@object1 & `@object2 = `@object3' '`@object1 & `@object2 == `@object3' '`@object1 | `@object2 ~= `@object3' '`@object1 | `@object2 ~~ `@object3' '`@object1 & `@object2 ~= `@object3' '`@object1 & `@object2 ~~ `@object3') name: 'Uses A | B = C instead of A | (B = C)'! ! !RBBasicLintRuleTest class methodsFor: 'private' stamp: ''! canCall: aSelector in: aClass from: anApplication | methodApp root | (aClass canUnderstand: aSelector) ifFalse: [^false]. root := anApplication rootApplication. methodApp := ((aClass whichClassIncludesSelector: aSelector) compiledMethodAt: aSelector) application rootApplication. ^methodApp == root or: [root isBasedOn: methodApp]! ! !RBBasicLintRuleTest class methodsFor: 'miscellaneous' stamp: 'lr 10/26/2009 22:11'! classNameInSelector | detector | detector := self new. detector name: 'Redundant class name in selector'. detector methodBlock: [:context :result | (context selectedClass isMetaclass and: [(context selector indexOfSubCollection: context selectedClass theNonMetaClass name startingAt: 1) > 0]) ifTrue: [result addClass: context selectedClass selector: context selector]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'unnecessary code' stamp: ''! classNotReferenced | detector | detector := self new. detector name: 'Class not referenced'. detector resultClass: ClassEnvironment. detector classBlock: [:context :result | (context selectedClass isMetaclass or: [context isApplication or: [context selectedClass subclasses isEmpty not]]) ifFalse: [| assoc | assoc := Smalltalk associationAt: context selectedClass name. ((context uses: assoc) or: [context uses: context selectedClass name]) ifFalse: [result addClass: context selectedClass; addClass: context selectedClass class]]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'private' stamp: ''! classShouldNotOverride ^#(#== #class)! ! !RBBasicLintRuleTest class methodsFor: 'possible bugs' stamp: ''! collectionCopyEmpty | detector | detector := self new. detector name: 'Subclass of collection that has instance variable but doesn''t define copyEmpty'. detector resultClass: ClassEnvironment. detector classBlock: [:context :result | (context selectedClass isVariable and: [(context selectedClass includesSelector: #copyEmpty:) not and: [context selectedClass instVarNames isEmpty not and: [context selectedClass inheritsFrom: Collection]]]) ifTrue: [result addClass: context selectedClass]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'intention revealing' stamp: 'lr 11/2/2009 00:14'! collectionMessagesToExternalObject | detector matcher | detector := self new. detector name: 'Sends add:/remove: to external collection'. matcher := RBParseTreeSearcher new. matcher addSearches: (#(#add: #remove: #addAll: #removeAll:) collect: [:each | ('(`@Object `@message: `@args) <1s> `@Arg' expandMacrosWith: each) asString]) -> [:aNode :answer | answer or: [(aNode receiver selector copyFrom: 1 to: (aNode receiver selector size min: 2)) ~= 'as' and: [| receiver | receiver := aNode receiver receiver. receiver isVariable not or: [((#('self' 'super') includes: receiver name) or: [Smalltalk includesKey: receiver name asSymbol]) not]]]]. detector methodBlock: [:context :result | (matcher executeTree: context parseTree initialAnswer: false) ifTrue: [result addClass: context selectedClass selector: context selector]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'intention revealing' stamp: ''! collectionProtocol ^self createParseTreeRule: #('`@collection do: [:`each | | `@temps | `@.Statements1. `@object add: `@arg. `@.Statements2]' '`@collection do: [:`each | | `@temps | `@.Statements1. `@condition ifTrue: [| `@blockTemps | `@.BlockStatements1. `@object add: `each. `@.BlockStatements2]. `@.Statements2]' '`@collection do: [:`each | | `@temps | `@.Statements1. `@condition ifFalse: [| `@blockTemps | `@.BlockStatements1. `@object add: `each. `@.BlockStatements2]. `@.Statements2]') name: 'Uses do: instead of collect: or select:''s'! ! !RBBasicLintRuleTest class methodsFor: 'intention revealing' stamp: ''! consistencyCheck ^self createParseTreeRule: #('`@object size == 0' '`@object size = 0' '`@object size > 0' '`@object size >= 1' '`@object == nil' '`@object = nil') name: 'Uses "size = 0" or "= nil" instead of "isEmpty" or "isNil"'! ! !RBBasicLintRuleTest class methodsFor: 'intention revealing' stamp: ''! contains ^self createParseTreeRule: #('(`@object detect: [:`each | | `@temps| `@.Statements] ifNone: [nil]) isNil' '(`@object detect: [:`each | | `@temps| `@.Statements] ifNone: [nil]) notNil' '(`@object detect: [:`each | | `@temps| `@.Statements] ifNone: [nil]) = nil' '(`@object detect: [:`each | | `@temps| `@.Statements] ifNone: [nil]) == nil' '(`@object detect: [:`each | | `@temps| `@.Statements] ifNone: [nil]) ~= nil' '(`@object detect: [:`each | | `@temps| `@.Statements] ifNone: [nil]) ~~ nil' '`@object detect: [:`each | | `@temps| `@.Statements] ifNone: [| `@temps1 | `@.Statements2. ^`@anything]') name: 'Uses detect:ifNone: instead of contains:'! ! !RBBasicLintRuleTest class methodsFor: 'private' stamp: 'lr 11/2/2009 00:14'! createMatcherFor: codeStrings method: aBoolean | matcher | matcher := RBParseTreeSearcher new. aBoolean ifTrue: [matcher addMethodSearches: codeStrings -> [:aNode :answer | true]] ifFalse: [matcher addSearches: codeStrings -> [:aNode :answer | true]]. ^matcher! ! !RBBasicLintRuleTest class methodsFor: 'instance creation' stamp: ''! createParseTreeRule: codeStrings method: aBoolean name: aName | detector matcher | detector := self new. detector name: aName. matcher := self createMatcherFor: codeStrings method: aBoolean. detector methodBlock: [:context :result | (matcher executeTree: context parseTree initialAnswer: false) ifTrue: [result addClass: context selectedClass selector: context selector]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'instance creation' stamp: ''! createParseTreeRule: codeStrings name: aName ^self createParseTreeRule: codeStrings method: false name: aName! ! !RBBasicLintRuleTest class methodsFor: 'possible bugs' stamp: ''! definesEqualNotHash | detector | detector := self new. detector name: 'Defines = but not hash'. detector resultClass: ClassEnvironment. detector classBlock: [:context :result | ((context selectedClass includesSelector: #=) and: [(context selectedClass includesSelector: #hash) not]) ifTrue: [result addClass: context selectedClass]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'intention revealing' stamp: ''! detectContains ^self createParseTreeRule: #('`@collection do: [:`each | | `@temps | `@.Statements1. `@condition ifFalse: [| `@BlockTemps | `@.BlockStatements1. ^`each]. `@.Statements2]' '`@collection do: [:`each | | `@temps | `@.Statements1. `@condition ifTrue: [| `@BlockTemps | `@.BlockStatements1. ^`each]. `@.Statements2]' '`@collection do: [:`each | | `@temps | `@.Statements1. `@condition ifFalse: [| `@BlockTemps | `@.BlockStatements1. ^true]. `@.Statements2]' '`@Collection do: [:`each | | `@temps | `@.Statements1. `@condition ifTrue: [| `@BlockTemps | `@.BlockStatements1. ^true]. `@.Statements2]' '`@collection do: [:`each | | `@temps | `@.Statements1. `@condition ifFalse: [| `@BlockTemps | `@.BlockStatements1. ^false]. `@.Statements2]' '`@collection do: [:`each | | `@temps | `@.Statements1. `@condition ifTrue: [| `@BlockTemps | `@.BlockStatements1. ^false]. `@.Statements2]') name: 'Uses do: instead of contains: or detect:''s'! ! !RBBasicLintRuleTest class methodsFor: 'unnecessary code' stamp: 'lr 11/2/2009 00:14'! endTrueFalse | detector matcher | detector := self new. detector name: 'Check for same statements at end of ifTrue:ifFalse: blocks'. matcher := (RBParseTreeSearcher new) addSearches: #('`@object ifTrue: [| `@temps1 | `@.Statements1. `.Statement] ifFalse: [| `@temps2 | `@.Statements2. `.Statement]' '`@object ifTrue: [| `@temps1 | `.Statement. `@.Statements1] ifFalse: [| `@temps2 | `.Statement. `@.Statements2]' '`@object ifFalse: [| `@temps1 | `@.Statements1. `.Statement] ifTrue: [| `@temps2 | `@.Statements2. `.Statement]' '`@object ifFalse: [| `@temps1 | `.Statement. `@.Statements1] ifTrue: [| `@temps2 | `.Statement. `@.Statement2]') -> [:aNode :answer | answer or: [| node | node := aNode arguments first body statements last. (node isVariable and: [node = aNode arguments last body statements last]) not]]; yourself. detector methodBlock: [:context :result | (matcher executeTree: context parseTree initialAnswer: false) ifTrue: [result addClass: context selectedClass selector: context selector]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'unnecessary code' stamp: 'lr 11/2/2009 00:14'! equalsTrue | detector matcher | detector := self new. detector name: 'Unnecessary "= true"'. matcher := (RBParseTreeSearcher new) addSearches: #('true' 'false') -> [:aNode :answer | answer or: [aNode parent isMessage and: [#(#= #== #~= #~~) includes: aNode parent selector]]]; yourself. detector methodBlock: [:context :result | (matcher executeTree: context parseTree initialAnswer: false) ifTrue: [result addClass: context selectedClass selector: context selector]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'unnecessary code' stamp: ''! equivalentSuperclassMethods | detector | detector := self new. detector name: 'Methods equivalently defined in superclass'. detector methodBlock: [:context :result | context selectedClass superclass notNil ifTrue: [(context selectedClass superclass canUnderstand: context selector) ifTrue: [(((context selectedClass superclass whichClassIncludesSelector: context selector) compiledMethodAt: context selector) equivalentTo: context compiledMethod) ifTrue: [result addClass: context selectedClass selector: context selector]]]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'unnecessary code' stamp: ''! extraBlock ^self createParseTreeRule: (#('value' 'value: `@value' 'value: `@value1 value: `@value2' 'value: `@value1 value: `value2 value: `@value3' 'valueWithArguments: `@values') collect: [:each | '[:`@params | | `@temps | `@.statements] ' , each]) name: 'Block immediately evaluated'! ! !RBBasicLintRuleTest class methodsFor: 'possible bugs' stamp: 'lr 11/19/2009 14:48'! fileBlocks ^self createParseTreeRule: #('[| `@temps | `var := `@object. `@.statements] ensure: [`var `@messages: `@args]' '[| `@temps | `var := `@object. `@.statements] ifCurtailed: [`var `@messages: `@args]') name: 'Assignment inside unwind blocks should be outside.'! ! !RBBasicLintRuleTest class methodsFor: 'miscellaneous' stamp: 'bh 4/8/2000 19:05'! fullBlocks "skip this test in squeak." " | detector | detector := self new. detector name: 'Method with full blocks'. detector methodBlock: [:context :result | context compiledMethod withAllBlockMethodsDo: [:method | method needsHybridFrame ifTrue: [result addClass: context selectedClass selector: context selector]]]. ^detector"! ! !RBBasicLintRuleTest class methodsFor: 'intention revealing' stamp: ''! guardingClause ^self createParseTreeRule: #('`@MethodName: `@args | `@temps | `@.Statements. `@condition ifTrue: [| `@BlockTemps | `.Statement1. `.Statement2. `@.BStatements]' '`@MethodName: `@args | `@temps | `@.Statements. `@condition ifFalse: [| `@BlockTemps | `.Statement1. `.Statement2. `@.BStatements]') method: true name: 'Guarding clauses'! ! !RBBasicLintRuleTest class methodsFor: 'miscellaneous' stamp: 'lr 11/2/2009 00:14'! ifTrueBlocks | detector matcher | detector := self new. detector name: 'Non-blocks in ifTrue:/ifFalse: messages'. matcher := RBParseTreeSearcher new. matcher addSearches: #('``@condition ifTrue: ``@block' '``@condition ifFalse: ``@block' '``@condition ifTrue: ``@block1 ifFalse: ``@block2' '``@condition ifFalse: ``@block1 ifTrue: ``@block2') -> [:aNode :answer | answer or: [(aNode arguments detect: [:each | each isBlock not] ifNone: [nil]) notNil]]. detector methodBlock: [:context :result | (matcher executeTree: context parseTree initialAnswer: false) ifTrue: [result addClass: context selectedClass selector: context selector]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'intention revealing' stamp: 'lr 11/2/2009 00:14'! ifTrueReturns | detector matcher | detector := self new. detector name: 'ifTrue:/ifFalse: returns instead of and:/or:''s'. matcher := RBParseTreeSearcher new. matcher addSearches: #('| `@temps | ``@.Statements. ``@object ifTrue: [^``@value1]. ^``@value2' '| `@temps | ``@.Statements. ``@object ifFalse: [^``@value1]. ^``@value2') -> [:aNode :answer | answer or: [| node | node := (aNode statements at: aNode statements size - 1) arguments first body statements last value. "``@value1" (node isLiteral and: [{true. false} includes: node value]) or: [node := aNode statements last value. node isLiteral and: [{true. false} includes: node value]]]]. detector methodBlock: [:context :result | (matcher executeTree: context parseTree initialAnswer: false) ifTrue: [result addClass: context selectedClass selector: context selector]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'unnecessary code' stamp: ''! implementedNotSent | detector | detector := self new. detector name: 'Methods implemented but not sent'. detector methodBlock: [:context :result | (context uses: context selector) ifFalse: [result addClass: context selectedClass selector: context selector]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'miscellaneous' stamp: ''! instVarInSubclasses | detector | detector := self new. detector name: 'Instance variables defined in all subclasses'. detector result: nil pullUpInstVar. detector classBlock: [:context :result | | subs | subs := context selectedClass subclasses. subs size > 1 ifTrue: [| sels | sels := Bag new. subs do: [:each | sels addAll: each instVarNames]. sels asSet do: [:val | (sels occurrencesOf: val) == subs size ifTrue: [result addInstVar: val for: context selectedClass]]]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'unnecessary code' stamp: 'lr 11/2/2009 00:14'! justSendsSuper | detector matcher | detector := self new. detector name: 'Method just sends super message'. matcher := RBParseTreeSearcher justSendsSuper. detector methodBlock: [:context :result | (context parseTree tag isNil and: [matcher executeMethod: context parseTree initialAnswer: false]) ifTrue: [result addClass: context selectedClass selector: context selector]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'private' stamp: ''! longMethodSize ^10! ! !RBBasicLintRuleTest class methodsFor: 'miscellaneous' stamp: 'lr 11/2/2009 00:14'! longMethods | detector matcher | detector := self new. detector name: 'Long methods'. matcher := RBParseTreeSearcher new. matcher addSearch: '`.Stmt' -> [:aNode :answer | (aNode children inject: answer into: [:sum :each | matcher executeTree: each initialAnswer: sum]) + 1]. detector methodBlock: [:context :result | (matcher executeTree: context parseTree initialAnswer: 0) >= self longMethodSize ifTrue: [result addClass: context selectedClass selector: context selector]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'private' stamp: ''! metaclassShouldNotOverride ^#(#name #comment)! ! !RBBasicLintRuleTest class methodsFor: 'intention revealing' stamp: 'lr 11/2/2009 00:14'! minMax | detector matcher | detector := self new. detector name: 'Uses ifTrue:/ifFalse: instead of min: or max:'. matcher := RBParseTreeSearcher new. matcher addSearches: #('(`x `message: `@y) `ifTrue: [`x := `@y]' '(`@x `message: `@y) `ifTrue: [`@x] `ifFalse: [`@y]') -> [:aNode :answer | answer or: [(#(#ifTrue: #ifFalse: #ifTrue:ifFalse: #ifFalse:ifTrue:) includes: aNode selector) and: [#(#< #<= #> #>=) includes: aNode receiver selector]]]. detector methodBlock: [:context :result | (matcher executeTree: context parseTree initialAnswer: false) ifTrue: [result addClass: context selectedClass selector: context selector]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'intention revealing' stamp: 'lr 9/5/2010 10:40'! missingSubclassResponsibility | detector | detector := self new. detector name: 'Method defined in all subclasses, but not in superclass'. "detector resultClass: MultiEnvironment." detector classBlock: [:context :result | | subs | subs := context selectedClass subclasses. subs size > 1 & context selectedClass isMetaclass not ifTrue: [| sels | sels := Bag new. subs do: [:each | sels addAll: each selectors]. sels asSet do: [:each | ((sels occurrencesOf: each) == subs size and: [(context selectedClass canUnderstand: each) not]) ifTrue: [| envName | envName := context selectedClass name , '>>', each. subs do: [:subClass | result addClass: subClass selector: each into: envName]]]]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'possible bugs' stamp: 'lr 11/2/2009 00:14'! missingYourself | detector matcher | detector := self new. detector name: 'Possible missing "; yourself"'. matcher := RBParseTreeSearcher new. matcher addSearch: '``@xobject `@messages: ``@args' -> [:aNode :answer | answer or: [aNode parent isCascade and: [aNode isDirectlyUsed and: [aNode selector ~~ #yourself]]]]. detector methodBlock: [:context :result | (matcher executeTree: context parseTree initialAnswer: false) ifTrue: [result addClass: context selectedClass selector: context selector]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'possible bugs' stamp: 'lr 9/4/2010 17:29'! modifiesCollection | detector addSearcher | detector := self new. detector name: 'Modifies collection while iterating over it'. addSearcher := RBBasicLintRuleTest modifiesCollection. detector methodBlock: [:context :result | addSearcher executeTree: context parseTree initialAnswer: false. addSearcher answer ifTrue: [result addClass: context selectedClass selector: context selector]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'private' stamp: 'nk 2/23/2005 16:09'! new ^super new! ! !RBBasicLintRuleTest class methodsFor: 'unnecessary code' stamp: 'lr 4/29/2010 19:35'! onlyReadOrWritten | detector | detector := self new. detector name: 'Instance variables not read AND written'. detector result: nil references. detector classBlock: [:context :result | | allSubclasses | allSubclasses := context selectedClass withAllSubclasses. context selectedClass instVarNames do: [:each | | reads writes | reads := false. writes := false. allSubclasses detect: [:class | reads ifFalse: [reads := (class whichSelectorsReallyRead: each) isEmpty not]. writes ifFalse: [writes := (class whichSelectorsWrite: each) isEmpty not]. reads & writes] ifNone: [result addInstVar: each for: context selectedClass]]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'bugs' stamp: ''! overridesSpecialMessage | detector | detector := self new. detector name: 'Overrides a "special" message'. detector resultClass: ClassEnvironment. detector classBlock: [:context :result | ((context selectedClass isMetaclass ifTrue: [self metaclassShouldNotOverride] ifFalse: [self classShouldNotOverride]) detect: [:each | context selectedClass superclass notNil and: [(context selectedClass superclass canUnderstand: each) and: [context selectedClass includesSelector: each]]] ifNone: [nil]) notNil ifTrue: [result addClass: context selectedClass]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'miscellaneous' stamp: 'lr 11/2/2009 00:14'! precedence | detector matcher | detector := self new. detector name: 'Inspect instances of "A + B * C" might be "A + (B * C)"'. matcher := RBParseTreeSearcher new. matcher addSearches: #('``@A + ``@B * ``@C' '``@A - ``@B * ``@C') -> [:aNode :answer | answer or: [aNode receiver parentheses isEmpty]]. detector methodBlock: [:context :result | (matcher executeTree: context parseTree initialAnswer: false) ifTrue: [result addClass: context selectedClass selector: context selector]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'accessing' stamp: ''! protocols ^#('bugs' 'possible bugs' 'unnecessary code' 'intention revealing' 'miscellaneous')! ! !RBBasicLintRuleTest class methodsFor: 'miscellaneous' stamp: 'lr 10/26/2009 22:11'! refersToClass | detector | detector := self new. detector name: 'Refers to class name instead of "self class"'. detector classBlock: [:context :result | | sels className | className := context selectedClass theNonMetaClass name. sels := context selectedClass whichSelectorsReferTo: (Smalltalk associationAt: className). sels isEmpty ifFalse: [result addSearchString: className. sels do: [:each | result addClass: context selectedClass selector: each]]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'possible bugs' stamp: 'lr 11/2/2009 00:14'! returnsBooleanAndOther | detector matcher | detector := self new. detector name: 'Returns a boolean and non boolean'. matcher := RBParseTreeSearcher new. matcher addSearch: '^``@xObject' -> [:aNode :answer | answer add: aNode value; yourself]. detector methodBlock: [:context :result | | hasBool hasSelf | hasBool := false. hasSelf := context parseTree lastIsReturn not. (matcher executeTree: context parseTree initialAnswer: Set new) do: [:each | hasBool := hasBool or: [(each isLiteral and: [{true. false} includes: each value]) or: [each isMessage and: [#(#and: #or:) includes: each selector]]]. hasSelf := hasSelf or: [(each isVariable and: [each name = 'self']) or: [each isLiteral and: [({true. false} includes: each value) not]]]]. hasSelf & hasBool ifTrue: [result addClass: context selectedClass selector: context selector]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'possible bugs' stamp: ''! returnsIfTrue ^self createParseTreeRule: #('^`@condition ifTrue: [| `@temps | `@.statements]' '^`@condition ifFalse: [| `@temps | `@.statements]') name: 'Returns value of ifTrue:/ifFalse: without ifFalse:/ifTrue: block'! ! !RBBasicLintRuleTest class methodsFor: 'possible bugs' stamp: ''! sendsDifferentSuper | detector | detector := self new. detector name: 'Sends different super message'. detector methodBlock: [:context :result | | message | (message := context superMessages detect: [:each | each ~= context selector] ifNone: [nil]) notNil ifTrue: [result addSearchString: message. result addClass: context selectedClass selector: context selector]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'bugs' stamp: ''! sentNotImplemented | detector | detector := self new. detector name: 'Messages sent but not implemented'. detector methodBlock: [:context :result | | message | message := context messages detect: [:each | (context implements: each) not] ifNone: [nil]. message isNil ifTrue: [message := context superMessages detect: [:each | context selectedClass superclass isNil or: [(context selectedClass superclass canUnderstand: each) not]] ifNone: [nil]. message isNil ifTrue: [message := context selfMessages detect: [:each | (context selectedClass canUnderstand: each) not] ifNone: [nil]]]. message notNil ifTrue: [result addSearchString: message. result addClass: context selectedClass selector: context selector]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'possible bugs' stamp: ''! sentNotImplementedInApplication | detector | detector := self new. detector name: 'Messages sent but not implemented in application'. detector methodBlock: [:context :result | | message class block | message := context messages detect: [:each | (context isItem: each in: context application) not] ifNone: [nil]. class := context selectedClass. block := [:each | | app | app := context application. (self canCall: each in: class from: app) not]. message isNil ifTrue: [message := context selfMessages detect: block ifNone: [nil]]. message isNil ifTrue: [class := class superclass. class isNil ifTrue: [context superMessages isEmpty ifFalse: [message := context superMessages asArray first]] ifFalse: [message := context superMessages detect: block ifNone: [nil]]]. message notNil ifTrue: [result addSearchString: message. result addClass: context selectedClass selector: context selector]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'intention revealing' stamp: ''! sizeCheck ^self createParseTreeRule: (#(#do: #collect: #reject: #select:) collect: [:each | '`@object size > 0 ifTrue: [`@object ' , each , ' [:`each | | `@temps | `@.Statements1]. `@.Statements2]']) , (#(#do: #collect: #reject: #select:) collect: [:each | '`@object isEmpty ifFalse: [`@object ' , each , ' [:`each | | `@temps | `@.Statements1]. `@.Statements2]']) name: 'Unnecessary size check'! ! !RBBasicLintRuleTest class methodsFor: 'miscellaneous' stamp: 'lr 11/2/2009 00:14'! stringConcatenation | detector matcher concatenationMatcher | detector := self new. detector name: 'String concatenation instead of streams'. matcher := RBParseTreeSearcher new. concatenationMatcher := RBParseTreeSearcher new. concatenationMatcher addSearch: '`@receiver , `@argument' -> [:aNode :answer | true]. matcher addSearches: #('``@collection do: [:`each | | `@temps | ``@.Statements]' '``@collection do: [:`each | | `@temps | ``@.Statements] separatedBy: [| `@temps1 | ``@.Statements1]' '``@number to: ``@endNumber do: [:`i | | `@temps | ``@.Statements]' '``@collection detect: [:`each | | `@temps | ``@.Statements]' '``@collection detect: [:`each | | `@temps | ``@.Statements] ifNone: [| `@temps1 | ``@.Statements1]' '``@collection select: [:`each | | `@temps | ``@.Statements]' '``@collection inject: ``@value into: [:`each | | `@temps | ``@.Statements]') -> [:aNode :answer | answer or: [(aNode arguments detect: [:each | each isBlock and: [concatenationMatcher executeTree: each initialAnswer: false]] ifNone: [nil]) notNil]]. detector methodBlock: [:context :result | (matcher executeTree: context parseTree initialAnswer: false) ifTrue: [result addClass: context selectedClass selector: context selector]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'private' stamp: ''! subclassOf: aClass overrides: aSelector | subs | subs := aClass subclasses. 1 to: subs size do: [:i | | each | each := subs at: i. (each includesSelector: aSelector) ifTrue: [^true]. (self subclassOf: each overrides: aSelector) ifTrue: [^true]]. ^false! ! !RBBasicLintRuleTest class methodsFor: 'bugs' stamp: ''! subclassResponsibilityNotDefined | detector subclassResponsibilitySymbol | detector := self new. subclassResponsibilitySymbol := 'subclassResponsibility' asSymbol. detector name: 'Subclass responsibility not defined'. detector classBlock: [:context :result | (context selectedClass whichSelectorsReferTo: subclassResponsibilitySymbol) do: [:each | (context selectedClass withAllSubclasses detect: [:class | class subclasses isEmpty and: [(class whichClassIncludesSelector: each) == context selectedClass]] ifNone: [nil]) notNil ifTrue: [result addClass: context selectedClass selector: each]]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'private' stamp: ''! superMessages ^#(#release #postCopy #postBuildWith: #preBuildWith: #postOpenWith: #noticeOfWindowClose: #initialize)! ! !RBBasicLintRuleTest class methodsFor: 'possible bugs' stamp: ''! superSends | detector | detector := self new. detector name: 'Missing super sends'. detector methodBlock: [:context :result | (context selectedClass isMetaclass not and: [self superMessages includes: context selector]) ifTrue: [(context selectedClass superclass notNil and: [context selectedClass superclass canUnderstand: context selector]) ifTrue: [(context superMessages includes: context selector) ifFalse: [result addClass: context selectedClass selector: context selector]]]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'possible bugs' stamp: 'lr 11/2/2009 00:14'! tempVarOverridesInstVar | detector matcher vars varName | detector := self new. detector name: 'Instance variable overridden by temporary variable'. matcher := (RBParseTreeSearcher new) addArgumentSearch: '`xxxvar' -> [:aNode :answer | answer or: [varName := aNode name. vars includes: varName]]; yourself. detector methodBlock: [:context :result | vars := context instVarNames. (matcher executeTree: context parseTree initialAnswer: false) ifTrue: [result addClass: context selectedClass selector: context selector. result addSearchString: varName]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'possible bugs' stamp: 'lr 11/2/2009 00:14'! tempsReadBeforeWritten | detector | detector := self new. detector name: 'Temporaries read before written'. detector methodBlock: [:context :result | | variables | variables := RBParseTreeSearcher nonBlockTempsIn: context parseTree. variables isEmpty ifFalse: [(RBReadBeforeWrittenTester variablesReadBeforeWrittenIn: context parseTree) do: [:each | result addClass: context selectedClass selector: context selector. result addSearchString: each]]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'possible bugs' stamp: 'lr 11/2/2009 00:14'! threeElementPoint | detector matcher | detector := self new. detector name: 'Possible three element point (e.g., x @ y + q @ r)'. matcher := (RBParseTreeSearcher new) addSearch: '``@x @ ``@y' -> [:aNode :answer | answer or: [| current | current := aNode parent. [current isNil or: [current isMessage and: [current selector == #@ or: [current selector isInfix not]]]] whileFalse: [current := current parent]. (current isNil or: [current isMessage and: [current selector isInfix not]]) not]]; yourself. detector methodBlock: [:context :result | (matcher executeTree: context parseTree initialAnswer: false) ifTrue: [result addClass: context selectedClass selector: context selector]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'intention revealing' stamp: 'lr 11/2/2009 00:14'! toDo | detector matcher | detector := self new. detector name: 'Uses to:do: instead of do:, with:do: or timesRepeat:'. matcher := RBParseTreeSearcher new. matcher addSearch: '1 to: ``@object size do: [:`each | | `@temps | `@.Statements]' -> [:aNode :answer | answer or: [| varName variableMatcher | varName := aNode arguments last arguments first name. "`each" variableMatcher := RBParseTreeSearcher new. variableMatcher addSearch: varName -> [:node :ans | ans and: [node parent isMessage and: [node parent selector == #at:]]]. variableMatcher executeTree: aNode arguments last body initialAnswer: true]]. detector methodBlock: [:context :result | (matcher executeTree: context parseTree initialAnswer: false) ifTrue: [result addClass: context selectedClass selector: context selector]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'unnecessary code' stamp: ''! unreferencedVariables | detector | detector := self new. detector name: 'Variables not referenced'. detector result: nil unreferenced. detector classBlock: [:context :result | | allSubclasses | allSubclasses := context selectedClass withAllSubclasses. context selectedClass instVarNames do: [:each | allSubclasses detect: [:class | (class whichSelectorsAccess: each) isEmpty not] ifNone: [result addInstVar: each for: context selectedClass]]. context selectedClass isMetaclass ifFalse: [context selectedClass classPool associationsDo: [:each | (context uses: each) ifFalse: [result addClassVar: each key for: context selectedClass]]]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'possible bugs' stamp: 'lr 11/2/2009 00:14'! usesAdd | detector addSearcher | detector := self new. detector name: 'Uses the result of an add: message'. addSearcher := RBParseTreeSearcher usesResultOfAdd. detector methodBlock: [:context :result | (addSearcher executeTree: context parseTree initialAnswer: false) ifTrue: [result addClass: context selectedClass selector: context selector]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'bugs' stamp: ''! usesTrue | detector trueBinding falseBinding | detector := self new. trueBinding := Smalltalk associationAt: #True. falseBinding := Smalltalk associationAt: #False. detector name: 'Uses True/False instead of true/false'. detector methodBlock: [:context :result | | method | method := context compiledMethod. ((method referencesLiteral: trueBinding) or: [method referencesLiteral: falseBinding]) ifTrue: [result addClass: context selectedClass selector: context selector. result searchStrings: #('True' 'False')]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'miscellaneous' stamp: 'lr 11/2/2009 00:14'! utilityMethods | detector | detector := self new. detector name: 'Utility methods'. detector methodBlock: [:context :result | (context selectedClass isMetaclass | (context selector numArgs == 0) or: [(context protocols detect: [:each | (self utilityProtocols detect: [:protocol | protocol match: each] ifNone: [nil]) notNil] ifNone: [nil]) notNil]) ifFalse: [(self subclassOf: context selectedClass overrides: context selector) ifFalse: [(context superMessages isEmpty and: [context selfMessages isEmpty]) ifTrue: [(RBParseTreeSearcher references: context selectedClass allInstVarNames , context selectedClass allClassVarNames asArray , #('self') in: context parseTree) isEmpty ifTrue: [result addClass: context selectedClass selector: context selector]]]]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'private' stamp: ''! utilityProtocols "If a method is defined in one of these protocols, then don't check if its a utility method." ^#('*utilit*')! ! !RBBasicLintRuleTest class methodsFor: 'miscellaneous' stamp: 'lr 11/2/2009 00:14'! variableAssignedLiteral | detector | detector := self new. detector name: 'Variable is only assigned a single literal value'. detector result: nil references. detector classBlock: [:context :result | | allSubclasses | allSubclasses := context selectedClass withAllSubclasses. context selectedClass instVarNames do: [:each | | defClass selector | (allSubclasses inject: 0 into: [:sum :class | | sels | sels := class whichSelectorsWrite: each. sels size == 1 ifTrue: [selector := sels asArray first. defClass := class]. sum + sels size]) == 1 ifTrue: [| tree searcher | searcher := RBParseTreeSearcher new. searcher addSearch: (each , ' := ``@object') -> [:aNode :answer | answer isNil and: [aNode value isLiteral]]. tree := defClass parseTreeFor: selector. tree notNil ifTrue: [(searcher executeTree: tree initialAnswer: nil) == true ifTrue: [result addInstVar: each for: context selectedClass]]]]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'unnecessary code' stamp: ''! variableReferencedOnce | detector | detector := self new. detector name: 'Variable referenced in only one method and always assigned first'. detector classBlock: [:context :result | | allSubclasses | allSubclasses := context selectedClass withAllSubclasses. context selectedClass instVarNames do: [:each | | defClass selector | (allSubclasses inject: 0 into: [:sum :class | | sels | sels := class whichSelectorsAccess: each. sels size == 1 ifTrue: [selector := sels asArray first. defClass := class]. sum + sels size]) == 1 ifTrue: [| tree | tree := defClass parseTreeFor: selector. tree notNil ifTrue: [(RBReadBeforeWrittenTester readBeforeWritten: (Array with: each) in: tree) isEmpty ifTrue: [result addClass: defClass selector: selector. result addSearchString: each]]]]]. ^detector! ! !RBBasicLintRuleTest class methodsFor: 'intention revealing' stamp: ''! whileTrue ^self createParseTreeRule: #('| `@temps | `@.Statements1. [`index <= `@stop] whileTrue: [| `@blockTemps | `@.BlockStmts1. `index := `index + 1]. `@.Statements2' '| `@temps | `@.Statements1. [`index < `@stop] whileTrue: [| `@blockTemps | `@.BlockStmts1. `index := `index + 1]. `@.Statements2' '| `@temps | `@.Statements1. [`index >= `@stop] whileTrue: [| `@blockTemps | `@.BlockStmts1. `index := `index - 1]. `@.Statements2' '| `@temps | `@.Statements1. [`index > `@stop] whileTrue: [| `@blockTemps | `@.BlockStmts1. `index := `index - 1]. `@.Statements2') name: 'Uses whileTrue: instead of to:do:'! ! !RBBasicLintRuleTest class methodsFor: 'miscellaneous' stamp: 'lr 11/2/2009 00:14'! yourselfNotUsed | detector addSearcher | detector := self new. detector name: 'Doesn''t use the result of a yourself message'. addSearcher := RBParseTreeSearcher new. addSearcher addSearch: '`@object yourself' -> [:aNode :answer | answer or: [aNode isUsed not]]. detector methodBlock: [:context :result | (addSearcher executeTree: context parseTree initialAnswer: false) ifTrue: [result addClass: context selectedClass selector: context selector]]. ^detector! ! !RBBasicLintRuleTest methodsFor: 'accessing' stamp: ''! checkClass: aSmalllintContext ^classBlock value: aSmalllintContext value: result! ! !RBBasicLintRuleTest methodsFor: 'accessing' stamp: ''! checkMethod: aSmalllintContext ^methodBlock value: aSmalllintContext value: result! ! !RBBasicLintRuleTest methodsFor: 'initialize-release' stamp: ''! classBlock: aBlock classBlock := aBlock testMethod1! ! !RBBasicLintRuleTest methodsFor: 'accessing' stamp: 'bh 4/3/2000 10:19'! foobar ^#( true false )! ! !RBBasicLintRuleTest methodsFor: 'initialize-release' stamp: ''! initialize super initialize. classBlock := [:context :aResult | ]. methodBlock := [:context :aResult | ]. self resultClass: SelectorEnvironment! ! !RBBasicLintRuleTest methodsFor: 'testing' stamp: ''! isEmpty ^result isEmpty! ! !RBBasicLintRuleTest methodsFor: 'initialize-release' stamp: ''! methodBlock: aBlock methodBlock := aBlock! ! !RBBasicLintRuleTest methodsFor: 'accessing' stamp: ''! problemCount ^result problemCount! ! !RBBasicLintRuleTest methodsFor: 'initialize-release' stamp: ''! resetResult result := result copyEmpty. result label: name! ! !RBBasicLintRuleTest methodsFor: 'accessing' stamp: ''! result ^result! ! !RBBasicLintRuleTest methodsFor: 'initialize-release' stamp: ''! result: aResult result := aResult copyEmpty! ! !RBBasicLintRuleTest methodsFor: 'initialize-release' stamp: ''! resultClass: aClass result := aClass new! ! !RBBasicLintRuleTest methodsFor: 'private' stamp: ''! viewResults result openEditor! ! RBLintRuleTest subclass: #RBCompositeLintRuleTest instanceVariableNames: 'rules' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core-Data'! !RBCompositeLintRuleTest class methodsFor: 'instance creation' stamp: ''! allRules ^self ruleFor: self protocol: 'all checks'! ! !RBCompositeLintRuleTest class methodsFor: 'all checks' stamp: 'lr 2/26/2009 14:51'! lintChecks ^ self rules: (RBBasicLintRuleTest protocols collect: [ :each | self ruleFor: RBBasicLintRuleTest protocol: each ]) name: 'Lint checks'! ! !RBCompositeLintRuleTest class methodsFor: 'instance creation' stamp: ''! ruleFor: aClass protocol: aProtocol ^self rules: (((BrowserEnvironment new selectorsFor: aProtocol asSymbol in: aClass class) collect: [:selector | aClass perform: selector]) asSortedCollection: [:a :b | a name < b name]) name: ((aProtocol asString copy) at: 1 put: aProtocol first asUppercase; yourself)! ! !RBCompositeLintRuleTest class methodsFor: 'instance creation' stamp: ''! rules: aCollection ^self new rules: aCollection! ! !RBCompositeLintRuleTest class methodsFor: 'instance creation' stamp: ''! rules: aCollection name: aString ^(self new) rules: aCollection; name: aString; yourself! ! !RBCompositeLintRuleTest class methodsFor: 'all checks' stamp: 'lr 2/26/2009 14:51'! transformations ^ self ruleFor: RBTransformationRuleTest protocol: 'transformations'! ! !RBCompositeLintRuleTest methodsFor: 'accessing' stamp: ''! checkClass: aSmalllintContext rules do: [:each | each checkClass: aSmalllintContext. Processor yield]! ! !RBCompositeLintRuleTest methodsFor: 'accessing' stamp: ''! checkMethod: aSmalllintContext rules do: [:each | each checkMethod: aSmalllintContext. Processor yield]! ! !RBCompositeLintRuleTest methodsFor: 'accessing' stamp: ''! failedRules ^rules inject: OrderedCollection new into: [:oc :each | oc addAll: each failedRules; yourself]! ! !RBCompositeLintRuleTest methodsFor: 'testing' stamp: ''! hasConflicts ^(rules detect: [:each | each hasConflicts] ifNone: [nil]) notNil! ! !RBCompositeLintRuleTest methodsFor: 'testing' stamp: ''! isComposite ^true! ! !RBCompositeLintRuleTest methodsFor: 'testing' stamp: ''! isEmpty ^(rules detect: [:each | each isEmpty not] ifNone: [nil]) isNil! ! !RBCompositeLintRuleTest methodsFor: 'accessing' stamp: ''! problemCount ^rules inject: 0 into: [:count :each | count + each problemCount]! ! !RBCompositeLintRuleTest methodsFor: 'initialize-release' stamp: ''! resetResult rules do: [:each | each resetResult]! ! !RBCompositeLintRuleTest methodsFor: 'accessing' stamp: ''! rules ^rules! ! !RBCompositeLintRuleTest methodsFor: 'initialize-release' stamp: ''! rules: aCollection rules := aCollection! ! !RBCompositeLintRuleTest methodsFor: 'private' stamp: ''! viewResults rules do: [:each | each viewResults]! ! RBLintRuleTest subclass: #RBFooLintRuleTest instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core-Data'! RBFooLintRuleTest subclass: #RBTransformationRuleTest instanceVariableNames: 'rewriteRule builder class' classVariableNames: 'RecursiveSelfRule' poolDictionaries: '' category: 'Refactoring-Tests-Core-Data'! !RBTransformationRuleTest class methodsFor: 'transformations' stamp: ''! assignmentInIfTrue ^self rewrite: #( #('``@Boolean ifTrue: [`variable := ``@true] ifFalse: [`variable := ``@false]' "->" '`variable := ``@Boolean ifTrue: [``@true] ifFalse: [``@false]') #('``@Boolean ifFalse: [`variable := ``@true] ifTrue: [`variable := ``@false]' "->" '`variable := ``@Boolean ifFalse: [``@true] ifTrue: [``@false]')) methods: false name: 'Move variable assignment outside of single statement ifTrue:ifFalse: blocks'! ! !RBTransformationRuleTest class methodsFor: 'transformations' stamp: ''! atIfAbsent ^self rewrite: #( #('``@dictionary at: ``@key ifAbsent: [| `@temps | ``@.Statements1. ``@dictionary at: ``@key put: ``@object. ``@.Statements2. ``@object]' "->" '``@dictionary at: ``@key ifAbsentPut: [| `@temps | ``@.Statements1. ``@.Statements2. ``@object]') #('``@dictionary at: ``@key ifAbsent: [| `@temps | ``@.Statements. ``@dictionary at: ``@key put: ``@object]' "->" '``@dictionary at: ``@key ifAbsentPut: [| `@temps | ``@.Statements. ``@object]')) methods: false name: 'at:ifAbsent: -> at:ifAbsentPut:'! ! !RBTransformationRuleTest class methodsFor: 'transformations' stamp: ''! betweenAnd ^self rewrite: #( #('``@a >= ``@b and: [``@a <= ``@c]' "->" '``@a between: ``@b and: ``@c') #('``@a >= ``@b & (``@a <= ``@c)' "->" '``@a between: ``@b and: ``@c') #('``@b <= ``@a and: [``@a <= ``@c]' "->" '``@a between: ``@b and: ``@c') #('``@b <= ``@a & (``@a <= ``@c)' "->" '``@a between: ``@b and: ``@c') #('``@a <= ``@c and: [``@a >= ``@b]' "->" '``@a between: ``@b and: ``@c') #('``@a <= ``@c & (``@a >= ``@b)' "->" '``@a between: ``@b and: ``@c') #('``@c >= ``@a and: [``@a >= ``@b]' "->" '``@a between: ``@b and: ``@c') #('``@c >= ``@a & (``@a >= ``@b)' "->" '``@a between: ``@b and: ``@c') #('``@a >= ``@b and: [``@c >= ``@a]' "->" '``@a between: ``@b and: ``@c') #('``@a >= ``@b & (``@c >= ``@a)' "->" '``@a between: ``@b and: ``@c') #('``@b <= ``@a and: [``@c >= ``@a]' "->" '``@a between: ``@b and: ``@c') #('``@b <= ``@a & (``@c >= ``@a)' "->" '``@a between: ``@b and: ``@c') #('``@a <= ``@c and: [``@b <= ``@a]' "->" '``@a between: ``@b and: ``@c') #('``@a <= ``@c & (``@b <= ``@a)' "->" '``@a between: ``@b and: ``@c') #('``@c >= ``@a and: [``@b <= ``@a]' "->" '``@a between: ``@b and: ``@c') #('``@c >= ``@a & (``@b <= ``@a)' "->" '``@a between: ``@b and: ``@c')) methods: false name: '"a >= b and: [a <= c]" -> "a between: b and: c"'! ! !RBTransformationRuleTest class methodsFor: 'transformations' stamp: ''! detectIfNone ^self rewrite: #( #('(``@collection detect: [:`each | | `@temps | ``@.Statements] ifNone: [nil]) isNil' "->" '(``@collection contains: [:`each | | `@temps | ``@.Statements]) not') #('(``@collection detect: [:`each | | `@temps | ``@.Statements] ifNone: [nil]) = nil' "->" '(``@collection contains: [:`each | | `@temps | ``@.Statements]) not') #('(``@collection detect: [:`each | | `@temps | ``@.Statements] ifNone: [nil]) == nil' "->" '(``@collection contains: [:`each | | `@temps | ``@.Statements]) not') #('(``@collection detect: [:`each | | `@temps | ``@.Statements] ifNone: [nil]) notNil' "->" '``@collection contains: [:`each | | `@temps | ``@.Statements]') #('(``@collection detect: [:`each | | `@temps | ``@.Statements] ifNone: [nil]) ~= nil' "->" '``@collection contains: [:`each | | `@temps | ``@.Statements]') #('(``@collection detect: [:`each | | `@temps | ``@.Statements] ifNone: [nil]) ~~ nil' "->" '``@collection contains: [:`each | | `@temps | ``@.Statements]')) methods: false name: 'detect:ifNone: -> contains:'! ! !RBTransformationRuleTest class methodsFor: 'transformations' stamp: ''! equalNil ^self rewrite: #( #('``@object = nil' "->" '``@object isNil') #('``@object == nil' "->" '``@object isNil') #('``@object ~= nil' "->" '``@object notNil') #('``@object ~~ nil' "->" '``@object notNil')) methods: false name: '= nil -> isNil AND ~= nil -> notNil'! ! !RBTransformationRuleTest class methodsFor: 'transformations' stamp: ''! guardClause ^self rewrite: #( #('`@methodName: `@args | `@temps | `@.Statements. `@condition ifTrue: [| `@trueTemps | `.Statement1. `.Statement2. `@.Statements1]' "->" '`@methodName: `@args | `@temps `@trueTemps | `@.Statements. `@condition ifFalse: [^self]. `.Statement1. `.Statement2. `@.Statements1') #('`@methodName: `@args | `@temps | `@.Statements. `@condition ifFalse: [| `@falseTemps | `.Statement1. `.Statement2. `@.Statements1]' "->" '`@methodName: `@args | `@temps `@falseTemps | `@.Statements. `@condition ifTrue: [^self]. `.Statement1. `.Statement2. `@.Statements1')) methods: true name: 'Eliminate guarding clauses'! ! !RBTransformationRuleTest class methodsFor: 'class initialization' stamp: 'lr 11/2/2009 00:14'! initializeAfterLoad1 RecursiveSelfRule := RBParseTreeSearcher new. RecursiveSelfRule addMethodSearches: #('`@methodName: `@args | `@temps | self `@methodName: `@args' '`@methodName: `@args | `@temps | ^self `@methodName: `@args') -> [:aNode :answer | true]! ! !RBTransformationRuleTest class methodsFor: 'transformations' stamp: ''! minMax ^self rewrite: #( #('``@a < ``@b ifTrue: [``@a] ifFalse: [``@b]' "->" '``@a min: ``@b') #('``@a <= ``@b ifTrue: [``@a] ifFalse: [``@b]' "->" '``@a min: ``@b') #('``@a > ``@b ifTrue: [``@a] ifFalse: [``@b]' "->" '``@a max: ``@b') #('``@a >= ``@b ifTrue: [``@a] ifFalse: [``@b]' "->" '``@a max: ``@b') #('``@a < ``@b ifTrue: [``@b] ifFalse: [``@a]' "->" '``@a max: ``@b') #('``@a <= ``@b ifTrue: [``@b] ifFalse: [``@a]' "->" '``@a max: ``@b') #('``@a > ``@b ifTrue: [``@b] ifFalse: [``@a]' "->" '``@a min: ``@b') #('``@a >= ``@b ifTrue: [``@b] ifFalse: [``@a]' "->" '``@a min: ``@b') #('`a < ``@b ifTrue: [`a := ``@b]' "->" '`a := `a max: ``@b') #('`a <= ``@b ifTrue: [`a := ``@b]' "->" '`a := `a max: ``@b') #('`a < ``@b ifFalse: [`a := ``@b]' "->" '`a := `a min: ``@b') #('`a <= ``@b ifFalse: [`a := ``@b]' "->" '`a := `a min: ``@b') #('`a > ``@b ifTrue: [`a := ``@b]' "->" '`a := `a min: ``@b') #('`a >= ``@b ifTrue: [`a := ``@b]' "->" '`a := `a min: ``@b') #('`a > ``@b ifFalse: [`a := ``@b]' "->" '`a := `a max: ``@b') #('`a >= ``@b ifFalse: [`a := ``@b]' "->" '`a := `a max: ``@b') #('``@b < `a ifTrue: [`a := ``@b]' "->" '`a := `a min: ``@b') #('``@b <= `a ifTrue: [`a := ``@b]' "->" '`a := `a min: ``@b') #('``@b < `a ifFalse: [`a := ``@b]' "->" '`a := `a max: ``@b') #('``@b <= `a ifFalse: [`a := ``@b]' "->" '`a := `a max: ``@b') #('``@b > `a ifTrue: [`a := ``@b]' "->" '`a := `a max: ``@b') #('``@b >= `a ifTrue: [`a := ``@b]' "->" '`a := `a max: ``@b') #('``@b > `a ifFalse: [`a := ``@b]' "->" '`a := `a min: ``@b') #('``@b >= `a ifFalse: [`a := ``@b]' "->" '`a := `a min: ``@b')) methods: false name: 'Rewrite ifTrue:ifFalse: using min:/max:'! ! !RBTransformationRuleTest class methodsFor: 'transformations' stamp: ''! notElimination ^self rewrite: #( #('``@object not not' "->" '``@object') #('``@object not ifTrue: ``@block' "->" '``@object ifFalse: ``@block') #('``@object not ifFalse: ``@block' "->" '``@object ifTrue: ``@block') #('``@collection select: [:`each | | `@temps | ``@.Statements. ``@object not]' "->" '``@collection reject: [:`each | | `@temps | ``@.Statements. ``@object]') #('``@collection reject: [:`each | | `@temps | ``@.Statements. ``@object not]' "->" '``@collection select: [:`each | | `@temps | ``@.Statements. ``@object]') #('[| `@temps | ``@.Statements. ``@object not] whileTrue: ``@block' "->" '[| `@temps | ``@.Statements. ``@object] whileFalse: ``@block') #('[| `@temps | ``@.Statements. ``@object not] whileFalse: ``@block' "->" '[| `@temps | ``@.Statements. ``@object] whileTrue: ``@block') #('[| `@temps | ``@.Statements. ``@object not] whileTrue' "->" '[| `@temps | ``@.Statements. ``@object] whileFalse') #('[| `@temps | ``@.Statements. ``@object not] whileFalse' "->" '[| `@temps | ``@.Statements. ``@object] whileTrue') #('(``@a <= ``@b) not' "->" '``@a > ``@b') #('(``@a < ``@b) not' "->" '``@a >= ``@b') #('(``@a = ``@b) not' "->" '``@a ~= ``@b') #('(``@a == ``@b) not' "->" '``@a ~~ ``@b') #('(``@a ~= ``@b) not' "->" '``@a = ``@b') #('(``@a ~~ ``@b) not' "->" '``@a == ``@b') #('(``@a >= ``@b) not' "->" '``@a < ``@b') #('(``@a > ``@b) not' "->" '``@a <= ``@b')) methods: false name: 'Eliminate unnecessary not''s'! ! !RBTransformationRuleTest class methodsFor: 'class initialization' stamp: ''! nuke RecursiveSelfRule := nil! ! !RBTransformationRuleTest class methodsFor: 'instance creation' stamp: 'lr 11/2/2009 00:14'! rewrite: stringArrays methods: aBoolean name: aName | rewriteRule | rewriteRule := RBParseTreeRewriter new. stringArrays do: [:each | aBoolean ifTrue: [rewriteRule addMethodSearch: each first -> each last] ifFalse: [rewriteRule addSearch: each first -> each last]]. ^(self new) name: aName; rewriteUsing: rewriteRule; yourself! ! !RBTransformationRuleTest class methodsFor: 'transformations' stamp: ''! showWhileBlocks ^self rewrite: #( #('``@cursor showWhile: [| `@temps | ``@.Statements. `var := ``@object]' "->" '`var := ``@cursor showWhile: [| `@temps | ``@.Statements. ``@object]') #('``@cursor showWhile: [| `@temps | ``@.Statements. ^``@object]' "->" '^``@cursor showWhile: [| `@temps | ``@.Statements. ``@object]')) methods: false name: 'Move assignment out of showWhile: blocks'! ! !RBTransformationRuleTest class methodsFor: 'transformations' stamp: ''! superSends ^(self new) name: 'Rewrite super messages to self messages when both refer to same method'; superSends; yourself! ! !RBTransformationRuleTest class methodsFor: 'transformations' stamp: 'lr 11/19/2009 14:49'! unwindBlocks ^self rewrite: #( #('[| `@temps | ``@.Statements. `var := ``@object] ensure: ``@block' "->" '`var := [| `@temps | ``@.Statements. ``@object] ensure: ``@block') #('[| `@temps | ``@.Statements. ^``@object] ensure: ``@block' "->" '^[| `@temps | ``@.Statements. ``@object] ensure: ``@block') #('[| `@temps | ``@.Statements. `var := ``@object] ifCurtailed: ``@block' "->" '`var := [| `@temps | ``@.Statements. ``@object] ifCurtailed: ``@block') #('[| `@temps | ``@.Statements. ^``@object] ifCurtailed: ``@block' "->" '^[| `@temps | ``@.Statements. ``@object] ifCurtailed: ``@block')) methods: false name: 'Move assignment out of unwind blocks'! ! !RBTransformationRuleTest methodsFor: 'accessing' stamp: ''! checkMethod: aSmalllintContext class := aSmalllintContext selectedClass. (rewriteRule executeTree: aSmalllintContext parseTree) ifTrue: [(RecursiveSelfRule executeTree: rewriteRule tree initialAnswer: false) ifFalse: [builder compile: rewriteRule tree printString in: class classified: aSmalllintContext protocols]]! ! !RBTransformationRuleTest methodsFor: 'testing' stamp: ''! hasConflicts ^true! ! !RBTransformationRuleTest methodsFor: 'testing' stamp: ''! isEmpty ^builder changes isEmpty! ! !RBTransformationRuleTest methodsFor: 'accessing' stamp: ''! problemCount ^builder problemCount! ! !RBTransformationRuleTest methodsFor: 'accessing' stamp: ''! resetResult builder := CompositeRefactoryChange new! ! !RBTransformationRuleTest methodsFor: 'initialize-release' stamp: ''! rewriteUsing: searchReplacer rewriteRule := searchReplacer. self resetResult! ! !RBTransformationRuleTest methodsFor: 'rules' stamp: 'lr 11/2/2009 00:14'! superSends | rule | rule := RBParseTreeRewriter new. rule addSearch: 'super `@message: ``@args' -> ( [:aNode | (class withAllSubclasses detect: [:each | each includesSelector: aNode selector] ifNone: [nil]) isNil] -> 'self `@message: ``@args'). self rewriteUsing: rule! ! !RBTransformationRuleTest methodsFor: 'private' stamp: ''! viewResults "I reset the result so that we don't fill up memory with methods to compile in the builder." builder inspect. self resetResult! ! !RBLintRuleTest methodsFor: 'accessing' stamp: ''! checkClass: aSmalllintContext! ! !RBLintRuleTest methodsFor: 'accessing' stamp: ''! checkMethod: aSmalllintContext! ! !RBLintRuleTest methodsFor: 'accessing' stamp: ''! displayName | nameStream | nameStream := WriteStream on: (String new: 64). nameStream nextPutAll: self name; nextPutAll: ' ('. self problemCount printOn: nameStream. nameStream nextPut: $). ^nameStream contents! ! !RBLintRuleTest methodsFor: 'private' stamp: ''! failedRules ^self isEmpty ifTrue: [#()] ifFalse: [Array with: self]! ! !RBLintRuleTest methodsFor: 'testing' stamp: ''! hasConflicts ^false! ! !RBLintRuleTest methodsFor: 'initialize-release' stamp: ''! initialize name := ''! ! !RBLintRuleTest methodsFor: 'testing' stamp: ''! isComposite ^false! ! !RBLintRuleTest methodsFor: 'testing' stamp: ''! isEmpty self subclassResponsibility! ! !RBLintRuleTest methodsFor: 'testing' stamp: 'lr 2/26/2009 15:07'! junk ^ RBRefactoryTestDataApp printString copyFrom: 1 to: CR! ! !RBLintRuleTest methodsFor: 'accessing' stamp: ''! name ^name! ! !RBLintRuleTest methodsFor: 'accessing' stamp: ''! name: aString name := aString! ! !RBLintRuleTest methodsFor: 'accessing' stamp: 'lr 8/7/2009 17:38'! openEditor | rules | rules := self failedRules. rules isEmpty ifTrue: [^self]. rules size == 1 ifTrue: [^rules first viewResults]! ! !RBLintRuleTest methodsFor: 'printing' stamp: ''! printOn: aStream name isNil ifTrue: [super printOn: aStream] ifFalse: [aStream nextPutAll: name]! ! !RBLintRuleTest methodsFor: 'accessing' stamp: ''! problemCount ^self subclassResponsibility! ! !RBLintRuleTest methodsFor: 'initialize-release' stamp: ''! resetResult! ! !RBLintRuleTest methodsFor: 'accessing' stamp: ''! run ^Object printOn: self! ! !RBLintRuleTest methodsFor: 'accessing' stamp: ''! runOnEnvironment: anEnvironment ^Object printOn: self onEnvironment: anEnvironment! ! !RBLintRuleTest methodsFor: 'private' stamp: ''! viewResults self subclassResponsibility! ! Object subclass: #RBRefactoryTestDataApp instanceVariableNames: 'temporaryVariable' classVariableNames: '' poolDictionaries: '' category: 'Refactoring-Tests-Core-Data'! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! asOrderedCollectionNotNeeded self foo addAll: (1 to: 10) asOrderedCollection! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! assignmentInBlock [^self printString] ensure: [self close]! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: 'nk 3/5/2005 15:28'! assignmentInIfTrue | variable | self isVariable ifTrue: [variable := self] ifFalse: [variable := self printString]. ^variable! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: 'md 3/14/2006 16:47'! atIfAbsent ^ Smalltalk at: #MyTest ifAbsent: [| collection | collection := #(). Smalltalk at: #MyTest put: collection]! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! badMessage self become: String new! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! booleanPrecedence ^true & 4 = 45! ! !RBRefactoryTestDataApp methodsFor: 'test' stamp: ''! callFoo ^self testFoo: 5! ! !RBRefactoryTestDataApp methodsFor: 'test' stamp: ''! callMethod ^self renameThisMethod: 5! ! !RBRefactoryTestDataApp methodsFor: 'inline' stamp: ''! called: anObject on1: aBlock | each | each := anObject printString. Transcript show: each; cr. aBlock value: each! ! !RBRefactoryTestDataApp methodsFor: 'inline' stamp: ''! called: anObject on: aBlock Transcript show: anObject printString; cr. aBlock value! ! !RBRefactoryTestDataApp methodsFor: 'inline' stamp: ''! caller | anObject | anObject := 5. self called: anObject + 1 on: [^anObject]! ! !RBRefactoryTestDataApp methodsFor: 'inline' stamp: ''! caller1 | anObject | anObject := 5. self called: anObject + 1 on1: [:each | each printString. ^anObject]! ! !RBRefactoryTestDataApp methodsFor: 'inline' stamp: ''! caller2 ^(1 to: 10) inject: 1 into: [:sum :each | sum * (self foo: each)]! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! collectSelectNotUsed (1 to: 10) select: [:each | each = 4]! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! collectionMessagesToExternalObject self someObject collection remove: 10! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! collectionProtocol | newCollection | newCollection := OrderedCollection new. (1 to: 10) asOrderedCollection do: [:each | | new | new := each * 2. newCollection add: new]. ^newCollection! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! consistencyCheck ^(1 to: 10) at: 1! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: 'nk 3/5/2005 15:28'! contains ^((1 to: 10) detect: [:each | each > 2] ifNone: [nil]) isNil! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: 'lr 7/1/2008 10:14'! cruft self halt! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! detectContains ^(1 to: 10) do: [:each | each > 2 ifTrue: [^each]]! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! endTrueFalse self isVariable ifTrue: [self printString. self isVariable printString] ifFalse: [self printString. ^4]! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! equalNotUsed | string | string = '' yourself. (1 to: 10) do: [:i | string := i printString]. ^string! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! equalsTrue ^true == self! ! !RBRefactoryTestDataApp methodsFor: 'test' stamp: ''! exampleCall ^self rename: 1 two: 2! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! extraBlock ^[:arg | arg + 43] value: 45! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! fileBlocks | file | ^ [file := 'asdf' asFilename readStream. file contents] ensure: [file close]! ! !RBRefactoryTestDataApp methodsFor: 'inline' stamp: ''! foo: aValue ^(1 to: 10) inject: aValue into: [:sum :each | sum + each]! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! fullBlocks ^[thisContext]! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! guardingClause self isSymbol ifFalse: [self printString. self isSymbol printString]! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! ifTrueReturns self isSymbol ifFalse: [^true]. ^false! ! !RBRefactoryTestDataApp methodsFor: 'inline' stamp: ''! inlineComponent | a | a := 5. ^a class superclass; hasImmediateInstances; yourself! ! !RBRefactoryTestDataApp methodsFor: 'inline' stamp: ''! inlineFailed | x y q | x := 5. y := 10. q := x + 1 fooMax: y. ^q! ! !RBRefactoryTestDataApp methodsFor: 'test' stamp: ''! inlineFoo: aBlock | bar baz asdf | bar := aBlock value: self. baz := bar + bar. asdf := baz + bar. ^asdf! ! !RBRefactoryTestDataApp methodsFor: 'test' stamp: ''! inlineJunk | asdf | asdf := self inlineFoo: [:each | | temp | temp := each. temp , temp]. ^asdf foo: [:bar | | baz | baz := bar. baz * baz]! ! !RBRefactoryTestDataApp methodsFor: 'inline' stamp: ''! inlineLast 5 = 3 ifTrue: [^self caller] ifFalse: [^self caller2]! ! !RBRefactoryTestDataApp methodsFor: 'inline' stamp: ''! inlineMax | x y q | x := 5. y := 10. q := x + 1 max: y. ^q! ! !RBRefactoryTestDataApp methodsFor: 'test' stamp: ''! inlineMethod | temp | temp := self foo; inlineMethod; bar. ^temp! ! !RBRefactoryTestDataApp methodsFor: 'test' stamp: ''! inlineParameterMethod: aSymbol ^aSymbol isSymbol! ! !RBRefactoryTestDataApp methodsFor: 'inline' stamp: ''! inlineTemporary | temp | self isNil ifTrue: [temp := 4]. ^temp! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! isLiteral ^false! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! justSendsSuper super justSendsSuper! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! literalArrayCharacters ^#($a $b $c) includes: $a! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: 'nk 3/4/2005 14:52'! literalArrayWithTrueFalseOrNil | a b c | a := #(true false nil). b := #(#true #false #nil). c := {true. false. nil}. ^{a. b. c}! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: 'nk 3/4/2005 16:40'! literalArrayWithTrueFalseOrNil2 | b c | b := #(#true #false #nil). c := #(#true (#true #false #nil) #false #nil). ^b! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! longMethods self printString. self printString. self isVariable ifTrue: [self printString]. self isVariable ifTrue: [self printString]. self isVariable ifTrue: [self printString]. self isVariable ifTrue: [self printString]! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: 'nk 3/5/2005 15:28'! minMax "Bug in 3<5 ifTrue: [3] ifFalse: [5]" ^3<5 ifTrue: [3] ifFalse: [5] " | var | var := 4. var < 5 ifTrue: [var := 5]. ^var"! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! missingYourself ^(OrderedCollection new) add: 1; add: 2; removeFirst! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! modifiesCollection | collection | collection := (1 to: 10) asOrderedCollection. collection do: [:each | each > 5 ifTrue: [collection remove: each]]. ^collection! ! !RBRefactoryTestDataApp methodsFor: 'test' stamp: ''! moveDefinition | temp | ^(self collect: [:each | temp := each printString. temp , temp]) select: [:each | temp := each size. temp odd]! ! !RBRefactoryTestDataApp methodsFor: 'inline' stamp: ''! multipleCalls self caller2. self caller2! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: 'nk 3/5/2005 14:51'! noIsNil: arg ^arg = nil or: [ arg ~= nil ]! ! !RBRefactoryTestDataApp methodsFor: 'test' stamp: ''! noMoveDefinition | temp | ^(self collect: [:each | temp := each printString. temp , temp]) select: [:each | temp := each size + temp]! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! precedence ^self isArray ifFalse: [self block + 5 * 34] ifTrue: [self printString = 10]! ! !RBRefactoryTestDataApp methodsFor: 'accessing' stamp: ''! referencesConditionFor: aClass | environment association | ^(RBCondition withBlock: [association := Smalltalk associationAt: aClass name ifAbsent: [self refactoringError: 'Could not find class']. environment := (self environment referencesTo: association) | (self environment referencesTo: aClass name). environment isEmpty]) errorMacro: aClass , ' is referenced.Browse references?'; errorBlock: [environment openEditor]; yourself! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: 'lr 2/26/2009 15:07'! refersToClass ^ RBRefactoryTestDataApp! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! release self printString! ! !RBRefactoryTestDataApp methodsFor: 'test' stamp: ''! rename: this two: argumentMethod ^self printString , this , argumentMethod! ! !RBRefactoryTestDataApp methodsFor: 'test' stamp: ''! renameThisMethod: anArg ^self! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! returnInEnsure [self error: 'asdf'] ensure: [^4]! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! returnsBooleanAndOther self isVariable ifTrue: [^false]. self printString! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! returnsIfTrue ^self isNil ifTrue: [4]! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: 'bh 4/2/2000 22:25'! searchingLiteral ^self printString = #a or: [#() = self printString | ( #() == self printString)]! ! !RBRefactoryTestDataApp methodsFor: 'test' stamp: ''! selectorNotReferenced ^self selectorNotReferenced + 4! ! !RBRefactoryTestDataApp methodsFor: 'test' stamp: ''! sendInlineParameterMethod ^self inlineParameterMethod: #(#asdf)! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: 'nk 3/5/2005 15:28'! sendsDifferentSuper super printString! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! sizeCheck self isEmpty ifFalse: [self do: [:each | Transcript show: each; cr]]! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! stringConcatenation | string | string := '' yourself. (1 to: 10) do: [:i | string := string , i printString]. ^string! ! !RBRefactoryTestDataApp methodsFor: 'test' stamp: ''! symbolReference ^#(#renameThisMethod: #(4 #renameThisMethod:))! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! tempVarOverridesInstVar | temporaryVariable | temporaryVariable := 4. ^temporaryVariable! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! tempsReadBeforeWritten | temp | self isVariable ifTrue: [temp := 4]. ^temp! ! !RBRefactoryTestDataApp methodsFor: 'test' stamp: ''! testFoo: anObject ^self class + anObject! ! !RBRefactoryTestDataApp methodsFor: 'test' stamp: ''! testMethod ^self class! ! !RBRefactoryTestDataApp methodsFor: 'test' stamp: ''! testMethod1 ^self testMethod1 , ([:each | each testMethod1] value: #(#(#testMethod1) 2 #testMethod1))! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! threeElementPoint ^5 @ 5 + 6 @ 6! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! toDo 1 to: self size do: [:i | (self at: i) printString]! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! toDoCollect | array | array := Array new: 10. 1 to: 10 do: [:i | array at: i put: i * i]. ^array! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! toDoWithIncrement | counter | counter := 0. 1 to: 10 by: 2 do: [:i | counter := counter + 2]. ^counter! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! usesAdd ^(1 to: 10) asOrderedCollection addAll: (11 to: 20)! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: 'nk 2/25/2005 16:50'! variableAssignedLiteral temporaryVariable := #() ! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! whileTrue | i | i := 1. [i < self size] whileTrue: [(self at: i) printString. i := i + 1]! ! !RBRefactoryTestDataApp methodsFor: 'lint' stamp: ''! yourselfNotUsed self printString; printString; yourself! !