mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-09-02 21:23:37 +02:00
Fix and improve new logging utility
This commit is contained in:
parent
52e0d6731e
commit
166722a15c
2 changed files with 20 additions and 18 deletions
|
@ -17,12 +17,13 @@ package org.eclipse.cdt.internal.core;
|
||||||
*/
|
*/
|
||||||
public class LoggingUtils {
|
public class LoggingUtils {
|
||||||
/**
|
/**
|
||||||
* Return a string that uniquely identifies a Java object reference, in the form "classname@id", where
|
* Return a string that uniquely identifies a Java object reference, in the
|
||||||
* 'classname' is the simple (unqualified) name of the object's class, and 'id' is the hash code. If the
|
* form "classname@id", where 'classname' is the simple (package
|
||||||
* object is of an anonymous class, classname will be "<anonymous-class>".
|
* 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
|
* Why not just use obj.toString()? That method is often overriden, and so
|
||||||
* representation that uniquely identifies the object in the VM space.
|
* cannot be relied on for a representation that uniquely identifies the
|
||||||
|
* object in the VM space.
|
||||||
*
|
*
|
||||||
* @param obj
|
* @param obj
|
||||||
* the object reference to stringify
|
* the object reference to stringify
|
||||||
|
@ -32,15 +33,14 @@ public class LoggingUtils {
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
return "null"; //$NON-NLS-1$
|
return "null"; //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
String className = obj.getClass().getSimpleName();
|
String className = obj.getClass().getName();
|
||||||
if (className == null) {
|
int lastDot = className.lastIndexOf('.');
|
||||||
className = "<anonymous-class>"; //$NON-NLS-1$
|
if ((lastDot >= 0) && ((lastDot + 1) < className.length())) {
|
||||||
|
className = className.substring(lastDot + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
String id = Integer.toHexString(System.identityHashCode(obj));
|
String id = Integer.toHexString(System.identityHashCode(obj));
|
||||||
|
|
||||||
return className + "@" + id; //$NON-NLS-1$
|
return className + "@" + id; //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,12 +21,13 @@ package org.eclipse.cdt.dsf.internal;
|
||||||
*/
|
*/
|
||||||
public class LoggingUtils {
|
public class LoggingUtils {
|
||||||
/**
|
/**
|
||||||
* Return a string that uniquely identifies a Java object reference, in the form "classname@id", where
|
* Return a string that uniquely identifies a Java object reference, in the
|
||||||
* 'classname' is the simple (unqualified) name of the object's class, and 'id' is the hash code. If the
|
* form "classname@id", where 'classname' is the simple (package
|
||||||
* object is of an anonymous class, classname will be "<anonymous-class>".
|
* 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
|
* Why not just use obj.toString()? That method is often overriden, and so
|
||||||
* representation that uniquely identifies the object in the VM space.
|
* cannot be relied on for a representation that uniquely identifies the
|
||||||
|
* object in the VM space.
|
||||||
*
|
*
|
||||||
* @param obj
|
* @param obj
|
||||||
* the object reference to stringify
|
* the object reference to stringify
|
||||||
|
@ -36,9 +37,10 @@ public class LoggingUtils {
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
return "null"; //$NON-NLS-1$
|
return "null"; //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
String className = obj.getClass().getSimpleName();
|
String className = obj.getClass().getName();
|
||||||
if (className == null) {
|
int lastDot = className.lastIndexOf('.');
|
||||||
className = "<anonymous-class>"; //$NON-NLS-1$
|
if ((lastDot >= 0) && ((lastDot + 1) < className.length())) {
|
||||||
|
className = className.substring(lastDot + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
String id = Integer.toHexString(System.identityHashCode(obj));
|
String id = Integer.toHexString(System.identityHashCode(obj));
|
||||||
|
|
Loading…
Add table
Reference in a new issue