mirror of
https://github.com/alibaba/arthas.git
synced 2024-04-21 10:21:39 +00:00
support print fields in parent class. #435
This commit is contained in:
committed by
hengyunabc
parent
9f0212422d
commit
5850869843
@@ -99,4 +99,14 @@ public class GlobalOptions {
|
||||
)
|
||||
public static volatile String jobTimeout = "1d";
|
||||
|
||||
/**
|
||||
* 是否打印parent类里的field
|
||||
* @see com.taobao.arthas.core.view.ObjectView
|
||||
*/
|
||||
@Option(level = 1,
|
||||
name = "print-parent-fields",
|
||||
summary = "Option to print all fileds in parent class",
|
||||
description = "This option enables print files in parent class, default value true."
|
||||
)
|
||||
public static volatile boolean printParentFields = true;
|
||||
}
|
||||
|
||||
@@ -582,7 +582,22 @@ public class ObjectView implements View {
|
||||
appendStringBuilder(buf, format("@%s[%s]", className, obj));
|
||||
} else {
|
||||
appendStringBuilder(buf, format("@%s[", className));
|
||||
final Field[] fields = obj.getClass().getDeclaredFields();
|
||||
List<Field> fields = new ArrayList<Field>();
|
||||
Class objClass = obj.getClass();
|
||||
if (GlobalOptions.printParentFields) {
|
||||
// 当父类为null的时候说明到达了最上层的父类(Object类).
|
||||
while (objClass != null) {
|
||||
for (Field field : objClass.getDeclaredFields()) {
|
||||
fields.add(field);
|
||||
}
|
||||
objClass = objClass.getSuperclass();
|
||||
}
|
||||
} else {
|
||||
for (Field field : objClass.getDeclaredFields()) {
|
||||
fields.add(field);
|
||||
}
|
||||
}
|
||||
|
||||
if (null != fields) {
|
||||
for (Field field : fields) {
|
||||
|
||||
@@ -620,17 +635,6 @@ public class ObjectView implements View {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否根节点
|
||||
*
|
||||
* @param deep 深度
|
||||
* @return true:根节点 / false:非根节点
|
||||
*/
|
||||
private static boolean isRoot(int deep) {
|
||||
return deep == 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 是否展开当前深度的节点
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user