From 48cd76544cdfc5728ddc0ed89d344ed529a79488 Mon Sep 17 00:00:00 2001 From: wangbing Date: Thu, 12 Dec 2019 17:53:37 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81API=E5=8D=87=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: 64a883ef12b7d5d26b40ee503859ce681ae4fa4e --- .../javafx/manger/callable/ApiCallable.java | 43 ++--- .../dbtool/javafx/tool/EntityReader.java | 133 +++++++------- .../dbtool/javafx/tool/RequestReader.java | 167 ++++++++++-------- .../dbtool/javafx/tool/ResponseReader.java | 152 ++++++++-------- .../xyz/wbsite/dbtool/javafx/tool/Tool.java | 35 +++- 5 files changed, 288 insertions(+), 242 deletions(-) diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/ApiCallable.java b/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/ApiCallable.java index 3f6bcf84..8ece910a 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/ApiCallable.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/ApiCallable.java @@ -11,7 +11,6 @@ import xyz.wbsite.dbtool.javafx.tool.ResponseReader; import xyz.wbsite.dbtool.javafx.tool.Tool; import java.io.File; -import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -221,41 +220,35 @@ public class ApiCallable implements Callable { Matcher matcher = compile.matcher(s); if (matcher.find()) { - String Package = matcher.group(1); String EntName = matcher.group(2); entNames.add(EntName); List files = Tool.findEntity(this.module, EntName + ".java"); - for (File file : files) { - try { - EntityReader entReader = new EntityReader(file); - generateEntity(entReader); - } catch (IOException e) { - e.printStackTrace(); - } + EntityReader entReader = new EntityReader(file); + generateEntity(entReader); } } } List reqNames = new ArrayList<>(); for (String depReqName : reader.getDeptReqList()) { - Pattern compile = Pattern.compile("(.*\\.req)\\.(.*)"); - Matcher matcher = compile.matcher(depReqName); - if (matcher.find()) { - String Package = matcher.group(1); - String ReqName = matcher.group(2); - entNames.add(depReqName); - List files = Tool.findRequest(this.module, depReqName + ".java"); - - for (File file : files) { - try { + if (depReqName.matches("(.*\\.req)\\.(.*)")) { + Pattern compile = Pattern.compile("(.*\\.req)\\.(.*)"); + Matcher matcher = compile.matcher(depReqName); + if (matcher.find()) { + entNames.add(depReqName); + List files = Tool.findRequest(this.module, depReqName + ".java"); + for (File file : files) { RequestReader reqReader = new RequestReader(file); generateRequest(reqReader); - } catch (IOException e) { - e.printStackTrace(); } } + } else { + List 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 files = Tool.findEntity(this.module, EntName + ".java"); for (File file : files) { - try { - EntityReader entReader = new EntityReader(file); - generateEntity(entReader); - } catch (IOException e) { - e.printStackTrace(); - } + EntityReader entReader = new EntityReader(file); + generateEntity(entReader); } } } diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/tool/EntityReader.java b/src/main/java/xyz/wbsite/dbtool/javafx/tool/EntityReader.java index 77c44b6e..ba4f9c78 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/tool/EntityReader.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/tool/EntityReader.java @@ -24,7 +24,7 @@ public class EntityReader { private String findOrSearchflag = "0"; private String Tclass = null; - public EntityReader(File javaClass) throws IOException { + public EntityReader(File javaClass) { this.javaClass = javaClass; importList = new ArrayList<>(); notesList = new ArrayList<>(); @@ -35,88 +35,89 @@ public class EntityReader { read(); } - private void read() throws IOException { - BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(javaClass), "utf-8")); + private void read() { + BufferedReader bufferedReader = null; + try { + bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(javaClass), "utf-8")); - String line = null; - while ((line = bufferedReader.readLine()) != null) { - if (line.matches("\\s*package\\s(.*);")) { - 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\\..*);"); + String line = null; + while ((line = bufferedReader.readLine()) != null) { + if (line.matches("\\s*package\\s(.*);")) { + Pattern compile = Pattern.compile("\\s*package\\s(.*)\\.module\\.(.*).ent;"); Matcher matcher = compile.matcher(line); if (matcher.find()) { - String group = matcher.group(1); - deptEntList.add(group); + domainName = matcher.group(1); + moduleName = matcher.group(2); } - } else if (line.contains("frame")) { - - } else if (line.contains("javax.validation")) { - - } 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 (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); - - if (matcher.find()) { - className = matcher.group(1); - fatherName = "BaseEntity"; + 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("frame")) { + + } else if (line.contains("javax.validation")) { + + } else if (line.contains("org.hibernate.validator")) { + + } else { + importList.add(line); + } + continue; } - continue; - } - if (className != null) { - if (line.matches("\\s*private\\s+(.*Request)\\s+(.*);")) { - Pattern compile = Pattern.compile("\\s*private\\s+(.*Request)\\s+(.*);"); + if ((line.contains("/**") || line.contains("*") || line.contains("*/")) && body.size() == 0) { + notesList.add(line); + } + + 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); if (matcher.find()) { - String group = matcher.group(1); - deptReqList.add(group); + className = matcher.group(1); + fatherName = "BaseEntity"; } - } - - if (line.contains("@ColumnName") || - line.contains("@ColumnDescription") - ) { 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--) { - if (body.get(i).contains("}")) { - body.set(i, body.get(i).replaceAll("}", "")); - break; + for (int i = body.size() - 1; i >= 0; i--) { + if (body.get(i).contains("}")) { + body.set(i, body.get(i).replaceAll("}", "")); + 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() { diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/tool/RequestReader.java b/src/main/java/xyz/wbsite/dbtool/javafx/tool/RequestReader.java index bdbda224..4d09f3bf 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/tool/RequestReader.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/tool/RequestReader.java @@ -24,7 +24,7 @@ public class RequestReader { private String findOrSearchflag = "0"; private String Tclass = null; - public RequestReader(File javaClass) throws IOException { + public RequestReader(File javaClass) { this.javaClass = javaClass; importList = new ArrayList<>(); notesList = new ArrayList<>(); @@ -35,99 +35,116 @@ public class RequestReader { read(); } - private void read() throws IOException { - BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(javaClass), "utf-8")); + private void read() { + BufferedReader bufferedReader = null; + try { + bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(javaClass), "utf-8")); - String line = null; - while ((line = bufferedReader.readLine()) != null) { - if (line.matches("\\s*package\\s(.*);")) { - 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\\..*);"); + String line = null; + while ((line = bufferedReader.readLine()) != null) { + if (line.matches("\\s*package\\s(.*);")) { + Pattern compile = Pattern.compile("\\s*package\\s(.*)\\.module\\.(.*).req;"); Matcher matcher = compile.matcher(line); if (matcher.find()) { - String group = matcher.group(1); - deptEntList.add(group); + domainName = matcher.group(1); + moduleName = matcher.group(2); } - } else if (line.contains("frame")) { - - } else if (line.contains("javax.validation")) { - - } 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 (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); - - if (matcher.find()) { - className = matcher.group(1); - fatherName = matcher.group(2); - - if (fatherName.contains("BaseFindRequest")) { - hasList = true; - findOrSearchflag = "1"; - } - if (fatherName.contains("BaseGetAllRequest")) { - hasList = true; - findOrSearchflag = "2"; + 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("frame")) { + + } else if (line.contains("javax.validation")) { + + } else if (line.contains("org.hibernate.validator")) { + + } else { + importList.add(line); } + 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); if (matcher.find()) { - String group = matcher.group(1); - deptReqList.add(group); + className = matcher.group(1); + 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; } + 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--) { - if (body.get(i).contains("}")) { - body.set(i, body.get(i).replaceAll("}", "")); - break; + for (int i = body.size() - 1; i >= 0; i--) { + if (body.get(i).contains("}")) { + body.set(i, body.get(i).replaceAll("}", "")); + 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() { diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/tool/ResponseReader.java b/src/main/java/xyz/wbsite/dbtool/javafx/tool/ResponseReader.java index d2ca1bf3..4bab20ca 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/tool/ResponseReader.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/tool/ResponseReader.java @@ -24,7 +24,7 @@ public class ResponseReader { private String findOrSearchflag = "0"; private String Tclass = null; - public ResponseReader(File javaClass) throws IOException { + public ResponseReader(File javaClass){ this.javaClass = javaClass; importList = new ArrayList<>(); notesList = new ArrayList<>(); @@ -35,93 +35,105 @@ public class ResponseReader { read(); } - private void read() throws IOException { - BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(javaClass), "utf-8")); + private void read() { + BufferedReader bufferedReader = null; + try { + bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(javaClass), "utf-8")); - String line = null; - while ((line = bufferedReader.readLine()) != null) { - if (line.matches("\\s*package\\s(.*);")) { - 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\\..*);"); + String line = null; + while ((line = bufferedReader.readLine()) != null) { + if (line.matches("\\s*package\\s(.*);")) { + Pattern compile = Pattern.compile("\\s*package\\s(.*)\\.module\\.(.*).rsp;"); Matcher matcher = compile.matcher(line); if (matcher.find()) { - String group = matcher.group(1); - deptEntList.add(group); + 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); + 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.")) { - Pattern compile = Pattern.compile("import\\s+(.*\\.req\\..*);"); + continue; + } + 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); + if (matcher.find()) { - String group = matcher.group(1); - deptReqList.add(group); + className = matcher.group(1); + fatherName = matcher.group(2); + + if (fatherName.contains("BaseFindResponse")) { + hasList = true; + findOrSearchflag = "1"; + } } - } else if (!line.contains("frame")) { - importList.add(line); + continue; } - continue; - } - 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); - - if (matcher.find()) { - className = matcher.group(1); - fatherName = matcher.group(2); + 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 (fatherName.contains("BaseFindResponse")) { - hasList = true; - findOrSearchflag = "1"; + if (matcher.find()) { + className = matcher.group(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*\\{"); - Matcher matcher = compile.matcher(line); - - if (matcher.find()) { - className = matcher.group(1); - fatherName = matcher.group(2); - Tclass = matcher.group(3); - - if (fatherName.contains("BaseFindResponse")) { - hasList = true; - findOrSearchflag = "1"; - } + + for (int i = body.size() - 1; i >= 0; i--) { + if (body.get(i).contains("}")) { + body.set(i, body.get(i).replaceAll("}", "")); + break; } - continue; } - if (className != null) { - body.add(line); + 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); } - } - for (int i = body.size() - 1; i >= 0; i--) { - if (body.get(i).contains("}")) { - body.set(i, body.get(i).replaceAll("}", "")); - break; + } 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() { diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/tool/Tool.java b/src/main/java/xyz/wbsite/dbtool/javafx/tool/Tool.java index b1f860ee..78ce8b9d 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/tool/Tool.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/tool/Tool.java @@ -2,10 +2,7 @@ package xyz.wbsite.dbtool.javafx.tool; import java.io.*; import java.net.URL; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.UUID; +import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -421,6 +418,36 @@ public class Tool { return files; } + private static Set 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 getJavaField() { + return javaFieldSet; + } + public static File createPath(String... subdir) { if (subdir.length == 0) { return null;