tools/android/dependency_analysis/print_class_dependencies.py
def print_class_dependencies(to_classes: List[class_dependency.JavaClass],
                             print_mode: PrintMode,
                             from_class: class_dependency.JavaClass,
                             direction: str,
                             audited_classes: Set[str]) -> TargetDependencies:
    """Prints the class dependencies to or from a class, grouped by target.

    If direction is OUTBOUND and print_mode.ignore_modularized is True, omits
    modularized outbound dependencies and returns the build targets that need
    to be added for those dependencies. In other cases, returns an empty
    TargetDependencies.

    If print_mode.ignore_same_package is True, omits outbound dependencies in
    the same package.
    """
    ignore_modularized = direction == OUTBOUND and print_mode.ignore_modularized
    bullet_point = '<-' if direction == INBOUND else '->'

    print_backlog: List[Tuple[int, str]] = []

    # TODO(crbug.com/1124836): This is not quite correct because
    # sets considered equal can be converted to different strings. Fix this by
    # making JavaClass.build_targets return a List instead of a Set.
    suspect_dependencies = 0

    target_dependencies = TargetDependencies()
    to_classes = sorted(to_classes, key=lambda c: str(c.build_targets))
    last_build_target = None

    for to_class in to_classes:
        # Check if dependency should be ignored due to --ignore-modularized,
        # --ignore-same-package, or due to being an ignored class.
        # Check if dependency should be listed as a cleared dep.
        ignore_allow = categorize_dependency(from_class, to_class,
                                             ignore_modularized, print_mode,
                                             audited_classes)
        if ignore_allow == CLEAR:
            target_dependencies.update_with_class_node(to_class)
            continue
        elif ignore_allow == IGNORE:
            continue

        # Print the dependency
        suspect_dependencies += 1
        build_target = str(to_class.build_targets)
        if last_build_target != build_target:
            build_target_names = [
                get_build_target_name_to_display(target, print_mode)
                for target in to_class.build_targets
            ]
            build_target_names_string = ", ".join(build_target_names)
            print_backlog.append((4, f'[{build_target_names_string}]'))
            last_build_target = build_target
        display_name = get_class_name_to_display(to_class.name, print_mode)
        print_backlog.append((8, f'{bullet_point} {display_name}'))

    # Print header
    class_name = get_class_name_to_display(from_class.name, print_mode)
    if ignore_modularized:
        cleared = len(to_classes) - suspect_dependencies
        print(f'{class_name} has {suspect_dependencies} outbound dependencies '
              f'that may need to be broken (omitted {cleared} cleared '
              f'dependencies):')
    else:
        if direction == INBOUND:
            print(f'{class_name} has {len(to_classes)} inbound dependencies:')
        else:
            print(f'{class_name} has {len(to_classes)} outbound dependencies:')

    # Print build targets and dependencies
    for indent, message in print_backlog:
        indents = ' ' * indent
        print(f'{indents}{message}')

    return target_dependencies
Prints the class dependencies to or from a class, grouped by target.

    If direction is OUTBOUND and print_mode.ignore_modularized is True, omits
    modularized outbound dependencies and returns the build targets that need
    to be added for those dependencies. In other cases, returns an empty
    TargetDependencies.

    If print_mode.ignore_same_package is True, omits outbound dependencies in
    the same package.
    
Prints the class dependencies to or from a class, grouped by target.
If direction is OUTBOUND and print_mode.ignore_modularized is True, omits
modularized outbound dependencies and returns the build targets that need
to be added for those dependencies. In other cases, returns an empty
TargetDependencies.

If print_mode.ignore_same_package is True, omits outbound dependencies in
the same package.
Prints the class dependencies to or from a class grouped by target . If direction is OUTBOUND and print_mode . ignore_modularized is True omits modularized outbound dependencies and returns the build targets that need to be added for those dependencies . In other cases returns an empty TargetDependencies . If print_mode . ignore_same_package is True omits outbound dependencies in the same package .
def print_class_dependencies(to_classes: List[class_dependency.JavaClass],
                             print_mode: PrintMode,
                             from_class: class_dependency.JavaClass,
                             direction: str,
                             audited_classes: Set[str]) -> TargetDependencies:
    ignore_modularized = direction == OUTBOUND and print_mode.ignore_modularized
    bullet_point = '<-' if direction == INBOUND else '->'
    print_backlog: List[Tuple[int, str]] = []
    suspect_dependencies = 0
    target_dependencies = TargetDependencies()
    to_classes = sorted(to_classes, key=lambda c: str(c.build_targets))
    last_build_target = None
    for to_class in to_classes:
        ignore_allow = categorize_dependency(from_class, to_class,
                                             ignore_modularized, print_mode,
                                             audited_classes)
        if ignore_allow == CLEAR:
            target_dependencies.update_with_class_node(to_class)
            continue
        elif ignore_allow == IGNORE:
            continue
        suspect_dependencies += 1
        build_target = str(to_class.build_targets)
        if last_build_target != build_target:
            build_target_names = [
                get_build_target_name_to_display(target, print_mode)
                for target in to_class.build_targets
            ]
            build_target_names_string = ", ".join(build_target_names)
            print_backlog.append((4, f'[{build_target_names_string}]'))
            last_build_target = build_target
        display_name = get_class_name_to_display(to_class.name, print_mode)
        print_backlog.append((8, f'{bullet_point} {display_name}'))
    class_name = get_class_name_to_display(from_class.name, print_mode)
    if ignore_modularized:
        cleared = len(to_classes) - suspect_dependencies
        print(f'{class_name} has {suspect_dependencies} outbound dependencies '
              f'that may need to be broken (omitted {cleared} cleared '
              f'dependencies):')
    else:
        if direction == INBOUND:
            print(f'{class_name} has {len(to_classes)} inbound dependencies:')
        else:
            print(f'{class_name} has {len(to_classes)} outbound dependencies:')
    for indent, message in print_backlog:
        indents = ' ' * indent
        print(f'{indents}{message}')
    return target_dependencies
def print_class_dependencies ( to_classes : List [ class_dependency . JavaClass ] , print_mode : PrintMode , from_class : class_dependency . JavaClass , direction : str , audited_classes : Set [ str ] ) -> TargetDependencies : ignore_modularized = direction == OUTBOUND and print_mode . ignore_modularized bullet_point = '<-' if direction == INBOUND else '->' print_backlog : List [ Tuple [ int , str ] ] = [ ] suspect_dependencies = 0 target_dependencies = TargetDependencies ( ) to_classes = sorted ( to_classes , key = lambda c : str ( c . build_targets ) ) last_build_target = None for to_class in to_classes : ignore_allow = categorize_dependency ( from_class , to_class , ignore_modularized , print_mode , audited_classes ) if ignore_allow == CLEAR : target_dependencies . update_with_class_node ( to_class ) continue elif ignore_allow == IGNORE : continue suspect_dependencies += 1 build_target = str ( to_class . build_targets ) if last_build_target != build_target : build_target_names = [ get_build_target_name_to_display ( target , print_mode ) for target in to_class . build_targets ] build_target_names_string = ", " . join ( build_target_names ) print_backlog . append ( ( 4 , f'[{build_target_names_string}]' ) ) last_build_target = build_target display_name = get_class_name_to_display ( to_class . name , print_mode ) print_backlog . append ( ( 8 , f'{bullet_point} {display_name}' ) ) class_name = get_class_name_to_display ( from_class . name , print_mode ) if ignore_modularized : cleared = len ( to_classes ) - suspect_dependencies print ( f'{class_name} has {suspect_dependencies} outbound dependencies ' f'that may need to be broken (omitted {cleared} cleared ' f'dependencies):' ) else : if direction == INBOUND : print ( f'{class_name} has {len(to_classes)} inbound dependencies:' ) else : print ( f'{class_name} has {len(to_classes)} outbound dependencies:' ) for indent , message in print_backlog : indents = ' ' * indent print ( f'{indents}{message}' ) return target_dependencies
Prints the class dependencies to or from a class, grouped by target.
Prints the class dependencies to or from a class grouped by target .
"""Prints the class dependencies to or from a class, grouped by target.

    If direction is OUTBOUND and print_mode.ignore_modularized is True, omits
    modularized outbound dependencies and returns the build targets that need
    to be added for those dependencies. In other cases, returns an empty
    TargetDependencies.

    If print_mode.ignore_same_package is True, omits outbound dependencies in
    the same package.
    """ # TODO(crbug.com/1124836): This is not quite correct because # sets considered equal can be converted to different strings. Fix this by # making JavaClass.build_targets return a List instead of a Set. # Check if dependency should be ignored due to --ignore-modularized, # --ignore-same-package, or due to being an ignored class. # Check if dependency should be listed as a cleared dep. # Print the dependency # Print header # Print build targets and dependencies
to_classes
List[class_dependency.JavaClass]
print_mode
PrintMode
from_class
class_dependency.JavaClass
direction
str
audited_classes
Set[str]