giftwrap

An annotation processor that creates decorators.

License

License

Categories

Categories

SBE Data Data Structures
GroupId

GroupId

com.github.andrasbeni
ArtifactId

ArtifactId

giftwrap-parent
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

pom
Description

Description

giftwrap
An annotation processor that creates decorators.
Project URL

Project URL

https://github.com/andrasbeni/giftwrap
Source Code Management

Source Code Management

https://github.com/andrasbeni/giftwrap.git

Download giftwrap-parent

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.andrasbeni/giftwrap-parent/ -->
<dependency>
    <groupId>com.github.andrasbeni</groupId>
    <artifactId>giftwrap-parent</artifactId>
    <version>1.0.0</version>
    <type>pom</type>
</dependency>
// https://jarcasting.com/artifacts/com.github.andrasbeni/giftwrap-parent/
implementation 'com.github.andrasbeni:giftwrap-parent:1.0.0'
// https://jarcasting.com/artifacts/com.github.andrasbeni/giftwrap-parent/
implementation ("com.github.andrasbeni:giftwrap-parent:1.0.0")
'com.github.andrasbeni:giftwrap-parent:pom:1.0.0'
<dependency org="com.github.andrasbeni" name="giftwrap-parent" rev="1.0.0">
  <artifact name="giftwrap-parent" type="pom" />
</dependency>
@Grapes(
@Grab(group='com.github.andrasbeni', module='giftwrap-parent', version='1.0.0')
)
libraryDependencies += "com.github.andrasbeni" % "giftwrap-parent" % "1.0.0"
[com.github.andrasbeni/giftwrap-parent "1.0.0"]

Dependencies

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

giftwrap

Build Status

A Dagger 2 inspired wrapper generator library

giftwrap generates decorator classes at compile-time

Usage

Create the annotation

@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.METHOD)
@InterceptedBy(LoggerInterceptor.class)
public @interface Logged {

	LogLevel value() default LogLevel.DEBUG;
	
}

Create the corresponding interceptor

public class LoggerInterceptor implements Interceptor<Logged> {

	private static final Logger logger = Logger.getLogger("entrylogger");
	
	@Override
	public Object intercept(Interception<Logged> interception) throws Exception {
		Level level = interception.getAnnotation().value().julLevel();
		logger.log(level, "Entering method " + interception.getMethodName());
		return interception.proceed();
	}

}

Annotate your class

@GiftWrap
public class Whatever {

	@Logged(LogLevel.DEBUG)
	@Transactional
	public String doWhatever(String result) throws IOException {
		return result;
	}

}

Instantiate the wrapper

Whatever object = new WhateverIntercepted(
        contructor, arguments, ofWhatever,
		new LoggerInterceptor(), 
		new TransactionInterceptor());

Have a look at the stack

c.g.a.g.example.Whatever.doWhatever(Whatever.java:20)
c.g.a.g.example.WhateverIntercepted.access$0(WhateverIntercepted.java:1)
c.g.a.g.example.WhateverIntercepted$1.call(WhateverIntercepted.java:21)
c.g.a.g.Interception.proceed(Interception.java:32)
c.g.a.g.example.LoggerInterceptor.intercept(LoggerInterceptor.java:18)
c.g.a.g.InterceptorCallable.call(InterceptorCallable.java:27)
c.g.a.g.Interception.proceed(Interception.java:32)
c.g.a.g.example.TransactionInterceptor.intercept(TransactionInterceptor.java:10)
c.g.a.g.InterceptorCallable.call(InterceptorCallable.java:27)
c.g.a.g.example.WhateverIntercepted.doWhatever(WhateverIntercepted.java:35)

Versions

Version
1.0.0