0

Is there a setting that instructs Netbeans to add missing @Override annotations automatically on save, or in particular, on generated code from the GUI builder?

I'm using netbeans 8.1

1 Answers1

0

Im not certain about a feature to auto complete them all however any missing override annotations in net-beans are usually detected as a "hint" in the interface appearing on the left side as a yellow triangle. However the net-beans website outlines this better than my description: Netbeans

However that works as far as i can tell only on a single method, there is also allegedly a refactor feature that highlights them all however i was unable to find it, outlined here: informit.

Override and Implement Methods dialog box. You can use this dialog box (shown in Figure 5-8) for generating any combination of the available implementable or overridable methods. This feature also enables you to generate calls to the super implementation of the methods within the body of the generated methods. To open this dialog box, choose Source | Override Methods or press Ctrl-I. To select multiple methods, use Ctrl-click.

However the method I have been using for problems such as these that i would recommend would be to go to source -> inspect and if required install the bug inspection plug-in. This will analyze your code and outline all the methods in it that could be overridden. However there may be another way, native to net-beans i have missed. Good luck, and hope i helped at-least in some regard :)

D3181
  • 2,037
  • 5
  • 19
  • 44
  • Looks like this functionality is unavailable as of 7.3, and my onsave menu is very similar. Eclipse has this functionality but the autoformatter breaks my GUI code. https://blogs.oracle.com/geertjan/entry/save_actions_in_netbeans_ide For regular code, doing them manually is fine for me. Once they're there they'll probably stay there, and sonarqube will root them all out for me at once. My big issue is that for generated code, which I can't edit manually. If I knew how one goes about customising the options for the GUI builder that would go a long way I think. – Marcus Wilson Jun 27 '16 at 19:26
  • Ah right, well iv still had success in netbeans 8.1 with clicking the source tab and then inspect and installing the recommended bug finder plugin. After going back into source->inspect it then outlines all the hints for me in a single page and allows me to correct them all via a tick box as shown here : [link] (https://netbeans.org/kb/docs/java/code-inspect.html) in the Setting Up the Tutorial Environment section. – D3181 Jun 27 '16 at 19:31
  • as a side Note :If the reason you cant use this is because of the generated code maybe try the steps from this post to disable the block : [link](http://stackoverflow.com/questions/17131589/how-to-change-non-editable-generated-code-in-netbeans) – D3181 Jun 27 '16 at 19:38
  • Refactor > Inspect and Transform has the tool I need to auto add the annotations for regular code, unfortunately it refuses to edit the read-only blocks of code from the GUI editor. That gets me halfway there at least. Thanks @Dean219. – Marcus Wilson Jun 27 '16 at 19:56
  • No worries, but according to the link i posted the read-only blocks can be removed by editing the file in a regular text editor and removing these tags : //GEN-BEGIN:initComponents //GEN-END:initComponents im not sure if this is true, but could be worth looking into and maybe make a script or something if necessary to remove them, though i feel there must be an easier answer. Good luck Marcus :) – D3181 Jun 27 '16 at 22:22