- live browsing of Self object memory -

lobby traitsselfMethodText

CopyDowns: vector

CreatorPath: traits selfMethodText

Module: methodText

parent* = traits abstractMethodText
isDisassembled = ( method mustBeDisassembled)
storeStringWorks = falseno asMethodText

conversions

asCode = ( copy formatCode)
asMethod = ( copy formatMethod)
asSlotContents = ( copy formatSlotContents)

creation

originalSource: = ( self)
sourceOrBytecodes = ( isDisassembled ifTrue: [method disassemble] False: [method source])
initializeForMethod: =
( | s |
    method: aMirror.
    s: sourceOrBytecodes.
    originalSource: s.
    lines: convertToLines: s.
    nullIfEmpty)

formatting

formatMethodBody =
( 
    detabify.
    leftShrinkwrap.
    addSlotList.
    removeFirstLineIf: firstLine isAllWhiteSpace)
formatMethodBodyWithoutSlots =
( 
    detabify.
    leftShrinkwrap.
    removeFirstLineIf: firstLine isAllWhiteSpace.
    self)

helpers

addSlotList =
( | sl |
    sl: convertToLines: slotList.
    firstLine isAllWhiteSpace ifTrue: [
      sl last: sl last, firstLine.
      lines removeFirst.
    ].
    isDisassembled ifTrue: [ lines addFirst: '' ].
    lines addAllFirst: sl.
    self)
format: =
( 
    detabify.
    leftShrinkwrap.
    addSlotList.
    removeFirstLineIf: firstLineTest.
    indentBody: indentation.
    parenthesize.
    self)
formatCode = ( detabify. leftShrinkwrap. indentBody: indentation. self)
formatMethod = ( format: [ firstLine isAllWhiteSpace ])
formatSlotContents =
( 
    indentation: 4.
    format: [ (height = 2) && [firstLine isAllWhiteSpace] ])
indentBody: =
( 
    indent: n.
    firstLine: firstLine leftShrinkwrapped.
    self)
parenthesize =
( 
    firstLine: '( ', firstLine.
    lastLine: lastLine isAllWhiteSpace ifTrue: ')'
                                        False: [ lastLine, ')' ].
    self)
removeFirstLineIf: =
( 
    test value ifTrue: [ lines removeFirst ].
    nullIfEmpty.
    self)
shrinkLine: = ( i > 0)
slotList =
( | m <- list. maxLineLength. maxMaxLineLength <- 70. 
      sl <- '| '. slop = 5. slotSeparator = '. '. totalSize |

    "Do a bit of fiddling to try to get the lines to be all
     approximately the same length, without going too far
     over either 70 characters or the length of the longest
     line in the method (whichever is greater). -- Adam, 8/04"

    m: method evalStringsForLocalSlots.

    m isEmpty ifTrue: [^ ''].

    totalSize: sl size.
    m do: [|:s| totalSize: totalSize + s size + slotSeparator size].

    lines do: [|:line| maxMaxLineLength: maxMaxLineLength max: line size].

    maxLineLength:  (totalSize /+ (totalSize /+ maxMaxLineLength)) + slop.

    m   doFirst: [|:s| sl: sl, s]
     MiddleLast: [|:s| sl: sl, slotSeparator.
                       (sl lastLine size + s size) > maxLineLength ifTrue: [
                         sl: sl, '\n  '.
                       ].
                       sl: sl, s].
    sl, ' |')