Explainer.st
changeset 4646 023f2d14b83d
parent 4645 593fe39d4cf1
child 4673 1e092670cf8f
equal deleted inserted replaced
4645:593fe39d4cf1 4646:023f2d14b83d
       
     1 "{ Encoding: utf8 }"
       
     2 
     1 "
     3 "
     2  COPYRIGHT (c) 1993 by Claus Gittinger
     4  COPYRIGHT (c) 1993 by Claus Gittinger
     3               All Rights Reserved
     5               All Rights Reserved
     4 
     6 
     5  This software is furnished under a license and may be used
     7  This software is furnished under a license and may be used
   288         |clsName action1 action2|
   290         |clsName action1 action2|
   289 
   291 
   290         implMethod := implClass compiledMethodAt:selector.
   292         implMethod := implClass compiledMethodAt:selector.
   291         clsName := implClass name.
   293         clsName := implClass name.
   292         clsName := self asLink:clsName to:(self actionToBrowseClass:implClass selector:selector).
   294         clsName := self asLink:clsName to:(self actionToBrowseClass:implClass selector:selector).
   293         "/ info := '%1 » %2' bindWith:clsName "allBold" with:selectorString.
   295         "/ info := '%1 » %2' bindWith:clsName "allBold" with:selectorString.
   294         info := '%1 %2' bindWith:clsName with:(implMethod methodDefinitionTemplateForSelector:selector).
   296         info := '%1 %2' bindWith:clsName with:(implMethod methodDefinitionTemplateForSelector:selector).
   295         info := self asLink:info to:(action1 := self actionToBrowseClass:implClass selector:selector info:nil).
   297         info := self asLink:info to:(action1 := self actionToBrowseClass:implClass selector:selector info:nil).
   296         
   298         
   297         redefiningClasses size ~~ 0 ifTrue:[
   299         redefiningClasses size ~~ 0 ifTrue:[
   298             redefiningClasses size == 1 ifTrue:[
   300             redefiningClasses size == 1 ifTrue:[
   571 
   573 
   572 fetchCommentOfMethod:mthd
   574 fetchCommentOfMethod:mthd
   573     "retrieve the comment of a method 
   575     "retrieve the comment of a method 
   574      (if possible and there is one; otherwise, return nil)"
   576      (if possible and there is one; otherwise, return nil)"
   575 
   577 
   576     |methodSource methodComment lines maxNumLines|
   578     |methodComment lines maxNumLines|
   577 
   579 
   578     self withWaitCursorDo:[
   580     self withWaitCursorDo:[
   579         SourceCodeManagerError handle:[:ex |
   581         SourceCodeManagerError handle:[:ex |
   580         ] do:[
   582         ] do:[
   581             methodSource := mthd source.
       
   582             methodComment := mthd comment
   583             methodComment := mthd comment
   583         ].
   584         ].
   584     ].
   585     ].
   585         
   586         
   586     methodComment isEmptyOrNil ifTrue:[^ nil].
   587     methodComment isEmptyOrNil ifTrue:[^ nil].
   587     
   588     
   588     lines := methodComment asStringCollection.
   589     lines := methodComment asStringCollection.
   589     maxNumLines := 1.
   590     maxNumLines := 1.
   590 true ifTrue:[
   591 
   591     methodComment := (lines copyToMax:maxNumLines) asString.
   592     methodComment := (lines copyToMax:maxNumLines) asString.
   592     maxNumLines := 5.
   593     maxNumLines := 5.
   593 ] ifFalse:[    
   594 
   594     methodComment := lines first.
       
   595     methodComment := methodComment withoutSeparators.
       
   596     (methodComment endsWith:',') ifTrue:[ methodComment := methodComment copyButLast:1].
       
   597     methodComment := methodComment withoutSeparators.
       
   598 ].
       
   599     (lines size > maxNumLines) ifTrue:[
   595     (lines size > maxNumLines) ifTrue:[
   600         methodComment := methodComment , '\...' withCRs
   596         methodComment := methodComment , c'\n...'
   601     ].
   597     ].
   602     ^ (methodComment) withColor:(UserPreferences current commentColor).
   598     ^ (methodComment) withColor:(UserPreferences current commentColor).
   603 
   599 
   604     "Created: / 14-09-2006 / 14:11:58 / cg"
   600     "Created: / 14-09-2006 / 14:11:58 / cg"
   605     "Modified (comment): / 30-04-2016 / 16:17:18 / cg"
   601     "Modified (comment): / 30-04-2016 / 16:17:18 / cg"
  1013             explanation notNil ifTrue:[ 
  1009             explanation notNil ifTrue:[ 
  1014                 string isBinarySelector ifTrue:[
  1010                 string isBinarySelector ifTrue:[
  1015                     "/ some are both known as syntax AND as selector (for example: #| )
  1011                     "/ some are both known as syntax AND as selector (for example: #| )
  1016                     tmp1 := self explainSyntax:string short:shortText.
  1012                     tmp1 := self explainSyntax:string short:shortText.
  1017                     tmp1 notNil ifTrue:[ 
  1013                     tmp1 notNil ifTrue:[ 
  1018                         ^ tmp1 , '\\also:\\' withCRs , explanation
  1014                         ^ tmp1 , c'\n\nalso:\n\n' , explanation
  1019                     ].
  1015                     ].
  1020                 ].
  1016                 ].
  1021                 ^ explanation
  1017                 ^ explanation
  1022             ].
  1018             ].
  1023 
  1019 
  1161             ].
  1157             ].
  1162             explanation := varName , ' is '.
  1158             explanation := varName , ' is '.
  1163             explanation := explanation , (val isLoaded ifTrue:['a'] ifFalse:['an autoloaded']).
  1159             explanation := explanation , (val isLoaded ifTrue:['a'] ifFalse:['an autoloaded']).
  1164             explanation := explanation , (val isSharedPool ifTrue:[' sharedPool'] ifFalse:[' class']).
  1160             explanation := explanation , (val isSharedPool ifTrue:[' sharedPool'] ifFalse:[' class']).
  1165             explanation := explanation , ' categorized as "' , val category , '"'.
  1161             explanation := explanation , ' categorized as "' , val category , '"'.
  1166             explanation := explanation , '\' withCRs , 'in the "' , val package , '" package.'.
  1162             explanation := explanation , c'\n' , 'in the "' , val package , '" package.'.
  1167             (doc := val commentOrDocumentationString) notEmptyOrNil ifTrue:[
  1163             (doc := val commentOrDocumentationString) notEmptyOrNil ifTrue:[
  1168                 doc := doc asStringCollection.
  1164                 doc := doc asStringCollection.
  1169                 doc size > 25 ifTrue:[
  1165                 doc size > 25 ifTrue:[
  1170                     doc := doc copyTo:25.
  1166                     doc := doc copyTo:25.
  1171                     doc add:''; add:'   ... <more documentation cut off>'.
  1167                     doc add:''; add:'   ... <more documentation cut off>'.
  1172                 ].
  1168                 ].
  1173                 doc := doc asString withColor:(UserPreferences current commentColor).
  1169                 doc := doc asString withColor:(UserPreferences current commentColor).
  1174                 explanation := explanation,'\\' withCRs,val name,'''s documentation:\'withCRs, doc
  1170                 explanation := explanation,'\n\n',val name,'''s documentation:\n', doc
  1175             ].
  1171             ].
  1176             ^ explanation.
  1172             ^ explanation.
  1177         ].
  1173         ].
  1178 
  1174 
  1179         explanation := explanation , '
  1175         explanation := explanation , '
  1419 
  1415 
  1420     (aClassOrNil notNil and:[aClassOrNil canUnderstand:selector]) ifTrue:[
  1416     (aClassOrNil notNil and:[aClassOrNil canUnderstand:selector]) ifTrue:[
  1421         s2 := ('Instances of ''' , aClassOrNil name , ''' respond to #') , selector "allBold" , '.'.
  1417         s2 := ('Instances of ''' , aClassOrNil name , ''' respond to #') , selector "allBold" , '.'.
  1422         shortText ifFalse:[
  1418         shortText ifFalse:[
  1423             s2 := '\\' , s2
  1419             s2 := '\\' , s2
  1424                   , '\- inherited from ' withCRs
  1420                   , c'\n- inherited from '
  1425                   , (aClassOrNil whichClassIncludesSelector:selector) name "allBold".
  1421                   , (aClassOrNil whichClassIncludesSelector:selector) name "allBold".
  1426         ].
  1422         ].
  1427         firstImplementingClass := (aClassOrNil whichClassIncludesSelector:selector)
  1423         firstImplementingClass := (aClassOrNil whichClassIncludesSelector:selector)
  1428     ] ifFalse:[
  1424     ] ifFalse:[
  1429         s2 := ''.
  1425         s2 := ''.
  1610                     cm := self fetchDescriptionOfMethod:(classProvidingComment compiledMethodAt:selector).
  1606                     cm := self fetchDescriptionOfMethod:(classProvidingComment compiledMethodAt:selector).
  1611                 ]
  1607                 ]
  1612             ].
  1608             ].
  1613         ].
  1609         ].
  1614         cm notNil ifTrue:[
  1610         cm notNil ifTrue:[
  1615             cm := ('%1 says:\' withCRs bindWith:(self asClassLink:classProvidingComment name)),cm.
  1611             cm := (c'%1 says:\n' bindWith:(self asClassLink:classProvidingComment name)),cm.
  1616 
  1612 
  1617             "/ msg := msg,(msg last isSeparator ifTrue:[''] ifFalse:[' ']),cm
  1613             "/ msg := msg,(msg last isSeparator ifTrue:[''] ifFalse:[' ']),cm
  1618             msg := msg,(Character cr),cm
  1614             msg := msg,(Character cr),cm
  1619         ].
  1615         ].
  1620         ^ msg
  1616         ^ msg
  2861                         asLink:selectorString "allBold" 
  2857                         asLink:selectorString "allBold" 
  2862                         info:('Browse all implementors of %1' bindWith:selectorString)
  2858                         info:('Browse all implementors of %1' bindWith:selectorString)
  2863                         to:(self actionToOpenMethodFinderFor:sel)) 
  2859                         to:(self actionToOpenMethodFinderFor:sel)) 
  2864             with:(self 
  2860             with:(self 
  2865                     asLink:inheritedClass name "allBold" 
  2861                     asLink:inheritedClass name "allBold" 
  2866                     info:('Browse %1 » %2' bindWith:inheritedClass name with:sel)
  2862                     info:('Browse %1 » %2' bindWith:inheritedClass name with:sel)
  2867                     to:(self actionToBrowseClass:inheritedClass selector:sel)).
  2863                     to:(self actionToBrowseClass:inheritedClass selector:sel)).
  2868     ].
  2864     ].
  2869 
  2865 
  2870     ^ msg
  2866     ^ msg
  2871 
  2867