Skip to content

A Kotlin annotation processor to generate a list of class fields.

License

Notifications You must be signed in to change notification settings

peter-tackage/jonty

Repository files navigation

Jonty

Build Status Release

A simple Kotlin/Java annotation processor to generate a list of a class field names.

For example:

@Fieldable
public class User {
    private final List<Profile> profiles;
    private final String username;
    private final String password;
    private final Date lastLogin;
    
    // etc...
}

Jonty will generate an object in a Kotlin file in the User class' package:

object User_JontyFielder {
  @JvmField
  val FIELDS: Iterable<String> = setOf("profiles", "username", "password", "lastLogin")
}

Which can be accessed via:

val fields = User_JontyFielder.FIELDS

or

Iterable<String> fields = User_JontyFielder.FIELDS

Usage

Just annotate your Java/Kotlin class with the @Fieldable annotation and Jonty will generate a class based upon your class name.

There are no restrictions on class or field access modifiers.

If the class is a child class, then the unique field names for all parent classes will also be added.

Static fields are ignored.

Download

Available via Jitpack.

For Gradle, add kapt3 plugin:

apply plugin: 'kotlin-kapt'

Add to your Jitpack to your project repository configuration"

maven { url "https://jitpack.io" }

Add these dependencies:

compileOnly "com.github.peter-tackage.jonty:jonty:<latest-version>"
kapt "com.github.peter-tackage.jonty:jonty-processor:<latest-version>"

See freesound-android for a full working example.

Why Jonty?

Because of the fielding (terrible pun, I know) done here.

Development

To locally test changes to Jonty, use the example-local module, which imports the module directly, rather than going through Jitpack.

To do this, uncomment this line in settings.gradle -

// Uncomment to test locally.
//include 'example-local'

Acknowledgements

Brought to you by the power of the Chilicorn and the Futurice Open Source Program.

Chilicorn Logo

License

Copyright 2017 Peter Tackage

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.