When I file search for certain keyword with CTRL + H in eclipse, results shows the matching line and filename. However, it doesn't show the method name in which the match occurred, and it is slow to double click the result and jump to the beginning of method, when searching a set of particular methods in mind.
Is it possible to format the results as such, that method name is associated with each match?
As #greg-449 mentioned in the comments, Eclipse's simple file/text search isn't aware of Java constructs like classes and methods. For that you'd need to use Java Search.
Alternatively, you might be interested in STS Quick Search, which can be installed into any Eclipse (even if you aren't using STS or Spring). It provides a very useful global workspace text search that shows previews of the context of each match as you select it.
Related
I have just started using IntelliJ for the first time on a project that I've just started working on, and am still getting familiar witht the setup and how it works. Previously when working on Java projects, I have predominantly used Eclipse as my IDE.
In Eclipse, when working on a particular method, there was the functionality to right-click the method, and select the option 'Find All References', to list everywhere in the project that the method was called.
I have made a few changes to the definitions of a couple of methods (the changes have mainly been in their parameters) in the project in IntelliJ, and now want to 'Find All References' on the methods, so that I can ensure that they are called with the correct parameters. However, when I right-click on the method definitions, and select 'Find Usages' from the menu, I get a popup message displaying the following warning:
Method 'abc() of class def' implements method of interface ghi. Do you want to find the usages of the base method?
Regardless of whether I select 'Yes' or 'No', the search results only return one result- the source file & line that I clicked on in order to do the search.
My guess is that there's something I need to change in the settings somewhere to ensure that doing this returns all of the places where that particular method is used in the code? I checked with a colleague, and when they do exactly the same thing, they get a list of all of the places within the project where that method is called...
How can I resolve this, so that I can find all of the method calls for the one I have highlighted?
Have you tried CTRL+click on method declaration?
I usually use Ctrl-Alt-H for Hierarchy and get a list of all callers even in tests.
By selecting the method name (double click on it) and pressing alt+ctrl+shift+f7 keys, a window named Fined Usages will popup. There is a checkbox in this window, you can check: Usages, Overriding methods, Search for text occurrences or Skip result tab with one usage. Then you can set the scope on All Places and click on Find. So, a search window appears and all classes and methods that called this method are listed there.
Alternatively, you can use "Find in path" option which lets you search for a raw string in any files in the project (although it's of course configurable). It is under Ctrl-Shift-F.
I have a relatively complex java project, with many classes that are probably not used.
Static analysis of the code base is relevant for some of the classes, but some are loaded dynamically (network services, persisted data, etc.)
Is there a method to get a list of deprecated classes that were actively used in the jvm, so I can know if those classes are used?
[I know there may be "sleeper classes" that are used only rarely, but that's a risk I can take]
The JVM may have an option to print information about all used classes. For example:
java -verbose:class ...
You still would have to filter out the deprecated ones by some other means.
You can try to compile with -deprecation (or -Xlint:deprecation) to see the uses of deprecated APIs if you have to sourcecode (I guess you have it)
I could think of the following :
Add static initializer to each of your classes in the form
static {
// here you can get creative :
// either do some writing to a file with each class printing its name
// or do System.err outputing the class name, then later fetching the entire output.
}
If you are too lazy to manually add the piece of code you could write simple program to append this initializer to all files ending with .java.
This is simple way of getting a list of all the classes that are being used ( I think).
Best of luck!
There are tools like UCDetector which I've used in the past. But that requires manual assessments which can be painful for large projects. You can do text analysis like below:
Listing active usage deprecated methods
For static code analysis, list down deprecated methods of which source is already available using an IDE.
In Eclipse, goto Window -> Preferences -> Java -> Compiler -> Errors/Warnings -> Deprecated and restricted API : Set level to WARNING and check the items besides.
In Problems view, click the down button near the tab -> Group By -> Java Problem Type
You will be able to see Deprecation usage list grouped together, copy the contents as text, which you can use to further prepare scripts/excel for analysis
Use a simple text editor to find and replace "from the type " and " is deprecated" with tab characters
Copy the contents to a spreadsheet. You will have a list of classes which contain deprecated methods but have active usage.
Listing inactive usage deprecated methods
List down the class and method names by using similar approach above (For method name replace the text "The method " and " from the type " with tab characters).
This list minus the previous list is the inactive methods list.
Listing dynamic deprecated methods
For dynamic code using reflections etc, there is no single bullet approach. You can do filtering of basic stuff using the method names.
List down the method names by using similar approach above (Replace the text "The method " and " from the type " with tab characters).
For the unique set of method names, loop to use a grep script. This type of search can be slow even for small projects. But just in case you 'ld want to invest the time.
Remove them all and try to run your application. Every time you get a ClassNotFoundException for one of them, write it down and add the class back. Rinse and repeat.
I know there is a Ctrl+Space dialog box that show the methods options that I have.
But if i have a method that I not fully remember the name of it and I remember only a part of the name.
For example: There is a big static class which contains tons of methods starting with "add"
add1_Buffer, add2_Render, add7_Function and so on..
now I don't remember the fully name but i remember only "Buffer".
so I want to type "buffer" press Ctrl+Space and get the "add1_Buffer" method and all the names
that contain the name "buffer" in it.
Edit:
By the way, i need it on the OpenGL api where there are tons of functions and i am not familiar with all of them i know only keywords, I was searching for something like in visual studio that is really fast and easy.
If you start typing the a in add1_Buffer and then an upper B and then press Ctrl + Space you will find the correct method.
You can then continue writing the word Buffer if there are more methods starting with add and then having an upper B.
This means that you'll have to remember at least the first part of your method but hopefully you do.
Add the CodeRecommenders plugin to your installation. That has a subwords completion, which the normal JDT code completion does not have.
Use search. From the Search menu at the top of the window, select "Java Search". You can limit your search to methods and use wildcards to search for *Buffer* if you know that Buffer is in the method name.
The shortcut Ctrl + O gives an outline of the current source. So you can view and search all your methods in your current class. Use wildcards when needed.
This merely meets you req: alt+/, just a replacement for ctrl+space
Currently there is no direct way to do that in eclipse. But i found these are helpful. here
This post resembles your's look at it. Similar one here
In eclipse, i want to see where in my workspace is a field actually being used. If I select it and press Ctrl+Shift+G i get all the references to it, but there's a drawback that if in the JavaDoc section someone mentioned that name, i get search results for those too.
So if i have a field called "user" and i want to see where it's being used, i get a ton of search results for every method that mentions "user" as a parameter in the javadoc...
Try using Ctrl+Shift+U that will show every line your variable/method occures in current class. Or Ctrl+Alt+H for every method using your variable.
I'm trying to do something weird, I'm trying to determine how many methods has my Java application.
This weird thing has a purpose, it is because I have to improve the logging in the application, and it will require to make a revision of every method and add the logging if it is missing, update the logging if it already has.
I'm in the estimation process, so knowing how many methods has the application will help me to provide a high level estimation with a reasonable basis for this.
Then, here is the question, is there any way to know how many methods has my Java application?
Thanks in advance.
Fer
PS: I'm using Eclipse
Using Eclipse you can do this:
Press Ctrl-H (Search), then select the "Java Search" tab (if it doesn't appear click on the "Customize..." button at the lower left corner)
Put * in the search box
Select "Method" in the "Search For" fieldset
Select "Declarations" in the "Limit To" fieldset
Select "Sources" in the "Search In" fieldset
Select "Workspace" in the "Scope" fieldset
Click on "Search"
After the search is complete you should see a "XXXX declarations in..." message in the search view and that will be your result.
Hope it helps!
I would prefer using Reflection.
Retrieve all the class from expected packages, where logging is necessary
Summing up all the method available to all those class
Try to use a static code analyzer; Source Monitor, for example, is free SW and has the count you're searching for.
Use sonar - http://www.sonarsource.org/ - it's great tool for analyzing code.
Or look here: What are the good static code analysis plugins?
If you are going to add logging to so many methods you might want to consider implementing an AOP solution. It will allow you to write consistent loggers, makes it easier to maintain and doesn't clutter your code with boilerplate stuff. There are countless examples in Google.
Metrics is a nice plugin for Eclipse: http://metrics.sourceforge.net/
Number of Methods (NOM): Total number of methods defined in the selected scope
For a specific class, it's easy just from the class outline panel in eclipse select all methods then right click and copy the fully qualified name to the editor of your choice then it's a simple count lines.
Please press CTRL+O in your respective Java Class in the Eclipse IDE - You will get the number of methods in the respective Java class.
Now you should be able to see the number of methods available in that class.