Bug 195810 - Unnecessary call of TypeReference#isValidBinding()
Summary: Unnecessary call of TypeReference#isValidBinding()
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Ayushman Jain CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2007-07-09 07:04 EDT by David Audel CLA
Modified: 2022-10-16 15:19 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Audel CLA 2007-07-09 07:04:37 EDT
from Stephan Herrmann inside bug 191125 comment 10

Browsing through all implementations and clients of
  TypeReference.resolveType() (both overloaded versions), 
  it is clear that this method only has two possible returns:
  null or a valid TypeBinding.

For one implementation this policy is not easy to validate:
+ ParameterizedQualifiedTypeReference.internalResolveType()
  The data flow for the final return is non-trivial.
  Might be interesting to actually analyze.

3 clients actually use a (unnecessary) check isValidBinding()
on the result of resolveType():
+ ThrowStatement.resolve()
+ ASTNode.resolveDeprecatedAnnotations() 
+ CompletionEngine.proposeType()
(all classes from ...compiler.ast)

Here's my suggestion: isn't this kind of policy (null or valid)
worth documenting?
IMHO that would facility maintenance and extension.
The unnecessary checks don't hurt for the functionality, but they
tend to confuse people trying to understand the code (like me): 
a good monkey will copy this kind of code and sooner or later 
nobody will remember the original policy.
Just my 2c.
Comment 1 Olivier Thomann CLA 2010-07-28 09:40:12 EDT
Ayushman, please see what you can do.
Remember that now we should have missing type bindings.
Comment 2 Ayushman Jain CLA 2010-09-13 05:27:30 EDT
Although it does seem safe to assume that the current implementations of TypeReference.resolveType() , including ParameterizedQualifiedTypeReference.internalResolveType(), either return null or a valid binding, I was wondering if its actually a could idea to document it in TypeReference.resolveType(). What if in the future we do want to have an implementation that returns a problem binding(or change an existing implementation to do so)? To an implementor, a documented contract saying that either null or valid binding is returned, will be a roadbloack in that case. What I mean is, even if we agree that its a trend being followed by implementors currently, we cant guarantee that it'll always be the case. It wouldve made more sense if such a contract was being followed by all implementors of Expression.resolveType(), but I dont think thats the case here.

Anyhow, I have limited experience in the area of API and documentation, and it'll be good to have your opinions as well. :)

Also, a clarification re comment 1:
ThrowStatement.resolve() checks for isValidBinding() on the result of Expression.resolveType() and not TypeReference.resolveType()
Comment 3 Eclipse Genie CLA 2020-07-07 17:46:48 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 4 Eclipse Genie CLA 2022-10-16 15:19:23 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.