Created
August 10, 2021 08:15
-
-
Save Naturalclar/13f851aa1402bb81056f95b746fc823e to your computer and use it in GitHub Desktop.
Patch file for react-native-codegen when you need to build android from source with React Native 0.64+
This file contains hidden or 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
diff --git a/node_modules/react-native-codegen/android/build.gradle b/node_modules/react-native-codegen/android/build.gradle | |
new file mode 100644 | |
index 0000000..4152a5e | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/build.gradle | |
@@ -0,0 +1,25 @@ | |
+/* | |
+ * 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. | |
+ */ | |
+ | |
+buildscript { | |
+ repositories { | |
+ mavenLocal() | |
+ google() | |
+ jcenter() | |
+ } | |
+ dependencies { | |
+ classpath("com.android.tools.build:gradle:4.1.0") | |
+ } | |
+} | |
+ | |
+allprojects { | |
+ repositories { | |
+ mavenLocal() | |
+ google() | |
+ jcenter() | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradle/wrapper/gradle-wrapper.jar b/node_modules/react-native-codegen/android/gradle/wrapper/gradle-wrapper.jar | |
new file mode 100644 | |
index 0000000..e69de29 | |
diff --git a/node_modules/react-native-codegen/android/gradle/wrapper/gradle-wrapper.properties b/node_modules/react-native-codegen/android/gradle/wrapper/gradle-wrapper.properties | |
new file mode 100644 | |
index 0000000..14e30f7 | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradle/wrapper/gradle-wrapper.properties | |
@@ -0,0 +1,5 @@ | |
+distributionBase=GRADLE_USER_HOME | |
+distributionPath=wrapper/dists | |
+distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip | |
+zipStoreBase=GRADLE_USER_HOME | |
+zipStorePath=wrapper/dists | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/build.gradle b/node_modules/react-native-codegen/android/gradlePlugin-build/build.gradle | |
new file mode 100644 | |
index 0000000..c335f1c | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/build.gradle | |
@@ -0,0 +1,14 @@ | |
+/* | |
+ * 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. | |
+ */ | |
+ | |
+allprojects { | |
+ repositories { | |
+ mavenLocal() | |
+ google() | |
+ jcenter() | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/build.gradle b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/build.gradle | |
new file mode 100644 | |
index 0000000..2eb21ff | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/build.gradle | |
@@ -0,0 +1,27 @@ | |
+/* | |
+ * 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. | |
+ */ | |
+ | |
+plugins { | |
+ id 'java-gradle-plugin' | |
+} | |
+ | |
+gradlePlugin { | |
+ plugins { | |
+ greeting { | |
+ id = 'com.facebook.react.codegen' | |
+ implementationClass = 'com.facebook.react.codegen.plugin.CodegenPlugin' | |
+ } | |
+ } | |
+} | |
+ | |
+dependencies { | |
+ implementation 'com.android.tools.build:gradle:4.1.0' | |
+ // Use the same Gson version that `com.android.tools.build:gradle` depends on. | |
+ implementation 'com.google.code.gson:gson:2.8.5' | |
+ implementation 'com.google.guava:guava:29.0-jre' | |
+ implementation 'com.squareup:javapoet:1.13.0' | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/JavaGenerator.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/JavaGenerator.java | |
new file mode 100644 | |
index 0000000..c0abf23 | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/JavaGenerator.java | |
@@ -0,0 +1,106 @@ | |
+/* | |
+ * 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; | |
+ | |
+import static java.nio.charset.StandardCharsets.UTF_8; | |
+ | |
+import com.facebook.react.codegen.generator.model.CodegenException; | |
+import com.facebook.react.codegen.generator.model.TypeData; | |
+import com.facebook.react.codegen.generator.resolver.ResolvedType; | |
+import com.facebook.react.codegen.generator.resolver.TypeResolver; | |
+import com.squareup.javapoet.JavaFile; | |
+import com.squareup.javapoet.TypeSpec; | |
+import java.io.File; | |
+import java.io.FileNotFoundException; | |
+import java.io.IOException; | |
+import java.io.OutputStreamWriter; | |
+import java.io.Writer; | |
+import java.nio.file.Files; | |
+import java.nio.file.Path; | |
+import java.util.List; | |
+import java.util.stream.Collectors; | |
+ | |
+/** | |
+ * Given a react-native-codegen JSON schema, generate a set of .java files for React Native. The | |
+ * generator is isolated to a single schema, and a single Java package output. | |
+ */ | |
+public final class JavaGenerator { | |
+ public static String LICENSE_HEADER = | |
+ "/*\n" | |
+ + " * Copyright (c) Facebook, Inc. and its affiliates.\n" | |
+ + " *\n" | |
+ + " * This source code is licensed under the MIT license found in the\n" | |
+ + " * LICENSE file in the root directory of this source tree.\n" | |
+ + " *\n" | |
+ + " * Generated by react-native-codegen JavaGenerator.\n" | |
+ + " *\n" | |
+ + " * @" | |
+ + "generated\n" | |
+ + " * @" | |
+ + "nolint\n" | |
+ + " */\n\n"; | |
+ private final File mSchemaFile; | |
+ private final String mJavaPackageName; | |
+ private final File mOutputDir; | |
+ | |
+ public JavaGenerator(final File schemaFile, final String javaPackageName, final File outputDir) { | |
+ mSchemaFile = schemaFile; | |
+ mJavaPackageName = javaPackageName; | |
+ mOutputDir = outputDir; | |
+ } | |
+ | |
+ public void build() throws CodegenException, FileNotFoundException, IOException { | |
+ // Step 1: Given a schema JSON, collect all types. | |
+ final TypeData typeData = SchemaJsonParser.parse(mSchemaFile); | |
+ | |
+ // Step 2: Resolve each type, then collect those that produce a class or interface (TypeSpec). | |
+ final List<TypeSpec> typeSpecsToWrite = | |
+ typeData.getAllTypes().stream() | |
+ .map( | |
+ t -> { | |
+ final ResolvedType resolvedType = | |
+ TypeResolver.resolveType(typeData.getType(t), typeData, false); | |
+ final TypeSpec spec = resolvedType.getGeneratedCode(mJavaPackageName); | |
+ return spec; | |
+ }) | |
+ .filter(f -> f != null) | |
+ .collect(Collectors.toList()); | |
+ | |
+ // Step 3: Write all of the TypeSpec's into the output directory. | |
+ for (final TypeSpec typeSpec : typeSpecsToWrite) { | |
+ writeTypeSpecToFile(typeSpec); | |
+ } | |
+ } | |
+ | |
+ private final void writeTypeSpecToFile(final TypeSpec typeSpec) | |
+ throws CodegenException, IOException { | |
+ JavaFile file = JavaFile.builder(mJavaPackageName, typeSpec).skipJavaLangImports(true).build(); | |
+ | |
+ // Instead of using JavaFile.writeTo() API, manage the output files ourselves because | |
+ // JavaFile.addFileComment() does not support "block comment" style. | |
+ // See https://github.com/square/javapoet/issues/682#issuecomment-512238075. | |
+ Path outputDirPath = new File(mOutputDir, "java").toPath(); | |
+ | |
+ if (Files.exists(outputDirPath) && !Files.isDirectory(outputDirPath)) { | |
+ throw new CodegenException( | |
+ "Output path " + outputDirPath + " exists but is not a directory."); | |
+ } | |
+ | |
+ if (!mJavaPackageName.isEmpty()) { | |
+ for (String packageComponent : mJavaPackageName.split("\\.")) { | |
+ outputDirPath = outputDirPath.resolve(packageComponent); | |
+ } | |
+ Files.createDirectories(outputDirPath); | |
+ } | |
+ | |
+ Path outputPath = outputDirPath.resolve(typeSpec.name + ".java"); | |
+ try (Writer writer = new OutputStreamWriter(Files.newOutputStream(outputPath), UTF_8)) { | |
+ writer.write(LICENSE_HEADER + file.toString()); | |
+ } | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/SchemaJsonParser.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/SchemaJsonParser.java | |
new file mode 100644 | |
index 0000000..422317a | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/SchemaJsonParser.java | |
@@ -0,0 +1,275 @@ | |
+/* | |
+ * 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; | |
+ | |
+import com.facebook.react.codegen.generator.model.AliasType; | |
+import com.facebook.react.codegen.generator.model.AnyType; | |
+import com.facebook.react.codegen.generator.model.ArrayType; | |
+import com.facebook.react.codegen.generator.model.BooleanType; | |
+import com.facebook.react.codegen.generator.model.CodegenException; | |
+import com.facebook.react.codegen.generator.model.DoubleType; | |
+import com.facebook.react.codegen.generator.model.FloatType; | |
+import com.facebook.react.codegen.generator.model.FunctionType; | |
+import com.facebook.react.codegen.generator.model.GenericObjectType; | |
+import com.facebook.react.codegen.generator.model.Int32Type; | |
+import com.facebook.react.codegen.generator.model.NativeModuleType; | |
+import com.facebook.react.codegen.generator.model.NullableType; | |
+import com.facebook.react.codegen.generator.model.NumberType; | |
+import com.facebook.react.codegen.generator.model.ObjectType; | |
+import com.facebook.react.codegen.generator.model.PromiseType; | |
+import com.facebook.react.codegen.generator.model.ReservedFunctionValueType; | |
+import com.facebook.react.codegen.generator.model.StringType; | |
+import com.facebook.react.codegen.generator.model.Type; | |
+import com.facebook.react.codegen.generator.model.TypeData; | |
+import com.facebook.react.codegen.generator.model.TypeId; | |
+import com.facebook.react.codegen.generator.model.VoidType; | |
+import com.google.common.base.CaseFormat; | |
+import com.google.common.collect.ImmutableList; | |
+import com.google.gson.JsonArray; | |
+import com.google.gson.JsonElement; | |
+import com.google.gson.JsonObject; | |
+import com.google.gson.JsonParser; | |
+import java.io.File; | |
+import java.io.FileNotFoundException; | |
+import java.io.FileReader; | |
+import java.io.IOException; | |
+import java.util.HashMap; | |
+import java.util.Map; | |
+import java.util.stream.Collectors; | |
+ | |
+public final class SchemaJsonParser { | |
+ private final TypeData mTypeData = new TypeData(); | |
+ | |
+ public static TypeData parse(final File schemaFile) | |
+ throws CodegenException, FileNotFoundException, IOException { | |
+ final SchemaJsonParser parser = new SchemaJsonParser(); | |
+ return parser.buildTypeData(schemaFile); | |
+ } | |
+ | |
+ private TypeData buildTypeData(final File schemaFile) | |
+ throws CodegenException, FileNotFoundException, IOException { | |
+ final JsonParser parser = new JsonParser(); | |
+ final JsonElement rootElement = parser.parse(new FileReader(schemaFile)); | |
+ | |
+ final Map<String, Map<String, NativeModuleType>> collection = new HashMap<>(); | |
+ | |
+ if (rootElement.isJsonObject()) { | |
+ final JsonObject root = rootElement.getAsJsonObject(); | |
+ final JsonObject modules = root.getAsJsonObject("modules"); | |
+ modules | |
+ .entrySet() | |
+ .forEach( | |
+ entry -> { | |
+ final String jsModuleName = entry.getKey(); | |
+ final JsonObject jsModule = entry.getValue().getAsJsonObject(); | |
+ final String jsModuleType = jsModule.get("type").getAsString(); | |
+ | |
+ if (!"NativeModule".equals(jsModuleType)) { | |
+ return; | |
+ } | |
+ | |
+ if (jsModule.has("excludedPlatforms")) { | |
+ final JsonArray excludedPlatforms = jsModule.getAsJsonArray("excludedPlatforms"); | |
+ for (JsonElement p : excludedPlatforms) { | |
+ if (p.getAsString().equals("android")) { | |
+ // This module is not for Android. | |
+ return; | |
+ } | |
+ } | |
+ } | |
+ | |
+ final Type parsedType = | |
+ parseNativeModule( | |
+ // TODO (T71955395): NativeModule spec type name does not | |
+ // exist in the schema. For now assume it's "Spec". | |
+ // The final type name will be the output class name. | |
+ TypeId.of(jsModuleName, jsModuleName + "Spec"), jsModule); | |
+ mTypeData.addType(parsedType); | |
+ }); | |
+ } | |
+ | |
+ return mTypeData; | |
+ } | |
+ | |
+ // Parse type information from a JSON "typeAnnotation" node. | |
+ private Type parseTypeAnnotation(final TypeId typeId, final JsonObject originalTypeAnnotation) { | |
+ JsonObject typeAnnotation = originalTypeAnnotation; | |
+ String type = typeAnnotation.get("type").getAsString(); | |
+ boolean nullable = false; | |
+ Type parsedType = null; | |
+ | |
+ if (type.equals(NullableType.TYPE_NAME)) { | |
+ nullable = true; | |
+ typeAnnotation = typeAnnotation.get("typeAnnotation").getAsJsonObject(); | |
+ type = typeAnnotation.get("type").getAsString(); | |
+ } | |
+ | |
+ switch (type) { | |
+ case AliasType.TYPE_NAME: | |
+ parsedType = parseAliasTypeAnnotation(typeId, typeAnnotation); | |
+ break; | |
+ case AnyType.TYPE_NAME: | |
+ parsedType = new AnyType(typeId); | |
+ break; | |
+ case ArrayType.TYPE_NAME: | |
+ parsedType = parseArrayTypeAnnotation(typeId, typeAnnotation); | |
+ break; | |
+ case BooleanType.TYPE_NAME: | |
+ parsedType = new BooleanType(typeId); | |
+ break; | |
+ case DoubleType.TYPE_NAME: | |
+ parsedType = new DoubleType(typeId); | |
+ break; | |
+ case FloatType.TYPE_NAME: | |
+ parsedType = new FloatType(typeId); | |
+ break; | |
+ case FunctionType.TYPE_NAME: | |
+ parsedType = parseFunctionTypeAnnotation(typeId, typeAnnotation); | |
+ break; | |
+ case GenericObjectType.TYPE_NAME: | |
+ parsedType = new GenericObjectType(typeId); | |
+ break; | |
+ case Int32Type.TYPE_NAME: | |
+ parsedType = new Int32Type(typeId); | |
+ break; | |
+ case NumberType.TYPE_NAME: | |
+ // Use double type for generic numbers. | |
+ parsedType = new DoubleType(typeId); | |
+ break; | |
+ case ObjectType.TYPE_NAME: | |
+ parsedType = parseObjectTypeAnnotation(typeId, typeAnnotation); | |
+ break; | |
+ case PromiseType.TYPE_NAME: | |
+ parsedType = new PromiseType(typeId); | |
+ break; | |
+ case ReservedFunctionValueType.TYPE_NAME: | |
+ parsedType = parseReservedFunctionValueTypeAnnotation(typeId, typeAnnotation); | |
+ break; | |
+ case StringType.TYPE_NAME: | |
+ parsedType = new StringType(typeId); | |
+ break; | |
+ case VoidType.TYPE_NAME: | |
+ return VoidType.VOID; | |
+ default: | |
+ throw new CodegenException("Found invalid type annotation: " + type); | |
+ } | |
+ | |
+ final Type finalType = maybeCreateNullableType(nullable, parsedType); | |
+ mTypeData.addType(finalType); | |
+ return finalType; | |
+ } | |
+ | |
+ private NativeModuleType parseNativeModule(final TypeId typeId, final JsonObject json) { | |
+ final JsonObject aliases = json.getAsJsonObject("aliases"); | |
+ final JsonArray properties = json.getAsJsonObject("spec").getAsJsonArray("properties"); | |
+ | |
+ final ImmutableList<Type> collectedAliases = | |
+ ImmutableList.copyOf( | |
+ aliases.entrySet().stream() | |
+ .map( | |
+ entry -> { | |
+ final String typeName = entry.getKey(); | |
+ final JsonObject typeAnnotation = entry.getValue().getAsJsonObject(); | |
+ // The alias name is the type name that other types can refer to. | |
+ return parseTypeAnnotation( | |
+ TypeId.of(typeId.moduleName, typeName), typeAnnotation); | |
+ }) | |
+ .collect(Collectors.toList())); | |
+ | |
+ ImmutableList.Builder<NativeModuleType.Property> collectedPropertiesBuilder = | |
+ new ImmutableList.Builder<>(); | |
+ properties.forEach( | |
+ p -> { | |
+ final JsonObject node = p.getAsJsonObject(); | |
+ final String name = node.get("name").getAsString(); | |
+ final JsonObject typeAnnotation = node.getAsJsonObject("typeAnnotation"); | |
+ final boolean optional = node.get("optional").getAsBoolean(); | |
+ final TypeId propertyTypeId = | |
+ TypeId.expandOf(typeId, CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, name)); | |
+ collectedPropertiesBuilder.add( | |
+ new NativeModuleType.Property( | |
+ name, parseTypeAnnotation(propertyTypeId, typeAnnotation), optional)); | |
+ }); | |
+ | |
+ return new NativeModuleType(typeId, collectedAliases, collectedPropertiesBuilder.build()); | |
+ } | |
+ | |
+ private Type parseAliasTypeAnnotation(final TypeId typeId, final JsonObject typeAnnotation) { | |
+ // For now, assume the alias lives inside the same file. | |
+ return new AliasType( | |
+ typeId, TypeId.of(typeId.moduleName, typeAnnotation.get("name").getAsString())); | |
+ } | |
+ | |
+ private Type parseArrayTypeAnnotation(final TypeId typeId, final JsonObject typeAnnotation) { | |
+ final JsonObject elementTypeAnnotation = typeAnnotation.getAsJsonObject("elementType"); | |
+ final TypeId elementTypeId = TypeId.expandOf(typeId, "ElementType"); | |
+ // TODO (T71847026): Some array types are missing elementType annotation. | |
+ final Type elementType = | |
+ elementTypeAnnotation != null | |
+ ? parseTypeAnnotation(elementTypeId, elementTypeAnnotation) | |
+ : new AnyType(elementTypeId); | |
+ return new ArrayType(typeId, elementType); | |
+ } | |
+ | |
+ private Type parseFunctionTypeAnnotation(final TypeId typeId, final JsonObject typeAnnotation) { | |
+ final JsonArray params = typeAnnotation.getAsJsonArray("params"); | |
+ | |
+ ImmutableList.Builder<FunctionType.ArgumentType> paramsList = new ImmutableList.Builder<>(); | |
+ | |
+ for (int i = 0; i < params.size(); i++) { | |
+ final JsonElement p = params.get(i); | |
+ final JsonObject node = p.getAsJsonObject(); | |
+ final String name = node.get("name").getAsString(); | |
+ paramsList.add( | |
+ FunctionType.createArgument( | |
+ name, | |
+ parseTypeAnnotation( | |
+ TypeId.expandOf(typeId, CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, name)), | |
+ node.getAsJsonObject("typeAnnotation")))); | |
+ } | |
+ | |
+ final JsonObject returnTypeAnnotation = typeAnnotation.getAsJsonObject("returnTypeAnnotation"); | |
+ final Type returnType = | |
+ parseTypeAnnotation(TypeId.expandOf(typeId, "ReturnType"), returnTypeAnnotation); | |
+ | |
+ return new FunctionType(typeId, paramsList.build(), returnType); | |
+ } | |
+ | |
+ private Type parseObjectTypeAnnotation(final TypeId typeId, final JsonObject typeAnnotation) { | |
+ final JsonArray properties = typeAnnotation.getAsJsonArray("properties"); | |
+ | |
+ ImmutableList.Builder<ObjectType.Property> propertiesList = new ImmutableList.Builder<>(); | |
+ properties.forEach( | |
+ p -> { | |
+ final JsonObject node = p.getAsJsonObject(); | |
+ final String name = node.get("name").getAsString(); | |
+ final boolean optional = node.get("optional").getAsBoolean(); | |
+ final JsonObject propertyTypeAnnotation = node.getAsJsonObject("typeAnnotation"); | |
+ final TypeId propertyTypeId = | |
+ TypeId.expandOf(typeId, CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, name)); | |
+ final Type propertyType = parseTypeAnnotation(propertyTypeId, propertyTypeAnnotation); | |
+ propertiesList.add(new ObjectType.Property(name, propertyType, optional)); | |
+ }); | |
+ | |
+ return new ObjectType(typeId, propertiesList.build()); | |
+ } | |
+ | |
+ private Type parseReservedFunctionValueTypeAnnotation( | |
+ final TypeId typeId, final JsonObject typeAnnotation) { | |
+ return new ReservedFunctionValueType( | |
+ typeId, | |
+ ReservedFunctionValueType.ReservedName.valueOf(typeAnnotation.get("name").getAsString())); | |
+ } | |
+ | |
+ private Type maybeCreateNullableType(final boolean nullable, final Type original) { | |
+ if (!nullable || original instanceof VoidType) { | |
+ return original; | |
+ } | |
+ return new NullableType(TypeId.of(original.getTypeId()), original); | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/AliasType.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/AliasType.java | |
new file mode 100644 | |
index 0000000..4114dc5 | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/AliasType.java | |
@@ -0,0 +1,19 @@ | |
+/* | |
+ * 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 static final String TYPE_NAME = "TypeAliasTypeAnnotation"; | |
+ | |
+ public final TypeId referredTypeId; | |
+ | |
+ public AliasType(final TypeId typeId, final TypeId referredTypeId) { | |
+ super(typeId); | |
+ this.referredTypeId = referredTypeId; | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/AnyType.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/AnyType.java | |
new file mode 100644 | |
index 0000000..ce22b20 | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/AnyType.java | |
@@ -0,0 +1,16 @@ | |
+/* | |
+ * 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 static final String TYPE_NAME = "AnyTypeAnnotation"; | |
+ | |
+ public AnyType(final TypeId typeId) { | |
+ super(typeId); | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/ArrayType.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/ArrayType.java | |
new file mode 100644 | |
index 0000000..536a082 | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/ArrayType.java | |
@@ -0,0 +1,19 @@ | |
+/* | |
+ * 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 static final String TYPE_NAME = "ArrayTypeAnnotation"; | |
+ | |
+ public final Type elementType; | |
+ | |
+ public ArrayType(final TypeId typeId, final Type elementType) { | |
+ super(typeId); | |
+ this.elementType = elementType; | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/BooleanType.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/BooleanType.java | |
new file mode 100644 | |
index 0000000..c5f8b9b | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/BooleanType.java | |
@@ -0,0 +1,16 @@ | |
+/* | |
+ * 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 static final String TYPE_NAME = "BooleanTypeAnnotation"; | |
+ | |
+ public BooleanType(final TypeId typeId) { | |
+ super(typeId); | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/CodegenException.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/CodegenException.java | |
new file mode 100644 | |
index 0000000..0b0ff3c | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/CodegenException.java | |
@@ -0,0 +1,16 @@ | |
+/* | |
+ * 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 CodegenException extends RuntimeException { | |
+ private static final long serialVersionUID = 1L; | |
+ | |
+ public CodegenException(final String message) { | |
+ super(message); | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/DoubleType.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/DoubleType.java | |
new file mode 100644 | |
index 0000000..ddfa061 | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/DoubleType.java | |
@@ -0,0 +1,16 @@ | |
+/* | |
+ * 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 static final String TYPE_NAME = "DoubleTypeAnnotation"; | |
+ | |
+ public DoubleType(final TypeId typeId) { | |
+ super(typeId); | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/FloatType.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/FloatType.java | |
new file mode 100644 | |
index 0000000..6698735 | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/FloatType.java | |
@@ -0,0 +1,16 @@ | |
+/* | |
+ * 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 static final String TYPE_NAME = "FloatTypeAnnotation"; | |
+ | |
+ public FloatType(final TypeId typeId) { | |
+ super(typeId); | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/FunctionType.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/FunctionType.java | |
new file mode 100644 | |
index 0000000..d664d74 | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/FunctionType.java | |
@@ -0,0 +1,89 @@ | |
+/* | |
+ * 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 final String TYPE_NAME = "FunctionTypeAnnotation"; | |
+ | |
+ public static class ArgumentType { | |
+ public final String name; | |
+ public final Type type; | |
+ | |
+ // Note: Function argument is not optional. | |
+ // TODO (T71926678): Revisit if optional should be supported. | |
+ 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); | |
+ } | |
+ | |
+ @Override | |
+ public String toString() { | |
+ return name + ": " + type; | |
+ } | |
+ } | |
+ | |
+ public static ArgumentType createArgument(String name, Type type) { | |
+ return new ArgumentType(name, type); | |
+ } | |
+ | |
+ public final List<ArgumentType> parameters; | |
+ public final Type returnType; | |
+ | |
+ public FunctionType( | |
+ final TypeId typeId, final List<ArgumentType> parameters, final Type returnType) { | |
+ super(typeId); | |
+ this.parameters = Collections.unmodifiableList(parameters); | |
+ this.returnType = returnType; | |
+ } | |
+ | |
+ @Override | |
+ public boolean equals(final Object o) { | |
+ if (this == o) { | |
+ return true; | |
+ } | |
+ if (o == null || getClass() != o.getClass() || !super.equals(o)) { | |
+ return false; | |
+ } | |
+ | |
+ final 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); | |
+ } | |
+ | |
+ @Override | |
+ public String toString() { | |
+ return "(" + returnType + ")" + this.getTypeId() + "(" + parameters + ")"; | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/GenericObjectType.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/GenericObjectType.java | |
new file mode 100644 | |
index 0000000..ce4a2b0 | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/GenericObjectType.java | |
@@ -0,0 +1,16 @@ | |
+/* | |
+ * 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 static final String TYPE_NAME = "GenericObjectTypeAnnotation"; | |
+ | |
+ public GenericObjectType(final TypeId typeId) { | |
+ super(typeId); | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/Int32Type.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/Int32Type.java | |
new file mode 100644 | |
index 0000000..4639d39 | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/Int32Type.java | |
@@ -0,0 +1,16 @@ | |
+/* | |
+ * 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 static final String TYPE_NAME = "Int32TypeAnnotation"; | |
+ | |
+ public Int32Type(final TypeId typeId) { | |
+ super(typeId); | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/NativeModuleType.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/NativeModuleType.java | |
new file mode 100644 | |
index 0000000..2f3a410 | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/NativeModuleType.java | |
@@ -0,0 +1,48 @@ | |
+/* | |
+ * 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; | |
+ | |
+public final class NativeModuleType extends Type { | |
+ public static String TYPE_NAME = "<NONE>"; // Not an actual type in the schema. | |
+ | |
+ public final List<Type> aliases; | |
+ public final List<Property> properties; | |
+ | |
+ public static class Property { | |
+ public final String name; | |
+ public final FunctionType type; | |
+ public final boolean optional; | |
+ | |
+ public Property(final String name, final Type type, final boolean optional) { | |
+ assertType(type, FunctionType.class); | |
+ this.name = name; | |
+ this.type = (FunctionType) type; | |
+ this.optional = optional; | |
+ } | |
+ | |
+ @Override | |
+ public String toString() { | |
+ return name + ": " + (this.optional ? "?" : "") + type; | |
+ } | |
+ } | |
+ | |
+ public NativeModuleType( | |
+ final TypeId typeId, final List<Type> aliases, final List<Property> properties) { | |
+ super(typeId); | |
+ this.aliases = Collections.unmodifiableList(aliases); | |
+ this.properties = Collections.unmodifiableList(properties); | |
+ } | |
+ | |
+ @Override | |
+ public String toString() { | |
+ return getTypeId() + "\n aliases: " + aliases + "\n properties: " + properties; | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/NullableType.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/NullableType.java | |
new file mode 100644 | |
index 0000000..5180925 | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/NullableType.java | |
@@ -0,0 +1,19 @@ | |
+/* | |
+ * 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 NullableType extends Type { | |
+ public static final String TYPE_NAME = "NullableTypeAnnotation"; | |
+ | |
+ public final Type innerType; | |
+ | |
+ public NullableType(final TypeId typeId, final Type innerType) { | |
+ super(typeId); | |
+ this.innerType = innerType; | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/NumberType.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/NumberType.java | |
new file mode 100644 | |
index 0000000..382e068 | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/NumberType.java | |
@@ -0,0 +1,16 @@ | |
+/* | |
+ * 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 abstract class NumberType extends Type { | |
+ public static final String TYPE_NAME = "NumberTypeAnnotation"; | |
+ | |
+ public NumberType(final TypeId typeId) { | |
+ super(typeId); | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/ObjectType.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/ObjectType.java | |
new file mode 100644 | |
index 0000000..3c1fcab | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/ObjectType.java | |
@@ -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.Collections; | |
+import java.util.List; | |
+ | |
+public final class ObjectType extends Type { | |
+ public static final String TYPE_NAME = "ObjectTypeAnnotation"; | |
+ | |
+ public static class Property { | |
+ public final String name; | |
+ public final Type type; | |
+ public final boolean optional; | |
+ | |
+ public Property(String name, Type type, boolean optional) { | |
+ this.name = name; | |
+ this.type = type; | |
+ this.optional = optional; | |
+ } | |
+ | |
+ @Override | |
+ public String toString() { | |
+ return (optional ? "?" : "") + name + ": " + type; | |
+ } | |
+ } | |
+ | |
+ public final List<Property> properties; | |
+ | |
+ public ObjectType(final TypeId typeId, final List<Property> properties) { | |
+ super(typeId); | |
+ this.properties = Collections.unmodifiableList(properties); | |
+ } | |
+ | |
+ @Override | |
+ public String toString() { | |
+ return getTypeId() + " -> " + properties; | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/PromiseType.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/PromiseType.java | |
new file mode 100644 | |
index 0000000..c243cae | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/PromiseType.java | |
@@ -0,0 +1,16 @@ | |
+/* | |
+ * 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 PromiseType extends Type { | |
+ public static final String TYPE_NAME = "PromiseTypeAnnotation"; | |
+ | |
+ public PromiseType(final TypeId typeId) { | |
+ super(typeId); | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/ReservedFunctionValueType.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/ReservedFunctionValueType.java | |
new file mode 100644 | |
index 0000000..c1f755e | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/ReservedFunctionValueType.java | |
@@ -0,0 +1,28 @@ | |
+/* | |
+ * 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 static final String TYPE_NAME = "ReservedFunctionValueTypeAnnotation"; | |
+ | |
+ public enum ReservedName { | |
+ RootTag, | |
+ } | |
+ | |
+ public ReservedName reservedName; | |
+ | |
+ public ReservedFunctionValueType(final TypeId typeId, ReservedName reservedName) { | |
+ super(typeId); | |
+ this.reservedName = reservedName; | |
+ } | |
+ | |
+ @Override | |
+ public String toString() { | |
+ return mTypeId + "(" + reservedName.toString() + ")"; | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/StringType.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/StringType.java | |
new file mode 100644 | |
index 0000000..39ba374 | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/StringType.java | |
@@ -0,0 +1,16 @@ | |
+/* | |
+ * 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 static final String TYPE_NAME = "StringTypeAnnotation"; | |
+ | |
+ public StringType(final TypeId typeId) { | |
+ super(typeId); | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/Type.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/Type.java | |
new file mode 100644 | |
index 0000000..b6151d2 | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/Type.java | |
@@ -0,0 +1,54 @@ | |
+/* | |
+ * 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 { | |
+ public static String TYPE_NAME = "<NONE>"; | |
+ | |
+ protected final TypeId mTypeId; | |
+ | |
+ public static <T extends Type> void assertType( | |
+ final Type type, final Class<T> expectedTypeClass) { | |
+ if (!expectedTypeClass.isInstance(type)) { | |
+ throw new IllegalStateException( | |
+ "Expected: " + expectedTypeClass.getName() + " but found: " + type.getClass().getName()); | |
+ } | |
+ } | |
+ | |
+ 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); | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/TypeData.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/TypeData.java | |
new file mode 100644 | |
index 0000000..91a58f5 | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/TypeData.java | |
@@ -0,0 +1,48 @@ | |
+/* | |
+ * 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.HashMap; | |
+import java.util.Map; | |
+import java.util.Set; | |
+import javax.annotation.Nullable; | |
+ | |
+/** A collection of all types information based on the parsed schema. */ | |
+public final class TypeData { | |
+ private final Map<TypeId, Type> mTypes = new HashMap<>(); | |
+ | |
+ public void addType(final TypeId typeId, final Type type) throws IllegalStateException { | |
+ if (getType(typeId) != null) { | |
+ throw new IllegalStateException("Found duplicated TypeId: " + typeId + " for: " + type); | |
+ } | |
+ mTypes.put(typeId, type); | |
+ } | |
+ | |
+ public void addType(final Type type) { | |
+ addType(type.getTypeId(), type); | |
+ } | |
+ | |
+ public @Nullable Type getType(final TypeId typeId) { | |
+ return mTypes.get(typeId); | |
+ } | |
+ | |
+ public Set<TypeId> getAllTypes() { | |
+ return mTypes.keySet(); | |
+ } | |
+ | |
+ @Override | |
+ public String toString() { | |
+ final StringBuilder builder = new StringBuilder(); | |
+ mTypes.forEach( | |
+ (k, v) -> { | |
+ builder.append(v.toString()); | |
+ builder.append("\n"); | |
+ }); | |
+ return builder.toString(); | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/TypeId.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/TypeId.java | |
new file mode 100644 | |
index 0000000..ef9831c | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/TypeId.java | |
@@ -0,0 +1,74 @@ | |
+/* | |
+ * 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; | |
+import javax.annotation.Nullable; | |
+ | |
+/** Represents the fully qualified name for a Flow type. */ | |
+public final class TypeId { | |
+ public final String moduleName; | |
+ public final String typeName; | |
+ | |
+ private static final String EMPTY_TYPE_NAME = ""; | |
+ | |
+ private TypeId(final String moduleName, final String typeName) { | |
+ this.moduleName = moduleName; | |
+ this.typeName = typeName; | |
+ } | |
+ | |
+ public static TypeId of(final String moduleName) { | |
+ return new TypeId(moduleName, EMPTY_TYPE_NAME); | |
+ } | |
+ | |
+ public static TypeId of(final String moduleName, @Nullable final String typeName) { | |
+ if (typeName == null) { | |
+ return TypeId.of(moduleName); | |
+ } | |
+ | |
+ if (moduleName.equals(typeName)) { | |
+ return TypeId.of(moduleName); | |
+ } | |
+ | |
+ return new TypeId(moduleName, typeName); | |
+ } | |
+ | |
+ public static TypeId of(final TypeId typeId) { | |
+ return of(typeId.moduleName, typeId.typeName); | |
+ } | |
+ | |
+ public static TypeId expandOf(final TypeId typeId, String suffix) { | |
+ return of(typeId.moduleName, typeId.typeName + suffix); | |
+ } | |
+ | |
+ @Override | |
+ public String toString() { | |
+ return String.format( | |
+ "<moduleName = %s, typeName = %s>", | |
+ moduleName, EMPTY_TYPE_NAME.equals(typeName) ? "\"\"" : typeName); | |
+ } | |
+ | |
+ @Override | |
+ public boolean equals(final Object o) { | |
+ if (this == o) { | |
+ return true; | |
+ } | |
+ if (o == null || getClass() != o.getClass()) { | |
+ return false; | |
+ } | |
+ | |
+ final TypeId typeId = (TypeId) o; | |
+ return Objects.equals(moduleName, typeId.moduleName) | |
+ && Objects.equals(typeName, typeId.typeName); | |
+ } | |
+ | |
+ @Override | |
+ public int hashCode() { | |
+ return Objects.hash(moduleName, typeName); | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/VoidType.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/VoidType.java | |
new file mode 100644 | |
index 0000000..29ea494 | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/model/VoidType.java | |
@@ -0,0 +1,17 @@ | |
+/* | |
+ * 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 VoidType extends Type { | |
+ public static final String TYPE_NAME = "VoidTypeAnnotation"; | |
+ public static final VoidType VOID = new VoidType(TypeId.of("")); | |
+ | |
+ private VoidType(final TypeId typeId) { | |
+ super(typeId); | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/AliasResolvedType.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/AliasResolvedType.java | |
new file mode 100644 | |
index 0000000..6720ef7 | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/AliasResolvedType.java | |
@@ -0,0 +1,43 @@ | |
+/* | |
+ * 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.resolver; | |
+ | |
+import com.facebook.react.codegen.generator.model.AliasType; | |
+import com.facebook.react.codegen.generator.model.AnyType; | |
+import com.facebook.react.codegen.generator.model.Type; | |
+import com.facebook.react.codegen.generator.model.TypeData; | |
+import com.squareup.javapoet.TypeName; | |
+import com.squareup.javapoet.TypeSpec; | |
+import javax.annotation.Nullable; | |
+ | |
+public final class AliasResolvedType extends ResolvedType<AliasType> { | |
+ | |
+ private AliasResolvedType(final AliasType type, final boolean nullable) { | |
+ super(type, nullable); | |
+ throw new UnsupportedOperationException(); | |
+ } | |
+ | |
+ public static ResolvedType create( | |
+ final AliasType type, final TypeData typeData, final boolean nullable) { | |
+ Type referredType = typeData.getType(type.referredTypeId); | |
+ if (referredType != null) { | |
+ return resolveType(referredType, typeData, nullable); | |
+ } | |
+ return resolveType(new AnyType(type.getTypeId()), typeData, nullable); | |
+ } | |
+ | |
+ @Override | |
+ public TypeName getNativeType(final NativeTypeContext typeContext) { | |
+ throw new UnsupportedOperationException(); | |
+ } | |
+ | |
+ @Override | |
+ public @Nullable TypeSpec getGeneratedCode(final String packageName) { | |
+ throw new UnsupportedOperationException(); | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/Annotations.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/Annotations.java | |
new file mode 100644 | |
index 0000000..4025b54 | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/Annotations.java | |
@@ -0,0 +1,16 @@ | |
+/* | |
+ * 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.resolver; | |
+ | |
+import com.squareup.javapoet.AnnotationSpec; | |
+import javax.annotation.Nullable; | |
+ | |
+public class Annotations { | |
+ public static final AnnotationSpec OVERRIDE = AnnotationSpec.builder(Override.class).build(); | |
+ public static final AnnotationSpec NULLABLE = AnnotationSpec.builder(Nullable.class).build(); | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/AnyResolvedType.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/AnyResolvedType.java | |
new file mode 100644 | |
index 0000000..e9fc8dc | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/AnyResolvedType.java | |
@@ -0,0 +1,36 @@ | |
+/* | |
+ * 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.resolver; | |
+ | |
+import com.facebook.react.codegen.generator.model.AnyType; | |
+import com.facebook.react.codegen.generator.model.TypeData; | |
+import com.squareup.javapoet.TypeName; | |
+ | |
+public final class AnyResolvedType extends ResolvedType<AnyType> { | |
+ | |
+ private AnyResolvedType(final AnyType type, final boolean nullable) { | |
+ super(type, nullable); | |
+ } | |
+ | |
+ public static AnyResolvedType create( | |
+ final AnyType type, final TypeData typeData, final boolean nullable) { | |
+ return new AnyResolvedType(type, nullable); | |
+ } | |
+ | |
+ @Override | |
+ public TypeName getNativeType(final NativeTypeContext typeContext) { | |
+ switch (typeContext) { | |
+ case FUNCTION_ARGUMENT: | |
+ return TypeUtils.makeNullable(ReactClassNames.REACT_READABLE_MAP, mNullable); | |
+ case FUNCTION_RETURN: | |
+ return TypeUtils.makeNullable(ReactClassNames.REACT_WRITABLE_MAP, mNullable); | |
+ default: | |
+ return TypeUtils.makeNullable(TypeName.OBJECT, mNullable); | |
+ } | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/ArrayResolvedType.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/ArrayResolvedType.java | |
new file mode 100644 | |
index 0000000..b6a7d3b | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/ArrayResolvedType.java | |
@@ -0,0 +1,45 @@ | |
+/* | |
+ * 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.resolver; | |
+ | |
+import com.facebook.react.codegen.generator.model.ArrayType; | |
+import com.facebook.react.codegen.generator.model.TypeData; | |
+import com.squareup.javapoet.ArrayTypeName; | |
+import com.squareup.javapoet.TypeName; | |
+ | |
+public final class ArrayResolvedType extends ResolvedType<ArrayType> { | |
+ | |
+ private final ResolvedType mElementResolvedType; | |
+ | |
+ private ArrayResolvedType(final ArrayType type, final TypeData typeData, final boolean nullable) { | |
+ super(type, nullable); | |
+ mElementResolvedType = resolveType(mType.elementType, typeData, nullable); | |
+ } | |
+ | |
+ public static ArrayResolvedType create( | |
+ final ArrayType type, final TypeData typeData, final boolean nullable) { | |
+ return new ArrayResolvedType(type, typeData, nullable); | |
+ } | |
+ | |
+ public ResolvedType getElementResolvedType() { | |
+ return mElementResolvedType; | |
+ } | |
+ | |
+ @Override | |
+ public TypeName getNativeType(final NativeTypeContext typeContext) { | |
+ switch (typeContext) { | |
+ case FUNCTION_ARGUMENT: | |
+ return TypeUtils.makeNullable(ReactClassNames.REACT_READABLE_ARRAY, mNullable); | |
+ case FUNCTION_RETURN: | |
+ return TypeUtils.makeNullable(ReactClassNames.REACT_WRITABLE_ARRAY, mNullable); | |
+ default: | |
+ return TypeUtils.makeNullable( | |
+ ArrayTypeName.of(mElementResolvedType.getNativeType(typeContext)), mNullable); | |
+ } | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/BooleanResolvedType.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/BooleanResolvedType.java | |
new file mode 100644 | |
index 0000000..75ac0a7 | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/BooleanResolvedType.java | |
@@ -0,0 +1,29 @@ | |
+/* | |
+ * 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.resolver; | |
+ | |
+import com.facebook.react.codegen.generator.model.BooleanType; | |
+import com.facebook.react.codegen.generator.model.TypeData; | |
+import com.squareup.javapoet.TypeName; | |
+ | |
+public final class BooleanResolvedType extends ResolvedType<BooleanType> { | |
+ | |
+ private BooleanResolvedType(final BooleanType type, final boolean nullable) { | |
+ super(type, nullable); | |
+ } | |
+ | |
+ public static BooleanResolvedType create( | |
+ final BooleanType type, final TypeData typeData, final boolean nullable) { | |
+ return new BooleanResolvedType(type, nullable); | |
+ } | |
+ | |
+ @Override | |
+ public TypeName getNativeType(final NativeTypeContext typeContext) { | |
+ return TypeUtils.makeNullable(TypeName.BOOLEAN, mNullable); | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/ClassNames.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/ClassNames.java | |
new file mode 100644 | |
index 0000000..5a76753 | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/ClassNames.java | |
@@ -0,0 +1,23 @@ | |
+/* | |
+ * 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.resolver; | |
+ | |
+import com.squareup.javapoet.ClassName; | |
+import com.squareup.javapoet.ParameterizedTypeName; | |
+import com.squareup.javapoet.TypeName; | |
+import java.util.Map; | |
+ | |
+/** Names of Java classes required by generated code. */ | |
+public class ClassNames { | |
+ | |
+ // Java standard classes | |
+ public static final TypeName STRING = ClassName.get(String.class); | |
+ | |
+ public static final ParameterizedTypeName CONSTANTS_MAP = | |
+ ParameterizedTypeName.get(ClassName.get(Map.class), ClassNames.STRING, ClassName.OBJECT); | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/FunctionResolvedType.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/FunctionResolvedType.java | |
new file mode 100644 | |
index 0000000..2a7468c | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/FunctionResolvedType.java | |
@@ -0,0 +1,123 @@ | |
+/* | |
+ * 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.resolver; | |
+ | |
+import com.facebook.react.codegen.generator.model.FunctionType; | |
+import com.facebook.react.codegen.generator.model.TypeData; | |
+import com.squareup.javapoet.AnnotationSpec; | |
+import com.squareup.javapoet.CodeBlock; | |
+import com.squareup.javapoet.MethodSpec; | |
+import com.squareup.javapoet.ParameterSpec; | |
+import com.squareup.javapoet.TypeName; | |
+import java.util.Collections; | |
+import java.util.Map; | |
+import java.util.stream.Collectors; | |
+import javax.annotation.Nullable; | |
+import javax.lang.model.element.Modifier; | |
+ | |
+public final class FunctionResolvedType extends ResolvedType<FunctionType> { | |
+ private final Map<String, ResolvedType> mResolvedArgTypes; | |
+ private final ResolvedType mResolvedReturnType; | |
+ | |
+ private FunctionResolvedType( | |
+ final FunctionType type, final TypeData typeData, final boolean nullable) { | |
+ super(type, nullable); | |
+ mResolvedReturnType = resolveType(type.returnType, typeData, nullable); | |
+ mResolvedArgTypes = | |
+ Collections.unmodifiableMap( | |
+ type.parameters.stream() | |
+ .collect( | |
+ Collectors.toMap( | |
+ item -> item.name, item -> resolveType(item.type, typeData, false)))); | |
+ } | |
+ | |
+ public static FunctionResolvedType create( | |
+ final FunctionType type, final TypeData typeData, final boolean nullable) { | |
+ return new FunctionResolvedType(type, typeData, nullable); | |
+ } | |
+ | |
+ public ResolvedType getResolvedReturnType() { | |
+ return mResolvedReturnType; | |
+ } | |
+ | |
+ public Map<String, ResolvedType> getResolvedArgTypes() { | |
+ return mResolvedArgTypes; | |
+ } | |
+ | |
+ @Override | |
+ public TypeName getNativeType(final NativeTypeContext typeContext) { | |
+ return TypeUtils.makeNullable(ReactClassNames.REACT_CALLBACK, mNullable); | |
+ } | |
+ | |
+ public MethodSpec getGeneratedMethodWithReactAnnotation(String methodName) { | |
+ TypeName resolvedReturnTypeName = | |
+ mResolvedReturnType.getNativeType(NativeTypeContext.FUNCTION_RETURN); | |
+ | |
+ boolean isReturnTypePromise = resolvedReturnTypeName == ReactClassNames.REACT_PROMISE; | |
+ TypeName returnTypeName = isReturnTypePromise ? TypeName.VOID : resolvedReturnTypeName; | |
+ | |
+ MethodSpec.Builder methodBuilder = | |
+ MethodSpec.methodBuilder(methodName).addModifiers(Modifier.PUBLIC); | |
+ methodBuilder.returns(returnTypeName); | |
+ | |
+ if (!mNullable) { | |
+ methodBuilder.addModifiers(Modifier.ABSTRACT); | |
+ } else { | |
+ String returnStatement = getFalsyReturnStatement(returnTypeName); | |
+ if (returnStatement != null) { | |
+ CodeBlock.Builder methodBody = CodeBlock.builder(); | |
+ methodBody.addStatement(returnStatement); | |
+ methodBuilder.addCode(methodBody.build()); | |
+ } | |
+ } | |
+ | |
+ mResolvedArgTypes | |
+ .entrySet() | |
+ .forEach( | |
+ e -> { | |
+ String argName = e.getKey(); | |
+ ResolvedType argResolvedType = e.getValue(); | |
+ methodBuilder.addParameter( | |
+ ParameterSpec.builder( | |
+ argResolvedType.getNativeType(NativeTypeContext.FUNCTION_ARGUMENT), | |
+ argName) | |
+ .build()); | |
+ }); | |
+ | |
+ AnnotationSpec.Builder annotationBuilder = AnnotationSpec.builder(ReactClassNames.REACT_METHOD); | |
+ | |
+ // Special case: Promise inserts additional method arg at the end. | |
+ if (isReturnTypePromise) { | |
+ methodBuilder.addParameter( | |
+ ParameterSpec.builder(ReactClassNames.REACT_PROMISE, "promise").build()); | |
+ } else if (!TypeName.VOID.equals(returnTypeName)) { | |
+ // A non-promise non-void return type means the method is synchronous. | |
+ annotationBuilder.addMember("isBlockingSynchronousMethod", "$L", true); | |
+ } | |
+ | |
+ // React methods need special `@ReactMethod` annotation for now. | |
+ methodBuilder.addAnnotation(annotationBuilder.build()); | |
+ | |
+ return methodBuilder.build(); | |
+ } | |
+ | |
+ private static @Nullable String getFalsyReturnStatement(TypeName returnType) { | |
+ // TODO: Handle nullable falsy return. | |
+ if (returnType == TypeName.BOOLEAN) { | |
+ return "return false"; | |
+ } else if (returnType == TypeName.DOUBLE) { | |
+ return "return 0.0"; | |
+ } else if (returnType == ClassNames.STRING | |
+ || returnType == ReactClassNames.REACT_WRITABLE_ARRAY | |
+ || returnType == ReactClassNames.REACT_WRITABLE_MAP) { | |
+ return "return null"; | |
+ } | |
+ | |
+ return null; | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/GenericObjectResolvedType.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/GenericObjectResolvedType.java | |
new file mode 100644 | |
index 0000000..84b98eb | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/GenericObjectResolvedType.java | |
@@ -0,0 +1,40 @@ | |
+/* | |
+ * 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.resolver; | |
+ | |
+import com.facebook.react.codegen.generator.model.CodegenException; | |
+import com.facebook.react.codegen.generator.model.GenericObjectType; | |
+import com.facebook.react.codegen.generator.model.TypeData; | |
+import com.squareup.javapoet.TypeName; | |
+ | |
+public final class GenericObjectResolvedType extends ResolvedType<GenericObjectType> { | |
+ | |
+ private GenericObjectResolvedType(final GenericObjectType type, final boolean nullable) { | |
+ super(type, nullable); | |
+ } | |
+ | |
+ public static GenericObjectResolvedType create( | |
+ final GenericObjectType type, final TypeData typeData, final boolean nullable) { | |
+ return new GenericObjectResolvedType(type, nullable); | |
+ } | |
+ | |
+ @Override | |
+ public TypeName getNativeType(final NativeTypeContext typeContext) { | |
+ switch (typeContext) { | |
+ case FUNCTION_ARGUMENT: | |
+ return TypeUtils.makeNullable(ReactClassNames.REACT_READABLE_MAP, mNullable); | |
+ case FUNCTION_RETURN: | |
+ return TypeUtils.makeNullable(ReactClassNames.REACT_WRITABLE_MAP, mNullable); | |
+ default: | |
+ break; | |
+ } | |
+ | |
+ throw new CodegenException( | |
+ "Unsupported GenericObjectType: " + mType + " - typeContext: " + typeContext); | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/NativeModuleResolvedType.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/NativeModuleResolvedType.java | |
new file mode 100644 | |
index 0000000..0022209 | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/NativeModuleResolvedType.java | |
@@ -0,0 +1,260 @@ | |
+/* | |
+ * 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.resolver; | |
+ | |
+import com.facebook.react.codegen.generator.model.NativeModuleType; | |
+import com.facebook.react.codegen.generator.model.TypeData; | |
+import com.squareup.javapoet.ClassName; | |
+import com.squareup.javapoet.CodeBlock; | |
+import com.squareup.javapoet.MethodSpec; | |
+import com.squareup.javapoet.ParameterSpec; | |
+import com.squareup.javapoet.ParameterizedTypeName; | |
+import com.squareup.javapoet.TypeName; | |
+import com.squareup.javapoet.TypeSpec; | |
+import java.util.Arrays; | |
+import java.util.Collections; | |
+import java.util.HashSet; | |
+import java.util.List; | |
+import java.util.Map; | |
+import java.util.Set; | |
+import java.util.stream.Collectors; | |
+import javax.annotation.Nullable; | |
+import javax.lang.model.element.Modifier; | |
+ | |
+public final class NativeModuleResolvedType extends ResolvedType<NativeModuleType> { | |
+ private final Map<String, ResolvedType> mResolvedAliasTypes; | |
+ private final Map<String, FunctionResolvedType> mResolvedPropertyTypes; | |
+ | |
+ private NativeModuleResolvedType( | |
+ final NativeModuleType type, final TypeData typeData, final boolean nullable) { | |
+ super(type, nullable); | |
+ mResolvedAliasTypes = | |
+ Collections.unmodifiableMap( | |
+ type.aliases.stream() | |
+ .collect( | |
+ Collectors.toMap( | |
+ item -> item.getTypeId().typeName, | |
+ item -> resolveType(item, typeData, false)))); | |
+ mResolvedPropertyTypes = | |
+ Collections.unmodifiableMap( | |
+ type.properties.stream() | |
+ .collect( | |
+ Collectors.toMap( | |
+ item -> item.name, | |
+ // TODO: Optional Object property is not necessarily nullable. | |
+ item -> { | |
+ final ResolvedType resolvedType = | |
+ resolveType(item.type, typeData, item.optional); | |
+ TypeUtils.assertCondition( | |
+ resolvedType instanceof FunctionResolvedType, | |
+ "NativeModules can only contain methods. Constants like '" | |
+ + item.name | |
+ + "' must be declared in the return type of the 'getConstants()' method."); | |
+ return (FunctionResolvedType) resolvedType; | |
+ }))); | |
+ } | |
+ | |
+ public static NativeModuleResolvedType create( | |
+ final NativeModuleType type, final TypeData typeData, final boolean nullable) { | |
+ return new NativeModuleResolvedType(type, typeData, nullable); | |
+ } | |
+ | |
+ @Override | |
+ public TypeName getNativeType(final NativeTypeContext typeContext) { | |
+ throw new UnsupportedOperationException( | |
+ "NativeModuleType cannot be referred to by other types."); | |
+ } | |
+ | |
+ @Override | |
+ public @Nullable TypeSpec getGeneratedCode(final String packageName) { | |
+ final TypeSpec.Builder classBuilder = | |
+ TypeSpec.classBuilder(mType.getTypeId().typeName) | |
+ .addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT) | |
+ .superclass(ReactClassNames.REACT_CONTEXT_BASE_JAVA_MODULE) | |
+ .addSuperinterface(ReactClassNames.REACT_MODULE_WITH_SPEC) | |
+ .addSuperinterface(ReactClassNames.REACT_TURBOMODULE); | |
+ | |
+ final MethodSpec.Builder constructorBuilder = | |
+ MethodSpec.constructorBuilder() | |
+ .addModifiers(Modifier.PUBLIC) | |
+ .addParameter( | |
+ ParameterSpec.builder(ReactClassNames.REACT_APPLICATION_CONTEXT, "reactContext") | |
+ .build()) | |
+ .addStatement("super($N)", "reactContext"); | |
+ classBuilder.addMethod(constructorBuilder.build()); | |
+ | |
+ mResolvedPropertyTypes.forEach( | |
+ (name, resolvedType) -> { | |
+ if (name.equals("getConstants")) { | |
+ classBuilder.addMethod(generateGetTypedExportedConstantsMethod()); | |
+ classBuilder.addMethod(generateGetConstantsMethod(resolvedType)); | |
+ } else { | |
+ classBuilder.addMethod( | |
+ ((FunctionResolvedType) resolvedType).getGeneratedMethodWithReactAnnotation(name)); | |
+ } | |
+ }); | |
+ | |
+ return classBuilder.build(); | |
+ } | |
+ | |
+ // For now, getConstants() needs a runtime check to ensure the object return value has the | |
+ // required properties. In the future, the method should return the specific object type that | |
+ // can be verified during build time. | |
+ private static MethodSpec generateGetConstantsMethod(final FunctionResolvedType resolvedType) { | |
+ final ResolvedType resolvedReturnType = resolvedType.getResolvedReturnType(); | |
+ TypeUtils.assertCondition( | |
+ resolvedReturnType instanceof ObjectResolvedType, | |
+ "getConstants() method must return an exact object. Found: " + resolvedType.mType); | |
+ | |
+ final ParameterizedTypeName returnType = | |
+ ParameterizedTypeName.get(ClassName.get(Map.class), ClassNames.STRING, ClassName.OBJECT); | |
+ return MethodSpec.methodBuilder("getConstants") | |
+ .addModifiers(Modifier.PUBLIC, Modifier.FINAL) | |
+ .addAnnotation(Annotations.OVERRIDE) | |
+ .returns(returnType.annotated(Annotations.NULLABLE)) | |
+ .addCode( | |
+ getConstantsMethodBody( | |
+ returnType, ((ObjectResolvedType) resolvedReturnType).getResolvedPropertyTypes())) | |
+ .build(); | |
+ } | |
+ | |
+ private static MethodSpec generateGetTypedExportedConstantsMethod() { | |
+ return MethodSpec.methodBuilder("getTypedExportedConstants") | |
+ .addModifiers(Modifier.PROTECTED, Modifier.ABSTRACT) | |
+ .returns(ClassNames.CONSTANTS_MAP) | |
+ .build(); | |
+ } | |
+ | |
+ private static CodeBlock getConstantsMethodBody( | |
+ final ParameterizedTypeName returnType, final Map<String, ResolvedType> constantsTypes) { | |
+ final CodeBlock.Builder methodBody = CodeBlock.builder(); | |
+ | |
+ final Map<Boolean, List<Map.Entry<String, ResolvedType>>> constantsByNullability = | |
+ constantsTypes.entrySet().stream() | |
+ .collect(Collectors.partitioningBy(entry -> entry.getValue().mNullable)); | |
+ | |
+ final String constantsVariableName = "constants"; | |
+ final String obligatoryFlowConstantsVariableName = "obligatoryFlowConstants"; | |
+ final String optionalFlowConstantsVariableName = "optionalFlowConstants"; | |
+ final TypeName setOfStringsType = | |
+ ParameterizedTypeName.get(ClassName.get(Set.class), ClassNames.STRING); | |
+ final TypeName hashsetType = ClassName.get(HashSet.class); | |
+ | |
+ methodBody.addStatement( | |
+ "$T $N = $N()", | |
+ returnType, | |
+ constantsVariableName, | |
+ generateGetTypedExportedConstantsMethod().name); | |
+ | |
+ // Enable all of this for internal (debug) builds only. | |
+ methodBody.beginControlFlow( | |
+ "if ($1T.DEBUG || $1T.IS_INTERNAL_BUILD)", ReactClassNames.REACT_BUILD_CONFIG); | |
+ { | |
+ final List<String> obligatoryConstants = | |
+ constantsByNullability.get(false).stream() | |
+ .map(Map.Entry::getKey) | |
+ .sorted() | |
+ .collect(Collectors.toList()); | |
+ addVariableDeclaration( | |
+ methodBody, | |
+ obligatoryFlowConstantsVariableName, | |
+ obligatoryConstants, | |
+ setOfStringsType, | |
+ hashsetType); | |
+ | |
+ final List<String> optionalConstants = | |
+ constantsByNullability.get(true).stream() | |
+ .map(Map.Entry::getKey) | |
+ .sorted() | |
+ .collect(Collectors.toList()); | |
+ addVariableDeclaration( | |
+ methodBody, | |
+ optionalFlowConstantsVariableName, | |
+ optionalConstants, | |
+ setOfStringsType, | |
+ hashsetType); | |
+ | |
+ final String undeclaredConstantsVariableName = "undeclaredConstants"; | |
+ | |
+ methodBody | |
+ .addStatement( | |
+ "$T $N = new $T<>($N.keySet())", | |
+ setOfStringsType, | |
+ undeclaredConstantsVariableName, | |
+ hashsetType, | |
+ constantsVariableName) | |
+ .addStatement( | |
+ "$N.removeAll($N)", | |
+ undeclaredConstantsVariableName, | |
+ obligatoryFlowConstantsVariableName) | |
+ .addStatement( | |
+ "$N.removeAll($N)", | |
+ undeclaredConstantsVariableName, | |
+ optionalFlowConstantsVariableName); | |
+ methodBody.add( | |
+ checkForConstantsFulfillmentBlock( | |
+ undeclaredConstantsVariableName, | |
+ "Native Module Flow doesn\'t declare constants: %s")); | |
+ | |
+ methodBody | |
+ .addStatement( | |
+ "$N = $N", undeclaredConstantsVariableName, obligatoryFlowConstantsVariableName) | |
+ .addStatement( | |
+ "$N.removeAll($N.keySet())", undeclaredConstantsVariableName, constantsVariableName); | |
+ methodBody.add( | |
+ checkForConstantsFulfillmentBlock( | |
+ undeclaredConstantsVariableName, "Native Module doesn\'t fill in constants: %s")); | |
+ } | |
+ methodBody.endControlFlow(); | |
+ methodBody.addStatement("return $N", constantsVariableName); | |
+ | |
+ return methodBody.build(); | |
+ } | |
+ | |
+ private static void addVariableDeclaration( | |
+ final CodeBlock.Builder builder, | |
+ final String variableName, | |
+ final List<String> values, | |
+ final TypeName varType, | |
+ final TypeName actualType) { | |
+ if (values.isEmpty()) { | |
+ builder.addStatement("$T $N = new $T<>()", varType, variableName, actualType); | |
+ } else { | |
+ builder.add( | |
+ "$T $N = new $T<>($T.asList(\n", | |
+ varType, | |
+ variableName, | |
+ actualType, | |
+ ClassName.get(Arrays.class)); | |
+ builder.indent().indent(); | |
+ | |
+ int constantsToAdd = values.size(); | |
+ for (final String constantName : values) { | |
+ builder.add("\"$L\"", constantName); | |
+ if (--constantsToAdd > 0) { | |
+ builder.add(","); | |
+ } | |
+ builder.add("\n"); | |
+ } | |
+ | |
+ builder.unindent().unindent(); | |
+ builder.addStatement("))"); | |
+ } | |
+ } | |
+ | |
+ private static CodeBlock checkForConstantsFulfillmentBlock( | |
+ final String undeclaredConstantsVariableName, final String formatString) { | |
+ return CodeBlock.builder() | |
+ .beginControlFlow("if (!$N.isEmpty())", undeclaredConstantsVariableName) | |
+ .addStatement( | |
+ "throw new IllegalStateException(String.format(\"" + formatString + "\", $N))", | |
+ undeclaredConstantsVariableName) | |
+ .endControlFlow() | |
+ .build(); | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/NullableResolvedType.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/NullableResolvedType.java | |
new file mode 100644 | |
index 0000000..b5dd2fe | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/NullableResolvedType.java | |
@@ -0,0 +1,37 @@ | |
+/* | |
+ * 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.resolver; | |
+ | |
+import com.facebook.react.codegen.generator.model.NullableType; | |
+import com.facebook.react.codegen.generator.model.TypeData; | |
+import com.squareup.javapoet.TypeName; | |
+import com.squareup.javapoet.TypeSpec; | |
+import javax.annotation.Nullable; | |
+ | |
+public final class NullableResolvedType extends ResolvedType<NullableType> { | |
+ | |
+ private NullableResolvedType(final NullableType type, final boolean nullable) { | |
+ super(type, nullable); | |
+ throw new UnsupportedOperationException(); | |
+ } | |
+ | |
+ public static ResolvedType create( | |
+ final NullableType type, final TypeData typeData, final boolean nullable) { | |
+ return resolveType(type.innerType, typeData, true); | |
+ } | |
+ | |
+ @Override | |
+ public TypeName getNativeType(final NativeTypeContext typeContext) { | |
+ throw new UnsupportedOperationException(); | |
+ } | |
+ | |
+ @Override | |
+ public @Nullable TypeSpec getGeneratedCode(final String packageName) { | |
+ throw new UnsupportedOperationException(); | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/NumberResolvedType.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/NumberResolvedType.java | |
new file mode 100644 | |
index 0000000..6a9576e | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/NumberResolvedType.java | |
@@ -0,0 +1,42 @@ | |
+/* | |
+ * 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.resolver; | |
+ | |
+import com.facebook.react.codegen.generator.model.CodegenException; | |
+import com.facebook.react.codegen.generator.model.DoubleType; | |
+import com.facebook.react.codegen.generator.model.FloatType; | |
+import com.facebook.react.codegen.generator.model.Int32Type; | |
+import com.facebook.react.codegen.generator.model.NumberType; | |
+import com.facebook.react.codegen.generator.model.TypeData; | |
+import com.squareup.javapoet.TypeName; | |
+ | |
+public final class NumberResolvedType extends ResolvedType<NumberType> { | |
+ | |
+ private NumberResolvedType(final NumberType type, final boolean nullable) { | |
+ super(type, nullable); | |
+ } | |
+ | |
+ public static NumberResolvedType create( | |
+ final NumberType type, final TypeData typeData, final boolean nullable) { | |
+ return new NumberResolvedType(type, nullable); | |
+ } | |
+ | |
+ @Override | |
+ public TypeName getNativeType(final NativeTypeContext typeContext) { | |
+ if (mType instanceof Int32Type) { | |
+ return TypeUtils.makeNullable(TypeName.INT, mNullable); | |
+ } | |
+ if (mType instanceof FloatType) { | |
+ return TypeUtils.makeNullable(TypeName.FLOAT, mNullable); | |
+ } | |
+ if (mType instanceof DoubleType) { | |
+ return TypeUtils.makeNullable(TypeName.DOUBLE, mNullable); | |
+ } | |
+ throw new CodegenException("Unsupported NumberType: " + mType.getClass()); | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/ObjectResolvedType.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/ObjectResolvedType.java | |
new file mode 100644 | |
index 0000000..54a9cb0 | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/ObjectResolvedType.java | |
@@ -0,0 +1,68 @@ | |
+/* | |
+ * 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.resolver; | |
+ | |
+import com.facebook.react.codegen.generator.model.CodegenException; | |
+import com.facebook.react.codegen.generator.model.ObjectType; | |
+import com.facebook.react.codegen.generator.model.TypeData; | |
+import com.squareup.javapoet.TypeName; | |
+import com.squareup.javapoet.TypeSpec; | |
+import java.util.Collections; | |
+import java.util.Map; | |
+import java.util.stream.Collectors; | |
+import javax.annotation.Nullable; | |
+ | |
+public final class ObjectResolvedType extends ResolvedType<ObjectType> { | |
+ private final Map<String, ResolvedType> mResolvedPropertyTypes; | |
+ | |
+ private ObjectResolvedType( | |
+ final ObjectType type, final TypeData typeData, final boolean nullable) { | |
+ super(type, nullable); | |
+ mResolvedPropertyTypes = | |
+ Collections.unmodifiableMap( | |
+ type.properties.stream() | |
+ .collect( | |
+ Collectors.toMap( | |
+ item -> item.name, | |
+ // TODO: Optional Object property is not necessarily nullable. | |
+ item -> resolveType(item.type, typeData, item.optional)))); | |
+ } | |
+ | |
+ public static ObjectResolvedType create( | |
+ final ObjectType type, final TypeData typeData, final boolean nullable) { | |
+ return new ObjectResolvedType(type, typeData, nullable); | |
+ } | |
+ | |
+ public Map<String, ResolvedType> getResolvedPropertyTypes() { | |
+ return mResolvedPropertyTypes; | |
+ } | |
+ | |
+ @Override | |
+ public TypeName getNativeType(final NativeTypeContext typeContext) { | |
+ // TODO: It should return its own class type. | |
+ // However, the NativeModule system only supports built-in ReadableMap/WritableMap for now. | |
+ switch (typeContext) { | |
+ case FUNCTION_ARGUMENT: | |
+ return TypeUtils.makeNullable(ReactClassNames.REACT_READABLE_MAP, mNullable); | |
+ case FUNCTION_RETURN: | |
+ return TypeUtils.makeNullable(ReactClassNames.REACT_WRITABLE_MAP, mNullable); | |
+ default: | |
+ break; | |
+ } | |
+ | |
+ throw new CodegenException( | |
+ "Unsupported ObjectType: " + mType + " - typeContext: " + typeContext); | |
+ } | |
+ | |
+ @Override | |
+ public @Nullable TypeSpec getGeneratedCode(final String packageName) { | |
+ // TODO: Object type should produce is own class to represent its shape. | |
+ // However, the NativeModule system only supports built-in ReadableMap/WritableMap for now. | |
+ return null; | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/PromiseResolvedType.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/PromiseResolvedType.java | |
new file mode 100644 | |
index 0000000..0c575ff | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/PromiseResolvedType.java | |
@@ -0,0 +1,29 @@ | |
+/* | |
+ * 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.resolver; | |
+ | |
+import com.facebook.react.codegen.generator.model.PromiseType; | |
+import com.facebook.react.codegen.generator.model.TypeData; | |
+import com.squareup.javapoet.TypeName; | |
+ | |
+public final class PromiseResolvedType extends ResolvedType<PromiseType> { | |
+ | |
+ private PromiseResolvedType(final PromiseType type, final boolean nullable) { | |
+ super(type, nullable); | |
+ } | |
+ | |
+ public static PromiseResolvedType create( | |
+ final PromiseType type, final TypeData typeData, final boolean nullable) { | |
+ return new PromiseResolvedType(type, nullable); | |
+ } | |
+ | |
+ @Override | |
+ public TypeName getNativeType(final NativeTypeContext typeContext) { | |
+ return TypeUtils.makeNullable(ReactClassNames.REACT_PROMISE, mNullable); | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/ReactClassNames.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/ReactClassNames.java | |
new file mode 100644 | |
index 0000000..2fca4df | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/ReactClassNames.java | |
@@ -0,0 +1,39 @@ | |
+/* | |
+ * 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.resolver; | |
+ | |
+import com.squareup.javapoet.ClassName; | |
+ | |
+/** Names of React-specific Java classes required by generated code. */ | |
+public class ReactClassNames { | |
+ | |
+ public static final ClassName REACT_APPLICATION_CONTEXT = | |
+ ClassName.bestGuess("com.facebook.react.bridge.ReactApplicationContext"); | |
+ public static final ClassName REACT_CALLBACK = | |
+ ClassName.bestGuess("com.facebook.react.bridge.Callback"); | |
+ public static final ClassName REACT_CONTEXT_BASE_JAVA_MODULE = | |
+ ClassName.bestGuess("com.facebook.react.bridge.ReactContextBaseJavaModule"); | |
+ public static final ClassName REACT_METHOD = | |
+ ClassName.bestGuess("com.facebook.react.bridge.ReactMethod"); | |
+ public static final ClassName REACT_MODULE_WITH_SPEC = | |
+ ClassName.bestGuess("com.facebook.react.bridge.ReactModuleWithSpec"); | |
+ public static final ClassName REACT_PROMISE = | |
+ ClassName.bestGuess("com.facebook.react.bridge.Promise"); | |
+ public static final ClassName REACT_READABLE_ARRAY = | |
+ ClassName.bestGuess("com.facebook.react.bridge.ReadableArray"); | |
+ public static final ClassName REACT_READABLE_MAP = | |
+ ClassName.bestGuess("com.facebook.react.bridge.ReadableMap"); | |
+ public static final ClassName REACT_WRITABLE_ARRAY = | |
+ ClassName.bestGuess("com.facebook.react.bridge.WritableArray"); | |
+ public static final ClassName REACT_WRITABLE_MAP = | |
+ ClassName.bestGuess("com.facebook.react.bridge.WritableMap"); | |
+ public static final ClassName REACT_BUILD_CONFIG = | |
+ ClassName.bestGuess("com.facebook.react.common.build.ReactBuildConfig"); | |
+ public static final ClassName REACT_TURBOMODULE = | |
+ ClassName.bestGuess("com.facebook.react.turbomodule.core.interfaces.TurboModule"); | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/ReservedFunctionValueResolvedType.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/ReservedFunctionValueResolvedType.java | |
new file mode 100644 | |
index 0000000..3cd677c | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/ReservedFunctionValueResolvedType.java | |
@@ -0,0 +1,48 @@ | |
+/* | |
+ * 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.resolver; | |
+ | |
+import com.facebook.react.codegen.generator.model.CodegenException; | |
+import com.facebook.react.codegen.generator.model.DoubleType; | |
+import com.facebook.react.codegen.generator.model.ReservedFunctionValueType; | |
+import com.facebook.react.codegen.generator.model.TypeData; | |
+import com.squareup.javapoet.TypeName; | |
+import com.squareup.javapoet.TypeSpec; | |
+import javax.annotation.Nullable; | |
+ | |
+public final class ReservedFunctionValueResolvedType | |
+ extends ResolvedType<ReservedFunctionValueType> { | |
+ | |
+ private ReservedFunctionValueResolvedType( | |
+ final ReservedFunctionValueType type, final boolean nullable) { | |
+ super(type, nullable); | |
+ throw new UnsupportedOperationException(); | |
+ } | |
+ | |
+ public static ResolvedType create( | |
+ final ReservedFunctionValueType type, final TypeData typeData, final boolean nullable) { | |
+ switch (type.reservedName) { | |
+ case RootTag: | |
+ return resolveType(new DoubleType(type.getTypeId()), typeData, nullable); | |
+ default: | |
+ break; | |
+ } | |
+ | |
+ throw new CodegenException("Unsupported ReservedFunctionValueType: " + type); | |
+ } | |
+ | |
+ @Override | |
+ public TypeName getNativeType(final NativeTypeContext typeContext) { | |
+ throw new UnsupportedOperationException(); | |
+ } | |
+ | |
+ @Override | |
+ public @Nullable TypeSpec getGeneratedCode(final String packageName) { | |
+ throw new UnsupportedOperationException(); | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/ResolvedType.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/ResolvedType.java | |
new file mode 100644 | |
index 0000000..e9373ed | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/ResolvedType.java | |
@@ -0,0 +1,52 @@ | |
+/* | |
+ * 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.resolver; | |
+ | |
+import com.facebook.react.codegen.generator.model.Type; | |
+import com.facebook.react.codegen.generator.model.TypeData; | |
+import com.squareup.javapoet.TypeName; | |
+import com.squareup.javapoet.TypeSpec; | |
+import javax.annotation.Nullable; | |
+ | |
+public abstract class ResolvedType<T extends Type> { | |
+ /** Contexts native types can appear in. */ | |
+ public enum NativeTypeContext { | |
+ FUNCTION_ARGUMENT, | |
+ FUNCTION_RETURN, | |
+ DEFAULT, | |
+ } | |
+ | |
+ protected final T mType; | |
+ protected final boolean mNullable; | |
+ | |
+ protected ResolvedType(final T type, final boolean nullable) { | |
+ mType = type; | |
+ mNullable = nullable; | |
+ } | |
+ | |
+ protected static ResolvedType resolveType( | |
+ final Type type, final TypeData typeData, final boolean nullable) { | |
+ return TypeResolver.resolveType(type, typeData, nullable); | |
+ } | |
+ | |
+ public T getType() { | |
+ return mType; | |
+ } | |
+ | |
+ public boolean isNullable() { | |
+ return mNullable; | |
+ } | |
+ | |
+ /** The Java type generated for this type */ | |
+ public abstract TypeName getNativeType(NativeTypeContext typeContext); | |
+ | |
+ /** Generate code for this type itself, if applicable. */ | |
+ public @Nullable TypeSpec getGeneratedCode(final String packageName) { | |
+ return null; | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/StringResolvedType.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/StringResolvedType.java | |
new file mode 100644 | |
index 0000000..c247111 | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/StringResolvedType.java | |
@@ -0,0 +1,29 @@ | |
+/* | |
+ * 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.resolver; | |
+ | |
+import com.facebook.react.codegen.generator.model.StringType; | |
+import com.facebook.react.codegen.generator.model.TypeData; | |
+import com.squareup.javapoet.TypeName; | |
+ | |
+public final class StringResolvedType extends ResolvedType<StringType> { | |
+ | |
+ private StringResolvedType(final StringType type, final boolean nullable) { | |
+ super(type, nullable); | |
+ } | |
+ | |
+ public static StringResolvedType create( | |
+ final StringType type, final TypeData typeData, final boolean nullable) { | |
+ return new StringResolvedType(type, nullable); | |
+ } | |
+ | |
+ @Override | |
+ public TypeName getNativeType(final NativeTypeContext typeContext) { | |
+ return TypeUtils.makeNullable(ClassNames.STRING, mNullable); | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/TypeResolver.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/TypeResolver.java | |
new file mode 100644 | |
index 0000000..6b9b533 | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/TypeResolver.java | |
@@ -0,0 +1,90 @@ | |
+/* | |
+ * 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.resolver; | |
+ | |
+import com.facebook.react.codegen.generator.model.AliasType; | |
+import com.facebook.react.codegen.generator.model.AnyType; | |
+import com.facebook.react.codegen.generator.model.ArrayType; | |
+import com.facebook.react.codegen.generator.model.BooleanType; | |
+import com.facebook.react.codegen.generator.model.FunctionType; | |
+import com.facebook.react.codegen.generator.model.GenericObjectType; | |
+import com.facebook.react.codegen.generator.model.NativeModuleType; | |
+import com.facebook.react.codegen.generator.model.NullableType; | |
+import com.facebook.react.codegen.generator.model.NumberType; | |
+import com.facebook.react.codegen.generator.model.ObjectType; | |
+import com.facebook.react.codegen.generator.model.PromiseType; | |
+import com.facebook.react.codegen.generator.model.ReservedFunctionValueType; | |
+import com.facebook.react.codegen.generator.model.StringType; | |
+import com.facebook.react.codegen.generator.model.Type; | |
+import com.facebook.react.codegen.generator.model.TypeData; | |
+import com.facebook.react.codegen.generator.model.VoidType; | |
+ | |
+public final class TypeResolver { | |
+ public static ResolvedType resolveType( | |
+ final Type type, final TypeData typeData, final boolean nullable) { | |
+ | |
+ if (type instanceof AliasType) { | |
+ return AliasResolvedType.create((AliasType) type, typeData, nullable); | |
+ } | |
+ | |
+ if (type instanceof AnyType) { | |
+ return AnyResolvedType.create((AnyType) type, typeData, nullable); | |
+ } | |
+ | |
+ if (type instanceof ArrayType) { | |
+ return ArrayResolvedType.create((ArrayType) type, typeData, nullable); | |
+ } | |
+ | |
+ if (type instanceof BooleanType) { | |
+ return BooleanResolvedType.create((BooleanType) type, typeData, nullable); | |
+ } | |
+ | |
+ if (type instanceof FunctionType) { | |
+ return FunctionResolvedType.create((FunctionType) type, typeData, nullable); | |
+ } | |
+ | |
+ if (type instanceof GenericObjectType) { | |
+ return GenericObjectResolvedType.create((GenericObjectType) type, typeData, nullable); | |
+ } | |
+ | |
+ if (type instanceof NativeModuleType) { | |
+ return NativeModuleResolvedType.create((NativeModuleType) type, typeData, nullable); | |
+ } | |
+ | |
+ if (type instanceof NullableType) { | |
+ return NullableResolvedType.create((NullableType) type, typeData, nullable); | |
+ } | |
+ | |
+ if (type instanceof NumberType) { | |
+ return NumberResolvedType.create((NumberType) type, typeData, nullable); | |
+ } | |
+ | |
+ if (type instanceof ObjectType) { | |
+ return ObjectResolvedType.create((ObjectType) type, typeData, nullable); | |
+ } | |
+ | |
+ if (type instanceof PromiseType) { | |
+ return PromiseResolvedType.create((PromiseType) type, typeData, nullable); | |
+ } | |
+ | |
+ if (type instanceof ReservedFunctionValueType) { | |
+ return ReservedFunctionValueResolvedType.create( | |
+ (ReservedFunctionValueType) type, typeData, nullable); | |
+ } | |
+ | |
+ if (type instanceof StringType) { | |
+ return StringResolvedType.create((StringType) type, typeData, nullable); | |
+ } | |
+ | |
+ if (type instanceof VoidType) { | |
+ return VoidResolvedType.create((VoidType) type, typeData, nullable); | |
+ } | |
+ | |
+ throw new IllegalArgumentException("Unable to resolve unsupported type: " + type.getClass()); | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/TypeUtils.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/TypeUtils.java | |
new file mode 100644 | |
index 0000000..b8742b6 | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/TypeUtils.java | |
@@ -0,0 +1,43 @@ | |
+/* | |
+ * 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.resolver; | |
+ | |
+import com.facebook.react.codegen.generator.model.CodegenException; | |
+import com.squareup.javapoet.ParameterizedTypeName; | |
+import com.squareup.javapoet.TypeName; | |
+import com.squareup.javapoet.TypeVariableName; | |
+ | |
+public class TypeUtils { | |
+ | |
+ public static TypeName getNativeClassName(TypeName className) { | |
+ while (className instanceof ParameterizedTypeName) { | |
+ className = ((ParameterizedTypeName) className).rawType; | |
+ } | |
+ | |
+ return (className instanceof TypeVariableName) ? TypeName.OBJECT : className.box(); | |
+ } | |
+ | |
+ public static TypeName makeNullable(final TypeName typeName, final boolean isNullable) { | |
+ if (isNullable) { | |
+ if (typeName.isPrimitive()) { | |
+ return typeName.box(); | |
+ } | |
+ if (!typeName.annotations.contains(Annotations.NULLABLE)) { | |
+ return typeName.annotated(Annotations.NULLABLE); | |
+ } | |
+ } | |
+ return typeName; | |
+ } | |
+ | |
+ public static void assertCondition(final boolean condition, final String errorMessage) | |
+ throws CodegenException { | |
+ if (!condition) { | |
+ throw new CodegenException(errorMessage); | |
+ } | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/VoidResolvedType.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/VoidResolvedType.java | |
new file mode 100644 | |
index 0000000..0665ddf | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/generator/resolver/VoidResolvedType.java | |
@@ -0,0 +1,36 @@ | |
+/* | |
+ * 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.resolver; | |
+ | |
+import com.facebook.react.codegen.generator.model.TypeData; | |
+import com.facebook.react.codegen.generator.model.VoidType; | |
+import com.squareup.javapoet.TypeName; | |
+import com.squareup.javapoet.TypeSpec; | |
+import javax.annotation.Nullable; | |
+ | |
+public final class VoidResolvedType extends ResolvedType<VoidType> { | |
+ | |
+ private VoidResolvedType(final VoidType type, final boolean nullable) { | |
+ super(type, nullable); | |
+ } | |
+ | |
+ public static VoidResolvedType create( | |
+ final VoidType type, final TypeData typeData, final boolean nullable) { | |
+ return new VoidResolvedType(type, nullable); | |
+ } | |
+ | |
+ @Override | |
+ public TypeName getNativeType(final NativeTypeContext typeContext) { | |
+ return TypeName.VOID; | |
+ } | |
+ | |
+ @Override | |
+ public @Nullable TypeSpec getGeneratedCode(final String packageName) { | |
+ throw new UnsupportedOperationException(); | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/plugin/CodegenPlugin.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/plugin/CodegenPlugin.java | |
new file mode 100644 | |
index 0000000..fa148bf | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/plugin/CodegenPlugin.java | |
@@ -0,0 +1,147 @@ | |
+/* | |
+ * 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.plugin; | |
+ | |
+import com.android.build.gradle.BaseExtension; | |
+import com.facebook.react.codegen.generator.JavaGenerator; | |
+import com.google.common.collect.ImmutableList; | |
+import com.google.common.collect.ImmutableMap; | |
+import java.io.File; | |
+import org.gradle.api.GradleException; | |
+import org.gradle.api.Plugin; | |
+import org.gradle.api.Project; | |
+import org.gradle.api.Task; | |
+import org.gradle.api.tasks.Exec; | |
+ | |
+/** | |
+ * A Gradle plugin to enable react-native-codegen in Gradle environment. See the Gradle API docs for | |
+ * more information: https://docs.gradle.org/6.5.1/javadoc/org/gradle/api/Project.html | |
+ */ | |
+public class CodegenPlugin implements Plugin<Project> { | |
+ | |
+ public void apply(final Project project) { | |
+ final CodegenPluginExtension extension = | |
+ project.getExtensions().create("react", CodegenPluginExtension.class, project); | |
+ | |
+ // 1. Set up build dir. | |
+ final File generatedSrcDir = new File(project.getBuildDir(), "generated/source/codegen"); | |
+ final File generatedSchemaFile = new File(generatedSrcDir, "schema.json"); | |
+ | |
+ // 2. Task: produce schema from JS files. | |
+ project | |
+ .getTasks() | |
+ .register( | |
+ "generateCodegenSchemaFromJavaScript", | |
+ Exec.class, | |
+ task -> { | |
+ task.doFirst( | |
+ s -> { | |
+ generatedSrcDir.delete(); | |
+ generatedSrcDir.mkdirs(); | |
+ }); | |
+ | |
+ task.getInputs() | |
+ .files(project.fileTree(ImmutableMap.of("dir", extension.codegenDir()))); | |
+ task.getInputs() | |
+ .files( | |
+ project.fileTree( | |
+ ImmutableMap.of( | |
+ "dir", | |
+ extension.jsRootDir, | |
+ "includes", | |
+ ImmutableList.of("**/*.js")))); | |
+ task.getOutputs().file(generatedSchemaFile); | |
+ | |
+ ImmutableList<String> execCommands = | |
+ new ImmutableList.Builder<String>() | |
+ .add("yarn") | |
+ .addAll(ImmutableList.copyOf(extension.nodeExecutableAndArgs)) | |
+ .add(extension.codegenGenerateSchemaCLI().getAbsolutePath()) | |
+ .add(generatedSchemaFile.getAbsolutePath()) | |
+ .add(extension.jsRootDir.getAbsolutePath()) | |
+ .build(); | |
+ task.commandLine(execCommands); | |
+ }); | |
+ | |
+ // 3. Task: generate Java code from schema. | |
+ project | |
+ .getTasks() | |
+ .register( | |
+ "generateCodegenArtifactsFromSchema", | |
+ Exec.class, | |
+ task -> { | |
+ task.dependsOn("generateCodegenSchemaFromJavaScript"); | |
+ | |
+ task.getInputs() | |
+ .files(project.fileTree(ImmutableMap.of("dir", extension.codegenDir()))); | |
+ task.getInputs().files(generatedSchemaFile); | |
+ task.getOutputs().dir(generatedSrcDir); | |
+ | |
+ if (extension.useJavaGenerator) { | |
+ task.doLast( | |
+ s -> { | |
+ generateJavaFromSchemaWithJavaGenerator( | |
+ generatedSchemaFile, extension.codegenJavaPackageName, generatedSrcDir); | |
+ }); | |
+ } | |
+ | |
+ ImmutableList<String> execCommands = | |
+ new ImmutableList.Builder<String>() | |
+ .add("yarn") | |
+ .addAll(ImmutableList.copyOf(extension.nodeExecutableAndArgs)) | |
+ .add(extension.codegenGenerateNativeModuleSpecsCLI().getAbsolutePath()) | |
+ .add("android") | |
+ .add(generatedSchemaFile.getAbsolutePath()) | |
+ .add(generatedSrcDir.getAbsolutePath()) | |
+ .add(extension.libraryName) | |
+ .add(extension.codegenJavaPackageName) | |
+ .build(); | |
+ task.commandLine(execCommands); | |
+ }); | |
+ | |
+ // 4. Add dependencies & generated sources to the project. | |
+ // Note: This last step needs to happen after the project has been evaluated. | |
+ project.afterEvaluate( | |
+ s -> { | |
+ // `preBuild` is one of the base tasks automatically registered by Gradle. | |
+ // This will invoke the codegen before compiling the entire project. | |
+ Task preBuild = project.getTasks().findByName("preBuild"); | |
+ if (preBuild != null) { | |
+ preBuild.dependsOn("generateCodegenArtifactsFromSchema"); | |
+ } | |
+ | |
+ /** | |
+ * Finally, update the android configuration to include the generated sources. This | |
+ * equivalent to this DSL: | |
+ * | |
+ * <p>android { sourceSets { main { java { srcDirs += "$generatedSrcDir/java" } } } } | |
+ * | |
+ * <p>See documentation at | |
+ * https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.BaseExtension.html. | |
+ */ | |
+ BaseExtension android = (BaseExtension) project.getExtensions().getByName("android"); | |
+ android | |
+ .getSourceSets() | |
+ .getByName("main") | |
+ .getJava() | |
+ .srcDir(new File(generatedSrcDir, "java")); | |
+ }); | |
+ } | |
+ | |
+ // Use Java-based generator implementation to produce the source files, instead of using the | |
+ // JS-based generator. | |
+ private void generateJavaFromSchemaWithJavaGenerator( | |
+ final File schemaFile, final String javaPackageName, final File outputDir) { | |
+ final JavaGenerator generator = new JavaGenerator(schemaFile, javaPackageName, outputDir); | |
+ try { | |
+ generator.build(); | |
+ } catch (final Exception ex) { | |
+ throw new GradleException("Failed to generate Java from schema.", ex); | |
+ } | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/plugin/CodegenPluginExtension.java b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/plugin/CodegenPluginExtension.java | |
new file mode 100644 | |
index 0000000..70bbc82 | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/gradlePlugin/src/main/java/com/facebook/react/codegen/plugin/CodegenPluginExtension.java | |
@@ -0,0 +1,53 @@ | |
+/* | |
+ * 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.plugin; | |
+ | |
+import com.google.common.base.CaseFormat; | |
+import java.io.File; | |
+import java.util.StringTokenizer; | |
+import org.gradle.api.Project; | |
+ | |
+public class CodegenPluginExtension { | |
+ public String codegenJavaPackageName = "com.facebook.fbreact.specs"; | |
+ public File jsRootDir; | |
+ public String libraryName; | |
+ public String[] nodeExecutableAndArgs = {"node"}; | |
+ public File reactNativeRootDir; | |
+ public File projectRootDir; | |
+ public boolean useJavaGenerator = false; | |
+ | |
+ public CodegenPluginExtension(final Project project) { | |
+ this.reactNativeRootDir = new File(project.getRootDir(), "node_modules/react-native"); | |
+ this.projectRootDir = new File(project.getRootDir(), "../"); | |
+ this.libraryName = projectPathToLibraryName(project.getPath()); | |
+ } | |
+ | |
+ public File codegenDir() { | |
+ return new File(this.projectRootDir, "node_modules/react-native-codegen"); | |
+ } | |
+ | |
+ public File codegenGenerateSchemaCLI() { | |
+ return new File(this.codegenDir(), "lib/cli/combine/combine-js-to-schema-cli.js"); | |
+ } | |
+ | |
+ public File codegenGenerateNativeModuleSpecsCLI() { | |
+ return new File(this.reactNativeRootDir, "scripts/generate-specs-cli.js"); | |
+ } | |
+ | |
+ private String projectPathToLibraryName(final String projectPath) { | |
+ final StringTokenizer tokenizer = new StringTokenizer(projectPath, ":-_."); | |
+ final StringBuilder nameBuilder = new StringBuilder(); | |
+ | |
+ while (tokenizer.hasMoreTokens()) { | |
+ nameBuilder.append(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, tokenizer.nextToken())); | |
+ } | |
+ nameBuilder.append("Spec"); | |
+ | |
+ return nameBuilder.toString(); | |
+ } | |
+} | |
diff --git a/node_modules/react-native-codegen/android/gradlePlugin-build/settings.gradle b/node_modules/react-native-codegen/android/gradlePlugin-build/settings.gradle | |
new file mode 100644 | |
index 0000000..b9fdc14 | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlePlugin-build/settings.gradle | |
@@ -0,0 +1,10 @@ | |
+/* | |
+ * 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. | |
+ */ | |
+ | |
+rootProject.name = 'react-native-codegen-gradlePlugin-build' | |
+ | |
+include(":gradlePlugin") | |
diff --git a/node_modules/react-native-codegen/android/gradlew b/node_modules/react-native-codegen/android/gradlew | |
new file mode 100755 | |
index 0000000..4f906e0 | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlew | |
@@ -0,0 +1,185 @@ | |
+#!/usr/bin/env sh | |
+ | |
+# | |
+# Copyright 2015 the original author or authors. | |
+# | |
+# Licensed under the Apache License, Version 2.0 (the "License"); | |
+# you may not use this file except in compliance with the License. | |
+# You may obtain a copy of the License at | |
+# | |
+# https://www.apache.org/licenses/LICENSE-2.0 | |
+# | |
+# Unless required by applicable law or agreed to in writing, software | |
+# distributed under the License is distributed on an "AS IS" BASIS, | |
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
+# See the License for the specific language governing permissions and | |
+# limitations under the License. | |
+# | |
+ | |
+############################################################################## | |
+## | |
+## Gradle start up script for UN*X | |
+## | |
+############################################################################## | |
+ | |
+# Attempt to set APP_HOME | |
+# Resolve links: $0 may be a link | |
+PRG="$0" | |
+# Need this for relative symlinks. | |
+while [ -h "$PRG" ] ; do | |
+ ls=`ls -ld "$PRG"` | |
+ link=`expr "$ls" : '.*-> \(.*\)$'` | |
+ if expr "$link" : '/.*' > /dev/null; then | |
+ PRG="$link" | |
+ else | |
+ PRG=`dirname "$PRG"`"/$link" | |
+ fi | |
+done | |
+SAVED="`pwd`" | |
+cd "`dirname \"$PRG\"`/" >/dev/null | |
+APP_HOME="`pwd -P`" | |
+cd "$SAVED" >/dev/null | |
+ | |
+APP_NAME="Gradle" | |
+APP_BASE_NAME=`basename "$0"` | |
+ | |
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. | |
+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' | |
+ | |
+# Use the maximum available, or set MAX_FD != -1 to use that value. | |
+MAX_FD="maximum" | |
+ | |
+warn () { | |
+ echo "$*" | |
+} | |
+ | |
+die () { | |
+ echo | |
+ echo "$*" | |
+ echo | |
+ exit 1 | |
+} | |
+ | |
+# OS specific support (must be 'true' or 'false'). | |
+cygwin=false | |
+msys=false | |
+darwin=false | |
+nonstop=false | |
+case "`uname`" in | |
+ CYGWIN* ) | |
+ cygwin=true | |
+ ;; | |
+ Darwin* ) | |
+ darwin=true | |
+ ;; | |
+ MINGW* ) | |
+ msys=true | |
+ ;; | |
+ NONSTOP* ) | |
+ nonstop=true | |
+ ;; | |
+esac | |
+ | |
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar | |
+ | |
+ | |
+# Determine the Java command to use to start the JVM. | |
+if [ -n "$JAVA_HOME" ] ; then | |
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then | |
+ # IBM's JDK on AIX uses strange locations for the executables | |
+ JAVACMD="$JAVA_HOME/jre/sh/java" | |
+ else | |
+ JAVACMD="$JAVA_HOME/bin/java" | |
+ fi | |
+ if [ ! -x "$JAVACMD" ] ; then | |
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME | |
+ | |
+Please set the JAVA_HOME variable in your environment to match the | |
+location of your Java installation." | |
+ fi | |
+else | |
+ JAVACMD="java" | |
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. | |
+ | |
+Please set the JAVA_HOME variable in your environment to match the | |
+location of your Java installation." | |
+fi | |
+ | |
+# Increase the maximum file descriptors if we can. | |
+if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then | |
+ MAX_FD_LIMIT=`ulimit -H -n` | |
+ if [ $? -eq 0 ] ; then | |
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then | |
+ MAX_FD="$MAX_FD_LIMIT" | |
+ fi | |
+ ulimit -n $MAX_FD | |
+ if [ $? -ne 0 ] ; then | |
+ warn "Could not set maximum file descriptor limit: $MAX_FD" | |
+ fi | |
+ else | |
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" | |
+ fi | |
+fi | |
+ | |
+# For Darwin, add options to specify how the application appears in the dock | |
+if $darwin; then | |
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" | |
+fi | |
+ | |
+# For Cygwin or MSYS, switch paths to Windows format before running java | |
+if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then | |
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"` | |
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` | |
+ | |
+ JAVACMD=`cygpath --unix "$JAVACMD"` | |
+ | |
+ # We build the pattern for arguments to be converted via cygpath | |
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` | |
+ SEP="" | |
+ for dir in $ROOTDIRSRAW ; do | |
+ ROOTDIRS="$ROOTDIRS$SEP$dir" | |
+ SEP="|" | |
+ done | |
+ OURCYGPATTERN="(^($ROOTDIRS))" | |
+ # Add a user-defined pattern to the cygpath arguments | |
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then | |
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" | |
+ fi | |
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh | |
+ i=0 | |
+ for arg in "$@" ; do | |
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` | |
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option | |
+ | |
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition | |
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` | |
+ else | |
+ eval `echo args$i`="\"$arg\"" | |
+ fi | |
+ i=`expr $i + 1` | |
+ done | |
+ case $i in | |
+ 0) set -- ;; | |
+ 1) set -- "$args0" ;; | |
+ 2) set -- "$args0" "$args1" ;; | |
+ 3) set -- "$args0" "$args1" "$args2" ;; | |
+ 4) set -- "$args0" "$args1" "$args2" "$args3" ;; | |
+ 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; | |
+ 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; | |
+ 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; | |
+ 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; | |
+ 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; | |
+ esac | |
+fi | |
+ | |
+# Escape application args | |
+save () { | |
+ for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done | |
+ echo " " | |
+} | |
+APP_ARGS=`save "$@"` | |
+ | |
+# Collect all arguments for the java command, following the shell quoting and substitution rules | |
+eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" | |
+ | |
+exec "$JAVACMD" "$@" | |
diff --git a/node_modules/react-native-codegen/android/gradlew.bat b/node_modules/react-native-codegen/android/gradlew.bat | |
new file mode 100644 | |
index 0000000..107acd3 | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/gradlew.bat | |
@@ -0,0 +1,89 @@ | |
+@rem | |
+@rem Copyright 2015 the original author or authors. | |
+@rem | |
+@rem Licensed under the Apache License, Version 2.0 (the "License"); | |
+@rem you may not use this file except in compliance with the License. | |
+@rem You may obtain a copy of the License at | |
+@rem | |
+@rem https://www.apache.org/licenses/LICENSE-2.0 | |
+@rem | |
+@rem Unless required by applicable law or agreed to in writing, software | |
+@rem distributed under the License is distributed on an "AS IS" BASIS, | |
+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
+@rem See the License for the specific language governing permissions and | |
+@rem limitations under the License. | |
+@rem | |
+ | |
+@if "%DEBUG%" == "" @echo off | |
+@rem ########################################################################## | |
+@rem | |
+@rem Gradle startup script for Windows | |
+@rem | |
+@rem ########################################################################## | |
+ | |
+@rem Set local scope for the variables with windows NT shell | |
+if "%OS%"=="Windows_NT" setlocal | |
+ | |
+set DIRNAME=%~dp0 | |
+if "%DIRNAME%" == "" set DIRNAME=. | |
+set APP_BASE_NAME=%~n0 | |
+set APP_HOME=%DIRNAME% | |
+ | |
+@rem Resolve any "." and ".." in APP_HOME to make it shorter. | |
+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi | |
+ | |
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. | |
+set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" | |
+ | |
+@rem Find java.exe | |
+if defined JAVA_HOME goto findJavaFromJavaHome | |
+ | |
+set JAVA_EXE=java.exe | |
+%JAVA_EXE% -version >NUL 2>&1 | |
+if "%ERRORLEVEL%" == "0" goto execute | |
+ | |
+echo. | |
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. | |
+echo. | |
+echo Please set the JAVA_HOME variable in your environment to match the | |
+echo location of your Java installation. | |
+ | |
+goto fail | |
+ | |
+:findJavaFromJavaHome | |
+set JAVA_HOME=%JAVA_HOME:"=% | |
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe | |
+ | |
+if exist "%JAVA_EXE%" goto execute | |
+ | |
+echo. | |
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% | |
+echo. | |
+echo Please set the JAVA_HOME variable in your environment to match the | |
+echo location of your Java installation. | |
+ | |
+goto fail | |
+ | |
+:execute | |
+@rem Setup the command line | |
+ | |
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar | |
+ | |
+ | |
+@rem Execute Gradle | |
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* | |
+ | |
+:end | |
+@rem End local scope for the variables with windows NT shell | |
+if "%ERRORLEVEL%"=="0" goto mainEnd | |
+ | |
+:fail | |
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of | |
+rem the _cmd.exe /c_ return code! | |
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 | |
+exit /b 1 | |
+ | |
+:mainEnd | |
+if "%OS%"=="Windows_NT" endlocal | |
+ | |
+:omega | |
diff --git a/node_modules/react-native-codegen/android/settings.gradle b/node_modules/react-native-codegen/android/settings.gradle | |
new file mode 100644 | |
index 0000000..4beec15 | |
--- /dev/null | |
+++ b/node_modules/react-native-codegen/android/settings.gradle | |
@@ -0,0 +1,20 @@ | |
+/* | |
+ * 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. | |
+ */ | |
+ | |
+pluginManagement { | |
+ repositories { | |
+ gradlePluginPortal() | |
+ mavenLocal() | |
+ google() | |
+ } | |
+} | |
+ | |
+rootProject.name = 'react-native-codegen' | |
+ | |
+include(":generator") | |
+ | |
+includeBuild("gradlePlugin-build") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment