本文整理了Java中java.lang.reflect.Constructor.getParameters()
方法的一些代码示例,展示了Constructor.getParameters()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Constructor.getParameters()
方法的具体详情如下:
包路径:java.lang.reflect.Constructor
类名称:Constructor
方法名:getParameters
暂无
代码示例来源:origin: spring-projects/spring-framework
@Override
@Nullable
public String[] getParameterNames(Constructor<?> ctor) {
return getParameterNames(ctor.getParameters());
}
代码示例来源:origin: org.springframework/spring-core
@Override
@Nullable
public String[] getParameterNames(Constructor<?> ctor) {
return getParameterNames(ctor.getParameters());
}
代码示例来源:origin: lettuce-io/lettuce-core
@Override
public String[] getParameterNames(Constructor<?> ctor) {
Parameter[] parameters = ctor.getParameters();
String[] parameterNames = new String[parameters.length];
for (int i = 0; i < parameters.length; i++) {
Parameter param = parameters[i];
if (!param.isNamePresent()) {
return null;
}
parameterNames[i] = param.getName();
}
return parameterNames;
}
代码示例来源:origin: fabioCollini/DaggerMock
public Object instantiateModule(Class<?> moduleClass) {
try {
Constructor<?>[] constructors = moduleClass.getConstructors();
if (constructors.length == 0) {
return moduleClass.newInstance();
} else {
// instantiate the module passing null or a test field to constructor
Parameter[] parameters = constructors[0].getParameters();
Object[] args = new Object[parameters.length];
for (int i = 0; i < parameters.length; i++) {
Parameter parameter = parameters[i];
Class<?> type = parameter.getType();
args[i] = getValueOfClass(type);
}
return constructors[0].newInstance(args);
}
} catch (Exception e) {
throw new RuntimeException("Error instantiating module " + moduleClass, e);
}
}
}
代码示例来源:origin: oracle/helidon
static <T> Optional<FactoryAccessor<T>> findConstructorWithParameters(Class<T> type) {
AtomicReference<Constructor<?>> foundConstructor = new AtomicReference<>();
for (Constructor<?> constructor : type.getConstructors()) {
if (checkConstructor(constructor, true)) {
if (foundConstructor.get() != null) {
LOGGER.log(Level.WARNING,
() -> "Class " + type.getName() + " contains more than one constructor with parameters."
+ " Any will be used to initialize the type.");
return Optional.empty();
}
foundConstructor.set(constructor);
}
}
if (foundConstructor.get() == null) {
return Optional.empty();
} else {
return findConstructor(type, foundConstructor.get().getParameterTypes())
.map(handle -> new FactoryAccessor<>(type,
handle,
foundConstructor.get().getParameters()));
}
}
代码示例来源:origin: jenkinsci/configuration-as-code-plugin
@Override
public Set<Attribute<T,?>> describe() {
final Set<Attribute<T,?>> attributes = super.describe();
final Constructor constructor = getDataBoundConstructor(target);
if (constructor != null) {
final Parameter[] parameters = constructor.getParameters();
final String[] names = ClassDescriptor.loadParameterNames(constructor);
for (int i = 0; i < parameters.length; i++) {
final Parameter p = parameters[i];
final Attribute a = createAttribute(names[i], TypePair.of(p));
if (a == null) continue;
attributes.add(a);
}
}
return attributes;
}
代码示例来源:origin: gchq/Gaffer
for (final Parameter parameter : creator.getParameters()) {
final JsonProperty anno = parameter.getAnnotation(JsonProperty.class);
if (null != anno && propName.equals(anno.value())) {
代码示例来源:origin: jenkinsci/configuration-as-code-plugin
private T tryConstructor(Constructor<T> constructor, Mapping config, ConfigurationContext context) throws ConfiguratorException {
final Parameter[] parameters = constructor.getParameters();
final String[] names = ClassDescriptor.loadParameterNames(constructor);
Object[] args = new Object[names.length];
代码示例来源:origin: jenkinsci/configuration-as-code-plugin
final Parameter[] parameters = constructor.getParameters();
final String[] names = ClassDescriptor.loadParameterNames(constructor);
final Attribute[] attributes = new Attribute[parameters.length];
代码示例来源:origin: jdbi/jdbi
@Test
public void getQualifiers() throws Exception {
assertThat(foo(1))
.isEqualTo(foo(1))
.isNotEqualTo(foo(2));
assertThat(Qualifiers.getQualifiers(getClass().getDeclaredField("qualifiedField")))
.containsExactly(foo(1));
assertThat(Qualifiers.getQualifiers(getClass().getDeclaredMethod("qualifiedMethod")))
.containsExactly(foo(2));
assertThat(Qualifiers.getQualifiers(getClass().getDeclaredMethod("qualifiedParameter", String.class).getParameters()[0]))
.containsExactly(foo(3));
assertThat(Qualifiers.getQualifiers(QualifiedClass.class))
.containsExactly(foo(4));
assertThat(Qualifiers.getQualifiers(QualifiedClass.class.getDeclaredConstructor(String.class).getParameters()[0]))
.containsExactly(foo(5));
assertThat(Qualifiers.getQualifiers(getClass().getDeclaredField("twoQualifiers")))
.containsExactlyInAnyOrder(foo(6), bar("six"));
}
代码示例来源:origin: immutables/immutables
@Test
public void passAnnotations() throws Exception {
check(ImmutableValForPass.class.getAnnotation(A1.class)).notNull();
check(ImmutableValForPass.class.getAnnotation(A2.class)).notNull();
check(ImmutableValForPass.class.getAnnotation(B1.class)).isNull();
Parameter parameter = ImmutableValForPass.class.getConstructor(int.class).getParameters()[0];
check(parameter.getAnnotation(A1.class)).notNull();
check(parameter.getAnnotation(A2.class)).notNull();
}
代码示例来源:origin: pholser/junit-quickcheck
/**
* Uses the given constructor to generate values of the declaring type.
*
* @param ctor the constructor to reflect on to generate constructor
* parameter values
*/
public Ctor(Constructor<T> ctor) {
super(ctor.getDeclaringClass());
this.ctor = ctor;
this.parameters = ctor.getParameters();
}
代码示例来源:origin: resteasy/Resteasy
public DefaultResourceConstructor(final ResourceClass resourceClass, final Constructor constructor)
{
this.resourceClass = resourceClass;
this.constructor = constructor;
if (constructor.getParameterTypes() != null)
{
this.params = new ConstructorParameter[constructor.getParameterTypes().length];
Parameter[] reflectionParameters = constructor.getParameters();
for (int i = 0; i < constructor.getParameterTypes().length; i++)
{
this.params[i] = new ConstructorParameter(this, reflectionParameters[i].getName(), constructor.getParameterTypes()[i], constructor.getGenericParameterTypes()[i], constructor.getParameterAnnotations()[i]);
}
}
}
代码示例来源:origin: resteasy/Resteasy
public ConstructorInjectorImpl(final Constructor constructor, final ResteasyProviderFactory factory)
{
this.constructor = constructor;
params = new ValueInjector[constructor.getParameterTypes().length];
Parameter[] reflectionParameters = constructor.getParameters();
for (int i = 0; i < constructor.getParameterTypes().length; i++)
{
Class type = constructor.getParameterTypes()[i];
Type genericType = constructor.getGenericParameterTypes()[i];
Annotation[] annotations = constructor.getParameterAnnotations()[i];
String name = reflectionParameters[i].getName();
params[i] = factory.getInjectorFactory().createParameterExtractor(constructor.getDeclaringClass(), constructor, name, type, genericType, annotations, factory);
}
}
代码示例来源:origin: spotify/heroic
private List<FieldSpec> buildFieldSpecs(
final Constructor<?> constructor, final FakeValueProvider valueProvider
) {
final Parameter[] parameters = constructor.getParameters();
代码示例来源:origin: net.serenity-bdd/serenity-core
private <T extends PageObject> boolean hasOuterClassConstructor(Class<T> pageObjectClass) {
return Arrays.stream(pageObjectClass.getConstructors())
.anyMatch( constructor -> constructor.getParameters().length == 1
&& constructor.getParameters()[0].getType() == pageObjectClass.getEnclosingClass() );
}
代码示例来源:origin: org.hibernate.validator/hibernate-validator
@Override
public List<String> getParameterNames(Constructor<?> constructor) {
return getParameterNames( constructor.getParameters() );
}
代码示例来源:origin: xap/xap
public static <T> String[] getParametersName(Constructor<T> ctor) {
List<String> parametersNames = new ArrayList<String>();
for (Parameter parameter : ctor.getParameters()) {
if (!parameter.isNamePresent()) {
throw new UnsupportedOperationException("Enable the Reflection API to retrieve formal parameter names by compiling the source of your POJO with the -parameters option of the javac compiler");
}
parametersNames.add(parameter.getName());
}
return parametersNames.toArray(new String[0]);
}
代码示例来源:origin: org.kantega.reststop/reststop-core
public Set<Class> findConsumedTypes(Class clazz) {
Constructor constructor = clazz.getConstructors()[0];
Set<Class> consumedType = new HashSet<>();
for (int i = 0; i < constructor.getParameterTypes().length; i++) {
Class<?> paramClass = constructor.getParameterTypes()[i];
if (constructor.getParameters()[i].isAnnotationPresent(Config.class)) {
continue;
}
consumedType.add(unwrapParameterType(constructor, paramClass, i));
}
return consumedType;
}
代码示例来源:origin: Enigmatis/graphql-java-annotations
public static <T> T newInstance(Class<T> clazz, Object parameter) {
if (parameter != null) {
for (Constructor<T> constructor : (Constructor<T>[]) clazz.getConstructors()) {
if (constructor.getParameterCount() == 1 && constructor.getParameters()[0].getType().isAssignableFrom(parameter.getClass())) {
return constructNewInstance(constructor, parameter);
}
}
}
return null;
}
}
内容来源于网络,如有侵权,请联系作者删除!