andrew.arnott Posted October 20, 2005 Share Posted October 20, 2005 (edited) Woot! It works now -- Any issues/suggestions? This hotkey function will take whatever variable declarations you have highlighted in your IDE, and then create appropriate getter/setter methods (upon pressing ctrl + shift + d). For example: Say you have highlighted: private int monkey; public Chimpanzee andrew; protected Monkey kingKong; Would put into the clipboard for you to paste (upon pressing ctrl + shift + d) public int getMonkey() { return this.monkey; } public void setMonkey(int monkey) { this.monkey = monkey; } public Chimpanzee getAndrew() { return this.andrew; } public void setAndrew(Chimpanzee andrew) { this.andrew = andrew; } public Monkey getKingKong() { return this.kingKong; } public void setKingKong(Monkey kingKong) { this.kingKong = kingKong; } expandcollapse popupHotKeySet("^+d", "CreateGetterSetter") #Include <string.au3> #Include <array.au3> While 1 Sleep(0x7FFFFFFF) WEnd Func CreateGetterSetter() Send("{CTRLDOWN}c{CTRLUP}") $text = ClipGet() $text = StringReplace($text,@CRLF," ") $text = StringReplace($text,@LF," ") $text = StringReplace($text,@CR," ") $text = StringReplace($text,@TAB,"") Local $split = StringSplit($text, " ") $count = 1 While($count < UBound($split)) If($split[$count] = "") Then _ArrayDelete($split, $count) $split[0] = $split[0] - 1 Else $count = UBound($split) EndIf WEnd $count = UBound($split) - 1 While($count > 0) If($split[$count] = "") Then _ArrayDelete($split, $count) $count = $count - 1 $split[0] = $split[0] - 1 Else $count = 0 EndIf WEnd Local $return = "" If (Mod($split[0], 3) = 0) Then For $i = 1 To ($split[0] / 3) $split[$i*3] = StringReplace($split[$i*3],";",'') $return = $return & "public " & $split[$i*3 - 1] & " get" & StringReplace($split[$i*3], StringMid($split[$i*3], 1, 1), StringUpper(StringMid($split[$i*3], 1, 1)), 1) & "() {" & @CRLF $return = $return & @TAB & "return this." & $split[$i*3] & ";" & @CRLF $return = $return & "}" & @CRLF & @CRLF $return = $return & "public void set" & StringReplace($split[$i*3], StringMid($split[$i*3], 1, 1), StringUpper(StringMid($split[$i*3], 1, 1)), 1) & "(" & $split[$i*3 - 1] & " " & $split[$i*3] & ") {" & @CRLF $return = $return & @TAB & "this." & $split[$i*3] & " = " & $split[$i*3] & ";" & @CRLF $return = $return & "}" & @CRLF & @CRLF ClipPut($return) Next MsgBox(0, "Done!", "Getters and Setters successfully created", 0) EndIf EndFunc Hurray for lazy coding! Edited October 21, 2005 by andrew.arnott Link to comment Share on other sites More sharing options...
Insolence Posted October 20, 2005 Share Posted October 20, 2005 What a fool I was doing those by hand in C#, sweet script "I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar. Link to comment Share on other sites More sharing options...
andrew.arnott Posted October 21, 2005 Author Share Posted October 21, 2005 Updates complete -- now allows for multiple setter/getters at once Link to comment Share on other sites More sharing options...
w0uter Posted October 21, 2005 Share Posted October 21, 2005 i prefere more controll over what i make but for the lazy ppl its nice My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll Link to comment Share on other sites More sharing options...
andrew.arnott Posted October 24, 2005 Author Share Posted October 24, 2005 Well really you don't need any control over setter and getter methods. They should never be any different than the template. And as far as naming conventions, this preserves the java standard (I'm not sure what other languages have for their standards). I'm probably going to add some more lazy-coder hotkeys when I see myself doing repetitive tasks. I'm pretty sure this one has already saved me some time (lets just say I make a boatload of POJOs on a regular basis). Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now