Name | Description |
---|---|
Folder name | templates/android-java |
Invocation example | gyro -m <model> -t android-java … |
Language | Java |
If you want to use this template you need to work with Realm
.
You can use the following parameters to inject custom values to this template (using --param KEY:VALUE
on the command line):
Parameter Key | Description |
---|---|
package |
The Android package in which the generated files will be generated (e.g. "com.gyro.model.realm ") |
use_wrappers |
Define this to true if you want to use wrapper types (e.g. Boolean ) instead of primitive types (e.g. boolean ) when your attribute is optional inside xcdatamodel |
support_annotations |
Define this to true to generate @android.support.annotation s for properties (e.g. @android.support.annotation.IntRange(from=0,to=255) , @android.support.annotation.Nullable , etc) |
Package exemple :
gyro -m <model> -t android-java -o <output> --param package:com.gyro.model.realm
Use wrappers exemple :
gyro -m <model> -t android-java -o <output> --param use_wrappers:true
Support annotations exemple :
gyro -m <model> -t android-java -o <output> --param support_annotations:true
And you can combine options :
gyro -m <model> -t android-java -o <output> --param package:com.gyro.model.realm --param support_annotations:true --param use_wrappers:true
Combine options :
FidelityCard.java
:
package com.gyro.model.realm;
/* DO NOT EDIT | Generated by gyro */
import io.realm.RealmObject;
public class FidelityCard extends RealmObject {
public static final class Attributes {
public static final String IDENTIFIER = "identifier";
public static final String POINTS = "points";
private Attributes() {
// Hide constructor
}
}
public static final class Relationships {
public static final String USER = "user";
private Relationships() {
// Hide constructor
}
}
private short identifier;
@android.support.annotation.IntRange(from=0,to=255)
private Integer points;
private User user;
public short getIdentifier() {
return identifier;
}
public void setIdentifier(final short identifier) {
this.identifier = identifier;
}
@android.support.annotation.Nullable
@android.support.annotation.IntRange(from=0,to=255)
public Integer getPoints() {
return points;
}
public void setPoints(@android.support.annotation.Nullable @android.support.annotation.IntRange(from=0,to=255) final Integer points) {
this.points = points;
}
@android.support.annotation.NonNull
public User getUser() {
return user;
}
public void setUser(@android.support.annotation.NonNull final User user) {
this.user = user;
}
}
Compare to generated code without options :
FidelityCard.java
:
/* DO NOT EDIT | Generated by gyro */
import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;
public class Product extends RealmObject {
public static final class Attributes {
public static final String BRAND = "brand";
public static final String NAME = "name";
public static final String PRICE = "price";
private Attributes() {
// Hide constructor
}
}
private String brand;
@PrimaryKey
private String name;
private int price;
public String getBrand() {
return brand;
}
public void setBrand(final String brand) {
this.brand = brand;
}
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
public int getPrice() {
return price;
}
public void setPrice(final int price) {
this.price = price;
}
}