diff --git a/src/java/org/apache/commons/lang/builder/ReflectionToStringBuilder.java b/src/java/org/apache/commons/lang/builder/ReflectionToStringBuilder.java index ff3dbd647..232e7423a 100644 --- a/src/java/org/apache/commons/lang/builder/ReflectionToStringBuilder.java +++ b/src/java/org/apache/commons/lang/builder/ReflectionToStringBuilder.java @@ -104,7 +104,7 @@ import org.apache.commons.lang.ClassUtils; * @author Stephen Colebourne * @author Pete Gieser * @since 2.0 - * @version $Id: ReflectionToStringBuilder.java,v 1.13 2003/10/23 22:27:45 ggregory Exp $ + * @version $Id: ReflectionToStringBuilder.java,v 1.14 2003/11/03 00:21:19 ggregory Exp $ */ public class ReflectionToStringBuilder extends ToStringBuilder { @@ -335,91 +335,6 @@ public class ReflectionToStringBuilder extends ToStringBuilder { return new ReflectionToStringBuilder(object, style, null, reflectUpToClass, outputTransients).toString(); } - /** - * TODO: Is this convenience API really needed? - * - *

This method uses reflection to build a suitable - * toString value which includes static fields.

- * - *

It uses AccessibleObject.setAccessible to gain access to private - * fields. This means that it will throw a security exception if run - * under a security manager, if the permissions are not set up correctly. - * It is also not as efficient as testing explicitly.

- * - *

Transient fields are not output.

- * - *

Superclass fields will be appended up to and including - * java.lang.Object.

- * - *

The default ToStringStyle is used.

- * - * @param object the Object to be output - * @return the String result - * @throws IllegalArgumentException if the Object is null - */ - public static Object toStringWithStatics(Object object) { - return toString(object, null, false, true, null); - } - - /** - * TODO: Is this convenience API really needed? - * - *

This method uses reflection to build a suitable - * toString value which includes static fields.

- * - *

It uses AccessibleObject.setAccessible to gain access to private - * fields. This means that it will throw a security exception if run - * under a security manager, if the permissions are not set up correctly. - * It is also not as efficient as testing explicitly.

- * - *

Transient fields are not output.

- * - *

Superclass fields will be appended up to and including the specified superclass. - * A null superclass is treated as java.lang.Object.

- * - *

The default ToStringStyle is used.

- * - * @param object the Object to be output - * @param reflectUpToClass the superclass to reflect up to (inclusive), - * may be null - * @return the String result - * @throws IllegalArgumentException if the Object is null - */ - public static Object toStringWithStatics(Object object, Class reflectUpToClass) { - return toString(object, null, false, true, reflectUpToClass); - } - - /** - * TODO: Is this convenience API really needed? - * - *

This method uses reflection to build a suitable - * toString value which includes static fields.

- * - *

It uses AccessibleObject.setAccessible to gain access to private - * fields. This means that it will throw a security exception if run - * under a security manager, if the permissions are not set up correctly. - * It is also not as efficient as testing explicitly.

- * - *

Transient fields are not output.

- * - *

Superclass fields will be appended up to and including the specified superclass. - * A null superclass is treated as java.lang.Object.

- * - *

If the style is null, the default - * ToStringStyle is used.

- * - * @param object the Object to be output - * @param style the style of the toString to create, - * may be null - * @param reflectUpToClass the superclass to reflect up to (inclusive), - * may be null - * @return the String result - * @throws IllegalArgumentException if the Object is null - */ - public static Object toStringWithStatics(Object object, ToStringStyle style, Class reflectUpToClass) { - return toString(object, style, false, true, reflectUpToClass); - } - /** *

Unregisters the given object.

* diff --git a/src/test/org/apache/commons/lang/builder/ToStringBuilderTest.java b/src/test/org/apache/commons/lang/builder/ToStringBuilderTest.java index 673784051..9f1951250 100644 --- a/src/test/org/apache/commons/lang/builder/ToStringBuilderTest.java +++ b/src/test/org/apache/commons/lang/builder/ToStringBuilderTest.java @@ -68,7 +68,7 @@ import junit.textui.TestRunner; * @author Stephen Colebourne * @author Gary Gregory * @author Alex Chaffee - * @version $Id: ToStringBuilderTest.java,v 1.11 2003/10/23 22:26:00 ggregory Exp $ + * @version $Id: ToStringBuilderTest.java,v 1.12 2003/11/03 00:20:55 ggregory Exp $ */ public class ToStringBuilderTest extends TestCase { @@ -850,10 +850,10 @@ public class ToStringBuilderTest extends TestCase { ReflectionToStringBuilder.toString(instance1, null, true, true, SimpleReflectionStaticFieldsFixture.class)); assertEquals( this.toBaseString(instance1) + "[staticString=staticString,staticInt=12345]", - ReflectionToStringBuilder.toStringWithStatics(instance1, null, SimpleReflectionStaticFieldsFixture.class)); + this.toStringWithStatics(instance1, null, SimpleReflectionStaticFieldsFixture.class)); assertEquals( this.toBaseString(instance1) + "[staticString=staticString,staticInt=12345]", - ReflectionToStringBuilder.toStringWithStatics(instance1, SimpleReflectionStaticFieldsFixture.class)); + this.toStringWithStatics(instance1, null, SimpleReflectionStaticFieldsFixture.class)); } /** @@ -869,10 +869,10 @@ public class ToStringBuilderTest extends TestCase { ReflectionToStringBuilder.toString(instance1, null, true, true, ReflectionStaticFieldsFixture.class)); assertEquals( this.toBaseString(instance1) + "[staticString=staticString,staticInt=12345,instanceString=instanceString,instanceInt=67890]", - ReflectionToStringBuilder.toStringWithStatics(instance1, null, ReflectionStaticFieldsFixture.class)); + this.toStringWithStatics(instance1, null, ReflectionStaticFieldsFixture.class)); assertEquals( this.toBaseString(instance1) + "[staticString=staticString,staticInt=12345,instanceString=instanceString,instanceInt=67890]", - ReflectionToStringBuilder.toStringWithStatics(instance1, ReflectionStaticFieldsFixture.class)); + this.toStringWithStatics(instance1, null, ReflectionStaticFieldsFixture.class)); } /** @@ -888,10 +888,39 @@ public class ToStringBuilderTest extends TestCase { ReflectionToStringBuilder.toString(instance1, null, false, true, SimpleReflectionStaticFieldsFixture.class)); assertEquals( this.toBaseString(instance1) + "[staticString2=staticString2,staticInt2=67890,staticString=staticString,staticInt=12345]", - ReflectionToStringBuilder.toStringWithStatics(instance1, null, SimpleReflectionStaticFieldsFixture.class)); + this.toStringWithStatics(instance1, null, SimpleReflectionStaticFieldsFixture.class)); assertEquals( this.toBaseString(instance1) + "[staticString2=staticString2,staticInt2=67890,staticString=staticString,staticInt=12345]", - ReflectionToStringBuilder.toStringWithStatics(instance1, SimpleReflectionStaticFieldsFixture.class)); + this.toStringWithStatics(instance1, null, SimpleReflectionStaticFieldsFixture.class)); + } + + /** + *

This method uses reflection to build a suitable + * toString value which includes static fields.

+ * + *

It uses AccessibleObject.setAccessible to gain access to private + * fields. This means that it will throw a security exception if run + * under a security manager, if the permissions are not set up correctly. + * It is also not as efficient as testing explicitly.

+ * + *

Transient fields are not output.

+ * + *

Superclass fields will be appended up to and including the specified superclass. + * A null superclass is treated as java.lang.Object.

+ * + *

If the style is null, the default + * ToStringStyle is used.

+ * + * @param object the Object to be output + * @param style the style of the toString to create, + * may be null + * @param reflectUpToClass the superclass to reflect up to (inclusive), + * may be null + * @return the String result + * @throws IllegalArgumentException if the Object is null + */ + public Object toStringWithStatics(Object object, ToStringStyle style, Class reflectUpToClass) { + return ReflectionToStringBuilder.toString(object, style, false, true, reflectUpToClass); } /**