Added prototype JavaScript (setter method) code generator (CustomJavaScriptSimpleSetterMethodsCodeGenerator)
well, it is not very compatible with Refactory Browser package, but it works (limited) for this case
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CustomJavaScriptSimpleSetterMethodsCodeGenerator.st Sun Feb 01 16:34:31 2015 +0100
@@ -0,0 +1,58 @@
+"{ Package: 'jn:refactoring_custom' }"
+
+"{ NameSpace: Smalltalk }"
+
+CustomSimpleSetterMethodsCodeGenerator subclass:#CustomJavaScriptSimpleSetterMethodsCodeGenerator
+ instanceVariableNames:''
+ classVariableNames:''
+ poolDictionaries:''
+ category:'Interface-Refactoring-Custom-Generators'
+!
+
+!CustomJavaScriptSimpleSetterMethodsCodeGenerator class methodsFor:'documentation'!
+
+documentation
+"
+ Same purpose like superclass, but for STX JavaScript language.
+
+ [author:]
+ Jakub Nesveda <nesvejak@fit.cvut.cz>
+"
+! !
+
+!CustomJavaScriptSimpleSetterMethodsCodeGenerator class methodsFor:'queries'!
+
+availableForProgrammingLanguages
+
+ ^ {STXJavaScriptLanguage instance}
+
+ "Created: / 31-01-2015 / 18:16:04 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
+! !
+
+!CustomJavaScriptSimpleSetterMethodsCodeGenerator methodsFor:'code generation'!
+
+sourceForClass: aClass variableName: aName
+ "Returns simple setter for given STX JavaScript class and variable name."
+
+ | methodName comment argName |
+
+ methodName := aName.
+ argName := self argNameForMethodName: methodName.
+ comment := ''.
+
+ userPreferences generateCommentsForSetters ifTrue:[
+ | varType |
+
+ varType := self varTypeOf: aName class: aClass.
+ comment := '
+ // set the value of the %1 variable ''%2'' (automatically generated)'.
+ comment := comment bindWith: varType with: aName.
+ ].
+
+ ^ methodName, '(', argName, ') {', comment, '
+ ', aName, ' = ', argName, ';
+}'.
+
+ "Created: / 31-01-2015 / 18:15:11 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
+! !
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CustomJavaScriptSimpleSetterMethodsCodeGeneratorTests.st Sun Feb 01 16:34:31 2015 +0100
@@ -0,0 +1,90 @@
+"{ Package: 'jn:refactoring_custom' }"
+
+"{ NameSpace: Smalltalk }"
+
+CustomCodeGeneratorOrRefactoringTestCase subclass:#CustomJavaScriptSimpleSetterMethodsCodeGeneratorTests
+ instanceVariableNames:'javaScriptClass'
+ classVariableNames:''
+ poolDictionaries:''
+ category:'Interface-Refactoring-Custom-Generators-Tests'
+!
+
+!CustomJavaScriptSimpleSetterMethodsCodeGeneratorTests methodsFor:'accessing'!
+
+generatorOrRefactoring
+ ^ CustomJavaScriptSimpleSetterMethodsCodeGenerator new
+! !
+
+!CustomJavaScriptSimpleSetterMethodsCodeGeneratorTests methodsFor:'initialization & release'!
+
+setUp
+ | classDefinition |
+
+ super setUp.
+
+ classDefinition := 'public class DummyJavaStriptClass01 extends Object {
+ var instVar01;
+}'.
+
+ Class withoutUpdatingChangesDo: [
+ JavaScriptCompiler evaluate: classDefinition notifying: nil compile: nil
+ ].
+
+ javaScriptClass := Smalltalk at: #DummyJavaStriptClass01.
+
+ "Modified: / 01-02-2015 / 16:22:44 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
+!
+
+tearDown
+
+ Class withoutUpdatingChangesDo: [
+ javaScriptClass removeFromSystem
+ ].
+ "super tearDown."
+ "Call of undoing changes produces error relevant
+ to parsing JavaScript source code as Smalltalk code."
+ "changeManager undoChanges."
+ mock unmockAll
+
+ "Modified: / 01-02-2015 / 16:21:27 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
+! !
+
+!CustomJavaScriptSimpleSetterMethodsCodeGeneratorTests methodsFor:'tests'!
+
+test_simple_setter_generated_with_comment
+ | expectedSource |
+
+ userPreferences generateComments: true.
+
+ context selectedClasses: {javaScriptClass}.
+
+ expectedSource := 'instVar01(something) {
+ // set the value of the instance variable ''instVar01'' (automatically generated)
+ instVar01 = something;
+}'.
+
+ generatorOrRefactoring executeInContext: context.
+
+ self assertMethodSource: expectedSource atSelector: #'instVar01:' forClass: javaScriptClass
+
+ "Created: / 01-02-2015 / 16:24:34 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
+!
+
+test_simple_setter_generated_without_comment
+ | expectedSource |
+
+ userPreferences generateComments: false.
+
+ context selectedClasses: {javaScriptClass}.
+
+ expectedSource := 'instVar01(something) {
+ instVar01 = something;
+}'.
+
+ generatorOrRefactoring executeInContext: context.
+
+ self assertMethodSource: expectedSource atSelector: #'instVar01:' forClass: javaScriptClass
+
+ "Created: / 01-02-2015 / 16:26:05 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
+! !
+
--- a/abbrev.stc Sat Jan 31 23:31:30 2015 +0100
+++ b/abbrev.stc Sun Feb 01 16:34:31 2015 +0100
@@ -59,6 +59,7 @@
CustomCodeSelectionToResourceTranslationTests CustomCodeSelectionToResourceTranslationTests jn:refactoring_custom 'Interface-Refactoring-Custom-Refactorings-Tests' 1
CustomDefaultGetterMethodsCodeGeneratorTests CustomDefaultGetterMethodsCodeGeneratorTests jn:refactoring_custom 'Interface-Refactoring-Custom-Generators-Tests' 1
CustomIsAbstractCodeGeneratorTests CustomIsAbstractCodeGeneratorTests jn:refactoring_custom 'Interface-Refactoring-Custom-Generators-Tests' 1
+CustomJavaScriptSimpleSetterMethodsCodeGeneratorTests CustomJavaScriptSimpleSetterMethodsCodeGeneratorTests jn:refactoring_custom 'Interface-Refactoring-Custom-Generators-Tests' 1
CustomLazyInitializationAccessMethodsCodeGeneratorTests CustomLazyInitializationAccessMethodsCodeGeneratorTests jn:refactoring_custom 'Interface-Refactoring-Custom-Generators-Tests' 1
CustomLazyInitializationGetterMethodsCodeGeneratorTests CustomLazyInitializationGetterMethodsCodeGeneratorTests jn:refactoring_custom 'Interface-Refactoring-Custom-Generators-Tests' 1
CustomLocalChangeManager CustomLocalChangeManager jn:refactoring_custom 'Interface-Refactoring-Custom' 0
--- a/jn_refactoring_custom.st Sat Jan 31 23:31:30 2015 +0100
+++ b/jn_refactoring_custom.st Sun Feb 01 16:34:31 2015 +0100
@@ -64,7 +64,7 @@
#'stx:libcomp' "Parser - referenced by CustomNamespace>>createMethodImmediate:protocol:source:package:"
#'stx:libjava' "JavaClass - referenced by CustomCodeGeneratorOrRefactoringTests>>test_available_for_programming_languages_in_context_filled_with_class_perspective_java"
#'stx:libjava/tools' "JavaCompiler - referenced by CustomRBAbstractClassTests>>test_compiler_class_java"
- #'stx:libjavascript' "JavaScriptCompiler - referenced by CustomRBAbstractClassTests>>test_compiler_class_javascript"
+ #'stx:libjavascript' "JavaScriptCompiler - referenced by CustomJavaScriptSimpleSetterMethodsCodeGeneratorTests>>setUp"
#'stx:libview' "WindowGroup - referenced by CustomCodeGeneratorOrRefactoring>>executeInContextWithWaitCursor:"
#'stx:libwidg' "DialogBox - referenced by CustomCodeGeneratorOrRefactoringTests>>test_execute_in_context_aborted"
#'stx:libwidg2' "CheckBox - referenced by CustomDialog>>addCheckBoxOn:labeled:"
@@ -152,6 +152,7 @@
(CustomCodeSelectionToResourceTranslationTests autoload)
(CustomDefaultGetterMethodsCodeGeneratorTests autoload)
(CustomIsAbstractCodeGeneratorTests autoload)
+ (CustomJavaScriptSimpleSetterMethodsCodeGeneratorTests autoload)
(CustomLazyInitializationAccessMethodsCodeGeneratorTests autoload)
(CustomLazyInitializationGetterMethodsCodeGeneratorTests autoload)
CustomLocalChangeManager
--- a/patches/patches.rc Sat Jan 31 23:31:30 2015 +0100
+++ b/patches/patches.rc Sun Feb 01 16:34:31 2015 +0100
@@ -25,7 +25,7 @@
VALUE "LegalCopyright", "My CopyRight or CopyLeft\0"
VALUE "ProductName", "LibraryName\0"
VALUE "ProductVersion", "6.2.5.1516\0"
- VALUE "ProductDate", "Sat, 31 Jan 2015 22:15:54 GMT\0"
+ VALUE "ProductDate", "Sun, 01 Feb 2015 15:30:01 GMT\0"
END
END
--- a/refactoring_custom.rc Sat Jan 31 23:31:30 2015 +0100
+++ b/refactoring_custom.rc Sun Feb 01 16:34:31 2015 +0100
@@ -25,7 +25,7 @@
VALUE "LegalCopyright", "My CopyRight or CopyLeft\0"
VALUE "ProductName", "ProductName\0"
VALUE "ProductVersion", "6.2.5.1516\0"
- VALUE "ProductDate", "Sat, 31 Jan 2015 22:15:53 GMT\0"
+ VALUE "ProductDate", "Sun, 01 Feb 2015 15:30:00 GMT\0"
END
END