Netbeans generated code - java

I have a netbeans project that I imported into eclipse. When I use my code formatting style in eclipse, it breaks the auto generated code in Netbeans. The code is similar to the following.
private void customActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_customActionPerformed
// aaa
}// GEN-LAST:event_customActionPerformed
Is there any way to tell Netbeans to go back and use the correctly named methods? Currently when I am in the GUI Builder, it will not find the method that it had previously generated.

To avoid altering the comments:
Open the preferences (In the Window menu, select Preferences)
In the Preferences tree, go to "Java", "Code Style", "Formatter"
If you only wish to configure a single project, click the "Configure Project Specific Settings" link (looks like a blue URL link)
You may wish to create a "new" profile, copying from the default (or whatever is used for your project)
When you are editing the profile, go to the "Comments" tab, and deselect "Enable Line Comment Formatting". That will prevent spaces from appearing in single line comments.

NetBeans is picky about the comments surrounding guarded blocks At issue here is the space between the // and the GEN.
The GEN needs to immediately follow the comment.
Fails, space before GEN:
// GEN_FIRST:event_customActionPerformed
OK, no space before GEN:
//GEN_FIRST:event_customActionPerformed

Related

Intellij auto-generate java method at the end of the file

Is there any way to ask the auto-generate methods created by intellij to be generated at the end of the class?
currently when i generate a method (⌥⌘M) it is created right below the function I extracted the method from, and I would like it to be at the end of the file.
Does intellij offer that option?
You can re-arrange the code in IntelliJ after code generation manually even though this does not guarantee that the code will go to the bottom of the file. You can do that by clicking on the "Rearrange" menu item in the "Code" menu:
Another option to re-arrange the code without having to use the menus would be via the "Reformat" file dialogue, by pressing on Windows Ctrl+Shift+Alt+L and by activating in it the "Re-format code" checkbox.
You can change the pattern of code arrangement in the settings in the following dialogue:
There is no such option in Intellij, Once you extract method you can move method up and down using Press Up( ⌥ ⇧ Up) or Down( ⌥ ⇧ Down).

Folding (collapse/expand) codes in Intellij (How does it look like Eclipse?)

I got to InteliJ from Eclipse. So, I am programming in Java (for Android) in InteliJ now.
I have problems with FOLDING (collapse/expand) style in IntelliJ.
This is a sample of code folding in Eclipse (and I love it) :
and This is code folding in Intellij (or Android Studio) and I hate it :
Is it possible to convert code folding style in InteliJ to Eclipse? (Eclipse folding is my target)
I want to hide #Override or any annotations from all methods in IntelliJ
I want to hide folded symbol {...} or move it in method name line in IntelliJ
Like this :
(in following picture, I removed #Override manually. so,I've moved to manually bracket { to the method name line.
)
Update 1 :
I tried to solve my problem in (Intellij) File -> Settings... -> Editor -> Code Folding , but I could not solve.
For Android Studio:
File --> Settings --> Editor --> General --> Code Folding
From that section you can select the way you want to fold your methods and inner classes etc.
Hope this helps.
You can change it by changing code formatter style.
For Mac :
Eclipse -> Preference -> Java -> Code Style -> Formatter -> Edit
For Window :
Window -> Preference -> Java -> Code Style -> Formatter -> Edit
Please check below links for more details.
http://www.wikihow.com/Change-the-Default-Format-Settings-in-Eclipse
Open Eclipse.
Click on the top tool bar and then click on Preferences.
On the left side of the box, expand Java option, expand Code Style, and click Formatter.
The active profile must be set to Eclipse[built-in], you cannot edit this setting, so make a new one by clicking the New... button.
Enter your new profile name and click OK.
You will now be presented with the "Profile 'name you set'"box.
There are 8 tabs: Indentation, Braces, White Space, Blank Line, New lines, Control statements, Line wrapping, Comments.
Click on each tab and make the changes. Dont forget to click Apply.
Now to format the current document, click on Source from the menu bar, click Format or press Ctrl+Shift+F.
Job well done. =)

Stop spacebar keypress from triggering autocomplete in Eclipse

Update
This was fixed in Eclipse 2018-12. This behaviour is still default, but can be configured off - see the accepted answer for how
I'll leave the question as it was for posterity, and for those on earlier versions of Eclipse
In Eclipse, I've enabled intellisense-style suggestions for Java by going to
Window -> Preferences -> Java/Editor/Content Assist
and setting the following
Auto activation delay (ms) -> 0
Auto activation triggers for Java -> .(abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
source = Eclipse Intellisense?
This works brilliantly, apart from one annoying problem. When I hit spacebar, the token being typed is autocompleted with whatever is at the top of the suggestions list. Fair enough, except that sometimes I'll type a class/variable name with an exact legal match, but this won't appear as the top suggestion. So when I naturally hit spacebar Eclipse inserts something completely wrong.
E.G. after typing Cookie I'll hit spacebar and get CookieMonster.
This seems like a bug, and happens often enough to be annoying, but even despite this I don't want spacebar to trigger autocomplete in general. I may want to type a variable name which hasn't been declared yet, or something similar. I want to use autocomplete as a helper tool, but my natural typing should always take priority over it.
I'd like to stop spacebar triggering autocomplete, and either fall back to using enter, or better still trigger autocomplete with a custom key not used in ordinary typing. Is any of this possible?
I've played around with all the settings in Content Assist to no avail. Googling the question just returns a bunch of results about disabling the autocomplete feature.
This issue is fixed from Eclipse 2018-12 [4.10] see the accepted answer
It's present in all prior versions, i.e. 2018-09 [4.9], Photon [4.8], Oxygen [4.7], Neon [4.6], etc..
Eclipse 2018-12 was already patched for this!
A patch for Bug 348857 was recently merged to the Eclipse project and was released as part of Eclipse 2018-12. You can download that version here.
You now have a new option to disable all insertion triggers apart from enter, which will prevent spacebar from causing autocompletion.
Simply go to Preferences... -> Java -> Editor -> Content Assist (or Window -> Preferences -> Java -> Editor -> Content Assist on Windows) and select Disable insertion triggers except 'Enter', as shown in the screenshot below:
There is a solution on the issue tracker for this.
Copy the jar in the eclipse/dropins folder. With the next restart space is diabled as autocompletion trigger.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=348857
Eclipse 12-2018 and newer: This is working natively, check Pyves answer.
Use a SDK version of eclipse
1.open Plug-ins View and find org.eclipse.jface.text, right click, choose import as Source Project. After import, you find it in your workspace.
2.In src/org/eclipse/jface/text/contentassist/CompletionProposalPopup.java
char[] triggers = t.getTriggerCharacter();
if(contains(triggers,key))
change to
if(key!='='&&key!=0x20&&contains(triggers,key))
3.Export org.eclipse.jface.text
Right click the project folder of org.eclipse.jface.text, choose export-->Deployable plugins and fragments, next, destination choose archive file, finish. Replace the one in eclipse/plugins with the one you generate.
The spacebar has been a key to select the autocomplete even in Indigo. To my knowledge, this can't be configured.
In fact, that is probably why the delay exists.
I suggest setting the delay to some optimal value that allows you to type things like private void ... comfortably without triggering suggestions for private and void. Then in case you get a suggestion because you waited too long, press Escape to abort Content Assist.
Same configuration as davnicwil, same issue, still on eclipse 4.4.
Solution: Intercept (hook) SHIFT+SPACE (press and hold) on (editor-window) eclipse and replace it with ESC,SPACE (sequence). Now you my decide between
Autocomplete+SPACE: press SPACE when autosuggestion present
just SPACE: press predefined key combination or sequence (e.g. SHIFT+SPACE)
On windows you may use http://www.heise.de/download/activaid.html (you can also use AutoHotkey, java native hook, ...)
HowTo with ActivAid:
Open Ac'tivAid, select "UserHotkeys"
click on "+", set a description
click on "short cut", press e.g. SHIFT+SPACE
Command: "{ESC}{SPACE}" (without quotes)
click "+", select eclipse editor frame, press ENTER
click OK, OK in Ac'tivAid
My config file:activAid/settings/ac'tivAid.ini:[UserHotkeys]
Hotkey11=+Space
Path11=<Send>{ESC}{SPACE}
Description11=Eclipse Shift+Space -> Esc,Space
Category11=
Application11=ahk_class SWT_Window0
You may also remap keys on non-english keyboards with "HotStrings", e.g. ö->{,ä->} etc.
Finally worked it out.
Try download this org.eclipse.jface.text.jar and copy it to your plugin folder(Typically eclipse/plugin). Do not forget to backup your own one.
Works on Eclipse Juno.
If the link doesn't work, comment on this, thanks.
In Eclipse go to Window -> Preferences -> General -> Keys and remove the binding for the command Content Assist.
You could disable Auto activation via the check box in
Window -> Preferences -> Java/Editor/Content Assist
and activate the auto-complete feature on demand. The default hotkey for this is
CTRL+Space

Eclipse, Easily remove/fix all #Override due to Java version change

I am aware of 'Must Override a Superclass Method' Errors after importing a project into Eclipse (my issue is the opposite, I need to remove the #Overrides) and I understand the reason the error occurs.
My question
Is there an easy way to remove all of those errors, or remove all the errors of the same kind in one swoop? Kind of like solving all imports...
Thanks for any tips to help save time.
I do not know better way than find and replace all #Override by empty string. Eclipse can do it globally: press Cnrtl/H, write text #Override and leave the target empty. Then press "replace all" and pray... :(
Solution:
If you imported a Java 6 project and have Eclipse complaining about #Override annotations because you are compiling with Java 5...
Make sure you have a file from the project open and selected in your workspace
CTRL+H
Change the Tab at the top from Java Search to File Search
In Containing Text enter #Override
In File name patterns enter *
Select Enclosing Projects for your Scope
Press Search to do a dry run to see what happens and what it finds
Then, if all looks good, proceed with:
CTRL+H
Change the Tab at the top from Java Search to File Search
All your values should be remembered, if not follow the steps above from the dry run
Press Replace
Example Replace
Replacing 92 matches in 18 files
Replace: field should have carried over #Override
Remove anything/everything from the With: field
Press OK
Awesome...no laborious removing of #Overrides ever again.
Please NOTE: Occasionally, for me at least, when pressing CTRL+H the File Search wont allow me to choose Enclosing Projects as a Scope or it will automatically search the entire Workspace as opposed to the project. This is resolved by ensuring a file from your project is open and focused in Eclipse.
Hope this helps others. Thanks
After removing all instances of "#Override", you can also add back the non-interface overrides using "Clean Up".
Steps (search/replace, then add back):
Select the projects or folders containing your source files.
Go to "Search > Search..." (Ctrl-H) to bring up the Search dialog.
Go to the "File Search" tab.
Enter "#Override" in "Containing text" and "*.java" in "File name patterns". Click "Replace...", then "OK", to remove all instances of "#Override".
Go to "Window > Preferences > Java > Code Style > Clean Up" and create a new profile.
Edit the profile, and uncheck everything except "Missing Code > Add missing Annotations > #Override". Make sure "Implementations of interface methods" is unchecked.
Select the projects or folders containing your source files.
Select "Source > Clean Up..." (Alt+Shift+s, then u), then "Finish" to add back the non-interface overrides.
Eclipse->Window->Preferences->Java->Compiler->Compiler compliance level ----> choose 1.6.
JAVA JRE 1.5 override is only superclass

How do I modify Eclipse code formatting?

When I reformat code with Eclipse, it turns method headers like this:
public void myMethod(String param) {
into method headers like this:
public void myMethod(
String param) {
When I was brought on here I'd never used Eclipse before, and I imported project settings provided by someone else. I have seen that on small new projects I've worked on Eclipse does not do this, so it must be in the settings I've imported. But I've gone through every panel I can find, as well as every hidden file I can find in the workspace, and I can't figure out what is causing this.
How do I turn it off? I don't want a newline before parameters in my method signatures, and I can't imagine why anyone would!
Have a look at Window>Preferences>Java>Code Style>Formatter.
There you can configure almost everything. Your case is found at
Line Wrapping>Method Declarations>Parameters.
In my version of Eclipse, I found the option under Window->Preferences->Java->Code Style->Formatter, then clicked the Edit.. button.
In the new window, go to the Line Wrapping tab and find Method Declarations. You want to change the Line wrapping policy. The Force split check box seems to do the same.
Go into preferences: Java -> Code Style -> Formatter
Restore Defaults or edit what's there.
Additionally, Code Style -> Code Templates will allow you to define generate code formatting.
Note that this is for Eclipse Workspace as a whole, the same Preferences can be accessed under the project preferences if you want to get more fine grained at a per project level.
In eclipse you can define your code formatting use Code Style ,
for MAC System :--> Eclipse --> Preference -- > java--> code Style
for Window System :--> Window->Preferences->Java->Code Style->Formatter
The best way to change your format is to go to Window-> Preferences-> Java-> Code Style-> Formatter. Inside the formatter window, eclipse has a couple of built in styles, but the best way is create a new profile of your own by pressing on New. You can change the format as you please on the edit tab
You can change parentheses and curly braces positioning along with other stuff.

Categories