Bug 88265 - Make SourceRange API
Summary: Make SourceRange API
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 3.6 M1   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords: api
: 67140 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-03-16 18:18 EST by Dirk Baeumer CLA
Modified: 2009-07-08 08:34 EDT (History)
4 users (show)

See Also:


Attachments
Proposed fix and tests (17.10 KB, patch)
2009-06-24 06:01 EDT, Srikanth Sankaran CLA
no flags Details | Diff
Improved patch (14.14 KB, patch)
2009-07-07 04:19 EDT, Srikanth Sankaran 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 2005-03-16 18:18:07 EST
JDT/Core uses source ranges to indicate the range of elements in source. Since
most of the JDT/UI can deal with source range from IJavaElements and DOM/AST we
implemented our own source range with implements ISoureRange to not be forced to
copy source ranges retrieved from JDT/Core.

Would it be possible to allow implementation of ISourceRange ?
Comment 1 Dirk Baeumer CLA 2005-03-16 18:22:59 EST
A class SourceRange that we can extend would do the trick as well. This might be
saver since you can still change the interface then.
Comment 2 Philipe Mulet CLA 2005-04-07 08:01:49 EDT
Deferring post 3.1
Comment 3 Markus Keller CLA 2006-03-02 12:04:57 EST
*** Bug 67140 has been marked as a duplicate of this bug. ***
Comment 4 Markus Keller CLA 2007-11-22 11:26:03 EST
JDT/UI still implements this interface (illegally).

JDT/Core should provide a public class SourceRange and add a helper method to test for bug 18311 (like we do in our implementation:
    public static boolean isAvailable(ISourceRange range) {
    		return range != null && range.getOffset() != -1;
    }
)
Comment 5 Markus Keller CLA 2008-12-16 05:42:49 EST
Could you please fix this? It's one of the last API problems we have in JDT/UI.
Comment 6 Philipe Mulet CLA 2008-12-16 15:53:26 EST
Reopen for consideration.
Jerome - what do you think ?
Comment 7 Philipe Mulet CLA 2008-12-16 15:54:08 EST
Jerome - what do you think ?
Comment 8 Jerome Lanneluc CLA 2008-12-17 06:03:09 EST
That makes sense.
Comment 9 Jerome Lanneluc CLA 2009-01-09 06:36:27 EST
Not for 3.5
Comment 10 Dani Megert CLA 2009-01-29 09:24:35 EST
This should be trivial to provide. We only need the existing org.eclipse.jdt.internal.core.SourceRange as API (OK if not subclassable) plus the helper mentioned in comment 4, though I'd prefer to have a non-static isValid() (or similar) method.
Comment 11 Markus Keller CLA 2009-01-29 10:06:58 EST
> [..] though I'd prefer to have a non-static isValid() (or similar) method.

Unfortunately, the method has to be static, since invalid ranges are either null or [-1, 0] (bug 18311).

You should also mention the helper method in the Javadoc of ISourceRange (to make clients aware that e.g. ISourceRange#getOffset() can return -1).
Comment 12 Jerome Lanneluc CLA 2009-02-10 07:09:56 EST
Srikanth, can you please move SourceRange to be API (org.eclipse.jdt.core.model.SourceRange)? 

It should be tagged with @noextend and contain the static method mentioned in comment 4
Comment 13 Srikanth Sankaran CLA 2009-06-23 07:11:39 EDT
(In reply to comment #12)
> Srikanth, can you please move SourceRange to be API
> (org.eclipse.jdt.core.model.SourceRange)? 
> It should be tagged with @noextend and contain the static method mentioned in
> comment 4

comment #1 and comment#3 mention a subclassable API SourceRange, 
while comment #10 says it is OK if not subclassable.

So does comment #10, by virtue of being the latest (and there not
being any debate around it) take precedence ?
 
Comment 14 Dani Megert CLA 2009-06-23 07:59:50 EDT
Yes, at a minimum we *could* live with that but of course it would serve us much more if we were allowed to subclass (you could make your methods private and the fields protected) because otherwise we have to move the code we have in our copy into some helper and redirect the calls. So, unless you have strong objections we'd prefer to be able to subclass it.
Comment 15 Dani Megert CLA 2009-06-23 08:03:36 EDT
FYI: this is our current copy: org.eclipse.jdt.internal.corext.SourceRange
Comment 16 Srikanth Sankaran CLA 2009-06-24 06:01:25 EDT
Created attachment 139967 [details]
Proposed fix and tests

The attached patch :

    - Moves SourceRange to be API under the package
hierarchy structure org.eclipse.jdt.core.model.SourceRange
    - This is tagged with @since 3.6. 
    - SourceRange is subclassable.
    - The static helper method isAvailable(ISourceRange range)
      has been added per comment #4
    - Javadoc on ISourceRange#getOffset mentions that -1 may be
      returned.
    - Tests have been added to verify the availbility and correctness
      of the API.
Comment 17 Dani Megert CLA 2009-06-26 05:21:41 EDT
I looked at the patch from an API/client standpoint. It works for us and all our tests pass with our adjusted client code. Here some things to improve:
- do not introduce 'org.eclipse.jdt.core.model' as this is confusing since 
  all other model related types are not in this package and adding it for just one
  class is overkill ==> put it into 'org.eclipse.jdt.core'
- make the fields private (we don't need to access them and it makes the class 
  safer if it can't be modified after creation)
- the formatting of SourceRange seems odd: the method declarations start at 
  column 1 instead of being indented
- there is no Javadoc comment for the type
- the Javadoc comment for isAvailable(...) should mention why this method is
  needed at all (link to bug 130161)
- copyright is wrong, it should be 2009 or otherwise mention in the Javadoc that
  it existed before but in another package
Comment 18 Srikanth Sankaran CLA 2009-07-07 04:19:44 EDT
Created attachment 140936 [details]
Improved patch
Comment 19 Srikanth Sankaran CLA 2009-07-08 02:31:35 EDT
Released in HEAD for 3.6M1
Comment 20 Dani Megert CLA 2009-07-08 08:34:28 EDT
Verified in HEAD and adopted the API in JDT Text and JDT UI.