parent
da890801a9
commit
1a2b32d3b9
@ -0,0 +1,61 @@
|
||||
package xyz.wbsite.dbtool.javafx.tool;
|
||||
|
||||
import xyz.wbsite.dbtool.javafx.po.DocParam;
|
||||
import xyz.wbsite.dbtool.web.frame.utils.FileUtil;
|
||||
import xyz.wbsite.dbtool.web.frame.utils.MapperUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class DocEntityReader extends EntityReader{
|
||||
private List<DocParam> fieldDocList;
|
||||
|
||||
public DocEntityReader(File javaClass) {
|
||||
super(javaClass);
|
||||
fieldDocList = new ArrayList<>();
|
||||
DocParam docParam = new DocParam();
|
||||
for (String s : getBody()) {
|
||||
s = s.trim();
|
||||
|
||||
// 提取注释
|
||||
if (s.startsWith("/**") || s.endsWith("*/") || s.startsWith("*")) {
|
||||
s = s.replaceAll("^/\\*\\*", "");
|
||||
s = s.replaceAll("^\\*/$", "");
|
||||
s = s.replaceAll("^\\*", "");
|
||||
docParam.setNote(nullF(docParam.getNote()) + s.trim());
|
||||
}
|
||||
|
||||
// 必填项检查
|
||||
if (s.startsWith("@NotBlank") || s.startsWith("@NotNull")) {
|
||||
docParam.setRequired(true);
|
||||
}
|
||||
|
||||
if (s.matches("private\\s(.*)\\s(.*);")) {
|
||||
Pattern compile = Pattern.compile("private\\s(.*)\\s(.*);");
|
||||
Matcher matcher = compile.matcher(s);
|
||||
if (matcher.find()) {
|
||||
docParam.setTupe(matcher.group(1));
|
||||
docParam.setName(matcher.group(2));
|
||||
fieldDocList.add(docParam);
|
||||
System.out.println(MapperUtil.toJson(docParam));
|
||||
docParam = new DocParam();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<DocParam> getFieldDocList() {
|
||||
return fieldDocList;
|
||||
}
|
||||
|
||||
public void setFieldDocList(List<DocParam> fieldDocList) {
|
||||
this.fieldDocList = fieldDocList;
|
||||
}
|
||||
|
||||
private String nullF(String value) {
|
||||
return value == null ? "" : value;
|
||||
}
|
||||
}
|
@ -1,47 +1,136 @@
|
||||
package xyz.wbsite.dbtool.javafx.tool;
|
||||
|
||||
import xyz.wbsite.dbtool.javafx.po.DocParam;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class DocRequestReader extends RequestReader {
|
||||
private Map<String, String> fieldDocMap;
|
||||
private String classNote;
|
||||
private List<DocParam> fieldDocList;
|
||||
private Map<String, List<DocParam>> ents;
|
||||
|
||||
public DocRequestReader(File javaClass) {
|
||||
super(javaClass);
|
||||
}
|
||||
fieldDocList = new ArrayList<>();
|
||||
ents = new HashMap<>();
|
||||
|
||||
List<String> notesList = getNotesList();
|
||||
for (String s : notesList) {
|
||||
s = s.trim();
|
||||
// 提取注释
|
||||
if ((s.startsWith("/**") || s.endsWith("*/") || s.startsWith("*")) && !s.contains("@")) {
|
||||
s = s.replaceAll("^/\\*\\*", "");
|
||||
s = s.replaceAll("^\\*/$", "");
|
||||
s = s.replaceAll("^\\*", "");
|
||||
classNote = nullF(classNote) + s.trim();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void read() {
|
||||
super.read();
|
||||
fieldDocMap = new HashMap<>();
|
||||
String doc = null;
|
||||
String field = null;
|
||||
DocParam docParam = new DocParam();
|
||||
for (String s : getBody()) {
|
||||
if (s.matches("\\s+/\\*(\\*)?(.*)(\\*/)?")) {
|
||||
Pattern compile = Pattern.compile("\\s+/\\*(\\*)?(.*)(\\*/)?");
|
||||
Matcher matcher = compile.matcher(s);
|
||||
if (matcher.find()) {
|
||||
doc = matcher.group(2);
|
||||
} else {
|
||||
doc = "";
|
||||
}
|
||||
s = s.trim();
|
||||
|
||||
// 提取注释
|
||||
if (s.startsWith("/**") || s.endsWith("*/") || s.startsWith("*")) {
|
||||
s = s.replaceAll("^/\\*\\*", "");
|
||||
s = s.replaceAll("^\\*/$", "");
|
||||
s = s.replaceAll("^\\*", "");
|
||||
docParam.setNote(nullF(docParam.getNote()) + s.trim());
|
||||
}
|
||||
|
||||
if (s.matches("\\s+\\*\\s+(.*)")) {
|
||||
Pattern compile = Pattern.compile("\\s+\\*\\s+(.*)");
|
||||
Matcher matcher = compile.matcher(s);
|
||||
if (matcher.find()) doc += matcher.group(1);
|
||||
// 必填项检查
|
||||
if (s.startsWith("@NotBlank") || s.startsWith("@NotNull")) {
|
||||
docParam.setRequired(true);
|
||||
}
|
||||
|
||||
if (s.matches("\\s+private\\s.*\\s(.*);")) {
|
||||
Pattern compile = Pattern.compile("\\s+private\\s.*\\s(.*);");
|
||||
if (s.matches("private\\s(.*)\\s(.*);")) {
|
||||
Pattern compile = Pattern.compile("private\\s(.*)\\s(.*);");
|
||||
Matcher matcher = compile.matcher(s);
|
||||
if (matcher.find()) field = matcher.group(1);
|
||||
fieldDocMap.put(field, doc != null ? doc : "");
|
||||
if (matcher.find()) {
|
||||
String type = matcher.group(1);
|
||||
docParam.setTupe(type);
|
||||
if (!Tool.getJavaField().contains(type)) {//读取自定义对象
|
||||
|
||||
if (type.endsWith("Request")) {
|
||||
String module = null;
|
||||
for (String s1 : getImportList()) {
|
||||
Pattern compile1 = Pattern.compile("import\\s+.*\\.module\\.(.*)\\.req\\." + type);
|
||||
Matcher matcher1 = compile1.matcher(s1);
|
||||
if (matcher1.find()) {
|
||||
module = matcher1.group(1);
|
||||
}
|
||||
}
|
||||
if (module == null) {// 同目录下查找
|
||||
List<File> files = Tool.find(this.getJavaClass().getParentFile().getParentFile(), type + ".java");
|
||||
if (files.size() == 1) {
|
||||
DocRequestReader docRequestReader = new DocRequestReader(files.get(0));
|
||||
ents.put(docRequestReader.getModuleName() + "#" + type, docRequestReader.getFieldDocList());
|
||||
}
|
||||
} else {//其他模块下查找
|
||||
File path = Tool.createPath(this.getJavaClass().getParentFile().getParentFile().getParentFile(), module);
|
||||
List<File> files = Tool.find(path, type + ".java");
|
||||
if (files.size() == 1) {
|
||||
DocRequestReader docRequestReader = new DocRequestReader(files.get(0));
|
||||
ents.put(docRequestReader.getModuleName() + "#" + type, docRequestReader.getFieldDocList());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
String module = null;
|
||||
for (String s1 : getImportList()) {
|
||||
Pattern compile1 = Pattern.compile("import\\s+.*\\.module\\.(.*)\\.ent\\." + type);
|
||||
Matcher matcher1 = compile1.matcher(s1);
|
||||
if (matcher1.find()) {
|
||||
module = matcher1.group(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (module == null) {// 同目录下查找
|
||||
List<File> files = Tool.find(this.getJavaClass().getParentFile().getParentFile(), type + ".java");
|
||||
if (files.size() == 1) {
|
||||
DocEntityReader docEntityReader = new DocEntityReader(files.get(0));
|
||||
ents.put(docEntityReader.getModuleName() + "#" + type, docEntityReader.getFieldDocList());
|
||||
}
|
||||
} else {//其他模块下查找
|
||||
File path = Tool.createPath(this.getJavaClass().getParentFile().getParentFile().getParentFile(), module);
|
||||
List<File> files = Tool.find(path, type + ".java");
|
||||
if (files.size() == 1) {
|
||||
DocEntityReader docEntityReader = new DocEntityReader(files.get(0));
|
||||
ents.put(docEntityReader.getModuleName() + "#" + type, docEntityReader.getFieldDocList());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
docParam.setName(matcher.group(2));
|
||||
fieldDocList.add(docParam);
|
||||
docParam = new DocParam();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String nullF(String value) {
|
||||
return value == null ? "" : value;
|
||||
}
|
||||
|
||||
public List<DocParam> getFieldDocList() {
|
||||
return fieldDocList;
|
||||
}
|
||||
|
||||
public void setFieldDocList(List<DocParam> fieldDocList) {
|
||||
this.fieldDocList = fieldDocList;
|
||||
}
|
||||
|
||||
public String getClassNote() {
|
||||
return classNote;
|
||||
}
|
||||
|
||||
public void setClassNote(String classNote) {
|
||||
this.classNote = classNote;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,55 @@
|
||||
package xyz.wbsite.dbtool.javafx.tool;
|
||||
|
||||
import xyz.wbsite.dbtool.javafx.po.DocParam;
|
||||
import xyz.wbsite.dbtool.web.frame.utils.MapperUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class DocResponseReader extends ResponseReader {
|
||||
private List<DocParam> fieldDocList;
|
||||
|
||||
public DocResponseReader(File javaClass) {
|
||||
super(javaClass);
|
||||
fieldDocList = new ArrayList<>();
|
||||
DocParam docParam = new DocParam();
|
||||
for (String s : getBody()) {
|
||||
s = s.trim();
|
||||
|
||||
// 提取注释
|
||||
if (s.startsWith("/**") || s.endsWith("*/") || s.startsWith("*")) {
|
||||
s = s.replaceAll("^/\\*\\*", "");
|
||||
s = s.replaceAll("^\\*/$", "");
|
||||
s = s.replaceAll("^\\*", "");
|
||||
docParam.setNote(nullF(docParam.getNote()) + s.trim());
|
||||
}
|
||||
|
||||
if (s.matches("private\\s(.*)\\s(.*);")) {
|
||||
Pattern compile = Pattern.compile("private\\s(.*)\\s(.*);");
|
||||
Matcher matcher = compile.matcher(s);
|
||||
if (matcher.find()) {
|
||||
docParam.setTupe(matcher.group(1));
|
||||
docParam.setName(matcher.group(2));
|
||||
fieldDocList.add(docParam);
|
||||
System.out.println("===" + MapperUtil.toJson(docParam));
|
||||
docParam = new DocParam();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String nullF(String value) {
|
||||
return value == null ? "" : value;
|
||||
}
|
||||
|
||||
public List<DocParam> getFieldDocList() {
|
||||
return fieldDocList;
|
||||
}
|
||||
|
||||
public void setFieldDocList(List<DocParam> fieldDocList) {
|
||||
this.fieldDocList = fieldDocList;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue