Creates a class with a public constructor whose parameter types match
the given source classes. Another constructor is also created that
accepts an InstanceFactory.
766156
private static synchronized Class<?> getMergedClass(ClassInjector injector,
                                                        ClassEntry[] classEntries,
                                                        Class<?>[] interfaces,
                                                        int observerMode)
        throws IllegalArgumentException
    {
        Map<MultiKey, String> classListMap = cMergedMap.get(injector);
        if (classListMap == null) {
            classListMap = new HashMap<MultiKey, String>(7);
            cMergedMap.put(injector, classListMap);
        }

        MultiKey key = generateKey(classEntries);
        String mergedName = classListMap.get(key);
        if (mergedName != null) {
            try {
                return injector.loadClass(mergedName);
            }
            catch (ClassNotFoundException e) {
            }
        }

        ClassFile cf;
        try {
            cf = buildClassFile(injector, null, classEntries, interfaces, 
                                observerMode);
        }
        catch (IllegalArgumentException e) {
            e.fillInStackTrace();
            throw e;
        }

        try {
            OutputStream stream = injector.getStream(cf.getClassName());
            cf.writeTo(stream);
            stream.close();
        }
        catch (Throwable e) {
            String output = outputClassToFile(cf);
            throw new RuntimeException(
                "Error generating merged class, contents saved to: " + output, 
                e
            );
        }

        if (DEBUG) {
            String output = outputClassToFile(cf);
            System.out.println("Saved merged class to: " + output);
        }
        
        Class<?> merged;
        try {
            merged = injector.loadClass(cf.getClassName());
        }
        catch (ClassNotFoundException e) {
            throw new InternalError(e.toString());
        }

        classListMap.put(key, merged.getName());
        return merged;
    }
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));
    }
428766
public <S, D> TypeMap<S, D> create(S source, Class<S> sourceType, Class<D> destinationType,
      String typeMapName, InheritingConfiguration configuration, MappingEngineImpl engine) {
    synchronized (lock) {
      TypeMapImpl<S, D> typeMap = new TypeMapImpl<S, D>(sourceType, destinationType, typeMapName,
          configuration, engine);
      if (configuration.isImplicitMappingEnabled()
          && Types.mightContainsProperties(typeMap.getSourceType())
          && Types.mightContainsProperties(typeMap.getDestinationType()))
        ImplicitMappingBuilder.build(source, typeMap, config.typeMapStore, config.converterStore);
      typeMaps.put(TypePair.of(sourceType, destinationType, typeMapName), typeMap);
      return typeMap;
    }
  }
572628
public static <T> T newInstance(Constructor<T> constructor, Object... args) throws IllegalAccessException, InvocationTargetException, InstantiationException {
        if (constructor.isVarArgs()) {
            args = fixVarArgs(constructor.getParameterTypes(), args);
        }
        return constructor.newInstance(args);
    }
1252179
private static <T> Constructor<T> lookupConstructor(Class<T> clazz, Object[] pArguments) throws NoSuchMethodException {
        Class[] argTypes = extractArgumentTypes(pArguments);
        return clazz.getConstructor(argTypes);
    }
557108
public static ConstructorBuilder getInstance(Context context,
            TypeElement typeElement, ConstructorWriter writer) {
        return new ConstructorBuilder(context, typeElement, writer);
    }
1039249
def parameter_constructor(cls, loader, node):
        
        value = loader.construct_scalar(node)

        if isinstance(value, str):
            if '=' in value:
                (varname, varvalue) = Parser.parse_equality(value)
                return cls(varname, varvalue)
            else:
                return cls(value)
        else:
            return cls(value)
1276479
public static <T> T newInstance(Constructor<T> constructor, Object... args) {
        try {
            return constructor.newInstance(args);
        } catch (Exception e) {
            throw new ClientException(e);
        }
    }
946121
public static <T> Constructor<T> getConstructor(Class<T> cls, Class... params) {
        try {
            return cls.getConstructor(params);
        } catch (Exception e) {
            throw new ClientException(e);
        }
    }
808926
private E createUsingConstructor() throws CheckedAnalysisException {
        Constructor<E> constructor;
        try {
            constructor = databaseClass.getConstructor(new Class[0]);
        } catch (NoSuchMethodException e) {
            return null;
        }

        try {
            return constructor.newInstance(new Object[0]);
        } catch (InstantiationException e) {
            throw new CheckedAnalysisException("Could not create " + databaseClass.getName(), e);
        } catch (IllegalAccessException e) {
            throw new CheckedAnalysisException("Could not create " + databaseClass.getName(), e);
        } catch (InvocationTargetException e) {
            throw new CheckedAnalysisException("Could not create " + databaseClass.getName(), e);
        }
    }
738110
public static Constructor findConstructor(Class<?> type, Object[] args) {
        outer:
        for (Constructor constructor : type.getConstructors()) {
            Class<?>[] paramTypes = constructor.getParameterTypes();
            if (paramTypes.length != args.length) continue;
            for (int i = 0; i < args.length; i++) {
                Object arg = args[i];
                if (arg != null && !paramTypes[i].isAssignableFrom(arg.getClass()) && !isBoxedType(paramTypes[i], arg.getClass())) continue outer;
                if (arg == null && paramTypes[i].isPrimitive()) continue outer;
            }
            return constructor;
        }
        throw new GrammarException("No constructor found for %s and the given %s arguments", type, args.length);
    }
501980
public T newInstanceUsingCoercion(String... args) throws Throwable
    {
        Constructor<? extends T> constructor = ClassUtils.findPossibleConstructor(klass, args);
        Class[] types = constructor.getParameterTypes();
        return newInstance( TypeConversion.convert( args, types ) );
    }
73556
private static Object newInstance(String className,
                                      ClassLoader classLoader,
                                      Properties properties)
    {
        try {
            Class<?> spiClass;
            if (classLoader == null) {
                spiClass = Class.forName(className);
            } else {
                spiClass = classLoader.loadClass(className);
            }
            if (properties != null) {
                Constructor constr = null;
                try {
                    constr = spiClass.getConstructor(Properties.class);
                } catch (Exception ex) {
                }
                if (constr != null) {
                    return constr.newInstance(properties);
                }
            }
            return spiClass.newInstance();
        } catch (ClassNotFoundException x) {
            throw new ELException(
                "Provider " + className + " not found", x);
        } catch (Exception x) {
            throw new ELException(
                "Provider " + className + " could not be instantiated: " + x,
                x);
        }
    }
1005322
private static Constructor<?> createImpl(Class<?> cl,
                                           ClassLoader loader)
  {
    /**
    if (! Modifier.isAbstract(cl.getModifiers())) {
      throw new IllegalArgumentException();
    }
    */
    
    ClassGeneratorVault<?> generator
      = new ClassGeneratorVault<>(cl, loader);
    
    Class<?> proxyClass = generator.generate();
    
    return proxyClass.getConstructors()[0];
  }
52271
function construct (constructor, args) {
  function Factory () {
    return constructor.apply(this, args);
  }

  Factory.prototype = constructor.prototype;

  return new Factory();
}
601455
static <T> Pair<Boolean, T> constructViaConstructor(Class<T> type, String fromValue) {

		Constructor[] allConstructors = type.getDeclaredConstructors();
		for (Constructor ctor : allConstructors) {

			Class<?>[] pType = ctor.getParameterTypes();
			if (pType.length == 1) { // ok ... match ... might be possible to use

				try {

					for (Class primitive : SIMPLE_TYPE) {

						if (pType[0].isAssignableFrom(primitive)) {

							Object value = stringToPrimitiveType(fromValue, primitive);
							return new Pair(true, ctor.newInstance(value));
						}
					}
				}
				catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
					//continue; // try next one ... if any
					log.warn("Failed constructing: " + ctor, e);
				}
			}
		}

		return new Pair<>(false, null);
	}
1226900
private static MessageBuffer newInstance(Constructor<?> constructor, Object... args)
    {
        try {
            // We need to use reflection to create MessageBuffer instances in order to prevent TypeProfile generation for getInt method. TypeProfile will be
            // generated to resolve one of the method references when two or more classes overrides the method.
            return (MessageBuffer) constructor.newInstance(args);
        }
        catch (InstantiationException e) {
            // should never happen
            throw new IllegalStateException(e);
        }
        catch (IllegalAccessException e) {
            // should never happen unless security manager restricts this reflection
            throw new IllegalStateException(e);
        }
        catch (InvocationTargetException e) {
            if (e.getCause() instanceof RuntimeException) {
                // underlying constructor may throw RuntimeException
                throw (RuntimeException) e.getCause();
            }
            else if (e.getCause() instanceof Error) {
                throw (Error) e.getCause();
            }
            // should never happen
            throw new IllegalStateException(e.getCause());
        }
    }