* @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:----RDbcf4jVABAnN2PMMCCNgc6urDe9zvKqe9N+DdKVKvQWgo9lmHiJgPicwPprOkqTlwKBsMH/a+CwB4Tcw7o/xdukRD3vRbm+2K55x6ZYA9TrYKMtqbokvR1B/HhWGYzfcNmeRwki75guSWrthOq/aEbeE2JxgPtNyPPXKfjJ8Z1ske+ITYfGl969aTHcrslrQysLRShnUlwhhDf+TJFnfrb2HAb9Xt9joIoMA9yL3u7zg4RcKRu0Z6c301LH0zyhRubREBrh4hDQzMVFG8eoCFvzp8AuII2m33TXmQoH8wydf+UV0X3LG1V0BaGTB4+lzMB4GVMenK7yu7qpVz3oe52Hfzpag0Xj/eoWZd2zUNgmg0gsnpo9tQQT8N2UwZGiHgONQ6QARQyIGe9jJtgGy5QNs3KzdPNFFId9P8V4owuT9lIuJO3gNhGvilBcmPsTp/r0X6JJlOc3dA+ClbE1B/eTi4c/O3c9z3kQoCfbx6rCL9UwVqdswFDRaCTOSo/GoJr0apIofEbM7XdfOK9mYADyJP/XNfqmydu6aAC8dx8xgsdiOecPgA9EUZ4mAjQjkmUogYqgLfGM1on0rxNkw8vrk4o2ixQikwDROfAA13R8cbQy0hqzJOqnQvKslnSVbR4LJwih9Q9UuVsQZeq6bxu7VEx54RxH4zzF+kJ3pF8=----ATTACHMENT:----NTg4MjkxNjIzNzI0NTIwNSAyMDA4OTI2MjE3Mzk4MjM1IDcxNzk1NzA3NzIxODQyNjY=