@ SuppressWarnings ( "checkstyle:npathcomplexity" ) public static String dump ( Object object , boolean includeStaticField ) { if ( object == null ) { return new String ( ) ; } final StringBuilder buffer = new StringBuilder ( ) ; final LinkedList < Class < ? > > types = new LinkedList <> ( ) ; types . add ( object . getClass ( ) ) ; while ( ! types . isEmpty ( ) ) { final Class < ? > type = types . removeFirst ( ) ; final Class < ? > supertype = type . getSuperclass ( ) ; if ( supertype != null && ! supertype . equals ( Object . class ) ) { types . add ( supertype ) ; } if ( buffer . length ( ) > 0 ) { buffer . append ( "\n" ) ; //$NON-NLS-1$ } final Field [ ] fields = type . getDeclaredFields ( ) ; buffer . append ( type . getSimpleName ( ) ) . append ( " {\n" ) ; //$NON-NLS-1$ boolean firstRound = true ; for ( final Field field : fields ) { if ( ! includeStaticField && Flags . isStatic ( field . getModifiers ( ) ) ) { continue ; } if ( ! firstRound ) { buffer . append ( ",\n" ) ; //$NON-NLS-1$ } firstRound = false ; field . setAccessible ( true ) ; try { final Object fieldObj = field . get ( object ) ; final String value ; if ( null == fieldObj ) { value = "null" ; //$NON-NLS-1$ } else { value = fieldObj . toString ( ) ; } buffer . append ( ' ' ) . append ( field . getName ( ) ) . append ( ' ' ) . append ( ' ' ) ; buffer . append ( org . eclipse . xtext . util . Strings . convertToJavaString ( value ) ) ; buffer . append ( "\"\n" ) ; //$NON-NLS-1$ } catch ( IllegalAccessException ignore ) { //this should never happen } } buffer . append ( ' ' ) ; } return buffer . toString ( ) ; }
Dump the object .