/*
 * fb-contrib - Auxiliary detectors for Java programs
 * Copyright (C) 2005-2014 Dave Brosius
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package com.mebigfatguy.fbcontrib.utils;

import java.lang.reflect.Field;
import java.util.Arrays;

/**
 * an automatic toString() builder using reflection
 */
public class ToString {

	private ToString() {
	}
	
	public static String build(Object o) {
		StringBuilder sb = new StringBuilder(100);
		Class<?> cls = o.getClass();
		sb.append(cls.getSimpleName()).append('[');
		
		try {
			String sep = "";
			for (Field f : cls.getDeclaredFields()) {
				sb.append(sep);
				sep = ", ";
				sb.append(f.getName()).append('=');
				f.setAccessible(true);
				Object value = f.get(o);
				if (value == null) {
					sb.append((String) null);
				} else if (value.getClass().isArray()) {
					sb.append(Arrays.toString((Object[]) value));
				} else {
					sb.append(value);
				}
			}
		} catch (Exception e) {
		}
		
		sb.append(']');
		return sb.toString();
	}
}

@@ -1362,16 +1362,30 @@
 d('=');%0A
+%09%09%09%09try %7B%0A    
 %09%09%09%09f.se
@@ -1399,24 +1399,28 @@
 ible(true);%0A
+    
 %09%09%09%09Object v
@@ -1436,16 +1436,20 @@
 get(o);%0A
+    
 %09%09%09%09if (
@@ -1461,24 +1461,28 @@
  == null) %7B%0A
+    
 %09%09%09%09%09sb.appe
@@ -1500,16 +1500,20 @@
  null);%0A
+    
 %09%09%09%09%7D el
@@ -1545,24 +1545,28 @@
 sArray()) %7B%0A
+    
 %09%09%09%09%09sb.appe
@@ -1604,16 +1604,20 @@
 alue));%0A
+    
 %09%09%09%09%7D el
@@ -1621,16 +1621,20 @@
  else %7B%0A
+    
 %09%09%09%09%09sb.
@@ -1648,16 +1648,105 @@
 value);%0A
+    %09%09%09%09%7D%0A%09%09%09%09%7D catch (SecurityException e) %7B%0A%09%09%09%09    sb.append(%22*SECURITY_EXCEPTION*%22);%0A
 %09%09%09%09%7D%0A%09%09

handle java 8's SecurityException on looking at ClassLoaders