How to add an instance variable using Refactoring Browser?

I want to add an instance variable programmatically to an existing class using Refactoring Browser:

| theClass className | className := #MyClass. theClass := (RBClass existingNamed: className) model: (RBNamespace new classNamed: className; yourself); yourself. theClass addInstanceVariable: 'testIVar' 

but the class does not change with the new instance variable, what am I missing?

+4
source share
1 answer

You forgot to do your refactoring. try it

 | model className theClass iVarName | className := #MyClass. iVarName := 'testIVar'. model := RBNamespace new classNamed: className; yourself. theClass := (RBClass existingNamed: className) model: model; yourself. (RBAddInstanceVariableRefactoring model: model variable: iVarName class: theClass) execute. 

you might want to add autodomain access methods (getter and setter) for the new instance variable

 (RBCreateAccessorsForVariableRefactoring model: model variable: iVarName class: theClass classVariable: false) execute 
+6
source

Source: https://habr.com/ru/post/1481818/


All Articles