本文整理了Java中java.lang.reflect.Method.getDeclaredAnnotations()
方法的一些代码示例,展示了Method.getDeclaredAnnotations()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Method.getDeclaredAnnotations()
方法的具体详情如下:
包路径:java.lang.reflect.Method
类名称:Method
方法名:getDeclaredAnnotations
暂无
代码示例来源:origin: spring-projects/spring-loaded
public static String annoAccessor() {
try {
Annotation[] annos = ScenarioB003.class.getDeclaredMethod("foo").getDeclaredAnnotations();
if (annos == null || annos.length == 0) {
return "no annotations";
} else {
return "found " + (annos[0]);
}
} catch (Exception e) {
return "no annotations";
}
}
代码示例来源:origin: spring-projects/spring-loaded
public static String annoAccessor() {
try {
Annotation[] annos = ScenarioB002.class.getDeclaredMethod("foo").getDeclaredAnnotations();
if (annos == null || annos.length == 0) {
return "no annotations";
} else {
return "found " + (annos[0]);
}
} catch (Exception e) {
return "no annotations";
}
}
代码示例来源:origin: libgdx/libgdx
/** Returns an array of {@link Annotation} objects reflecting all annotations declared by this method,
* or an empty array if there are none. Does not include inherited annotations.
* Does not include parameter annotations. */
public Annotation[] getDeclaredAnnotations () {
java.lang.annotation.Annotation[] annotations = method.getDeclaredAnnotations();
Annotation[] result = new Annotation[annotations.length];
for (int i = 0; i < annotations.length; i++) {
result[i] = new Annotation(annotations[i]);
}
return result;
}
代码示例来源:origin: libgdx/libgdx
/** Returns an array of {@link Annotation} objects reflecting all annotations declared by this method,
* or an empty array if there are none. Does not include inherited annotations.
* Does not include parameter annotations. */
public Annotation[] getDeclaredAnnotations () {
java.lang.annotation.Annotation[] annotations = method.getDeclaredAnnotations();
Annotation[] result = new Annotation[annotations.length];
for (int i = 0; i < annotations.length; i++) {
result[i] = new Annotation(annotations[i]);
}
return result;
}
代码示例来源:origin: libgdx/libgdx
/** Returns an {@link Annotation} object reflecting the annotation provided, or null of this method doesn't
* have such an annotation. This is a convenience function if the caller knows already which annotation
* type he's looking for. */
public Annotation getDeclaredAnnotation (Class<? extends java.lang.annotation.Annotation> annotationType) {
java.lang.annotation.Annotation[] annotations = method.getDeclaredAnnotations();
if (annotations == null) {
return null;
}
for (java.lang.annotation.Annotation annotation : annotations) {
if (annotation.annotationType().equals(annotationType)) {
return new Annotation(annotation);
}
}
return null;
}
代码示例来源:origin: libgdx/libgdx
/** Returns an {@link Annotation} object reflecting the annotation provided, or null of this method doesn't
* have such an annotation. This is a convenience function if the caller knows already which annotation
* type he's looking for. */
public Annotation getDeclaredAnnotation (Class<? extends java.lang.annotation.Annotation> annotationType) {
java.lang.annotation.Annotation[] annotations = method.getDeclaredAnnotations();
if (annotations == null) {
return null;
}
for (java.lang.annotation.Annotation annotation : annotations) {
if (annotation.annotationType().equals(annotationType)) {
return new Annotation(annotation);
}
}
return null;
}
代码示例来源:origin: junit-team/junit4
/**
* Get the annotations associated with given TestCase.
* @param test the TestCase.
*/
private static Annotation[] getAnnotations(TestCase test) {
try {
Method m = test.getClass().getMethod(test.getName());
return m.getDeclaredAnnotations();
} catch (SecurityException e) {
} catch (NoSuchMethodException e) {
}
return new Annotation[0];
}
代码示例来源:origin: jersey/jersey
private void handleMetaAnnotations(ResourceMethod resourceMethod, Method method,
List<ProvideLinkDescriptor> linkDescriptors) {
Annotation[] annotations = method.getDeclaredAnnotations();
for (Annotation annotation : annotations) {
handleAnnotations(resourceMethod, linkDescriptors, annotation.annotationType(), annotation);
}
}
代码示例来源:origin: apache/hbase
private boolean isDeprecated(Method method) {
Annotation[] annotations = method.getDeclaredAnnotations();
for (Annotation annotation : annotations) {
if (annotation instanceof Deprecated) {
return true;
}
}
return false;
}
}
代码示例来源:origin: spring-projects/spring-loaded
public static Annotation getFirstDeclaredAnnotation(String name) throws Exception {
Annotation[] annos = getDeclaredMethod(name).getDeclaredAnnotations();
if (annos == null || annos.length == 0) {
return null;
} else {
return annos[0];
}
}
代码示例来源:origin: jenkinsci/jenkins
private static boolean isRoutableMethod(@Nonnull Method m) {
for (Annotation a : m.getDeclaredAnnotations()) {
if (WebMethodConstants.WEB_METHOD_ANNOTATION_NAMES.contains(a.annotationType().getName())) {
return true;
}
if (a.annotationType().isAnnotationPresent(InterceptorAnnotation.class)) {
// This is a Stapler interceptor annotation like RequirePOST or JsonResponse
return true;
}
}
for (Annotation[] set : m.getParameterAnnotations()) {
for (Annotation a : set) {
if (WebMethodConstants.WEB_METHOD_PARAMETER_ANNOTATION_NAMES.contains(a.annotationType().getName())) {
return true;
}
}
}
for (Class<?> parameterType : m.getParameterTypes()) {
if (WebMethodConstants.WEB_METHOD_PARAMETERS_NAMES.contains(parameterType.getName())) {
return true;
}
}
return WebApp.getCurrent().getFilterForDoActions().keep(new Function.InstanceFunction(m));
}
代码示例来源:origin: redisson/redisson
/**
* {@inheritDoc}
*/
@CachedReturnPlugin.Enhance("declaredAnnotations")
public AnnotationList getDeclaredAnnotations() {
return new AnnotationList.ForLoadedAnnotations(method.getDeclaredAnnotations());
}
代码示例来源:origin: ronmamo/reflections
public List<String> getMethodAnnotationNames(Member method) {
Annotation[] annotations =
method instanceof Method ? ((Method) method).getDeclaredAnnotations() :
method instanceof Constructor ? ((Constructor) method).getDeclaredAnnotations() : null;
return getAnnotationNames(annotations);
}
代码示例来源:origin: org.codehaus.jackson/jackson-mapper-asl
/**
* Method that will add annotations from specified source method to target method,
* but only if target does not yet have them.
*/
protected void _addMixUnders(Method src, AnnotatedMethod target)
{
for (Annotation a : src.getDeclaredAnnotations()) {
if (_annotationIntrospector.isHandled(a)) {
target.addIfNotPresent(a);
}
}
}
代码示例来源:origin: jersey/jersey
private void checkUnexpectedAnnotations(ResourceMethod resourceMethod) {
Invocable invocable = resourceMethod.getInvocable();
for (Annotation annotation : invocable.getHandlingMethod().getDeclaredAnnotations()) {
if (PARAM_ANNOTATION_SET.contains(annotation.annotationType())) {
Errors.fatal(resourceMethod, LocalizationMessages.METHOD_UNEXPECTED_ANNOTATION(
invocable.getHandlingMethod().getName(),
invocable.getHandler().getHandlerClass().getName(),
annotation.annotationType().getName())
);
}
}
}
代码示例来源:origin: jersey/jersey
private void checkUnexpectedAnnotations(ResourceMethod resourceMethod) {
Invocable invocable = resourceMethod.getInvocable();
for (Annotation annotation : invocable.getHandlingMethod().getDeclaredAnnotations()) {
if (PARAM_ANNOTATION_SET.contains(annotation.annotationType())) {
Errors.fatal(resourceMethod, LocalizationMessages.METHOD_UNEXPECTED_ANNOTATION(
invocable.getHandlingMethod().getName(),
invocable.getHandler().getHandlerClass().getName(),
annotation.annotationType().getName())
);
}
}
}
代码示例来源:origin: swagger-api/swagger-core
@Test
public void isInjectTest() throws NoSuchMethodException {
final Method injectableMethod = Child.class.getMethod("injectableMethod");
Assert.assertTrue(ReflectionUtils.isInject(Arrays.asList(injectableMethod.getDeclaredAnnotations())));
final Method methodToFind = Child.class.getMethod("parametrizedMethod1", Integer.class);
Assert.assertFalse(ReflectionUtils.isInject(Arrays.asList(methodToFind.getDeclaredAnnotations())));
}
代码示例来源:origin: alibaba/jvm-sandbox
private BehaviorStructure newBehaviorStructure(final Method method) {
return new BehaviorStructure(
new AccessImplByJDKBehavior(method),
method.getName(),
this,
newInstance(method.getReturnType()),
newInstances(method.getParameterTypes()),
newInstances(method.getExceptionTypes()),
newInstances(getAnnotationTypeArray(method.getDeclaredAnnotations()))
);
}
代码示例来源:origin: org.codehaus.jackson/jackson-mapper-asl
protected AnnotatedMethod _constructCreatorMethod(Method m)
{
if (_annotationIntrospector == null) { // when annotation processing is disabled
return new AnnotatedMethod(m, _emptyAnnotationMap(), _emptyAnnotationMaps(m.getParameterTypes().length));
}
return new AnnotatedMethod(m, _collectRelevantAnnotations(m.getDeclaredAnnotations()),
_collectRelevantAnnotations(m.getParameterAnnotations()));
}
代码示例来源:origin: org.codehaus.jackson/jackson-mapper-asl
protected AnnotatedMethod _constructMethod(Method m)
{
/* note: parameter annotations not used for regular (getter, setter)
* methods; only for creator methods (static factory methods)
* -- at least not yet!
*/
if (_annotationIntrospector == null) { // when annotation processing is disabled
return new AnnotatedMethod(m, _emptyAnnotationMap(), null);
}
return new AnnotatedMethod(m, _collectRelevantAnnotations(m.getDeclaredAnnotations()), null);
}
内容来源于网络,如有侵权,请联系作者删除!