Created
March 20, 2017 07:56
-
-
Save codingmiao/29ea42b496765de952c9c32e7ed898d8 to your computer and use it in GitHub Desktop.
生成装饰器模式的ResultSet代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.wowtools.dao; | |
import java.sql.SQLException; | |
import java.util.function.IntConsumer; | |
/** | |
* @author liuyu | |
* @date 2017/3/20 | |
*/ | |
public class T44 { | |
// @Override | |
// public String getString(int columnIndex) throws SQLException { | |
// return null; | |
// } | |
public static void main(String[] args) { | |
String s = org.wowtools.common.utils.ResourcesReader.readStr("D:\\IDEA\\work\\mygithub\\catframe\\catframe\\catframe-dao\\src\\main\\java\\org\\wowtools\\dao\\DecoratorResultSet.java"); | |
String[] methods = s.split("@Over" + "ride"); | |
for (String method : methods) { | |
int e = method.indexOf("("); | |
int b = method.lastIndexOf(" ", e); | |
String name = method.substring(b, e); | |
b = e; | |
e = method.indexOf(")") + 1; | |
String param = method.substring(b, e); | |
StringBuilder sb = new StringBuilder(); | |
sb.append("rs."); | |
sb.append(name.trim()); | |
sb.append("("); | |
IntConsumer ac = new IntConsumer() { | |
boolean in = false; | |
@Override | |
public void accept(int value) { | |
char c = (char) value; | |
if (c == ' ') { | |
in = !in; | |
} else { | |
if (in && ')' != c) { | |
sb.append(c); | |
} | |
} | |
} | |
}; | |
param.chars().forEach(ac); | |
sb.append(");"); | |
e = method.indexOf("}"); | |
b = method.lastIndexOf("{",e); | |
if (b<0){ | |
continue; | |
} | |
b++; | |
String rt = method.substring(b,e+1).trim(); | |
String rt1 = sb.toString(); | |
if (rt.indexOf("return ")>=0){ | |
rt1 = "return "+rt1; | |
} | |
method = method.replace(rt,rt1); | |
method="@Over" + "ride"+method+"}"; | |
System.out.println(method); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
生成的代码