walkmod-javalang-plugin

Walkmod plugin to clean unused code using the semantic analysis (imports, variables, private methods, fields, types and so on..).

License

License

GroupId

GroupId

org.walkmod
ArtifactId

ArtifactId

walkmod-dead-code-cleaner-plugin
Last Version

Last Version

1.3.3
Release Date

Release Date

Type

Type

jar
Description

Description

walkmod-javalang-plugin
Walkmod plugin to clean unused code using the semantic analysis (imports, variables, private methods, fields, types and so on..).
Project URL

Project URL

https://github.com/rpau/walkmod-clean-dead-code-plugin
Source Code Management

Source Code Management

https://github.com/rpau/walkmod-clean-dead-code-plugin

Download walkmod-dead-code-cleaner-plugin

How to add to project

<!-- https://jarcasting.com/artifacts/org.walkmod/walkmod-dead-code-cleaner-plugin/ -->
<dependency>
    <groupId>org.walkmod</groupId>
    <artifactId>walkmod-dead-code-cleaner-plugin</artifactId>
    <version>1.3.3</version>
</dependency>
// https://jarcasting.com/artifacts/org.walkmod/walkmod-dead-code-cleaner-plugin/
implementation 'org.walkmod:walkmod-dead-code-cleaner-plugin:1.3.3'
// https://jarcasting.com/artifacts/org.walkmod/walkmod-dead-code-cleaner-plugin/
implementation ("org.walkmod:walkmod-dead-code-cleaner-plugin:1.3.3")
'org.walkmod:walkmod-dead-code-cleaner-plugin:jar:1.3.3'
<dependency org="org.walkmod" name="walkmod-dead-code-cleaner-plugin" rev="1.3.3">
  <artifact name="walkmod-dead-code-cleaner-plugin" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.walkmod', module='walkmod-dead-code-cleaner-plugin', version='1.3.3')
)
libraryDependencies += "org.walkmod" % "walkmod-dead-code-cleaner-plugin" % "1.3.3"
[org.walkmod/walkmod-dead-code-cleaner-plugin "1.3.3"]

Dependencies

compile (2)

Group / Artifact Type Version
org.walkmod : javalang-compiler jar [2.0, 3.0)
org.walkmod : walkmod-core jar [1.0.0,3.0.0)

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

walkmod-dead-code-cleaner-plugin

Build Status

This is a walkmod plugin to remove unused declarations (imports, variables and private fields, methods and types) in Java source files. It applies the clean procedure in cascade. For example, if a unused method uses some types that are just used in this method, the imports related to these types are also removed.

Example

Let’s see an example. Take a look to this code. There is a private method called hello that is never referenced and also a variable in the goodBye method that also is never used.

package example;

import java.util.*;

public class Foo{
  private void hello(File file){
    ...
  }
  public void goodBye(){
    String s="bye";
    System.out.println("bye");
  }
}

What this plugins generates is the following modified code:

package example;

public class Foo{
  public void goodBye(){
    System.out.println("bye");
  }
}

Usage

Check that your walkmod version is at least 2.0.

  1. Add the walkmod-maven-plugin into your walkmod.xml as a configuration provider. This plugin will interpret your classpath accoding your pom.xml and will build your project to make the application classpath available for walkmod.

  2. Add the transformation dead-code-cleaner into your walkmod.xml.

<!DOCTYPE walkmod PUBLIC "-//WALKMOD//DTD" "http://www.walkmod.com/dtd/walkmod-1.1.dtd">
<walkmod>
    <conf-providers>
        <conf-provider type="maven"/>
    </conf-providers>
    <chain name="default">
        <transformation type="dead-code-cleaner"/>
    </chain>
</walkmod>

You can apply walkmod-dead-code-cleaner-plugin via walkmod.

$ walkmod apply

Or, you can also check which would be the modified classes typing:

$ walkmod check

Optionally, the plugin allows to select which elements are candidates to remove: private types, private methods, private fields, variables or imports:

	 <transformation type="dead-code-cleaner">
	 	<param name="removeUnusedImports">true</param>
	 	<param name="removeUnusedVariables">true</param>
	 	<param name="removeUnusedClasses">true</param>
	 	<param name="removeUnusedInterfaces">true</param>
	 	<param name="removeUnusedAnnotationTypes">true</param>
	 	<param name="removeUnusedEnumerations">true</param>
	 	<param name="removeUnusedMethods">true</param>
	 	<param name="removeUnusedFields">true</param>
	 </transformation>

Contributing

If you want to hack on this, fork it, improve it and send me a pull request.

To get started using it, just clone it and call mvn install.

Versions

Version
1.3.3
1.3.2
1.3.1
1.3.0
1.2.0
1.1.0
1.0.3
1.0.2
1.0.1
1.0.0