本文整理汇总了Java中java.lang.annotation.Annotation类的典型用法代码示例。如果您正苦于以下问题:Java Annotation类的具体用法?Java Annotation怎么用?Java Annotation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Annotation类属于java.lang.annotation包,在下文中一共展示了Annotation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: callChar
import java.lang.annotation.Annotation; //导入依赖的package包/类
private static <A extends Annotation, E extends Throwable> char callChar(
AnnotationInterceptor<A> annotationInterceptor,
int annotationId, A[] annotations, CallContext context, Arguments currentArguments,
ToCharFunction<Arguments> terminalInvokeFun) throws E {
A annotation = annotations[annotationId];
if (annotationId == annotations.length - 1) { // last annotation
return annotationInterceptor.onCall(annotation, context,
new SimpleCharInterceptionHandler(currentArguments, terminalInvokeFun));
} else {
return annotationInterceptor.onCall(annotation, context,
new SimpleCharInterceptionHandler(currentArguments,
(args) -> callChar(annotationInterceptor, annotationId + 1, annotations, context, args,
terminalInvokeFun)));
}
}
示例2: resolveJar
import java.lang.annotation.Annotation; //导入依赖的package包/类
/**
* 解析jar包中的类
* @param jarFile 表示jar文件
* @param packageLocation 扫描的包路径
* @throws Exception 反射时的异常
*/
private void resolveJar(JarFile jarFile, String packageLocation) throws Exception {
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
String classLocation = entries.nextElement().getName();
// 当jar文件中的路径是以packageLocation指定的路径开头,并且是以.class结尾时
if (classLocation.startsWith(packageLocation) && classLocation.endsWith(".class")) {
String location = classLocation.replace(".class", "").replace("/", ".");
Class<?> forName = Class.forName(location);
configurationBeansHandler(forName);
Annotation[] annos = forName.getAnnotations();
if (AnnoUtil.exist(annos, Bean.class) && !forName.isInterface()) {
beansInitializedHandler(forName);
}
}
}
}
示例3: TypeInfo
import java.lang.annotation.Annotation; //导入依赖的package包/类
public TypeInfo(QName tagName, Type type, Annotation... annotations) {
if(tagName==null || type==null || annotations==null) {
String nullArgs = "";
if(tagName == null) nullArgs = "tagName";
if(type == null) nullArgs += (nullArgs.length() > 0 ? ", type" : "type");
if(annotations == null) nullArgs += (nullArgs.length() > 0 ? ", annotations" : "annotations");
// Messages.ARGUMENT_CANT_BE_NULL.format(nullArgs);
throw new IllegalArgumentException( "Argument(s) \"" + nullArgs + "\" can''t be null.)");
}
this.tagName = new QName(tagName.getNamespaceURI().intern(), tagName.getLocalPart().intern(), tagName.getPrefix());
this.type = type;
if (type instanceof Class && ((Class<?>)type).isPrimitive()) nillable = false;
this.annotations = annotations;
}
示例4: writeTo
import java.lang.annotation.Annotation; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public void writeTo(Value<?> entity,
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
OutputStream entityStream)
throws IOException {
final Object entityValue = entity.getOrElseThrow(() -> EmptyValueException.INSTANCE);
final Class<?> entityClass = entityValue.getClass();
final Type actualGenericTypeArgument;
if (genericType instanceof ParameterizedType) {
actualGenericTypeArgument = ((ParameterizedType) genericType).getActualTypeArguments()[0];
} else {
actualGenericTypeArgument = entityClass;
}
final MessageBodyWriter writer = mbw.get().getMessageBodyWriter(entityClass, actualGenericTypeArgument, annotations, mediaType);
writer.writeTo(entityValue, entityClass, actualGenericTypeArgument, annotations, mediaType, httpHeaders, entityStream);
}
示例5: exposeInternal
import java.lang.annotation.Annotation; //导入依赖的package包/类
private <T> AnnotatedElementBuilder exposeInternal(Key<T> key) {
if (privateElements == null) {
addError("Cannot expose %s on a standard binder. "
+ "Exposed bindings are only applicable to private binders.", key);
return new AnnotatedElementBuilder() {
@Override
public void annotatedWith(Class<? extends Annotation> annotationType) {
}
@Override
public void annotatedWith(Annotation annotation) {
}
};
}
ExposureBuilder<T> builder = new ExposureBuilder<>(this, getSource(), key);
privateElements.addExposureBuilder(builder);
return builder;
}
示例6: query
import java.lang.annotation.Annotation; //导入依赖的package包/类
/**
* Query clazz's methods to getPlugin all annotated spec annotations.
*
* @param clazz
* @param methodCls
* @return
*/
public static Annotation[] query(final Class<?> clazz,
final Class<? extends Annotation> methodCls) {
return Fn.get(() -> {
final Method[] methods = clazz.getDeclaredMethods();
final List<Method> methodSet = Arrays.asList(methods);
final List<Method> result = methodSet.stream()
.filter(item -> item.isAnnotationPresent(methodCls))
.collect(Collectors.toList());
final List<Annotation> resultAnnos = new ArrayList<>();
for (final Method method : result) {
final Annotation anno = method.getAnnotation(methodCls);
if (null != anno) {
resultAnnos.add(anno);
}
}
return resultAnnos.toArray(new Annotation[]{});
}, clazz, methodCls);
}
示例7: prepareBundle
import java.lang.annotation.Annotation; //导入依赖的package包/类
private Bundle prepareBundle(Object[] args) {
Bundle bundle = new Bundle();
int paramCount = parameterTypes.length;
if (parameterTypes != null && paramCount > 0){
for (int i = 0; i < paramCount; i++) {
String key;
Annotation[] paramAnnotations = parameterAnnotationsArray[i];
for (Annotation anno: paramAnnotations) {
if (anno instanceof Key){
key = ((Key) anno).value();
handleParams(bundle, key, parameterTypes[i], args[i]);
}else if(anno instanceof FieldMap){
}else{
throw new IllegalStateException("不支持的参数注解: " + anno.toString() );
}
}
}
}
return bundle;
}
示例8: writeTo
import java.lang.annotation.Annotation; //导入依赖的package包/类
@Override
public void writeTo(
Object o, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders, OutputStream os) throws IOException {
String fields = uriInfo.getQueryParameters() == null ? null
: uriInfo.getQueryParameters().getFirst("fields");
FieldFilter fieldFilter = FieldFilter.create(fields);
if (!fieldFilter.hasFilters()) {
super.writeTo(o, type, genericType, annotations, mediaType, httpHeaders, os);
return;
}
JsonGenerator jgen = objectMapper.getFactory().createGenerator(os);
TokenBuffer tokenBuffer = new TokenBuffer(objectMapper, false);
objectMapper.writeValue(tokenBuffer, o);
JsonParser jsonParser = tokenBuffer.asParser();
fieldFilter.writeJson(jsonParser, jgen);
jgen.flush();
}
示例9: doMerge
import java.lang.annotation.Annotation; //导入依赖的package包/类
private Annotation[] doMerge(Annotation[] annotations, Annotation[] externalAnnotations) {
HashMap<String, Annotation> mergeMap = new HashMap<String, Annotation>();
if (annotations != null) {
for (Annotation reflectionAnnotation : annotations) {
mergeMap.put(reflectionAnnotation.annotationType().getName(), reflectionAnnotation);
}
}
// overriding happens here, based on annotationType().getName() ...
if (externalAnnotations != null) {
for (Annotation externalAnnotation : externalAnnotations) {
mergeMap.put(externalAnnotation.annotationType().getName(), externalAnnotation);
}
}
Collection<Annotation> values = mergeMap.values();
int size = values.size();
return size == 0 ? null : values.toArray(new Annotation[size]);
}
示例10: writeIfNotEmpty
import java.lang.annotation.Annotation; //导入依赖的package包/类
protected void writeIfNotEmpty(Properties prop, String key, Object value) throws InvocationTargetException, IllegalAccessException {
if(value != null && !"".equals(value.toString().trim())) {
if(value instanceof String[]){
String[] arr = (String[])value;
if(arr.length > 0){
prop.put(key, String.join(",", arr));
}
} else if(Object[].class.isInstance(value)) {
Object[] array = (Object[]) value;
for (int i=0; i<array.length; i++) {
if (propertyEnumAnnotationClass.isInstance(array[i])) {
Annotation enumAnn = (Annotation) array[i];
Properties props = gatherProperties(enumAnn, propertyEnumAnnotationClass);
for (String propName : props.stringPropertyNames()) {
prop.put(key + "[" + i + "]." + propName, props.getProperty(propName));
}
}
}
} else {
prop.put(key, value.toString());
}
}
}
示例11: TestClassContext
import java.lang.annotation.Annotation; //导入依赖的package包/类
protected TestClassContext(Class testClass, AbstractTest testInstance, Class<? extends Annotation> annotationClassToInvokeMethods, ITestContext testContext) {
this.testClass = testClass;
this.testInstance = testInstance;
this.annotationClassToInvokeMethods = annotationClassToInvokeMethods;
if (testContext.getExcludedGroups() == null) {
this.excludedGroups = new String[0];
} else {
this.excludedGroups = Arrays.copyOf(testContext.getExcludedGroups(), testContext.getExcludedGroups().length);
}
if (testContext.getIncludedGroups() == null) {
this.includedGroups = new String[0];
} else {
this.includedGroups = Arrays.copyOf(testContext.getIncludedGroups(), testContext.getIncludedGroups().length);
}
this.testContext = testContext;
}
示例12: scanSpecific
import java.lang.annotation.Annotation; //导入依赖的package包/类
private void scanSpecific(final Field field) {
// Vert.x Defined
final Set<Class<? extends Annotation>> defineds
= Plugins.INFIX_MAP.keySet();
final Annotation[] annotations = field.getDeclaredAnnotations();
// Annotation counter
final Set<String> set = new HashSet<>();
final Annotation hitted = Observable.fromArray(annotations)
.filter(annotation -> defineds.contains(annotation.annotationType()))
.map(annotation -> {
set.add(annotation.annotationType().getName());
return annotation;
}).blockingFirst();
// Duplicated annotated
Fn.flingUp(Values.ONE < set.size(), LOGGER,
MultiAnnotatedException.class, getClass(),
field.getName(), field.getDeclaringClass().getName(), set);
// Fill typed directly.
LOGGER.info(Info.SCANED_FIELD, this.reference,
field.getName(),
field.getDeclaringClass().getName(),
hitted.annotationType().getName());
this.fieldMap.put(field.getName(), field.getType());
}
示例13: TypesModel
import java.lang.annotation.Annotation; //导入依赖的package包/类
public TypesModel(final Set<Class<?>> classes, final Set<String> packages, final Set<Class<? extends Annotation>> ignoreAnnotations) {
this.ignoreAnnotations = ignoreAnnotations != null ? ignoreAnnotations : Collections.emptySet();
// first index all direct classes
if (classes != null) {
for (Class<?> aClass : classes) {
indexClass(aClass);
}
}
if (packages != null && !packages.isEmpty()) {
Indexer indexer = getIndexer();
for (String aPackage : packages) {
for (Class<?> clazz : indexer.getClassesForPackage(aPackage)) {
indexClass(clazz);
}
}
}
this.classHierarchy = buildClassHierarchy(allClasses);
}
示例14: getAnnotations
import java.lang.annotation.Annotation; //导入依赖的package包/类
/**
* 获取constructors数组中匹配的annotationClass注解
*
* @param constructors constructor对象数组
* @param annotationClass annotationClass注解
* @return List
*/
public static <T extends Annotation> List<T> getAnnotations(
Constructor[] constructors, Class annotationClass) {
if (isEmpty(constructors)) {
return null;
}
List<T> result = new ArrayList<T>();
for (Constructor constructor : constructors) {
Annotation annotation = getAnnotation(constructor, annotationClass);
if (annotation != null) {
result.add((T) annotation);
}
}
return result;
}
示例15: responseConverterFactoryQueried
import java.lang.annotation.Annotation; //导入依赖的package包/类
@Test public void responseConverterFactoryQueried() {
Type type = String.class;
Annotation[] annotations = new Annotation[0];
Converter<ResponseBody, ?> expectedAdapter = mock(Converter.class);
Converter.Factory factory = mock(Converter.Factory.class);
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://example.com/")
.addConverterFactory(factory)
.build();
doReturn(expectedAdapter).when(factory).responseBodyConverter(type, annotations, retrofit);
Converter<ResponseBody, ?> actualAdapter = retrofit.responseBodyConverter(type, annotations);
assertThat(actualAdapter).isSameAs(expectedAdapter);
verify(factory).responseBodyConverter(type, annotations, retrofit);
verifyNoMoreInteractions(factory);
}