Community
Participate
Working Groups
Build ID: I20070621-1340 Steps To Reproduce: There should be a quick assist on constants and methods for converting them to a static import. e.g. Math.min(1, 2); Ctrl-1 on "min" will have an entry 'Convert to static import' which will replace the code with: import static java.lang.Math.min; [...] min(1, 2); Where the static import might also become java.lang.Math.* based on the preferences for imports. I'm constantly surprised that this isn't available when I try to use it, so I guess it's time to report it.
This already exists: Add Import (CTRL + M) on the static method/field name. But you're right, it would make sense as a quick assist.
Oooh... Add Import on static methods is delicious! We all love you. It's Ctrl-Shift-M by the way.
It will be also better if we have other way to change all calls of certain static method/static field to use this import static. For example: package bug.a; public class A { public static void bbb() { } } package bug; import bug.a.A; public class B { public B() { A.bbb(); A.bbb(); } } Currently if we do 'Add Import' in the first A.bbb() it will change the class B to: package bug; import static bug.a.A.bbb; import bug.a.A; public class B { public B() { bbb(); A.bbb(); } } But I want: package bug; import static bug.a.A.bbb; public class B { public B() { bbb(); bbb(); } }
I'm using eclipse Juno and this is still an open issue. Also, I noticed the add import only fixes the import you are on and not any similar import. A quick fix option should fix all of them. So if you ctrl+1 on Math.sin(...), it should add the static import and then replace all Math.sin occurrences with sin. I frankly don't see why you would want to fix only one occurrence and the current behavior seems wrong.
*** Bug 478840 has been marked as a duplicate of this bug. ***
New Gerrit change created: https://git.eclipse.org/r/59590
I just pushed a patch which allows to quick assist "import static" on fields and method invocations.
I just wanted to check back and see if somebody did have a look at the patch? Or if I need to make any changes.
The patch provides a quick assist that performs the conversion to static import only at the invocation location. It does not convert all occurrences of that method/field in the compilation unit, as discussed in this bug. This can be added as another quick assist with suffix message "(replace all occurrences)". Some comments on patch set 4: - Do not include whitespace changes in the patch. - Update copyright year in files. - Combine the two methods added in QuickAssistProcessor to keep a single method for converting to static imports. - Make sure import statement is not added for private members and when the static member is directly accessible from the invoking location. See bug 409594 for such scenarios. - Refer AddImportsOperation#evaluateEdits method and make sure to cover all the applicable scenarios handled there.
I just pushed patch set #6 which should solve those issues. Sorry for the white spaces, it was pretty hard finding a code formatter setting that worked. The copyright was changed to 2016. Now that I made some changes in 2016, that actually makes sense. The two methods are merged. I am not sure this is more readable, but it is done. I also did take over the "directly accessible" check from "AddImportsOperation#evaluateEdits".
I just had a look at the Hudson jobs triggered by Gerrit [1], [2]. I have no idea what is wrong here. Two times, two different errors. The first one seems to have some issued with X11 and the second one fails at a total different location. On my local machine the test cases run fine. Is there a way to re-run those jobs? [1] https://hudson.eclipse.org/platform/job/eclipse.jdt.ui-Gerrit/540/ [2] https://hudson.eclipse.org/platform/job/eclipse.jdt.ui-Gerrit/542/
(In reply to Jens Reimann from comment #11) > Is there a way to re-run those jobs? > > [1] https://hudson.eclipse.org/platform/job/eclipse.jdt.ui-Gerrit/540/ > [2] https://hudson.eclipse.org/platform/job/eclipse.jdt.ui-Gerrit/542/ I've retriggered both.
Ok, thanks. Patch #7 is Verified +1 now.
(In reply to Jens Reimann from comment #10) > I just pushed patch set #6 which should solve those issues. The latest patch set does not work in the following cases: package p1; public class S { { T.<String>doIt(""); // Invoke at: do|It System.out.println(T.str); // Invoke at S|ystem and T|.str - should not be available at Type. } } class T { static String str; static <V> void doIt(V o) {} } Other comments: - Change the name of the quick assist to: "Convert to static import" and update the associated constants in code. - Add new test cases in AssistQuickFixTest.java. (In reply to Noopur Gupta from comment #9) > The patch provides a quick assist that performs the conversion to static > import only at the invocation location. It does not convert all occurrences > of that method/field in the compilation unit, as discussed in this bug. This > can be added as another quick assist with suffix message "(replace all > occurrences)". As discussed in the bug, it would be useful if this quick assist converts all occurrences in the compilation unit at the same time. Please add another quick assist for that as mentioned in the above comment.
@Jens Reimann: will you have time to update based on comment:14, or may I take over from where you left and update the patchset/create a new one based on it?
(In reply to Robert Roth from comment #15) > @Jens Reimann: will you have time to update based on comment:14, or may I > take over from where you left and update the patchset/create a new one based > on it? Not at the moment. I would be glad if you do so.
*** Bug 502847 has been marked as a duplicate of this bug. ***
*** Bug 507111 has been marked as a duplicate of this bug. ***
I've submitted a new changeset because I can't work on the existing changeset. The issues that you had mentioned should be fixed and I've added a second quickfix that replaces all occurrences. The change can be found here: https://git.eclipse.org/r/#/c/113254/
New Gerrit change created: https://git.eclipse.org/r/113254
Noopur, I removed your - as Sarika is working on the code review.
Created Bug 536235 to handle adding of new quick assists to use the static imports also.
Gerrit change https://git.eclipse.org/r/113254 was merged to [master]. Commit: http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=182a1609f5d754dfb8873f8e2f6d3fc1dd560a6b
Thanks Fabian!!
Fabian, please add to N&N for 4.9
Eclipse SDK Version: 4.9 Build id: I20180731-2000
(In reply to Lars Vogel from comment #25) > Fabian, please add to N&N for 4.9 Ping
(In reply to Lars Vogel from comment #27) > (In reply to Lars Vogel from comment #25) > > Fabian, please add to N&N for 4.9 > > Ping I already created a change in Gerrit for that. And it got merged. So it guess there is nothing to be done here.
(In reply to Jens Reimann from comment #28) > (In reply to Lars Vogel from comment #27) > > (In reply to Lars Vogel from comment #25) > > > Fabian, please add to N&N for 4.9 > > > > Ping > > I already created a change in Gerrit for that. And it got merged. So it > guess there is nothing to be done here. Please ignore my last comment. Wrong issue, similar subject.
Ping!!! @Fabian please add a N&N.
New Gerrit change created: https://git.eclipse.org/r/127873
Gerrit change https://git.eclipse.org/r/127873 was merged to [master]. Commit: http://git.eclipse.org/c/www.eclipse.org/eclipse/news.git/commit/?id=9b5a18751276ae4967468e09801a32f264f769b3