1、API升级

Former-commit-id: 64a883ef12b7d5d26b40ee503859ce681ae4fa4e
master
wangbing 5 years ago
parent a43cc1c13e
commit 48cd76544c

@ -11,7 +11,6 @@ import xyz.wbsite.dbtool.javafx.tool.ResponseReader;
import xyz.wbsite.dbtool.javafx.tool.Tool; import xyz.wbsite.dbtool.javafx.tool.Tool;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -221,41 +220,35 @@ public class ApiCallable implements Callable {
Matcher matcher = compile.matcher(s); Matcher matcher = compile.matcher(s);
if (matcher.find()) { if (matcher.find()) {
String Package = matcher.group(1);
String EntName = matcher.group(2); String EntName = matcher.group(2);
entNames.add(EntName); entNames.add(EntName);
List<File> files = Tool.findEntity(this.module, EntName + ".java"); List<File> files = Tool.findEntity(this.module, EntName + ".java");
for (File file : files) { for (File file : files) {
try { EntityReader entReader = new EntityReader(file);
EntityReader entReader = new EntityReader(file); generateEntity(entReader);
generateEntity(entReader);
} catch (IOException e) {
e.printStackTrace();
}
} }
} }
} }
List<String> reqNames = new ArrayList<>(); List<String> reqNames = new ArrayList<>();
for (String depReqName : reader.getDeptReqList()) { for (String depReqName : reader.getDeptReqList()) {
Pattern compile = Pattern.compile("(.*\\.req)\\.(.*)"); if (depReqName.matches("(.*\\.req)\\.(.*)")) {
Matcher matcher = compile.matcher(depReqName); Pattern compile = Pattern.compile("(.*\\.req)\\.(.*)");
if (matcher.find()) { Matcher matcher = compile.matcher(depReqName);
String Package = matcher.group(1); if (matcher.find()) {
String ReqName = matcher.group(2); entNames.add(depReqName);
entNames.add(depReqName); List<File> files = Tool.findRequest(this.module, depReqName + ".java");
List<File> files = Tool.findRequest(this.module, depReqName + ".java"); for (File file : files) {
for (File file : files) {
try {
RequestReader reqReader = new RequestReader(file); RequestReader reqReader = new RequestReader(file);
generateRequest(reqReader); generateRequest(reqReader);
} catch (IOException e) {
e.printStackTrace();
} }
} }
} else {
List<File> files = Tool.findRequest(this.module, depReqName + ".java");
for (File file : files) {
generateRequest(new RequestReader(file));
}
} }
} }
@ -304,12 +297,8 @@ public class ApiCallable implements Callable {
List<File> files = Tool.findEntity(this.module, EntName + ".java"); List<File> files = Tool.findEntity(this.module, EntName + ".java");
for (File file : files) { for (File file : files) {
try { EntityReader entReader = new EntityReader(file);
EntityReader entReader = new EntityReader(file); generateEntity(entReader);
generateEntity(entReader);
} catch (IOException e) {
e.printStackTrace();
}
} }
} }
} }

@ -24,7 +24,7 @@ public class EntityReader {
private String findOrSearchflag = "0"; private String findOrSearchflag = "0";
private String Tclass = null; private String Tclass = null;
public EntityReader(File javaClass) throws IOException { public EntityReader(File javaClass) {
this.javaClass = javaClass; this.javaClass = javaClass;
importList = new ArrayList<>(); importList = new ArrayList<>();
notesList = new ArrayList<>(); notesList = new ArrayList<>();
@ -35,88 +35,89 @@ public class EntityReader {
read(); read();
} }
private void read() throws IOException { private void read() {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(javaClass), "utf-8")); BufferedReader bufferedReader = null;
try {
bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(javaClass), "utf-8"));
String line = null; String line = null;
while ((line = bufferedReader.readLine()) != null) { while ((line = bufferedReader.readLine()) != null) {
if (line.matches("\\s*package\\s(.*);")) { if (line.matches("\\s*package\\s(.*);")) {
Pattern compile = Pattern.compile("\\s*package\\s(.*)\\.module\\.(.*).ent;"); Pattern compile = Pattern.compile("\\s*package\\s(.*)\\.module\\.(.*).ent;");
Matcher matcher = compile.matcher(line);
if (matcher.find()) {
domainName = matcher.group(1);
moduleName = matcher.group(2);
}
continue;
}
if (line.matches("import\\s.*")) {
if (line.contains(".ent.")) {
Pattern compile = Pattern.compile("import\\s+(.*\\.ent\\..*);");
Matcher matcher = compile.matcher(line); Matcher matcher = compile.matcher(line);
if (matcher.find()) { if (matcher.find()) {
String group = matcher.group(1); domainName = matcher.group(1);
deptEntList.add(group); moduleName = matcher.group(2);
} }
} else if (line.contains("frame")) { continue;
} else if (line.contains("javax.validation")) {
} else if (line.contains("org.hibernate.validator")) {
} else {
importList.add(line);
} }
continue; if (line.matches("import\\s.*")) {
} if (line.contains(".ent.")) {
if ((line.contains("/**") || line.contains("*") || line.contains("*/")) && body.size() == 0) { Pattern compile = Pattern.compile("import\\s+(.*\\.ent\\..*);");
notesList.add(line); Matcher matcher = compile.matcher(line);
} if (matcher.find()) {
String group = matcher.group(1);
if (line.matches("public class\\s+(.*)\\s+extends\\s+BaseEntity\\s*\\{")) { deptEntList.add(group);
Pattern compile = Pattern.compile("public class\\s+(.*)\\s+extends\\s+BaseEntity\\s*\\{"); }
Matcher matcher = compile.matcher(line); } else if (line.contains("frame")) {
if (matcher.find()) { } else if (line.contains("javax.validation")) {
className = matcher.group(1);
fatherName = "BaseEntity"; } else if (line.contains("org.hibernate.validator")) {
} else {
importList.add(line);
}
continue;
} }
continue; if ((line.contains("/**") || line.contains("*") || line.contains("*/")) && body.size() == 0) {
} notesList.add(line);
if (className != null) { }
if (line.matches("\\s*private\\s+(.*Request)\\s+(.*);")) {
Pattern compile = Pattern.compile("\\s*private\\s+(.*Request)\\s+(.*);"); if (line.matches("public class\\s+(.*)\\s+extends\\s+BaseEntity\\s*\\{")) {
Pattern compile = Pattern.compile("public class\\s+(.*)\\s+extends\\s+BaseEntity\\s*\\{");
Matcher matcher = compile.matcher(line); Matcher matcher = compile.matcher(line);
if (matcher.find()) { if (matcher.find()) {
String group = matcher.group(1); className = matcher.group(1);
deptReqList.add(group); fatherName = "BaseEntity";
} }
}
if (line.contains("@ColumnName") ||
line.contains("@ColumnDescription")
) {
continue; continue;
} }
if (className != null) {
if (line.contains("@ColumnName") ||
line.contains("@ColumnDescription")
) {
continue;
}
body.add(line); body.add(line);
}
} }
}
for (int i = body.size() - 1; i >= 0; i--) { for (int i = body.size() - 1; i >= 0; i--) {
if (body.get(i).contains("}")) { if (body.get(i).contains("}")) {
body.set(i, body.get(i).replaceAll("}", "")); body.set(i, body.get(i).replaceAll("}", ""));
break; break;
}
}
if (body.size() > 1 && "".equals(body.get(0))) {
body.remove(0);
}
if (body.size() > 1 && "".equals(body.get(body.size() - 1))) {
body.remove(body.size() - 1);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
} }
} }
if (body.size() > 1 && "".equals(body.get(0))) {
body.remove(0);
}
if (body.size() > 1 && "".equals(body.get(body.size() - 1))) {
body.remove(body.size() - 1);
}
bufferedReader.close();
} }
public String getDomainName() { public String getDomainName() {

@ -24,7 +24,7 @@ public class RequestReader {
private String findOrSearchflag = "0"; private String findOrSearchflag = "0";
private String Tclass = null; private String Tclass = null;
public RequestReader(File javaClass) throws IOException { public RequestReader(File javaClass) {
this.javaClass = javaClass; this.javaClass = javaClass;
importList = new ArrayList<>(); importList = new ArrayList<>();
notesList = new ArrayList<>(); notesList = new ArrayList<>();
@ -35,99 +35,116 @@ public class RequestReader {
read(); read();
} }
private void read() throws IOException { private void read() {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(javaClass), "utf-8")); BufferedReader bufferedReader = null;
try {
bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(javaClass), "utf-8"));
String line = null; String line = null;
while ((line = bufferedReader.readLine()) != null) { while ((line = bufferedReader.readLine()) != null) {
if (line.matches("\\s*package\\s(.*);")) { if (line.matches("\\s*package\\s(.*);")) {
Pattern compile = Pattern.compile("\\s*package\\s(.*)\\.module\\.(.*).req;"); Pattern compile = Pattern.compile("\\s*package\\s(.*)\\.module\\.(.*).req;");
Matcher matcher = compile.matcher(line);
if (matcher.find()) {
domainName = matcher.group(1);
moduleName = matcher.group(2);
}
continue;
}
if (line.matches("import\\s.*")) {
if (line.contains(".ent.")) {
Pattern compile = Pattern.compile("import\\s+(.*\\.ent\\..*);");
Matcher matcher = compile.matcher(line); Matcher matcher = compile.matcher(line);
if (matcher.find()) { if (matcher.find()) {
String group = matcher.group(1); domainName = matcher.group(1);
deptEntList.add(group); moduleName = matcher.group(2);
} }
} else if (line.contains("frame")) { continue;
} else if (line.contains("javax.validation")) {
} else if (line.contains("org.hibernate.validator")) {
} else {
importList.add(line);
} }
continue; if (line.matches("import\\s.*")) {
} if (line.contains(".ent.")) {
if ((line.contains("/**") || line.contains("*") || line.contains("*/")) && body.size() == 0) { Pattern compile = Pattern.compile("import\\s+(.*\\.ent\\..*);");
notesList.add(line); Matcher matcher = compile.matcher(line);
} if (matcher.find()) {
String group = matcher.group(1);
if (line.matches("public\\s+class\\s+(.*Request)\\s+extends\\s+(.*)Request\\s*\\{")) { deptEntList.add(group);
Pattern compile = Pattern.compile("public\\s+class\\s+(.*Request)\\s+extends\\s+(.*)Request\\s*\\{"); }
Matcher matcher = compile.matcher(line); } else if (line.contains("frame")) {
if (matcher.find()) { } else if (line.contains("javax.validation")) {
className = matcher.group(1);
fatherName = matcher.group(2); } else if (line.contains("org.hibernate.validator")) {
if (fatherName.contains("BaseFindRequest")) { } else {
hasList = true; importList.add(line);
findOrSearchflag = "1";
}
if (fatherName.contains("BaseGetAllRequest")) {
hasList = true;
findOrSearchflag = "2";
} }
continue;
}
if ((line.contains("/**") || line.contains("*") || line.contains("*/")) && body.size() == 0) {
notesList.add(line);
} }
continue;
}
if (className != null) {
if (line.matches("\\s*private\\s+(.*Request)\\s+(.*);")) {
Pattern compile = Pattern.compile("\\s*private\\s+(.*Request)\\s+(.*);"); if (line.matches("public\\s+class\\s+(.*Request)\\s+extends\\s+(.*)Request\\s*\\{")) {
Pattern compile = Pattern.compile("public\\s+class\\s+(.*Request)\\s+extends\\s+(.*)Request\\s*\\{");
Matcher matcher = compile.matcher(line); Matcher matcher = compile.matcher(line);
if (matcher.find()) { if (matcher.find()) {
String group = matcher.group(1); className = matcher.group(1);
deptReqList.add(group); fatherName = matcher.group(2);
if (fatherName.contains("BaseFindRequest")) {
hasList = true;
findOrSearchflag = "1";
}
if (fatherName.contains("BaseGetAllRequest")) {
hasList = true;
findOrSearchflag = "2";
}
} }
}
if (line.contains("@ColumnName") ||
line.contains("@ColumnDescription")
) {
continue; continue;
} }
if (className != null) {
if (line.matches("\\s*private\\s+(.*Request)\\s+(.*);")) {
Pattern compile = Pattern.compile("\\s*private\\s+(.*Request)\\s+(.*);");
Matcher matcher = compile.matcher(line);
if (matcher.find()) {
String group = matcher.group(1);
deptReqList.add(group);
}
} else if (line.matches("\\s*private\\s+(.*\\.)*([^\\\\.]*)\\s+(.*);")) {
Pattern compile = Pattern.compile("\\s*private\\s+(.*\\.)*([^\\\\.]*)\\s+(.*);");
Matcher matcher = compile.matcher(line);
if (matcher.find()) {
String group = matcher.group(2);
deptEntList.add(group);
}
}
if (line.contains("@ColumnName") ||
line.contains("@ColumnDescription")
) {
continue;
}
body.add(line); body.add(line);
}
} }
}
for (int i = body.size() - 1; i >= 0; i--) { for (int i = body.size() - 1; i >= 0; i--) {
if (body.get(i).contains("}")) { if (body.get(i).contains("}")) {
body.set(i, body.get(i).replaceAll("}", "")); body.set(i, body.get(i).replaceAll("}", ""));
break; break;
}
}
if (body.size() > 1 && "".equals(body.get(0))) {
body.remove(0);
}
if (body.size() > 1 && "".equals(body.get(body.size() - 1))) {
body.remove(body.size() - 1);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
} }
} }
if (body.size() > 1 && "".equals(body.get(0))) {
body.remove(0);
}
if (body.size() > 1 && "".equals(body.get(body.size() - 1))) {
body.remove(body.size() - 1);
}
bufferedReader.close();
} }
public String getDomainName() { public String getDomainName() {

@ -24,7 +24,7 @@ public class ResponseReader {
private String findOrSearchflag = "0"; private String findOrSearchflag = "0";
private String Tclass = null; private String Tclass = null;
public ResponseReader(File javaClass) throws IOException { public ResponseReader(File javaClass){
this.javaClass = javaClass; this.javaClass = javaClass;
importList = new ArrayList<>(); importList = new ArrayList<>();
notesList = new ArrayList<>(); notesList = new ArrayList<>();
@ -35,93 +35,105 @@ public class ResponseReader {
read(); read();
} }
private void read() throws IOException { private void read() {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(javaClass), "utf-8")); BufferedReader bufferedReader = null;
try {
bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(javaClass), "utf-8"));
String line = null; String line = null;
while ((line = bufferedReader.readLine()) != null) { while ((line = bufferedReader.readLine()) != null) {
if (line.matches("\\s*package\\s(.*);")) { if (line.matches("\\s*package\\s(.*);")) {
Pattern compile = Pattern.compile("\\s*package\\s(.*)\\.module\\.(.*).rsp;"); Pattern compile = Pattern.compile("\\s*package\\s(.*)\\.module\\.(.*).rsp;");
Matcher matcher = compile.matcher(line);
if (matcher.find()) {
domainName = matcher.group(1);
moduleName = matcher.group(2);
}
continue;
}
if (line.matches("import\\s.*")) {
if (line.contains(".ent.")) {
Pattern compile = Pattern.compile("import\\s+(.*\\.ent\\..*);");
Matcher matcher = compile.matcher(line); Matcher matcher = compile.matcher(line);
if (matcher.find()) { if (matcher.find()) {
String group = matcher.group(1); domainName = matcher.group(1);
deptEntList.add(group); moduleName = matcher.group(2);
}
continue;
}
if (line.matches("import\\s.*")) {
if (line.contains(".ent.")) {
Pattern compile = Pattern.compile("import\\s+(.*\\.ent\\..*);");
Matcher matcher = compile.matcher(line);
if (matcher.find()) {
String group = matcher.group(1);
deptEntList.add(group);
}
} else if (line.contains(".req.")) {
Pattern compile = Pattern.compile("import\\s+(.*\\.req\\..*);");
Matcher matcher = compile.matcher(line);
if (matcher.find()) {
String group = matcher.group(1);
deptReqList.add(group);
}
} else if (!line.contains("frame")) {
importList.add(line);
} }
} else if (line.contains(".req.")) { continue;
Pattern compile = Pattern.compile("import\\s+(.*\\.req\\..*);"); }
if ((line.contains("/**") || line.contains("*") || line.contains("*/")) && body.size() == 0) {
notesList.add(line);
}
if (line.matches("public class (.*Response) extends (.*)Response\\s*\\{")) {
Pattern compile = Pattern.compile("public class (.*Response) extends (.*)Response\\s*\\{");
Matcher matcher = compile.matcher(line); Matcher matcher = compile.matcher(line);
if (matcher.find()) { if (matcher.find()) {
String group = matcher.group(1); className = matcher.group(1);
deptReqList.add(group); fatherName = matcher.group(2);
if (fatherName.contains("BaseFindResponse")) {
hasList = true;
findOrSearchflag = "1";
}
} }
} else if (!line.contains("frame")) { continue;
importList.add(line);
} }
continue; if (line.matches("public class (.*Response) extends (.*)Response<(.*)>\\s*\\{")) {
} Pattern compile = Pattern.compile("public class (.*Response) extends (.*)Response<(.*)>\\s*\\{");
if ((line.contains("/**") || line.contains("*") || line.contains("*/")) && body.size() == 0) { Matcher matcher = compile.matcher(line);
notesList.add(line);
}
if (line.matches("public class (.*Response) extends (.*)Response\\s*\\{")) {
Pattern compile = Pattern.compile("public class (.*Response) extends (.*)Response\\s*\\{");
Matcher matcher = compile.matcher(line);
if (matcher.find()) {
className = matcher.group(1);
fatherName = matcher.group(2);
if (fatherName.contains("BaseFindResponse")) { if (matcher.find()) {
hasList = true; className = matcher.group(1);
findOrSearchflag = "1"; fatherName = matcher.group(2);
Tclass = matcher.group(3);
if (fatherName.contains("BaseFindResponse")) {
hasList = true;
findOrSearchflag = "1";
}
} }
continue;
}
if (className != null) {
body.add(line);
} }
continue;
} }
if (line.matches("public class (.*Response) extends (.*)Response<(.*)>\\s*\\{")) {
Pattern compile = Pattern.compile("public class (.*Response) extends (.*)Response<(.*)>\\s*\\{"); for (int i = body.size() - 1; i >= 0; i--) {
Matcher matcher = compile.matcher(line); if (body.get(i).contains("}")) {
body.set(i, body.get(i).replaceAll("}", ""));
if (matcher.find()) { break;
className = matcher.group(1);
fatherName = matcher.group(2);
Tclass = matcher.group(3);
if (fatherName.contains("BaseFindResponse")) {
hasList = true;
findOrSearchflag = "1";
}
} }
continue;
} }
if (className != null) { if (body.size() > 1 && "".equals(body.get(0))) {
body.add(line); body.remove(0);
}
if (body.size() > 1 && "".equals(body.get(body.size() - 1))) {
body.remove(body.size() - 1);
} }
}
for (int i = body.size() - 1; i >= 0; i--) { } catch (IOException e) {
if (body.get(i).contains("}")) { e.printStackTrace();
body.set(i, body.get(i).replaceAll("}", "")); } finally {
break; if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
} }
} }
if (body.size() > 1 && "".equals(body.get(0))) {
body.remove(0);
}
if (body.size() > 1 && "".equals(body.get(body.size() - 1))) {
body.remove(body.size() - 1);
}
bufferedReader.close();
} }
public String getDomainName() { public String getDomainName() {

@ -2,10 +2,7 @@ package xyz.wbsite.dbtool.javafx.tool;
import java.io.*; import java.io.*;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.*;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -421,6 +418,36 @@ public class Tool {
return files; return files;
} }
private static Set<String> javaFieldSet = new HashSet<>();
static {
javaFieldSet.add("boolean");
javaFieldSet.add("Boolean");
javaFieldSet.add("byte");
javaFieldSet.add("Byte");
javaFieldSet.add("byte[]");
javaFieldSet.add("Byte[]");
javaFieldSet.add("char");
javaFieldSet.add("Character");
javaFieldSet.add("short");
javaFieldSet.add("Short");
javaFieldSet.add("int");
javaFieldSet.add("Integer");
javaFieldSet.add("long");
javaFieldSet.add("Long");
javaFieldSet.add("float");
javaFieldSet.add("Float");
javaFieldSet.add("double");
javaFieldSet.add("Double");
javaFieldSet.add("Date");
javaFieldSet.add("BigDecimal");
javaFieldSet.add("String");
}
public static Set<String> getJavaField() {
return javaFieldSet;
}
public static File createPath(String... subdir) { public static File createPath(String... subdir) {
if (subdir.length == 0) { if (subdir.length == 0) {
return null; return null;

Loading…
Cancel
Save

Powered by TurnKey Linux.