Eclipse Open Type Pick Absolute Match First - eclipse

I have two classes, UserServiceDBImpl and UsergroupServiceDBImpl. When I use the "Open Type" dialog and type in 'UserServiceDBImpl' it often puts UsergroupServiceDBImpl first even though the other class is an exact match.
Is there any way to convince Eclipse to put the absolute match ahead of whatever it decides is the "best" solution according to its internal rules?

There has been a bug report open for this since 2005:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=109670
If you include the package when typing the classname into the dialog eg: "*.user.UserServiceDBImpl" it will help narrow it down, at least if the wrong options are in different packages anyway. Tedious though.

Related

Netbeans Java code suggestion options/plugin?

If I type Car.Mile and press ctrl-spacebar to autocomplete the member name, it does not bring up matches that don't begin with Mile at all. This is pretty annoying because so many methods are prefixed with get/set/is like getMileage() and setMileage().
My code completion options look like this currently. Not seeing this as a choice. This is JMonkeyEngine's version of Netbeans, if that matters.
Anyway to get this behavior?
Don't use the settings for "All Languages" use the Java settings:

what makes a variable be visible (intellij idea)

With intellij idea, how do I find out what makes a variable be visible?
An example of when it is hard:
Suppose you look at class A, and you see a variable something. If you jump to source you see that it's defined in trait X. But you don't extend trait X directly. What do you extend, then, that makes this variable visible? If you have a deeply nested hierarchy, tracking can be hard.
Any recommendations or solutions?
EDIT: Please vote for the feature if you're interested: http://youtrack.jetbrains.com/issue/IDEA-124369
I don't think that IntelliJ IDEA has any shortcut for "finding what makes a variable visible".
However you can determine it using the "Find Usages" option (Alt + F7). For example:
import java.nio._
object TempObj extends App {
def func = 2
val p = file.Paths.get("some-path")
func
}
So Find Usages on "file", tells you that its from the Package "file" (in heading of the new Tab it also shows the complete package name, ex: Find Usages of java.nio.file in Project Files).
Whereas Find Usages on func will tell you that its a Method (And the Tab heading now says: Find Usages of func() in Project and Libraries)
So now in way you can determine, what exactly makes the variable visible. This also works for imports since it shows the package from which it is imported and you can then look for import of that packages.
I know of two almost-solutions to this problem.
Go-to-declaration, as you mentioned, solves this problem in the case of local variables.
More generally, the "find usages" feature gives you a neat little breakdown by type and file of different uses of the variable. From this you can see if it's involved in a static import.
It's not perfect, but with a moment's thought these two are generally sufficient to figure out what you want.
Use ctrl+b or F4 to jump to source code. Alternatively you can use ctrl+shift+a to get option/action. You can find shortcuts at http://gaerfield.github.io/ide-shortcuts/ as well. Hope it will help.
From what I understood you want to see the code that creates an Object you use, for instance Mystery someMystery;.
That gives you two options to populate someMystery:
someMystery = ... where ... is your code to populate
someMystery and if that is the case you should follow
that code (with ctrl+B as far as you need to) to the point where it
actually creates the Mystery object.
Use CDI to populate that object instance for you, in which case you should look into the CDI mechanism in order to see in what way the object instance is populated.
In either way IMO there is no way to know for sure if the someMystery instance is of some more concrete class than Mystery, because it is decided in runtime, not in compile time, so your next bet would be to run the program in debug and see what object goes into someMystery, although you are not guaranteed to get the same type of object every time.
PS. My answer is based entirely on my java understanding of the topic, can't say if it is valid for scala also.
This might not be exactly the answer you were hoping to get.
However, quoting yourself,
If you have a deeply nested hierarchy, tracking can be hard.
Have you considered using composition over inheritance? Perhaps this would remove the need for the feature you are looking for.
Deeply nested hierarchy doesn't sound good. I understand your pain about that.
When you override vals or defs there is a little circle next to the line number that shows where it is from even when it is from nested hierarchy. Hovering over vals with the command key down also shows you a little tooltip where it is from.
Does this help?
https://youtu.be/r3D9axSlBo8
if you want class, field or method to be visible, you need to implement them as public. If it was your question.

How to disable Eclipse's "auto-folding during typing"?

Eclipse (any version AFAIK) has some weird behavior related to folding in Java code. Suppose I’m editing this class:
class A {
String field;
#Nonnull
Object method(){
// whatever
}
}
If folding is enabled and I tell it to collapse everything (it’s Control-NumSlash in mine, but that might be customized), the method is correctly folded, i.e. it shows only Object method()... for the method. All good ’till now.
The part that bothers me is that if I move the cursor right after field;, press Enter, and type something like “public”, and then stop for a second, Eclipse automatically folds that word into the method below.
That might seem reasonable (presumably it assumes I wanted to add that qualifier to the method); but in practice what I’m actually doing is trying to add a new method, and paused for a moment to think about its return type or maybe its name. (If I wanted to modify the method I’d unfold it first, since it might already have that qualifier, folded.)
I hate this “feature” with passion, but I can’t for the life of me find out how to disable it, nor even which of the damned mess of plugins (that Eclipse keeps insisting I should not be allowed to remove) is responsible for it so I can file a bug report.
So, does anyone know (1) where does that behavior come from, and hopefully (2) how can I get rid of it but keep manual folding? Thanks!
(For the record, I’m using Kepler SR1, but this behavior goes back a really long time, at least five years or so.)
I don't believe there's any way to prevent it from doing that unless you just make a habit of putting a semicolon ; or closing curly brace } after public which prevents the Object method(){.. from 'folding' it up. I believe it's written to fold everything up until the closest semicolon which is why #Nonnull is also included.
The only options for folding I can find are located in Window > Preferences > Java > Editor > folding
I would consider this to be a bug, or just a feature that had unintended side effects.
Funny enough, if you put almost any symbol or misspell public it wont fold it.

Auto fix common typo in eclipse

Lets say for example I write many times priavte instead private.
Is there a way to let Eclipse automatically fix my common typo?
Something like construct a map of my common typo to its desire fix,
and then just let Eclipse fix it without asking me about that.
Are there any other IDE\editors that have such support?
There is no builtin support for automatically changing strings. The closest to your request are the templates of the Java editor, but even those must explicitly be activated using CtrlSpace.
To get around your problem, I suggest simply not to write that much yourself. If you want to declare a private field, type just "pr" and hit CtrlSpace to invoke code completion. Eclipse can do code completion quite well, often even without any trigger characters (try it with an empty class file).

IntelliJ call hierarchy of fields

Eclipse JDT has a 'call hierarchy' feature -- start from a field/method and it recursively finds all references.
IntelliJ also implements this, but it only works from methods. For fields, you can only 'Find Usages', so if you want to dig deeper you have to do additional searches.
Tried 'Dataflow to here', but it's not what I'm looking for.
Am I missing something? Is there a better way to explore field usage in IntelliJ?
Select the method you're interested in and then use from the top menu "Navigate > Call Hierarchy" or simply Ctrl+Alt+H.
AFAIK this doesn't work for fields, because when I select a field, the "Navigate > Call Hierarchy" option becomes grayed-out. The only similar featutes I'm aware of for fields are "Edit > Find > Find Usages" (Alt+F7) and "Edit > Find > Show Usages" (Ctrl+Alt+F7).
EDIT
The issue below has been resolved and IntelliJ IDEA 2019.3 will have this feature.
EDIT 2
I downloaded:
IntelliJ IDEA 2019.3 EAP (Community Edition)
Build #IC-193.3793.14, built on September 25, 2019
But it seems this issue was not fixed correctly, the call hierarchy for fields does not take you to the actual usage of the field in the method rather to the line of the method definition.
See: https://youtrack.jetbrains.net/issue/IDEA-160274#focus=streamItem-27-3721096.0-0
Original answer
IntelliJ doesn't have this feature, however there is a feature request here:
https://youtrack.jetbrains.com/issue/IDEA-160274
If you would like the feature implemented, you can vote there.
"Dataflow to here" and "Dataflow from here" give you a recursive view of data flowing in to, and out of, fields (or local variables).
I think that these two features, in fact, are what you're after.
If not, can you rephrase the question in less IDE-specific terms? In other words: what information do you want to extract from your codebase?
Use "Find Usages" feature (Alt+F7)