Skip to content

Commit

Permalink
Initial support for Java (#106)
Browse files Browse the repository at this point in the history
- This generation is targeted at Java running on the Android platform (Java 7).
It will be designed with that use-case in mind and may involve usage of
platform APIs that are not available in all Java environments
- Immutability is provided by AutoValue. This annotation is a dependency
of all models.
- Models assume you are using GSON and will generate SerializedName
annotations for model properties. In addition, we generate TypeAdapter methods to support auto-value-gson. This will likely be configurable to support Moshi in the future
- This commit does not have a working implementation of ADTs. This will
be addressed in a future commit and should not be relied upon
  • Loading branch information
rahul-malik authored Mar 10, 2018
1 parent a5e132e commit a86117d
Show file tree
Hide file tree
Showing 52 changed files with 2,221 additions and 706 deletions.
2 changes: 1 addition & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# For more details on bazelrc's:
# https://docs.bazel.build/versions/master/bazel-user-manual.html#bazelrc

build --xcode_toolchain=com.apple.dt.toolchain.Swift_3_1
build --xcode_toolchain=com.apple.dt.toolchain.Swift_4_0
build --apple_crosstool_transition
build --experimental_objc_crosstool=all
build --symlink_prefix=.bazel/
71 changes: 16 additions & 55 deletions Examples/Cocoa/Sources/Objective_C/Board.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//
// Board.m
// Autogenerated by plank
// Board.m
// Autogenerated by plank
//
// DO NOT EDIT - EDITS WILL BE OVERWRITTEN
// @generated
// DO NOT EDIT - EDITS WILL BE OVERWRITTEN
// @generated
//

#import "Board.h"
Expand All @@ -16,7 +16,6 @@
unsigned int BoardDirtyPropertyCreatedAt:1;
unsigned int BoardDirtyPropertyCreator:1;
unsigned int BoardDirtyPropertyDescriptionText:1;
unsigned int BoardDirtyPropertyIdentifier:1;
unsigned int BoardDirtyPropertyImage:1;
unsigned int BoardDirtyPropertyName:1;
unsigned int BoardDirtyPropertyUrl:1;
Expand Down Expand Up @@ -53,9 +52,7 @@ - (instancetype)initWithModelDictionary:(NS_VALID_UNTIL_END_OF_SCOPE NSDictionar
if (!modelDictionary) {
return self;
}
if (!(self = [super init])) {
return self;
}
if (!(self = [super initWithModelDictionary:modelDictionary])) { return self; }
{
__unsafe_unretained id value = modelDictionary[@"contributors"]; // Collection will retain.
if (value != nil) {
Expand Down Expand Up @@ -119,15 +116,6 @@ - (instancetype)initWithModelDictionary:(NS_VALID_UNTIL_END_OF_SCOPE NSDictionar
self->_boardDirtyProperties.BoardDirtyPropertyDescriptionText = 1;
}
}
{
__unsafe_unretained id value = modelDictionary[@"id"]; // Collection will retain.
if (value != nil) {
if (value != (id)kCFNull) {
self->_identifier = [value copy];
}
self->_boardDirtyProperties.BoardDirtyPropertyIdentifier = 1;
}
}
{
__unsafe_unretained id value = modelDictionary[@"image"]; // Collection will retain.
if (value != nil) {
Expand Down Expand Up @@ -168,15 +156,14 @@ - (instancetype)initWithBuilder:(BoardBuilder *)builder
- (instancetype)initWithBuilder:(BoardBuilder *)builder initType:(PlankModelInitType)initType
{
NSParameterAssert(builder);
if (!(self = [super init])) {
if (!(self = [super initWithBuilder:builder initType:initType])) {
return self;
}
_contributors = builder.contributors;
_counts = builder.counts;
_createdAt = builder.createdAt;
_creator = builder.creator;
_descriptionText = builder.descriptionText;
_identifier = builder.identifier;
_image = builder.image;
_name = builder.name;
_url = builder.url;
Expand All @@ -189,7 +176,7 @@ - (instancetype)initWithBuilder:(BoardBuilder *)builder initType:(PlankModelInit
- (NSString *)debugDescription
{
NSArray<NSString *> *parentDebugDescription = [[super debugDescription] componentsSeparatedByString:@"\n"];
NSMutableArray *descriptionFields = [NSMutableArray arrayWithCapacity:9];
NSMutableArray *descriptionFields = [NSMutableArray arrayWithCapacity:8];
[descriptionFields addObject:parentDebugDescription];
struct BoardDirtyProperties props = _boardDirtyProperties;
if (props.BoardDirtyPropertyContributors) {
Expand All @@ -207,9 +194,6 @@ - (NSString *)debugDescription
if (props.BoardDirtyPropertyDescriptionText) {
[descriptionFields addObject:[@"_descriptionText = " stringByAppendingFormat:@"%@", _descriptionText]];
}
if (props.BoardDirtyPropertyIdentifier) {
[descriptionFields addObject:[@"_identifier = " stringByAppendingFormat:@"%@", _identifier]];
}
if (props.BoardDirtyPropertyImage) {
[descriptionFields addObject:[@"_image = " stringByAppendingFormat:@"%@", _image]];
}
Expand All @@ -233,6 +217,9 @@ - (BOOL)isEqual:(id)anObject
if (self == anObject) {
return YES;
}
if ([super isEqual:anObject] == NO) {
return NO;
}
if ([anObject isKindOfClass:[Board class]] == NO) {
return NO;
}
Expand All @@ -247,7 +234,6 @@ - (BOOL)isEqualToBoard:(Board *)anObject
(_createdAt == anObject.createdAt || [_createdAt isEqualToDate:anObject.createdAt]) &&
(_creator == anObject.creator || [_creator isEqualToDictionary:anObject.creator]) &&
(_descriptionText == anObject.descriptionText || [_descriptionText isEqualToString:anObject.descriptionText]) &&
(_identifier == anObject.identifier || [_identifier isEqualToString:anObject.identifier]) &&
(_image == anObject.image || [_image isEqual:anObject.image]) &&
(_name == anObject.name || [_name isEqualToString:anObject.name]) &&
(_url == anObject.url || [_url isEqual:anObject.url])
Expand All @@ -256,13 +242,12 @@ - (BOOL)isEqualToBoard:(Board *)anObject
- (NSUInteger)hash
{
NSUInteger subhashes[] = {
17,
[super hash],
[_contributors hash],
[_counts hash],
[_createdAt hash],
[_creator hash],
[_descriptionText hash],
[_identifier hash],
[_image hash],
[_name hash],
[_url hash]
Expand All @@ -282,7 +267,7 @@ - (instancetype)mergeWithModel:(Board *)modelObject initType:(PlankModelInitType
}
- (NSDictionary *)dictionaryObjectRepresentation
{
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithCapacity:9];
NSMutableDictionary *dict = [[super dictionaryObjectRepresentation] mutableCopy];
if (_boardDirtyProperties.BoardDirtyPropertyContributors) {
if (_contributors != (id)kCFNull) {
__auto_type items0 = _contributors;
Expand Down Expand Up @@ -328,13 +313,6 @@ - (NSDictionary *)dictionaryObjectRepresentation
[dict setObject:[NSNull null] forKey:@"description"];
}
}
if (_boardDirtyProperties.BoardDirtyPropertyIdentifier) {
if (_identifier != (id)kCFNull) {
[dict setObject:_identifier forKey:@"id"];
} else {
[dict setObject:[NSNull null] forKey:@"id"];
}
}
if (_boardDirtyProperties.BoardDirtyPropertyImage) {
if (_image != (id)kCFNull) {
[dict setObject:[_image dictionaryObjectRepresentation] forKey:@"image"];
Expand Down Expand Up @@ -370,15 +348,12 @@ + (BOOL)supportsSecureCoding
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
if (!(self = [super init])) {
return self;
}
if (!(self = [super initWithCoder:aDecoder])) { return self; }
_contributors = [aDecoder decodeObjectOfClasses:[NSSet setWithArray:@[[NSSet class], [User class]]] forKey:@"contributors"];
_counts = [aDecoder decodeObjectOfClasses:[NSSet setWithArray:@[[NSDictionary class], [NSNumber class]]] forKey:@"counts"];
_createdAt = [aDecoder decodeObjectOfClass:[NSDate class] forKey:@"created_at"];
_creator = [aDecoder decodeObjectOfClasses:[NSSet setWithArray:@[[NSDictionary class], [NSString class]]] forKey:@"creator"];
_descriptionText = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"description"];
_identifier = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"id"];
_image = [aDecoder decodeObjectOfClass:[Image class] forKey:@"image"];
_name = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"name"];
_url = [aDecoder decodeObjectOfClass:[NSURL class] forKey:@"url"];
Expand All @@ -387,7 +362,6 @@ - (instancetype)initWithCoder:(NSCoder *)aDecoder
_boardDirtyProperties.BoardDirtyPropertyCreatedAt = [aDecoder decodeIntForKey:@"created_at_dirty_property"] & 0x1;
_boardDirtyProperties.BoardDirtyPropertyCreator = [aDecoder decodeIntForKey:@"creator_dirty_property"] & 0x1;
_boardDirtyProperties.BoardDirtyPropertyDescriptionText = [aDecoder decodeIntForKey:@"description_dirty_property"] & 0x1;
_boardDirtyProperties.BoardDirtyPropertyIdentifier = [aDecoder decodeIntForKey:@"id_dirty_property"] & 0x1;
_boardDirtyProperties.BoardDirtyPropertyImage = [aDecoder decodeIntForKey:@"image_dirty_property"] & 0x1;
_boardDirtyProperties.BoardDirtyPropertyName = [aDecoder decodeIntForKey:@"name_dirty_property"] & 0x1;
_boardDirtyProperties.BoardDirtyPropertyUrl = [aDecoder decodeIntForKey:@"url_dirty_property"] & 0x1;
Expand All @@ -398,12 +372,12 @@ - (instancetype)initWithCoder:(NSCoder *)aDecoder
}
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[super encodeWithCoder:aCoder];
[aCoder encodeObject:self.contributors forKey:@"contributors"];
[aCoder encodeObject:self.counts forKey:@"counts"];
[aCoder encodeObject:self.createdAt forKey:@"created_at"];
[aCoder encodeObject:self.creator forKey:@"creator"];
[aCoder encodeObject:self.descriptionText forKey:@"description"];
[aCoder encodeObject:self.identifier forKey:@"id"];
[aCoder encodeObject:self.image forKey:@"image"];
[aCoder encodeObject:self.name forKey:@"name"];
[aCoder encodeObject:self.url forKey:@"url"];
Expand All @@ -412,7 +386,6 @@ - (void)encodeWithCoder:(NSCoder *)aCoder
[aCoder encodeInt:_boardDirtyProperties.BoardDirtyPropertyCreatedAt forKey:@"created_at_dirty_property"];
[aCoder encodeInt:_boardDirtyProperties.BoardDirtyPropertyCreator forKey:@"creator_dirty_property"];
[aCoder encodeInt:_boardDirtyProperties.BoardDirtyPropertyDescriptionText forKey:@"description_dirty_property"];
[aCoder encodeInt:_boardDirtyProperties.BoardDirtyPropertyIdentifier forKey:@"id_dirty_property"];
[aCoder encodeInt:_boardDirtyProperties.BoardDirtyPropertyImage forKey:@"image_dirty_property"];
[aCoder encodeInt:_boardDirtyProperties.BoardDirtyPropertyName forKey:@"name_dirty_property"];
[aCoder encodeInt:_boardDirtyProperties.BoardDirtyPropertyUrl forKey:@"url_dirty_property"];
Expand All @@ -423,9 +396,7 @@ @implementation BoardBuilder
- (instancetype)initWithModel:(Board *)modelObject
{
NSParameterAssert(modelObject);
if (!(self = [super init])) {
return self;
}
if (!(self = [super initWithModel:modelObject])) { return self; }
struct BoardDirtyProperties boardDirtyProperties = modelObject.boardDirtyProperties;
if (boardDirtyProperties.BoardDirtyPropertyContributors) {
_contributors = modelObject.contributors;
Expand All @@ -442,9 +413,6 @@ - (instancetype)initWithModel:(Board *)modelObject
if (boardDirtyProperties.BoardDirtyPropertyDescriptionText) {
_descriptionText = modelObject.descriptionText;
}
if (boardDirtyProperties.BoardDirtyPropertyIdentifier) {
_identifier = modelObject.identifier;
}
if (boardDirtyProperties.BoardDirtyPropertyImage) {
_image = modelObject.image;
}
Expand All @@ -464,6 +432,7 @@ - (Board *)build
- (void)mergeWithModel:(Board *)modelObject
{
NSParameterAssert(modelObject);
[super mergeWithModel:modelObject];
BoardBuilder *builder = self;
if (modelObject.boardDirtyProperties.BoardDirtyPropertyContributors) {
builder.contributors = modelObject.contributors;
Expand All @@ -480,9 +449,6 @@ - (void)mergeWithModel:(Board *)modelObject
if (modelObject.boardDirtyProperties.BoardDirtyPropertyDescriptionText) {
builder.descriptionText = modelObject.descriptionText;
}
if (modelObject.boardDirtyProperties.BoardDirtyPropertyIdentifier) {
builder.identifier = modelObject.identifier;
}
if (modelObject.boardDirtyProperties.BoardDirtyPropertyImage) {
id value = modelObject.image;
if (builder.image) {
Expand Down Expand Up @@ -523,11 +489,6 @@ - (void)setDescriptionText:(NSString *)descriptionText
_descriptionText = [descriptionText copy];
_boardDirtyProperties.BoardDirtyPropertyDescriptionText = 1;
}
- (void)setIdentifier:(NSString *)identifier
{
_identifier = [identifier copy];
_boardDirtyProperties.BoardDirtyPropertyIdentifier = 1;
}
- (void)setImage:(Image *)image
{
_image = image;
Expand Down
9 changes: 5 additions & 4 deletions Examples/Cocoa/Sources/Objective_C/Everything.m
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
//
// Everything.m
// Autogenerated by plank
// Everything.m
// Autogenerated by plank
//
// DO NOT EDIT - EDITS WILL BE OVERWRITTEN
// @generated
// DO NOT EDIT - EDITS WILL BE OVERWRITTEN
// @generated
//

#import "Board.h"
#import "Everything.h"
#import "Everything.h"
#import "Image.h"
#import "Pin.h"
#import "User.h"
Expand Down
8 changes: 4 additions & 4 deletions Examples/Cocoa/Sources/Objective_C/Image.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//
// Image.m
// Autogenerated by plank
// Image.m
// Autogenerated by plank
//
// DO NOT EDIT - EDITS WILL BE OVERWRITTEN
// @generated
// DO NOT EDIT - EDITS WILL BE OVERWRITTEN
// @generated
//

#import "Image.h"
Expand Down
Loading

0 comments on commit a86117d

Please sign in to comment.