Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse: Is there a way to force an import in Organize Import to solve an ambiguity?

Tags:

java

eclipse

I'm using Eclipse on an android project. I updated to Lion and problems began to appear... Trying stuff for hours, no results.

Here is the problem:

I have dozens of files com.stuff.morestuff in my project. I would like to crtl+shift+O my project so every import are resolved. But, on each file, eclipse ask me to resolve ambiguities.

Therefore, I would like to impose to eclipse to choose the first choice.

Some clues

1 - I tried to make rules in the build path, but it's to powerful. Ex: If i exclude android.R from the build path, then it doesn't appear in the choices but I cannot use it explicitly in my code...

2 - Do it manually —> to long

3 - I tried to configure the Organize Import tool, but didn't succeed.

Thank for your answers!

like image 699
PHF Avatar asked Jul 23 '11 09:07

PHF


People also ask

How do I organize imports in Eclipse?

Here are the steps to organising imports whenever you save: Go to Window > Preferences > Java > Editor > Save Actions. Select Perform the selected actions on save (off by default). Ensure that Organize imports is selected (on by default).

How do I fix all imports in Eclipse?

Go to the line of unused import, press Ctrl + 1, which is an Eclipse shortcut of a quick fix. This will show a drop-down menu to fix this error and one of them will be “remove unused imports.” It will remove that import statement from the Java file.

What is Ctrl Shift O in Eclipse?

Ctrl + D. Deletes current line in the editor. Command + Shift + O. Ctrl + Shift + O. Organize imports in the current java file.


1 Answers

You can use 'Preferences > Java > Appearance > Type Filters'. Create filters for types that you don't want to use. E.g. If you are not interested in types from java.awt package, you can create a filter for the entire package, or you can filter out individual types.

The filtered types are then hidden from the UI, i.e. they are not used in Organize imports or shown in Open Type dialog etc. Note that the types are still visible to the compiler, this is different from fiddling with the build path which will hide the types from the compiler.

like image 131
Deepak Azad Avatar answered Sep 21 '22 01:09

Deepak Azad