Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » How to recognize implicit toString call?
How to recognize implicit toString call? [message #1783476] Tue, 13 March 2018 13:58 Go to next message
Sergey Toshin is currently offline Sergey ToshinFriend
Messages: 50
Registered: May 2015
Member
Hi, let's assume that I have the following code:

Uri uri = smth;
String s = "Uri is " + uri;

In this case line
String s = "Uri is " + uri;
means
String s = "Uri is " + uri.toString();

How do I recognize that I should call toString in the first example? resolveTypeBinding() for "uri" returns "... .Uri", but not "java.lang.String"

[Updated on: Tue, 13 March 2018 14:00]

Report message to a moderator

Re: How to recognize implicit toString call? [message #1783675 is a reply to message #1783476] Thu, 15 March 2018 13:05 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1650
Registered: July 2009
Senior Member
Are you asking about how a *tool* can recognize this situation?
Just look for a binary expression with operator "+", where the type of the overall expression is String.
Then if the right operand is not already a String, an invocation to StringBuilder.append(Object) will be generated, which internally may use toString().
Re: How to recognize implicit toString call? [message #1783683 is a reply to message #1783675] Thu, 15 March 2018 14:07 Go to previous messageGo to next message
Sergey Toshin is currently offline Sergey ToshinFriend
Messages: 50
Registered: May 2015
Member
Thanks, I was doing the same thing, but considered that I'm missing something, and there is a flag

[Updated on: Thu, 15 March 2018 14:08]

Report message to a moderator

Re: How to recognize implicit toString call? [message #1783684 is a reply to message #1783683] Thu, 15 March 2018 14:10 Go to previous message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1650
Registered: July 2009
Senior Member
Internally, the compiler has conversion flags like org.eclipse.jdt.internal.compiler.lookup.TypeIds.Object2String, but those are not exposed in the public AST/bindings.
Previous Topic:internal vs non-internal CompilationUnits
Next Topic:java.lang.NullPointerException LazyStackRenderer.showElementRecursive when changing perspectives
Goto Forum:
  


Current Time: Wed Nov 14 05:19:44 GMT 2018

Powered by FUDForum. Page generated in 0.02692 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top