Esempio n. 1
0
def get_annotation_name(name, is_handle):
    pass
    simple = fqn = None
    if is_handle:
        parts = name.split(HANDLE_SEPARATOR)
        (simple, fqn) = clean_java_name(parts[1])
    else:
        match = ANNOTATION_PATTERN.match(name)
        if match:
            (simple, fqn) = clean_java_name(match.group('annotation'))

    return (su.safe_strip(simple), su.safe_strip(fqn))
Esempio n. 2
0
    def _get_field_name(self, scode_reference):
        field_name = fqn_container = None

        if scode_reference.snippet != None:
            parts = scode_reference.content.split(HANDLE_SEPARATOR)
            (field_name, fqn_container) = \
                    self._get_field_name_from_snippet(parts)
        else:
            content = je.get_clean_name(scode_reference.content)
            (field_name, fqn) = je.clean_java_name(content)
            if fqn != field_name:
                fqn = je.get_package_name(fqn)
                fqn_container = je.clean_potential_annotation(fqn)

        return (su.safe_strip(field_name), su.safe_strip(fqn_container))
Esempio n. 3
0
    def _get_field_name(self, scode_reference):
        field_name = fqn_container = None

        if scode_reference.snippet != None:
            parts = scode_reference.content.split(HANDLE_SEPARATOR)
            (field_name, fqn_container) = \
                    self._get_field_name_from_snippet(parts)
        else:
            content = je.get_clean_name(scode_reference.content)
            (field_name, fqn) = je.clean_java_name(content)
            if fqn != field_name:
                fqn = je.get_package_name(fqn)
                fqn_container = je.clean_potential_annotation(fqn)

        return (su.safe_strip(field_name), su.safe_strip(fqn_container))
Esempio n. 4
0
    def _link_all_references(self, unknown_refs, ucount, progress_monitor):
        skipped = 0
        class_tuples = []

        progress_monitor.start('Parsing all unknown refs', ucount)
        for reference in unknown_refs:
            content = su.safe_strip(reference.content)
            if content is None or content == '':
                progress_monitor.info('Empty {0}'.format(reference.pk))
                progress_monitor.work('Empty {0}'.format(reference.pk), 1)
                skipped += 1

            (simple, fqn) = je.clean_java_name(je.get_clean_name(content))
            prefix = '{0}{1}'.format(PREFIX_GENERIC_LINKER,
                                     cu.get_codebase_key(self.codebase))
            code_elements = cu.get_value(prefix, simple,
                                         gl.get_any_code_element,
                                         [simple, self.codebase])

            classified_elements = self._classify_code_elements(code_elements)
            class_tuples.append((reference, simple, fqn) + classified_elements)

        count = self._process_tuples(class_tuples, progress_monitor)

        progress_monitor.info(
            'Associated {0} elements, Skipped {1} elements'.format(
                count, skipped))
        progress_monitor.done()
Esempio n. 5
0
    def _link_all_references(self, unknown_refs, ucount, progress_monitor):
        skipped = 0
        class_tuples = []

        progress_monitor.start('Parsing all unknown refs', ucount)
        for reference in unknown_refs:
            content = su.safe_strip(reference.content)
            if content is None or content == '':
                progress_monitor.info('Empty {0}'.format(reference.pk))
                progress_monitor.work('Empty {0}'.format(reference.pk), 1)
                skipped += 1

            (simple, fqn) = je.clean_java_name(je.get_clean_name(content))
            prefix = '{0}{1}'.format(PREFIX_GENERIC_LINKER,
                cu.get_codebase_key(self.codebase))
            code_elements = cu.get_value(
                    prefix,
                    simple,
                    gl.get_any_code_element,
                    [simple, self.codebase])

            classified_elements = self._classify_code_elements(code_elements)
            class_tuples.append((reference, simple, fqn) + classified_elements)

        count = self._process_tuples(class_tuples, progress_monitor)

        progress_monitor.info('Associated {0} elements, Skipped {1} elements'
                .format(count, skipped))
        progress_monitor.done()
Esempio n. 6
0
    def _get_method_info(self, scode_reference, skip_complex_search=False):
        method_name = fqn_container = nb_params = type_params = None

        if scode_reference.snippet != None:
            parts = scode_reference.content.split(HANDLE_SEPARATOR)
            (method_name, fqn_container, nb_params, type_params) = \
                    self._get_method_info_snippet(parts)
        else:
            content = scode_reference.content
            match1 = je.CALL_CHAIN_RE.search(content)
            match2 = je.METHOD_DECLARATION_RE.search(content)
            match3 = je.METHOD_SIGNATURE_RE.search(content)
            match4 = je.SIMPLE_CALL_RE.search(content)

            if match1 and not skip_complex_search:
                (method_name, fqn_container) = self._get_method_header(match1)
                eindex = content.index(')')
                sindex = content.index('(')
                params_text = content[sindex + 1:eindex]

                if len(params_text) == 0:
                    # This means that there was no parameter, so no ','
                    nb_params = 0
                else:
                    params = params_text.split(',')
                    nb_params = len(params)
                    type_params = [param.strip() for param in params]

            elif match2 and not skip_complex_search:
                method_name = match2.group('method_name')
                eindex = content.index(')')
                sindex = content.index('(')
                params_text = content[sindex + 1:eindex]

                if len(params_text) == 0:
                    # This means that there was no parameter, so no ','
                    nb_params = 0
                else:
                    params = params_text.split(',')
                    nb_params = len(params)
                    type_params = [param.strip() for param in params]
            elif match3 and not skip_complex_search:
                (method_name, fqn_container) = self._get_method_header(match3)
                (nb_params, type_params) = self._get_method_params(match3)
            elif match4 and not skip_complex_search:
                (method_name, fqn_container) = self._get_method_header(match4)
                (nb_params, type_params) = self._get_method_params(match4)
            else:
                if len(content.strip()) > 0:
                    method_name = je.get_clean_name(content)

            # Convert literals
            if type_params is not None:
                for i, type_param in enumerate(type_params):
                    if type_param is not None:
                        type_param = type_param.strip()
                        atype = je.find_type(type_param)
                        if atype is not None:
                            type_params[i] = atype

        if type_params is not None:
            type_params = \
                    [su.safe_strip(type_param) for type_param in type_params]

        return MethodInfo(su.safe_strip(method_name),
                          su.safe_strip(fqn_container), nb_params, type_params)
Esempio n. 7
0
    def _get_method_info(self, scode_reference, skip_complex_search=False):
        method_name = fqn_container = nb_params = type_params = None

        if scode_reference.snippet != None:
            parts = scode_reference.content.split(HANDLE_SEPARATOR)
            (method_name, fqn_container, nb_params, type_params) = \
                    self._get_method_info_snippet(parts)
        else:
            content = scode_reference.content
            match1 = je.CALL_CHAIN_RE.search(content)
            match2 = je.METHOD_DECLARATION_RE.search(content)
            match3 = je.METHOD_SIGNATURE_RE.search(content)
            match4 = je.SIMPLE_CALL_RE.search(content)

            if match1 and not skip_complex_search:
                (method_name, fqn_container) = self._get_method_header(match1)
                eindex = content.index(')')
                sindex = content.index('(')
                params_text = content[sindex + 1:eindex]

                if len(params_text) == 0:
                    # This means that there was no parameter, so no ','
                    nb_params = 0
                else:
                    params = params_text.split(',')
                    nb_params = len(params)
                    type_params = [param.strip() for param in params]

            elif match2 and not skip_complex_search:
                method_name = match2.group('method_name')
                eindex = content.index(')')
                sindex = content.index('(')
                params_text = content[sindex + 1:eindex]

                if len(params_text) == 0:
                    # This means that there was no parameter, so no ','
                    nb_params = 0
                else:
                    params = params_text.split(',')
                    nb_params = len(params)
                    type_params = [param.strip() for param in params]
            elif match3 and not skip_complex_search:
                (method_name, fqn_container) = self._get_method_header(match3)
                (nb_params, type_params) = self._get_method_params(match3)
            elif match4 and not skip_complex_search:
                (method_name, fqn_container) = self._get_method_header(match4)
                (nb_params, type_params) = self._get_method_params(match4)
            else:
                if len(content.strip()) > 0:
                    method_name = je.get_clean_name(content)

            # Convert literals
            if type_params is not None:
                for i, type_param in enumerate(type_params):
                    if type_param is not None:
                        type_param = type_param.strip()
                        atype = je.find_type(type_param)
                        if atype is not None:
                            type_params[i] = atype

        if type_params is not None:
            type_params = \
                    [su.safe_strip(type_param) for type_param in type_params]

        return MethodInfo(su.safe_strip(method_name),
                su.safe_strip(fqn_container), nb_params, type_params)