def compile_constructor(self, constructor): signature = util.StringBuilder() for annotation in constructor.annotations: formatter.output_annotation(annotation, signature) formatter.output_modifiers(constructor.modifiers, signature) signature.append(' ') if constructor.type_parameters: formatter.output_type_params(constructor.type_parameters, signature) signature.append(' ') signature.append(constructor.name) signature.append('(') formatter.output_list(formatter.output_formal_param, constructor.parameters, signature, ', ') signature.append(')') if constructor.throws: signature.append(' throws ') formatter.output_list(formatter.output_exception, constructor.throws, signature, ', ') doc = self.__output_doc(constructor) directive = util.Directive('java:constructor', signature.build()) directive.add_content(doc) return directive
def compile_method(self, method): signature = util.StringBuilder() for annotation in method.annotations: formatter.output_annotation(annotation, signature) formatter.output_modifiers(method.modifiers, signature) signature.append(' ') if method.type_parameters: formatter.output_type_params(method.type_parameters, signature) signature.append(' ') formatter.output_type(method.return_type, signature) signature.append(' ') signature.append(method.name) signature.append('(') formatter.output_list(formatter.output_formal_param, method.parameters, signature, ', ') signature.append(')') if method.throws: signature.append(' throws ') formatter.output_list(formatter.output_exception, method.throws, signature, ', ') doc = self.__output_doc(method) directive = util.Directive('java:method', signature.build()) directive.add_content(doc) return directive
def handle_field_signature(self, sig, signode): try: member = javalang.parse.parse_member_signature(sig) except javalang.parser.JavaSyntaxError: raise self.error("syntax error in field signature") if not isinstance(member, javalang.tree.FieldDeclaration): raise self.error("expected field declaration") mods = formatter.output_modifiers(member.modifiers).build() signode += nodes.Text(mods + ' ', mods + ' ') tnode = addnodes.desc_type('', '') tnode += self._build_type_node(member.type) signode += tnode signode += nodes.Text(' ', ' ') if len(member.declarators) > 1: self.error('only one field may be documented at a time') declarator = member.declarators[0] signode += addnodes.desc_name(declarator.name, declarator.name) dim = '[]' * len(declarator.dimensions) signode += nodes.Text(dim) if declarator.initializer and isinstance(declarator.initializer, javalang.tree.Literal): signode += nodes.Text(' = ' + declarator.initializer.value) return declarator.name
def handle_constructor_signature(self, sig, signode): try: member = javalang.parse.parse_constructor_signature(sig) except javalang.parser.JavaSyntaxError: raise self.error("syntax error in constructor signature") if not isinstance(member, javalang.tree.ConstructorDeclaration): raise self.error("expected constructor declaration") mods = formatter.output_modifiers(member.modifiers).build() signode += nodes.Text(mods + ' ', mods + ' ') signode += addnodes.desc_name(member.name, member.name) paramlist = addnodes.desc_parameterlist() for parameter in member.parameters: param = addnodes.desc_parameter('', '', noemph=True) param += self._build_type_node(parameter.type) if parameter.varargs: param += nodes.Text('...', '') param += nodes.emphasis(' ' + parameter.name, ' ' + parameter.name) paramlist += param signode += paramlist param_reprs = [ formatter.output_type(param.type, with_generics=False).build() for param in member.parameters ] return '%s(%s)' % (member.name, ', '.join(param_reprs))
def handle_constructor_signature(self, sig, signode): try: member = javalang.parse.parse_constructor_signature(sig) except javalang.parser.JavaSyntaxError: raise self.error("syntax error in constructor signature") if not isinstance(member, javalang.tree.ConstructorDeclaration): raise self.error("expected constructor declaration") mods = formatter.output_modifiers(member.modifiers).build() signode += nodes.Text(mods + ' ', mods + ' ') signode += addnodes.desc_name(member.name, member.name) paramlist = addnodes.desc_parameterlist() for parameter in member.parameters: param = addnodes.desc_parameter('', '', noemph=True) param += self._build_type_node(parameter.type) if parameter.varargs: param += nodes.Text('...', '') param += nodes.emphasis(' ' + parameter.name, ' ' + parameter.name) paramlist += param signode += paramlist param_reprs = [formatter.output_type(param.type, with_generics=False).build() for param in member.parameters] return '%s(%s)' % (member.name, ', '.join(param_reprs))
def handle_type_signature(self, sig, signode): try: member = javalang.parse.parse_type_signature(sig) except javalang.parser.JavaSyntaxError: raise self.error("syntax error in field signature") if isinstance(member, javalang.tree.ClassDeclaration): self.declaration_type = 'class' elif isinstance(member, javalang.tree.InterfaceDeclaration): self.declaration_type = 'interface' elif isinstance(member, javalang.tree.EnumDeclaration): self.declaration_type = 'enum' elif isinstance(member, javalang.tree.AnnotationDeclaration): self.declaration_type = 'annotation' else: raise self.error("expected type declaration") mods = formatter.output_modifiers(member.modifiers).build() signode += nodes.Text(mods + ' ', mods + ' ') if self.declaration_type == 'class': signode += nodes.Text('class ', 'class ') elif self.declaration_type == 'interface': signode += nodes.Text('interface ', 'interface ') elif self.declaration_type == 'enum': signode += nodes.Text('enum ', 'enum ') elif self.declaration_type == 'annotation': signode += nodes.Text('@interface ', '@interface ') signode += addnodes.desc_name(member.name, member.name) if self.declaration_type in ('class', 'interface') and member.type_parameters: type_params = formatter.output_type_params( member.type_parameters).build() signode += nodes.Text(type_params, type_params) if self.declaration_type == 'class': if member.extends: extends = ' extends ' signode += nodes.Text(extends, extends) signode += self._build_type_node(member.extends) if member.implements: implements = ' implements ' signode += nodes.Text(implements, implements) signode += self._build_type_node_list(member.implements) elif self.declaration_type == 'interface': if member.extends: extends = ' extends ' signode += nodes.Text(extends, extends) signode += self._build_type_node_list(member.extends) elif self.declaration_type == 'enum': if member.implements: implements = ' implements ' signode += nodes.Text(implements, implements) signode += self._build_type_node_list(member.implements) return member.name
def handle_type_signature(self, sig, signode): try: member = javalang.parse.parse_type_signature(sig) except javalang.parser.JavaSyntaxError: raise self.error("syntax error in field signature") if isinstance(member, javalang.tree.ClassDeclaration): self.declaration_type = 'class' elif isinstance(member, javalang.tree.InterfaceDeclaration): self.declaration_type = 'interface' elif isinstance(member, javalang.tree.EnumDeclaration): self.declaration_type = 'enum' elif isinstance(member, javalang.tree.AnnotationDeclaration): self.declaration_type = 'annotation' else: raise self.error("expected type declaration") mods = formatter.output_modifiers(member.modifiers).build() signode += nodes.Text(mods + ' ', mods + ' ') if self.declaration_type == 'class': signode += nodes.Text('class ', 'class ') elif self.declaration_type == 'interface': signode += nodes.Text('interface ', 'interface ') elif self.declaration_type == 'enum': signode += nodes.Text('enum ', 'enum ') elif self.declaration_type == 'annotation': signode += nodes.Text('@interface ', '@interface ') signode += addnodes.desc_name(member.name, member.name) if self.declaration_type in ('class', 'interface') and member.type_parameters: type_params = formatter.output_type_params(member.type_parameters).build() signode += nodes.Text(type_params, type_params) if self.declaration_type == 'class': if member.extends: extends = ' extends ' signode += nodes.Text(extends, extends) signode += self._build_type_node(member.extends) if member.implements: implements = ' implements ' signode += nodes.Text(implements, implements) signode += self._build_type_node_list(member.implements) elif self.declaration_type == 'interface': if member.extends: extends = ' extends ' signode += nodes.Text(extends, extends) signode += self._build_type_node_list(member.extends) elif self.declaration_type == 'enum': if member.implements: implements = ' implements ' signode += nodes.Text(implements, implements) signode += self._build_type_node_list(member.implements) return member.name
def compile_field(self, field): signature = util.StringBuilder() for annotation in field.annotations: formatter.output_annotation(annotation, signature) formatter.output_modifiers(field.modifiers, signature) signature.append(' ') formatter.output_type(field.type, signature) signature.append(' ') signature.append(field.declarators[0].name) doc = self.__output_doc(field) directive = util.Directive('java:field', signature.build()) directive.add_content(doc) return directive