Author Topic: Java Annotations, import static, and Organize imports  (Read 6817 times)

Tree

  • Community Member
  • Posts: 71
  • Hero Points: 2
Java Annotations, import static, and Organize imports
« on: July 12, 2007, 03:34:55 pm »
Does Organize Imports work with either Java annotations or static imports?

It appears not to... using "organize imports" on a file using annotations or import static appears to REMOVE the related import lines.

(using 12.0.2.0)

Ryan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 987
  • Hero Points: 77
Re: Java Annotations, import static, and Organize imports
« Reply #1 on: July 12, 2007, 08:12:38 pm »
Organize Imports is written to ignore static imports...it should not be deleting any of these imports, it should just be leaving them alone.  I tested this out in 12.0.2, and it seems to be working ok.

You have an example of a file where Organize Imports is deleting your static imports?  Can you post the file here, or alternatively, send it into support@slickedit.com (and reference my name and this thread)?  I'll have a look.

- Ryan

Tree

  • Community Member
  • Posts: 71
  • Hero Points: 2
Re: Java Annotations, import static, and Organize imports
« Reply #2 on: July 12, 2007, 08:33:47 pm »
Yep. This file. This also demonstrates the annotation breakage.
<<<
package foo;

import static org.junit.Assert.*;
import org.junit.Test;

public class ImportTest
{

    @Test
    public void testFoo()
    throws Exception {
       
    }


}
>>>


Ryan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 987
  • Hero Points: 77
Re: Java Annotations, import static, and Organize imports
« Reply #3 on: July 13, 2007, 01:45:16 pm »
Backup your copy of jrefactor.e (/path/to/slickedit/macros/jrefactor.e), and save the attached version to this same directory.  Then load it via Macro > Load Module...this should fix it.

We also treat .* imports differently, and this was messing with the static import.

- Ryan

Tree

  • Community Member
  • Posts: 71
  • Hero Points: 2
Re: Java Annotations, import static, and Organize imports
« Reply #4 on: July 13, 2007, 02:46:54 pm »
That appears to handle the import static correctly, but not the annotation.

I think that this use case, which is essentially the boilerplate recommendation for junit tests, is very likely the most common initial exposure to java annotations *and* java static imports for users.

Now, oddly, if I put my cursor on the "@Test" and do a push-ref, it pops up a list that includes annotation *usage* and the correct annotation definition, along with other class definitions. But, if I instead get to "add import for Test" it brings up a list of only non-annotation classes. It seems like tagging support for annotations is not complete...

Ryan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 987
  • Hero Points: 77
Re: Java Annotations, import static, and Organize imports
« Reply #5 on: July 13, 2007, 07:15:24 pm »
Ahh, yes...the annotation case.  I have modified jrefactor.e (see attachment) to support annotations and annotation type definitions for Organize Imports... and Add Import.  It doesn't look like these features were ever updated as annotations were added to Java...the tagging information is there, though.

Let me know how this works for you.

- Ryan

Tree

  • Community Member
  • Posts: 71
  • Hero Points: 2
Re: Java Annotations, import static, and Organize imports
« Reply #6 on: July 13, 2007, 07:27:54 pm »
That... is simply beautiful!

I suspect this would be quite useful to other java developers... ;)

Tree

  • Community Member
  • Posts: 71
  • Hero Points: 2
Re: Java Annotations, import static, and Organize imports
« Reply #7 on: December 07, 2007, 08:27:14 pm »
So, I've started using code that uses Java Enums, and they are similarly broken for imports.

Worse, SlickEdit is actually removing existing imports of Enums, not just being unable to add them.

push-tag and push-ref both work correctly, as does the symbol browser, so it is specifically the refactoring logic that doesn't handle them.

Thanks in advance...

Ryan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 987
  • Hero Points: 77
Re: Java Annotations, import static, and Organize imports
« Reply #8 on: December 07, 2007, 11:00:53 pm »
A hotfix at 5:57 PM on a Friday?  Unheard of...

New jrefactor.e is attached, same drill as above...let me know if you are still having issues with Enums (or anything else Organize Imports-related).  I'll add this to the hotfix soon.

- Ryan

Tree

  • Community Member
  • Posts: 71
  • Hero Points: 2
Re: Java Annotations, import static, and Organize imports
« Reply #9 on: December 07, 2007, 11:12:01 pm »
Works great!

(as usual) ;)


windowe

  • Community Member
  • Posts: 5
  • Hero Points: 0
Re: Java Annotations, import static, and Organize imports
« Reply #10 on: December 19, 2007, 06:57:03 pm »
I tried this on version 11.0.2, and it didn't work.  My static imports still vanish.

1) backed up existing file
2) copied new one in place
3) did Macros -> Load Module
4) tried it
5) did it again

Any ideas?

Ryan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 987
  • Hero Points: 77
Re: Java Annotations, import static, and Organize imports
« Reply #11 on: December 19, 2007, 07:01:39 pm »
First off...when you did Load Module, did it load successfully? This macro file is for 12.0.x...

windowe

  • Community Member
  • Posts: 5
  • Hero Points: 0
Re: Java Annotations, import static, and Organize imports
« Reply #12 on: December 19, 2007, 07:04:03 pm »
it did appear to load successfully, and the organize imports still works like it did before.  it didn't give me any errors on the load.

windowe

  • Community Member
  • Posts: 5
  • Hero Points: 0
Re: Java Annotations, import static, and Organize imports
« Reply #13 on: December 19, 2007, 07:07:56 pm »
I just unloaded it, deleted the .ex, and reloaded it.  still works like before.

I know it's for 12, I just thought I'd try it.

I had a yearly renewal for years, that expired Jan 1st of 2007, and now' the first time I actually really, really, really need a fix.

LOL

Ryan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 987
  • Hero Points: 77
Re: Java Annotations, import static, and Organize imports
« Reply #14 on: December 19, 2007, 07:10:34 pm »
I would double check that you are loading the right jrefactor.e correctly.  I just tested this in my 11.0.2:

1) Saved the jrefactor.e attached here to my Desktop.
2) Opened 11.0.2 with a Java project.
3) Confirmed that Organize Imports would nuke a static import.
4) Open the new jrefactor.e, and loaded it via F12.
5) Re-ran Organize Imports, and it didn't nuke my static import.