org.dmfs.srcless.annotations.composable.Composable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of srcless.annotations Show documentation
Show all versions of srcless.annotations Show documentation
Generate code too trivial to write it down.
The newest version!
package org.dmfs.srcless.annotations.composable;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Generate an abstract class for compositions.
*
* The resulting class is abstract. Its constructor takes an instance of the same type and each method is final and delegates to the same
* method of the delegate.
*
*
Example
*
*
* {@literal @}Composable
* public interface FooBar<T>
* {
* void foo(T foo);
*
* T bar(String bazz) throws IOException;
* }
*
*
* will generate this code
*
*
{@code
* public abstract class FooBarComposition implements FooBar {
* private final FooBar mDelegate;
*
* public FooBarComposition(FooBar delegate) {
* mDelegate = delegate;
* }
*
* public final void foo(T foo) {
* mDelegate.foo(foo);
* }
*
* public final T bar(String bazz) throws IOException {
* return mDelegate.bar(bazz);
* }
* }
* }
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.SOURCE)
public @interface Composable
{
/**
* The package name of the generated class.
*
* Defaults to the package name of the annotated interface.
*/
String packageName() default "";
/**
* The name of the generated class.
*
* Defaults to the name of the annotated interface plus the word "Composition".
*/
String className() default "";
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy