Skip to content

The library enhancing Java classes at compilation by annotations that contained in the Develhack Core Library.

License

Notifications You must be signed in to change notification settings

develhack/develhacked-lombok

 
 

Repository files navigation

Develhacked-Lombok

About

A library enhancing Java classes at compilation by annotations that contained in the Develhack Core Library. It’s powered by The Project Lombok.

This library provides following features.

Description

Injects argument check statements

If an argument is annotated, injects argument check statements as the first statement of a method or constructor.
Also, some annotations can combine with @Nullable for ignoring the check when the argument is null.

All statements generated by this feature are using the method prefixed by check that defined in the com.develhack.Conditions.
Correspondence between annotations and used method are below.

Annotation Used method Used method if combile with @Nullable

@Nonnull

checkNonnull

CAN NOT COMBINE

@Nonempty

checkNonempty

checkNonemptyIfNonnull

@Nonzero

checkNonzero

checkNonzeroIfNonnull

@Positive

checkPositive

checkPositiveIfNonnull

@Negative

checkNegative

checkNegativeIfNonnull

@ValidNumber

checkValidNumber

checkValidNumberIfNonnull

@FiniteNumber

checkFiniteNumber

checkFiniteNumberIfNonnull

@GreaterThan

checkGreaterThan

checkGreaterThanIfNonnull

@GreaterThanOrEqualTo

checkGreaterThanOrEqualTo

checkGreaterThanOrEqualToIfNonnull

@LessThan

checkLessThan

checkLessThanIfNonnull

@LessThanOrEqualTo

checkLessThanOrEqualTo

checkLessThanOrEqualToIfNonnull

@InRange

checkInRange

checkInRangeIfNonnull

Some annotations that having attributes of the comparison value, support the following types.

  • All primitive types

  • All wrapper of primitive types

  • java.math.BigInteger

  • java.math.BigDecimal

  • java.util.Date

  • Some types included java.time package

  • Some types included org.threeten.bp package of ThreeTen-Backport

Also, it accepts the following formats according to the type.

Number literal

A string representing a number literal. e.g. "1", "-1" and "1.0F".

Date time literal for java.util.Date

A string representing the date and time by such format as ISO 8601.
However, delimiters can not be omitted, and time zone can not be specified.
For example, "2015-01-01" or "2015-01-01T00:00:00".

Date time literal for java.time.* and org.threeten.bp.*

A string representing the date and time that parsable by the parse method defined on the type.

Variable reference

A string representing the variable reference.

Modifies a structure of the class to match the features

If a class or a field is annotated, modifies a structure of the class to match the features.

Correspondence between annotations and contents of modification are below.

@DTO (Applicable to classes)

  • Supplement java.io.Serializable to implemented interfaces.

  • Supplement accessors for fields defined the class.

Caution

Accessors of the transient field are not supplied by the annotation for the class. If necessary, please specify the @Accessible to the transient field individually.

Note

Visibility of all accessors will be the one specified by the attribute of the @DTO. If you want to specify a separate visibility, please specify the the @Accessible to individual fields for overridden the visibility.

@Equatable (Applicable to a class)

  • Supplement an equals method.

  • Supplement a hashCode method.

Caution

Transient fields are ignored from the equals method and hashCode method.

@Stringable (Applicable to classes)

  • Supplement a toString method.

@InitializeFieldsByConstructor (Applicable to a class)

  • Supplement constructors that takes arguments for initialize the fields.

@Serializable (Applicable to classes)

  • Supplement java.io.Serializable to implemented interfaces.

@VO (Applicable to classes)

  • Supplement java.io.Serializable to implemented interfaces.

  • Supplement getters for fields defined the class.

  • Supplement an equals method.

  • Supplement a hashCode method.

@Utility (Applicable to classes)

  • Supplement final modifier to the class.

  • Supplement an uncallable constructor.

@Accessible (Applicable to fields)

  • Supplement accessors for the field.

@ExcludedFrom (Applicable to fields)

  • Excludes the field from specified fietures.

Combination of the above

If specify the annotation that supplements the accessor for the field, and specify the annotation that represents assertion to the field together, the check argument statement is injected to the accessor.

Note

The check argument statement is injected to only the methods that is supplemented by this library.
The methods implemented by you are not injected the check argument statement.

A few configurable items

This library supports following configuration items that provided by the original Lombok. See the document of Lombok for information of those.

  • config.stopBubbling

  • lombok.addGeneratedAnnotation

  • lombok.extern.findbugs.addSuppressFBWarnings

  • lombok.accessors.prefix

Also, this library supports a few additional configuration items for Javadoc.
All of the following entry’s value will be formatted by the java.text.MessageFormat.

com.develhack.lombok.feature.getterCommentTemplate

If this entry is specified, a description of Javadoc comment to the getters that supplemented by this library will be generated.
The following parameters are specified at the time of format.

Index Value

0

A property name. e.g. a "foo" if the spplemented getter signature is getFoo().

1

A description of the field that is specified as the Javadoc comment to the field.

2 and subsequent

Attributes of @Meta if it is specified to the field.

com.develhack.lombok.feature.setterCommentTemplate

If this entry is specified, a description of Javadoc comment to the setters that supplemented by this library will be generated.
The following parameters are specified at the time of format.

Index Value

0

A property name. e.g. a "foo" if the spplemented setter signature is setFoo(Object foo).

1

A description of the field that is specified as the Javadoc comment to the field.

2 and subsequent

Attributes of @Meta if it is specified to the field.

com.develhack.lombok.feature.constructorCommentTemplate

If this entry is specified, Javadoc comment to the constructor that supplemented by this library will be generated.
The following parameters are specified at the time of format.

Index Value

0

The class name.

1

A description of the class that is specified as the Javadoc comment to the class.

2 and subsequent

Attributes of @Meta if it is specified to the class.

More information

See the develhacked-lombok-example project for more information.

Compatibility with the original Lombok

This library can coexist with the original Lombok, but can not be combine with the original Lombok.

For example, the argument check statement by the com.develhack.annotation.assertion.Nonempty is not injected to the method that will supplemented by the lombok.Setter.

Caution

@Nonnull and @Nullable will evaluated by some methods that supplemented by the original Lombok, because the original Lombok is detecting those annotations by the simple name.

Requirement

  • JDK 1.6 or higher

Usage

Usage is basically the same as the original Lombok. However, you should add the Develhack Core Library to class-path.

Maven

pom.xml
<dependency>
    <groupId>com.develhack</groupId>
    <artifactId>develhack-core</artifactId>
    <version>[0.9,1.0)</version>
    <scope>compile</scope>
</dependency>
<dependency>
    <groupId>com.develhack</groupId>
    <artifactId>develhacked-lombok</artifactId>
    <version>0.1.3</version>
    <scope>provided</scope>
</dependency>

Gradle

build.gradle
configurations {
    apt {
            visible false
    }
}

dependencies {
    compile 'com.develhack:develhack-core:0.9.+'
    apt 'com.develhack:develhacked-lombok:0.1.3'
}

sourceSets {
    main {
        java {
            compileClasspath += [ configurations.apt ]
        }
    }
    test {
        java {
            compileClasspath += [ configurations.apt ]
        }
    }
}

Eclipse IDE

Download the develhacked-lombok-0.1.3.jar from the release page. Then execute it and follow the instructions.

License

About

The library enhancing Java classes at compilation by annotations that contained in the Develhack Core Library.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 92.7%
  • HTML 6.9%
  • Other 0.4%