Skip to content

high-stakes/AutoInterface

Repository files navigation

AutoInterface - Java annotation processor

Build Status Maven Central Bintray

  • Generate Java interfaces from annotated class files based on their public methods.
  • Generate Decorator interface for classes or interfaces

Benefits

  • No need to manually maintain interfaces when there is only a single implementation
  • Help with dependency injection for frameworks such as Spring
    • Spring runtime injection requires an Interface by default, otherwise spring uses a CGLIB proxy.
      By auto-generating interfaces you do not need to use CGLIB and be limited by it.
  • Help with 3rd party generated code or classes you want to keep final

Usage

//Reference dependency
dependencies {
  annotationProcessor 'io.github.high-stakes:autointerface:<version>'
}
//Annotated the class you wish to generate an interface for
@AutoInterface(createDecorator=true)
public final class MyClass {
  public void myMethod() {}
}

//Generates
public interface MyClassInterface {
  void myMethod();
}
public interface MyClassDecorator extends MyClassInterface {
  MyClassInterface getDecoratedObject();
  
  void myMethod() {
    getDecoratedObject().myMyethod();
  }
}

About

Generate Java interface source code automatically

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages