当前位置: 首页>>代码示例>>Java>>正文


Java Annotation类代码示例

本文整理汇总了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)));
    }
}
 
开发者ID:primeval-io,项目名称:primeval-reflex,代码行数:17,代码来源:RepeatedAnnotationObjectInterceptor.java

示例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);
			}
		}
	}
}
 
开发者ID:NymphWeb,项目名称:nymph,代码行数:23,代码来源:ScannerNymphBeans.java

示例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;
    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:TypeInfo.java

示例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);
}
 
开发者ID:dropwizard,项目名称:dropwizard-vavr,代码行数:27,代码来源:ValueMessageBodyWriter.java

示例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;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:20,代码来源:Elements.java

示例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);
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:26,代码来源:Anno.java

示例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;
}
 
开发者ID:seasonfif,项目名称:SwiftModule,代码行数:22,代码来源:IntentMethod.java

示例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();
}
 
开发者ID:cerner,项目名称:beadledom,代码行数:21,代码来源:FilteringJacksonJsonProvider.java

示例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]);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:ExternalMetadataReader.java

示例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());
        }
    }
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:24,代码来源:SyndesisExtensionActionProcessor.java

示例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;
}
 
开发者ID:WileyLabs,项目名称:teasy,代码行数:17,代码来源:MethodsInvoker.java

示例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());
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:25,代码来源:AffluxThread.java

示例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);
}
 
开发者ID:axelspringer,项目名称:polymorphia,代码行数:21,代码来源:TypesModel.java

示例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;
}
 
开发者ID:egzosn,项目名称:spring-jdbc-orm,代码行数:26,代码来源:ReflectionUtils.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:RetrofitTest.java


注:本文中的java.lang.annotation.Annotation类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。