Find a constructor for a static class.

@param klazz a class to find a constructor, must not be null
@return found constructor to be used to make an instance
960485
private static Constructor<?> findConstructorForStaticClass(final Class<?> klazz) {
    final Constructor<?>[] constructors = klazz.getDeclaredConstructors();
    if (constructors.length == 1) {
      return constructors[0];
    }
    for (final Constructor<?> c : constructors) {
      final Class<?>[] params = c.getParameterTypes();
      if (params.length == 0) {
        return c;
      }
    }
    return constructors[0];
  }
946121
public static <T> Constructor<T> getConstructor(Class<T> cls, Class... params) {
        try {
            return cls.getConstructor(params);
        } catch (Exception e) {
            throw new ClientException(e);
        }
    }
515317
private static Constructor<?> getConstructor(final Class<?> genericClass, final Class<?>[] constructorParameterTypes) {
        Constructor<?> constructor = null;
        try {
            constructor = genericClass.getConstructor(constructorParameterTypes);
        } catch (final NoSuchMethodException e) {
            // Return the first constructor as a workaround
            constructor = genericClass.getConstructors()[0];
        } catch (final SecurityException e) {
            LOGGER.log(NO_CONSTRUCTOR, e);
            throw e; // Pop up the exception to let it managed by the caller method
        }
        return constructor;
    }
707837
private static Object newInstance(Class<?> clazz) {
        Object instance = null;
        try {
            instance = clazz.newInstance();
        } catch (Exception ex) {
            log.error("Error loading class: {}", clazz.getName(), ex);
        }
        return instance;
    }
295000
protected static IJavaClassConstructor findConstructor( IJavaClassInfo cls, int numArgs ) {
    IJavaClassConstructor match = null;
    for (IJavaClassConstructor cons : cls.getDeclaredConstructors()) {
      if (cons.getParameterTypes().length == numArgs) {
        if (match != null) {
          throw new IllegalArgumentException("The call to create a new " + cls + " with " + numArgs + " arguments is ambiguous");
        } else {
          match = cons;
        }
      }
    }

    if (match == null) {
      throw new IllegalArgumentException("No constructor with " + numArgs + " arguments found on class " + cls);
    }

    return match;
  }
1297573
public static Builder forClass(Class clazz) {
        if (clazz == null) {
            throw new IllegalArgumentException("class can not be null");
        }
        return new Builder(Collections.singletonList(clazz));
    }
1364896
public static ClassLoader getClassLoader(Class clazz){
        ClassLoader classLoader = clazz.getClassLoader();
        return classLoader==null ? ClassLoader.getSystemClassLoader() : classLoader;
    }
835464
public static Constructor<?>[] getAllConstructorsOfClass(final Class<?> clazz, boolean accessible) {
        if (clazz == null) {
            return null;
        }
        Constructor<?>[] constructors = clazz.getDeclaredConstructors();
        if (constructors != null && constructors.length > 0) {
            AccessibleObject.setAccessible(constructors, accessible);
        }
        return constructors;
    }
250645
public static URL findClassBase(Class clazz)
   {
      String resource = clazz.getName().replace('.', '/') + ".class";
      return findResourceBase(resource, clazz.getClassLoader());
   }
1017896
public static <T> Clazz<T> Clazz( Class<T> clazz )
	{
		return impl.Clazz( clazz );
	}
816691
public ASTConstructor getConstructor(Constructor constructor, boolean isEnum, boolean isInnerClass) {
        ASTAccessModifier modifier = ASTAccessModifier.getModifier(constructor.getModifiers());

        Annotation[][] parameterAnnotations = constructor.getParameterAnnotations();

        if(constructor.getDeclaringClass().getEnclosingClass() != null && !Modifier.isStatic(constructor.getDeclaringClass().getModifiers())){
            // An inner class constructor contains a hidden non-annotated prameter
            Annotation[][] paddedParameterAnnotations = new Annotation[parameterAnnotations.length + 1][];

            paddedParameterAnnotations[0] = new Annotation[0];
            System.arraycopy(parameterAnnotations, 0, paddedParameterAnnotations, 1, parameterAnnotations.length);

            parameterAnnotations = paddedParameterAnnotations;
        }

        ImmutableList<ASTParameter> constructorParameters = getParameters(constructor.getParameterTypes(), constructor.getGenericParameterTypes(), parameterAnnotations);
        if(isEnum) {
            constructorParameters = constructorParameters.subList(2, constructorParameters.size());
        }
        if(isInnerClass){
            constructorParameters = constructorParameters.subList(1, constructorParameters.size());
        }
        ImmutableSet<ASTType> throwsTypes = getTypes(constructor.getExceptionTypes());

        return new ASTClassConstructor(getAnnotations(constructor), constructor, constructorParameters, modifier, throwsTypes);
    }
1170971
public static <T> T callConstructor(Class<T> klass) {
        return callConstructor(klass, new Class<?>[0], new Object[0]);
    }
1168731
public Constructor<?> getEnterpriseBeanClassConstructor() {
        Constructor<?> constructor = ivEnterpriseBeanClassConstructor;
        if (constructor == null) {
            constructor = ivEnterpriseBeanFactory.getConstructor();
        }
        return constructor;
    }
263974
public static Constructor<?> getConstructor(final Class<?> clazz,
        final Class<?>... argumentTypes) throws NoSuchMethodException {
        try {
            return AccessController
                .doPrivileged(new PrivilegedExceptionAction<Constructor<?>>() {
                    public Constructor<?> run()
                        throws NoSuchMethodException {
                        return clazz.getConstructor(argumentTypes);
                    }
                });
        }
        // Unwrap
        catch (final PrivilegedActionException pae) {
            final Throwable t = pae.getCause();
            // Rethrow
            if (t instanceof NoSuchMethodException) {
                throw (NoSuchMethodException) t;
            } else {
                // No other checked Exception thrown by Class.getConstructor
                try {
                    throw (RuntimeException) t;
                }
                // Just in case we've really messed up
                catch (final ClassCastException cce) {
                    throw new RuntimeException(
                        "Obtained unchecked Exception; this code should never be reached",
                        t);
                }
            }
        }
    }
718249
public static Object instantiateObject(Class<?> clazz) {
    try {
      Constructor<?> constructor = clazz.getConstructor();
      return constructor.newInstance();
    } catch (Exception exp) {
      throw new EntityManagerException(exp);
    }

  }
437303
public static ConstructorNode getDefaultConstructor(ClassNode classNode) {
        for (ConstructorNode cons : classNode.getDeclaredConstructors()) {
            if (cons.getParameters().length == 0) {
                return cons;
            }
        }
        return null;
    }
1133911
public static Constructor<?> getEmptyConstructor(Class<?> clazz) {
        Constructor<?> c = clazz.getDeclaredConstructors()[0];
        for (int i = 0; i < clazz.getDeclaredConstructors().length; i++) {
            if (clazz.getDeclaredConstructors()[i].getParameterTypes().length < 1) {
                c = clazz.getDeclaredConstructors()[i];
                break;
            }
        }

        return c;
    }