scab2
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;
}
}
随机推荐
- Fixing Missing Windows App Runtime Environment Prompt for Unpackaged WinUI 3 Applications
This article will tell you how to fix the prompt for a missing Windows App Runtime environment when ...
- dotnet SemanticKernel 入门 注入日志
使用 SemanticKernel 框架在对接 AI 时,由于使用到了大量的魔法,需要有日志的帮助才好更方便定位问题,本文将告诉大家如何在 SemanticKernel 注入日志 本文属于 Seman ...
- 2019-9-2-C#-设计模式-责任链
title author date CreateTime categories C# 设计模式 责任链 lindexi 2019-09-02 12:57:37 +0800 2018-2-13 17:2 ...
- 利用Navicat的历史日志查询表的索引信息(还可以查询很多系统级别的信息)
1.使用前提 所有的能用Navicat连接的数据库都可以使用这个方法 DDL/DML语句都有 2.Navicat中的历史日志 3.比如查询mysql的表的索引 先打开"历史记录" ...
- linux-centos7.6 硬盘挂载
目录 一 .功能 二.VM中设置硬盘 2.1 系统关机状态下 2.2 添加硬盘 三.系统中挂载硬盘 3.1 查看硬盘信息 3.2 硬盘分区 3.3 格式化硬盘 3.4 临时挂载硬盘 3.4 开机自动挂 ...
- 让AnaTraf成为您网络流量分析的最佳利器
在快速发展的数字时代,企业对网络性能的监测与分析需求愈加旺盛.作为网络性能监测与诊断(NPMD)领域的佼佼者,AnaTraf网络流量分析仪凭借其出色的性能和易用性,正成为网络管理人员的首选工具. An ...
- ASP.NET Core Web中使用AutoMapper进行对象映射
前言 在日常开发中,我们常常需要将一个对象映射到另一个对象,这个过程中可能需要编写大量的重复性代码,如果每次都手动编写,不仅会影响开发效率,而且当项目越来越复杂.庞大的时候还容易出现错误.为了解决这个 ...
- prometheus使用2
参考不错的 Prometheus监控实战之node_exporter详解: https://blog.csdn.net/ygq13572549874/article/details/129115350 ...
- 【c++】求解八皇后问题
为:在8×8格的国际象棋上摆放8个皇后,使其不能互相攻击,即任意两个皇后都不能处于同一行.同一列或同一斜线上,问有多少种摆法.一共92个解 解决思路:一层层回溯,采用深度优先的递归算法. 动态分配的数 ...
- 开发中你不得不知的一个Git小技巧
一. 背景 在工作中大家应会碰到需要频繁在两个分支中切换工作的情况,我们通常做法是利用git stash命令暂存当前工作区中的变更,然后git checkout到目标分支中工作,工作完成后回到刚刚分支 ...