Find implicit toString() invocations

Hi all,

Is there a reliable way to find all common usages, where object references will be converted to strings?

Example:

final StringBuffer buffer = ...
...
buffer.append(foo);

or

final String text = foo + ":";

Tom

3 comments


Currently, there's an IG inspection for all places where a non-overridden .toString() method is called, either implicitly or explicitly. It would be pretty trivial to create an inspectin that simply found all implicit .toString() calls. Possibly someone better than I am with SSR could come up with a solution there, but I kind of doubt it.

What's the use case?

--Dave Griffith

0

What's the use case?


We have a class, which overrides the toString() method to give debug output (as usual). Another method toUIString() returns the string, which should be displayed. Unfortunately there are some UI messages like +"foo " + foo + " bar"+ scattered over the application and we like to find them.

For us it would also help, if the inspection would also warn for overriden toString() calls, because we don't use it intentionally except for debug output.

Tom

0

Sounds like what you actually need is to have findUsages on toString() for a given class find all of the implicit as well as explicit usages. This is certainly worth a JIRA request, along with finding other "implicit" method calls (implicit constructor calls, iterator() in for-each loops, readObject()/writeObject(), did I miss any?)

--Dave Griffith

0

Please sign in to leave a comment.