Skip to content

Commit 2cd92f7

Browse files
authored
Merge pull request #92 from hpi-swa-lab/big/fix-auto-refactor-styling
Fixes Auto Refactoring for the BPBrowser
2 parents 3ef3fd5 + 27a1f52 commit 2cd92f7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+411
-31
lines changed
Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,33 @@
11
public access
2-
compile: aCueWithBPSource ifFail: failBlock
2+
compile: aCueWithStyledSource ifFail: failBlock
33

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

16-
bpSource := originalMethodNode sourceText asString.
17-
(self methodSourceRequiresBPLayers: bpSource) ifTrue: [
18-
(self compileInstrumentedVersionOf: aCueWithBPSource) ifFalse: failBlock].
19-
20-
^ originalMethodNode
20+
unstyledCue := CompilationCue
21+
source: bpUnstyledSource readStream
22+
context: aCueWithStyledSource context
23+
receiver: aCueWithStyledSource receiver
24+
class: aCueWithStyledSource getClass
25+
environment: aCueWithStyledSource environment
26+
requestor: aCueWithStyledSource requestor.
27+
originalMethodNode := super compile: unstyledCue ifFail: failBlock.
28+
29+
bpUnstyledSource := originalMethodNode sourceText asString.
30+
(self methodSourceRequiresBPLayers: bpUnstyledSource) ifTrue: [
31+
(self compileInstrumentedVersionOf: aCueWithStyledSource) ifFalse: failBlock].
32+
33+
^ originalMethodNode

packages/Babylonian-Compiler.package/BPCompiler.class/methodProperties.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
"instance" : {
77
"annotationKeywords" : "pre 11/8/2019 20:29",
88
"backgroundCompileInstrumentedVersionOf:basedOn:" : "pre 10/12/2020 15:36",
9-
"compile:ifFail:" : "pre 5/3/2021 10:59",
10-
"compileInstrumentedVersionOf:" : "pre 1/11/2021 15:51",
9+
"compile:ifFail:" : "jb 10/17/2021 19:02",
10+
"compileInstrumentedVersionOf:" : "jb 9/9/2021 17:31",
1111
"keywords" : "pre 7/26/2019 14:00",
1212
"methodSourceRequiresBPLayers:" : "pre 11/11/2019 15:49",
1313
"parse:" : "pre 1/11/2021 15:51",

packages/Babylonian-Tests.package/BPCompilerExceptionTest.class/README.md

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
compiling
2+
compilerClass
3+
4+
^ BPCompiler
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
assertions
2+
assertCanceled
3+
4+
self
5+
assertText: originalText;
6+
assertSelection: previousSelection.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
assertions
2+
assertSelection: selectionMatch
3+
4+
selectionMatch isBlock ifTrue: [
5+
^ self assertSelection: selectionMatch value].
6+
^ self
7+
assert: selectionMatch
8+
equals: (selectionMatch isInterval
9+
ifTrue: [self selectionInterval]
10+
ifFalse: [self selection])
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
assertions
2+
assertSucceeded: textMatch
3+
4+
self
5+
assertText: textMatch;
6+
assertSelection: originalSelection.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
assertions
2+
assertSucceeded
3+
4+
^ self assertSucceeded: originalText
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
assertions
2+
assertText: textMatch
3+
4+
text isBlock ifTrue: [
5+
^ self assertText: text value].
6+
^ (textMatch respondsTo: #matches:)
7+
ifTrue: [
8+
self assert: [textMatch matches: (self codePaneTextMorph textMorph contents) asString]]
9+
ifFalse: [
10+
self assert: textMatch equals: (self codePaneTextMorph textMorph contents) asString]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
private
2+
codePaneTextMorph
3+
4+
^ browser containingWindow submorphNamed: 'codePaneTextMorph'.

0 commit comments

Comments
 (0)