List of usage examples for java.lang.reflect Constructor isAnnotationPresent
@Override public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
From source file:mangotiger.poker.channel.EventMatcherImpl.java
public static Type[] args(final Constructor<?> constructor) { return constructor.isAnnotationPresent(Parameters.class) ? constructor.getAnnotation(Parameters.class).value() : ZERO_TYPES;//from www.j a va 2s.c o m }
From source file:co.jirm.mapper.definition.SqlParameterDefinition.java
static Map<String, SqlParameterDefinition> getSqlBeanParameters(Class<?> k, SqlObjectConfig config) { Map<String, SqlParameterDefinition> parameters = new LinkedHashMap<String, SqlParameterDefinition>(); Constructor<?> cons[] = k.getDeclaredConstructors(); for (Constructor<?> c : cons) { if (c.isAnnotationPresent(JsonCreator.class)) { return getSqlBeanParametersFromJsonCreatorConstructor(c, config); }/*from w w w. j a va 2 s .c om*/ if (c.isAnnotationPresent(ConstructorProperties.class)) { return getSqlBeanParametersFromConstructorProperties(c, config); } } check.argument(!parameters.isEmpty(), "No SQL columns/parameters found for: {}", k); return parameters; }
From source file:com.rockagen.commons.util.ClassUtil.java
/** * obtain constructors list of specified class and which are annotated by * incoming annotation class If recursively is true, obtain constructors * from all class hierarchy/* w w w . ja v a 2 s .c o m*/ * * @param clazz class * - where constructors are searching * @param annotationClass * - specified annotation class * @param recursively * param * @return list of annotated constructors */ public static Constructor<?>[] getAnnotatedDeclaredConstructors(Class<?> clazz, Class<? extends Annotation> annotationClass, boolean recursively) { Constructor<?>[] allConstructors = getDeclaredConstructors(clazz, recursively); List<Constructor<?>> annotatedConstructors = new LinkedList<Constructor<?>>(); for (Constructor<?> field : allConstructors) { if (field.isAnnotationPresent(annotationClass)) annotatedConstructors.add(field); } return annotatedConstructors.toArray(new Constructor<?>[annotatedConstructors.size()]); }
From source file:org.openehr.rm.binding.DADLBinding.java
private static Constructor fullConstructor(Class klass) { if (klass == null) { return null; }// w ww . ja v a 2s. c o m Constructor[] array = klass.getConstructors(); for (Constructor constructor : array) { if (constructor.isAnnotationPresent(FullConstructor.class)) { return constructor; } } return null; }
From source file:xiaofei.library.hermes.util.TypeUtils.java
public static void validateAccessible(Constructor<?> constructor) throws HermesException { if (constructor.isAnnotationPresent(WithinProcess.class)) { throw new HermesException(ErrorCodes.METHOD_WITH_PROCESS, "Constructor " + constructor.getName() + " of class " + constructor.getDeclaringClass().getName() + " has a WithProcess annotation on it, so it cannot be accessed from " + "outside the process."); }/*w ww . java2 s .c om*/ }
From source file:org.jgentleframework.utils.Utils.java
/** * Returns the default {@link Constructor} of the given class. The default * constructor is identified with annotated {@link DefaultConstructor} * annotation.//ww w . ja va2 s . co m * * @param clazz * the given class * @return returns the default constructor if it exists, if not, return * <code>null</code>. * @throws InOutDependencyException * throws this exception if there are more than one default * constructor. * @see DefaultConstructor */ public static Constructor<?> getDefaultConstructor(Class<?> clazz) { Constructor<?> constructor = null; int i = 0; for (Constructor<?> objCons : clazz.getDeclaredConstructors()) { if (objCons.isAnnotationPresent(DefaultConstructor.class)) { constructor = objCons; i++; } } if (i > 1) { throw new RuntimeException("There are more than one default constructor."); } return constructor; }
From source file:com.zc.util.refelect.Reflector.java
/** * ?constructorannotationClass/*from ww w . jav a 2 s . c o m*/ * * @param constructor * constructor * @param annotationClass * annotationClass * * @return {@link java.lang.annotation.Annotation} */ public static <T extends Annotation> T getAnnotation(Constructor constructor, Class annotationClass) { constructor.setAccessible(true); if (constructor.isAnnotationPresent(annotationClass)) { return (T) constructor.getAnnotation(annotationClass); } return null; }
From source file:org.openehr.build.RMObjectBuilder.java
private static Constructor fullConstructor(Class klass) { Constructor[] array = klass.getConstructors(); for (Constructor constructor : array) { if (constructor.isAnnotationPresent(FullConstructor.class)) { return constructor; }//from ww w . j a va2s .c o m } return null; }
From source file:com.github.dactiv.common.utils.ReflectionUtils.java
/** * ?constructorannotationClass//from w ww . j a v a 2 s . co m * * @param constructor * constructor * @param annotationClass * annotationClass * * @return {@link Annotation} */ public static <T extends Annotation> T getAnnotation(Constructor constructor, Class annotationClass) { Assert.notNull(constructor, "constructor?"); Assert.notNull(annotationClass, "annotationClass?"); constructor.setAccessible(true); if (constructor.isAnnotationPresent(annotationClass)) { return (T) constructor.getAnnotation(annotationClass); } return null; }
From source file:org.diorite.impl.bean.BeanScanner.java
private void processClass(final Class<?> clazz) throws BeanException { // Bean registration by class if (clazz.isAnnotationPresent(DioriteBean.class)) { final DioriteBean beanInfo = clazz.getAnnotation(DioriteBean.class); final BeanContainer beanContainer = new BeanContainer(clazz, new ClassBeanProvider(clazz)); this.beanManager.registerBean(beanContainer); }//from w ww . j a va 2s .com // Bean registration by constructor for (final Constructor<?> constructor : clazz.getConstructors()) { if (constructor.isAnnotationPresent(DioriteBean.class)) { final DioriteBean beanInfo = constructor.getAnnotation(DioriteBean.class); final BeanContainer beanContainer = new BeanContainer(clazz, new ConstructorBeanProvider(constructor)); this.beanManager.registerBean(beanContainer); } } // Bean registration by method for (final Method method : clazz.getMethods()) { if (method.isAnnotationPresent(DioriteBean.class)) { final Class<?> returnType = method.getReturnType(); if (returnType.equals(Void.TYPE) || returnType.isPrimitive()) { throw new BeanRegisteringException(MessageFormat.format( "Can't register method '{0}' in class '{1}' as Diorite Bean. Method must return object.", method.getName(), clazz.getName())); } else if (returnType.getPackage().equals(JAVA_PACKAGE)) { throw new BeanRegisteringException(MessageFormat.format( "Can't register method '{0}' in class '{1}' as Diorite Bean. Method can't return object from java package.", method.getName(), clazz.getName())); } final DioriteBean beanInfo = method.getAnnotation(DioriteBean.class); final BeanContainer beanContainer = new BeanContainer(returnType, new MethodBeanProvider(method)); this.beanManager.registerBean(beanContainer); } } for (final Field field : clazz.getDeclaredFields()) { if (field.isAnnotationPresent(InjectedValue.class)) { this.beanManager.addInjectorCode(clazz); break; } } }