Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/victornoel/eo-envelopes

Elegant Objects Envelopes
https://github.com/victornoel/eo-envelopes

annotation-processing java java-library oop oop-library oop-principles

Last synced: 3 months ago
JSON representation

Elegant Objects Envelopes

Awesome Lists containing this project

README

        

![Build Status](https://github.com/victornoel/eo-envelopes/actions/workflows/build.yaml/badge.svg?branch=master)
[![Maven Central](https://img.shields.io/maven-central/v/com.github.victornoel.eo/eo-envelopes.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.github.victornoel.eo%22%20AND%20a%3A%22eo-envelopes%22)
![OSS Sonatype](https://img.shields.io/nexus/s/com.github.victornoel.eo/eo-envelopes?label=OSS%20Sonatype&server=https%3A%2F%2Foss.sonatype.org)

# Elegant Objects Envelopes

Distributed under the GPL 3.0.

Note that the output of the processor is not covered by this license and can be used without any restrictions.

## Why

See http://www.yegor256.com/2017/01/31/decorating-envelopes.html for an explanation of the requirements.

## How

For the latest version, see the Maven Central badge at the top, SNAPSHOTs are deployed to OSS Sonatype.

Add the following dependency:

```xml

com.github.victornoel.eo
eo-envelopes-annotations

provided

```

And the processor:

```xml




maven-compiler-plugin



com.github.victornoel.eo
eo-envelopes






```

Enable Annotation Processing in your IDE to take advantage of it during development.

Simply annotate your interfaces with `@GenerateEnvelope` and an envelope class will be generated for it.
You can now extend it to write a decorating envelope without managing the delegation yourself.

## What

```java
package test;

import com.github.victornoel.eo.GenerateEnvelope;

@GenerateEnvelope
public interface Test {
String lol(int ab);
void lol(Double a) throws Exception;
}
```

Gives you:

```java
package test;

import java.lang.Double;
import java.lang.Exception;
import java.lang.Override;
import java.lang.String;

public abstract class TestEnvelope implements Test {
protected final Test wrapped;

public TestEnvelope(Test wrapped) {
this.wrapped = wrapped;
}

@Override
public final String lol(int ab) {
return wrapped.lol(ab);
}

@Override
public final void lol(Double a) throws Exception {
wrapped.lol(a);
}
}
```

Inner interfaces are also supported:

```java
package test;

import com.github.victornoel.eo.GenerateEnvelope;

public class AClass {

@GenerateEnvelope
public interface Test {

String lol(int ab);

void lol(Double a) throws Exception;
}
}
```

Gives you

```java
package test;

import java.lang.Double;
import java.lang.Exception;
import java.lang.Override;
import java.lang.String;
import javax.annotation.Generated;

@Generated("com.github.victornoel.eo.apt.GenerateEnvelopeProcessor")
public abstract class AClassTestEnvelope implements AClass.Test {
protected final AClass.Test wrapped;

public AClassTestEnvelope(AClass.Test wrapped) {
this.wrapped = wrapped;
}

@Override
public final String lol(int ab) {
return wrapped.lol(ab);
}

@Override
public final void lol(Double a) throws Exception {
wrapped.lol(a);
}
}
```