Community
Participate
Working Groups
I20060718-0800 package xy; import java. lang. Object; public class Try { } Select import declaration in Outline -> expected: selects "java. lang. Object" or whole line in editor -> was: selects "import java. lan" in editor Reason: indexOf(..) does not work in JavaEditor.setSelection(.., ..): String name= ((IImportDeclaration) reference).getElementName(); if (name != null && name.length() > 0) { String content= reference.getSource(); if (content != null) { offset= range.getOffset() + content.indexOf(name); length= name.length(); } }
This is ugly for us to parse. Can JDT Core give is getElementRange() (like we have for ILocalVariable and others) for this? other cases: import java.lang.Math; import java.lang.Math ; And of course a mix of all those cases.
>Can JDT Core give is getElementRange() It should of course be "getNameRange()". NOTE: as of now you can no longer reproduce this since I improved our heuristics.
The same problem appears for IPackageDeclarations, which are also missing a getNameRange().
So basically you want getNameRange() for IPackageDeclaration and IImportDeclaration. None of them are actually IMember where the method getNameRange() is defined. So you just want the getNameRange() method to be added for these two types ?
>So basically you want getNameRange() for IPackageDeclaration and >IImportDeclaration. Yes.
Do you expect the import declaration on demand to include the '*' in its name source range ?
Created attachment 175364 [details] Proposed fix + regression tests
This patch doesn't include the trailing '*' as part of the name for on demand imports. This can be done, but we need to store an extra position to do so. It could also be patched at the UI side if needed.
>This patch doesn't include the trailing '*' as part of the name for on demand >imports. You mean it ends with (or before) the '.'? Since we need the API to select the whole declaration I would expect to get the '*' as well. If that's not the case then the new API still forces us to scan the code and hence we wouldn't spend time to adopt it.
(In reply to comment #9) > You mean it ends with (or before) the '.'? Since we need the API to select the > whole declaration I would expect to get the '*' as well. If that's not the case > then the new API still forces us to scan the code and hence we wouldn't spend > time to adopt it. This is all I wanted to know. If you need the '*' as part of the name source range, I'll add it. Thanks.
Thanks! ;-)
Created attachment 175422 [details] Proposed fix + regression tests New patch that includes the trailing '*' as part of the import on demand name range.
Created attachment 175423 [details] Adoption of the new API in the JavaEditor This patch enables the new API in the java editor and makes it possible to select the proper source code from the outline view when selecting an import declaration or a package declaration with spaces inside the name. Markys, let me know what you think.
Released for 3.7M1. Added regression tests in: org.eclipse.jdt.core.tests.model.GetSourceTests#testNameRange09 org.eclipse.jdt.core.tests.model.GetSourceTests#testNameRange10 org.eclipse.jdt.core.tests.model.GetSourceTests#testNameRange11
Thanks for the patch. Committed to HEAD. Olivier, when you now look at the code in JavaEditor you see the huge if-then-else clause. Maybe we could add it to ISourceRange. I think the only deal breaker for that would be the import container. Otherwise we might want to add a new interface. What do you think?
(In reply to comment #15) > Maybe we could add it to ISourceRange. I guess you meant ISourceReference. That would mean that getNameRange() has to be added to IImportContainer and ITypeRoot. We could just say it returns null in those types.
>I guess you meant ISourceReference. Yep, of course.
We could do that post M1. I don't want to change this now.
Opened bug 321764 to take care of this.
Verified for 3.7M1 using build I20100802-1800
>We could do that post M1. I don't want to change this now. Yes, of course.