private void generateInjectAdapter(TypeElement type, ExecutableElement constructor,
      List<Element> fields) throws IOException {
    String packageName = getPackage(type).getQualifiedName().toString();
    TypeMirror supertype = getApplicationSupertype(type);
    if (supertype != null) {
      supertype = processingEnv.getTypeUtils().erasure(supertype);
    }
    ClassName injectedClassName = ClassName.get(type);
    ClassName adapterClassName = adapterName(injectedClassName, INJECT_ADAPTER_SUFFIX);

    boolean isAbstract = type.getModifiers().contains(ABSTRACT);
    boolean injectMembers = !fields.isEmpty() || supertype != null;
    boolean disambiguateFields = !fields.isEmpty()
        && (constructor != null)
        && !constructor.getParameters().isEmpty();
    boolean dependent = injectMembers
        || ((constructor != null) && !constructor.getParameters().isEmpty());

    TypeSpec.Builder result = TypeSpec.classBuilder(adapterClassName.simpleName())
        .addOriginatingElement(type)
        .addModifiers(PUBLIC, FINAL)
        .superclass(ParameterizedTypeName.get(ClassName.get(Binding.class), injectedClassName))
        .addJavadoc("$L", bindingTypeDocs(injectableType(type.asType()), isAbstract,
            injectMembers, dependent).toString());

    for (Element field : fields) {
      result.addField(memberBindingField(disambiguateFields, field));
    }
    if (constructor != null) {
      for (VariableElement parameter : constructor.getParameters()) {
        result.addField(parameterBindingField(disambiguateFields, parameter));
      }
    }
    if (supertype != null) {
      result.addField(supertypeBindingField(supertype));
    }

    result.addMethod(writeInjectAdapterConstructor(constructor, type, injectedClassName));
    if (dependent) {
      result.addMethod(attachMethod(
          constructor, fields, disambiguateFields, injectedClassName, supertype, true));
      result.addMethod(getDependenciesMethod(
          constructor, fields, disambiguateFields, supertype, true));
    }
    if (constructor != null) {
      result.addMethod(
          getMethod(constructor, disambiguateFields, injectMembers, injectedClassName));
    }
    if (injectMembers) {
      result.addMethod(
          membersInjectMethod(fields, disambiguateFields, injectedClassName, supertype));
    }

    JavaFile javaFile = JavaFile.builder(packageName, result.build())
        .addFileComment(AdapterJavadocs.GENERATED_BY_DAGGER)
        .build();
    javaFile.writeTo(processingEnv.getFiler());
  }
private void generateInjectAdapter ( TypeElement type , ExecutableElement constructor , List < Element > fields ) throws IOException { String packageName = getPackage ( type ) . getQualifiedName ( ) . toString ( ) ; TypeMirror supertype = getApplicationSupertype ( type ) ; if ( supertype != null ) { supertype = processingEnv . getTypeUtils ( ) . erasure ( supertype ) ; } ClassName injectedClassName = ClassName . get ( type ) ; ClassName adapterClassName = adapterName ( injectedClassName , INJECT_ADAPTER_SUFFIX ) ; boolean isAbstract = type . getModifiers ( ) . contains ( ABSTRACT ) ; boolean injectMembers = ! fields . isEmpty ( ) || supertype != null ; boolean disambiguateFields = ! fields . isEmpty ( ) && ( constructor != null ) && ! constructor . getParameters ( ) . isEmpty ( ) ; boolean dependent = injectMembers || ( ( constructor != null ) && ! constructor . getParameters ( ) . isEmpty ( ) ) ; TypeSpec . Builder result = TypeSpec . classBuilder ( adapterClassName . simpleName ( ) ) . addOriginatingElement ( type ) . addModifiers ( PUBLIC , FINAL ) . superclass ( ParameterizedTypeName . get ( ClassName . get ( Binding . class ) , injectedClassName ) ) . addJavadoc ( "$L" , bindingTypeDocs ( injectableType ( type . asType ( ) ) , isAbstract , injectMembers , dependent ) . toString ( ) ) ; for ( Element field : fields ) { result . addField ( memberBindingField ( disambiguateFields , field ) ) ; } if ( constructor != null ) { for ( VariableElement parameter : constructor . getParameters ( ) ) { result . addField ( parameterBindingField ( disambiguateFields , parameter ) ) ; } } if ( supertype != null ) { result . addField ( supertypeBindingField ( supertype ) ) ; } result . addMethod ( writeInjectAdapterConstructor ( constructor , type , injectedClassName ) ) ; if ( dependent ) { result . addMethod ( attachMethod ( constructor , fields , disambiguateFields , injectedClassName , supertype , true ) ) ; result . addMethod ( getDependenciesMethod ( constructor , fields , disambiguateFields , supertype , true ) ) ; } if ( constructor != null ) { result . addMethod ( getMethod ( constructor , disambiguateFields , injectMembers , injectedClassName ) ) ; } if ( injectMembers ) { result . addMethod ( membersInjectMethod ( fields , disambiguateFields , injectedClassName , supertype ) ) ; } JavaFile javaFile = JavaFile . builder ( packageName , result . build ( ) ) . addFileComment ( AdapterJavadocs . GENERATED_BY_DAGGER ) . build ( ) ; javaFile . writeTo ( processingEnv . getFiler ( ) ) ; }
Write a companion class for {@code type} that extends {@link Binding}.

@param constructor the injectable constructor, or null if this binding
supports members injection only.