Added prototype Java code generator which generates setter methods CustomJavaSimpleSetterMethodsCodeGenerator
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CustomJavaSimpleSetterMethodsCodeGenerator.st Mon Feb 02 22:23:11 2015 +0100
@@ -0,0 +1,95 @@
+"{ Package: 'jn:refactoring_custom' }"
+
+"{ NameSpace: Smalltalk }"
+
+CustomCodeGenerator subclass:#CustomJavaSimpleSetterMethodsCodeGenerator
+ instanceVariableNames:''
+ classVariableNames:''
+ poolDictionaries:''
+ category:'Interface-Refactoring-Custom-Generators'
+!
+
+!CustomJavaSimpleSetterMethodsCodeGenerator class methodsFor:'accessing-presentation'!
+
+description
+ "Returns more detailed description of the receiver"
+
+ ^ 'Generates setter methods for instance variables of Java Class'
+
+ "Created: / 01-02-2015 / 20:42:59 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
+!
+
+label
+ "Returns show label describing the receiver. This label
+ is used in UI as menu item/tree item label."
+
+ ^ 'Setter Method(s)'
+
+ "Created: / 01-02-2015 / 20:43:33 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
+! !
+
+!CustomJavaSimpleSetterMethodsCodeGenerator class methodsFor:'queries'!
+
+availableForProgrammingLanguages
+ "Returns list of programming language instances for which this generator / refactoring works.
+ (SmalltalkLanguage instance, JavaLanguage instance, GroovyLanguage instance, etc.)
+
+ See also availableForProgrammingLanguagesInContext:withPerspective:"
+
+ ^ {JavaLanguage instance}
+
+ "Created: / 01-02-2015 / 20:44:19 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
+!
+
+availableInContext: aCustomContext
+ "Returns true if the generator/refactoring is available in given
+ context, false otherwise.
+
+ Called by the UI to figure out what generators / refactorings
+ are available at given point. See class CustomContext for details."
+
+ ^ aCustomContext selectedClasses notEmptyOrNil
+
+ "Created: / 01-02-2015 / 20:40:38 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
+!
+
+availableInPerspective: aCustomPerspective
+ "Returns true if the generator/refactoring is available in given
+ perspective, false otherwise.
+
+ Called by the UI to figure out what generators / refactorings
+ to show"
+
+ ^ aCustomPerspective isClassPerspective
+
+ "Created: / 01-02-2015 / 20:41:14 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
+! !
+
+!CustomJavaSimpleSetterMethodsCodeGenerator methodsFor:'executing - private'!
+
+buildInContext: aCustomContext
+ "Prototype generator for Java language - proper way should be usage of some Java parser"
+
+ self warn: 'Experimenatal generator, may not work as expected.'.
+
+ aCustomContext selectedClasses do: [ :class |
+ class instanceVariableNames do: [ :varName |
+ | setter type newDefinition endOfClass |
+
+ type := (class realClass typeOfField: varName) asString.
+ setter := '
+ public ', type, ' ', varName, '(', type, ' ', varName, ') {
+ this.', varName, ' = ', varName, ';
+ }
+'.
+ newDefinition := class realClass definition.
+ endOfClass := newDefinition lastIndexOf: $}.
+ newDefinition := (newDefinition copyTo: endOfClass - 1), setter, (newDefinition copyFrom: endOfClass).
+ JavaCompiler compile: newDefinition
+ ]
+ ]
+
+ "Created: / 01-02-2015 / 17:58:54 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
+ "Modified: / 02-02-2015 / 22:20:34 / Jakub Nesveda <nesvejak@fit.cvut.cz>"
+! !
+
--- a/jn_refactoring_custom.st Sun Feb 01 20:31:27 2015 +0100
+++ b/jn_refactoring_custom.st Mon Feb 02 22:23:11 2015 +0100
@@ -187,6 +187,7 @@
CustomAccessMethodsCodeGenerator
CustomCodeSelectionRefactoring
CustomIsAbstractCodeGenerator
+ CustomJavaSimpleSetterMethodsCodeGenerator
CustomNewClassGenerator
CustomReplaceIfNilWithIfTrueRefactoring
CustomSubclassResponsibilityCodeGenerator
--- a/patches/patches.rc Sun Feb 01 20:31:27 2015 +0100
+++ b/patches/patches.rc Mon Feb 02 22:23:11 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", "Sun, 01 Feb 2015 19:29:08 GMT\0"
+ VALUE "ProductDate", "Mon, 02 Feb 2015 21:22:08 GMT\0"
END
END
--- a/refactoring_custom.rc Sun Feb 01 20:31:27 2015 +0100
+++ b/refactoring_custom.rc Mon Feb 02 22:23:11 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", "Sun, 01 Feb 2015 19:29:06 GMT\0"
+ VALUE "ProductDate", "Mon, 02 Feb 2015 21:22:06 GMT\0"
END
END