Bug 43587 - Searching for references to default constructors reports questionable results
Summary: Searching for references to default constructors reports questionable results
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M2   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-09-24 11:58 EDT by Dirk Baeumer CLA
Modified: 2004-09-23 12:14 EDT (History)
2 users (show)

See Also:


Attachments
Proposed implementation for additional implicit info (10.07 KB, patch)
2004-07-13 10:16 EDT, Frederic Fusier CLA
no flags Details | Diff
UI is now able to distinguish implict constructor calls... (33.96 KB, image/gif)
2004-07-13 10:21 EDT, Frederic Fusier CLA
no flags Details
Other proposal: without new match class but using existing one (12.59 KB, patch)
2004-07-15 12:23 EDT, Frederic Fusier CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dirk Baeumer CLA 2003-09-24 11:58:08 EDT
 
Comment 1 Dirk Baeumer CLA 2003-09-24 12:04:25 EDT
As discussed in PR 43276 searching for declaration of a default constructor 
should report no matches, which is the case. If I search for all occurrences 
it seems that declarations are reported as well. Consider the following 
example:

package p;

class A{
}
class B extends A {
}

Searching for p.A() limited to "All occurrences" reports a match on class A 
and class B which is not correct.

- A neither declares a default constuctor nor does it reference one
- B only implicit reference constructor A() through its implicit constructor.
  Folloing the arguments in PR 43276 this shouldn't reported either.

This results in a lot of work arounds in refactoring. Can you please comment 
on this semantic.
Comment 2 Philipe Mulet CLA 2003-09-24 12:08:55 EDT
To be consistent, I agree we should not find them (or find them as well when 
searching for sole declarations).

Comment 3 Philipe Mulet CLA 2003-09-24 12:10:48 EDT
I suspect the constructor locator gets fooled in all-occurrences mode due to 
the fact it is considering types & constructors for reference search, but then 
matches them as declarations as well where it shouldn't for default 
constructors.
Comment 4 Dirk Baeumer CLA 2003-09-24 12:42:13 EDT
If we find them all refactoring somehow needs an indication that they don't 
exist in source (e.g the are syntetic). Otherwise we have to build an AST 
again to check if the match has a representation in source.
Comment 5 Kent Johnson CLA 2003-09-24 13:10:05 EDT
This only occurs when the 2 types are in the same compilation unit since we 
keep track of possible matches per unit.

Fixed so that references & all occurrences both find the single match, while 
declarations finds no matches.
Comment 6 Dirk Baeumer CLA 2003-09-24 13:16:08 EDT
Kent, which match is reported when searching for references ? If the match is 
reported on "class B" then refactoring somehow needs an easy way to figure out 
that this isn't a "real" match (easy means without parsing the source again).
Comment 7 Kent Johnson CLA 2003-09-24 14:09:25 EDT
Backup...

We have always reported the explicit reference.

Do you not want it anymore?
Comment 8 Philipe Mulet CLA 2003-09-24 17:13:35 EDT
This defect was a consistency problem in between all-occurrence and 
declarations. We should find these references as we used to (would be a 
breaking change if not).

Refactoring is only one particular use case. Furthermore, I could imagine 
situations where refactoring would need to turn an implicit constructor 
references into explicit ones (i.e. when adding a parameter to a superclass 
constructor which had no param before, the subtypes need to be fixed up).
Comment 9 Dirk Baeumer CLA 2003-09-25 04:25:58 EDT
But without any hint that the match is for a syntetic default constructor 
refactoring doesn't know what to do with the match. So currently we simply 
implement our own constructor reference finder using ASTs which IMO is 
somehow "stupid". 

What is your suggestion to distinguish between these two different kind of 
references.
Comment 10 Dirk Baeumer CLA 2003-09-29 17:19:11 EDT
Reopening

I discussed this issue with Philippe on the phone and we agreed that 
refactoring should not implement their own search engine to work around this 
problem. Philippe suggested that we could extend the limitTo flag to specify 
if we want references to syntetic default constructors included in the result 
set. This doesn't break current clients and would allow refactoring to remove 
their work around code.
Comment 11 Philipe Mulet CLA 2003-09-29 18:17:31 EDT
To be accurate, I claimed that the new search API would offer a mean to provide 
access to synthetic constructor declaration/reference at the best. The limitTo 
flag would not be an option for now (changing a soon obsolete API).
Comment 12 Dirk Baeumer CLA 2003-09-30 03:42:25 EDT
Correct, we agreed on considering this in the new search API only.
Comment 13 Philipe Mulet CLA 2004-05-10 13:13:04 EDT
Post 3.0
Comment 14 Jerome Lanneluc CLA 2004-07-06 05:12:56 EDT
Reopening
Comment 15 Dirk Baeumer CLA 2004-07-07 07:11:52 EDT
While converting to the new AST I again stumble over your nasty workaround 
code to handle this.

Now that we have the new search engine couldn't we simple annotate the match 
object with information that it is an "implicit" constructor reference (e.g. 
there isn't any representation in code). Then refactoring could skip these. 
Currently we are building an AST to figure out if the have to consider the 
reference or not.
Comment 16 Dirk Baeumer CLA 2004-07-07 07:12:26 EDT
Should read sumbled of OUR nasty workaround...
Comment 17 Frederic Fusier CLA 2004-07-08 06:11:03 EDT
Using 3.0 or HEAD, I now only find implicit reference constructor on B (which is
different than results described in comment 1).
Dirk, may you confirm this new behavior?
Thx
Comment 18 Dirk Baeumer CLA 2004-07-08 06:24:00 EDT
I get the same behaviour.

As outlined the fix shouldn't be to remove these matches (since this would be 
breaking). We should enrich the match object with additional state telling 
that the match is implicit.
Comment 19 Frederic Fusier CLA 2004-07-13 10:16:52 EDT
Created attachment 13195 [details]
Proposed implementation for additional implicit info

Summary of this patch is:
- Add a new specific match for constructor (ConstructorReferenceMatch) which
will provide whether the found reference is on a synthetic constructor or not
(API: isSynthetic()).
- Returns this kind of match with isSynthetic field set instead of
TypeDeclarationMatch when reference was found on a constructor.
Comment 20 Frederic Fusier CLA 2004-07-13 10:21:37 EDT
Created attachment 13196 [details]
UI is now able to distinguish implict constructor calls...

With this patch (and some changes in JDT/UI), I was able to mark implicit
constructors calls as potential matches...
Comment 21 Frederic Fusier CLA 2004-07-15 12:23:57 EDT
Created attachment 13307 [details]
Other proposal: without new match class but using existing one

This second patch is an alternative to avoid creation of a match class
ConstructorReferenceMatch. Instead, we use existing MethodReferenceMatch on
which we add two additional information: isConstructor and isSynthetic...

Of course this impact client code which should change the cast to get these
extra information. We strongly prefer the second one as it is similar to
bindings structure...

Dirk, let me know if this second solution fit your need and I'll release it in
HEAD.
Comment 22 Dirk Baeumer CLA 2004-07-19 10:47:28 EDT
The second patch is OK for me. As far as I understand it the patch will not 
impact existing code (since the dealt with Methode refs as well). And we don't 
have a special type in Java Model for constructors either.
Comment 23 Frederic Fusier CLA 2004-07-20 11:44:06 EDT
Fixed using second patch has been released in HEAD.

Dirk, you're assumption is correct as this implementation does not impact
existing code (all JDT/UI tests pass).

[jdt-core-internal]
Test case testContructorReference10 added to JavaSearchTest.
Comment 24 David Audel CLA 2004-09-23 12:14:45 EDT
Verified in I200409230100.