I'm quite the happy user of eclipse mars, it gets the job done.
One thing that does bug me a bit is that when i use "Override/Implements methods.." feature the generate code is always put at the end of the java source file.
Is it possible to add the generate code at the cursor/caret position?
Yes, you can specify after which method to put it using Insertion point.
Example with Getters/Setters
Override/Implements dialog:
Related
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.
When using Netbeans' features for generating event handlers from a GUI, for example, while the body of the generated methods are editable, I cannot find a way to change the order of the generated methods within the code of a class.
Cutting for cutting and pasting is not allowed with generated code.
How instead might I do this?
Thank you very much!
You can't do that in Netbeans. It's not really a priority because you can use the Navigator instead.
If you really want to move those blocks, open the Java file with an other editor (Gedit, Notepad...) and re-order the blocks here.
You can also remove the //GEN-FIRST and //GEN-LAST to make them editable in Netbeans.
(First time please be gentle etc. etc.)
Let's say I was lazy/unthinking/pressed for time and hardcoded a string instead of making a global variable. And I repeated this mistake over hundreds of classes and test cases that I wrote. Now, I want to fix this, since I found out I'll eventually need to update that string. Is there some refactoring method in Eclipse or elsewhere that will let me replace all instances of that specific string with a global variable?
I can think of a programmatic solution, to run through all those files and replace the string, but I'd prefer not to go down that route unless absolutely necessary.
Thanks a lot!
Well you can use search and replace within Eclipse across all the files in your project, for one thing. You don't need to write that yourself.
It doesn't look like the "Extract Constant" refactoring of Eclipse is willing to extract it across classes, unfortunately. That would obviously be the nicer solution.
Eclipse provide Refactor option.
right click on value which you want to replace with variable, you will see option Refactor.
this will help you replace value from all other occurance.
You can find referenced place to an element in eclipse as following:
Selected element.(variable of String in your case)
Sight click on selected element
Selected menu References
Select Workspace item for finding all references in your workspace
Then you can edit evry item in result
Exist another way such as using search and replace feature.
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