From f53c0d4f1da31b36c3cf194fb51a9c08368eae2f Mon Sep 17 00:00:00 2001 From: John Cortell Date: Thu, 1 Oct 2009 02:20:29 +0000 Subject: [PATCH] Add variant of toString() that allows caller to indicate he wants qualified or simple class name --- .../cdt/internal/core/LoggingUtils.java | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/LoggingUtils.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/LoggingUtils.java index c71be72663f..95a43543cf2 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/LoggingUtils.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/LoggingUtils.java @@ -12,14 +12,12 @@ package org.eclipse.cdt.internal.core; /** * Some general purpose functions that can be useful for logging/tracing activities. - * - * @since 5.2 */ public class LoggingUtils { /** * Return a string that uniquely identifies a Java object reference, in the - * form "classname@id", where 'classname' is the simple (package - * unqualified) name of the object's class, and 'id' is the hash code. + * form "classname@id", where 'classname' is the simple or package qualified + * name of the object's class, and 'id' is the hash code. * * Why not just use obj.toString()? That method is often overriden, and so * cannot be relied on for a representation that uniquely identifies the @@ -27,20 +25,33 @@ public class LoggingUtils { * * @param obj * the object reference to stringify + * @param simpleClassName + * if true, use the class's simple name, otherwise the package + * qualified one + * * @return the stringified representation of the object reference */ - public static String toString(Object obj) { + public static String toString(Object obj, boolean simpleClassName) { if (obj == null) { return "null"; //$NON-NLS-1$ } String className = obj.getClass().getName(); - int lastDot = className.lastIndexOf('.'); - if ((lastDot >= 0) && ((lastDot + 1) < className.length())) { - className = className.substring(lastDot + 1); + if (simpleClassName) { + int lastDot = className.lastIndexOf('.'); + if ((lastDot >= 0) && ((lastDot + 1) < className.length())) { + className = className.substring(lastDot + 1); + } } String id = Integer.toHexString(System.identityHashCode(obj)); return className + "@" + id; //$NON-NLS-1$ } + + /** + * Equivalent to toString(obj, false) + */ + public static String toString(Object obj) { + return toString(obj, true); + } }