writejava4me-examples

Artifact to use as universal maven parent

Лицензия

Лицензия

Группа

Группа

com.github.sviperll
Идентификатор

Идентификатор

writejava4me-examples
Последняя версия

Последняя версия

0.3
Дата

Дата

Тип

Тип

jar
Описание

Описание

writejava4me-examples
Artifact to use as universal maven parent

Скачать writejava4me-examples

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.github.sviperll/writejava4me-examples/ -->
<dependency>
    <groupId>com.github.sviperll</groupId>
    <artifactId>writejava4me-examples</artifactId>
    <version>0.3</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.sviperll/writejava4me-examples/
implementation 'com.github.sviperll:writejava4me-examples:0.3'
// https://jarcasting.com/artifacts/com.github.sviperll/writejava4me-examples/
implementation ("com.github.sviperll:writejava4me-examples:0.3")
'com.github.sviperll:writejava4me-examples:jar:0.3'
<dependency org="com.github.sviperll" name="writejava4me-examples" rev="0.3">
  <artifact name="writejava4me-examples" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.sviperll', module='writejava4me-examples', version='0.3')
)
libraryDependencies += "com.github.sviperll" % "writejava4me-examples" % "0.3"
[com.github.sviperll/writejava4me-examples "0.3"]

Зависимости

compile (1)

Идентификатор библиотеки Тип Версия
com.github.sviperll : writejava4me jar 0.3

test (1)

Идентификатор библиотеки Тип Версия
junit : junit jar 4.11

Модули Проекта

Данный проект не имеет модулей.

writejava4me Easy code generation for Java

Works as annotation for annotation. User defines new annotation and annotate it with @GeneratesClass annotation. @GeneratesClass defines wich class will be generated.

Example

Imagine that we would like to define both checked exception and RuntimeException when checked exception can't be used.

We can write it like this:

public class MyException extends Exception {
    private final MyData valuableData;
    public MyException(String message, MyData valuableData) {
        super(message);
        this.valuableData = valuableData;
    }
    public MyData valuableData() {
        return valuableData;
    }
}

public class RuntimeMyException extends RuntimeException {
    private final MyException cause;
    public RuntimeMyException(MyException cause) {
        super(cause);
        this.cause = cause;
    }
    @Override
    public MyException getCause() {
        return cause;
    }
}

If we are going to define many exceptions pairs like this we may want to generate Runtime wrappers automatically. It will be good to have annotation for this.

@GenerateRuntimeExceptionWrapper
public class MyException extends Exception {
    private final MyData valuableData;
    public MyException(String message, MyData valuableData) {
        super(message);
        this.valuableData = valuableData;
    }
    public MyData valuableData() {
        return valuableData;
    }
}

With writejava4me it's easy to define such annotations. Here is an implementation for @GenerateRuntimeExceptionWrapper

GenerateRuntimeExceptionWrapper.java:

@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.TYPE)
@Documented
@GeneratesClass(classNameTemplateString = "Runtime{{annotated}}", classTemplateResourcePath = "RuntimeExceptionWrapper.mustache")
@interface GenerateRuntimeExceptionWrapper {
}

RuntimeExceptionWrapper.mustache located in resources folder:

package {{package}};

public class {{class}} extends RuntimeException {
    private final {{annotated}} cause;

    public {{class}}({{annotated}} cause) {
        super(cause);
        this.cause = cause;
    }

    @Override
    public {{annotated}} getCause() {
        return cause;
    }
}

See examples project for more examples

License

writejava4me is under BSD 3-clause license.

Flattr

Flattr this git repo

Installation

Use maven dependency:

<dependency>
    <groupId>com.github.sviperll</groupId>
    <artifactId>writejava4me</artifactId>
    <version>0.1</version>
</dependency>

Версии библиотеки

Версия
0.3
0.1