

def _find_package_by_freq(self, linkset, package_freq):
    package_names = [p[0] for p in package_freq]
    size = len(package_freq)
    best_index = size
    best_element = None
    for link in linkset.links.all():
        package = find_package(link.code_element)
        if (package is not None):
            try:
                index = package_names.index(package)
                if (index < best_index):
                    if ((index == (size - 1)) or (best_index == size)):
                        best_index = index
                        best_element = link.code_element
                    elif (package_freq[index][1] > package_freq[best_index][1]):
                        best_index = index
                        best_element = link.code_element
                    else:
                        depth_best = len(package_names[best_index].split('.'))
                        depth_index = len(package_names[index].split('.'))
                        if (depth_best < depth_index):
                            continue
                        elif (depth_index < depth_best):
                            best_index = index
                            best_element = link.code_element
                        else:
                            best_index = package_names
                            best_element = None
            except Exception:
                pass
    return best_element

dataset/ETHPy150Open bartdag/recodoc2/recodoc2/apps/codebase/linker/java_linkers.py JavaPostClassLinker._find_package_by_freq/VarMisuse@232/323 `size`->`package_names`