eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'RBFormatter':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: RBFormatter


Inheritance:

   Object
   |
   +--RBProgramNodeVisitor
      |
      +--RBFormatter

Package:
stx:goodies/refactoryBrowser/parser
Category:
Refactory-Parser
Version:
rev: 1.96 date: 2023/11/23 11:05:54
user: cg
file: RBFormatter.st directory: goodies/refactoryBrowser/parser
module: stx stc-classLibrary: parser

Class protocol:

defaults
o  blockArgumentsOnNewLine
return the blockArgumentsOnNewLine flag; if on, block arguments
are on a new line.
defaults to true in original formatter; false in ST/X

o  blockArgumentsOnNewLine: aBoolean
set/clear the blockArgumentsOnNewLine flag; if on, block arguments
are on a new line.
defaults to true in original formatter; false in ST/X

o  cStyleBlocks
return the cStyleBlocks flag; if on, blocks are formatted
the c-style (k&r style); if off, they are formatted the lisp-style.
defaults to false in original formatter; true in ST/X

o  cStyleBlocks: aBoolean
set/clear the cStyleBlocks flag; if on, blocks are formatted
the c-style (k&r style); if off, they are formatted the lisp-style.
defaults to false in original formatter; true in ST/X

o  emptyLineAfterMethodComment
return the emptyLineAfterMethodComment flag; if on, an empty line
is inserted after the method's initial comment.
defaults to false in original formatter; true in ST/X

o  emptyLineAfterMethodComment: aBoolean
set/clear the emptyLineAfterMethodComment flag; if on, an empty line
is inserted after the method's initial comment.
defaults to false in original formatter; true in ST/X

o  emptyLineAfterTemporaries
return the emptyLineAfterTemporaries flag; if on, an empty line
is inserted after the locals declaration part.
defaults to false in original formatter; true in ST/X

o  emptyLineAfterTemporaries: aBoolean
set/clear the emptyLineAfterTemporaries flag; if on, an empty line
is inserted after the locals declaration part.
defaults to false in original formatter; true in ST/X

o  maxLengthForSingleLineBlocks
return the maxLengthForSingleLineBlocks setting;
blocks with code longer than this are broken into multiple lines.
defaults to false in original formatter; true in ST/X

o  maxLengthForSingleLineBlocks: anInteger
set the maxLengthForSingleLineBlocks value;
blocks with code longer than this are broken into multiple lines.
defaults to false in original formatter; true in ST/X

o  periodAfterLastStatementPolicy
return the periodAfterLastStatementPolicy flag;
this can be one of #keep, #add or #remove

o  periodAfterLastStatementPolicy: aSymbol
set the periodAfterLastStatementPolicy flag;
this can be one of #keep, #add or #remove

o  spaceAfterBlockStart
return the spaceAfterBlockStart flag; if on, a space character
is inserted after a [ token.

o  spaceAfterBlockStart: aBoolean
set/clear the spaceAfterBlockStart flag; if on, a space character
is inserted after a [ token.

o  spaceAfterKeywordSelector
return the spaceAfterKeywordSelector flag; if on, a space character
is inserted after a : in a keyword message (to separate the arg).
defaults to true in original formatter; false in ST/X

o  spaceAfterKeywordSelector: aBoolean
set/clear the spaceAfterKeywordSelector flag; if on, a space character
is inserted after a : in a keyword message (to separate the arg).
defaults to true in original formatter; false in ST/X

o  spaceAfterReturnToken
return the spaceAfterReturn flag; if on, a space character
is inserted after a ^ token.
defaults to false in original formatter; true in ST/X

o  spaceAfterReturnToken: aBoolean
set/clear the spaceAfterReturn flag; if on, a space character
is inserted after a ^ token.
defaults to false in original formatter; true in ST/X

o  spaceAroundTemporaries
return the spaceAroundTemporariesr flag; if on, a space character
is inserted before the first and after the last local variable
in the locals declaration part (i.e. as in | foo bar |)
defaults to true in original formatter; false in ST/X

o  spaceAroundTemporaries: aBoolean
set/clear the spaceAroundTemporariesr flag; if on, a space character
is inserted before the first and after the last local variable
in the locals declaration part (i.e. as in | foo bar |)
defaults to true in original formatter; false in ST/X

o  spaceBeforeBlockEnd
return the spaceBeforeBlockEnd flag; if on, a space character
is inserted before a ] token.

o  spaceBeforeBlockEnd: aBoolean
set/clear the spaceBeforeBlockEnd flag; if on, a space character
is inserted before a ] token.

o  tabIndent
the indent; defaults to 8 in original formatter;
4 in ST/X

o  tabIndent: newIndent
set the indent; defaults to 8 in original formatter;
4 in ST/X

formatting-public
o  format: aMethodSource
ignore any error

Usage example(s):

     RBFormatter format:'foo ^ self'

initialization
o  initializeSettings
self initialize

o  initializeSettingsForBR
BR original settings

o  initializeSettingsForSTX
ST/X settings


Instance protocol:

accessing
o  codeStream

o  firstLineLength

o  format: aNode

o  isMultiLine

o  lastLineLength

o  rewriteOldAssignments: aBoolean
if true (which is the default), old style assignments '_'
are formatted as ':='.
There is only one use of turning this off: when the original
source is to be preserve (i.e. when generating code for an old ST,
or showing a searchString's original pattern)

o  suppressAfterComment: something

o  suppressBeforeComment: something

additions - ST/X
o  addTab

copying-private
o  postCopy

initialize-release
o  initialize

private
o  crNoIndent

o  for: aValue do: doBlock separatedBy: separatorBlock
This is implemented here since IBM Smalltalk doesn't implement a do:separatedBy: method

o  indent

o  indent: anInteger while: aBlock

o  indentOnly

o  indentWhile: aBlock

o  lineLength

o  lineStart: aPosition

o  maxLineSize

o  maximumArgumentsPerLine

o  needsParenthesisFor: aNode
if original code had parentheses - generate them again

o  possiblyIndent
cr-tab - but only if not already at beginning

o  precedenceOf: parentSelector greaterThan: childSelector
Put parentheses around things that are preceived to have 'lower' precedence. For example, 'a + b * c'
-> '(a + b) * c' but 'a * b + c' -> 'a * b + c'

o  selectorsToLeaveOnLine

o  selectorsToStartOnNewLine

private-formatting
o  formatArrayNodeExpressions: statements

o  formatArrayNodeExpressions: statements singleLine: singleLine
or:[ PeriodAfterLastStatementPolicy == #keep
and:[ aSequenceNode lastHasPeriod]]

o  formatLiteral: aLiteralNode
to preserve the original radix...

o  formatLiteralArray: aLiteralNode
needSpace := false.

o  formatLiteralValue: aValue

o  formatMessage: aMessageNode cascade: cascadeBoolean

o  formatMessage: aMessageNode cascade: cascadeBoolean newLine: newLine
(aMessageNode arguments size > 0
and:[(self startMessageSendOnNewLine: aMessageNode)]) ifTrue:[
howMuchIndent := 0.
].

o  formatMessageSelector: selectorParts withArguments: formattedArgs multiline: multiLine

o  formatMethodPatternFor: aMethodNode

o  formatPragma: aPragmaNode

o  formatStatementsFor: aSequenceNode
self formatStatementComments:(stat commentsAfter) for:stat.

o  formatSymbol: aSymbol
Format the symbol, if it's not a selector then we must put quotes around it. The and: case below,
handles the VisualWorks problem of not accepting two bars as a symbol.

o  formatTagFor: aMethodNode

o  formatTemporariesFor: aSequenceNode

o  newLinesFor: aString startingAt: anIndex

private-formatting-comments
o  formatArgumentComments: comments for: aNode

o  formatBlockCommentFor: aNode

o  formatComments: comments for: aNode spaceAfter: spaceafter

o  formatComments: comments for: aNode spaceBefore: spaceBefore spaceAfter: spaceafter
crs := self newLinesFor: source startingAt: eachComment first.
(crs - 1 max: 0) timesRepeat: [codeStream cr].
crs == 0 ifTrue: [self addTab] ifFalse: [self indent].

o  formatMethodComment: aComment for: aNode indentBefore: indentBefore

o  formatMethodComment: aComment for: aNode indentBefore: indentBefore indentAfter: indentAfter
source isNil ifTrue: [^self].

o  formatMethodCommentFor: aNode indentBefore: aBoolean

o  formatMethodComments: comments for: aNode indentBefore: indentBefore
source := aNode source.

o  formatMethodCommentsAfter: comments for: aNode
special case for comment-only methods: leave as is

o  formatMethodCommentsAfterRightBar: comments for: aNode

o  formatStatementCommentFor: aNode

o  formatStatementComments: comments for: aNode
this:

o  formatStatementCommentsBefore: comments for: aNode

o  formatTemporaryComments: comments for: aNode

testing
o  startMessageSendOnNewLine: aMessageNode

o  tagBeforeTemporaries

visiting
o  visitNode: aNode

visiting-comments
o  formatCommentsAfter: comments for: aNode

o  formatCommentsBefore: comments for: aNode

o  formatMethodCommentsBefore: comments for: aNode

o  formatSequenceCommentsBefore: comments for: aNode

visitor-double dispatching
o  acceptArrayNode: anArrayNode
try as single line first

o  acceptAssignmentNode: anAssignmentNode
oldStyle ifTrue:[' _ '] ifFalse:[' := ']).

o  acceptBlockNode: aBlockNode
I am the receiver of a message (i.e. typically a control structure)

o  acceptBlockNodeCStyle: aBlockNode

o  acceptCascadeNode: aCascadeNode

o  acceptLiteralNode: aLiteralNode

o  acceptMessageNode: aMessageNode
pre-generate the code for the receiver into a string.

o  acceptMethodNode: aMethodNode
self formatMethodCommentFor: aMethodNode indentBefore: true.

o  acceptOptimizedNode: anOptimizedNode

o  acceptPragmaNode: aLiteralNode

o  acceptReturnNode: aReturnNode

o  acceptSTXPrimitiveCCodeNode: aPrimitiveNode

o  acceptSTXPrimitiveValueCCodeNode: aPrimitiveNode

o  acceptSequenceNode: aSequenceNode
self formatMethodCommentFor: aSequenceNode indentBefore: false.

o  acceptVariableNode: aVariableNode

o  formatBlockArguments: aBlockNode

o  whichArgIsToBeFormattedKRLikeIn: selector
for CStyle (kernigham-ritchie style) formatting of blocks arguments.
Return the arg-index or nil or #both



ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Thu, 21 Nov 2024 15:47:14 GMT