printError("Wrong type $type"); return ''; default: if (substr($type, 0, 6) === 'vector') { if ($type[6] !== '<' || $type[strlen($type) - 1] !== '>') { $this->printError("Wrong vector subtype in $type"); return ''; } return $this->getTypeName(substr($type, 7, -1)).'[]'; } if (preg_match('/[^A-Za-z0-9.]/', $type)) { $this->printError("Wrong type $type"); return ''; } return $this->getClassName($type); } } protected function getBaseClassName($is_function) { return $is_function ? 'Function' : 'Object'; } protected function needRemoveLine($line) { return strpos(trim($line), '/**') === 0 || strpos(trim($line), '*') === 0 || ($this->nullable_type && strpos($line, $this->nullable_type) > 0); } protected function needSkipLine($line) { $line = $this->fixLine(trim($line)); return (strpos($line, 'public') !== 0 && !$this->isHeaderLine($line)) || $line === 'public @interface Constructors {}'; } protected function isHeaderLine($line) { return trim($line) === '@Override' || trim($line) === '@Constructors'; } protected function extractClassName($line) { if (strpos($line, 'public static class ') > 0) { return preg_split('/( |<|>)/', trim($line))[3]; } return ''; } protected function fixLine($line) { if (strpos($line, 'CONSTRUCTOR = ') > 0) { return substr($line, 0, strpos($line, '=')); } return $this->nullable_annotation ? str_replace($this->nullable_annotation.' ', '', $line) : $line; } protected function addGlobalDocumentation() { if ($this->nullable_type) { $nullable_type_import = "import $this->nullable_type;".PHP_EOL; } else { $nullable_type_import = ''; } $this->addDocumentation('public class TdApi {', << * It has no inner classes, functions or public members. */ EOT ); $this->addDocumentation(' public abstract static class Object {', <<addDocumentation(" public Object() {", <<addDocumentation(' public abstract int getConstructor();', <<addDocumentation(' public native String toString();', <<addDocumentation(' public abstract static class Function extends Object {', <<addDocumentation(" public Function() {", <<addDocumentation(' public static final int CONSTRUCTOR', <<addDocumentation(' public int getConstructor() {', <<addDocumentation(" public abstract static class $class_name extends Object {", <<addDocumentation(" public $class_name() {", << Returns {@link $return_type $return_type}

"; } protected function addClassDocumentation($class_name, $base_class_name, $return_type, $description) { $this->addDocumentation(" public static class $class_name extends ".$base_class_name.(empty($return_type) ? "" : "<".$return_type.">")." {", <<addDocumentation($full_line, <<nullable_annotation && ($this->java_version >= 8 || substr($type_name, -1) != ']')) { $this->addLineReplacement($full_line, " $this->nullable_annotation public $type_name $field_name;".PHP_EOL); } } protected function addDefaultConstructorDocumentation($class_name, $class_description) { $this->addDocumentation(" public $class_name() {", << $type) { $full_constructor .= $colon.$this->getTypeName($type).' '.$this->getFieldName($name, $class_name); $colon = ', '; } $full_constructor .= ') {'; $full_doc = << $type) { $full_doc .= ' * @param '.$this->getFieldName($name, $class_name).' '.$info[$name].PHP_EOL; } $full_doc .= ' */'; $this->addDocumentation($full_constructor, $full_doc); } public function __construct($nullable_type, $nullable_annotation, $java_version) { $this->nullable_type = trim($nullable_type); $this->nullable_annotation = trim($nullable_annotation); $this->java_version = intval($java_version); } } $nullable_type = isset($argv[3]) ? $argv[3] : ''; $nullable_annotation = isset($argv[4]) ? $argv[4] : ''; $java_version = isset($argv[5]) ? intval($argv[5]) : 7; $generator = new JavadocTlDocumentationGenerator($nullable_type, $nullable_annotation, $java_version); $generator->generate($argv[1], $argv[2]);