io.slugstack.rewritejavarecipes.EncapsulateData Maven / Gradle / Ivy
Show all versions of rewrite-java-recipes Show documentation
package io.slugstack.rewritejavarecipes;
import org.openrewrite.ExecutionContext;
import org.openrewrite.Recipe;
import org.openrewrite.TreeVisitor;
/**
* Performs information hiding by transforming "public"-visibility fields to
* "private", generating getField() and setField(..) methods on the declaring
* class, and updating consumer references to these once-public fields to use
* their accessor methods.
*
* If a field is declared "public static final", it is left untouched.
*
* If a field is declared "public final", only the field's "getField()" method
* is generated, not it's "setField(..)".
*/
public class EncapsulateData extends Recipe {
@Override
public String getDisplayName() {
return "Encapsulate data";
}
@Override
public String getDescription() {
return "Performs information hiding by transforming 'public'-visibility fields to 'private', generating getField() and setField(..) methods on the declaring class, and updating consumer references to these once-public fields to use their accessor methods.";
}
@Override
protected TreeVisitor, ExecutionContext> getVisitor() {
return new EncapsulateDataVisitor<>();
}
}