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


Java Constructor.isAnnotationPresent方法代码示例

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


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

示例1: extractFromConstructors

import java.lang.reflect.Constructor; //导入方法依赖的package包/类
protected final void extractFromConstructors()
{
    if (builderType == null) {
        // struct class must have a valid constructor
        addConstructors(structType);
    }
    else {
        // builder class must have a valid constructor
        addConstructors(builderType);

        // builder class must have a build method annotated with @ThriftConstructor
        addBuilderMethods();

        // verify struct class does not have @ThriftConstructors
        for (Constructor<?> constructor : getStructClass().getConstructors()) {
            if (constructor.isAnnotationPresent(ThriftConstructor.class)) {
                metadataErrors.addWarning(
                        "Thrift class '%s' has a builder class, but constructor '%s' annotated with @ThriftConstructor",
                        getStructClass().getName(),
                        constructor);
            }
        }
    }
}
 
开发者ID:airlift,项目名称:drift,代码行数:25,代码来源:AbstractThriftMetadataBuilder.java

示例2: init

import java.lang.reflect.Constructor; //导入方法依赖的package包/类
public static void init(Object object) throws IllegalAccessException, InvocationTargetException, InstantiationException {
    if (object instanceof User) {
        Class clz = object.getClass();
        Constructor [] constructors = clz.getConstructors();
        for (Constructor constructor : constructors) {
            if (constructor.isAnnotationPresent(AConstructor.class)) {
                AConstructor aConstructor = (AConstructor) constructor.getAnnotation(AConstructor.class);
                String name = aConstructor.initName();
                int age = aConstructor.initAge();
                ((User) object).name = name;
                ((User) object).age = age;
            }
        }
    }else{
        throw new RuntimeException("无法向下转型到指定类");
    }

}
 
开发者ID:byhieg,项目名称:JavaTutorial,代码行数:19,代码来源:AConstructorProcess.java

示例3: parseConstructAnnotation

import java.lang.reflect.Constructor; //导入方法依赖的package包/类
/**
   * 简单打印出UserAnnotation 类中所使用到的构造方法注解
   * 该方法只打印了 构造方法 类型的注解
   * @throws ClassNotFoundException
   */
  @SuppressWarnings("rawtypes")
  public static void parseConstructAnnotation()  throws ClassNotFoundException{
Constructor[] constructors = UserAnnotation.class.getConstructors();
      for (Constructor constructor : constructors) {
          /* 
           * 判断构造方法中是否有指定注解类型的注解 
           */  
          boolean hasAnnotation = constructor.isAnnotationPresent(TestA.class);
          if(hasAnnotation){
               /* 
               * 根据注解类型返回方法的指定类型注解 
               */
              @SuppressWarnings("unchecked")
		TestA annotation = (TestA) constructor.getAnnotation(TestA.class);
              System.out.println("constructor = " + constructor.getName()  
                      + "   |   id = " + annotation.id() + "  |  description = "  
                      + annotation.name() + "  |   gid= "+annotation.gid());
          }
      }
  }
 
开发者ID:MinsxCloud,项目名称:minsx-java-example,代码行数:26,代码来源:ParseAnnotation.java

示例4: updateFactoryData

import java.lang.reflect.Constructor; //导入方法依赖的package包/类
private void updateFactoryData(Class<? extends T> clazz, DeveloperData data){
	this.data=data;
	variableSetters=new ArrayList<>();
	Constructor<? extends T> myCtor=null;
	Constructor<? extends T>[] ctors=(Constructor<? extends T>[]) clazz.getConstructors();
	for(Constructor<? extends T> constructor:ctors){
		if(constructor.isAnnotationPresent(ConstructorForDeveloper.class)){
			ctor=constructor;
			break;
		}
	}	
	if(ctor==null){
		AlertHandler.showError("Constructor not found");//Throw exception
		return;
	}
	parameters=ctor.getParameters();
	setterFactory=new VariableSetterFactory(data);
}
 
开发者ID:LtubSalad,项目名称:voogasalad-ltub,代码行数:19,代码来源:DefaultObjectSetter.java

示例5: Select

import java.lang.reflect.Constructor; //导入方法依赖的package包/类
public Constructor Select(Class type) throws NoSuchMethodException {
    Constructor[] constructors = type.getConstructors();
    if (constructors.length == 0) {
        throw new NoSuchMethodException("No constructor was found in " + type.getName());
    }
    for (Constructor<?> constructor : constructors) {
        if (constructor.isAnnotationPresent(Inject.class)) {
            return constructor;
        }
    }
    return constructors[0];
}
 
开发者ID:lemon-project,项目名称:DependencyInjection,代码行数:13,代码来源:DefaultConstructorSelector.java

示例6: getConstructor

import java.lang.reflect.Constructor; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private static <T> Constructor<T> getConstructor(final Key<T> key) {
    final boolean staticClass = Modifier.isStatic(key.getType().getModifiers());
    final Class<?> parentClass = key.getType().getDeclaringClass();
    final boolean innerClass = !staticClass && parentClass != null;

    Constructor<T> inject = null;
    Constructor<T> noarg = null;

    for (final Constructor<T> c : ((Constructor<T>[]) key.getType().getDeclaredConstructors())) {
        if (c.isAnnotationPresent(Inject.class)) {
            if (inject == null) {
                inject = c;
            } else {
                throw new InjectException(String.format("%s has multiple @Inject constructors", key.getType()));
            }
        } else if (c.getParameterTypes().length == 0) {
            noarg = c;
        } else if (innerClass && c.getParameterTypes().length == 1) {
            noarg = c;
        }
    }

    final Constructor<T> constructor = inject != null ? inject : noarg;
    if (constructor == null) {
        throw new InjectException(String.format("%s doesn't have an @Inject or no-arg constructor, or a module provider", key.getType().getName()));
    }

    constructor.setAccessible(true);
    return constructor;
}
 
开发者ID:minijax,项目名称:minijax,代码行数:32,代码来源:ConstructorProviderBuilder.java

示例7: injectFieldsIntoClass

import java.lang.reflect.Constructor; //导入方法依赖的package包/类
private Object injectFieldsIntoClass(final Class<?> classToInject)
        throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    for (final Constructor<?> constructor : classToInject.getConstructors()) {
        if (constructor.isAnnotationPresent(OwnInject.class)) {
            return injectFieldsViaConstructor(classToInject, constructor);
        } else {
            return injectFields(classToInject);
        }
    }
    return null;
}
 
开发者ID:zeldan,项目名称:your-own-dependency-injection-framework,代码行数:12,代码来源:OwnDiFramework.java

示例8: findMatchingConstructor

import java.lang.reflect.Constructor; //导入方法依赖的package包/类
/**
 * Finds a constructor suitable for the method. If the implementation contained any constructors marked with {@link AssistedInject}, this requires all
 * {@link Assisted} parameters to exactly match the parameters (in any order) listed in the method. Otherwise, if no {@link AssistedInject} constructors
 * exist, this will default to looking for a {@literal @}{@link Inject} constructor.
 */
private Constructor findMatchingConstructor(Method method, TypeLiteral<?> implementation, List<Key<?>> paramList, Errors errors) throws ErrorsException {
    Constructor<?> matchingConstructor = null;
    boolean anyAssistedInjectConstructors = false;

    // Look for AssistedInject constructors...
    for (Constructor<?> constructor : implementation.getRawType().getDeclaredConstructors()) {
        if (constructor.isAnnotationPresent(AssistedInject.class)) {
            anyAssistedInjectConstructors = true;

            if (constructorHasMatchingParams(implementation, constructor, paramList, errors)) {
                if (matchingConstructor != null) {
                    errors.addMessage(PrettyPrinter.format("%s has more than one constructor annotated with @AssistedInject "
                            + "that matches the parameters in method %s.", implementation, method));
                    return null;
                } else {
                    matchingConstructor = constructor;
                }
            }
        }
    }

    if (matchingConstructor != null) {
        return matchingConstructor;
    }

    if (anyAssistedInjectConstructors) {
        errors.addMessage(PrettyPrinter.format("%s has @AssistedInject constructors, but none of them match the " + "parameters in method %s.",
                implementation, method));
        return null;
    }

    // Look for @Inject constructors...
    Constructor<?> injectConstructor = (Constructor) InjectionPoint.forConstructorOf(implementation).getMember();

    if (injectConstructorHasMatchingParams(implementation, injectConstructor, paramList, errors)) {
        return injectConstructor;
    }

    // No matching constructor exists, complain.
    errors.addMessage(PrettyPrinter.format("%s has no constructors matching the parameters in method %s.", implementation, method));
    return null;
}
 
开发者ID:YoungDigitalPlanet,项目名称:empiria.player,代码行数:48,代码来源:FactoryBinding.java

示例9: hasAtInject

import java.lang.reflect.Constructor; //导入方法依赖的package包/类
/** Returns true if the inject annotation is on the constructor. */
private static boolean hasAtInject(Constructor cxtor) {
  return cxtor.isAnnotationPresent(Inject.class)
      || cxtor.isAnnotationPresent(javax.inject.Inject.class);
}
 
开发者ID:maetrive,项目名称:businessworks,代码行数:6,代码来源:ConstructorBindingImpl.java


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