熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java開源技術 >> 正文

Eclipse工具開發:編寫代碼生成器[5]

2022-06-13   來源: Java開源技術 
    ——此文章摘自《自己動手寫開發工具基於Eclipse的工具開發》定價 特價 詳細>>http://tracklinktechcn/?m_id=dangdang&a_id=A&l=&l_type= width= height= border= nosave>

    【代碼】模板參數類
    public class EnumGenArgInfo
    {
        private Set<String> items;
        private String className;
        private String packageName;
      
        public String getPackageName()
        {
            return packageName;
        }
        public void setPackageName(String packageName)
        {
            thispackageName = packageName;
        }
        public String getClassName()
        {
            return className;
        }
        public void setClassName(String className)
        {
            thisclassName = className;
        }
        public Set<String> getItems()
        {
            return items;
        }
        public void setItems(Set<String> items)
        {
            thisitems = items;
        }
    }

    接下來我們來寫模板文件

    【代碼】模板文件
    <%@ jet package=comcownewenumgeneratorwizards
    class=EnumCodeGenerator
      imports=javautil*
    %>
    <%
      EnumGenArgInfo argInfo = (EnumGenArgInfo)argument;
      Set<String> enumItems = argInfogetItems();
      String className = argInfogetClassName();
      String packageName = argInfogetPackageName();
    %>
    package <%=packageName%>;
    public class <%=className%>
    {
        private String type;
        <%for(String item:enumItems){%>
        public <%=className%> <%=item%> = new <%=className%>(<%=item%>);
        <%}%>

right>[http://developcsaicn/Java_Eclipse/htm>]  [http://developcsaicn/Java_Eclipse/htm>]  [http://developcsaicn/Java_Eclipse/htm>]  [http://developcsaicn/Java_Eclipse/htm>]  []  [http://developcsaicn/Java_Eclipse/htm>]  


From:http://tw.wingwit.com/Article/program/Java/ky/201311/29011.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.