From 166722a15cb5e3499593dbf8128038d7250b53f9 Mon Sep 17 00:00:00 2001 From: John Cortell Date: Thu, 10 Sep 2009 19:33:53 +0000 Subject: [PATCH] Fix and improve new logging utility --- .../cdt/internal/core/LoggingUtils.java | 20 +++++++++---------- .../cdt/dsf/internal/LoggingUtils.java | 18 +++++++++-------- 2 files changed, 20 insertions(+), 18 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 99ee9745387..c71be72663f 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 @@ -17,12 +17,13 @@ package org.eclipse.cdt.internal.core; */ public class LoggingUtils { /** - * Return a string that uniquely identifies a Java object reference, in the form "classname@id", where - * 'classname' is the simple (unqualified) name of the object's class, and 'id' is the hash code. If the - * object is of an anonymous class, classname will be "". + * 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. * - * Why not just use obj.toString()? That method is often overriden, and so cannot be relied on for a - * representation that uniquely identifies the object in the VM space. + * Why not just use obj.toString()? That method is often overriden, and so + * cannot be relied on for a representation that uniquely identifies the + * object in the VM space. * * @param obj * the object reference to stringify @@ -32,15 +33,14 @@ public class LoggingUtils { if (obj == null) { return "null"; //$NON-NLS-1$ } - String className = obj.getClass().getSimpleName(); - if (className == null) { - className = ""; //$NON-NLS-1$ + String className = obj.getClass().getName(); + 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$ } - - } diff --git a/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/internal/LoggingUtils.java b/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/internal/LoggingUtils.java index 5b65c993514..b1c13ca3578 100644 --- a/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/internal/LoggingUtils.java +++ b/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/internal/LoggingUtils.java @@ -21,12 +21,13 @@ package org.eclipse.cdt.dsf.internal; */ public class LoggingUtils { /** - * Return a string that uniquely identifies a Java object reference, in the form "classname@id", where - * 'classname' is the simple (unqualified) name of the object's class, and 'id' is the hash code. If the - * object is of an anonymous class, classname will be "". + * 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. * - * Why not just use obj.toString()? That method is often overriden, and so cannot be relied on for a - * representation that uniquely identifies the object in the VM space. + * Why not just use obj.toString()? That method is often overriden, and so + * cannot be relied on for a representation that uniquely identifies the + * object in the VM space. * * @param obj * the object reference to stringify @@ -36,9 +37,10 @@ public class LoggingUtils { if (obj == null) { return "null"; //$NON-NLS-1$ } - String className = obj.getClass().getSimpleName(); - if (className == null) { - className = ""; //$NON-NLS-1$ + String className = obj.getClass().getName(); + int lastDot = className.lastIndexOf('.'); + if ((lastDot >= 0) && ((lastDot + 1) < className.length())) { + className = className.substring(lastDot + 1); } String id = Integer.toHexString(System.identityHashCode(obj));