Bug 248878 - [search] Odd API in ReferenceMatch
Summary: [search] Odd API in ReferenceMatch
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.5 M6   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords: api
Depends on:
Blocks:
 
Reported: 2008-09-28 16:10 EDT by Markus Keller CLA
Modified: 2009-03-10 08:46 EDT (History)
3 users (show)

See Also:
frederic_fusier: review? (jerome_lanneluc)


Attachments
Proposed patch (15.85 KB, patch)
2009-02-18 07:36 EST, Frederic Fusier CLA
no flags Details | Diff
New proposed patch (16.02 KB, patch)
2009-02-18 10:22 EST, Frederic Fusier CLA
jerome_lanneluc: review+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2008-09-28 16:10:12 EDT
Follow-up to bug 247618

- org.eclipse.jdt.core.search.ReferenceMatch says:
 * This class is not intended to be subclassed by clients.

=> So shouldn't this class get an @noextend tag and be considered like an internal class now? Which leads us back to field 1 ... with respect to internal superclasses.

The dances you introduced with bug 209996 to make setLocalElement(..) inaccessible are striking back again (as I predicted)-: .

The protected method ReferenceMatch#localElement() makes little sense (at least after InternalSearchMatch has gone). You should remove localElement() and make getLocalElement() non-final.

Or should clients not reimplement localElement()? Then you would have to document this. But if yes, can you then explain how clients of MethodReferenceMatch (which is explicitly intended to be instantiated and subclassed by clients) can create objects of this subclass whose getLocalElement() returns a non-null value?

Sorry that I sound a little harsh, but I hate messy APIs, and this one is definitely not yet as clean as it could and should be.
Comment 1 Jerome Lanneluc CLA 2008-09-29 04:44:09 EDT
I don't think @noextend means it is internal. API tooling still allows a public class to extend a @noextend class. Darin, am I correct?
Comment 2 Darin Wright CLA 2008-09-29 10:32:26 EDT
@noextend means the class is not intended to be extended outside of the bundle it is defined in. There may be subclasses within the same bundle, and clients may be allowed to instantiate it (unless @noinstantiate), or use instances of it produced by the framework.
Comment 3 Markus Keller CLA 2008-09-29 11:12:39 EDT
The question is whether it's a good idea to have a hierarchy:

SearchMatch - intended to be instantiated and subclassed
+ ReferenceMatch - @noextend
  + MethodReferenceMatch - intended to be instantiated and subclassed

... and a protected method localElement() in ReferenceMatch.

Does that mean that subclasses of MethodReferenceMatch can freely call and override localElement()? If yes, then the method makes little sense. If no, shouldn't API tooling flag such usages of a protected method from an @noextend class, since only subclasses can use that method?
Comment 4 Darin Wright CLA 2008-09-29 13:01:53 EDT
The contract is up to the provider... Whether methods from the superclass can/are intended to be overridden is up to the provider. Methods should be marked as final or @nooverride if they are not intended to be overridden.

This is similar to the argument of allowing @noimplement interfaces to be extended and implemented - the contract is up to the provider...
Comment 5 Jerome Lanneluc CLA 2008-09-30 04:15:32 EDT
Thanks Darin. Agreed that localElement() should then be marked with @nooverride and @noreference, or we should get rid of it.
Comment 6 Frederic Fusier CLA 2009-02-18 04:24:11 EST
(In reply to comment #5)
> Agreed that localElement() should then be marked with @nooverride
> and @noreference
> 
Released for 3.5M6 in HEAD stream.
Comment 7 Markus Keller CLA 2009-02-18 05:46:22 EST
Sorry, I have to reopen this. None of the issues of comment 0 have been resolved.

> Or should clients not reimplement localElement()? Then you would have to
> document this.

ReferenceMatch#localElement() is now hidden from clients, but this does not resolve the problems, as I outlined:

> But if yes, can you then explain how clients of
> MethodReferenceMatch (which is explicitly intended to be instantiated and
> subclassed by clients) can create objects of this subclass whose
> getLocalElement() returns a non-null value?

We either need a setLocalElement(..) method, or all subclasses of ReferenceMatch need a new constructor that also takes a local element.

I still vote for the simplest solution (like e.g. for SearchMatch.insideDocComment).
Comment 8 Frederic Fusier CLA 2009-02-18 06:01:11 EST
(In reply to comment #7)
> 
> I still vote for the simplest solution (like e.g. for
> SearchMatch.insideDocComment).
> 
If I have well understood, your vote would be:
1) make getLocalElement() non-final
2) remove localElement()
3) add setLocalElement(Object) on ReferenceMatch
4) also add a new constructor on ReferenceMatch and it subclasses with an 
   additional argument for the local element
  (or maybe the setLocalElement(Object) would be enough?)
Comment 9 Frederic Fusier CLA 2009-02-18 07:36:07 EST
Created attachment 126015 [details]
Proposed patch

Does it look better?

This patch implements 1-3) but does not add any new constructor as I think there's already enough arguments to existing one...
Comment 10 Markus Keller CLA 2009-02-18 09:51:13 EST
> Created an attachment (id=126015) [details]
> Proposed patch
> 
> Does it look better?

Yes, looks great, except for the Javadoc of ReferenceMatch, which still says "[..] not intended to be subclassed [..]", but has no @noextend. I would remove the restriction (otherwise, there would be an "internal" superclass in the hierarchy again).

> This patch implements 1-3) but does not add any new constructor as I think
> there's already enough arguments to existing one...

I fully agree.
Comment 11 Frederic Fusier CLA 2009-02-18 10:22:45 EST
Created attachment 126029 [details]
New proposed patch

Same patch + remove "This class cannot be subclassed by clients..." in ReferenceMatch class javadoc.
Comment 12 Frederic Fusier CLA 2009-02-18 10:23:28 EST
Jerome, could let me know if you agree with this proposal?
TIA
Comment 13 Jerome Lanneluc CLA 2009-02-23 09:46:16 EST
Comment on attachment 126029 [details]
New proposed patch

Agreed
Comment 14 Frederic Fusier CLA 2009-02-23 12:41:45 EST
(In reply to comment #11)
> Created an attachment (id=126029) [details]
> New proposed patch
> 
Released for 3.5M6 in HEAD stream.
Comment 15 David Audel CLA 2009-03-10 08:46:30 EDT
Verified for 3.5M6