List of usage examples for java.lang.reflect Method getAnnotations
public Annotation[] getAnnotations()
From source file:org.lunarray.model.descriptor.builder.annotation.resolver.property.field.FieldPropertyResolver.java
/** * Resolves the accessor./*from w w w. j av a 2 s . c o m*/ * * @param methods * Candidate methods. * @param builder * The builder. * @param type * The property type. * @param name * The property name. * @param <P> * The property type. */ private <P> void resolveAccessor(final List<Method> methods, final PropertyBuilder<P> builder, final Class<P> type, final String name) { Method accessor = null; for (final Method method : methods) { if (this.getAccessorMatcherResolver().matches(method, name, type)) { for (final Annotation a : method.getAnnotations()) { builder.addAnnotation(a); } accessor = method; } } if (!CheckUtil.isNull(accessor)) { builder.accessor(accessor); } }
From source file:org.lunarray.model.descriptor.builder.annotation.resolver.property.field.FieldPropertyResolver.java
/** * Resolves the mutator./*w w w . ja v a 2 s. c om*/ * * @param methods * Candidate methods. * @param builder * The builder. * @param type * The property type. * @param name * The property name. * @param <P> * The property type. */ private <P> void resolveMutator(final List<Method> methods, final PropertyBuilder<P> builder, final Class<P> type, final String name) { Method mutator = null; for (final Method method : methods) { if (this.getMutatorMatcherResolver().matches(method, name, type)) { for (final Annotation a : method.getAnnotations()) { builder.addAnnotation(a); } mutator = method; } } if (CheckUtil.isNull(mutator)) { builder.addModifier(Modifier.FINAL); } else { builder.mutator(mutator); } }
From source file:pl.bristleback.server.bristle.conf.resolver.action.ResponseResolver.java
@SuppressWarnings("unchecked") private void resolveResponseSerialization(Method action, ActionResponseInformation responseInformation) { SerializationResolver serializationResolver = serializationEngine.getSerializationResolver(); Object payloadSerialization = serializationResolver.resolveSerialization(action.getGenericReturnType(), action.getAnnotations()); responseInformation.setSerialization(payloadSerialization); }
From source file:org.nuxeo.runtime.test.runner.ConditionalIgnoreRule.java
@Override public Statement apply(Statement base, FrameworkMethod method, Object fixtureTarget) { Class<?> fixtureType = fixtureTarget.getClass(); Method fixtureMethod = method.getMethod(); Description description = Description.createTestDescription(fixtureType, fixtureMethod.getName(), fixtureMethod.getAnnotations()); return shouldIgnore(base, description, runner.getConfig(Ignore.class), fixtureType, fixtureMethod, fixtureTarget);// w w w. j a v a 2 s . co m }
From source file:org.specrunner.parameters.core.AccessImpl.java
@Override public Annotation[] getAnnotations() { if (field != null) { return field.getAnnotations(); } else if (property != null) { Method writeMethod = property.getWriteMethod(); if (writeMethod != null) { return writeMethod.getAnnotations(); }/*from ww w.j a v a 2s.c om*/ } else if (method != null) { return method.getAnnotations(); } return new Annotation[] {}; }
From source file:com.github.lightdocs.ModelBuilder.java
/** * Traverses each method annotations checking if it is annotated with the * JAXRS HttpMethod annotation.// www . ja va 2 s.c o m * * @param method * required. * @return null if not found */ private javax.ws.rs.HttpMethod findJAXRSHttpMethodAnnotation(Method method) { // all GET/POST/etc JAXRS annotations have the HttpMethod JAXRS // annotation on them for (Annotation a : method.getAnnotations()) { Class<? extends Annotation> aType = a.annotationType(); if (aType.isAnnotationPresent(javax.ws.rs.HttpMethod.class)) { return aType.getAnnotation(javax.ws.rs.HttpMethod.class); } } return null; }
From source file:kr.re.dev.LikeAA.LikeAA.java
private void mappingListenerByAnnotation() { Object target = mFinder.getTarget(); if (target == null) return;//from www .j av a 2s. c o m Method[] methods = target.getClass().getDeclaredMethods(); for (final Method method : methods) { Annotation[] annotations = method.getAnnotations(); // ?? ? Continue if (annotations == null || annotations.length == 0) continue; /*// ? ? . Class<?>[] params = method.getParameterTypes();*/ // annotation ? ? . for (Annotation annotation : annotations) { if (annotation instanceof Background) { // ? . //int delay = ((Background)annotation).value(); mBackgroundRunner.putRunnerMethod(method, 0); } else if (annotation instanceof UiThread) { // UI. int delay = ((UiThread) annotation).value(); mUiThreadRunner.putRunnerMethod(method, delay); } else { // . mListenerMapper.callInjectionListenerMethod(annotation, method); } } } mListenerMapper.recycle(); }
From source file:com.impetus.kundera.metadata.processor.EntityListenersProcessor.java
/** * Gets the valid jpa annotations from method. * //www . j av a 2s . co m * @param clazz * the clazz * @param method * the method * @param numberOfParams * the number of params * * @return the valid jpa annotations from method */ private List<Class<?>> getValidJPAAnnotationsFromMethod(Class<?> clazz, Method method, int numberOfParams) { List<Class<?>> annotations = new ArrayList<Class<?>>(); for (Annotation methodAnnotation : method.getAnnotations()) { Class<?> methodAnnotationType = methodAnnotation.annotationType(); if (isValidJPAEntityListenerAnnotation(methodAnnotationType)) { // verify method signature // verify exceptions boolean hasUncheckedExceptions = false; for (Class<?> exception : method.getExceptionTypes()) { if (!ReflectUtils.hasSuperClass(RuntimeException.class, exception)) { hasUncheckedExceptions = true; break; } } if (hasUncheckedExceptions) { log.info("Skipped method(" + clazz.getName() + "." + method.getName() + ") Must not throw unchecked exceptions."); continue; } // return type must be "void" if (!method.getReturnType().getSimpleName().equals("void")) { log.info("Skipped method(" + clazz.getName() + "." + method.getName() + ") Must have \"void\" return type."); continue; } // argument must be an Entity or Object Class<?>[] paramTypes = method.getParameterTypes(); if (paramTypes.length != numberOfParams) { log.info("Skipped method(" + clazz.getName() + "." + method.getName() + ") Must have " + numberOfParams + " parameter."); continue; } if (numberOfParams == 1) { Class<?> parameter = paramTypes[0]; if (!parameter.getName().equals("java.lang.Object")) { log.info("Skipped method(" + clazz.getName() + "." + method.getName() + ") Must have only 1 \"Object\" type parameter."); continue; } } annotations.add(methodAnnotationType); } } return annotations; }
From source file:org.springmodules.validation.bean.conf.loader.annotation.AnnotationBeanValidationConfigurationLoader.java
/** * Handles all the property level annotations of the given class and manipulates the given validation configuration * accordingly. The property level annotations can either be placed on the <code>setter</code> methods of the * properties or on the appropriate class fields. * * @param clazz The annotated class./*from w w w.j ava 2 s . c o m*/ * @param configuration The bean validation configuration to mainpulate. */ protected void handlePropertyAnnotations(Class clazz, MutableBeanValidationConfiguration configuration) { // extracting & handling all property annotation placed on property fields List<Field> fields = extractFieldFromClassHierarchy(clazz); for (Field field : fields) { String fieldName = field.getName(); PropertyDescriptor descriptor = BeanUtils.getPropertyDescriptor(clazz, fieldName); if (descriptor != null) { Annotation[] annotations = field.getAnnotations(); handleProprtyAnnotations(annotations, clazz, descriptor, configuration); } } // extracting & handling all property annotations placed on property setters PropertyDescriptor[] descriptors = BeanUtils.getPropertyDescriptors(clazz); for (PropertyDescriptor descriptor : descriptors) { Method writeMethod = descriptor.getWriteMethod(); if (writeMethod == null) { continue; } Annotation[] annotations = writeMethod.getAnnotations(); handleProprtyAnnotations(annotations, clazz, descriptor, configuration); } }
From source file:com.laxser.blitz.web.impl.module.ControllerRef.java
private Map<ReqMethod, String[]> collectsShotcutMappings(Method method) { Map<ReqMethod, String[]> restMethods = new HashMap<ReqMethod, String[]>(); Annotation[] annotations = method.getAnnotations(); for (Annotation annotation : annotations) { if (annotation instanceof Delete) { restMethods.put(ReqMethod.DELETE, ((Delete) annotation).value()); } else if (annotation instanceof Get) { restMethods.put(ReqMethod.GET, ((Get) annotation).value()); } else if (annotation instanceof Head) { restMethods.put(ReqMethod.HEAD, ((Head) annotation).value()); } else if (annotation instanceof Options) { restMethods.put(ReqMethod.OPTIONS, ((Options) annotation).value()); } else if (annotation instanceof Post) { restMethods.put(ReqMethod.POST, ((Post) annotation).value()); } else if (annotation instanceof Put) { restMethods.put(ReqMethod.PUT, ((Put) annotation).value()); } else if (annotation instanceof Trace) { restMethods.put(ReqMethod.TRACE, ((Trace) annotation).value()); } else {/*w w w . j a v a 2 s . c o m*/ } } for (String[] paths : restMethods.values()) { for (int i = 0; i < paths.length; i++) { if (paths[i].equals("/")) { paths[i] = ""; } else if (paths[i].length() > 0 && paths[i].charAt(0) != '/') { paths[i] = "/" + paths[i]; } if (paths[i].length() > 1 && paths[i].endsWith("/")) { if (paths[i].endsWith("//")) { throw new IllegalArgumentException( "invalid path '" + paths[i] + "' for method " + method.getDeclaringClass().getName() + "#" + method.getName() + ": don't end with more than one '/'"); } paths[i] = paths[i].substring(0, paths[i].length() - 1); } } } return restMethods; }