flex生成po类get,set方法
发布时间:2020-12-15 04:00:42 所属栏目:百科 来源:网络整理
导读:为flex的as文件生成po类的set,get方法。貌似工具只支持一次产生一个,所以就写了一个小程序,支持一次生成多个set/get方法。 遇到一个问题,就是怎么在一个字符串前面,得到第一个非空格字符的位置?也就是说,想要知道第一个非空格字符前有多少个空格?这
为flex的as文件生成po类的set,get方法。貌似工具只支持一次产生一个,所以就写了一个小程序,支持一次生成多个set/get方法。 遇到一个问题,就是怎么在一个字符串前面,得到第一个非空格字符的位置?也就是说,想要知道第一个非空格字符前有多少个空格?这个怎么得到?注意:两个空tab,和4个空格,实现的效果是一样的,但怎么分他们呢?
package com.lee.genPO.genFlexAsPO; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; /** * @author painarthur * @since 2013.11 * @version 1.0 * @share http://blog.csdn.net/paincupid */ public class GenFlexAsPO { public static void genPO(String fileName) throws Exception { File file = new File(fileName); BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(file)); String tempString = null; // 一次读入一行,直到读入null为文件结束 while ((tempString = reader.readLine()) != null) { String str = tempString.trim(); if(!str.contains("var")||!str.contains(";")||str.contains("return")||str.contains("function")){ continue; } if(str==null||str.length()<2){ throw new Exception("不可为空,或没有冒号或数据类型"); } int num = str.indexOf(";"); str = str.substring(0,num); str = str.replace("private","").replace("var","").trim(); int num_Colon = str.indexOf(":"); String poName = str.substring(0,num_Colon); if(poName==null||poName.equals("") ||!(poName.subSequence(0,1).equals("_"))||poName.length()<2){ throw new Exception("不可为空,或属性前不是下划线"); } String type = str.substring(num_Colon+1,str.length()); StringBuilder getMethod = new StringBuilder(); getMethod.append(genSpace(4)).append("public function get ").append(poName.substring(1,poName.length())) .append("():").append(type).append("{").append("rn"); getMethod.append(genSpace(6)).append("return ") .append(poName).append(";").append("rn").append(genSpace(4)).append("}").append("rn"); StringBuilder postMethod = new StringBuilder(); postMethod.append(genSpace(4)).append("public function set ").append(poName.substring(1,poName.length())) .append("(value:").append(type).append("):void").append("{").append("rn") .append(genSpace(6)).append(poName).append("=") .append("value;").append("rn").append(genSpace(4)).append("}").append("rn"); System.out.println(getMethod); System.out.println(postMethod); } reader.close(); } catch (IOException e) { e.printStackTrace(); } finally { if (reader != null) { try { reader.close(); } catch (IOException e1) { } } } } public static String genSpace(int num){ StringBuilder s = new StringBuilder(); if(num<=0) return ""; for(int i= 0;i<num;i++){ s.append("u0020"); } return s.toString(); } public static void main(String[] args) throws Exception { String path = "G:asPOgen.txt"; GenFlexAsPO g = new GenFlexAsPO(); genPO(path); } } 文章来自于(转载时请注明): http://www.voidcn.com/article/p-fqflwpbi-oz.html (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |