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

Fixes Auto Refactoring for the BPBrowser #92

Merged
merged 21 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
382c238
changes styling of text morph in compilation
JoeAtHPI Sep 9, 2021
e327f76
Fixes comment styling
JoeAtHPI Sep 9, 2021
c996515
Adds styling the code to unstyled when compiling
JoeAtHPI Oct 7, 2021
6e52db3
Merge pull request #91 from hpi-swa-lab/develop
JoeAtHPI Oct 7, 2021
7a198b0
Dirty hack to fix the problem of outdated BPTextAnchors in the code e…
JoeAtHPI Oct 17, 2021
5df546b
Replaces dirty hack with a more consistent workaround
JoeAtHPI Oct 23, 2021
ffb1582
Adds tests for compiler exceptions which trigger auto refactoring
JoeAtHPI Oct 24, 2021
0faec34
Deletes dead code
JoeAtHPI Oct 24, 2021
2e306c1
Categorize uncategorized method
JoeAtHPI Oct 24, 2021
4b724b6
Merge pull request #95 from hpi-swa-lab/develop
JoeAtHPI Oct 24, 2021
98114f5
Deletes tab character from test strings
JoeAtHPI Oct 24, 2021
7f7306b
Cleans up BPCompilerExceptionTest setup + adds comment to BPStyler
JoeAtHPI Oct 28, 2021
185b595
Copies trunk code into this version
JoeAtHPI Nov 10, 2021
026bf49
Adds the rest of the class' code
JoeAtHPI Nov 10, 2021
889db95
Comments out tests that fail due to needing 5.3 trunk changes
JoeAtHPI Nov 10, 2021
b3371c4
Adds todo flags in uncommented tests
JoeAtHPI Nov 10, 2021
3acae14
Merge branch 'develop' of origin into big/fix-auto-refactor-styling
JoeAtHPI Nov 16, 2021
85b80d9
Update main.yml
JoeAtHPI Nov 16, 2021
3534525
Update prepare_image.st
JoeAtHPI Nov 16, 2021
6c10e19
Merge branch 'develop' into big/fix-auto-refactor-styling
JoeAtHPI Nov 16, 2021
27a1f52
who would win? an engineer or one(1) curly boi {}
JoeAtHPI Nov 16, 2021
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,20 +1,33 @@
public access
compile: aCueWithBPSource ifFail: failBlock
compile: aCueWithStyledSource ifFail: failBlock

"This method expects source code which has annotations embedded in comments, if any."
| originalMethodNode bpSource basicCue |
bpSource := aCueWithBPSource sourceStream contents asString.
basicCue := CompilationCue
source: bpSource readStream
context: aCueWithBPSource context
receiver: aCueWithBPSource receiver
class: aCueWithBPSource getClass
environment: aCueWithBPSource environment
requestor: aCueWithBPSource requestor.
originalMethodNode := super compile: basicCue ifFail: failBlock.
"This method expects source code which has annotations embedded in comments,
if any, meaning it's styled with text attributes. Since the BPBrowser breaks the premise
of the Parser that the source stream and the code panel's morph code is the same, auto
refactoring will quickly cause inconsistencies. For example, if one were to add a temporal
variable to existing ones, with the second vertical line being at position 18, the styled
version could have it at position 19. The parser would then re-add two lines,
causing for synctactic errors when compiling. Therefore, we remove the text styling
inside the morph to re-fullfill that premise again during compilation."
| originalMethodNode bpUnstyledSource unstyledCue |
bpUnstyledSource := aCueWithStyledSource sourceStream contents asString asBPSource.
aCueWithStyledSource requestor ifNotNil: [
aCueWithStyledSource requestor useDefaultStyler.
aCueWithStyledSource requestor setText: bpUnstyledSource.
aCueWithStyledSource requestor styler: (BPStyler new view: aCueWithStyledSource requestor).
].

bpSource := originalMethodNode sourceText asString.
(self methodSourceRequiresBPLayers: bpSource) ifTrue: [
(self compileInstrumentedVersionOf: aCueWithBPSource) ifFalse: failBlock].

^ originalMethodNode
unstyledCue := CompilationCue
source: bpUnstyledSource readStream
context: aCueWithStyledSource context
receiver: aCueWithStyledSource receiver
class: aCueWithStyledSource getClass
environment: aCueWithStyledSource environment
requestor: aCueWithStyledSource requestor.
originalMethodNode := super compile: unstyledCue ifFail: failBlock.

bpUnstyledSource := originalMethodNode sourceText asString.
(self methodSourceRequiresBPLayers: bpUnstyledSource) ifTrue: [
(self compileInstrumentedVersionOf: aCueWithStyledSource) ifFalse: failBlock].

^ originalMethodNode
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"instance" : {
"annotationKeywords" : "pre 11/8/2019 20:29",
"backgroundCompileInstrumentedVersionOf:basedOn:" : "pre 10/12/2020 15:36",
"compile:ifFail:" : "pre 5/3/2021 10:59",
"compileInstrumentedVersionOf:" : "pre 1/11/2021 15:51",
"compile:ifFail:" : "jb 10/17/2021 19:02",
"compileInstrumentedVersionOf:" : "jb 9/9/2021 17:31",
"keywords" : "pre 7/26/2019 14:00",
"methodSourceRequiresBPLayers:" : "pre 11/11/2019 15:49",
"parse:" : "pre 1/11/2021 15:51",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
compiling
compilerClass

^ BPCompiler
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
assertions
assertText: textMatch

text isBlock ifTrue: [
^ self assertText: text value].
^ (textMatch respondsTo: #matches:)
ifTrue: [
self assert: [textMatch matches: (self codePaneTextMorph textMorph contents) asString]]
ifFalse: [
self assert: textMatch equals: (self codePaneTextMorph textMorph contents) asString]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
private
codePaneTextMorph

^ browser containingWindow submorphNamed: 'codePaneTextMorph'.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
private
compile: sourceString

| result |
originalText := text := sourceString.
previousSelection := originalSelection := 1 to: text size + 1.
selectionInterval := nil.
result := self class
compile: text
classified: 'generated'
notifying: self codePaneTextMorph.
result ifNil: [^ self].
self codePaneTextMorph accept.
selectionInterval := originalSelection.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
private
compileMethodHeaderAndSetBrowserToIt

text := 'someMethod\\ ' withCRs asText.
self compile: text.
browser setSelector: #someMethod.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
private
compiling: sourceCode shouldRaise: exceptionClass andSelect: selectionMatch testing: tests

"See CompilerException"

| referenceTest |
referenceTest := [] -> [].
(tests copyWithFirst: referenceTest) associationsDo: [:test |
self
should: [self compile: sourceCode.]
raise: exceptionClass
thenDo: [:exception |
previousSelection := self selectionInterval.
(self handlerBlockFor: test key) cull: exception].
self codePaneTextMorph accept.
(self testBlockFor: test value) value].
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
running
setUp

browser := BPBrowser fullOnClass: self class.
stylePreference := Preferences confirmFirstUseOfStyle.
JoeAtHPI marked this conversation as resolved.
Show resolved Hide resolved
Preferences setPreference: #confirmFirstUseOfStyle toValue: false.
self compileMethodHeaderAndSetBrowserToIt.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
running
tearDown

self codePaneTextMorph accept.
super tearDown.
browser containingWindow abandon.
Preferences setPreference: #confirmFirstUseOfStyle toValue: stylePreference.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
tests
testAmbiguousSelector

| expectedString |
self codePaneTextMorph textMorph contents append: '\^1@-1' withCRs.
text append: '\^1@-1' withCRs.
expectedString := ('someMethod\', Character startOfHeader, '\ \^1@ -1') withCRs.
self
compiling: text
shouldRaise: AmbiguousSelector
andSelect: '@-'
testing: {
[:ex | ex resume] -> [self assertCanceled].
[:ex | ex resume: '@ -'] -> expectedString }.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
tests
testPastesBlockLocalTemp

| expectedString |
self codePaneTextMorph textMorph contents append: ('\^ [ ', self undeclaredVar ,' ] value') withCRs.
text append: ('\^ [ ', self undeclaredVar ,' ] value') withCRs.
expectedString := ('someMethod\', Character startOfHeader, '\ \^ [ | foo | ', self undeclaredVar, ' ] value') withCRs.
self
compiling: text
shouldRaise: UndeclaredVariable
andSelect: 'foo'
testing: {
false -> [self assertCanceled].
'declare block-local temp' -> expectedString}.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
tests
testPastesFirstTempAtMethodLevel

| expectedString |
self codePaneTextMorph textMorph contents append: self undeclaredVar.
text append: self undeclaredVar.
expectedString := ('someMethod\', Character startOfHeader, '\ \| foo |', self undeclaredVar) withCRs.
self
compiling: text
shouldRaise: UndeclaredVariable
andSelect: 'foo'
testing: {
false -> [self assertCanceled].
'declare method temp' -> expectedString}.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
tests
testPastesSecondTempAtMethodLevel

| expectedString |
self codePaneTextMorph textMorph contents append: ('| a | \ a := 3.', self undeclaredVar) withCRs.
text append: ('| a | \ a := 3.', self undeclaredVar) withCRs.
expectedString := ('someMethod\', Character startOfHeader, '\ | a foo | \ a := 3.', self undeclaredVar) withCRs.
self
compiling: text
shouldRaise: UndeclaredVariable
andSelect: 'foo'
testing: {
false -> [self assertCanceled].
'declare method temp' -> expectedString}.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
tests
testPastesTempForBlockValue

| expectedString |
self codePaneTextMorph textMorph contents append: ('\^ [ ', self undeclaredVar ,' ] value') withCRs.
text append: ('\^ [ ', self undeclaredVar ,' ] value') withCRs.
expectedString := ('someMethod\', Character startOfHeader, '\ \| foo |\^ [ ', self undeclaredVar, ' ] value') withCRs.
self
compiling: text
shouldRaise: UndeclaredVariable
andSelect: 'foo'
testing: {
false -> [self assertCanceled].
'declare method temp' -> expectedString}.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
tests
testUndefinedVariable


self codePaneTextMorph textMorph contents append: '| foo | ^ foo'.
text append: '| foo | ^ foo'.
self
compiling: text
shouldRaise: UndefinedVariable
andSelect: [(self text allRangesOfRegexMatches: '(?<=\^ )foo') first]
testing: {
true -> [self assertSucceeded].
false -> [self assertCanceled] }.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
tests
testUndefinedVariableBlockValue

self codePaneTextMorph textMorph contents append: '[ | foo | ^ foo ] value'.
text append: '[ | foo | ^ foo ] value'.
self
compiling: text
shouldRaise: UndefinedVariable
andSelect: [(self text allRangesOfRegexMatches: '(?<=\^ )foo') first]
testing: {
true -> [self assertSucceeded].
false -> [self assertCanceled] }.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
tests
testUnusedVariable

self codePaneTextMorph textMorph contents append: '| foo | ^nil'.
text append: '| foo | ^nil'.
self
compiling: text
shouldRaise: UnusedVariable
andSelect: [text]
testing: {
[:ex | ex resume] -> [self assertCanceled].
false -> [self assertSucceeded].
true -> [self assertSucceeded: ('someMethod\' withCRs, Character startOfHeader, '\s*\^nil') asRegex] }.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
tests
testUnusedVariableInBlock

self codePaneTextMorph textMorph contents append: '^[ | foo | ]'.
text append: '^[ | foo | ]'.
self
compiling: text
shouldRaise: UnusedVariable
andSelect: [text]
testing: {
[:ex | ex resume] -> [self assertCanceled].
false -> [self assertSucceeded].
true -> [self assertSucceeded: ('someMethod\' withCRs, Character startOfHeader, '\s*\^\[\s*\]') asRegex] }.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
private
undeclaredVar

^ '\foo := 42.' withCRs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"class" : {
"compilerClass" : "jb 10/24/2021 01:58" },
"instance" : {
"assertText:" : "jb 10/24/2021 02:51",
"codePaneTextMorph" : "jb 10/20/2021 18:18",
"compile:" : "jb 10/24/2021 03:09",
"compileMethodHeaderAndSetBrowserToIt" : "jb 10/24/2021 01:52",
"compiling:shouldRaise:andSelect:testing:" : "jb 10/24/2021 03:03",
"setUp" : "jb 10/24/2021 02:11",
"tearDown" : "jb 10/24/2021 02:26",
"testAmbiguousSelector" : "jb 10/24/2021 22:41",
"testPastesBlockLocalTemp" : "jb 10/24/2021 22:41",
"testPastesFirstTempAtMethodLevel" : "jb 10/24/2021 22:41",
"testPastesSecondTempAtMethodLevel" : "jb 10/24/2021 22:41",
"testPastesTempForBlockValue" : "jb 10/24/2021 22:41",
"testUndefinedVariable" : "jb 10/24/2021 02:34",
"testUndefinedVariableBlockValue" : "jb 10/24/2021 02:37",
"testUnusedVariable" : "jb 10/24/2021 22:42",
"testUnusedVariableInBlock" : "jb 10/24/2021 22:42",
"undeclaredVar" : "jb 10/23/2021 16:49" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"category" : "Babylonian-Tests",
"classinstvars" : [
],
"classvars" : [
],
"commentStamp" : "",
"instvars" : [
"browser",
"stylePreference" ],
"name" : "BPCompilerExceptionTest",
"pools" : [
],
"super" : "CompilerExceptionsTest",
"type" : "normal" }
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ui constants
smallFontHeight

^ self fontHeight * 0.75
^ self fontHeight * 0.75
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"fontHeight" : "pre 11/18/2019 10:40",
"fontWidth" : "pre 11/18/2019 10:44",
"newContainerMorph" : "pre 10/12/2020 17:47",
"smallFontHeight" : "pre 10/6/2020 11:54",
"smallFontHeight" : "jb 9/9/2021 18:39",
"smallFontWidth" : "pre 1/7/2021 11:49" },
"instance" : {
"annotation" : "pre 7/2/2019 16:39",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
converting
unstyledTextFrom: aText

^ Text fromString: aText asBPSource
| answer |
answer := Text fromString: aText asBPSource.
aText runs withStartStopAndValueDo: [:start :stop :attribs |
(attribs anySatisfy: [:each | each shoutShouldPreserve])
JoeAtHPI marked this conversation as resolved.
Show resolved Hide resolved
ifTrue: [
attribs do: [:eachAttrib |answer addAttribute: eachAttrib from: start to: stop]]].
^answer
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
"removePotentialEmptyLinesInText:around:" : "pre 8/25/2020 09:47",
"selectedMethod:" : "ct 8/20/2021 06:24",
"textForAnnotation:from:at:" : "pre 11/23/2020 11:57",
"unstyledTextFrom:" : "lu 6/1/2021 21:39" } }
"unstyledTextFrom:" : "jb 10/24/2021 03:17" } }
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
writing
writeStartTagFor: aTextAttribute

[self nextPutAll: aTextAttribute anchoredMorph startTag]
on: MessageNotUnderstood do: [].
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
"respectExamples" : "pre 1/11/2021 14:54",
"writeContent:" : "jb 12/7/2020 19:03",
"writeEndTagFor:" : "jb 12/7/2020 19:03",
"writeStartTagFor:" : "jb 12/7/2020 19:03" } }
"writeStartTagFor:" : "jb 8/31/2021 00:29" } }
Loading