* @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:----f8kU5gkkvNcprEeXWBssdeXUAmzgCoQfoJ46Zq5RS+b5TSk5ZLKNwLiTTtTbV1+B3G7czVNqDwBWd89KvZhlxpCkp7UwVuxqdmF+zkySwaFJPmSWA0lHr/4gjx23QIo0pSmlaNH6DtgMuuvemXnYlTjXCR9zAKw3qVjB/2kBf3K4/Erdgemm5KHaOAHK+s3iU4+9OwCYr/Gj9oZk9ehweNjuBnTCU3Q3uRS3PSnTjQkMo7LbDMp16VVag32NRQI6OoyrefQJQ8nk75GyfPpIrfu5dkoA3gftl0AeSFw7OcxICAWVNwHFWvZsZpDP4HSIK60fAzB72YWmol/AMc+LWbNgspGqav2FVkvhydPmOHSFNfPXrwNvyIYqRUoZPflU/vcw1mAQRQ2D3BIYF6aUJnUS7K7msZfEFx2hZJdSqHAfJxPcsSSALKy70MpGuKz4TbMPOSBvsh27nAYiOM5sNGEWEwcJuQlh1TLmMGtt3JVo+I3Hsn7C8fZEZURqMYtgvN1THtFPSJjBUpu6OFwxG4PHyPCLpXokWz4YNwJY2MrvCoN+D8N7+PofMaLBfJxeUh0ecCTtkGrgwjrkz4StrqbX4dgHOXTJc5XEjMXYWst6ZA6tDd75TvewmQiieV7v/sp1ac9ktLjgCN0LDKVtnbq0Rz6Zmfe7H4o7pVsNzHM=----ATTACHMENT:----Nzg0MzgwODI3NzQ4NTM2NCA3NTE0NTUyOTEwMTAwNzkzIDQzMjY4NDUwMDYyNjg4Ng==