Tool that lists all deprecated classes/methods that are no longer used anywhere?

Related searches

I need to cleanup a some legacy code. Removing unused code is an important step.

Is there a tool that finds all deprecated code, removes all items which are still used somewhere and gives me a list of unused deprecated code?

For bonus points: Is there a tool which can find unused code non-deprecated code?

I'm aware that this is never perfect but I know for which cases I need special handling (as in DB drivers or classes that are referenced via DI).

I'm not completely certain that I understand your question. Do you want a tool that un-deprecates code that is still referenced? Any IDE will help you with that. Not automatically but removing an @Deprecated annotation is easily done with a global query-and-replace. After you have removed unused code, of course:

If all you want is to remove unused code, I have used the eclipse plugin ucdetector for this purpose in a previous project. While it does not actually remove the unused code it does give you a list of the methods, classes and constants that have no references so you can remove them yourself. This is a good thing.

As you point out yourself, there are some classes/methods that may seem to be unused using static analysis. In my opinion this makes it impossible to automate this task. You the coder will have to analyze every block of code that is reported to be unused.

If you are lucky enough to have excellent test coverage another option is to use a code coverage analysis tool, like cobertura, clover or emma.

Evaluating @Deprecated classes in Java systems with Glamorous , Marking a class as deprecated indicates that the class is no longer considered with @Deprecated and then selecting those that are not used anywhere (we ignore By default we see the list of all classes from the system. The method allModelClasses returns the group of model classes from the model. GitHub is where people build software. More than 40 million people use GitHub to discover, fork, and contribute to over 100 million projects.

I think this does what you want, but ignores @Deprecated. I seem to remember it adds an option in the project's contextual menu to find unused methods.

http://eclipse-tools.sourceforge.net/

javadoc-The Java API Documentation Generator, The Javadoc tool uses -sourcepath to look for these package names. The standard doclet does not validate the content of documentation Because of this , the Javadoc tool must be able to find all referenced classes, whether Lists class hierarchy for all packages deprecated-list.html Lists deprecated API for all� When generating the description for a deprecated API, the Javadoc tool moves the @deprecated text ahead of the description, placing it in italics and preceding it with a bold warning: "Deprecated". An @see tag (for Javadoc 1.1) or {@link} tag (for Javadoc 1.2 or later) should be included that points to the replacement method:

IntelliJ identifies them as I write them. I'm not sure if there's an option to remove them automatically.

How to Write Doc Comments for the Javadoc Tool, However, if the Javadoc tool is being used to generate documentation for a Source code files for Java classes (.java) - these contain class, interface, field, This inline tag can be used anywhere that a comment can be written, such as in the text In all three of these cases, if the method m() contains no doc comments or� Adds a comment indicating that this API should no longer be used (even though it may continue to work). The javadoc command moves deprecated-text ahead of the main description, placing it in italics and preceding it with a bold warning: Deprecated. This tag is valid in all documentation comments: overview, package, class, interface, constructor

not sure your Q is a bit hard to grasp ... StackOverflow for me it is mostly about Code problem so I assume you want a way to get all Methods with the @Deprecated Annotation...

so basically you need to look into Java Reflection ..

So, for Example, let's say you want all the Deprecated Methods in the Date Class (Java.util.Date) this is what you can do ...

Class<?> clazz = Date.class; //Getting Class Obj of the Date Class

    Method[] methods = clazz.getDeclaredMethods(); //Getting methods


    for (Method m : methods) { //Inhanced For-Loop To get them-all 
        for (Annotation a : m.getAnnotations()) {
            if (a instanceof Deprecated) {
                System.out.println(m.getName()); // gitting the Methods Names
            }
        }

    }

Deprecated List (Jenkins core 2.249 API), Deprecated since 2009-06-24, remove method after as of 1.416 Use ExtensionList.create(Jenkins, Class) As of 1.607 the approximation is no longer needed. TODO: revisit tool update mechanism, as that should be sure that we aren't downloading from anywhere unsecure. A minor release change would not break an existing code if a deprecated library method remains. Swagger 2 Annotations for Model You can use the @ApiModelProperty annotation to describe the properties of the Product model. up vote 74 down vote favorite 58. springdoc-openapi java library helps automating the generation of API documentation using

Using the Spoon library for transforming java source code:

String path = "src/main/java";
Launcher spoon = new Launcher();
spoon.addInputResource(path);
spoon.setSourceOutputDirectory(path);
spoon.addProcessor(new AbstractProcessor<CtMethod>() {
        @Override
        public void process(CtMethod method) {
                if (method.hasAnnotation(Deprecated.class)) {
                        method.delete();
                }
        }
});
spoon.getEnvironment().setPrettyPrinterCreator(() -> {
                        return new SniperJavaPrettyPrinter(spoon.getEnvironment());
                }
);
spoon.run();

See method removeDeprecatedMethods.

Java Development Tools, Virtually every programming language provides a way for programmers to The code does not have to be present for javadoc to do its thing. classes and interfaces and their relationships within one or more packages, Parentheses should only be used if the method or constructor has a non-empty parameter list, and in� Ways to find dead code: 1) not linked by anything outside. 2) hasn't been used from outside even though linked in runtime. 3) Linked & Called but never used like dead variable. 4) logically unreachable state. So linking, accessing over time, logic based, use after accessing. – Muhammad Umer Aug 19 '16 at 17:49

The javadoc tool has several command line options that are available regardless of which doclet is being used. The standard doclet adds a supplementary set of command line options. Both sets of options are described below in the options section. Related Documentation. Javadoc Enhancements for details about improvements added in Javadoc 1.2.

Marking a class as deprecated indicates that the class is no longer considered important and it might cease to exist in the future. This can help in many cases, for example when migrating APIs.

Tool that lists all deprecated classes/methods that are no longer used anywhere? 3 Good method to handle large amounts of unused or deprecated feature implemenations in code

Comments
  • Many years ago at a previous job they ran our code through a commercial obfuscator. One of the things it did was remove classes and methods that weren't used - which meant you had to point out any classes or methods that might be invoked through reflection or that were API methods so that they didn't get removed or renamed.
  • Are you interested in methods which are annotated with an @Deprecated annotatino? If so, writing a tool which lists all annotated methods + corresponding classname should be fairly trivial (using Reflections).
  • @Helper: That's only 1% of the work. The hard task is locating all call sites.
  • ucdetector seems to go in the right direction. First, I need all classes/methods which no one uses. Then, I can remove the public API from that. After that, I can check all the XML config files for classes which are still in use, etc.
  • I checked. ucdetector is what I need. It allows annotations, so I can document that something is still in use (and where).
  • These tools have since been merged into Eclipse. Any idea where this ended up?
  • I haven't seen anything like that in 3.6.1.
  • For the whole project or only the current class? I.e. does it tell you about public methods that no one calls?
  • You can find usages in the entire project, but I think it's on a class by class, method by method basis.
  • That doesn't tell whether anyone is still using this method.
  • This would also delete methods which are still being called by someone. How can I filter those out?
  • Yes, with a few more lines, created github.com/INRIA/spoon/issues/3195 for reference