This repository has been archived by the owner on Dec 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Improve template android #25
Merged
Merged
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
fc9eddf
Allow direct local execution
f6d7390
Improve templates
4831299
Avoid useless enum member
3ad447b
Hide setter and getter for fields with enum values
5619f20
Better template for enums
36da2b3
Fix issue
39fecd8
Fix issue with hide_members_with_enum not working
9547fe8
Class with private constructor have to be final
edbd7af
Improve template
111f622
Fix Java fixtures
ca726c0
fix issue with annotations
7a18b1c
Fix regression with annotations
3d7afa3
Fix all java fixture
2c36a52
Fix issue with extra empty lines
e35b51f
Fix issue on comment. Note: comment on relationship does not work
5660490
Fix rubocop offenses
30195e6
Fix rubocop offense
313fdbe
Fix sonar issue about order of elements
67f750c
Fix sonar issue about order of elements - update unitary tests
5db3b98
fix injected params check
StevenWatremez c552aaa
fix primitive anotations
StevenWatremez 3325f3a
remove $LOAD_PATH
StevenWatremez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,49 @@ | ||
{%- capture imports -%} | ||
{%- if params.package.size > 0 -%} | ||
package {{ params.package }}; | ||
{% endif -%} | ||
{%- endif %} | ||
|
||
/* DO NOT EDIT | Generated by gyro */ | ||
{{ empty_line }} | ||
{%- if entity.has_json_key_path == true %} | ||
import com.google.gson.annotations.SerializedName; | ||
{%- endif -%} | ||
{% comment %} *** Empty line *** {% endcomment %} | ||
{%- endif %} | ||
{%- if entity.has_date_attribute == true %} | ||
import java.util.Date; | ||
{%- endif -%} | ||
{%- endif %} | ||
{%- if entity.has_list_relationship == true %} | ||
import java.util.List; | ||
{%- endif -%} | ||
{%- endif %} | ||
{%- if entity.has_date_attribute == true or entity.has_list_relationship == true %} | ||
{{ empty_line }} | ||
{%- endif %} | ||
{%- if entity.has_list_attributes == true %} | ||
import io.realm.RealmList; | ||
{%- endif %} | ||
import io.realm.RealmObject; | ||
{%- if entity.has_ignored == true or entity.has_enum_attributes == true %} | ||
{%- if entity.has_ignored == true %} | ||
import io.realm.annotations.Ignore; | ||
{%- endif -%} | ||
{%- endif %} | ||
{%- if entity.has_indexed_attributes == true %} | ||
import io.realm.annotations.Index; | ||
{%- endif -%} | ||
{%- endif %} | ||
{%- if entity.has_primary_key == true %} | ||
import io.realm.annotations.PrimaryKey; | ||
{%- endif %} | ||
{%- endcapture -%} | ||
|
||
{{ imports }} | ||
|
||
/* DO NOT EDIT | Generated by gyro */ | ||
|
||
{% if entity.comment.size > 0 -%} | ||
/** | ||
* {{ entity.comment }} | ||
*/ | ||
{%- endif %} | ||
{% endif %} | ||
{%- assign primary_key = entity.identity_attribute -%} | ||
public class {{ entity.name }} extends RealmObject { | ||
|
||
{%- include 'inc/attributes_enum' %} | ||
{%- include 'inc/relationships_enum' %} | ||
{%- include 'inc/attributes_properties' %} | ||
{% include 'inc/attributes_properties' %} | ||
{%- include 'inc/relationships_properties' %} | ||
{%- include 'inc/attributes_getter_setter' %} | ||
{%- include 'inc/relationships_getter_setter' %} | ||
{%- include 'inc/enum_getter_setter' %} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
{%- if entity.attributes.size > 0 %} | ||
|
||
public static class Attributes { | ||
private Attributes() { | ||
// Hide constructor | ||
} | ||
{% for attribute in entity.attributes -%} | ||
public static final class Attributes { | ||
{%- for attribute in entity.attributes -%} | ||
{%- if attribute.realm_ignored == false or attribute.read_only == false -%} | ||
{%- if attribute.comment.size > 0 -%} | ||
/** {{ attribute.comment }} */ | ||
{%- if attribute.comment.size > 0 %} | ||
// {{ attribute.comment }} | ||
{%- endif %} | ||
public static final String {{ attribute.name | snake_case | upcase }} = "{{ attribute.name }}"; | ||
{%- endif -%} | ||
{%- endfor %} | ||
|
||
private Attributes() { | ||
// Hide constructor | ||
} | ||
} | ||
{%- endif -%} |
65 changes: 42 additions & 23 deletions
65
lib/templates/android/inc/_attributes_getter_setter.liquid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,58 @@ | ||
{%- for attribute in entity.attributes %} | ||
|
||
{% if attribute.realm_read_only.size == 0 -%} | ||
{%- if attribute.realm_read_only.size == 0 %} | ||
{%- comment %} ******* CONVERT TYPE CAPTURE ******* {% endcomment -%} | ||
{%- capture convert_type -%} | ||
|
||
{%- capture visibility %} | ||
{%- if attribute.enum_type.size > 0 and params.hide_members_with_enum.size > 0 -%} | ||
protected | ||
{%- else -%} | ||
public | ||
{%- endif %} | ||
{%- endcapture %} | ||
|
||
{%- capture convert_type %} | ||
{%- if attribute.realm_read_only.size == 0 and attribute.enum_type.size > 0 -%} | ||
String | ||
{%- else -%} | ||
{%- if params.use_wrappers == true -%} | ||
{%- if params.use_wrappers.size > 0 and attribute.optional == true -%} | ||
{%- include 'inc/wrapper_type_converter' -%} | ||
{%- else -%} | ||
{%- include 'inc/type_converter' -%} | ||
{%- endif %} | ||
{%- endif %} | ||
{%- endcapture %} | ||
|
||
{%- capture isPrimitives %} | ||
{%- include 'inc/primitives' %} | ||
{%- endcapture %} | ||
|
||
{%- capture annotation %} | ||
{%- if params.support_annotations.size > 0 %} | ||
{%- if isPrimitives == "false" -%} | ||
{%- if params.use_wrappers.size > 0 or attribute.enum_type.size > 0 or isPrimitives == "false" -%} | ||
@android.support.annotation.{% if attribute.optional == true %}Nullable{% else %}NonNull{%- endif -%} | ||
{%- if attribute.support_annotation.size > 0 %}|{%- endif -%} | ||
{%- endif -%} | ||
{%- endif -%} | ||
{%- endif -%} | ||
{%- endcapture -%} | ||
{%- capture isPrimitives -%} | ||
{%- include 'inc/primitives' -%} | ||
{%- endcapture -%} | ||
{%- capture annotation -%}{%- if params.support_annotations == true -%} | ||
{%- if params.use_wrappers == true or attribute.enum_type.size > 0 or isPrimitives == "false" -%} | ||
@android.support.annotation.{% if attribute.optional == true %}Nullable{% else %}NonNull{% endif -%} | ||
{%- if attribute.support_annotation.size > 0 %}|{% endif -%} | ||
{%- endif -%} | ||
{%- if attribute.support_annotation.size > 0 %}@android.support.annotation.{{ attribute.support_annotation }}{%- endif -%} | ||
{%- endif -%} | ||
{%- endcapture -%} | ||
{%- assign name = attribute.name -%} | ||
{%- if annotation.size > 0 %}{{ annotation | replace: "|"," | ||
{%- if attribute.support_annotation.size > 0 -%} | ||
@android.support.annotation.{{ attribute.support_annotation }} | ||
{%- endif %} | ||
{%- endif %} | ||
{%- endcapture %} | ||
{%- assign name = attribute.name %} | ||
{{ empty_line }} | ||
|
||
{%- if annotation.size > 0 %} | ||
{{ annotation | replace: "|"," | ||
" }} | ||
{% endif -%} | ||
public {{ convert_type }} get{{ name | titleize }}() { | ||
{%- endif %} | ||
{{ visibility }} {{ convert_type }} get{{ name | titleize }}() { | ||
return {{ name }}; | ||
} | ||
|
||
public void set{{ name | titleize }}({%- if annotation.size > 0 %}{{ annotation | replace: "|"," " }} {% endif %}final {{ convert_type }} {{ name }}) { | ||
{{ visibility }} void set{{ name | titleize }}({%- if annotation.size > 0 %}{{ annotation | replace: "|"," " }} {% endif %}final {{ convert_type }} {{ name }}) { | ||
this.{{ name }} = {{ name }}; | ||
} | ||
{%- endif -%} | ||
{%- endfor -%} | ||
{%- endif %} | ||
{%- endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
{%- if entity.relationships.size > 0 and entity.has_only_inverse == false %} | ||
|
||
public static class Relationships { | ||
private Relationships() { | ||
// Hide constructor | ||
} | ||
{% for relationship in entity.relationships -%} | ||
public static final class Relationships { | ||
{%- for relationship in entity.relationships -%} | ||
{%- if relationship.inverse == false %} | ||
public static final String {{ relationship.name | snake_case | upcase }} = "{{ relationship.name }}"; | ||
{%- endif -%} | ||
{%- endfor %} | ||
|
||
private Relationships() { | ||
// Hide constructor | ||
} | ||
} | ||
{%- endif -%} |
49 changes: 27 additions & 22 deletions
49
lib/templates/android/inc/_relationships_getter_setter.liquid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,47 @@ | ||
{%- for relationship in entity.relationships %} | ||
|
||
{% if relationship.inverse == false -%} | ||
{%- capture relationship_type -%} | ||
{%- if relationship.inverse == false %} | ||
{%- capture relationship_type %} | ||
{%- if relationship.realm_read_only.size == 0 and relationship.enum_type.size > 0 -%} | ||
String | ||
{%- else -%} | ||
{%- if relationship.destination.size == 0 -%} | ||
{%- else %} | ||
{%- if relationship.destination.size == 0 %} | ||
{%- if relationship.type != "to_many" -%} | ||
{{ relationship.inverse_type }} | ||
{%- else -%} | ||
RealmList<{{ relationship.inverse_type }}> | ||
{%- endif -%} | ||
{%- endif %} | ||
{%- else -%} | ||
List<{{ relationship.destination }}> | ||
{%- endif -%} | ||
{%- endif -%} | ||
{%- endcapture -%} | ||
{%- endif %} | ||
{%- endif %} | ||
{%- endcapture %} | ||
|
||
{%- capture annotation -%} | ||
{%- if params.support_annotations == true -%} | ||
{%- if relationship.optional == true -%} | ||
@android.support.annotation.Nullable{% endif -%} | ||
{%- if relationship.optional == false -%} | ||
@android.support.annotation.NonNull{% endif -%} | ||
{%- if relationship.support_annotation.size > 0 %}|@android.support.annotation.{{ relationship.support_annotation }}{% endif -%} | ||
{% endif -%} | ||
{%- endcapture -%} | ||
{%- capture annotation %} | ||
{%- if params.support_annotations.size > 0 %} | ||
{%- if relationship.optional == true -%} | ||
@android.support.annotation.Nullable | ||
{%- endif %} | ||
{%- if relationship.optional == false -%} | ||
@android.support.annotation.NonNull | ||
{%- endif %} | ||
{%- if relationship.support_annotation.size > 0 -%} | ||
|@android.support.annotation.{{ relationship.support_annotation }} | ||
{%- endif %} | ||
{%- endif %} | ||
{%- endcapture %} | ||
|
||
{%- assign name = relationship.name %} | ||
{%- if annotation.size > 0 %}{{ annotation | replace: "|"," | ||
{% comment %} *** Empty line *** {% endcomment %} | ||
{%- if annotation.size > 0 %} | ||
{{ annotation | replace: "|"," | ||
" }} | ||
{% endif -%} | ||
{%- endif %} | ||
public {{ relationship_type }} get{{ name | titleize }}() { | ||
return {{ name }}; | ||
} | ||
|
||
public void set{{ name | titleize }}({%- if annotation.size > 0 %}{{ annotation | replace: "|"," " }} {% endif %}final {{ relationship_type }} {{ name }}) { | ||
this.{{ name }} = {{ name }}; | ||
} | ||
{%- endif -%} | ||
{%- endfor -%} | ||
{%- endif %} | ||
{%- endfor %} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is no longer be useful. If you want to test gyro locally, please use the following lines :
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or you can use an other command when you develop gyro. Go to gyro repo and launch :