/*
 * Copyright 2019-present Facebook, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.facebook.litho.sections;

import com.facebook.litho.sections.SectionsLogEventUtils.ApplyNewChangeSet;
import com.facebook.litho.widget.RenderInfo;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;

/**
 * Used for debugging changeset generation. If a {@link ChangesetDebugListener} instance is
 * configured, an event will be dispatched from the {@link SectionTree} whenever a new changeset is
 * generated and applied.
 */
public class ChangesetDebugConfiguration {
  private static @Nullable ChangesetDebugListener sListener;

  public interface ChangesetDebugListener {
    void onChangesetApplied(
        @Nullable Section rootSection,
        @Nullable Section oldSection,
        ChangesInfo changesInfo,
        String surfaceId,
        @ApplyNewChangeSet int source,
        @Nullable String attribution);
  }

  public static void setListener(ChangesetDebugListener listener) {
    sListener = listener;
  }

  static @Nullable ChangesetDebugListener getListener() {
    return sListener;
  }

  /** @return a list with the names of the RenderInfos for this change. */
  public static List<String> getRenderInfoNames(Change change) {
    final List<String> names = new ArrayList<>();
    final List<RenderInfo> renderInfos = change.getRenderInfos();

    if (renderInfos.isEmpty()) {
      names.add(change.getRenderInfo().getName());
    } else {
      for (int i = 0; i < renderInfos.size(); i++) {
        names.add(renderInfos.get(i).getName());
      }
    }

    return names;
  }

  public static boolean isSectionDirty(
      @Nullable Section previousSection, @Nullable Section currentSection) {
    /**
     * If currentSection is null, the SectionTree has been released. Mark it as dirty as something
     * did change, though at this point we don't really care about its lifecycle anymore.
     */
    if (previousSection == null || currentSection == null) {
      return true;
    }

    return currentSection.shouldComponentUpdate(previousSection, currentSection);
  }

  public static int getSectionCount(Section section) {
    return section.getCount();
  }
}

@@ -1173,16 +1173,1343 @@
 tener;%0A%0A
+  public static class ChangesetDebugInfo %7B%0A    final @ApplyNewChangeSet int mSource;%0A    final @Nullable String mAttribution;%0A    @Nullable Section mOldSection;%0A    @Nullable String mUpdateStateAttribution;%0A%0A    ChangesetDebugInfo(int source, @Nullable String attribution, @Nullable Section oldSection) %7B%0A      this(source, attribution, null, oldSection);%0A    %7D%0A%0A    ChangesetDebugInfo(%0A        int source,%0A        @Nullable String attribution,%0A        @Nullable String updateStateAttribution,%0A        @Nullable Section oldSection) %7B%0A      mSource = source;%0A      mAttribution = attribution;%0A      mUpdateStateAttribution = updateStateAttribution;%0A      mOldSection = oldSection;%0A    %7D%0A%0A    /** Get the id for the type of event that triggered a new changeset generation. */%0A    public int getSource() %7B%0A      return mSource;%0A    %7D%0A%0A    /** Get the name of the section to which a new changeset generation is attributed to. */%0A    @Nullable%0A    public String getAttribution() %7B%0A      return mAttribution;%0A    %7D%0A%0A    /** Get the root section from the old tree. */%0A    @Nullable%0A    public Section getOldSection() %7B%0A      return mOldSection;%0A    %7D%0A%0A    /** Get the name of the section which triggered a state update. */%0A    @Nullable%0A    public String getUpdateStateAttribution() %7B%0A      return mUpdateStateAttribution;%0A    %7D%0A  %7D%0A%0A
   public

Add ChangesetDebugInfo class