/**
   * Constructs a ClassVisitor to efficiently travel to the specified classes and class members.
   *
   * @param classSpecification the specifications of the class(es) and class members to visit.
   * @param classVisitor the ClassVisitor to be applied to matching classes.
   * @param memberVisitor the MemberVisitor to be applied to matching class members.
   */
  private static ClassVisitor createCombinedClassVisitor(
      ClassSpecification classSpecification,
      ClassVisitor classVisitor,
      MemberVisitor memberVisitor) {
    // Don't visit any members if there aren't any member specifications.
    if (classSpecification.fieldSpecifications == null
        && classSpecification.methodSpecifications == null) {
      memberVisitor = null;
    }

    // The class visitor for classes and their members.
    MultiClassVisitor multiClassVisitor = new MultiClassVisitor();

    // If specified, let the class visitor visit the class itself.
    if (classVisitor != null) {
      // This class visitor may be the only one.
      if (memberVisitor == null) {
        return classVisitor;
      }

      multiClassVisitor.addClassVisitor(classVisitor);
    }

    // If specified, let the member info visitor visit the class members.
    if (memberVisitor != null) {
      ClassVisitor memberClassVisitor = createClassVisitor(classSpecification, memberVisitor);

      // This class visitor may be the only one.
      if (classVisitor == null) {
        return memberClassVisitor;
      }

      multiClassVisitor.addClassVisitor(memberClassVisitor);
    }

    return multiClassVisitor;
  }
  /**
   * Adds elements to the given MultiClassVisitor, to apply the given MemberVisitor to all class
   * members that match the given List of options (of the given type).
   */
  private static void addMemberVisitors(
      List memberSpecifications,
      boolean isField,
      MultiClassVisitor multiClassVisitor,
      MemberVisitor memberVisitor) {
    if (memberSpecifications != null) {
      for (int index = 0; index < memberSpecifications.size(); index++) {
        MemberSpecification memberSpecification =
            (MemberSpecification) memberSpecifications.get(index);

        multiClassVisitor.addClassVisitor(
            createClassVisitor(memberSpecification, isField, memberVisitor));
      }
    }
  }