-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Codegen: JavaGenerator [1] - introduce type model to represent the pa…
…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
1 parent
3f1a453
commit 59a4d6f
Showing
16 changed files
with
405 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
...uild/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/AliasType.java
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 |
---|---|---|
@@ -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; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/AnyType.java
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 |
---|---|---|
@@ -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); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...uild/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/ArrayType.java
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 |
---|---|---|
@@ -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; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...ld/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/BooleanType.java
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 |
---|---|---|
@@ -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); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...ild/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/DoubleType.java
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 |
---|---|---|
@@ -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); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...uild/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/FloatType.java
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 |
---|---|---|
@@ -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); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...d/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/FunctionType.java
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 |
---|---|---|
@@ -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); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...dlePlugin/src/main/java/com/facebook/react/codegen/generator/model/GenericObjectType.java
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 |
---|---|---|
@@ -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); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...uild/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/Int32Type.java
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 |
---|---|---|
@@ -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); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...ild/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/NumberType.java
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 |
---|---|---|
@@ -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); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...ild/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/ObjectType.java
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 |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...n/src/main/java/com/facebook/react/codegen/generator/model/ReservedFunctionValueType.java
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 |
---|---|---|
@@ -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; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...ild/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/StringType.java
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 |
---|---|---|
@@ -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); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...gin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/Type.java
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 |
---|---|---|
@@ -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); | ||
} | ||
} |
Oops, something went wrong.