java类java.lang.annotation.Annotation的实例源码

Symbol.java 文件源码 项目:OpenJSharp 阅读 38 收藏 0 点赞 0 评论 0
@Override
protected <A extends Annotation> A[] getInheritedAnnotations(Class<A> annoType) {

    ClassSymbol sup = getSuperClassToSearchForAnnotations();

    return sup == null ? super.getInheritedAnnotations(annoType)
                       : sup.getAnnotationsByType(annoType);
}
AnnotatedConverters.java 文件源码 项目:GitHub 阅读 31 收藏 0 点赞 0 评论 0
public Builder add(Class<? extends Annotation> cls, Converter.Factory factory) {
  if (cls == null) {
    throw new NullPointerException("cls == null");
  }
  if (factory == null) {
    throw new NullPointerException("factory == null");
  }
  factories.put(cls, factory);
  return this;
}
JPAOverriddenAnnotationReader.java 文件源码 项目:lams 阅读 205 收藏 0 点赞 0 评论 0
private Annotation getConvertsForAttribute(List<Element> elementsForProperty, XMLContext.Default defaults) {
    // NOTE : we use a map here to make sure that an xml and annotation referring to the same attribute
    // properly overrides.  Very sparse map, yes, but easy setup.
    // todo : revisit this
    // although bear in mind that this code is no longer used in 5.0...

    final Map<String,Convert> convertAnnotationsMap = new HashMap<String, Convert>();

    for ( Element element : elementsForProperty ) {
        final boolean isBasic = "basic".equals( element.getName() );
        final boolean isEmbedded = "embedded".equals( element.getName() );

        // todo : can be collections too

        final boolean canHaveConverts = isBasic || isEmbedded;

        if ( !canHaveConverts ) {
            continue;
        }

        final String attributeNamePrefix = isBasic ? null : propertyName;
        applyXmlDefinedConverts( element, defaults, attributeNamePrefix, convertAnnotationsMap );
    }

    // NOTE : per section 12.2.3.16 of the spec <convert/> is additive, although only if "metadata-complete" is not
    // specified in the XML

    if ( defaults.canUseJavaAnnotations() ) {
        // todo : note sure how to best handle attributeNamePrefix here
        applyPhysicalConvertAnnotations( propertyName, convertAnnotationsMap );
    }

    if ( !convertAnnotationsMap.isEmpty() ) {
        final AnnotationDescriptor groupingDescriptor = new AnnotationDescriptor( Converts.class );
        groupingDescriptor.setValue( "value", convertAnnotationsMap.values().toArray( new Convert[convertAnnotationsMap.size()]) );
        return AnnotationFactory.create( groupingDescriptor );
    }

    return null;
}
BehaviorDelegate.java 文件源码 项目:GitHub 阅读 20 收藏 0 点赞 0 评论 0
@SuppressWarnings("unchecked") // Single-interface proxy creation guarded by parameter safety.
public <R> T returning(Call<R> call) {
  final Call<R> behaviorCall = new BehaviorCall<>(behavior, executor, call);
  return (T) Proxy.newProxyInstance(service.getClassLoader(), new Class[] { service },
      new InvocationHandler() {
        @Override
        public T invoke(Object proxy, Method method, Object[] args) throws Throwable {
          Type returnType = method.getGenericReturnType();
          Annotation[] methodAnnotations = method.getAnnotations();
          CallAdapter<R, T> callAdapter =
              (CallAdapter<R, T>) retrofit.callAdapter(returnType, methodAnnotations);
          return callAdapter.adapt(behaviorCall);
        }
      });
}
GsonConverterFactory.java 文件源码 项目:XSnow 阅读 25 收藏 0 点赞 0 评论 0
@Override
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
    if (type != null && type.equals(String.class)) {
        return new JsonResponseBodyConverter<>();
    }
    TypeAdapter<?> adapter = null;
    if (type != null) {
        adapter = gson.getAdapter(TypeToken.get(type));
    }
    return new GsonResponseBodyConverter<>(gson, adapter);
}
MapBinder.java 文件源码 项目:Elasticsearch 阅读 29 收藏 0 点赞 0 评论 0
/**
 * Returns a new mapbinder that collects entries of {@code keyType}/{@code valueType} in a
 * {@link Map} that is itself bound with {@code annotation}.
 */
public static <K, V> MapBinder<K, V> newMapBinder(Binder binder,
                                                  TypeLiteral<K> keyType, TypeLiteral<V> valueType, Annotation annotation) {
    binder = binder.skipSources(MapBinder.class, RealMapBinder.class);
    return newMapBinder(binder, valueType,
            Key.get(mapOf(keyType, valueType), annotation),
            Key.get(mapOfProviderOf(keyType, valueType), annotation),
            Multibinder.newSetBinder(binder, entryOfProviderOf(keyType, valueType), annotation));
}
UnixTimestampParameterHandler.java 文件源码 项目:bootstrap 阅读 90 收藏 0 点赞 0 评论 0
@SuppressWarnings("unchecked")
@Override
public <T> ParamConverter<T> getConverter(final Class<T> rawType, final Type genericType, final Annotation[] annotations) { // NOSONAR

    // Basic date handler
    if (rawType.equals(Date.class)) {
        return (ParamConverter<T>) converter;
    }

    // LocalDate handler
    if (rawType.equals(LocalDate.class)) {
        return (ParamConverter<T>) localDateconverter;
    }
    return null;
}
AbstractMultiTestRunner.java 文件源码 项目:Reer 阅读 33 收藏 0 点赞 0 评论 0
public <A extends Annotation> A getAnnotation(Class<A> type) {
    A annotation = test.getAnnotation(type);
    if (annotation != null) {
        return annotation;
    }
    return parent.getAnnotation(type);
}
ClassInfoImpl.java 文件源码 项目:OpenJSharp 阅读 26 收藏 0 点赞 0 评论 0
/**
 * Gets an annotation that are allowed on both class and type.
 */
private <T extends Annotation> T getClassOrPackageAnnotation(Class<T> type) {
    T t = reader().getClassAnnotation(type,clazz,this);
    if(t!=null)
        return t;
    // defaults to the package level
    return reader().getPackageAnnotation(type,clazz,this);
}
SizeValidator.java 文件源码 项目:GPigValidator 阅读 28 收藏 0 点赞 0 评论 0
@Override
public Optional<String> getErrorMessage(Object objectValue, Annotation annotation) {
    if (isCorrect(objectValue, annotation))
        return Optional.absent();

    Size sizeAnnotation = (Size) annotation;

    if (objectValue instanceof String) {
        return Optional.of(createErrorMessageForString(sizeAnnotation));
    } else {
        return Optional.of(createErrorMessageForCollection(sizeAnnotation));
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号