Skip to content

Commit

Permalink
Codegen: JavaGenerator [1] - introduce type model to represent the pa…
Browse files Browse the repository at this point in the history
…rsed JSON schema

Summary:
These Java types are to represent the schema structure based on the definition here: https://github.com/facebook/react-native/blob/master/packages/react-native-codegen/src/CodegenSchema.js#L260
This commit only deals with NativeModules related types, not Fabric yet.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D23100170

fbshipit-source-id: f3d837c04b35bef099cb0132bccaca117c22f211
  • Loading branch information
fkgozali authored and facebook-github-bot committed Aug 13, 2020
1 parent 3f1a453 commit 59a4d6f
Show file tree
Hide file tree
Showing 16 changed files with 405 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.codegen.generator.model;

public final class AliasType extends Type {

public final TypeId referredTypeId;

public AliasType(final TypeId typeId, final TypeId referredTypeId) {
super(typeId);
this.referredTypeId = referredTypeId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.codegen.generator.model;

public final class AnyType extends Type {

public AnyType(final TypeId typeId) {
super(typeId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.codegen.generator.model;

public final class ArrayType extends Type {

public final Type elementType;

public ArrayType(final TypeId typeId, final Type elementType) {
super(typeId);
this.elementType = elementType;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.codegen.generator.model;

public final class BooleanType extends Type {

public BooleanType(final TypeId typeId) {
super(typeId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.codegen.generator.model;

public final class DoubleType extends NumberType {

public DoubleType(final TypeId typeId) {
super(typeId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.codegen.generator.model;

public final class FloatType extends NumberType {

public FloatType(final TypeId typeId) {
super(typeId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.codegen.generator.model;

import java.util.Collections;
import java.util.List;
import java.util.Objects;

public final class FunctionType extends Type {

public static class ArgumentType {
public final String name;
public final Type type;

private ArgumentType(String name, Type type) {
this.name = name;
this.type = type;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

ArgumentType that = (ArgumentType) o;
return Objects.equals(this.name, that.name) && Objects.equals(this.type, that.type);
}

@Override
public int hashCode() {
return Objects.hash(name, type);
}
}

public final List<ArgumentType> parameters;
public final Type returnType;

public FunctionType(final TypeId typeId, List<ArgumentType> parameters, Type returnType) {
super(typeId);
this.parameters = Collections.unmodifiableList(parameters);
this.returnType = returnType;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass() || !super.equals(o)) {
return false;
}

FunctionType that = (FunctionType) o;
return Objects.equals(this.parameters, that.parameters)
&& Objects.equals(this.returnType, that.returnType);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), parameters, returnType);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.codegen.generator.model;

public final class GenericObjectType extends Type {

public GenericObjectType(final TypeId typeId) {
super(typeId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.codegen.generator.model;

public final class Int32Type extends NumberType {

public Int32Type(final TypeId typeId) {
super(typeId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.codegen.generator.model;

public class NumberType extends Type {

public NumberType(final TypeId typeId) {
super(typeId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.codegen.generator.model;

public final class ObjectType extends Type {

public ObjectType(final TypeId typeId) {
super(typeId);
}

public static class Property {
public final String propertyName;
public final Type type;
public final boolean optional;

public Property(String propertyName, Type type, boolean optional) {
this.propertyName = propertyName;
this.type = type;
this.optional = optional;
}

@Override
public String toString() {
return propertyName + " " + type;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.codegen.generator.model;

public final class ReservedFunctionValueType extends Type {
public enum ReservedName {
RootTag,
}

public ReservedName reservedName;

public ReservedFunctionValueType(final TypeId typeId, ReservedName reservedName) {
super(typeId);
this.reservedName = reservedName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.codegen.generator.model;

public final class StringType extends Type {

public StringType(final TypeId typeId) {
super(typeId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.codegen.generator.model;

import java.util.Objects;

public abstract class Type {
protected final TypeId mTypeId;

public Type(final TypeId typeId) {
mTypeId = typeId;
}

public TypeId getTypeId() {
return mTypeId;
}

@Override
public String toString() {
return mTypeId.toString();
}

@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
final Type type = (Type) o;
return Objects.equals(mTypeId, type.mTypeId);
}

@Override
public int hashCode() {
return Objects.hash(mTypeId);
}
}
Loading

0 comments on commit 59a4d6f

Please sign in to comment.