is it possible to check the usage for multiple methods in a class at once in Intellij?
For example, class A has 100 methods. Instead of going over each single method and check if it is used, can we actually check some or all of usages for methods in this class at once in Intellij?
If you are purely looking for methods that are unused, and there are no errors in the source, you can just use F2 to jump between them.
Unused methods will be highlighted grey, with an underline.
Related
On windows, I know that we can search for all the methods in the current class by using Ctrl+F12.
Suppose, that I am in the class Car.java
and there we have a method called accelerate();
The method is really long and now I did some modifications at the end of this method. How can I jump back to the place where the method accelerate() starts?
I used Ctrl+U but that just does not do anything at all.
Refer to this page from IntelliJ's manual: Method navigation
It's Alt+Up or Alt+Down
I'm using IntelliJ with a mixed Java/Kotlin project. In one of my Kotlin files, I have this property:
override val value: String
get() {
return webElement.getAttribute("value")
}
IntelliJ's light bulb offers to "Convert property getter to initializer", which changes the code to this:
override val value: String = webElement.getAttribute("value")
To me, it seems like this isn't a simple refactoring, but a significant code change. What I think is happening is:
In the first version, the value property is retrieved when I call value.
In the changed version, the value property is set immediately when the class instance is constructed, and then never changes for that class instance.
But maybe this is more like C# expression-bodied members, which use a lambda arrow => instead of braces and return but otherwise work exactly the same way.
So...which is it? When will the second version of the code initialize?
You are correct regarding these statements:
In the first version, the value property is retrieved when I call value.
In the changed version, the value property is set immediately when the class instance is constructed, and then never changes for that class instance.
IntelliJ's light bulb offers to "Convert property getter to initializer" because it is just an option available. Light bulb only highlights the actions you can do with a selected piece of code.
IntelliJ does not try to tell you that "property initializer" and "property getter" are equal. What it tells you is that you can convert one to the other if you wish to.
I agree that it is confusing, especially considering this quote from IntelliJ Idea documentation:
As soon as the IDE finds a way to alter your code, it displays a yellow bulb icon in the editor next to the current line. By clicking this icon, you can view intention actions available for this unit of code. Intention actions cover a wide range of situations from warnings to optimization suggestions. You can view the full list of intentions and customize them in the Settings/Preferences dialog ⌘,.
Having this in mind it could appear that your code is either can be optimized or has a warning.
The answer
When will the second version of the code initialize?
... immediately when the class instance is constructed.
You are correct.
I'm used to work with NetBeans and now I'm trying IntelliJ. So my question is: Does IntelliJ has a way to get right class by its methods?
For example, in NetBeans if I write:
glGenBu // Intellisense will kick in and will suggest me
to use GL15.glGenBuffers() method from GL15 class
This will automatically import the right library.
This is very handy because I'm working with LWJGL and it has a bad way to manage OpenGL methods ('GLXX' where XX is the version of OpenGL and all methods that appeared in that version are stored in that class) and I never remember the right class where my desired method is.
Thank you.
Pressing Ctrl+Space when you already see completion list will show more suggestions, with static methods from the entire project among them. See https://www.jetbrains.com/help/idea/auto-completing-code.html for more details.
Is there a quick easy way to have IntelliJ identify the superclass or interface defining the method being called in a class?
For example, in the following example, the fireEvent method is being called on the implicit this but this method is not defined within this Java class being edited in IntelliJ 2018.3. Is there some way to ask IntelliJ which of the several interfaces being implemented as well as any parent in the superclass hierarchy defines this particular method?
…
private void doIt() {
…
fireEvent( event ) ;
}
What I am asking is for the opposite of this Question, Does IntelliJ have the equivalent of the Eclipse “method view”?. That Question asks “for a given class, what are its methods offered?”. I am asking “for a given method being invoked, from what inherited superclass or interface is that method defined?”.
I generally just context-click (Ctrl-click on PC, Command-click on macOS) to navigate to the source for a method. The .java file of the superclass or interface opens in the editor.
In order to avoid navigating away, you can also context-hover. Another option is showing the javadoc via context-q when the cursor is somewhere in the method name.
So I have a case where Find Usages doesn't return hits from a particular class of mine. I'm using Android Studio 1.0.2. The class is used in a method paramter, is a part of the main source code base and module, and does pop up when I do a free text Find in Path
Have I somehow removed the file VgXitiLogger.java from indexing? Where in that case do I configure that?
Your "Find Usages" screenshot shows the usages of the constructor of the SearchPerformedEvent class, because you triggered Find Usages when the caret was on the constructor of the class. The occurrences on the second screenshot are usages of the class, not of the constructor.