This small library generates standard implementations of a given interface:
@Noop
generates a class that does nothing and returned default values (0 ornull
). Classes of that kind are often used as base for classes that handle only some event/method calls of the annotated interface.@Decor
generates a class that passes all calls to another implementation of the interface. Really useful to create decorators.@Factory
generates a factory interface that provides instance of the marked interface. Mostly used in Android when a Fragment expects it Activity to provide it with an instance.
package com.company.example;
@Noop
@Decor
@Factory
interface Example {
void setProperty(String value);
String calculateSomething(String param, int thistoo);
}
The generated code will look like this:
package com.company.example;
/**
* @Generated ..
*/
public class NoopExample implements Example {
void setProperty(String ignored) { }
String calculateSomething(String ignore1, int ignored2) {
return null;
}
}
This annotation has 2 attributes:
- The name of the class, which can be defined in the
value
attribute. - Specifying the attribute
mutable
astrue
will generate a setter for the decorated property, so it can be changed after creation.
package com.company.example;
/**
* @Generated ..
*/
public class DecoratingExample implements Example {
private final Example decorated;
public DecoratingExample(@NonNull Example decorated) {
this.decorated = decorated;
}
void setProperty(String value) {
decorated.setProperty(value);
}
String calculateSomething(String param, int thistoo) {
return decorated.calculateSomething(param, thistoo);
}
}
package com.company.example;
/**
* @Generated ..
*/
public class ExampleFactory {
Example createExample();
}
Thanks Travis-CI for providing a build system. The status of the last master build:
The binaries are also available thanks to Jitpack. The latest release there is .
> gradlew build
builds the app
> gradlew install
places it in the local Maven repository.
That means creating a release version and prepare it for the next release increment. That includes setting up its SCM.
Releases are tagged with their version number (e.g. release 5.3.2 is build from he version tagged 5.3.2
in Git).
-
Checkout the head of
master
and start a command prompt -
Run pre-release checks. Do a full build to ensure the code is good to be released.
> ./gradlew build
-
Release (assuming authentication with SSH keys is already setup. If not, Bitbucket explained it well here):
> ./gradlew release
Make sure the last output line indicates it's been pushed to origin.
To set the release number, rather than accept the usual bug-level increment, add the following property on the command line:
-Prelease.forceVersion=k.m.n
-
Build the release version of the app to take the new version number into account:
> ./gradlew build install
That is only needed if you do not want to wait for Jitpack to finish its build.
The overall command is quite simple:
> ./gradlew build release
Generate a decorator for non-final classes with non-final public methods.
Only source download available, from this site! Releases are tagged.
To use, download the source for the version of interest, build it and install it in your local Maven repository. Then, in a Maven project:
<dependency>
<groupId>com.github.pijpijpij.noopetal</groupId>
<artifactId>noopetal-annotations</artifactId>
<version>1.2.9</version>
</dependency>
<dependency>
<groupId>com.github.pijpijpij.noopetal</groupId>
<artifactId>noopetal-compiler</artifactId>
<version>1.2.9</version>
<scope>provided</scope>
</dependency>
or Gradle for an Android project:
dependencies {
compile 'com.github.pijpijpij.noopetal:noopetal-annotations:1.2.9'
annotationProcessor 'com.github.pijpijpij.noopetal:noopetal-compiler:1.2.9'
}
With an older Android Gradle plugin, use Hugo Visser's apt
instead of
annotationProcessor
.
Finally, I started that project from Butterknife's annotation processor.
Copyright 2015 PJ Champault
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Image by Brenda Clarke. Not sure what the license is, but it's available for public download, so I'll assume I can use it.
Inspiration from Butterknife
Copyright 2013 Jake Wharton
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Annotation processing tools from Google. Apache still rocks! ...