I work on a code base that is ... messy. One aspect of this messiness is that we have a ton of methods whose signatures no longer match the associated Javadoc. For instance:
/**
*
* # param foo
*/
public void doFoo(int bar) {...
I'm no fan of generated Javadoc (as it's almost always worthless), but I really could use a tool that would go through our code, find cases like that, and:
remove the javadoc for the "foo" param
add javadoc for the "bar" param (but just a blank one, no auto-generated doc or anything)
Does such a tool exist? If not, does a tool that just does #1 exist? Even that much would significantly reduce the amount of garbage warnings we get in our builds. Thanks.
NetBeans has a tool for that. It does exactly what you ask.
You can either click on the Tools Menu, then Analyze Javadocs from the top,
or right click on a file and click Tools, then Analyze Javadocs.
This then give you a list of all problems it finds with your Javadocs with an option to fix it. It allows you to fix a single problem in a method, fix the javadocs for the method, for the file, for the package, or for the entire project.
One solution, if you're using eclipse, is to go to Window -> Preferences -> Java -> Compiler -> Javadoc
and then set the 'Malformed Javadoc comments' variable to warning or error.
You can then go to the problems view Window -> Show View -> Problems and then on each error right click and select 'Quick Fix'.
I have not tried any of these other than DocCheck, but this somewhat-dated page on Sun's site lists several third-party doclets, some of which purport to insert Javadoc into your source. Of those, you might take a look at Doc-o-Matic, JRefactory Pretty Printer, and ACTOS Auto Commentator for Java. Again, I have not tried any of these, but it's a place to start.
Related
I'm considering switching from Eclipse to IntelliJ IDEA, but there's one thing holding me back: the autocomplete. Eclipse shows me all the information I want from the start whereas IntelliJ holds back some information. The only thing I'm still missing is separate entries in code completion for each constructor signature. And I believe it's pretty weird that's missing since method signatures are done separately.
My question being, is it possible (am I overlooking something) to get IntelliJ to show separate entries for each signature for constructors WITH documentation, instead of just showing the class name and making you figure out afterwards if you're even in the right place or not.
Eclipse way of showing (preferred)
IntelliJ IDEA way of showing (not preferred)
This answer is base on IDEA version 2021.2.2
In the Settings -> Editor -> General -> Code Completion, check Show parameter name hints on completion under Parameter Info session.
Combine with Ctrl + Q, you can view the javadoc for each constructor.
Type the class name and the parenthesis. Inside parenthesis, type Ctrl+P. Eg: new BufferedWriter( <ctrl+P> )
In fact you can type, ctrl+P to get details of any function, not just constructor.
It is also possible to show overloaded constructors by enabling a hidden option. Invoke the Help | Find Action menu item and type Registry to go to the Registry. Here enable the java.completion.show.constructors option.
Copied From: https://stackoverflow.com/a/43639241/2920861
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.
can I has fulltext autocompletion for Java # Eclipse? Let's demonstrate:
Final piece of code:
getVariants().add(new Variant(MediaType.TEXT_XML));
How do I code now:
getv[ctrl+space].a[Enter]new
V[ctrl+space, down arrow,
Enter]M[Ctrl+Space, Enter].text_x
Basically, Eclipse completes word "TEXT_XML" when I provide letters "TEXT_X".
How would I like to code:
getv[ctrl+space].a[Enter]new
V[ctrl+space, down arrow,
Enter]M[Ctrl+Space, Enter].xml
and Eclipse should realise I meant "TEXT_XML" (fulltext autocompletion).
As far as I'm aware, there is no way of enabling a full-text code completion in the Eclipse preferences view. This has been bugging me for a while, too. I did quite a bit of digging and I'm pretty certain there is no easy way of achieving this.
However,
there are two ways of implementing the desired, but I assume both of which are way to much work for fixing this little nuisance.
There is an Eclipse plug-in extension point for the JDT Java Completion Proposal Computer - reference page
A sample project which implements this extension point can be found in this repository.
This is fairly convenient, but still a lot of boilerplate and tedious coding.
You can change the findKeywords method in the internal org.eclipse.jdt.internal.codeassist.CompletionEngine class and compile your own JDT fork. But this is discouraged for so many reasons. First of all, this class is a 12000 line monster and hard to just jump in. And of course, if you'd only hack a kludge in, there is little chance of this becoming an official contribution, so you'd need to worry about every eclipse release.
Additionally, there might be a very chillaxed way in the future. Although this might exceed your requirements a bit.
Have a look at the Code Recommenders project. This blog has an outline of the project objectives
It doesn't mention full-text auto-completion specifically, but I'd assume its matching algorithms go even beyond that.
Edit: In the proper SO-spirit, I'll keep this answer up to date:
Apparently the feature is now implemented in the Code Recommenders plug-in. See this blog post and this forum thread. I'm quite surprised it only took 10 locs. To me the extension point appeared more complex.
If your MediaType class does not contain a large number of accessible fields/methods you could simply use
getv[ctrl+space].a[Enter]new V[ctrl+space, down arrow, Enter]M[Ctrl+Space, Enter].[Ctrl+Space, down arrow, Enter]
you may need to press the down arrow more than once, though to select the desired field.
Yes, you can using Templates. (Window -> Preferences -> Java -> Editor -> Templates)
The basic usage is you set the name to what you want to type and you set the pattern to what you want to appear.
In my testing I set the name to xml, the Context to Java, the Pattern to TEXT_XML and Automatically insert turned on. Then when I typed out your example I was able to follow a pattern like...
getv[ctrl+space].a[enter]new V[ctrl+space, down arrow, Enter]M[ctrl+Space, Enter].xml[ctrl+space]
and since Automatically insert was turned on poof TEXT_XML was inserted.
Templates have much more functionality than that and the one source I used for this answer was Effective Eclipse.
I hope this helps!
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
I often have to debug Java code which was written so that there is an interface and exactly one implementation of that interface.
For instance there would be an interface Foo with exactly one implementation called FooImpl. In the following code if I Ctrl-click on doThings it'll jump to Foo.java when I actually want to go to FooImpl.java to see the implementation.
public void doStuff(Foo foo) {
foo.doThings();
}
When I end up at the interface I have to use Ctrl-Shift-R to open up FooImpl. It'd be really nice if I could do something lick Ctrl-Alt-click on doThings and end up inside FooImpl.java. If there are multiple implementations in the workspace then perhaps it would just pop up a box telling me what they are.
Is there a plugin or existing function in eclipse that does this? I know that I could go to Foo.java and then get the hierarchy and go to the implementation, but that's more clicks than are necessary when there is exactly one implementation of an interface.
Move the cursor to the method call
Press Ctrl + T
Select your desired implementation
Hit Enter
This also works if there are several implementors.
Go to Window > Preferences > General > Editors > Text Editors > Hyperlinking, and uncheck Open Declaration.
From now on, when you hold Ctrl while hovering over a method name, the following popup will be displayed. Just click on the method name and the implementation will be opened (or a Types implementing XXX box, if more than one implementation exists).
You will still be able to use the Open Declaration feature by pressing F3.
In Eclipse 3.5, when you hover over doThings while holding down the control key, a pop up box gives you two options to click on:
Open Declaration
Open Implementation
There's a screenshot as the second section of the Eclipse 3.5 New & Noteworthy page for JDT:
The Implementors plugin does pretty much exactly what you ask for. If there is only one implementation it will open it directly, otherwise it will let you choose.
In Eclipse IDE for C/C++ Developers Version: Oxygen.3a Release (4.7.3a) I saw Ctrl+Tab (Toggle Source/Header) which worked for me (although not directly but its a workaround).