writejava4me-maven-parent

Artifact to use as universal maven parent

License

License

Categories

Categories

Maven Build Tools
GroupId

GroupId

com.github.sviperll
ArtifactId

ArtifactId

writejava4me-maven-parent
Last Version

Last Version

0.3
Release Date

Release Date

Type

Type

pom
Description

Description

writejava4me-maven-parent
Artifact to use as universal maven parent
Project URL

Project URL

http://maven.apache.org
Source Code Management

Source Code Management

https://github.com/sviperll/writejava4me

Download writejava4me-maven-parent

How to add to project

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

Dependencies

test (1)

Group / Artifact Type Version
junit : junit jar 4.11

Project Modules

  • writejava4me
  • writejava4me-examples

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>

Versions

Version
0.3
0.1