Eclipse: Exclude specific packages when autocompleting a class name
Asked Answered
U

2

105

When auto-completing a class name in Eclipse, e.g. if you type:

ListITab

A pop-up menu appears offering you matching class names for completion (which you can select with the mouse or by using the arrow keys:

In this example, I almost certainly want java.util.ListIterator and I almost never want com.sun.xml.internal.bind.v2.runtime.reflect.ListIterator (or anything else from that package).

This particular class will appear in the list frequently (every time I declare a ListIterator). I would like to be able to exclude packages from autocomplete searches, so that java.util.ListIterator is auto-completed without the need for a pop-up menu.

Is this possible?

Unheardof answered 15/1, 2010 at 18:42 Comment(2)
Oh, it would be great if you could just select the one you do not like and press Delete like in some other programs. But no ...Lucey
Just completed my answer to address the java.awt.List question you mention in the comments.Akee
A
154

Window > Preferences > Java > Appearance > Type Filters

You should be able to specify there the packages you do not want to see.

https://static.mcmap.net/file/mcmap/ZG-Ab5ovKRhlaGzQXVMsZ7BxXS2vbmb/galileo/topic/org.eclipse.jdt.doc.user/tips/images/type-filter.png

See Java Tips and Tricks

To exclude certain types from appearing in content assist, use the type filter feature configured on the Java > Appearance > Type Filters preference page.
Types matching one of these filter patterns will not appear in the Open Type dialog and will not be available to content assist, quick fix and organize imports.
These filter patterns do not affect the Package Explorer and Hierarchy views.


finnw (the OP) adds in the comments:

Now how do you add a single class to this list? I'm not interested in java.awt.List but occasionally I want java.awt.Window or java.awt.Dimension. –

"Type filter" is actually based on class pattern matching, meaning if you add:

 java.awt.List

that class will disappear from the content assist propositions.
If you know all java.awt.Lxxx classes are of no interest, you could add

 java.awt.L*

All other classes from java.awt would still be there for the content assist.
With a recent eclipse (I have right now a eclipse 3.6Mx, but this should work for 3.5.x as well), you are not limited to package pattern only in the Type Filter.

Akee answered 15/1, 2010 at 18:51 Comment(3)
It's also case sensitive, which is why when I tried "java.awt.list" it didn't work.Unheardof
It's a shame you can't just prioritize certain classes instead of removing them from the list...Shaggy
Thanks for the answer - I had to google for this as well even though I'd added some before. Its a crying shame that someone really thinks this belongs in Appearance instead of, oh, Java->Editor->ContentAssist...Sublunary
S
53

Window > Preferences > Java > Appearance > Type Filters

Safe answered 21/10, 2009 at 18:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.