Make stub arguments for a constructor.

@param constructorParamTypes types of constructor arguments, must not be
null
@return generated Object array contains stub values for the constructor,
must not be null
197837
private static Object[] makeStubForConstructor(final Class<?>[] constructorParamTypes) {
    if (constructorParamTypes.length == 0) {
      return EMPTY_OBJECT_ARRAY;
    }
    final Object[] result = new Object[constructorParamTypes.length];
    for (int i = 0; i < constructorParamTypes.length; i++) {
      final Class<?> arg = constructorParamTypes[i];
      final Object obj;
      if (arg.isArray()) {
        obj = null;
      } else {
        if (arg == byte.class) {
          obj = (byte) 0;
        } else if (arg == char.class) {
          obj = 'a';
        } else if (arg == short.class) {
          obj = (short) 0;
        } else if (arg == boolean.class) {
          obj = Boolean.FALSE;
        } else if (arg == int.class) {
          obj = 0;
        } else if (arg == long.class) {
          obj = 0L;
        } else if (arg == double.class) {
          obj = 0.0d;
        } else if (arg == float.class) {
          obj = 0.0f;
        } else {
          obj = null;
        }
      }
      result[i] = obj;
    }
    return result;
  }
161730
public static Object createInstanceByType(Class<?> type, Object... args) throws Exception {
		if (args.length == 0) {
			Constructor<?> constructor = type.getConstructor();
			return constructor.newInstance();
		} else {
			throw new UnsupportedException(null, "NOT_SUPPORTED", "Constructors with parameters are not supported");
		}
	}
1286120
private function getConstructorArgs($reflectionClass, int $constructorArgsCount = 0)
    {
        if ($reflectionClass->hasMethod('__construct')) {
            $constructor = $reflectionClass->getConstructor();
            $constructor->setAccessible(true);
            $constructorArgsCount = $constructor->getNumberOfParameters();

            return [$constructor, $constructorArgsCount];
        }
    }
423740
public static <T> T createInstance(Class<T> type, Object... parameters) {

    // get types for parameters
    Class<?>[] parameterTypes = new Class<?>[parameters.length];
    for (int i = 0; i < parameters.length; i++) {
      Object parameter = parameters[i];
      parameterTypes[i] = parameter.getClass();
    }

    try {
      // create instance
      Constructor<T> constructor = type.getConstructor(parameterTypes);
      return constructor.newInstance(parameters);

    } catch (Exception e) {
      throw new ModelException("Exception while creating an instance of type "+type, e);
    }
  }
989271
@Deprecated
    private T build(Constructor<T> constructor, Object[] args) {
        try {
            return constructor.newInstance(args);

        } catch (IllegalArgumentException | IllegalAccessException | InstantiationException ex) {
            throw new IllegalArgumentException(
                    "Bean cannot be created: " + beanName() + " from " + Arrays.toString(args), ex);
        } catch (InvocationTargetException ex) {
            if (ex.getCause() instanceof RuntimeException) {
                throw (RuntimeException) ex.getCause();
            }
            throw new RuntimeException(ex);
        }
    }
390294
private boolean injectConstructorHasMatchingParams(TypeLiteral<?> type,
      Constructor<?> constructor, List<Key<?>> paramList, Errors errors) throws ErrorsException {
    List<TypeLiteral<?>> params = type.getParameterTypes(constructor);
    Annotation[][] paramAnnotations = constructor.getParameterAnnotations();
    int p = 0;
    for (TypeLiteral<?> param : params) {
      Key<?> paramKey = getKey(param, constructor, paramAnnotations[p++], errors);
      if (paramKey.getAnnotationType() == Assisted.class && !paramList.contains(paramKey)) {
        return false;
      }
    }

    return true;
  }
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);
        }
    }
189389
public String [] getParamTypeDescriptors() {
        return methodType().parameterList().stream()
                .map(BSHType::getTypeDescriptor).toArray(String[]::new);
    }
1093054
def encode_constructor_arguments(self, args):
        
        if self.constructor_data is None:
            raise ValueError(
                "The contract interface didn't have a constructor")

        return encode_abi(self.constructor_data['encode_types'], args)
1356023
public static Enum<?>[][] explodeArguments(TestConstructor constructor) {
    checkNotNull(constructor, "constructor");

    return explodeParameters(constructor.getVariationTypes(),
        constructor.getName() + " constructor");
  }
64319
@Requires({
    "roots != null",
    "diagnosticManager != null"
  })
  @Ensures({
    "result != null",
    "result.size() >= roots.size()",
    "result.size() <= 2 * roots.size()"
  })
  protected List<TypeModel> createTypes(Set<TypeElement> roots,
                                        DiagnosticManager diagnosticManager) {
    boolean errors = false;

    /*
     * Extract all type names that will be part of this compilation
     * task.
     */
    final HashSet<String> knownTypeNames = new HashSet<String>();
    for (TypeElement r : roots) {
      ElementScanner6<Void, Void> visitor =
          new ElementScanner6<Void, Void>() {
            @Override
            public Void visitType(TypeElement e, Void p) {
              knownTypeNames.add(e.getQualifiedName().toString());
              return super.visitType(e, p);
            }
          };
      r.accept(visitor, null);
    }
    /*
     * Mark annotations inherited from classes compiled in the same
     * task as weak so we don't generate stubs for them later on. This
     * prevents name clashes due to erasure.
     */
    ArrayList<TypeModel> undecoratedTypes =
        new ArrayList<TypeModel>(roots.size());
    for (TypeElement r : roots) {
      TypeModel type = factory.createType(r, diagnosticManager);
      ElementScanner annotator =
          new ElementScanner() {
            @Override
            public void visitContractAnnotation(
                ContractAnnotationModel annotation) {
              if (annotation.isVirtual()
                  && knownTypeNames.contains(
                      annotation.getOwner().getQualifiedName())) {
                annotation.setWeakVirtual(true);
              }
            }
          };
      type.accept(annotator);
      undecoratedTypes.add(type);
    }
    /*
     * Decorate the type models with contract methods and create
     * helper types.
     */
    ArrayList<TypeModel> types =
        new ArrayList<TypeModel>(undecoratedTypes.size());
    for (TypeModel type : undecoratedTypes) {
      ClassContractCreator creator =
          new ClassContractCreator(diagnosticManager);
      type.accept(creator);
      TypeModel helper = creator.getHelperType();
      types.add(type);
      if (helper != null) {
        types.add(helper);
      }
    }

    return types;
  }
473236
public ParamValueType<FilterType<T>> getOrCreateInitParam()
   {
      List<Node> nodeList = childNode.get("init-param");
      if (nodeList != null &&  nodeList.size() > 0)
      {
         return new ParamValueTypeImpl<FilterType<T>>(this, "init-param", childNode, nodeList.get(0));
      }
      return createInitParam();
   }
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);
        }
    }
66716
private static <T> T createInstance(Constructor<T> constructor, Object... arguments) throws Exception {
        if (constructor == null) {
            throw new IllegalArgumentException("Constructor cannot be null");
        }
        constructor.setAccessible(true);

        T createdObject = null;
        try {
            if (constructor.isVarArgs()) {
                Class<?>[] parameterTypes = constructor.getParameterTypes();
                final int varArgsIndex = parameterTypes.length - 1;
                Class<?> varArgsType = parameterTypes[varArgsIndex].getComponentType();
                Object varArgsArrayInstance = createAndPopulateVarArgsArray(varArgsType, varArgsIndex, arguments);
                Object[] completeArgumentList = new Object[parameterTypes.length];
                System.arraycopy(arguments, 0, completeArgumentList, 0, varArgsIndex);
                completeArgumentList[completeArgumentList.length - 1] = varArgsArrayInstance;
                createdObject = constructor.newInstance(completeArgumentList);
            } else {
                createdObject = constructor.newInstance(arguments);
            }
        } catch (InvocationTargetException e) {
            Throwable cause = e.getCause();
            if (cause instanceof Exception) {
                throw (Exception) cause;
            } else if (cause instanceof Error) {
                throw (Error) cause;
            }
        }
        return createdObject;
    }
179317
FunctionTypeBuilder inferParameterTypes(@Nullable Node paramsParent, @Nullable JSDocInfo info) {
    if (paramsParent == null) {
      if (info == null) {
        return this;
      } else {
        return inferParameterTypes(info);
      }
    }

    // arguments
    Node oldParameterType = null;
    if (parametersNode != null) {
      oldParameterType = parametersNode.getFirstChild();
    }

    FunctionParamBuilder builder = new FunctionParamBuilder(typeRegistry);
    boolean warnedAboutArgList = false;
    Set<String> allJsDocParams =
        (info == null) ? new HashSet<>() : new HashSet<>(info.getParameterNames());
    boolean isVarArgs = false;
    int paramIndex = 0;
    for (Node param : paramsParent.children()) {
      boolean isOptionalParam = false;

      if (param.isRest()) {
        isVarArgs = true;
        param = param.getOnlyChild();
      } else if (param.isDefaultValue()) {
        // The first child is the actual positional parameter
        param = checkNotNull(param.getFirstChild(), param);
        isOptionalParam = true;
      } else {
        isVarArgs = isVarArgsParameterByConvention(param);
        isOptionalParam = isOptionalParameterByConvention(param);
      }

      String paramName = null;
      if (param.isName()) {
        paramName = param.getString();
      } else {
        checkState(param.isDestructuringPattern());
        // Right now, the only way to match a JSDoc param to a destructuring parameter is through
        // ordering the JSDoc parameters. So the third formal parameter will correspond to the
        // third JSDoc parameter.
        if (info != null) {
          paramName = info.getParameterNameAt(paramIndex);
        }
      }
      allJsDocParams.remove(paramName);

      // type from JSDocInfo
      JSType parameterType = null;
      if (info != null && info.hasParameterType(paramName)) {
        JSTypeExpression parameterTypeExpression = info.getParameterType(paramName);
        parameterType = parameterTypeExpression.evaluate(templateScope, typeRegistry);
        isOptionalParam = isOptionalParam || parameterTypeExpression.isOptionalArg();
        isVarArgs = isVarArgs || parameterTypeExpression.isVarArgs();
      } else if (param.getJSDocInfo() != null && param.getJSDocInfo().hasType()) {
        JSTypeExpression parameterTypeExpression = param.getJSDocInfo().getType();
        parameterType = parameterTypeExpression.evaluate(templateScope, typeRegistry);
        isOptionalParam = parameterTypeExpression.isOptionalArg();
        isVarArgs = parameterTypeExpression.isVarArgs();
      } else if (oldParameterType != null &&
          oldParameterType.getJSType() != null) {
        parameterType = oldParameterType.getJSType();
        isOptionalParam = oldParameterType.isOptionalArg();
        isVarArgs = oldParameterType.isVarArgs();
      } else {
        parameterType = typeRegistry.getNativeType(UNKNOWN_TYPE);
      }

      warnedAboutArgList |= addParameter(
          builder, parameterType, warnedAboutArgList,
          isOptionalParam,
          isVarArgs);

      if (oldParameterType != null) {
        oldParameterType = oldParameterType.getNext();
      }
      paramIndex++;
    }
    // Copy over any old parameters that aren't in the param list.
    if (!isVarArgs) {
      while (oldParameterType != null && !isVarArgs) {
        builder.newParameterFromNode(oldParameterType);
        oldParameterType = oldParameterType.getNext();
      }
    }

    for (String inexistentName : allJsDocParams) {
      reportWarning(INEXISTENT_PARAM, inexistentName, formatFnName());
    }

    parametersNode = builder.build();
    return this;
  }
117503
public static Class<?>[] getConstructorParameters(Class<?> type, Class<?>[] givenTypes) {
        next_constructor:
        for (Constructor<?> constructor : type.getConstructors()) {
            int matches = 0;
            Class<?>[] parameters = constructor.getParameterTypes();
            Iterator<Class<?>> parameterIterator = Arrays
                    .asList(parameters)
                    .iterator();
            if (!isEmpty(givenTypes)
                    && !isEmpty(parameters)) {
                Class<?> parameter = null;
                for (Class<?> argument : givenTypes) {

                    if (parameterIterator.hasNext()) {
                        parameter = parameterIterator.next();
                        if (!compatible(parameter, argument)) {
                            continue next_constructor;
                        }
                        matches++;
                    } else if (constructor.isVarArgs()) {
                        if (!compatible(parameter, argument)) {
                            continue next_constructor;
                        }
                    } else {
                        continue next_constructor; //default
                    }
                }
                if (matches == parameters.length) {
                    return parameters;
                }
            } else if (isEmpty(givenTypes)
                    && isEmpty(parameters)) {
                return NO_ARGS;
            }
        }
        throw new ExpressionException("No constructor found for " + type.toString()
                + " with parameters: " + Arrays.deepToString(givenTypes));
    }
397606
public InitParamType<FilterType<T>> getOrCreateInitParam()
   {
      List<Node> nodeList = childNode.get("init-param");
      if (nodeList != null &&  nodeList.size() > 0)
      {
         return new InitParamTypeImpl<FilterType<T>>(this, "init-param", childNode, nodeList.get(0));
      }
      return createInitParam();
   }