[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-smalltalk] [PATCH] stinst: Allow gst-convert to work for OldSyntax
From: |
Holger Hans Peter Freyther |
Subject: |
[Help-smalltalk] [PATCH] stinst: Allow gst-convert to work for OldSyntax/Squeak syntax |
Date: |
Sun, 10 Feb 2013 12:00:51 +0100 |
From: Holger Hans Peter Freyther <address@hidden>
The gst-convert command
$ gst-convert -r'Osmo.LogManager -> LogManager' -F squeak -f gst
was rewriting the nodes but the exported file contained the original
unmodified sourcecode. The FormattingExporter for the gst syntax is
using the >>#methodFormattedSourceString to format, use it inside the
OldSyntaxExporter as well. Another option would be to subclass the
SqueakSyntaxExporter and OldSyntaxExporter and add the formatting there.
2013-02-10 Holger Hans Peter Freyther <address@hidden>
* OldSyntaxExporter.st: Reformat the method node in
OldSyntaxExporter>>#oldSyntaxSourceCodeFor:.
* RewriteTests.st: Add the TestRewrite class.
* package.xml: Add the TestRewrite test to the testsuite.
---
packages/stinst/parser/ChangeLog | 7 +++
packages/stinst/parser/OldSyntaxExporter.st | 3 +-
packages/stinst/parser/RewriteTests.st | 74 +++++++++++++++++++++++++++
packages/stinst/parser/package.xml | 1 +
4 files changed, 83 insertions(+), 2 deletions(-)
diff --git a/packages/stinst/parser/ChangeLog b/packages/stinst/parser/ChangeLog
index 71f4139..df4407e 100644
--- a/packages/stinst/parser/ChangeLog
+++ b/packages/stinst/parser/ChangeLog
@@ -1,3 +1,10 @@
+2013-02-10 Holger Hans Peter Freyther <address@hidden>
+
+ * OldSyntaxExporter.st: Reformat the method node in
+ OldSyntaxExporter>>#oldSyntaxSourceCodeFor:.
+ * RewriteTests.st: Add the TestRewrite class.
+ * package.xml: Add the TestRewrite test to the testsuite.
+
2013-01-29 Holger Hans Peter Freyther <address@hidden>
* STLoaderObjs.st: Put class variables into the classVars array.
diff --git a/packages/stinst/parser/OldSyntaxExporter.st
b/packages/stinst/parser/OldSyntaxExporter.st
index b02221e..d23cd22 100644
--- a/packages/stinst/parser/OldSyntaxExporter.st
+++ b/packages/stinst/parser/OldSyntaxExporter.st
@@ -171,8 +171,7 @@ FileOutExporter subclass: OldSyntaxExporter [
oldSyntaxSourceCodeFor: aMethod [
| source cat |
- aMethod isOldSyntax ifTrue: [ ^aMethod methodSourceString ].
- source := aMethod methodSourceString.
+ source := aMethod methodFormattedSourceString.
source := source copyReplacingRegex: '\s*\[\s*(.*[\S\n])' with: '
%1'.
source := source copyReplacingRegex: '\s*]\s*$' with: '
diff --git a/packages/stinst/parser/RewriteTests.st
b/packages/stinst/parser/RewriteTests.st
index 018035b..8b09598 100644
--- a/packages/stinst/parser/RewriteTests.st
+++ b/packages/stinst/parser/RewriteTests.st
@@ -249,5 +249,79 @@ behavior stayed the same, at least as much as I care it to
stay so.'>
]
]
+TestCase subclass: TestRewrite [
+ <comment: 'I test that rewriting a method for the OldSyntaxExport and
+ SqueakExporter will pick up the new code.'>
+
+ testNamespaceRewrite [
+ | class tree rule rewriter res out|
+
+ tree := RBParser parseRewriteExpression: 'Osmo.LogManager ->
LogManager'.
+ rule := RBStringReplaceRule
+ searchForTree: tree receiver
+ replaceWith: tree arguments first.
+ rewriter := ParseTreeRewriter new
+ addRule: rule; yourself.
+
+ class := (STClassLoader new
+ parseSmalltalkStream: 'Object subclass: TestData [
+ logManager [
+ ^Osmo.LogManager default
+ ]
+ ]' readStream with: GSTFileInParser) first.
+
+ "Rewrite the method. This will modify the code on inside the class"
+ res := rewriter executeTree: (class >> #logManager) node; tree.
+ self assert: (class >> #logManager) node == res.
+
+ "Now generate the code"
+ out := WriteStream on: (String new).
+ (SqueakSyntaxExporter on: class to: out)
+ completeFileOut: false;
+ fileOutSelectors: (Array with: #logManager) classSelectors: #().
+ self assert: (out contents indexOfSubCollection: 'Osmo.LogManager') =
0.
+ ]
+
+ testOldSyntaxNamespaceRewrite [
+ | class tree rule rewriter res out|
+
+ tree := RBParser parseRewriteExpression: 'Osmo.LogManager ->
LogManager'.
+ rule := RBStringReplaceRule
+ searchForTree: tree receiver
+ replaceWith: tree arguments first.
+ rewriter := ParseTreeRewriter new
+ addRule: rule; yourself.
+
+ "Load the old code"
+ class := (STClassLoader new
+ parseSmalltalkStream:
+'SystemOrganization addCategory: #''osmo-logging-core''!
+Object subclass: #LogManager
+ instanceVariableNames: ''target filter areas''
+ classVariableNames: ''Log''
+ poolDictionaries: ''''
+ category: ''osmo-logging-core''!
+
+!LogManager methodsFor: ''as yet unclassified''!
+
+logManager
+ ^Osmo.LogManager default
+! !' readStream with: SqueakFileInParser) first.
+
+
+ "Rewrite the method. This will modify the code on inside the class"
+ res := rewriter executeTree: (class >> #logManager) node; tree.
+ self assert: (class >> #logManager) node == res.
+ self assert: (class >> #logManager) isOldSyntax.
+
+ "Now generate the code"
+ out := WriteStream on: (String new).
+ (SqueakSyntaxExporter on: class to: out)
+ completeFileOut: false;
+ fileOutSelectors: (Array with: #logManager) classSelectors: #().
+ self assert: (out contents indexOfSubCollection: 'Osmo.LogManager') =
0.
+ ]
+]
+
]
diff --git a/packages/stinst/parser/package.xml
b/packages/stinst/parser/package.xml
index 1c9f2c7..ad33622 100644
--- a/packages/stinst/parser/package.xml
+++ b/packages/stinst/parser/package.xml
@@ -28,6 +28,7 @@
<test>
<namespace>STInST.Tests</namespace>
<sunit>STInST.Tests.TestStandardRewrites</sunit>
+ <sunit>STInST.Tests.TestRewrite</sunit>
<sunit>STInST.Tests.TestDefaultPoolResolution</sunit>
<sunit>STInST.Tests.TestClassicPoolResolution</sunit>
<filein>RewriteTests.st</filein>
--
1.7.10.4
- [Help-smalltalk] [PATCH] stinst: Allow gst-convert to work for OldSyntax/Squeak syntax,
Holger Hans Peter Freyther <=