private void introspectViaReflection ( ) { { Class < ? > memberClass = _member . getClass ( ) ; if ( memberClass . isArray ( ) ) { int length = Array . getLength ( _member ) ; Class < ? > componentType = memberClass . getComponentType ( ) ; if ( componentType . isPrimitive ( ) ) { addNewChild ( componentType + "[0.." + ( length - 1 ) + "]" , _member ) ; } else { String simpleName = componentType . getSimpleName ( ) ; for ( int i = 0 ; i < length && i < MAX_ARRAY_LENGTH ; i ++ ) { Object value = Array . get ( _member , i ) ; addNewChild ( simpleName + "[" + i + "]" , value ) ; } if ( length > MAX_ARRAY_LENGTH ) { addNewChild ( simpleName + "[...]" , "/* array length = " + length + " */" ) ; } } } else { /* * Loop around the fields of the object (including fields of its * superclass) adding them as children (and, it we haven't seen * the child before, getting introspected at the next level if * its worth doing so) */ Class < ? > currentClass = _member . getClass ( ) ; while ( currentClass != Object . class ) { Field [ ] fields = getFields ( currentClass ) ; for ( int i = 0 ; i < fields . length && i < MAX_ARRAY_LENGTH ; i ++ ) { final Field field = fields [ i ] ; Object value = getFieldValue ( field ) ; addNewChild ( field . getName ( ) , value ) ; } if ( fields . length > MAX_ARRAY_LENGTH ) { addNewChild ( "field..." , "/* total # of fields = " + fields . length + " */" ) ; } currentClass = currentClass . getSuperclass ( ) ; } } } }
Introspect the object via reflection