Tuesday, October 20, 2009

Serial Version UID - Netbeans 6.8 M2

Providing a code template is a very simple affair in Netbeans. You can manually create the entry in the options dialog or write a plugin. The plugin affair is quite simple.

Steps:

  1. Create a new NB Module
  2. Expand the Tree as follows in the projects view
    1. -->Important files-->XML Layer-->-->Editors-->text-->x-java-->CodeTemplates-->Defaults
    2. Right click on the file named org-netbeans-modules-editor-java-codetemplates.xml.
    3. Click Edit
    4. append the following line near the end of the file (before the </codetemplates> tag)  
<codetemplate abbreviation="suid" descriptionId="Generate Serial version uid"><code><![CDATA[private static final long serialVersionUID = 1L; ]]></code></codetemplate>
    • Run the project, 
    • a new instance of netbeans will be started. 
    • Bring up the options dialog. 
    • Click on editor-->Code templates tab
    • Select Java as the language
    • Scroll down the list looking for suid
    Viola, code template ready.


    Another option is to use the code generator




    1. in the module create above right click on the module package and click new
    2. Optionally click other
    3. Select code generator in the Module development
    4. Provide a name
    5. in the mime type enter text/x-java
    6. Open the class that is generated and search for the getDisplayName method and replace the method content as return NbBundle.getMessage(SerialVersionUIDGenerator.class, "SerialVersionUIDGenerator.label");
    7. Now for the meat of the implementation. Search for the invoke method and add the following contents


            Caret caret = textComp.getCaret();
            int start = Math.min(caret.getDot(), caret.getMark());
            StringBuilder builder = new StringBuilder("private static final long serialVersionUID = 1L;");
            builder.append(System.getProperty("line.separator","\n"));
            Document doc = textComp.getDocument();
            try {
                doc.insertString(start, builder.toString(), null);
            } catch (BadLocationException ex) {
                Exceptions.printStackTrace(ex);
            }

    The plugin is available for download from Kenai or netbeans plugin portal

    37 comments:

    Michal Hlaváč said...

    netbeans 6.8 has already implemented hint for serialVersionUID. Goto Tools -> Options -> Editor -> Hints

    Set language to Java and in General section check serialVersionUID not defined checkbox.

    Or if you want to generated value use http://kenai.com/projects/nb-svuid-generator

    九份 said...

    If you can not be kind, at least have the decency to be vague.............................................

    太可怕 said...

    讓人流連忘返,真期待新文章發表!........................................

    pass said...

    自拍短片國中自拍免費自拍小魔自拍影片做愛自拍線上台灣自拍論壇台灣自慰影片台灣色小說台灣色文學台灣色文學網台灣情kiss網台灣情網色網台灣論壇區外國色片外國色情網站外國色情影片外國免費a片外國免費色情外國免費影片外國美女做愛外國美女圖外國美女圖片外國美女寫真孕婦做愛小說孕婦做愛自拍台灣論壇小說區台灣論台台灣線上a片王台灣情論壇台灣無限圖帖成人小說 言情小說 巨乳上班族聊天室

    水慧于名 said...

    很棒的分享~留言支持!........................................

    惠佩政萍 said...

    Hello~Nice to meet you~..................................................

    明宏明宏 said...

    nice job! waiting for your new artical. ........................................

    Myrle14778 said...

    以簡單的行為愉悅他人的心靈,勝過千人低頭禱告........................................

    昭士松修 said...

    Quietude is the crown of life.......................................................

    淑惠 said...

    我們唯一需要恐懼的事,是恐懼本身 ..................................................

    VincenzoJ詩婷 said...

    請繼續發表好文!加油加油加油!.............................................

    振宇 said...

    Circumstances are the rulers of the weak, instrument of the wise..........................

    柏勳 said...

    April showers bring May flowers. ........................................

    ElisaCe慈佐lestin0708 said...

    春冰薄,人情更薄;登天難,求人更難。 ............................................................

    huntb said...

    微風成人片 a視訊 一夜情情色聊天室 免費視訊 視訊影音交友 av女優寫真集 性感圖片 影片免費觀賞 偷拍影片 ut男女聊天室 如何做愛愛 情趣美女真 做愛18招 少女裸睡故事 免費色情片影城 成人免費a片 情色成人電影 線上免費色情影片 一夜情留言板 aio交友 名模寫真 玩美女影片 情色美女 辣妹按摩影片 人妻線上免費影片欣賞 聊天室 視訊聊天 ut a圖 女寫真 85cc 免費影城 貼圖區 78論壇 線上漫畫777 色貼圖片 台北援交妹留言版 性感情人趣味 鋼管秀影片 avdvd影片 洪爺影城 大奶頭美女 sex貼圖區 a片免費下載 日本巨乳av女優 免費性卡通影片觀賞 後宮電影院 限制級 偷拍0204 性愛罐頭影片 比基尼走光

    許美玉 said...

    人間好話,要如海綿遇水牢牢吸住..................................................................

    吳鈺婷 said...

    Where did you purchase this product?.................................................................

    涂宛臻 said...

    成熟,就是有能力適應生活中的模糊。.................................................................                           

    貴寶 said...

    Pen and ink is wits plough. ....................................................................

    靜宸靜宸 said...

    成熟,就是有能力適應生活中的模糊。.................................................................

    宥妃宥妃 said...

    人生是故事的創造與遺忘。............................................................

    懿綺懿綺 said...

    人因夢想而偉大,要堅持自己的理想哦..................................................................

    芸茂芸茂 said...

    今夜星光多美好~祝你快樂~~~~..................................................................

    吳婷婷 said...

    Pen and ink is wits plough. ............................................................

    楊儀卉 said...

    Of two evils choose the least.............................................................

    崔佐安崔佐安 said...

    很棒的分享~~~來留個言囉~~~~..................................................................

    瑤德 said...

    人類的聰明,並非以經驗為依歸,而是以接受經驗的行程為依歸。..................................................

    姚宜潔 said...

    教育的目的,不在應該思考什麼,而是教吾人怎樣思考............................................................

    謝俊柯凡豐德 said...

    Govern your thoughts when alone, and your tongue when in company...................................................

    鄭信弘 said...

    唯有學習不已的老師,才能認真的教,唯有燃燒自己,才能點亮他人的燈............................................................

    家唐銘 said...

    聰明人之所以不會成功,是因為他們缺乏了堅忍的毅力。.................................................

    偉曹琬 said...

    堅持是為著某種目的或目標,而持續不斷朝向既定方向努力的一種意念。..................................................

    偉曹琬 said...

    Of two evils choose the least.............................................................

    偉曹琬 said...

    所有的資產,在不被諒解時,都成了負債..................................................................

    怡屏 said...

    祝福你人氣不減ˊˇˋ............................................................

    幸平平平平杰 said...

    快樂,是享受工作過程的結果......................................................................

    璇陳陳陳竹 said...

    Subtlety is better than force. ......................................................................