Skip to content

Repository files navigation

Java - NoOp Build Status

This is probably one of the simplest Java annotation processing libraries out there.

It generates no-op implementations of your interfaces.

  • Supports Generics & Multiple Inheritance

Usage

  • Simply annotate your interface with @NoOp like this:
@NoOppublicinterfaceTestInterface {
byteaByte();
shortaShort();
intanInt();
longaLong();
floataFloat();
doubleaDouble();
charaChar();
booleanaBoolean();
StringaString();
voidaVoid();
}
  • And it will generate the following no-op implementation at compile time:
publicclassNoOpTestInterfaceimplementsTestInterface {
publicstaticfinalTestInterfaceINSTANCE = newNoOpTestInterface();
@OverridepublicbyteaByte() {
return (byte) 0;
}
@OverridepublicshortaShort() {
return (short) 0;
}
@OverridepublicintanInt() {
return0;
}
@OverridepubliclongaLong() {
return0L;
}
@OverridepublicfloataFloat() {
return0.0F;
}
@OverridepublicdoubleaDouble() {
return0.0D;
}
@OverridepubliccharaChar() {
return '';
}
@OverridepublicbooleanaBoolean() {
returnfalse;
}
@OverridepublicStringaString() {
returnnull;
}
@OverridepublicvoidaVoid() {
}
publicstaticTestInterfacenoOpTestInterface() {
returnINSTANCE;
}
}

The implemented methods return the default data type value as per Java Data Types:

Data typeDefault value
byte0
short0
int0
long0L
float0.0F
double0.0D
char'\u0000'
String (or any object)null
booleanfalse
  • It also supports Generics (bounded/unbounded) and multiple inheritance of interfaces:
@NoOppublicinterfaceTestInterface<A, B, CextendsThrowable> extendsTestInterface2, TestInterface3 {
AgenericA();
BgenericB();
CgenericC();
}
interfaceTestInterface2 {
voidfromTestInterface2();
}
interfaceTestInterface3 {
voidfromTestInterface3();
}
  • Generated no-op implementation:
publicclassNoOpTestInterface<A, B, CextendsThrowable> implementsTestInterface<A, B, C> {
@OverridepublicAgenericA() {
returnnull;
}
@OverridepublicBgenericB() {
returnnull;
}
@OverridepublicCgenericC() {
returnnull;
}
@OverridepublicvoidfromTestInterface2() {
}
@OverridepublicvoidfromTestInterface3() {
}
}

Download

Gradle (using apt):

def noOpVersion ='1.2.0'
compile "com.jenzz.noop:annotation:$noOpVersion"
apt "com.jenzz.noop:processor:$noOpVersion"

Maven (using maven-compiler-plugin):

<dependency>
<groupId>com.jenzz.noop</groupId>
<artifactId>annotation</artifactId>
<version>1.2.0</version>
</dependency>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<dependencies>
<dependency>
<groupId>com.jenzz.noop</groupId>
<artifactId>processor</artifactId>
<version>1.2.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>

Snapshot versions are available in Sonatype's SNAPSHOTS repository.

License

This project is licensed under the MIT License.

About

Easy no-op Java interface implementations

Resources

Stars

22 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages