Generate field name constant for Android.
FieldSchema helps you accessing field name in static.
@FieldSchemaClass(name = "myTodo") public class Todo {
public String name;
public String description;
public Date createdAt;
public String version;
}
Here is generated code.
public final class FS {
public static final String mytodo_name = "name";
public static final String mytodo_description = "description";
public static final String mytodo_createdAt = "createdAt";
public static final String mytodo_version = "version";
}
You can use FS.todo_name
instead of "name"
.
Constants named {class name}_{field name}
in FS.java
. To avoid collision name, Use name
option. (The default is class name)
@FieldSchemaClass(name = "myTodo") public class Todo {
public String name;
}
Here is generated.
public final class FS {
public static final String mytodo_name = "name";
}
When using in library project, FS.java
cause collision because it has fixed package com.yatatsu.fieldschema
.
Use support apt option to avoid this, here is example.
apt {
arguments {
fieldSchemaPackage 'com.example.app'
}
}
And generate class is com.example.app.FS
. The default package is com.yatatsu.fieldschema
.
- Distributed by JitPack. Current version is
- You also need
android-apt
plugin.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
apply plugin: 'com.neenbedankt.android-apt'
dependencies {
compile 'com.github.yatatsu.FieldSchema:annotations:X.X.X'
apt 'com.github.yatatsu.FieldSchema:processor:X.X.X'
}
Copyright 2016 KITAGAWA, Tatsuya
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.