Esempio n. 1
0
  def GenerateCreateInternallyConstructor(self):
    if not self._java_data.HasCreateInternallyAnnotation():
      return ''
    constructor_template = Template("""\
    private ${INTERNAL_CLASS_NAME} internal = null;
    ${BRIDGE_CLASS_NAME}(${INTERNAL_CLASS_NAME} internal) {
        this.internal = internal;
        this.wrapper = ReflectionHelper.createInstance(\
"${STATIC_CONSTRUCTOR_NAME}", this);
        try {
          reflectionInit();
        } catch (Exception e) {
          ReflectionHelper.handleException(e);
        }
    }
""")
    internal_class_name = self._java_data.class_name
    bridge_class_name = self._generated_class_name
    constructor_method = Method(self._java_data.class_name, self._class_loader,
        True, False, False, bridge_class_name, '', '', '')
    static_constructor_name = constructor_method.GetMethodDeclareName()
    value = {'INTERNAL_CLASS_NAME': internal_class_name,
             'BRIDGE_CLASS_NAME': bridge_class_name,
             'STATIC_CONSTRUCTOR_NAME': static_constructor_name}
    return constructor_template.substitute(value)
Esempio n. 2
0
  def GenerateStaticInitializerString(self):
    if not self._java_data.HasCreateInternallyAnnotation():
      return ''
    static_initializer_template = Template("""\
    static {
        ReflectionHelper.registerConstructor("${STATIC_CONSTRUCTOR_NAME}", \
"${FULL_CLASS_NAME}", Object.class);
    }
""")
    bridge_class_name = self._java_data.bridge_name
    constructor_method = Method(self._java_data.class_name, self._class_loader,
        True, False, False, bridge_class_name, '', '', '')
    static_constructor_name = constructor_method.GetMethodDeclareName()
    full_class_name = self._java_data.GetFullWrapperName()
    value = {'STATIC_CONSTRUCTOR_NAME': static_constructor_name,
             'FULL_CLASS_NAME': full_class_name}
    return static_initializer_template.substitute(value)
Esempio n. 3
0
  def ExtractMethods(self, java_content):
    constructor_re = re.compile(
        '(?P<method_doc>(\n\s*/\*\*.*\n(\s+\*(.)*\n)+\s+\*/\s*)?)\n'
        '\s*@XWalkAPI\(?'
        '(?P<method_annotation>[a-zA-Z0-9\$%,\s\(\)\{\};._"=]*)\)?'
        '\s*public\s(?P<method_name>[a-zA-Z0-9]+)\('
        '(?P<method_params>[a-zA-Z0-9\s,\[\]\>\<]*)\)')
    for match in re.finditer(constructor_re, java_content):
      method_annotation = match.group('method_annotation')
      method_name = match.group('method_name')
      method_params = match.group('method_params')
      method_doc = match.group('method_doc')
      method = Method(
          self._class_name,
          self._class_loader,
          True, # is_constructor
          False, # is_static
          False, # is_abstract
          method_name, None,
          method_params, method_annotation, method_doc)
      self._methods.append(method)
      self._need_default_constructor = False

    method_re = re.compile(
        '(?P<method_doc>(\n\s*/\*\*.*\n(\s+\*(.)*\n)+\s+\*/\s*)?)\n'
        '\s*@XWalkAPI\(?'
        '(?P<method_annotation>[a-zA-Z0-9%,\s\(\)\{\};._"=]*)\)?'
        '\s*public\s+(?P<method_return>[a-zA-Z0-9]+(\<[a-zA-Z0-9]+,\s[a-zA-Z0-9]+\>)*(\[\s*\])*)\s+'
        '(?P<method_name>[a-zA-Z0-9]+)\('
        '(?P<method_params>[a-zA-Z0-9\s,\]\[\<\>]*)\)')
    for match in re.finditer(method_re, java_content):
      method_annotation = match.group('method_annotation')
      method_name = match.group('method_name')
      method_params = match.group('method_params')
      method_return = match.group('method_return')
      method_doc = match.group('method_doc')
      method = Method(
          self._class_name,
          self._class_loader,
          False, # is_constructor
          False, # is_static
          False, # is_abstract
          method_name, method_return, method_params,
          method_annotation, method_doc)
      self._methods.append(method)

    method_re = re.compile(
        '(?P<method_doc>(\n\s*/\*\*.*\n(\s+\*(.)*\n)+\s+\*/\s*)?)\n'
        '\s*@XWalkAPI\(?'
        '(?P<method_annotation>[a-zA-Z0-9%,\s\(\)\{\};._"=]*)\)?'
        '\s*public\s+static\s+(synchronized\s+)*'
        '(?P<method_return>[a-zA-Z0-9]+)\s+'
        '(?P<method_name>[a-zA-Z0-9]+)\('
        '(?P<method_params>[a-zA-Z0-9\s,\[\]\<\>]*)\)')
    for match in re.finditer(method_re, java_content):
      method_annotation = match.group('method_annotation')
      method_name = match.group('method_name')
      method_params = match.group('method_params')
      method_return = match.group('method_return')
      method_doc = match.group('method_doc')
      method = Method(
          self._class_name,
          self._class_loader,
          False, # is_constructor
          True, # is_static
          False, # is_abstract
          method_name, method_return, method_params,
          method_annotation, method_doc)
      self._methods.append(method)

    method_re = re.compile(
        '(?P<method_doc>(\n\s*/\*\*.*\n(\s+\*(.)*\n)+\s+\*/\s*)?)\n'
        '\s*@XWalkAPI\(?'
        '(?P<method_annotation>[a-zA-Z0-9%,\s\(\)\{\};._"=]*)\)?'
        '\s*public\s+abstract\s+(synchronized\s+)*'
        '(?P<method_return>[a-zA-Z0-9]+)\s+'
        '(?P<method_name>[a-zA-Z0-9]+)\('
        '(?P<method_params>[a-zA-Z0-9\s,\[\]\<\>]*)\)')
    for match in re.finditer(method_re, java_content):
      method_annotation = match.group('method_annotation')
      method_name = match.group('method_name')
      method_params = match.group('method_params')
      method_return = match.group('method_return')
      method_doc = match.group('method_doc')
      method = Method(
          self._class_name,
          self._class_loader,
          False, # is_constructor
          False, # is_static
          True, # is_abstract
          method_name, method_return, method_params,
          method_annotation, method_doc)
      self._methods.append(method)
Esempio n. 4
0
 def create_new_method_object_and_clear_list(self):
     if self.method_name in self.common_methods:
         new_method = Method(self.method_name, self.code_lines.copy(),
                             self.class_name)
         self.all_methods.append(new_method)
         self.code_lines.clear()