當前位置: 首頁>>代碼示例>>Java>>正文


Java AnnotatedElement.getAnnotation方法代碼示例

本文整理匯總了Java中java.lang.reflect.AnnotatedElement.getAnnotation方法的典型用法代碼示例。如果您正苦於以下問題:Java AnnotatedElement.getAnnotation方法的具體用法?Java AnnotatedElement.getAnnotation怎麽用?Java AnnotatedElement.getAnnotation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.lang.reflect.AnnotatedElement的用法示例。


在下文中一共展示了AnnotatedElement.getAnnotation方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getName

import java.lang.reflect.AnnotatedElement; //導入方法依賴的package包/類
/**
 * Get display name of specified element from name parameter of {@link Editable} annotation. 
 * If the annotation is not defined or name parameter is not available in the annotation, the 
 * element name itself will be transferred to non-camel case and returned.
 *
 * @param element
 * 			annotated element to get name from
 * @return
 * 			display name of the element
 */
public static String getName(AnnotatedElement element) {
	Editable editable = element.getAnnotation(Editable.class);
	if (editable != null && editable.name().trim().length() != 0)
		return editable.name();
	else if (element instanceof Class)
		return WordUtils.uncamel(((Class<?>)element).getSimpleName());
	else if (element instanceof Field) 
		return WordUtils.uncamel(WordUtils.capitalize(((Field)element).getName()));
	else if (element instanceof Method)
		return StringUtils.substringAfter(WordUtils.uncamel(((Method)element).getName()), " ");
	else if (element instanceof Package) 
		return ((Package)element).getName();
	else
		throw new GeneralException("Invalid element type: " + element.getClass().getName());
}
 
開發者ID:jmfgdev,項目名稱:gitplex-mit,代碼行數:26,代碼來源:EditableUtils.java

示例2: getDescription

import java.lang.reflect.AnnotatedElement; //導入方法依賴的package包/類
/**
 * Get description of specified element from description parameter of {@link Editable} annotation
 *
 * @param element
 * 			annotated element to get description from
 * @return
 * 			defined description, or <tt>null</tt> if description can not be found
 */
public static @Nullable String getDescription(AnnotatedElement element) {
	Editable editable = element.getAnnotation(Editable.class);
	if (editable != null) {
		if (editable.description().length() != 0)
			return editable.description();
		if (editable.descriptionProvider().length() != 0) {
			Class<?> clazz;
			if (element instanceof Method)
				clazz = ((Method) element).getDeclaringClass();
			else if (element instanceof Class) 
				clazz = (Class<?>) element;
			else 
				clazz = ((Field) element).getDeclaringClass();
			return (String) ReflectionUtils.invokeStaticMethod(clazz, editable.descriptionProvider());
		}
	}
	return null;
}
 
開發者ID:jmfgdev,項目名稱:gitplex-mit,代碼行數:27,代碼來源:EditableUtils.java

示例3: EjbRefElement

import java.lang.reflect.AnnotatedElement; //導入方法依賴的package包/類
public EjbRefElement(Member member, PropertyDescriptor pd) {
	super(member, pd);
	AnnotatedElement ae = (AnnotatedElement) member;
	EJB resource = ae.getAnnotation(EJB.class);
	String resourceBeanName = resource.beanName();
	String resourceName = resource.name();
	this.isDefaultName = !StringUtils.hasLength(resourceName);
	if (this.isDefaultName) {
		resourceName = this.member.getName();
		if (this.member instanceof Method && resourceName.startsWith("set") && resourceName.length() > 3) {
			resourceName = Introspector.decapitalize(resourceName.substring(3));
		}
	}
	Class<?> resourceType = resource.beanInterface();
	if (resourceType != null && !Object.class.equals(resourceType)) {
		checkResourceType(resourceType);
	}
	else {
		// No resource type specified... check field/method.
		resourceType = getResourceType();
	}
	this.beanName = resourceBeanName;
	this.name = resourceName;
	this.lookupType = resourceType;
	this.mappedName = resource.mappedName();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:27,代碼來源:CommonAnnotationBeanPostProcessor.java

示例4: getAnnotations

import java.lang.reflect.AnnotatedElement; //導入方法依賴的package包/類
private <T extends Annotation> Collection<T> getAnnotations(AnnotatedElement ae, Class<T> annotationType) {
	Collection<T> anns = new ArrayList<T>(2);

	// look at raw annotation
	T ann = ae.getAnnotation(annotationType);
	if (ann != null) {
		anns.add(ann);
	}

	// scan meta-annotations
	for (Annotation metaAnn : ae.getAnnotations()) {
		ann = metaAnn.annotationType().getAnnotation(annotationType);
		if (ann != null) {
			anns.add(ann);
		}
	}

	return (anns.isEmpty() ? null : anns);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:20,代碼來源:SpringCacheAnnotationParser.java

示例5: findMappingAnnotation

import java.lang.reflect.AnnotatedElement; //導入方法依賴的package包/類
Annotation findMappingAnnotation(AnnotatedElement element) {
  Annotation mappingAnnotation = element.getAnnotation(RequestMapping.class);

  if (mappingAnnotation == null) {
    mappingAnnotation = element.getAnnotation(GetMapping.class);

    if (mappingAnnotation == null) {
      mappingAnnotation = element.getAnnotation(PostMapping.class);

      if (mappingAnnotation == null) {
        mappingAnnotation = element.getAnnotation(PutMapping.class);

        if (mappingAnnotation == null) {
          mappingAnnotation = element.getAnnotation(DeleteMapping.class);

          if (mappingAnnotation == null) {
            mappingAnnotation = element.getAnnotation(PatchMapping.class);
          }
        }
      }
    }
  }

  if (mappingAnnotation == null) {
    if (element instanceof Method) {
      Method method = (Method) element;
      mappingAnnotation = AnnotationUtils.findAnnotation(method, RequestMapping.class);
    } else {
      Class<?> clazz = (Class<?>) element;
      mappingAnnotation = AnnotationUtils.findAnnotation(clazz, RequestMapping.class);
    }
  }

  return mappingAnnotation;
}
 
開發者ID:mental-party,項目名稱:meparty,代碼行數:36,代碼來源:RestApiProxyInvocationHandler.java

示例6: ignoreThrowable

import java.lang.reflect.AnnotatedElement; //導入方法依賴的package包/類
private boolean ignoreThrowable(Exception exception, AnnotatedElement... annotatedElements) {
	if(exception != null) {
		for(AnnotatedElement element : annotatedElements) {
			if(element == null) {
				continue;
			}
			IgnoreRemoteExceptions annotation = element.getAnnotation(IgnoreRemoteExceptions.class);
			if(annotation != null) {
				return !Arrays.asList(annotation.exceptTypes()).contains(exception.getClass());
			}
		}
	}
	return false;
}
 
開發者ID:ThorbenKuck,項目名稱:NetCom2,代碼行數:15,代碼來源:RemoteObjectRegistrationImpl.java

示例7: getAnnotations

import java.lang.reflect.AnnotatedElement; //導入方法依賴的package包/類
private <T extends Annotation> Stream<T> getAnnotations(final AnnotatedElement annotatedElement,
                                                        final Class<T> annotationClass) {
    final T annotation = annotatedElement.getAnnotation(annotationClass);
    return Stream.concat(
            extractRepeatable(annotatedElement, annotationClass).stream(),
            Objects.isNull(annotation) ? Stream.empty() : Stream.of(annotation)
    );
}
 
開發者ID:allure-framework,項目名稱:allure-java,代碼行數:9,代碼來源:AllureJunit5AnnotationProcessor.java

示例8: withAnnotation

import java.lang.reflect.AnnotatedElement; //導入方法依賴的package包/類
private static Predicate<AnnotatedElement> withAnnotation(final Class<? extends Annotation> annotationType) {
    return new Predicate<AnnotatedElement>() {
        @Override
        public boolean apply(AnnotatedElement input) {
            return input.getAnnotation(annotationType) != null;
        }
    };
}
 
開發者ID:TNG,項目名稱:ArchUnit,代碼行數:9,代碼來源:ArchRules.java

示例9: readLayout

import java.lang.reflect.AnnotatedElement; //導入方法依賴的package包/類
private int readLayout(AnnotatedElement element) {
    if (element.isAnnotationPresent(BindItem.class)) {
        BindItem bindItem = element.getAnnotation(BindItem.class);
        return bindItem.layout();
    } else {
        throw new IllegalStateException("items should be annotated with BindItem");
    }
}
 
開發者ID:sajadshokri,項目名稱:GhostAdapter,代碼行數:9,代碼來源:GhostAdapter.java

示例10: WebServiceRefElement

import java.lang.reflect.AnnotatedElement; //導入方法依賴的package包/類
public WebServiceRefElement(Member member, PropertyDescriptor pd) {
	super(member, pd);
	AnnotatedElement ae = (AnnotatedElement) member;
	WebServiceRef resource = ae.getAnnotation(WebServiceRef.class);
	String resourceName = resource.name();
	Class<?> resourceType = resource.type();
	this.isDefaultName = !StringUtils.hasLength(resourceName);
	if (this.isDefaultName) {
		resourceName = this.member.getName();
		if (this.member instanceof Method && resourceName.startsWith("set") && resourceName.length() > 3) {
			resourceName = Introspector.decapitalize(resourceName.substring(3));
		}
	}
	if (resourceType != null && !Object.class.equals(resourceType)) {
		checkResourceType(resourceType);
	}
	else {
		// No resource type specified... check field/method.
		resourceType = getResourceType();
	}
	this.name = resourceName;
	this.elementType = resourceType;
	if (Service.class.isAssignableFrom(resourceType)) {
		this.lookupType = resourceType;
	}
	else {
		this.lookupType = (!Object.class.equals(resource.value()) ? resource.value() : Service.class);
	}
	this.mappedName = resource.mappedName();
	this.wsdlLocation = resource.wsdlLocation();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:32,代碼來源:CommonAnnotationBeanPostProcessor.java

示例11: getAnnotation

import java.lang.reflect.AnnotatedElement; //導入方法依賴的package包/類
static Annotation getAnnotation(AnnotatedElement element,
		String annotationTypeName) {
	Class<?> annotationType = null; //��������������
	try {
		annotationType = Class.forName(annotationTypeName);
	} catch (Exception e) {
		// TODO: handle exception
		throw new IllegalArgumentException(e);
	}
	return element.getAnnotation(annotationType
			.asSubclass(Annotation.class));
}
 
開發者ID:turoDog,項目名稱:effectiveJava,代碼行數:13,代碼來源:PrintAnnotation.java

示例12: extractRoles

import java.lang.reflect.AnnotatedElement; //導入方法依賴的package包/類
private List<Role> extractRoles(AnnotatedElement annotatedElement) {
    if (annotatedElement == null) {
        return new ArrayList<>();
    } else {
        Secured secured = annotatedElement.getAnnotation(Secured.class);
        if (secured == null) {
            return new ArrayList<>();
        } else {
            Role[] allowedRoles = secured.value();
            return Arrays.asList(allowedRoles);
        }
    }
}
 
開發者ID:ISIS2503,項目名稱:ThermalComfortBack,代碼行數:14,代碼來源:AuthorizationFilter.java

示例13: matches

import java.lang.reflect.AnnotatedElement; //導入方法依賴的package包/類
@Override
public boolean matches(AnnotatedElement element) {
    Annotation fromElement = element.getAnnotation(annotation.annotationType());
    return fromElement != null && annotation.equals(fromElement);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:6,代碼來源:Matchers.java

示例14: getAtInject

import java.lang.reflect.AnnotatedElement; //導入方法依賴的package包/類
static Annotation getAtInject(AnnotatedElement member) {
  Annotation a = member.getAnnotation(javax.inject.Inject.class);
  return a == null ? member.getAnnotation(Inject.class) : a;
}
 
開發者ID:maetrive,項目名稱:businessworks,代碼行數:5,代碼來源:InjectionPoint.java

示例15: listenerScope

import java.lang.reflect.AnnotatedElement; //導入方法依賴的package包/類
private static MatchScope listenerScope(AnnotatedElement thing, @Nullable MatchScope def) {
    final ListenerScope annotation = thing.getAnnotation(ListenerScope.class);
    return annotation == null ? def : annotation.value();
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:5,代碼來源:MatchEventRegistry.java


注:本文中的java.lang.reflect.AnnotatedElement.getAnnotation方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。