當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。