Beispiel #1
0
    def _link_enum_values(self, enum_refs, ecount, progress_monitor):
        count = 0
        progress_monitor.start('Parsing enumeration values', ecount)
        log = gl.LinkerLog(self, self.enum_value_kind.kind)

        for scode_reference in enum_refs:
            (field_name, fqn_container) = self._get_field_name(scode_reference)
            code_elements = self._get_field_elements(field_name,
                                                     PREFIX_ENUM_VAL_LINKER,
                                                     self.enum_value_kind)

            (code_element,
             potentials) = self.get_code_element(scode_reference,
                                                 code_elements, field_name,
                                                 fqn_container, log)
            count += gl.save_link(scode_reference, code_element, potentials,
                                  self)

            if not log.custom_filtered:
                reclassify_java(code_element, scode_reference)

            progress_monitor.work('Processed enum value', 1)

        log.close()
        progress_monitor.done()
        print('Associated {0} enum values'.format(count))
Beispiel #2
0
    def _link_fields(self, field_refs, acount, progress_monitor):
        count = 0
        progress_monitor.start('Parsing fields', acount)
        log = gl.LinkerLog(self, self.field_kind.kind)

        for scode_reference in field_refs:
            (field_name, fqn_container) = self._get_field_name(scode_reference)
            code_elements = []
            code_elements.extend(
                self._get_field_elements(field_name, PREFIX_FIELD_LINKER,
                                         self.field_kind))
            code_elements.extend(
                self._get_field_elements(field_name, PREFIX_ENUM_VAL_LINKER,
                                         self.enum_value_kind))
            code_elements.extend(
                self._get_field_elements(field_name, PREFIX_ANN_FIELD_LINKER,
                                         self.ann_field_kind))

            (code_element,
             potentials) = self.get_code_element(scode_reference,
                                                 code_elements, field_name,
                                                 fqn_container, log)
            count += gl.save_link(scode_reference, code_element, potentials,
                                  self)

            if not log.custom_filtered:
                reclassify_java(code_element, scode_reference)

            progress_monitor.work('Processed field', 1)

        log.close()
        progress_monitor.done()
        print('Associated {0} fields'.format(count))
Beispiel #3
0
    def _link_methods(self, method_refs, mcount, progress_monitor):
        count = 0
        progress_monitor.start('Parsing methods', mcount)
        log = gl.LinkerLog(self, self.method_kind.kind)

        for scode_reference in method_refs:
            method_info = self._get_method_info(scode_reference)
            code_elements = self._get_method_elements(method_info)

            (code_element,
             potentials) = self.get_code_element(scode_reference,
                                                 code_elements, method_info,
                                                 log)
            count += gl.save_link(scode_reference, code_element, potentials,
                                  self)

            if not log.custom_filtered:
                reclassify_java(code_element, scode_reference)

            progress_monitor.work('Processed method', 1)

        log.close()
        progress_monitor.done()
        print('Associated {0} methods'.format(count))
Beispiel #4
0
    def _link_enumerations(self, enum_refs, ecount, progress_monitor):
        count = 0
        progress_monitor.start('Parsing enumerations', ecount)
        log = gl.LinkerLog(self, self.enum_kind.kind)

        for scode_reference in enum_refs:
            if scode_reference.declaration:
                progress_monitor.work('Skipped declaration', 1)
                continue

            (simple,
             fqn) = je.get_annotation_name(scode_reference.content,
                                           scode_reference.snippet is not None)

            if simple is not None:
                prefix = '{0}{1}{2}'.format(PREFIX_ENUMERATION_LINKER, EXACT,
                                            cu.get_codebase_key(self.codebase))
                code_elements = cu.get_value(
                    prefix, simple, gl.get_type_code_elements,
                    [simple, self.codebase, self.enum_kind])

                (code_element,
                 potentials) = self.get_code_element(scode_reference,
                                                     code_elements, simple,
                                                     fqn, log)
                count += gl.save_link(scode_reference, code_element,
                                      potentials, self)

                if not log.custom_filtered:
                    reclassify_java(code_element, scode_reference)

            progress_monitor.work('Processed enumeration', 1)

        log.close()
        progress_monitor.done()
        print('Associated {0} enumerations'.format(count))
Beispiel #5
0
    def link_references(self,
                        progress_monitor=NullProgressMonitor(),
                        local_object_id=None):

        # Get link to filter.
        linksets = ReleaseLinkSet.objects\
                .filter(project_release=self.prelease)\
                .filter(first_link__code_element__kind__is_type=True)

        count = linksets.count()
        progress_monitor.start('Post-Processing Classes', count)
        log = gl.LinkerLog(self, 'type')

        for linkset in queryset_iterator(linksets):
            log.reset_variables()
            scode_reference = linkset.code_reference
            lcount = linkset.links.count()
            if lcount <= 1:
                log.log_type('', '', scode_reference,
                             linkset.first_link.code_element,
                             [linkset.first_link], lcount, 'onlyone')
                progress_monitor.work('Skipped a linkset.', 1)
                continue

            local_ctx_id = scode_reference.local_object_id
            source = scode_reference.source
            prefix = '{0}{1}{2}'.format(PREFIX_CLASS_POST_LINKER,
                                        cu.get_codebase_key(self.codebase),
                                        source)
            package_freq = cu.get_value(prefix, local_ctx_id, get_package_freq,
                                        [local_ctx_id, source, self.prelease])

            # Find package with highest frequency
            code_element = self._find_package_by_freq(linkset, package_freq)
            rationale = 'highest_frequency'

            # Heuristic
            if code_element is None:
                code_element = self._find_package_by_depth(linkset)
                rationale = 'heuristic_depth'

            # Update links
            if code_element is not None:
                linkset.first_link.code_element = code_element
                linkset.first_link.linker_name = self.name
                linkset.first_link.rationale = rationale
                linkset.first_link.save()
                for link in linkset.links.all()[1:]:
                    link.delete()
                log.log_type('', '', scode_reference,
                             linkset.first_link.code_element,
                             [linkset.first_link], lcount, rationale)
                progress_monitor.info(
                    'FOUND Best Package {0} because {1}'.format(
                        code_element.fqn, rationale))
            else:
                potentials =\
                    [link.code_element for link in linkset.links.all()]
                log.log_type('', '', scode_reference,
                             linkset.first_link.code_element, potentials,
                             lcount, 'nomatch')

            progress_monitor.work('Processed a linkset.', 1)

        progress_monitor.done()
Beispiel #6
0
    def _link_classes(self, class_refs, ccount, progress_monitor):
        count = 0
        progress_monitor.start('Parsing classes', ccount)
        log = gl.LinkerLog(self, self.class_kind.kind)

        for scode_reference in class_refs:
            if scode_reference.declaration:
                progress_monitor.work('Skipped declaration', 1)
                continue

            (simple,
             fqn) = je.get_annotation_name(scode_reference.content,
                                           scode_reference.snippet is not None)
            case_insensitive = scode_reference.snippet == None and\
                    self.source != 'd'

            if case_insensitive:
                exact = False
                exact_prefix = IEXACT
            else:
                exact = True
                exact_prefix = EXACT

            if simple is not None:
                prefix = '{0}{1}{2}'.format(PREFIX_CLASS_LINKER, exact_prefix,
                                            cu.get_codebase_key(self.codebase))
                code_elements = []
                code_elements.extend(
                    cu.get_value(
                        prefix, simple, gl.get_type_code_elements,
                        [simple, self.codebase, self.class_kind, exact]))

                prefix = '{0}{1}{2}'.format(PREFIX_ANNOTATION_LINKER,
                                            exact_prefix,
                                            cu.get_codebase_key(self.codebase))
                code_elements.extend(
                    cu.get_value(
                        prefix, simple, gl.get_type_code_elements,
                        [simple, self.codebase, self.ann_kind, exact]))

                prefix = '{0}{1}{2}'.format(PREFIX_ENUMERATION_LINKER,
                                            exact_prefix,
                                            cu.get_codebase_key(self.codebase))
                code_elements.extend(
                    cu.get_value(
                        prefix, simple, gl.get_type_code_elements,
                        [simple, self.codebase, self.enum_kind, exact]))

                (code_element,
                 potentials) = self.get_code_element(scode_reference,
                                                     code_elements, simple,
                                                     fqn, log, not exact)
                count += gl.save_link(scode_reference, code_element,
                                      potentials, self)

                if not log.custom_filtered:
                    reclassify_java(code_element, scode_reference)

            progress_monitor.work('Processed class', 1)

        log.close()
        progress_monitor.done()
        print('Associated {0} classes'.format(count))
Beispiel #7
0
    def _process_tuples(self, class_tuples, progress_monitor):
        method_tuples = []
        field_tuples = []
        count = 0

        for (reference, simple, fqn, class_elements, method_elements,
             field_elements) in class_tuples:
            if len(class_elements) > 0:
                log = gl.LinkerLog(self, 'generic-' + self.class_kind.kind)
                (code_element, potentials) = \
                        self.class_linker.get_code_element(reference,
                                class_elements, simple, fqn, log, True)
                if code_element is not None:
                    count += gl.save_link(reference, code_element, potentials,
                                          self)
                else:
                    method_tuples.append((reference, simple, fqn,
                                          method_elements, field_elements))
                log.close()
            else:
                method_tuples.append(
                    (reference, simple, fqn, method_elements, field_elements))

        for (reference, simple, fqn, method_elements,
             field_elements) in method_tuples:
            if len(method_elements) > 0:
                fqn_container = je.get_package_name(fqn)
                if fqn_container == simple:
                    fqn_container = None
                log = gl.LinkerLog(self, 'generic-' + self.method_kind.kind)
                method_info = MethodInfo(simple, fqn_container, None, None)
                (code_element, potentials) =\
                        self.method_linker.get_code_element(reference,
                                method_elements, method_info, log)
                if code_element is not None:
                    count += gl.save_link(reference, code_element, potentials,
                                          self)
                else:
                    field_tuples.append(
                        (reference, simple, fqn, field_elements))
                log.close()
            else:
                field_tuples.append((reference, simple, fqn, field_elements))

        for (reference, simple, fqn, field_elements) in field_tuples:
            if len(field_elements) > 0:
                fqn_container = je.get_package_name(fqn)
                if fqn_container == simple:
                    fqn_container = None
                log = gl.LinkerLog(self, 'generic-' + self.field_kind.kind)
                (code_element, potentials) =\
                        self.field_linker.get_code_element(reference,
                                field_elements, simple, fqn_container, log)
                if code_element is not None:
                    count += gl.save_link(reference, code_element, potentials,
                                          self)
                else:
                    field_tuples.append(
                        (reference, simple, fqn, field_elements))
                log.close()

        return count