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.
160440
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());
  }
1148416
public <S> ServiceBinder<S> bindServices(final Class<S> type) {
        ServiceBinderImpl<S> binder = new ServiceBinderImpl<S>(type);
        binders.add(binder);
        return binder;
    }
598892
public static <T> Constructor<T> getConstructor(Class<T> instantiable, Class<?>... constructorParameterTypes)
    {
        try
        {
            return instantiable.getConstructor(constructorParameterTypes);
        }
        catch (NoSuchMethodException ignored)
        {
            return ReflectionHelper.searchForConstructor(instantiable, constructorParameterTypes);
        }
    }
59741
@Override
  public boolean accept(Class<?> type) {

    if (type != null) {
      if (this.forceInheritence) {
        Annotation annotation = this.annotationUtil.getTypeAnnotation(type, this.annotationType);
        return (annotation != null);
      } else {
        return type.isAnnotationPresent(this.annotationType);
      }

    }
    return false;
  }
981748
@Override
    @SuppressWarnings("unchecked")
    public synchronized <P> PojoBinding<P> createPojoBinding(Class<P> pojoType) {
        DefaultPojoBinding<P> binding = (DefaultPojoBinding<P>) bindingMap.get(pojoType);
        if (binding == null) {
            binding = new DefaultPojoBinding<>(pojoType);
            bindingMap.put(pojoType, binding);
            List<Facet> keyFacets = injectFacetBindings(binding, pojoType);
            injectKeyBinding(binding, pojoType, keyFacets);
        }
        return binding;
    }
285059
public static <T> JavaType constructType(@Nonnull Argument<T> type, @Nonnull TypeFactory typeFactory) {
        ArgumentUtils.requireNonNull("type", type);
        ArgumentUtils.requireNonNull("typeFactory", typeFactory);
        Map<String, Argument<?>> typeVariables = type.getTypeVariables();
        JavaType[] objects = toJavaTypeArray(typeFactory, typeVariables);
        final Class<T> rawType = type.getType();
        if (ArrayUtils.isNotEmpty(objects)) {
            final JavaType javaType = typeFactory.constructType(
                    rawType
            );
            if (javaType.isCollectionLikeType()) {
                return typeFactory.constructCollectionLikeType(
                        rawType,
                        objects[0]
                );
            } else if (javaType.isMapLikeType()) {
                return typeFactory.constructMapLikeType(
                        rawType,
                        objects[0],
                        objects[1]
                );
            } else if (javaType.isReferenceType()) {
                return typeFactory.constructReferenceType(rawType, objects[0]);
            }
            return typeFactory.constructParametricType(rawType, objects);
        } else {
            return typeFactory.constructType(
                    rawType
            );
        }
    }
154299
public Reference createDefinitionReference(String bindingName, String type, Map<String, Object> properties) throws InjectionException {
        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();
        if (isTraceOn && tc.isEntryEnabled()) {
            Map<String, Object> traceProps = properties;
            if (traceProps.containsKey("password")) {
                traceProps = new HashMap<String, Object>(properties);
                traceProps.put("password", "********");
            }

            Tr.entry(tc, "createDefinitionReference: bindingName=" + bindingName + ", type=" + type, traceProps);
        }

        Reference ref;
        try {
            InternalInjectionEngine injectionEngine = (InternalInjectionEngine) InjectionEngineAccessor.getInstance();
            ref = injectionEngine.createDefinitionReference(ivNameSpaceConfig, ivInjectionScope, getJndiName(), bindingName, type, properties);
        } catch (Exception ex) {
            if (isTraceOn && tc.isEntryEnabled())
                Tr.exit(tc, "createDefinitionReference", ex);
            throw new InjectionException(ex);
        }

        if (isTraceOn && tc.isEntryEnabled())
            Tr.exit(tc, "createDefinitionReference", ref);
        return ref;
    }
1096848
protected Constructor getConstructor(Class type) {
        try {
            return type.getConstructor(String.class);
        }
        catch (NoSuchMethodException e) {
            throw new RuntimeException(
                    "Unable to find a constructor that accepts"
                    + " a single String argument in the "
                    + type.getName() + " class.", e);
        }
    }
1046403
@Override
    public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
        for (Class<?> t = type.getRawType(); (t != Object.class) && (t.getSuperclass() != null); t = t.getSuperclass()) {
            for (Method m : t.getDeclaredMethods()) {
                if (m.isAnnotationPresent(PostConstruct.class)) {
                    m.setAccessible(true);
                    TypeAdapter<T> delegate = gson.getDelegateAdapter(this, type);
                    return new PostConstructAdapter<T>(delegate, m);
                }
            }
        }
        return null;
    }
895081
private static @NotNull Optional<List<Type>> findTargetTypes(@NotNull Constructor<?> ctor, @NotNull List<String> resultSetColumns) {
        List<Type> constructorParameterTypes = asList(ctor.getGenericParameterTypes());

        int constructorParameterCount = constructorParameterTypes.size();

        if (constructorParameterCount > resultSetColumns.size()) {
            // We don't have enough columns in ResultSet to instantiate this constructor, discard it.
            return Optional.empty();

        } else if (constructorParameterCount == resultSetColumns.size()) {
            // We have exactly enough column in ResultSet. Use the constructor as it is.
            return Optional.of(constructorParameterTypes);

        } else {
            // Get the types of remaining properties
            ArrayList<Type> result = new ArrayList<>(resultSetColumns.size());
            result.addAll(constructorParameterTypes);

            List<String> propertyNames = resultSetColumns.subList(constructorParameterCount, resultSetColumns.size());
            for (String name : propertyNames) {
                Type type = PropertyAccessor.findPropertyType(ctor.getDeclaringClass(), name).orElse(null);
                if (type != null)
                    result.add(type);
                else
                    return Optional.empty();
            }

            return Optional.of(result);
        }
    }
1035580
public static <T> OptionalBinder<T> newOptionalBinder(Binder binder, Class<T> type) {
    return new OptionalBinder<T>(
        newRealOptionalBinder(binder.skipSources(OptionalBinder.class), Key.get(type)));
  }
431856
public <E> Optional<E> create(Class<E> type) {
    List<Constructor<?>> constructors = reflect().constructors()
        .filter(declared(Modifier.PUBLIC))
        .from(type);
    Optional created;
    for (Constructor<?> constructor : constructors) {
      created = tryCreate(constructor);
      if (created.isPresent()) {
        return created;
      }
    }
    return Optional.empty();
  }
411570
private static <T, G extends T> void generateConstructorAndFields(DexMaker dexMaker,
                                                                      TypeId<G> generatedType,
                                                                      TypeId<T> baseType) {
        final FieldId<G, Interceptor> interceptorField =
                generatedType.getField(INTERCEPTOR_TYPE, FIELD_NAME_INTERCEPTOR);
        dexMaker.declare(interceptorField, PRIVATE, null);

        final TypeId<?>[] types = classArrayToTypeArray(CONSTRUCTOR_ARG_TYPES);
        final MethodId<?, ?> constructor = generatedType.getConstructor(types);
        final Code constructorCode = dexMaker.declare(constructor, PUBLIC);

        final Local<?>[] params = new Local[types.length];
        for (int i = 0; i < params.length; ++i) {
            params[i] = constructorCode.getParameter(i, types[i]);
        }

        final MethodId<T, ?> superConstructor = baseType.getConstructor(types);
        final Local<G> thisRef = constructorCode.getThis(generatedType);
        constructorCode.invokeDirect(superConstructor, null, thisRef, params);
        constructorCode.returnVoid();
    }
991269
protected List<BindInfo> getBeanBinders(@NotNull Class<?> type) {
        List<BindInfo> bindings = beanInfoByClass.get(type);
        if (bindings != null) {
            return bindings;
        }
        bindings = new ArrayList<>();

        // check all public fields
        for (Field f : type.getFields()) {
            int modifiers = f.getModifiers();
            if (!isPublic(modifiers) || isStatic(modifiers) || isTransient(modifiers)) {
                continue; //ignore
            }
            DbBinder binder = findBinderByType(f.getType(), null);
            if (binder != null) {
                bindings.add(new BindInfo(f.getName(), binder, 0, f, null));
            }
        }

        // check all public get/is methods
        for (Method m : type.getMethods()) {
            int modifiers = m.getModifiers();
            String methodName = m.getName();
            if (!isPublic(modifiers) || isStatic(modifiers) || m.getParameterCount() != 0 || !(methodName.startsWith("get") || methodName.startsWith("is"))) {
                continue; //ignore
            }
            String suffix = methodName.startsWith("is") ? methodName.substring(2) : methodName.substring(3);
            String propertyName = Character.toLowerCase(suffix.charAt(0)) + suffix.substring(1);
            if (bindings.stream().filter(b -> b.mappedName.equals(propertyName)).findAny().orElse(null) != null) { // field has higher priority.
                continue;
            }
            DbBinder binder = findBinderByType(m.getReturnType(), null);
            if (binder != null) {
                bindings.add(new BindInfo(propertyName, binder, 0, null, m));
            }
        }
        beanInfoByClass.put(type, bindings);
        return bindings;
    }
882260
@Override
    public InjectionBinding<WebServiceRef> createOverrideInjectionBinding(Class<?> instanceClass, Member member,
                                                                          Resource resource, String jndiName) throws InjectionException {

        Class<?> typeClass = resource.type();

        if (member != null) {
            Class<?> inferredType = InjectionHelper.getTypeFromMember(member);
            if (typeClass.getName().equals(Object.class.getName())) { //default
                typeClass = inferredType;
//            } else {
//                if (!inferredType.isAssignableFrom(typeClass)) {
//                    Tr.error(tc, "error.service.ref.member.level.annotation.type.not.compatible",
//                             member.getName(), member.getDeclaringClass().getName(), typeClass.getName(), inferredType.getName());
//                    throw new InjectionException(Tr.formatMessage(tc, "error.service.ref.member.level.annotation.type.not.compatible",
//                                                                  member.getName(), member.getDeclaringClass().getName(), typeClass.getName(), inferredType.getName()));
//                }
            }
        }

        InjectionBinding<WebServiceRef> binding;

        //only service type injections are possible with the @Resource annotation
        if (Service.class.isAssignableFrom(typeClass)) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "The @Resource annotation found has type=" + typeClass.getName() + " and is refers to a JAX-WS service reference");
            }
            binding = WebServiceRefBindingBuilder.createWebServiceRefBindingFromResource(resource, ivNameSpaceConfig, typeClass, jndiName);
        } else {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "The @Resource annotation found did not refer to a web service reference type.");
            }
            binding = null;
        }

        return binding;
    }
1374862
private <T> Constructor<T> findFromStringConstructorByType(Class<T> cls) {
        try {
            return cls.getDeclaredConstructor(String.class);
        } catch (NoSuchMethodException ex) {
            try {
                return cls.getDeclaredConstructor(CharSequence.class);
            } catch (NoSuchMethodException ex2) {
                throw new IllegalArgumentException("Constructor not found", ex2);
            }
        }
    }
237585
private void addPojoField(final TypeSpec.Builder classBuilder,
                              final MethodSpec.Builder constructorBuilder,
                              final String fieldName,
                              final TypeName fieldClass) {
        classBuilder.addField(fieldClass, fieldName, Modifier.PRIVATE, Modifier.FINAL);
        addGetter(classBuilder, fieldName, fieldClass);
        addConstructorParameter(constructorBuilder, fieldName, fieldClass);
    }