public class StringRepresentation extends EmptyVisitor implements Visitor
BCEL's Node classes (those from the classfile API that accept() Visitor
instances) have toString() methods that were not designed to be robust,
this gap is closed by this class.
When performing class file verification, it may be useful to output which
entity (e.g. a Code instance) is not satisfying the verifier's
constraints, but in this case it could be possible for the toString()
method to throw a RuntimeException.
A (new StringRepresentation(Node n)).toString() never throws any exception.
Note that this class also serves as a placeholder for more sophisticated message
handling in future versions of JustIce.
Returns the String representation of the Node object obj;
this is obj.toString() if it does not throw any RuntimeException,
or else it is a string derived only from obj's class name.
String ret;
try{
ret = obj.toString();
}
catch(RuntimeException e){
String s = obj.getClass().getName();
s = s.substring(s.lastIndexOf(".")+1);
ret = "<<"+s+">>";
}
return ret;