<commit_before>/*
 * Copyright (c) 2017-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 */

package com.facebook.litho.sections.processor;

import com.facebook.litho.sections.annotations.DiffSectionSpec;
import com.facebook.litho.sections.annotations.GroupSectionSpec;
import com.facebook.litho.sections.processor.specmodels.model.DelegateMethodDescriptions;
import com.facebook.litho.sections.processor.specmodels.model.DiffSectionSpecModel;
import com.facebook.litho.sections.processor.specmodels.model.GroupSectionSpecModel;
import com.facebook.litho.sections.processor.specmodels.model.HasService;
import com.facebook.litho.specmodels.generator.BuilderGenerator;
import com.facebook.litho.specmodels.generator.ComponentImplGenerator;
import com.facebook.litho.specmodels.generator.DelegateMethodGenerator;
import com.facebook.litho.specmodels.generator.EventGenerator;
import com.facebook.litho.specmodels.generator.PreambleGenerator;
import com.facebook.litho.specmodels.model.DependencyInjectionHelper;
import com.facebook.litho.specmodels.model.SpecModel;
import javax.annotation.Nullable;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;

/**
 * Processor used to generate <code>com.facebook.litho.sections.SectionLifecycle</code> and
 * <code>com.facebook.litho.sections.Section</code> classes for a {@link GroupSectionSpec}
 * or a {@link DiffSectionSpec}.
 */
@SupportedSourceVersion(SourceVersion.RELEASE_7)
public class SectionsComponentProcessor extends AbstractSectionsComponentProcessor {

  @Override
  protected void generate(GroupSectionSpecHelper groupSectionSpecHelper) {
    final GroupSectionSpecModel specModel = groupSectionSpecHelper.getSpecModel();
    generateCommonListComponent(groupSectionSpecHelper);
    DelegateMethodGenerator.generateDelegates(
        specModel,
        DelegateMethodDescriptions.getGroupSectionSpecDelegatesMap(specModel))
        .addToTypeSpec(groupSectionSpecHelper.getTypeSpec());
    groupSectionSpecHelper.generateTreePropsMethods();
  }

  @Override
  protected void generate(DiffSectionSpecHelper diffSectionSpecHelper) {
    final DiffSectionSpecModel specModel = diffSectionSpecHelper.getSpecModel();
    generateCommonListComponent(diffSectionSpecHelper);
    DelegateMethodGenerator.generateDelegates(
            specModel, DelegateMethodDescriptions.getDiffSectionSpecDelegatesMap(specModel))
        .addToTypeSpec(diffSectionSpecHelper.getTypeSpec());
  }

  private <S extends SpecModel & HasService> void generateCommonListComponent(
      ListSpecHelper<S> listSpecHelper) {
    S specModel = listSpecHelper.getSpecModel();
    listSpecHelper.getTypeSpec().addModifiers(Modifier.FINAL);
    final Stages stages = listSpecHelper.getStages();

    stages.generateSourceDelegate(true);
    PreambleGenerator.generate(specModel).addToTypeSpec(listSpecHelper.getTypeSpec());

    ComponentImplGenerator.generate(specModel, specModel.getServiceParam())
        .addToTypeSpec(listSpecHelper.getTypeSpec());
    stages.generateTransferState(
        SectionClassNames.SECTION_CONTEXT,
        SectionClassNames.SECTION,
        SectionClassNames.STATE_CONTAINER_SECTION);

    BuilderGenerator.generate(listSpecHelper.getSpecModel())
        .addToTypeSpec(listSpecHelper.getTypeSpec());

    stages.generateOnStateUpdateMethods(
        SectionClassNames.SECTION_CONTEXT,
        SectionClassNames.SECTION,
        SectionClassNames.STATE_CONTAINER_SECTION,
        SectionClassNames.SECTION_STATE_UPDATE,
        Stages.StaticFlag.STATIC);
    stages.generateLazyStateUpdateMethods(
        SectionClassNames.SECTION_CONTEXT,
        SectionClassNames.SECTION,
        SectionClassNames.STATE_CONTAINER_SECTION,
        SectionClassNames.SECTION_STATE_UPDATE);

    EventGenerator.generate(specModel).addToTypeSpec(listSpecHelper.getTypeSpec());
  }

  @Override
  @Nullable
  protected DependencyInjectionHelper getDependencyInjectionGenerator(TypeElement typeElement) {
    return null;
  }
}<commit_msg>Reorder generated methods<commit_after>/*
 * Copyright (c) 2017-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 */

package com.facebook.litho.sections.processor;

import com.facebook.litho.sections.annotations.DiffSectionSpec;
import com.facebook.litho.sections.annotations.GroupSectionSpec;
import com.facebook.litho.sections.processor.specmodels.model.DelegateMethodDescriptions;
import com.facebook.litho.sections.processor.specmodels.model.DiffSectionSpecModel;
import com.facebook.litho.sections.processor.specmodels.model.GroupSectionSpecModel;
import com.facebook.litho.sections.processor.specmodels.model.HasService;
import com.facebook.litho.specmodels.generator.BuilderGenerator;
import com.facebook.litho.specmodels.generator.ComponentImplGenerator;
import com.facebook.litho.specmodels.generator.DelegateMethodGenerator;
import com.facebook.litho.specmodels.generator.EventGenerator;
import com.facebook.litho.specmodels.generator.PreambleGenerator;
import com.facebook.litho.specmodels.model.DependencyInjectionHelper;
import com.facebook.litho.specmodels.model.SpecModel;
import javax.annotation.Nullable;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;

/**
 * Processor used to generate <code>com.facebook.litho.sections.SectionLifecycle</code> and
 * <code>com.facebook.litho.sections.Section</code> classes for a {@link GroupSectionSpec}
 * or a {@link DiffSectionSpec}.
 */
@SupportedSourceVersion(SourceVersion.RELEASE_7)
public class SectionsComponentProcessor extends AbstractSectionsComponentProcessor {

  @Override
  protected void generate(GroupSectionSpecHelper groupSectionSpecHelper) {
    final GroupSectionSpecModel specModel = groupSectionSpecHelper.getSpecModel();
    generateCommonListComponent(groupSectionSpecHelper);
    DelegateMethodGenerator.generateDelegates(
        specModel,
        DelegateMethodDescriptions.getGroupSectionSpecDelegatesMap(specModel))
        .addToTypeSpec(groupSectionSpecHelper.getTypeSpec());
    groupSectionSpecHelper.generateTreePropsMethods();
  }

  @Override
  protected void generate(DiffSectionSpecHelper diffSectionSpecHelper) {
    final DiffSectionSpecModel specModel = diffSectionSpecHelper.getSpecModel();
    generateCommonListComponent(diffSectionSpecHelper);
    DelegateMethodGenerator.generateDelegates(
            specModel, DelegateMethodDescriptions.getDiffSectionSpecDelegatesMap(specModel))
        .addToTypeSpec(diffSectionSpecHelper.getTypeSpec());
  }

  private <S extends SpecModel & HasService> void generateCommonListComponent(
      ListSpecHelper<S> listSpecHelper) {
    S specModel = listSpecHelper.getSpecModel();
    listSpecHelper.getTypeSpec().addModifiers(Modifier.FINAL);
    final Stages stages = listSpecHelper.getStages();

    stages.generateSourceDelegate(true);
    PreambleGenerator.generate(specModel).addToTypeSpec(listSpecHelper.getTypeSpec());

    ComponentImplGenerator.generate(specModel, specModel.getServiceParam())
        .addToTypeSpec(listSpecHelper.getTypeSpec());
    BuilderGenerator.generate(listSpecHelper.getSpecModel())
        .addToTypeSpec(listSpecHelper.getTypeSpec());

    stages.generateTransferState(
        SectionClassNames.SECTION_CONTEXT,
        SectionClassNames.SECTION,
        SectionClassNames.STATE_CONTAINER_SECTION);
    stages.generateOnStateUpdateMethods(
        SectionClassNames.SECTION_CONTEXT,
        SectionClassNames.SECTION,
        SectionClassNames.STATE_CONTAINER_SECTION,
        SectionClassNames.SECTION_STATE_UPDATE,
        Stages.StaticFlag.STATIC);
    stages.generateLazyStateUpdateMethods(
        SectionClassNames.SECTION_CONTEXT,
        SectionClassNames.SECTION,
        SectionClassNames.STATE_CONTAINER_SECTION,
        SectionClassNames.SECTION_STATE_UPDATE);

    EventGenerator.generate(specModel).addToTypeSpec(listSpecHelper.getTypeSpec());
  }

  @Override
  @Nullable
  protected DependencyInjectionHelper getDependencyInjectionGenerator(TypeElement typeElement) {
    return null;
  }
}
{'fraction_non_alphanumeric': 0.08071748878923767, 'fraction_numerical': 0.0011498217776244682, 'mean_word_length': 5.599393019726858, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2567856', 'n_tokens_mistral': 2345, 'n_tokens_neox': 2318, 'n_words': 372}