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
Related
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.
Previously, I've been able to create a method stub in Eclipse (Java) by typing the method name and pressing CTRL - SPACE. This would then give me the option of automatically generating a void method stub.
Unfortunately, recently I've been unable to do this for any method name longer than two characters. Once the word is longer than 2 chars, the option is no longer there.
I've looked at the templates in the options, and found the private_method and public_method templates, which are similar, but not quite right. The void method stub is nowhere in there. Also, the icon next to the void method stub is different to the templates, which leads me to believe that it is indeed something other than templates.
Can anyone point me in the right direction of why this isn't working for anything longer than two characters?
Here's an image of the code suggestion I'm looking for (the selected one):
EDIT: For clarification, I've added two more images showing the problem, and a further description:
In the case where there are two characters and I press CTRL - SPACE, I get the autocomplete option for creating the method stub (which is what I want). However, when pressing CTRL - SPACE with more than two characters before the cursor, there is no such suggestion. See the second image below and you'll see what I mean.
It's related to Code Recommenders, which is now enabled by default in Eclipse (as of the Mars release, I think). To me it looks like a bug, either behavioral or, if it's working as intended, it's a usability and/or UI bug, because it's difficult to understand the new behavior.
One workaround is to disable Code Recommenders for code completion; see this screen shot for where to do so in the Preferences.
If you want to keep Code Recommenders enabled (it does seem to provide some valuable functionality), is to tweak a particular setting so that the method template is included for more characters. I'm not exactly sure how or why it's related to what you're seeing, but it does seem to work. I'm also not sure of the performance impact of adjusting this too much, as indicated by the UI instructions.
Increasing the "Maximum prefix length" for the sub-words completion seems to allow larger numbers of characters to trigger the method template suggestion. Again, I'm not sure why but I strongly suspect it's a bug in Code Recommenders.
I suggest asking about it on their forum and/or entering a bug about this: https://www.eclipse.org/recommenders/community/
form the image I can tell that you are trying to write your code within the class block and not within a method block...
Example
class a {
// you are trying to write your code here
}
This issue has been fixed with Eclipse Code Recommenders 2.2.5.
You can download it from the Recommenders stable update site stable update site.
When I type code in Sublime say, I just need to start with the first few letters of some variables and it would come up with a list of possible existing variable names that match what I just typed. But in Eclipse, I don't know how to realize this. In the preference-java-editor-content assist, I found this auto-activation pane and according to some other posts, I'm supposed to change the auto activation triggers for java. However this is how my default setting looks like. I don't understand the dot over there. Also I'm not sure if that's the right way to approach my problem?
Can someone help me out? Thanks!!
The auto activation will give you suggestions about fields and methods that are available. For example if you start typing in
new Object().
then the IDE (Eclipse) will give you suggestions (after 200ms from the "Auto activation delay") of toString(), equals(), and other methods.
If you just want to use plain auto-complete, I tend to use the shortcut CTRL+ Space (The spacebar key). So if I want Eclipse to auto-complete a method name for me (say the method is reallyLongMethodNameIDoNotWantToTypeOut()) I'll type in
reallyL press CTRL + Space and Eclipse will fill in the rest for me.
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.
Is there a simpler way of reordering methods within a class source file in IntelliJ than cutting and pasting the code manually? Nowadays I often need this while refactoring legacy code, e.g. to move related methods close to each other in the source code.
In Eclipse AFAIK there is a view similar to the Structure view of IntelliJ, where I can drag and drop methods around. However, this does not work in IntelliJ and I couldn't find any hints from its help either.
I am using IntelliJ 9.0.2 to be specific.
You can select a method name and hit: Ctrl+Shift+Up or Ctrl+Shift+Down to move it up and down.
On OS X: Cmd+Shift+Up or Cmd+Shift+Down
Beyond this the Rearranger Plugin lets you move methods around quickly, and even define a standard ordering based on your coding convention.
IntelliJ has a built in system that allows you to specify how to order your methods. You need to go to Settings (Ctrl + Alt +S) -> Editor -> Code Style -> Java -> Arrangement (tab) and scroll down until you find the icons with methods. There you can manipulate the options to sort them by visibility, or alphabetically, or to keep related ones grouped together.
Here is a screenshot of my settings which will order methods automatically by visibility (public, protected, private) and alphabetically (a-z).
The blue highlights show the currently selected rules.
Not a perfect answer yet, due to a bug in IntelliJ.
Though IntelliJ offers this feature implicitly, but it needs to be enabled as well as fixed. The OP's suggested way is technically arranging methods in depth-first order. However, if you use Breadth-first ordering(which works properly), it should reduce the manual work of moving functions by a lot, by arranging all caller and callee methods together.
Issue Link: https://youtrack.jetbrains.com/issue/IDEA-149524. Please do vote for its resolution.
The appropriate action for this is Rearrange Code. This has no key assigned to it, but you can define your own using Preferences->Keymap.
With your cursor on the method definition line (you do not have to and press ctrl+shift+up or ctrl+shift+down, to move up or down respectively.
You can also to ctrl+shift+numberpad - to quickly collapse everything so you can focus on moving around (plain - works on my laptop as well, not sure why) and ctrl+shift+numberpad + to get back to see everything (ctrl-shift-equals works on my laptop as well).
Select a block of text (hit Ctrl-W a few times) and then use Ctrl-Shift-Up and Ctrl-Shift-Down to move it around.
There is an automated way, which you can later tweak
Code -> show reformat file dialog
and tick "rearrange code" box