package com.cmb.cox.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl;

import java.io.File;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.JarURLConnection;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.*;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

public abstract class PackageScanner {
static final String Y = "Y";
static final String N = "N";
static final Set<String> Alphabet = new HashSet() {{
add("A");
add("B");
add("C");
add("D");
add("E");
add("F");
add("G");
add("H");
add("I");
add("J");
add("K");
add("L");
add("M");
add("N");
add("O");
add("P");
add("Q");
add("R");
add("S");
add("T");
add("U");
add("V");
add("W");
add("X");
add("Y");
add("Y");
}};

public PackageScanner() {
}

public abstract void dealClass(Class<?> klass);

private void dealClassFile(String rootPackage, File curFile) {
// 以下为我自己的处理.class方式
String fileName = curFile.getName();
if (fileName.endsWith(".class")) {
fileName = fileName.replaceAll(".class", "");
try {
System.out.println("... " + rootPackage + "." + fileName);
Class<?> klass = Class.forName(rootPackage + "." + fileName);
dealClass(klass);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}

private void dealDirectory(String rootPackage, File curFile) {
// 若为目录则继续处理目录下面的目录和.class文件
File[] fileList = curFile.listFiles();

for (File file : fileList) {
if (file.isDirectory()) {
rootPackage = rootPackage + '.' + file.getName();
System.out.println("00 " + rootPackage);
//按照文件处理
dealDirectory(rootPackage, file);
} else if (file.isFile()) {
//按照.class处理
dealClassFile(rootPackage, file);
}
}
}

private void dealJarPackage(URL url) {
try {
// 得到路径
JarURLConnection connection = (JarURLConnection) url.openConnection();
JarFile jarFile = connection.getJarFile();
// 循环执行看是否有实体的存在
Enumeration<JarEntry> jarEntries = jarFile.entries();
while (jarEntries.hasMoreElements()) {
JarEntry jar = jarEntries.nextElement();
// 若不是.class文件或者是目录则不处理
if (jar.isDirectory() || !jar.getName().endsWith(".class")) {
continue;
}
// 此处为处理
String jarName = jar.getName();
jarName = jarName.replace(".class", "");
jarName = jarName.replace("/", ".");

try {
System.out.println(jarName);
Class klass = Class.forName(jarName);
dealClass(klass);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
} catch (IOException e) {
e.printStackTrace();
}
}

public void packageScanner(String packageName) {
String rootPacksge = packageName;
System.out.println("packageName : " + packageName);
packageName = packageName.replace(".", "/");
// System.out.println("packageName : " + packageName);
URL url = Thread.currentThread().getContextClassLoader().getResource(packageName);
System.out.println("URL : " + url);
//判断协议名称是不是file,如果是file 则按照文件路径处理否则按照jar处理
if (url.getProtocol().equals("file")) {
URI uri;
try {
uri = url.toURI();
File root = new File(uri);
dealDirectory(rootPacksge, root);
} catch (URISyntaxException e) {
e.printStackTrace();
}
} else {
dealJarPackage(url);
}
}

public static void main(String[] args) throws Exception {

boolean basicType = isBasicType(new Integer(1));
new PackageScanner() {
@Override
public void dealClass(Class klass) {
try {
parseControler(klass);
} catch (Exception e) {
e.printStackTrace();
}
}
}.packageScanner("com.cmb.cox.controller.test");
}

public static void parseControler(Class klass) throws Exception {
List<Map<String, Object>> apiList = new ArrayList<>();
if (isController(klass)) {
Method[] methods = klass.getMethods();
for (Method method : methods) {
Annotation[] annotations = method.getAnnotations();
Map<String, Object> apiInfo = new HashMap();
for (Annotation annotation : annotations) {
//获取接口ID
if (annotation instanceof RequestMapping) {
getApiId(apiInfo, ((RequestMapping) annotation).value());
} else if (annotation instanceof PostMapping) {
getApiId(apiInfo, ((PostMapping) annotation).value());
}else if (annotation instanceof GetMapping) {
getApiId(apiInfo, ((GetMapping) annotation).value());
}
//获取接口中文名和描述
if (annotation instanceof ApiOperation) {
getApiCnName(apiInfo, (ApiOperation) annotation);
}else {
apiInfo.put("chApiName", "");
apiInfo.put("apiNote", "");
}
}

//增加接口信息
if (!CollectionUtils.isEmpty(apiInfo)) {

//获取入参信息
Parameter[] parameters = method.getParameters();
//获取出参信息
AnnotatedType annotatedReturnType = method.getAnnotatedReturnType();
Type genericReturnType = method.getGenericReturnType();
List<Map<String, Object>> fieldList = new ArrayList<>();
apiInfo.put("fieldList", fieldList);
searchTypeField(fieldList,annotatedReturnType,new HashMap());
// getReturnTypeFirst(fieldList, annotatedReturnType, true);
// getReturnType(fieldList, annotatedReturnType);
// System.out.println(fieldList);
apiInfo.put("returnType",getRuturnType(fieldList));
apiList.add(apiInfo);
}
}
}
apiList.stream().forEach((info)-> System.out.println(JSON.toJSONString(info)));
}
//获取字段信息中的返回类型信息
static Map<String,Object> getRuturnType(List<Map<String,Object>> list){
if (CollectionUtils.isEmpty(list))
return new HashMap<>();
int index = -1;
for (int i = 0; i < list.size(); i++) {
Map<String, Object> fieldInfo = list.get(i);
if ("".equals(fieldInfo.get("fieldName"))){
index = i;
break;
}
}
if (index<0)
return new HashMap<>();
Map<String, Object> returnTypeInfo = list.get(index);
list.remove(index);
return returnTypeInfo;
}
/**
* 判断是否为Controller类
*
* @param klass
* @return
*/
static boolean isController(Class klass) {
Annotation[] Annotations = klass.getAnnotations();
for (Annotation annotation : Annotations) {
if (annotation instanceof RestController) {
return true;
}
}
return false;
}

/**
* 获取接口Id
*
* @param apiMap
* @param value
*/
static void getApiId(Map<String, Object> apiMap, String[] value) {
if (value == null || value.length == 0)
apiMap.put("apiId", "");
else
apiMap.put("apiId", value[0]);
}

/**
* 获取接口中文名和描述
*
* @param apiMap
* @param apiOperation
*/
static void getApiCnName(Map<String, Object> apiMap, ApiOperation apiOperation) {
apiMap.put("chApiName", apiOperation.value() == null ? "" : apiOperation.value());
apiMap.put("apiNote", apiOperation.notes() == null ? "" : apiOperation.notes());
}

/**
* 首次判断返回类型,需获取返回类型是否有父类,有则获取父类返回值加入同级list
*
* @param fieldList
* @param annotatedType
* @throws Exception
*/
static void getReturnTypeFirst(List<Map<String, Object>> fieldList, AnnotatedType annotatedType, boolean isFirst) throws Exception {
//仅第一层时获取父类参数
if (isFirst) {
//获取返回类型父类字段
getFatherField(fieldList, annotatedType);
}
//判断是否为基础类型
if (isBasicType(annotatedType.getType())) {
System.out.println("基础类型..");
}

//判断是否有泛型,ParameterizedType为泛型类型
if (annotatedType.getType() instanceof ParameterizedType) {
((ParameterizedType) annotatedType.getType()).getActualTypeArguments();

} else {

//不包含泛型,直接加入同级list
Field[] declaredFields = new Field[0];
try {
declaredFields = Class.forName(annotatedType.getType().getTypeName()).getDeclaredFields();
} catch (ClassNotFoundException e) {
// 基础类型找不到类时发生异常
addField(fieldList, annotatedType);
}
if (declaredFields != null) {
for (Field declaredField : declaredFields) {
//加入同级list
addField(fieldList, declaredField);
// AnnotatedType fieldAnnoType = declaredField.getAnnotatedType();
//如果不是基础类型
// if (!isBasicType(fieldAnnoType)){
// //判断是否包含泛型,若包含
// if (fieldAnnoType instanceof ParameterizedType) {
//
// }else{
// //不包含泛型,加入递归子级
//
// }
// }
}
}
}
}

/**
* 增加同级字段信息,如果不是基础类型则递归增加
*
* @param fieldList
* @param declaredField
*/
static void addField(List<Map<String, Object>> fieldList, Field declaredField) throws Exception {
if (declaredField == null)
return;
ApiModelProperty annotatin = declaredField.getAnnotation(ApiModelProperty.class);
// fieldMap.put("id", UUID.randomUUID());
Map<String, Object> fieldMap = generaFieldInfo(declaredField.getName(), annotatin != null ? annotatin.value() : "", declaredField.getType().getSimpleName(), "Y", annotatin != null ? annotatin.example() : "");
fieldList.add(fieldMap);

Type fieldAnnoType = declaredField.getType();
//如果不是基础类型
if (!isBasicType(fieldAnnoType)) {
//判断是否包含泛型,若包含
if (fieldAnnoType instanceof ParameterizedType) {
//递归解析泛型数量为1的类型
if (((ParameterizedType) fieldAnnoType).getActualTypeArguments().length == 1) {
List<Map<String, Object>> subFieldList = new ArrayList<>();
fieldMap.put("children", subFieldList);
Type actualTypeArgument = ((ParameterizedType) fieldAnnoType).getActualTypeArguments()[0];
getReturnTypeFirst(subFieldList, null, false);
}

} else {
//不包含泛型,加入递归子级
List<Map<String, Object>> subFieldList = new ArrayList<>();
fieldMap.put("children", subFieldList);
getReturnTypeFirst(subFieldList, declaredField.getAnnotatedType(), false);
}
}
}

static void addField(List<Map<String, Object>> fieldList, AnnotatedType annotatedType) throws Exception {
if (annotatedType == null)
return;
Map<String, Object> fieldMap = new HashMap();
ApiModelProperty annotatin = annotatedType.getAnnotation(ApiModelProperty.class);
// fieldMap.put("id", UUID.randomUUID());
fieldMap.put("id", "id2");
fieldMap.put("desc", annotatin != null ? annotatin.value() : "");
// fieldMap.put("fieldName",((Field) ((AnnotatedTypeFactory.AnnotatedTypeBaseImpl) annotatedType).decl).name);
fieldMap.put("fieldType", annotatedType.getType().getTypeName());

fieldList.add(fieldMap);
}

/**
* 仅增加第一层父类,没有深入递归的必要
*
* @param fieldList
* @param annotatedType
*/
static void getFatherField(List<Map<String, Object>> fieldList, AnnotatedType annotatedType) throws Exception {
//判断是否有泛型,ParameterizedType为泛型类型
if (annotatedType.getType() instanceof ParameterizedType) {
//判断是否有父类,仅查找第一层父类
if (Class.forName(((ParameterizedType) annotatedType.getType()).getRawType().getTypeName()).getSuperclass() != null) {
Field[] declaredFields = Class.forName(((ParameterizedType) annotatedType.getType()).getRawType().getTypeName()).getSuperclass().getDeclaredFields();
if (declaredFields != null) {
for (Field declaredField : declaredFields) {
//增加父类成员到同级list
addField(fieldList, declaredField);
}
}
}
} else {
//判断是否有父类,仅查找第一层父类
if (Class.forName(annotatedType.getType().getTypeName()).getSuperclass() != null) {
Field[] declaredFields = Class.forName(annotatedType.getType().getTypeName()).getSuperclass().getDeclaredFields();
if (declaredFields != null) {
for (Field declaredField : declaredFields) {
//增加父类成员到同级list
addField(fieldList, declaredField);
}
}
}
}
}

// /**
// * 获取返回类型及描述
// *
// * @param fieldList
// * @param annotatedType
// */
// static void getReturnType(List<Map<String, Object>> fieldList, AnnotatedType annotatedType) throws Exception {
// if (annotatedType.getType() instanceof ParameterizedType) {
// ParameterizedType type = (ParameterizedType) annotatedType.getType();
// String typeName1 = type.getTypeName();
// Type rawType = type.getRawType();
// String typeName = rawType.getTypeName();
// Type[] actualTypeArguments = type.getActualTypeArguments();
// boolean entity = isEntity(actualTypeArguments[0]);
// System.out.println(entity);
// if (entity) {
// Class<?> responClass = Class.forName(actualTypeArguments[0].getTypeName());
// Field[] declaredFields = responClass.getDeclaredFields();
// if (declaredFields.length > 0) {
// for (Field declaredField : declaredFields) {
// Map<String, Object> fieldMap = new HashMap();
// ApiModelProperty annotatin = declaredField.getAnnotation(ApiModelProperty.class);
//// fieldMap.put("id", UUID.randomUUID());
// fieldMap.put("id", "id");
// String desc = "";
// if (annotatin != null) {
// desc = annotatin.value();
// }
// fieldMap.put("desc", desc);
// fieldMap.put("fieldName", declaredField.getName());
// fieldMap.put("fieldType", declaredField.getType().getSimpleName());
// fieldList.add(fieldMap);
// //如果为List类型则加入子集
//// if (declaredFie)
// //判断是否为Entity,如果为Entity则递归加入子集
// if ((!isBasicType(declaredField.getType()) && isEntity(declaredField.getType()))) {
// List<Map<String, Object>> subFieldList = new ArrayList<>();
// fieldMap.put("children", subFieldList);
// getReturnType(subFieldList, declaredField.getAnnotatedType());
// }
// }
// }
// System.out.println(declaredFields);
//
// } else {
// fieldList.add(new HashMap() {{
// put("id", UUID.randomUUID());
// put("fieldName", "result");
// put("fieldType", "Map<String,Object>");
// }});
// }
//
// } else {
// Type type = annotatedType.getType();
// String typeName = type.getTypeName();
//
// boolean entity = isEntity(type);
// if (entity) {
// Class<?> responClass = Class.forName(type.getTypeName());
// Field[] declaredFields = responClass.getDeclaredFields();
// if (declaredFields.length > 0) {
// for (Field declaredField : declaredFields) {
// Map<String, Object> fieldMap = new HashMap();
// ApiModelProperty annotatin = declaredField.getAnnotation(ApiModelProperty.class);
//// fieldMap.put("id", UUID.randomUUID());
// fieldMap.put("id", "id");
// String desc = "";
// if (annotatin != null) {
// desc = annotatin.value();
// }
// fieldMap.put("desc", desc);
// fieldMap.put("fieldName", declaredField.getName());
// fieldMap.put("fieldType", declaredField.getType().getSimpleName());
// fieldList.add(fieldMap);
// //判断是否为Entity,如果为Entity则递归加入子集
// if (!isBasicType(declaredField.getType()) && isEntity(declaredField.getType())) {
// List<Map<String, Object>> subFieldList = new ArrayList<>();
// fieldMap.put("children", subFieldList);
// getReturnType(subFieldList, declaredField.getAnnotatedType());
// }
// }
// }
// System.out.println(declaredFields);
//
// } else {
// fieldList.add(new HashMap() {{
// put("id", UUID.randomUUID());
// put("fieldName", "result");
// put("fieldType", "Map<String,Object>");
// }});
// }
// }
// System.out.println();
// }

/**
* 非基础类型,非Map、List皆判断为实体类
* @param returnType
* @return
*/
static boolean isEntity(Type returnType) {
if (returnType == null)
return false;
if (isBasicType(returnType))
return false;
if (returnType.getTypeName().contains("Object") || returnType.getTypeName().contains("java.util.Map") || returnType.getTypeName().contains("java.util.Set"))
return false;
Object o = null;
try {
o = Class.forName(((Class) returnType).getName()).newInstance();
} catch (Exception e) {
return true;
}
if (o instanceof Map || returnType.getTypeName().contains("Object"))
return false;
else return true;
}

static boolean isBasicType(Object obj) {
if (obj == null)
return true;
if (obj instanceof Type || obj instanceof AnnotatedType) {
String typeName = "";
if (obj instanceof Type)
typeName = ((Type) obj).getTypeName();
else
typeName = ((AnnotatedType) obj).getType().getTypeName();
if (typeName.equals(Integer.TYPE)
|| typeName.equals(String.class.getTypeName())
|| typeName.equals(Date.class.getTypeName())
|| typeName.equals(BigDecimal.class.getTypeName())
|| typeName.equals(BigInteger.class.getTypeName())
|| typeName.equals(JSONObject.class.getTypeName())
|| typeName.equals(Object.class.getTypeName())
|| typeName.equals(Character.class.getTypeName())
|| typeName.equals(Long.TYPE)
|| typeName.equals(Double.TYPE)
|| typeName.equals(Float.TYPE)
|| typeName.equals(Character.TYPE)
|| typeName.equals(Short.TYPE)
|| typeName.equals(Boolean.TYPE)
) {
return true;
}
}
if (obj instanceof Integer
|| obj instanceof Long
|| obj instanceof String
|| obj instanceof Double
|| obj instanceof Float
|| obj instanceof Character
|| obj instanceof JSONObject
|| obj instanceof Short
|| obj instanceof Boolean
|| obj instanceof BigDecimal
|| obj instanceof BigInteger
|| obj instanceof Date
|| obj.getClass().getTypeName().contains("java.lang.Object")
) {
return true;
}
return false;
}

/**
* 首次判断返回类型,需获取返回类型是否有父类,有则获取父类返回值加入同级list
*
* @param fieldList
* @param annotatedType
* @throws Exception
*/
static void searchTypeField(List<Map<String, Object>> fieldList, AnnotatedType annotatedType, Map<String, Object> genericsInfo) throws Exception {
Type calssType = annotatedType.getType();
getTypeAllField(fieldList,calssType,genericsInfo);
//类型是否为空
if (calssType.getTypeName().equals("void") || annotatedType == null){
fieldList.add(generaFieldInfo("","接口返回类型","void 此接口无任何返回",Y,""));
return;
}
//是否为基础类型
if (isBasicType(calssType) || isBasicType(annotatedType)) {
fieldList.add(generaFieldInfo("","接口返回类型",((Class) calssType).getSimpleName(),Y,""));
return;
}
//是否为数组
if (calssType.getTypeName().contains("[")) {
fieldList.add(generaFieldInfo("","接口返回类型",((Class) calssType).getSimpleName(),Y,""));
//基础类型数组不需要再解析
if (isBasicType(calssType))
return;
//非基础类型数组需递归获取所成员变量
}

//是否包含泛型
if (calssType instanceof ParameterizedType) {
fieldList.add(generaFieldInfo("","接口返回类型",calssType.getTypeName(),Y,""));
genericsInfo.put("typeName", ((ParameterizedType) calssType).getActualTypeArguments()[0].getTypeName());
//泛型为Map类型
if (isMapGenerics(annotatedType)) {
//判断是否有Map第二泛型
if (((ParameterizedType) calssType).getActualTypeArguments()[0] instanceof ParameterizedType) {
//判断Map的第二泛型是否为实体类(不是实体类不用解析当Object处理)

}

}
//泛型为List类型
if (isListGenerics(annotatedType)) {
//是否为泛型List
if (((ParameterizedType) calssType).getActualTypeArguments()[0] instanceof ParameterizedType) {
//判断Map的第二泛型是否为实体类(不是实体类不用解析当Object处理)

}
}
//泛型为实体类
//泛型为其他类型,无法识别当做Object处理

}else {
//非泛型
//有父类先获取父类信息
if (haveFatherClass(calssType)){
getFatherClassFields(fieldList,calssType,new HashMap<>());
}
//获取自身信息
fieldList.add(generaFieldInfo("","接口返回类型",((Class) calssType).getSimpleName(),Y,""));
//判断是否为实体类,若为实体类则地柜获取实体类信息
if (isEntity(calssType)){
Field[] declaredFields = Class.forName(calssType.getTypeName()).getDeclaredFields();
for (Field declaredField : declaredFields) {
addField(fieldList,declaredField);
}
}
}

//是否为泛型类型,如果为泛型类型,先递归扫描泛型实体类,再将实体类传入泛型类实际成员
// if (ann)
//是否包含父类,父类非空且不为Object
if (calssType.getClass().getSuperclass() != null && !"java.lang.Object".equals(calssType.getClass().getSuperclass().getCanonicalName())) {
//查询父类所有字段并加入字段集合

}
//是否为实体类且不包含泛型
}

static void getTypeAllField(List<Map<String, Object>> fieldList, Type classType, Map<String, Object> genericsInfo){
if (classType.getTypeName().equals("void") || classType == null)
return;
//有父类递归获取父类全部字段
if (haveFatherClass(classType)){
getFatherClassFields(fieldList,classType,genericsInfo);
}
//泛型(泛型类不填泛型也会是false)
if (classType instanceof ParameterizedType){
//如果实体类为泛型类则不解析
if (((ParameterizedTypeImpl) classType).getActualTypeArguments()[0] instanceof ParameterizedType){
genericsInfo.put("type",((ParameterizedTypeImpl) classType).getActualTypeArguments()[0].getTypeName());
} else {
//解析实体类
Type entityType = ((ParameterizedTypeImpl) classType).getActualTypeArguments()[0];
try {
Field[] declaredFields = Class.forName(entityType.getTypeName()).getDeclaredFields();
// declaredFields
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
((ParameterizedType) classType).getActualTypeArguments();
}
//获取当前类型的所有字段
//非基础类型/MAP/LIST则认定为实体类

//数组

//普通类型
}

/**
* 判断是否为Map类型泛型
*/
static boolean isMapGenerics(AnnotatedType annotatedType) {
try {
if (((ParameterizedType) annotatedType.getType()).getActualTypeArguments()[0].getTypeName().contains("java.util.Map")) {
return true;
}
} catch (Exception e) {
return false;
}
return false;
}

/**
* 判断是否为Map类型泛型
*/
static boolean isListGenerics(AnnotatedType annotatedType) {
try {
if (((ParameterizedType) annotatedType.getType()).getActualTypeArguments()[0].getTypeName().contains("java.util.List")) {
return true;
}
} catch (Exception e) {
return false;
}
return false;
}

static void getFatherClassFields(List<Map<String, Object>> fieldList, Type classType, Map<String, Object> genericsInfo){
if (classType instanceof ParameterizedType){
try {
Class<?> superclass = Class.forName(((ParameterizedTypeImpl) classType).getRawType().getTypeName()).getSuperclass();
Field[] declaredFields = superclass.getDeclaredFields();
addFatherFields(fieldList,declaredFields,genericsInfo);
} catch (ClassNotFoundException e) {
System.out.println("获取类对象失败");
return;
}
}else {
try {
Class<?> superclass = Class.forName(classType.getTypeName()).getSuperclass();
Field[] declaredFields = superclass.getDeclaredFields();
addFatherFields(fieldList,declaredFields,genericsInfo);
} catch (ClassNotFoundException e) {
System.out.println("获取类对象失败");
return;
}
}
}
static void addEntityFields(List<Map<String, Object>> fieldList, Field[] declaredFields, Map<String, Object> genericsInfo){

}
static int addFatherFields(List<Map<String, Object>> fieldList, Field[] declaredFields, Map<String, Object> genericsInfo){
int count = 0;
for (Field declaredField : declaredFields) {
//添加栏位信息
ApiModelProperty annotatin = declaredField.getAnnotation(ApiModelProperty.class);
String desc = "";
String example = "";
if (annotatin != null) {
desc = annotatin.value();
example = annotatin.example();
}
Map<String, Object> fieldMap = generaFieldInfo(declaredField.getName(), desc, declaredField.getType().getSimpleName(), "Y", example);
fieldList.add(fieldMap);
count++;

if (haveFatherClass(declaredField.getType())){
getFatherClassFields(fieldList,declaredField.getType(),genericsInfo);
}
}
return count;
}

static void scanType(List<Map<String, Object>> fieldList, Type type, Map<String, Object> genericsInfo){
//有父类先添加父类字段
if (haveFatherClass(type)){
//扫描父类信息加入同级栏位

}
}
/**
* 判断字符串是否为纯大写字符
* @param str
* @return
*/
static boolean isUpperAlphabet(String str){
if (StringUtils.isEmpty(str))
return false;
for (char c : str.toCharArray()) {
if (c >= 'A' && c <= 'Z'){
return false;
}
}
return true;
}

/**
* 类型是否有父类
* @param type
* @return
*/
static boolean haveFatherClass(Type type){
if (type == null)
return false;
if (type instanceof ParameterizedType){
try {
if (Class.forName(((ParameterizedTypeImpl) type).getRawType().getTypeName()).getSuperclass() !=null && !"java.lang.Object".equals(Class.forName(((ParameterizedTypeImpl) type).getRawType().getTypeName()).getSuperclass().getCanonicalName())){
return true;
}
} catch (ClassNotFoundException e) {
return false;
}
}

try {
if (Class.forName(type.getTypeName()).getSuperclass() != null && !"java.lang.Object".equals(Class.forName(type.getTypeName()).getSuperclass().getCanonicalName())){
return true;
}
} catch (ClassNotFoundException e) {
return false;
}
return false;
}

static Map<String,Object> generaFieldInfo(String name,String desc,String type,String require,String example){
Map<String,Object> resultMap = new HashMap();
resultMap.put("desc", desc);
resultMap.put("fieldName", name);
resultMap.put("fieldType", type);
resultMap.put("example", example);
// resultMap.put("require", Y.equals(require) ? Y:N);
return resultMap;
}

//是否是基础类型数组
static boolean isBasicArrType(Type arrType){
if (arrType.getTypeName().contains("int")
|| arrType.getTypeName().contains("long")
|| arrType.getTypeName().contains("char")
|| arrType.getTypeName().contains("short")
|| arrType.getTypeName().contains("float")
|| arrType.getTypeName().contains("double")
|| arrType.getTypeName().contains("boolean")
|| arrType.getTypeName().contains("JSON")
|| arrType.getTypeName().contains("JSONObject")
|| arrType.getTypeName().contains("java.lang")
)
return true;
return false;
}
}

随机推荐

  1. vue.js+canvas实现随机验证码

    登录注册啥的,不需要下载插件,上图: 代码: <template> <div class="about"> <p>当前验证码:{{codeStr ...

  2. neovim 使用系统剪贴板

    neovim 使用系统剪贴板 1.vim 与 neovim 使用系统剪切板的不同 Nvim has no direct connection to the system clipboard. Inst ...

  3. 安装assimp失败

    使用Cmake和Visual Studio编译assimp成功(包括Debug和Release),并且安装Release版本也成功,但安装debug版本失败,安装输出信息如下: 通过提示找到脚本文件, ...

  4. ansible(13)--ansible的lineinfile模块

    1. lineinfile模块 功能:修改或删除文件内容,与系统中的 sed 命令类似: 主要参数如下: 参数 说明 path 指定要操作的文件 regexp 使用正则表达式匹配对应的行 line 修 ...

  5. keepalived(2)- keepalived安装和配置

    目录 1. keepalived安装配置 1.1 keepalived安装环境 1.2 keepalived日志文件 1.3 keepalived配置文件 2. keepalived配置 2.1 ke ...

  6. Netflow/IPFIX 流量收集与分析

    目录 文章目录 目录 Netflow(网络数据流检测协议) IPFIX(网络流量监测) IPFIX 组网架构 IPFIX 应用场景 Usage-based Accounting(基于使用流量的计费) ...

  7. 有隙可乘 - Android 序列化漏洞分析实战

    作者:vivo 互联网大前端团队 - Ma Lian 本文主要描述了FileProvider,startAnyWhere实现,Parcel不对称漏洞以及这三者结合产生的漏洞利用实战,另外阐述了漏洞利用 ...

  8. 保姆教程系列:Git 实用命令详解

    !!!是的没错,胖友们,保姆教程系列又更新了!!! @ 目录 前言 1.将本地项目推送到远程仓库 2. Idea Git回退到某个历史版本 3. 修改项目关联远程地址方法 4. Git 修改分支的名称 ...

  9. .NET Aspire 正式发布:简化 .NET 云原生开发

    .NET团队北京时间2024年5月22日已正式发布.NET Aspire ,在博客文章里做了详细的介绍:.NET Aspire 正式发布:简化 .NET 云原生开发 - .NET 博客 (micros ...

  10. 文件系统(四):FAT32文件系统实现原理

    FAT32是从FAT12.FAT16发展而来,目前主要应用在移动存储设备中,比如SD卡.TF卡.隐藏的FAT文件系统现在也有被大量使用在UEFI启动分区中. 为使文章简单易读,下面内容特意隐藏了很多实 ...