Eclipse: Exclude specific packages when autocompleting a class name - java

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?

Window > Preferences > Java > Appearance > Type Filters
You should be able to specify there the packages you do not want to see.
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.

Window > Preferences > Java > Appearance > Type Filters

Related

How to document runtime of a function with Javadoc

I'm want to document the asymptotic runtime of a function, as it will be used for algorithm-engineering for graph problems.
What's the most idiomatic way to do this? Is there a way to create new tags in Javadoc like #return or #author?
I provided an example below, which is the method to delete a vertex in the graph.
/**
* Runtime: O( degreeOf(v) ) because every neighbour of [v] also needs to be updated.
*/
fun deleteVertex(v: V): SimpleGraph<V> {
if (v in m.keys) {
for (nb in m[v]!!)
m[nb]!!.remove(v)
m.remove(v)
}
return this
}
To create custom tags for Javadocs, simply follow these instructions.
You can create other customizations for Javadoc. For example, in Eclipse, you can create "templates" so that when you create new classes or add new methods, the IDE automatically apply this template to add a (Javadoc) comment formatted in the prescribed style of the template you applied. You can save these templates in an XML file so that you could share it with other members of your team. I am sure that IntelliJ and other modern IDEs will have similar features. I am just more familiarized with Eclipse. Here is a video I created many years ago on how to create a Code Formatter in Eclipse. If you advance to the 1:48 mark, you will see "Code Template" right above the "Code Formatter" option I selected in the video. Creating a code template is much easier than a formatter.
To do this, simply click on Windows > Preferences menu to get the Preferences popup. There, select Java > Code Style > Code Templates. in the right pane, expand Comments and select the component you wish to create a comment template for, for example Methods. Click Edit button and format the Javadoc comment to your liking. Obviously, you will have to do a bit of research to get really creative with your comments. For example, you might need to figure out how to use system variables or create your own. For example, in the image below, I made use the year variable to apply the current year whenever I create a new class.
Once you finish with all your template customizations, simply click the Export button and use the File Chooser dialog to save the file wherever you would like.
One last tip, if you need to embed code snippets in your Javadocs, you can follow the recommendations in this article. I do this very often. Sometimes I find it useful to embed a few lines of code to illustrate different use cases for the method. That way, other developers can see how to use the method in the correct context.

How to make eclipse auto-complete search be case-sensitive?

On Eclipse 2019-09 there is a very annoying "feature" which finds the wrong method when you are typing its name. The image below speaks for itself.
When I type "rem", it selects hasRemaining() and not remaining(). Also when I type "rem", of course remaining() should appear first and before should_remanage(). Is it possible to fix that?
Click here for the image
Go to Window > Preferences > Java > Editor > Content assist and you will find an option that let you select between relevance and alphabetically.
Also checkbox allow you to select camelcase matches 'show camel case matches' -
tune these properties to get expected results..

How to extend Eclipse's Java editor to recognize my own elements

I want to add references to other elements inside javadoc. The javadoc should look similar to:
/**
* ...
* #my.tag SomeElement
*/
I want to reuse the existing Java editor inside Eclipse. Of course I can type above javadoc already, however I'd like to add some features:
Navigation: upon Ctrl-Click / F3 I want to navigate to the editor showing SomeElement
Auto-completion: Ctrl-Space should complete the text / show valid alternatives
Checking: I want to create a warning marker and underline the SomeElement if it cannot be found
I already figured out that I can do the auto-completion by using the extension point org.eclipse.jdt.ui.javaCompletionProposalComputer, though this seems to be little more complex than I had hoped, so I might be on the wrong track here?
For checking my elements I might be able to use org.eclipse.jdt.core.compilationParticipant, which can generate markers upon compilation which afaik happens with every save operation.
But how can I can manage the navigation feature? Any pointers are welcome!
For navigation you can provide a Hyperlink Detector. You'll want to look at how the Java Editor and its existing detectors are declared in the org.eclipse.jdt.ui plug-in to determine the correct target ID.

Eclipse Content Assist Struggles

Lately Eclipse's content assist feature has been giving me some frustration.
I recently changed my Auto Activation trigger so that the autocomplete box would appear whenever I start typing, rather than just after I type a period.
This is great most of the time but it has some annoying downsides. For example:
Eclipse autocompletes 'String' to android.R.string. This is very very annoying considering it changes "String" to "string" when I press space or enter. Why would I want that? android.r.string hasn't even been imported!
Here is what my content assist settings look like:
Two desired solutions would be the following:
Don't show proposals that don't match case (little 's' shouldn't match big 'S')
Don't show proposals that I have not imported.
If anyone could help me out with this it would be greatly appreciated!
Try these:
1. Sort the proposals by relevance and not alphabetically.
2. Hide proposals not visible in the invocation context (you have this one) and
3. Hide deprecated references

How to configure Eclipse to autocomplete using java.util.List and not java.awt.List? [duplicate]

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?
Window > Preferences > Java > Appearance > Type Filters
You should be able to specify there the packages you do not want to see.
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.
Window > Preferences > Java > Appearance > Type Filters

Categories