Simplifying fully qualified names in Eclipse
Asked Answered
C

2

8

Does someone know a plugin for Eclipse that replaces fully qualified Java class names with the simple one and the corresponding import where possible? It would be even better if it could be performed as a Save Action.

Credulous answered 15/4, 2010 at 10:26 Comment(1)
According to bugs.eclipse.org/bugs/show_bug.cgi?id=112999, this is a pending enhancement request. Please vote for it. :) But still would be good to have it as a plugin...Credulous
C
2

Here's a plugin offering this functionality called Clean Qualified Types Plugin (CQTP): http://blog.mi-ernst.de/projekte/

Credulous answered 11/12, 2013 at 23:34 Comment(2)
How can you set it to preserve comments too?Yevetteyew
Need to use rewrite instead of toString after the clean. :)Yevetteyew
L
17

No. But you can use Add Import command (Ctrl+Shift+M) on each fully qualified identifier to convert it to an import + a short name.

Lockup answered 15/4, 2010 at 10:45 Comment(6)
+1 - I didn't either. But that's a one by one method. I would like to do it for whole source file(s) and at save if possible.Credulous
I asked last year about doing this with static imports and received no positive answers: #824511Sulph
FYI...at least on a Mac you need to put the cursor on the Type (not the path)Mar
I recently did some work in IntelliJ where doing this action resulted in all occurrences being replaced.Sulph
That's better than nothing. Thanks! However, I wish it also worked in block selects. :( It appears you really do have to do this one at a time.Disinterested
If you use maven it is trivially simple to work with your project in all the major Java ide'sSulph
C
2

Here's a plugin offering this functionality called Clean Qualified Types Plugin (CQTP): http://blog.mi-ernst.de/projekte/

Credulous answered 11/12, 2013 at 23:34 Comment(2)
How can you set it to preserve comments too?Yevetteyew
Need to use rewrite instead of toString after the clean. :)Yevetteyew

© 2022 - 2024 — McMap. All rights reserved.