'From Squeak3.8alpha of ''17 July 2004'' [latest update: #6211] on 22 September 2004 at 9:32:01 pm'! "Change Set: RefStrmObsolCls-tk Date: 19 September 2003 Author: Ted Kaehler V2: stef: Changed Smalltalk by SystemNavigation default at the right place please check. It is really too late. SmartReferenceStrm is in charge of converting reading in old .pr files and taking care of instances of classes that have changed shape. It also handles obsolete classes. It gives the user a chance to name a new class that old instances will be converted to. In 2000 Bob Arning made major changes, but these were never extended to converting the instances of obsolete classes. This changeSet fixes that."! !SmartRefStream methodsFor: 'read write' stamp: 'tk 9/19/2003 15:21'! mapClass: incoming "See if the old class named nm exists. If so, return it. If not, map it to a new class, and save the mapping in renamed. " | cls oldVer sel nm | self flag: #bobconv. nm _ renamed at: incoming ifAbsent: [incoming]. "allow pre-mapping around collisions" (nm endsWith: ' class') ifFalse: [cls _ Smalltalk at: nm ifAbsent: [nil]. cls ifNotNil: [^ cls]] "Known class. It will know how to translate the instance." ifTrue: [cls _ Smalltalk at: nm substrings first asSymbol ifAbsent: [nil]. cls ifNotNil: [^ cls class]]. "Known class. It will know how to translate the instance." oldVer _ self versionSymbol: (structures at: nm). sel _ nm asString. sel at: 1 put: (sel at: 1) asLowercase. sel _ sel, oldVer. "i.e. #rectangleoc4" Symbol hasInterned: sel ifTrue: [:symb | (self class canUnderstand: sel asSymbol) ifTrue: [ reshaped ifNil: [reshaped _ Dictionary new]. cls _ self perform: sel asSymbol]]. "This class will take responsibility" cls ifNil: [cls _ self writeClassRenameMethod: sel was: nm fromInstVars: (structures at: nm). cls class == String ifTrue: [cls _ nil]]. cls ifNotNil: [renamed at: nm put: cls name]. ^ cls ! ! !SmartRefStream methodsFor: 'class changed shape' stamp: 'kfr 9/22/2004 21:30'! writeClassRenameMethod: sel was: oldName fromInstVars: oldList "The class coming is unknown. Ask the user for the existing class it maps to. If got one, write a method, and restart the obj fileIn. If none, write a dummy method and get the user to complete it later. " | tell choice newName answ code | self flag: #bobconv. tell _ 'Reading an instance of ', oldName, '. Which modern class should it translate to?'. answ _ (PopUpMenu labels: 'Let me type the name now Let me think about it Let me find a conversion file on the disk') startUpWithCaption: tell. answ = 1 ifTrue: [ tell := 'Name of the modern class {1} should translate to:' translated format: {oldName}. choice _ FillInTheBlank request: tell. "class name" (choice size = 0) ifTrue: [answ _ 'conversion method needed'] ifFalse: [newName _ choice. answ _ Smalltalk at: newName asSymbol ifAbsent: ['conversion method needed']. answ class == String ifFalse: [renamed at: oldName asSymbol put: answ name]]]. (answ = 3) | (answ = 0) ifTrue: [self close. ^ 'conversion method needed']. answ = 2 ifTrue: [answ _ 'conversion method needed']. answ = 'conversion method needed' ifTrue: [ self close. newName _ 'PutNewClassHere']. code _ WriteStream on: (String new: 500). code nextPutAll: sel; cr. code cr; tab; nextPutAll: '^ ', newName. "Return new class" self class compile: code contents classified: 'conversion'. newName = 'PutNewClassHere' ifTrue: [ self inform: 'Please complete the following method and then read-in the object file again.'. SystemNavigation default browseAllImplementorsOf: sel asSymbol]. "The class version number only needs to change under one specific circumstance. That is when the first letters of the instance variables have stayed the same, but their meaning has changed. A conversion method is needed, but this system does not know it. If this is true for class Foo, define classVersion in Foo class. Beware of previous object fileouts already written after the change in meaning, but before bumping the version number. They have the old (wrong) version number, say 2. If this is true, your method must be able to test the data and successfully read files that say version 2 but are really 3." ^ answ! !