* @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://phpsx.org */ class Java extends CodeGeneratorAbstract { /** * @inheritDoc */ public function getFileName(string $file): string { return $file . '.java'; } /** * @inheritDoc */ protected function newTypeGenerator(array $mapping): GeneratorInterface { return new Type\Java($mapping); } /** * @inheritDoc */ protected function writeStruct( string $name, array $properties, ?string $extends, ?array $generics, StructType $origin, ): string { $code = 'public class ' . $name; if (!empty($generics)) { $code.= '<' . implode(', ', $generics) . '>'; } if (!empty($extends)) { $code.= ' extends ' . $extends; } $code.= ' {' . "\n"; foreach ($properties as $name => $property) { /** @var Code\Property $property */ $code.= $this->indent . 'private ' . $property->getType() . ' ' . $name . ';' . "\n"; } foreach ($properties as $name => $property) { /** @var Code\Property $property */ $code.= $this->indent . 'public void set' . ucfirst($name) . '(' . $property->getType() . ' ' . $name . ') {' . "\n"; $code.= $this->indent . $this->indent . 'this.' . $name . ' = ' . $name . ';' . "\n"; $code.= $this->indent . '}' . "\n"; $code.= $this->indent . 'public ' . $property->getType() . ' get' . ucfirst($name) . '() {' . "\n"; $code.= $this->indent . $this->indent . 'return this.' . $name . ';' . "\n"; $code.= $this->indent . '}' . "\n"; } $code.= '}' . "\n"; return $code; } protected function writeMap(string $name, string $type, MapType $origin): string { $subType = $this->generator->getType($origin->getAdditionalProperties()); $code = 'public class ' . $name . ' extends HashMap {' . "\n"; $code.= '}' . "\n"; return $code; } protected function writeReference(string $name, string $type, ReferenceType $origin): string { $code = 'public class ' . $name . ' extends ' . $type . ' {' . "\n"; $code.= '}' . "\n"; return $code; } 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:----VCbLwCvjXAVjePDh/ZKNhmvzGjS1IusGoHJHeowfAwdjW0CphNwlrLc832aV7vVvKcYTD6jgjqu3sumaXxzaZaLL2JOH1FSqoYsRf1Cbmmu/zgEw65f3YdsAB32Ud+6/nEMCmIvAjPgPDvRyU4QDWNHYC0Yrb6cAuOw4nhNsdR1HKNfogCFeQLV7KB7tL7QTGZrhhtHbd+1QNTnnPdvY3YYiRED1DrloALmXRJqth+KOllGwtsgyx0qlI8EhMIqHz8B6dt7wJQLhUEVQ/OTnLLe8TDcXLFY1Qgc1BuXPwM3TAHn6Zk2PYg7AmECfyPuZLSJsFtFJ1wQtsSIEXdYLrv9/Lpq9W3tDI0UFSVEzoVfQ9bMk8sX2sV3apw5dEP5TAsjMZGJ0WDz+XDSz1qUNZo9B8MukK8b2dlg6xtaPC4C5qFoE7VC56LlthV/9Efi+X+x4XgqySMH586CjQ8k7uMI7d7AUkZ3Ktjul5Qplj9FFXnnaYr/IItATeGxWsQUlxgIhTyZuARuZhiPPb5xiFCbWikKKzYr8+np873zW3Y3XKSrFEHk/WbC4UmbkNxZno6kZCKl/Pv1dpL4OGxRvQ7cIlgBPgDUgTbuv4itHKnSJGXXZ/l5oyI7Yv597HvtZAyYaLc8y2T8T+K6vpMHC3BH5VZk61lXqRapI7mLFBoE=----ATTACHMENT:----NDk4NzA5MjQ3NTQ1MDI0NCAxMzA0MDkxNDcyMTg5OTI3IDkzOTM1NDcwMzM4NjgxMTI=