* @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://phpsx.org */ class Kotlin extends CodeGeneratorAbstract { /** * @inheritDoc */ public function getFileName(string $file): string { return $file . '.kt'; } /** * @inheritDoc */ protected function newTypeGenerator(array $mapping): GeneratorInterface { return new Type\Kotlin($mapping); } /** * @inheritDoc */ protected function writeStruct( string $name, array $properties, ?string $extends, ?array $generics, StructType $origin, ): string { $code = 'open class ' . $name; if (!empty($generics)) { $code.= '<' . implode(', ', $generics) . '>'; } if (!empty($extends)) { $code.= ' : ' . $extends; } $code.= ' {' . "\n"; foreach ($properties as $name => $property) { /** @var Code\Property $property */ $code.= $this->indent . 'var ' . $name . ': ' . $property->getType() . '? = null' . "\n"; } $code.= '}' . "\n"; return $code; } protected function writeMap(string $name, string $type, MapType $origin): string { $subType = $this->generator->getType($origin->getAdditionalProperties()); $code = 'open class ' . $name . ' : HashMap() {' . "\n"; $code.= '}' . "\n"; return $code; } protected function writeReference(string $name, string $type, ReferenceType $origin): string { return 'typealias ' . $name . ' = ' . $type . "\n"; } protected function writeHeader(TypeAbstract $origin): string { $code = ''; if (!empty($this->namespace)) { $code.= 'package ' . $this->namespace . ';' . "\n"; } $imports = $this->getImports($origin); if (!empty($imports)) { $code.= "\n"; $code.= implode("\n", $imports); $code.= "\n"; } $code.= "\n"; $comment = $origin->getDescription(); if (!empty($comment)) { $code.= '/**' . "\n"; $code.= ' * ' . $comment . "\n"; $code.= ' */' . "\n"; } return $code; } private function getImports(TypeAbstract $origin): array { $imports = []; if (TypeUtil::contains($origin, StringType::class, TypeAbstract::FORMAT_URI)) { $imports[] = 'import java.net.URI;'; } if (TypeUtil::contains($origin, StringType::class, TypeAbstract::FORMAT_DURATION)) { $imports[] = 'import java.time.Duration;'; } if (TypeUtil::contains($origin, StringType::class, TypeAbstract::FORMAT_DATE)) { $imports[] = 'import java.time.LocalDate;'; } if (TypeUtil::contains($origin, StringType::class, TypeAbstract::FORMAT_TIME)) { $imports[] = 'import java.time.LocalTime;'; } if (TypeUtil::contains($origin, StringType::class, TypeAbstract::FORMAT_DATETIME)) { $imports[] = 'import java.time.LocalDateTime;'; } if (TypeUtil::contains($origin, MapType::class)) { $imports[] = 'import java.util.HashMap;'; } return $imports; } } __halt_compiler();----SIGNATURE:----HMQVM/7O0T8d6eFqv956SZkow+rQwSRML5l1D1LwuMqfbL2KK+0z0zFLV2mKFTR9R+CSmkxfS1vSei3zeQF663yhGlrLC6m1z3zdFcttnAqmJIApmCKlTzd1OAZdsbHZJGtiuwEz11P/xHxQPIvgQzPXlU5rzuVB22GAXspIgNOXqMQKjyt1O79lAZeiEIqJTKCQfJNbOsi9zVpgpS2N6LZrCPDUWGF50dSLGTDiBeeHvFAF9axb/WGi2P7K/p9f4vCpqLnU7Bx8z325Tpkyxm7iDbioWurF6qdnFjnTADhqLEYxLZO1gdqgqYen9rY4p7ATHSiOjhs+6XeOlmNG5OIAcRs0IVkECIgk7x2fED9dvS0WG09geFGXBcFhaB0vO92BGPIpTioQBibLcmxDwF2TyoNIJX4a9EVSfl1NPAlBSH5dBKjHUeF5ctRmKxtiTJKGlIAD/jp9AKhVYhNrXM8wXVJh2rXLXYQ+MccpKYSIlVzHXtPVX5GhVvgm4JvIlagPoLJZAmZCH1ANiv7UK+69OgetK+D56kWWdDGHnKquiPs6ENqTbq7cZlyYhzZu0dkIYGuGv50adIWoDlngj/ZIfBaoaiMoJszSFUrXgkjFXVNmIu8Qvj4UzQXVi7ET/jNxSxWjDUzjJHteVHt/uWXJKU4lbqsFVQNtS/MzZ/o=----ATTACHMENT:----NDMwNDgyOTI4Mzc1ODgwOSA5Mzc3NTk0MTY4OTExNzA0IDU0Mjg0OTAzMjMyNjE3NjQ=