当前位置: 首页>>代码示例>>Java>>正文


Java Constructor.getParameters方法代码示例

本文整理汇总了Java中java.lang.reflect.Constructor.getParameters方法的典型用法代码示例。如果您正苦于以下问题:Java Constructor.getParameters方法的具体用法?Java Constructor.getParameters怎么用?Java Constructor.getParameters使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.reflect.Constructor的用法示例。


在下文中一共展示了Constructor.getParameters方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: collectMemberDataForConstructor

import java.lang.reflect.Constructor; //导入方法依赖的package包/类
private static void collectMemberDataForConstructor(final Class<?> clazz, final Map<String, MemberData> memberData) {
    Constructor<?> annotatedConstructor = null;
    for (final Constructor<?> constuctor : clazz.getDeclaredConstructors()) {
        if (isFullyAnnotated(constuctor)
                && (annotatedConstructor == null || annotatedConstructor.getParameterTypes().length < constuctor.getParameterTypes().length)) {
            annotatedConstructor = constuctor;
        }
    }

    if (annotatedConstructor != null) {
        final Parameter[] parameters = annotatedConstructor.getParameters();
        for (int parameterIndex = 0; parameterIndex < parameters.length; parameterIndex++) {
            final Parameter parameter = parameters[parameterIndex];
            final String name = getNameFromMemberAnnotation(parameter);
            LOGGER.debug("constructor member '{}' -> ", name, parameter);
            getMemberData(memberData, name).constructor = annotatedConstructor;
            getMemberData(memberData, name).constructorIndex = parameterIndex;
        }
    }
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:21,代码来源:Configuration.java

示例2: test

import java.lang.reflect.Constructor; //导入方法依赖的package包/类
private void test(Constructor<MyEntity> constructor,
                 Class<?>[] paramClasses) {
    final Parameter[] params = constructor.getParameters();

    for (int i = 0; i < params.length; i++) {
        final Parameter parameter = params[i];
        System.out.println(parameter.toString());

        if (!parameter.getType().equals(paramClasses[i])) {
            errors++;
            System.err.println("Expected type " + paramClasses[i] +
                               " but got " + parameter.getType());
        }

        System.out.println(parameter.getParameterizedType());
        System.out.println(parameter.getAnnotatedType());
    }

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:InnerClassToString.java

示例3: hasNamedParameterSupport

import java.lang.reflect.Constructor; //导入方法依赖的package包/类
static <T> boolean hasNamedParameterSupport(Class<T> classDefinition) {
    for (Constructor constructor : classDefinition.getConstructors()) {
        for (Parameter parameter : constructor.getParameters()) {
            return parameter.isNamePresent();
        }
    }
    return true;
}
 
开发者ID:opsbears,项目名称:owc-dic,代码行数:9,代码来源:NamedParameterSupportChecker.java

示例4: validateConstructorArgs

import java.lang.reflect.Constructor; //导入方法依赖的package包/类
protected void validateConstructorArgs(List<Throwable> errors) {
    final Constructor<?> constructor = getTestClass().getOnlyConstructor();
    final java.lang.reflect.Parameter[] parameters = constructor.getParameters();
    for (int i = 0; i < parameters.length; i++) {
        final String refName = Spockito.parameterRefNameOrNull(parameters[i]);
        if (refName != null && !tableRow.isValidRefName(refName)) {
            errors.add(new Exception("Invalid @Ref value or parameter name for argument " + i +
                    " of type " + parameters[i].getType() + " in the constructor: " + refName +
                    " does not reference a column of the table defined by @Unroll"));
        }
    }
}
 
开发者ID:tools4j,项目名称:spockito,代码行数:13,代码来源:SingleRowMultiTestRunner.java

示例5: classHasDefaultConstructor

import java.lang.reflect.Constructor; //导入方法依赖的package包/类
private Boolean classHasDefaultConstructor(){
    for(Constructor constructor : tClass.getConstructors()){
        if(constructor.getParameters().length == 0){
            return true;
        }
    }
    return false;
}
 
开发者ID:krix38,项目名称:flowly,代码行数:9,代码来源:Action.java

示例6: getClassDefaultConstructor

import java.lang.reflect.Constructor; //导入方法依赖的package包/类
private Constructor getClassDefaultConstructor(){
    Constructor returnConstructor = null;
    for(Constructor constructor : tClass.getConstructors()){
        if(constructor.getParameters().length == 0){
            returnConstructor = constructor;
        }
    }
    return returnConstructor;
}
 
开发者ID:krix38,项目名称:flowly,代码行数:10,代码来源:Action.java

示例7: check

import java.lang.reflect.Constructor; //导入方法依赖的package包/类
public void check() {
    final Class<?> cls = this.getClass();
    final Constructor<?> ctor = cls.getDeclaredConstructors()[0];
    final Parameter[] params = ctor.getParameters();
    final String[] names = names();
    final int[] modifiers = modifiers();
    final Class[] types = types();

    System.err.println("Testing class " + cls);

    if (params.length == names.length) {
        for (int i = 0; i < names.length; i++) {
            System.err.println("Testing parameter " + params[i].getName());
            if (!params[i].getName().equals(names[i]))
                error("Expected parameter name " + names[i] +
                      " got " + params[i].getName());
            if (params[i].getModifiers() != modifiers[i])
                error("Expected parameter modifiers " +
                      modifiers[i] + " got " +
                      params[i].getModifiers());
            if (!params[i].getType().equals(types[i]))
                error("Expected parameter type " + types[i] +
                      " got " + params[i].getType());
        }
    } else
        error("Expected " + names.length + " parameters");

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:CaptureTest.java

示例8: canInstantiate

import java.lang.reflect.Constructor; //导入方法依赖的package包/类
@Override
public boolean canInstantiate() {
    if (workingConstructors == null) {
        /*
          This MUST be the first instruction, because the empty array list takes care of a loop in the
          instantiation graph.

          Side effect: this will also (possibly) not work:

          ```
          class A {
            A(B b) {
            }

            A(C c) {
            }
          }

          class B {
            B(A a) {
            }
          }
          ```

          At this time, circular dependencies of any kind are not supported and it should not be possible to
          instantiate A _at all_.

          TODO fix cycle detection for all possibilities.
         */
        workingConstructors = new ArrayList<>();
        for (ConstructorDefinition<T> constructorDefinition : classDefinition.getConstructorDefinitions()) {
            Constructor<T> constructor       = constructorDefinition.getConstructor();
            boolean        usableConstructor = true;
            for (Parameter parameter : constructor.getParameters()) {
                if (constructorDefinition.getFixedParameterValues().containsKey(parameter)) {
                    continue;
                }
                if (namedParameterValues.containsKey(parameter.getName())) {
                    continue;
                }
                if (!factoryMap.containsKey(parameter.getType())) {
                    usableConstructor = false;
                    logger.info(
                        "Removing constructor for " +
                        classDefinition.getClassDefinition().getName() +
                        " because the constructor parameter " +
                        parameter.getName() +
                        " of type " +
                        parameter.getType().getName() +
                        " has no dependency injection definition."
                    );
                    break;
                }
                if (!factoryMap.get(parameter.getType()).canInstantiate()) {
                    usableConstructor = false;
                    logger.info(
                        "Removing constructor for " +
                        classDefinition.getClassDefinition().getName() +
                        " because the constructor parameter " +
                        parameter.getName() +
                        " of type " +
                        parameter.getType().getName() +
                        " has a dependency injection definition, but cannot instantiate."
                    );
                    break;
                }
            }
            if (usableConstructor) {
                workingConstructors.add(constructorDefinition);
            }
        }
    }
    if (workingConstructors.size() == 0) {
        logger.warn(
            this.classDefinition.getClassDefinition().getName() + " has no working constructors"
        );
    }
    return workingConstructors.size() > 0;
}
 
开发者ID:opsbears,项目名称:owc-dic,代码行数:80,代码来源:ConstructorObjectFactory.java

示例9: recursiveRegisterType

import java.lang.reflect.Constructor; //导入方法依赖的package包/类
private void recursiveRegisterType(Class<?> clazz) {

        if (registeredTypes.contains(clazz)) {

            return;
        }

        IocIgnore ignore = clazz.getAnnotation(IocIgnore.class);

        if (ignore != null) {

            return;
        }

        registeredTypes.add(clazz);

        // register these who implement the interface
        if (clazz.isInterface()) {

            Class<?>[] implementers = ClassesWalker.reflectImplementers(appClass, clazz);
            Arrays.stream(implementers).forEach(this::recursiveRegisterType);
            return;
        }

        try {
            // controller self
            Service inject = clazz.getAnnotation(Service.class);
            if (inject != null && inject.sington()) {
                registerType(clazz).singleInstance();
            } else {
                registerType(clazz).instancePerDependency();
            }

            // constructor parameters
            Constructor constructor = ConstructorWalker.findInjectConstructor(clazz);
            if (constructor != null) {

                Parameter[] paramNames = constructor.getParameters();
                Arrays.stream(paramNames).map(Parameter::getType).forEach(this::recursiveRegisterType);
                log.info("Ioc registered {} parameters for {} constructor", paramNames, clazz.getName());

                // class fields
                registerFields(clazz);
            }
        } catch (Exception e) {

            log.error(e.getMessage());
            e.printStackTrace();
        }
    }
 
开发者ID:thundernet8,项目名称:Razor,代码行数:51,代码来源:ContainerBuilder.java


注:本文中的java.lang.reflect.Constructor.getParameters方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。