mirror of https://gitee.com/makejava/EasyCode.git
完善调式方法
This commit is contained in:
parent
2b2b3ca97e
commit
1a74bb84ab
|
@ -34,7 +34,7 @@ public class EasyCodeGlobalVariableProvider extends VtlGlobalVariableProvider {
|
||||||
result.add(new VtlLightVariable("modulePath", file, CommonClassNames.JAVA_LANG_STRING));
|
result.add(new VtlLightVariable("modulePath", file, CommonClassNames.JAVA_LANG_STRING));
|
||||||
result.add(new VtlLightVariable("importList", file, "java.util.Set<java.lang.String>"));
|
result.add(new VtlLightVariable("importList", file, "java.util.Set<java.lang.String>"));
|
||||||
result.add(new VtlLightVariable("callback", file, "com.sjhy.plugin.entity.Callback"));
|
result.add(new VtlLightVariable("callback", file, "com.sjhy.plugin.entity.Callback"));
|
||||||
result.add(new VtlLightVariable("tool", file, "com.sjhy.plugin.tool.NameUtils"));
|
result.add(new VtlLightVariable("tool", file, "com.sjhy.plugin.tool.GlobalTool"));
|
||||||
result.add(new VtlLightVariable("time", file, "com.sjhy.plugin.tool.TimeUtils"));
|
result.add(new VtlLightVariable("time", file, "com.sjhy.plugin.tool.TimeUtils"));
|
||||||
result.add(new VtlLightVariable("tableInfo", file, "com.sjhy.plugin.entity.TableInfo"));
|
result.add(new VtlLightVariable("tableInfo", file, "com.sjhy.plugin.entity.TableInfo"));
|
||||||
result.add(new VtlLightVariable("tableInfoList", file, "java.util.List<com.sjhy.plugin.entity.TableInfo>"));
|
result.add(new VtlLightVariable("tableInfoList", file, "java.util.List<com.sjhy.plugin.entity.TableInfo>"));
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
package com.sjhy.plugin.tool;
|
package com.sjhy.plugin.tool;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||||
import com.intellij.util.ExceptionUtil;
|
import com.intellij.util.ExceptionUtil;
|
||||||
import com.intellij.util.ReflectionUtil;
|
import com.intellij.util.ReflectionUtil;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -40,6 +41,7 @@ public class GlobalTool extends NameUtils {
|
||||||
}
|
}
|
||||||
return globalTool;
|
return globalTool;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* jackson格式化工具
|
* jackson格式化工具
|
||||||
*/
|
*/
|
||||||
|
@ -98,6 +100,21 @@ public class GlobalTool extends NameUtils {
|
||||||
return ReflectionUtil.getField(cls, obj, Object.class, fieldName);
|
return ReflectionUtil.getField(cls, obj, Object.class, fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取某个类的所有字段
|
||||||
|
*
|
||||||
|
* @param cls 类
|
||||||
|
* @return 所有字段
|
||||||
|
*/
|
||||||
|
private List<Field> getAllFieldByClass(Class<?> cls) {
|
||||||
|
List<Field> result = new ArrayList<>();
|
||||||
|
do {
|
||||||
|
result.addAll(Arrays.asList(cls.getDeclaredFields()));
|
||||||
|
cls = cls.getSuperclass();
|
||||||
|
} while (!cls.equals(Object.class));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 调式对象
|
* 调式对象
|
||||||
*
|
*
|
||||||
|
@ -105,11 +122,40 @@ public class GlobalTool extends NameUtils {
|
||||||
* @return 调式JSON结果
|
* @return 调式JSON结果
|
||||||
*/
|
*/
|
||||||
public String debug(Object obj) {
|
public String debug(Object obj) {
|
||||||
|
if (obj == null) {
|
||||||
|
return "null";
|
||||||
|
}
|
||||||
|
StringBuilder builder = new StringBuilder("\n/*调试信息:\nField Item List:\n");
|
||||||
|
Class<?> cls = obj.getClass();
|
||||||
|
List<Field> fieldList = getAllFieldByClass(cls);
|
||||||
|
fieldList.forEach(field -> {
|
||||||
|
field.setAccessible(true);
|
||||||
|
builder.append("field=");
|
||||||
|
builder.append(field.getName());
|
||||||
|
builder.append(",\t\ttype=");
|
||||||
|
builder.append(field.getType());
|
||||||
|
builder.append(",\t\tvalue=");
|
||||||
try {
|
try {
|
||||||
return objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(obj);
|
builder.append(field.get(obj));
|
||||||
} catch (JsonProcessingException e) {
|
} catch (IllegalAccessException e) {
|
||||||
ExceptionUtil.rethrow(e);
|
ExceptionUtil.rethrow(e);
|
||||||
}
|
}
|
||||||
return null;
|
builder.append("\n");
|
||||||
|
});
|
||||||
|
// 方法列表
|
||||||
|
builder.append("\nMethod List:\n");
|
||||||
|
// 排除方法
|
||||||
|
List<String> fillterMethodName = Arrays.asList("hashCode", "toString", "equals");
|
||||||
|
for (Method method : cls.getDeclaredMethods()) {
|
||||||
|
if (fillterMethodName.contains(method.getName())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
builder.append(method.getName());
|
||||||
|
builder.append("=");
|
||||||
|
builder.append(method.toGenericString());
|
||||||
|
builder.append("\n");
|
||||||
|
}
|
||||||
|
builder.append("*/\n");
|
||||||
|
return builder.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue