Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

50 keep new lines in arrays #85

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
14d9dd5
Implemented PPWindowFormatter and some tests for it.
racerX4004 Jun 1, 2022
8823659
Added some more acceptance tests
racerX4004 Jun 1, 2022
41e8dfb
Merge pull request #71 from hpi-swa-teaching/66-comma-and-spaces
EnnioEnnio Jun 1, 2022
1702f70
Merge pull request #72 from hpi-swa-teaching/66-comma-and-spaces
Yannis-Hofmann Jun 1, 2022
841d0b7
Merge branch 'Release_Branch' into 49-set-row-length-to-standard-brow…
racerX4004 Jun 1, 2022
cf3584b
Implementing Config for WindowFormatter
racerX4004 Jun 1, 2022
834a155
implementing no Linebreak in String
racerX4004 Jun 1, 2022
eea78cd
some renaming
racerX4004 Jun 1, 2022
7484b2d
Merge pull request #73 from hpi-swa-teaching/66-comma-and-spaces
simonmichaelnowack Jun 2, 2022
05a1d4a
Adding more Test for a better covarage of PPWindowFormatter
janiswehen Jun 15, 2022
b1fb128
Merge branch 'Release_Branch' into 49-set-row-length-to-standard-brow…
Yannis-Hofmann Jun 16, 2022
0fd3a77
Merge pull request #78 from hpi-swa-teaching/master
Yannis-Hofmann Jun 19, 2022
6703f51
resetting because of merge mistakes
Yannis-Hofmann Jun 19, 2022
ac96454
fix another merge mistake
Yannis-Hofmann Jun 19, 2022
e2bd936
remove accidental changes
Yannis-Hofmann Jun 20, 2022
737e1ed
move testAllMethods back to examples category
Yannis-Hofmann Jun 20, 2022
6060712
poppy-print testAllMethods again
Yannis-Hofmann Jun 20, 2022
d2401f9
move testAllMethods to tests- examples
Yannis-Hofmann Jun 20, 2022
0c7f83b
renaming and fixing typos
janiswehen Jun 23, 2022
3748fbb
Merge branch 'Release_Branch' into 49-set-row-length-to-standard-brow…
janiswehen Jun 23, 2022
b3bb208
small refactoring and fixing more typos
janiswehen Jun 23, 2022
97265b4
Merge pull request #76 from hpi-swa-teaching/49-set-row-length-to-sta…
kdauer Jun 23, 2022
e02476f
changing 'or:' and 'and:' styles
Yannis-Hofmann Jun 23, 2022
7b3036d
change more or: and and:
Yannis-Hofmann Jun 28, 2022
8144bc4
Merge branch 'Release_Branch' into 50-keep-new-lines-in-arrays
Yannis-Hofmann Jun 28, 2022
d378314
remove duplicate if-clause
Yannis-Hofmann Jun 28, 2022
ef21ccd
Merge branch '50-keep-new-lines-in-arrays' of https://github.com/hpi-…
Yannis-Hofmann Jun 28, 2022
60d211c
remove duplicate if-clause again
Yannis-Hofmann Jun 28, 2022
ba45be4
fixing error where optionalEmptyLines where not removed
Yannis-Hofmann Jun 28, 2022
88a5b9a
remove config option (to be implemented in different branch)
Yannis-Hofmann Jun 28, 2022
074110c
update evaluateBraceStatement and remove defensive checks
Yannis-Hofmann Jun 28, 2022
7d3bc56
Fix change suggestions
Jul 21, 2022
4e8907c
Update comment
Yannis-Hofmann Jul 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
format
formatString: aString class: aClass noPattern: aBoolean notifying: anObject with: aPPFormatterConfig

| formatter methodNode |
| formatter methodNode result |
self
example: 'string test'
receiver: [PPFormatter]
Expand All @@ -19,4 +19,10 @@ formatString: aString class: aClass noPattern: aBoolean notifying: anObject with
initForNode: methodNode;
config: aPPFormatterConfig.
methodNode accept: formatter.
^ aBoolean ifTrue: [self stripMethodPattern: formatter contents] ifFalse: [formatter contents]

result := aBoolean
ifTrue: [self stripMethodPattern: formatter contents]
ifFalse: [formatter contents].
aPPFormatterConfig formatToMaxLineWidth ifTrue: [result := PPWindowFormatter new format: result withWindowWidth: aPPFormatterConfig maxLineWidth].

^ result
Comment on lines +22 to +28
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this was used during debugging only? or is there a reason to keep the temp var around?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, this is actually needed for the LineWidth

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
helper
braceNodeHasMultiLineParts: aNode

^ (aNode elements anySatisfy: [:node |
(self willBeMultiLine: node) or: (self isTypeOfNewLineMarker: node)]) or: [self isCaseOf: (self parentFor: aNode)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing square brackets around the or:

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
helper
evaluateBraceStatements: aNode multiLine: multiLine
Yannis-Hofmann marked this conversation as resolved.
Show resolved Hide resolved

aNode elements do: [:element | | isLast |
isLast := element = aNode elements last.
((self isOptionalNewLineMarker: element) and: [multiLine]) ifFalse: [
((self isEmptyLineMarker: element) or: [self isOptionalEmptyLineMarker: element])
ifTrue: [self newLine]
ifFalse: [
(self isOptionalNewLineMarker: element) ifFalse: [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be that I'm reading this wrong, but isn't this always false because if it were true, control flow would have gone into the upper ifTrue branch?

One suggestion, to help clarify the method, could be to create a separate printBraceElement:multiLine: method and make use of early returns.

self visitNode: element.
isLast ifFalse: [
config spaceBeforePointInArray ifTrue: [stream space].
self stream nextPut: $.]].

isLast ifFalse: [multiLine ifTrue: [self newLine] ifFalse: [self stream space]]]]]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
helper
getBraceNodeLength: aNode

^ aNode elements
inject: 0
into: [:sum :node | sum + (self preFormat: node) size]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
helper
isOptionalEmptyLineMarker: aNode

^ aNode isLiteralNode and: [aNode key = #ppOptionalEmptyLine]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
helper
isOptionalNewLineMarker: aNode

^ aNode isLiteralNode and: [aNode key = #ppOptionalNewLine]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
helper
isTypeOfNewLineMarker: aNode

^ ((self isOptionalEmptyLineMarker: aNode) or: (self isOptionalNewLineMarker: aNode) or: (self isEmptyLineMarker: aNode))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing square brackets around or

Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ visitBlockNode: aNode

self printBlockComment: aNode.
aNode statements do: [:statement |
(self isEmptyLineMarker: statement) ifTrue: [self newLine] ifFalse: [
self visitNode: statement.
statement ~= aNode statements last ifTrue: [
stream nextPut: $..
self newLine]].
(self isEmptyLineMarker: statement)
ifTrue: [self newLine]
ifFalse: [
((self isOptionalEmptyLineMarker: statement) or: [self isOptionalNewLineMarker: statement])
Yannis-Hofmann marked this conversation as resolved.
Show resolved Hide resolved
ifFalse: [
self visitNode: statement.
statement ~= aNode statements last ifTrue: [
stream nextPut: $..
self newLine]]].
self printAllCommentsOf: statement lastStatement: statement = aNode statements last]].

isMethodBlock ifFalse: [stream nextPut: $]]
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,12 @@ visiting
visitBraceNode: aNode
Yannis-Hofmann marked this conversation as resolved.
Show resolved Hide resolved

| length multiLine |
length := aNode elements inject: 0 into: [:sum :node | sum + (self preFormat: node) size].
multiLine := length > self maxLineLength or: [(aNode elements anySatisfy: [:node | (self willBeMultiLine: node) or: [self isEmptyLineMarker: node]]) or: [self isCaseOf: (self parentFor: aNode)]].

stream nextPut: ${.
length := self getBraceNodeLength: aNode.
multiLine := length > self maxLineLength or: [self braceNodeHasMultiLineParts: aNode].
self stream nextPut: ${.

self indent: (multiLine ifTrue: [1] ifFalse: [0]) around: [
multiLine ifTrue: [self newLine].

aNode elements do: [:element | | isLast |
isLast := element = aNode elements last.
(self isEmptyLineMarker: element) ifFalse: [
self visitNode: element.
isLast ifFalse: [
config spaceBeforePointInArray ifTrue: [stream space].
stream nextPut: $.]].

isLast ifFalse: [multiLine ifTrue: [self newLine] ifFalse: [stream space]]]].
self evaluateBraceStatements: aNode multiLine: multiLine].

stream nextPut: $}
self stream nextPut: $}
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,35 @@
"format:in:notifying:decorated:" : "tobe 3/10/2021 15:45",
"formatCategory:" : "tobe 3/10/2021 14:59",
"formatClass:" : "tobe 3/10/2021 14:59",
"formatMethod:" : "tobe 3/10/2021 13:32",
"formatMethod:" : "JW 6/1/2022 19:34",
"formatPackage:" : "tobe 3/10/2021 14:59",
"formatString:class:noPattern:" : "tobe 3/10/2021 15:47",
"formatString:class:noPattern:notifying:" : "KD 6/15/2022 16:11",
"formatString:class:noPattern:notifying:with:" : "KD 6/15/2022 16:11",
"formatString:class:noPattern:with:" : "Alexander Ungefug 6/1/2022 16:06",
"stripMethodPattern:" : "tobe 3/19/2021 18:51" },
"instance" : {
"braceNodeHasMultiLineParts:" : "YH 6/9/2022 18:58",
"comments" : "Alexander Ungefug 5/30/2022 19:04",
"comments:" : "KD 6/15/2022 16:11",
"config" : "Alexander Ungefug 6/1/2022 16:02",
"config:" : "KD 6/15/2022 15:57",
"contents" : "tobe 3/10/2021 14:58",
"evaluateBraceStatements:multiLine:" : "YH 6/28/2022 13:50",
"example:receiver:args:" : "tobe 3/10/2021 14:58",
"formatTemporariesOf:isMethod:" : "KD 6/15/2022 16:11",
"getBraceNodeLength:" : "YH 6/8/2022 17:55",
"indent" : "Alexander Ungefug 5/30/2022 19:04",
"indent:" : "tobe 3/10/2021 14:58",
"indent:around:" : "tobe 3/10/2021 14:58",
"initForNode:" : "tobe 3/10/2021 14:58",
"initialize" : "KD 6/15/2022 16:11",
"isCaseOf:" : "KD 6/15/2022 16:11",
"isEmptyLineMarker:" : "tobe 3/11/2021 10:46",
"isMultiLineMessage:" : "KD 6/15/2022 16:11",
"isMultiLineMessage:" : "tobe 3/11/2021 10:38",
"isOptionalEmptyLineMarker:" : "YH 6/8/2022 17:52",
"isOptionalNewLineMarker:" : "YH 6/9/2022 18:07",
"isTypeOfNewLineMarker:" : "YH 6/9/2022 18:52",
"maxLineLength" : "tobe 3/10/2021 15:10",
"needsParenthesisFor:" : "KD 6/15/2022 16:11",
"newLine" : "tobe 3/10/2021 14:58",
Expand All @@ -52,17 +58,17 @@
"stream" : "tobe 3/10/2021 14:58",
"stream:" : "KD 6/15/2022 16:00",
"visitAssignmentNode:" : "tobe 3/10/2021 14:58",
"visitBlockNode:" : "KD 6/15/2022 16:11",
"visitBraceNode:" : "KD 6/15/2022 16:05",
"visitBlockNode:" : "YH 6/28/2022 11:06",
"visitBraceNode:" : "YH 6/9/2022 18:58",
"visitCascadeNode:" : "tobe 3/10/2021 17:17",
"visitFutureNode:" : "tobe 3/10/2021 14:58",
"visitInstanceVariableNode:" : "tobe 3/10/2021 14:58",
"visitLiteralNode:" : "tobe 3/11/2021 09:09",
"visitLiteralVariableNode:" : "tobe 3/10/2021 14:58",
"visitMessageNode:" : "KD 6/15/2022 16:11",
"visitMethodNode:" : "tobe 3/11/2021 11:38",
"visitMessageNode:" : "YH 6/19/2022 23:43",
"visitMethodNode:" : "JW 6/1/2022 20:51",
"visitNode:" : "tobe 3/11/2021 10:00",
"visitReturnNode:" : "KD 6/15/2022 16:05",
"visitReturnNode:" : "YH 6/20/2022 14:41",
"visitTempVariableNode:" : "tobe 3/10/2021 14:58",
"visitTrackedAssignmentNode:" : "tobe 3/10/2021 14:58",
"visitVariableNode:" : "tobe 3/10/2021 14:58",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
formatToMaxLineWidth: aBoolean

formatToMaxLineWidth := aBoolean
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
formatToMaxLineWidth

^ formatToMaxLineWidth ifNil: [formatToMaxLineWidth := false]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
maxLineWidth: anInteger

maxLineWidth := anInteger
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
maxLineWidth

^ maxLineWidth ifNil: [maxLineWidth := 83]
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
"class" : {
"default" : "KD 6/15/2022 16:11" },
"instance" : {
"formatToMaxLineWidth" : "JW 6/1/2022 20:57",
"formatToMaxLineWidth:" : "JW 6/23/2022 10:53",
"maxLineWidth" : "JW 6/1/2022 19:28",
"maxLineWidth:" : "JW 6/23/2022 10:52",
"spaceBeforeComma" : "KD 6/15/2022 16:07",
"spaceBeforeComma:" : "YH 6/2/2022 14:16",
"spaceBeforePointInArray" : "Alexander Ungefug 6/1/2022 15:59",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"commentStamp" : "",
"instvars" : [
"spaceBeforeComma",
"spaceBeforePointInArray" ],
"spaceBeforePointInArray",
"formatToMaxLineWidth",
"maxLineWidth" ],
"name" : "PPFormatterConfig",
"pools" : [
],
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
charAt: aNumber

^ string at: aNumber
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
charAtIndex

^ self charAt: index
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
helper
countTabs

| i |
i := index + 1.
tabCount := 0.

[i <= string size and: [(self charAt: i) = Character tab]] whileTrue: [
tabCount := tabCount + 1.
i := i + 1]
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
formatting
format: aString withWindowWidth: aNumber

aString isEmpty ifTrue: [^ aString].

string := aString.
maxWidth := aNumber.
self reset.

[index <= string size] whileTrue: [ | seperator |
seperator := self charAtIndex.
self getNextWord.

seperator = Character cr ifTrue: [self putNewlineAndCountTabs] ifFalse: [
wordWidth + lineWidth + 1 > maxWidth
ifTrue: [self putIndentedNewlineAndWord]
ifFalse: [self putSeperatorAndWord]]].

^ resultStream contents
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
helper
getNextWord

| i |
i := index + 1.
wordWidth := 0.
wordStream reset.

[i <= string size and: [inString or: [(seperators occurrencesOf: (self charAt: i)) = 0]]] whileTrue: [
wordStream nextPut: (self charAt: i).
(self charAt: i) = $' ifTrue: [inString := inString not].
wordWidth := wordWidth + 1.
i := i + 1]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
put
putIndentedNewlineAndWord

resultStream nextPut: Character cr;
next: tabCount + 1 put: Character tab;
nextPutAll: wordStream contents.
lineWidth := tabCount + 1 + wordWidth.
index := index + wordWidth + 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
put
putNewlineAndCountTabs

self countTabs.

resultStream nextPut: Character cr;
next: tabCount put: Character tab.
tabCount = 0
ifTrue: [
resultStream nextPutAll: wordStream contents.
index := index + wordWidth + 1]
ifFalse: [
index := index + tabCount.
self getNextWord.
resultStream nextPutAll: wordStream contents.
index := index + wordWidth + 1].
lineWidth := tabCount + wordWidth
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
put
putSeperatorAndWord

resultStream nextPut: self charAtIndex;
nextPutAll: wordStream contents.
lineWidth := lineWidth + wordWidth + 1.
index := index + wordWidth + 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
initialize
reset

seperators := { Character cr. Character tab. Character space}.
resultStream := '' writeStream.
wordStream := '' writeStream.
lineWidth := 0.
wordWidth := 0.
tabCount := 0.
index := 1.
inString := false.

self skipToEndOfFirstWord
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
initialize
skipToEndOfFirstWord

[index <= string size and: [inString or: [(seperators occurrencesOf: self charAtIndex) = 0]]] whileTrue: [
resultStream nextPut: self charAtIndex.
self charAtIndex = $' ifTrue: [inString := inString not].
lineWidth := lineWidth + 1.
index := index + 1]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"class" : {
},
"instance" : {
"charAt:" : "JW 5/31/2022 11:05",
"charAtIndex" : "JW 5/31/2022 11:05",
"countTabs" : "JW 5/31/2022 11:12",
"format:withWindowWidth:" : "JW 6/1/2022 20:52",
"getNextWord" : "JW 6/1/2022 20:09",
"putIndentedNewlineAndWord" : "JW 6/23/2022 11:45",
"putNewlineAndCountTabs" : "JW 6/23/2022 11:46",
"putSeperatorAndWord" : "JW 6/23/2022 11:47",
"reset" : "JW 6/1/2022 20:05",
"skipToEndOfFirstWord" : "JW 6/1/2022 20:10" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"category" : "PoppyPrint-Core",
"classinstvars" : [
],
"classvars" : [
],
"commentStamp" : "",
"instvars" : [
"string",
"resultStream",
"wordStream",
"seperators",
"lineWidth",
"wordWidth",
"tabCount",
"index",
"maxWidth",
"inString" ],
"name" : "PPWindowFormatter",
"pools" : [
],
"super" : "Object",
"type" : "normal" }
Loading