Java 类com.fasterxml.jackson.databind.introspect.AnnotatedClass 实例源码

项目:crnk-framework    文件:AnnotatedClassBuilder.java   
public static AnnotatedClass build(final Class<?> declaringClass, final SerializationConfig serializationConfig) {

        for (final Method method : AnnotatedClass.class.getMethods()) {
            if (CONSTRUCT_METHOD_NAME.equals(method.getName()) &&
                    method.getParameterTypes().length == 3) {

                return ExceptionUtil.wrapCatchedExceptions(new Callable<AnnotatedClass>() {
                    @Override
                    public AnnotatedClass call() throws Exception {
                        return buildAnnotatedClass(method, declaringClass, serializationConfig);
                    }
                }, "Exception while building AnnotatedClass");
            }
        }
        throw new IllegalStateException(CANNOT_FIND_PROPER_METHOD);
    }
项目:crnk-framework    文件:JacksonResourceFieldInformationProvider.java   
protected Optional<String> getName(Method method) {
    ObjectMapper objectMapper = context.getObjectMapper();
    SerializationConfig serializationConfig = objectMapper.getSerializationConfig();
    if (serializationConfig != null && serializationConfig.getPropertyNamingStrategy() != null) {
        String name = ClassUtils.getGetterFieldName(method);
        Annotation[] declaredAnnotations = method.getDeclaredAnnotations();
        AnnotationMap annotationMap = buildAnnotationMap(declaredAnnotations);

        int paramsLength = method.getParameterAnnotations().length;
        AnnotationMap[] paramAnnotations = new AnnotationMap[paramsLength];
        for (int i = 0; i < paramsLength; i++) {
            AnnotationMap parameterAnnotationMap = buildAnnotationMap(method.getParameterAnnotations()[i]);
            paramAnnotations[i] = parameterAnnotationMap;
        }

        AnnotatedClass annotatedClass = AnnotatedClassBuilder.build(method.getDeclaringClass(), serializationConfig);
        AnnotatedMethod annotatedField = AnnotatedMethodBuilder.build(annotatedClass, method, annotationMap, paramAnnotations);
        return Optional.of(serializationConfig.getPropertyNamingStrategy().nameForGetterMethod(serializationConfig, annotatedField, name));
    }
    return Optional.empty();
}
项目:leopard    文件:DisablingJsonSerializerIntrospector.java   
@Override
public Object findDeserializer(Annotated a) {
    // System.err.println("Annotated:" + a.getClass().getName() + " " + a);

    if (a instanceof AnnotatedClass) {
        Class<?> clazz = ((AnnotatedClass) a).getAnnotated();
        // System.err.println("clazz:" + clazz.getName() + " " + a.getName());

        if (clazz.isEnum()) {
            if (Onum.class.isAssignableFrom(clazz)) {
                // System.err.println("OnumJsonSerializerIntrospector findDeserializer:" + clazz.getName() + " a:" + a);
                return new OnumJsonDeserializer(clazz);
            }
        }
    }

    Object deserializer = super.findDeserializer(a);
    return deserializer;
}
项目:jacksonatic    文件:AnnotatedClassConstructor.java   
@SuppressWarnings("unchecked")
private AnnotatedClass processAnnotatedClass(JacksonOperation processType, AnnotatedClass ac) {
    if (ac.getAnnotated().getName().startsWith("java.")) {
        return ac;
    }
    Class<Object> annotated = (Class<Object>) ac.getAnnotated();
    ClassesMapping serOrDeserClassesMapping = getSerOrDeserClassMapping(processType);
    ClassesMapping mergedClassesMapping = this.mergedClassesMappingByOperation.getTyped(processType);

    return Optional.ofNullable(mergedClassesMapping.getOpt(annotated)
            .orElseGet(() -> mergeAndPutInMergedClassesMapping(mergedClassesMapping, annotated,
                    serOrDeserClassesMapping.getOpt(annotated),
                    classesMappingByOperation.get(ANY).getOpt(annotated),
                    getClassMappingFromSuperTypes(annotated, serOrDeserClassesMapping, mergedClassesMapping))))
            .map(classMapping -> classAnnotationDecorator.decorate(ac, classMapping))
            .orElse(ac);
}
项目:katharsis-framework    文件:ResourceFieldNameTransformer.java   
/**
 * Extract name to be used by Katharsis from getter's name. It uses
 * {@link ResourceFieldNameTransformer#getMethodName(Method)}, {@link JsonProperty} annotation and
 * {@link PropertyNamingStrategy}.
 *
 * @param method method to extract name
 * @return method name
 */
public String getName(Method method) {
    String name = getMethodName(method);

    if (method.isAnnotationPresent(JsonProperty.class) &&
        !"".equals(method.getAnnotation(JsonProperty.class).value())) {
        name = method.getAnnotation(JsonProperty.class).value();
    } else if (serializationConfig != null && serializationConfig.getPropertyNamingStrategy() != null) {
        Annotation[] declaredAnnotations = method.getDeclaredAnnotations();
        AnnotationMap annotationMap = buildAnnotationMap(declaredAnnotations);

        int paramsLength = method.getParameterAnnotations().length;
        AnnotationMap[] paramAnnotations = new AnnotationMap[paramsLength];
        for (int i = 0; i < paramsLength; i++) {
            AnnotationMap parameterAnnotationMap = buildAnnotationMap(method.getParameterAnnotations()[i]);
            paramAnnotations[i] = parameterAnnotationMap;
        }

        AnnotatedClass annotatedClass = AnnotatedClassBuilder.build(method.getDeclaringClass(), serializationConfig);
        AnnotatedMethod annotatedField = AnnotatedMethodBuilder.build(annotatedClass, method, annotationMap, paramAnnotations);
        name = serializationConfig.getPropertyNamingStrategy().nameForGetterMethod(serializationConfig, annotatedField, name);
    }
    return name;
}
项目:jackson-modules-java8    文件:JavaTimeModule.java   
protected AnnotatedMethod _findFactory(AnnotatedClass cls, String name, Class<?>... argTypes)
{
    final int argCount = argTypes.length;
    for (AnnotatedMethod method : cls.getFactoryMethods()) {
        if (!name.equals(method.getName())
                || (method.getParameterCount() != argCount)) {
            continue;
        }
        for (int i = 0; i < argCount; ++i) {
            Class<?> argType = method.getParameter(i).getRawType();
            if (!argType.isAssignableFrom(argTypes[i])) {
                continue;
            }
        }
        return method;
    }
    return null;
}
项目:bootique    文件:BQTimeModule.java   
protected AnnotatedMethod _findFactory(AnnotatedClass cls, String name, Class<?>... argTypes) {
    final int argCount = argTypes.length;
    for (AnnotatedMethod method : cls.getStaticMethods()) {
        if (!name.equals(method.getName())
                || (method.getParameterCount() != argCount)) {
            continue;
        }
        for (int i = 0; i < argCount; ++i) {
            Class<?> argType = method.getParameter(i).getRawType();
            if (!argType.isAssignableFrom(argTypes[i])) {
                continue;
            }
        }
        return method;
    }
    return null;
}
项目:QuizUpWinner    文件:StdSubtypeResolver.java   
public Collection<NamedType> collectAndResolveSubtypes(AnnotatedClass paramAnnotatedClass, MapperConfig<?> paramMapperConfig, AnnotationIntrospector paramAnnotationIntrospector)
{
  HashMap localHashMap = new HashMap();
  if (this._registeredSubtypes != null)
  {
    Class localClass = paramAnnotatedClass.getRawType();
    Iterator localIterator = this._registeredSubtypes.iterator();
    while (localIterator.hasNext())
    {
      NamedType localNamedType = (NamedType)localIterator.next();
      if (localClass.isAssignableFrom(localNamedType.getType()))
        _collectAndResolve(AnnotatedClass.constructWithoutSuperTypes(localNamedType.getType(), paramAnnotationIntrospector, paramMapperConfig), localNamedType, paramMapperConfig, paramAnnotationIntrospector, localHashMap);
    }
  }
  _collectAndResolve(paramAnnotatedClass, new NamedType(paramAnnotatedClass.getRawType(), null), paramMapperConfig, paramAnnotationIntrospector, localHashMap);
  return new ArrayList(localHashMap.values());
}
项目:QuizUpWinner    文件:BasicSerializerFactory.java   
public TypeSerializer createTypeSerializer(SerializationConfig paramSerializationConfig, JavaType paramJavaType)
{
  AnnotatedClass localAnnotatedClass = paramSerializationConfig.introspectClassAnnotations(paramJavaType.getRawClass()).getClassInfo();
  AnnotationIntrospector localAnnotationIntrospector = paramSerializationConfig.getAnnotationIntrospector();
  TypeResolverBuilder localTypeResolverBuilder = localAnnotationIntrospector.findTypeResolver(paramSerializationConfig, localAnnotatedClass, paramJavaType);
  Collection localCollection;
  if (localTypeResolverBuilder == null)
  {
    localTypeResolverBuilder = paramSerializationConfig.getDefaultTyper(paramJavaType);
    localCollection = null;
  }
  else
  {
    localCollection = paramSerializationConfig.getSubtypeResolver().collectAndResolveSubtypes(localAnnotatedClass, paramSerializationConfig, localAnnotationIntrospector);
  }
  if (localTypeResolverBuilder == null)
    return null;
  return localTypeResolverBuilder.buildTypeSerializer(paramSerializationConfig, paramJavaType, localCollection);
}
项目:QuizUpWinner    文件:BasicDeserializerFactory.java   
public TypeDeserializer findTypeDeserializer(DeserializationConfig paramDeserializationConfig, JavaType paramJavaType)
{
  AnnotatedClass localAnnotatedClass = paramDeserializationConfig.introspectClassAnnotations(paramJavaType.getRawClass()).getClassInfo();
  AnnotationIntrospector localAnnotationIntrospector = paramDeserializationConfig.getAnnotationIntrospector();
  Object localObject = localAnnotationIntrospector.findTypeResolver(paramDeserializationConfig, localAnnotatedClass, paramJavaType);
  Collection localCollection;
  if (localObject == null)
  {
    TypeResolverBuilder localTypeResolverBuilder = paramDeserializationConfig.getDefaultTyper(paramJavaType);
    localObject = localTypeResolverBuilder;
    localCollection = null;
    if (localTypeResolverBuilder == null)
      return null;
  }
  else
  {
    localCollection = paramDeserializationConfig.getSubtypeResolver().collectAndResolveSubtypes(localAnnotatedClass, paramDeserializationConfig, localAnnotationIntrospector);
  }
  if ((((TypeResolverBuilder)localObject).getDefaultImpl() == null) && (paramJavaType.isAbstract()))
  {
    JavaType localJavaType = mapAbstractType(paramDeserializationConfig, paramJavaType);
    if ((localJavaType != null) && (localJavaType.getRawClass() != paramJavaType.getRawClass()))
      localObject = ((TypeResolverBuilder)localObject).defaultImpl(localJavaType.getRawClass());
  }
  return ((TypeResolverBuilder)localObject).buildTypeDeserializer(paramDeserializationConfig, paramJavaType, localCollection);
}
项目:swagger-maven-plugin    文件:EnhancedSwaggerAnnotationIntrospector.java   
@Override
public PropertyName findRootName(AnnotatedClass ac) {
    ApiModel model = ac.getAnnotation(ApiModel.class);
    if (model != null) {
        return new PropertyName(model.value());
    } else {
        return super.findRootName(ac);
    }
}
项目:crnk-framework    文件:AnnotatedClassBuilder.java   
private static AnnotatedClass buildAnnotatedClass(Method method, Class<?> declaringClass,
        SerializationConfig serializationConfig)
        throws InvocationTargetException, IllegalAccessException {
    if (method.getParameterTypes()[0] == Class.class) {
        return buildOldAnnotatedClass(method, declaringClass, serializationConfig);
    }
    else {
        PreconditionUtil.assertEquals("unexpected method signature", method.getParameterTypes()[0], JavaType.class);
        return buildNewAnnotatedClass(method, declaringClass, serializationConfig);
    }
}
项目:crnk-framework    文件:AnnotatedClassBuilder.java   
private static AnnotatedClass buildOldAnnotatedClass(Method method, Class<?> declaringClass,
        SerializationConfig serializationConfig)
        throws InvocationTargetException, IllegalAccessException {
    boolean useAnnotations = serializationConfig.isAnnotationProcessingEnabled();
    AnnotationIntrospector aintr = useAnnotations ? serializationConfig.getAnnotationIntrospector() : null;
    return AnnotatedClass.class.cast(method.invoke(null, declaringClass, aintr, serializationConfig));
}
项目:crnk-framework    文件:AnnotatedFieldBuilder.java   
public static AnnotatedField build(final AnnotatedClass annotatedClass, final Field field,
        final AnnotationMap annotationMap) {
    final Constructor<?> constructor = AnnotatedField.class.getConstructors()[0];
    return ExceptionUtil.wrapCatchedExceptions(new Callable<AnnotatedField>() {
        @Override
        public AnnotatedField call() throws Exception {
            return buildAnnotatedField(annotatedClass, field, annotationMap, constructor);
        }
    }, "Exception while building AnnotatedField");
}
项目:crnk-framework    文件:AnnotatedFieldBuilder.java   
private static AnnotatedField buildAnnotatedField(AnnotatedClass annotatedClass, Field field,
        AnnotationMap annotationMap, Constructor<?> constructor)
        throws IllegalAccessException, InstantiationException, InvocationTargetException {
    Class<?> firstParameterType = constructor.getParameterTypes()[0];

    PreconditionUtil.assertTrue(CANNOT_FIND_PROPER_CONSTRUCTOR, firstParameterType == AnnotatedClass.class ||
            TypeResolutionContext.class.equals(firstParameterType));
    return (AnnotatedField) constructor.newInstance(annotatedClass, field, annotationMap);
}
项目:crnk-framework    文件:AnnotatedMethodBuilder.java   
public static AnnotatedMethod build(final AnnotatedClass annotatedClass, final Method method,
        final AnnotationMap annotationMap,
        final AnnotationMap[] paramAnnotations) {

    final Constructor<?> constructor = AnnotatedMethod.class.getConstructors()[0];

    return ExceptionUtil.wrapCatchedExceptions(new Callable<AnnotatedMethod>() {
        @Override
        public AnnotatedMethod call() throws Exception {
            return buildAnnotatedField(annotatedClass, method, annotationMap, paramAnnotations, constructor);
        }
    }, "Exception while building AnnotatedMethod");
}
项目:crnk-framework    文件:AnnotatedMethodBuilder.java   
private static AnnotatedMethod buildAnnotatedField(AnnotatedClass annotatedClass, Method method,
        AnnotationMap annotationMap, AnnotationMap[] paramAnnotations,
        Constructor<?> constructor)
        throws IllegalAccessException, InstantiationException, InvocationTargetException {
    Class<?> firstParameterType = constructor.getParameterTypes()[0];

    PreconditionUtil.assertTrue(CANNOT_FIND_PROPER_CONSTRUCTOR,
            firstParameterType == AnnotatedClass.class || TypeResolutionContext.class.equals(firstParameterType));
    return (AnnotatedMethod) constructor.newInstance(annotatedClass, method, annotationMap, paramAnnotations);
}
项目:crnk-framework    文件:JacksonResourceFieldInformationProvider.java   
protected Optional<String> getName(Field field) {
    ObjectMapper objectMapper = context.getObjectMapper();
    SerializationConfig serializationConfig = objectMapper.getSerializationConfig();

    if (serializationConfig != null && serializationConfig.getPropertyNamingStrategy() != null) {
        AnnotationMap annotationMap = buildAnnotationMap(field.getDeclaredAnnotations());

        AnnotatedClass annotatedClass = AnnotatedClassBuilder.build(field.getDeclaringClass(), serializationConfig);
        AnnotatedField annotatedField = AnnotatedFieldBuilder.build(annotatedClass, field, annotationMap);
        return Optional.of(serializationConfig.getPropertyNamingStrategy().nameForField(serializationConfig, annotatedField, field.getName()));
    }
    return Optional.empty();
}
项目:jacksonatic    文件:AnnotatedClassLogger.java   
public static void log(AnnotatedClass annotatedClass) {
    if (LOGGER.isDebugEnabled()) {
        StringBuilder sb = new StringBuilder();
        sb.append(ln);
        logClassAnnotations(annotatedClass, sb);
        logFieldAnnotations(annotatedClass, sb);
        logConstructorAnnotations(annotatedClass, sb);
        logStaticFactoryAnnotations(annotatedClass, sb);
        logMethodAnnotations(annotatedClass, sb);
        String toLog = sb.toString();
        if (!toLog.isEmpty()) {
            LOGGER.debug("Annotations added for : {}", toLog);
        }
    }
}
项目:jacksonatic    文件:AnnotatedClassLogger.java   
private static void logConstructorAnnotations(AnnotatedClass annotatedClass, StringBuilder sb) {
    stream(annotatedClass.getConstructors())
            .filter(annotatedConstructor -> hasAnnotationOrParameterAnnotation(annotatedConstructor))
            .forEach(annotatedConstructor -> {
                List<Class<?>> parameterTypes = IntStream.range(0, annotatedConstructor.getParameterCount()).mapToObj(index -> annotatedConstructor.getRawParameterType(index)).collect(Collectors.toList());
                sb.append("> Constructor[" + methodSignature(annotatedClass.getAnnotated().getSimpleName(), parameterTypes) + "] : " + annotationsItToStr(annotatedConstructor.annotations()))
                        .append(ln);
                logParameters(sb, annotatedConstructor);
            });
}
项目:jacksonatic    文件:AnnotatedClassLogger.java   
private static void logStaticFactoryAnnotations(AnnotatedClass annotatedClass, StringBuilder sb) {
    stream(annotatedClass.getStaticMethods())
            .filter(annotatedMethod -> hasAnnotationOrParameterAnnotation(annotatedMethod))
            .forEach(annotatedMethod -> {
                sb.append("> StaticFactory[" + methodSignature(annotatedMethod.getName(), annotatedMethod.getRawParameterTypes()) + "] : " + annotationsItToStr(annotatedMethod.annotations()))
                        .append(ln);
                logParameters(sb, annotatedMethod);
            });
}
项目:jacksonatic    文件:AnnotatedClassLogger.java   
private static void logMethodAnnotations(AnnotatedClass annotatedClass, StringBuilder sb) {
    stream(annotatedClass.memberMethods())
            .filter(annotatedMethod -> hasAnnotationOrParameterAnnotation(annotatedMethod))
            .forEach(annotatedMethod -> {
                sb.append("> Method[" + methodSignature(annotatedMethod.getName(), annotatedMethod.getRawParameterTypes()) + "] : " + annotationsItToStr(annotatedMethod.annotations()))
                        .append(ln);
                logParameters(sb, annotatedMethod);
            });
}
项目:jacksonatic    文件:JacksonaticClassIntrospector.java   
@Override
public BasicBeanDescription forClassAnnotations(MapperConfig<?> cfg, JavaType type, MixInResolver r) {
    BasicBeanDescription desc = _findStdTypeDesc(type);
    if (desc == null) {
        desc = _cachedFCA.get(type);
        if (desc == null) {
            boolean useAnnotations = cfg.isAnnotationProcessingEnabled();
            AnnotatedClass ac = annotatedClassConstructor.constructForSerialization(type.getRawClass(),
                    (useAnnotations ? cfg.getAnnotationIntrospector() : null), r);
            desc = BasicBeanDescription.forOtherUse(cfg, type, ac);
            _cachedFCA.put(type, desc);
        }
    }
    return desc;
}
项目:jacksonatic    文件:JacksonaticClassIntrospector.java   
@Override
public BasicBeanDescription forDirectClassAnnotations(MapperConfig<?> cfg, JavaType type, MixInResolver r) {
    BasicBeanDescription desc = _findStdTypeDesc(type);
    if (desc == null) {
        boolean useAnnotations = cfg.isAnnotationProcessingEnabled();
        AnnotationIntrospector ai = cfg.getAnnotationIntrospector();
        AnnotatedClass ac = annotatedClassConstructor.constructWithoutSuperTypes(type.getRawClass(),
                (useAnnotations ? ai : null), r);
        desc = BasicBeanDescription.forOtherUse(cfg, type, ac);
    }
    return desc;
}
项目:jacksonatic    文件:JacksonaticClassIntrospector.java   
@Override
protected POJOPropertiesCollector collectProperties(MapperConfig<?> config, JavaType type, MixInResolver r, boolean forSerialization, String mutatorPrefix) {
    boolean useAnnotations = config.isAnnotationProcessingEnabled();
    AnnotatedClass ac;
    if (forSerialization) {
         ac = annotatedClassConstructor.constructForSerialization(type.getRawClass(),
                (useAnnotations ? config.getAnnotationIntrospector() : null), r);
    } else {
         ac = annotatedClassConstructor.constructForDeserialization(type.getRawClass(),
                (useAnnotations ? config.getAnnotationIntrospector() : null), r);
    }
    POJOPropertiesCollector propertyCollector = constructPropertyCollector(config, ac, type, forSerialization, mutatorPrefix);
    return propertyCollector.collect();
}
项目:jacksonatic    文件:JacksonaticClassIntrospector.java   
protected POJOPropertiesCollector collectPropertiesWithBuilder(MapperConfig<?> config, JavaType type, MixInResolver r, boolean forSerialization) {
    boolean useAnnotations = config.isAnnotationProcessingEnabled();
    AnnotationIntrospector ai = useAnnotations ? config.getAnnotationIntrospector() : null;
    AnnotatedClass ac;
    if (forSerialization) {
        ac = annotatedClassConstructor.constructForSerialization(type.getRawClass(), ai, r);
    } else {
        ac = annotatedClassConstructor.constructForDeserialization(type.getRawClass(), ai, r);
    }
    JsonPOJOBuilder.Value builderConfig = (ai == null) ? null : ai.findPOJOBuilderConfig(ac);
    String mutatorPrefix = (builderConfig == null) ? "with" : builderConfig.withPrefix;
    return constructPropertyCollector(config, ac, type, forSerialization, mutatorPrefix).collect();
}
项目:katharsis-framework    文件:ResourceFieldNameTransformer.java   
public String getName(Field field) {

        String name = field.getName();
        if (field.isAnnotationPresent(JsonProperty.class) &&
            !"".equals(field.getAnnotation(JsonProperty.class).value())) {
            name = field.getAnnotation(JsonProperty.class).value();
        } else if (serializationConfig != null && serializationConfig.getPropertyNamingStrategy() != null) {
            AnnotationMap annotationMap = buildAnnotationMap(field.getDeclaredAnnotations());

            AnnotatedClass annotatedClass = AnnotatedClassBuilder.build(field.getDeclaringClass(), serializationConfig);
            AnnotatedField annotatedField = AnnotatedFieldBuilder.build(annotatedClass, field, annotationMap);
            name = serializationConfig.getPropertyNamingStrategy().nameForField(serializationConfig, annotatedField, name);
        }
        return name;
    }
项目:katharsis-framework    文件:AnnotatedClassBuilder.java   
public static AnnotatedClass build(Class<?> declaringClass, SerializationConfig serializationConfig) {

        for (Method method : AnnotatedClass.class.getMethods()) {
            if (CONSTRUCT_METHOD_NAME.equals(method.getName()) &&
                method.getParameterTypes().length == 3) {
                try {
                    return buildAnnotatedClass(method, declaringClass, serializationConfig);
                } catch (InvocationTargetException | IllegalAccessException e) {
                    throw new InternalException("Exception while building " + AnnotatedClass.class.getCanonicalName(), e);
                }
            }
        }

        throw new InternalException(CANNOT_FIND_PROPER_METHOD);
    }
项目:katharsis-framework    文件:AnnotatedClassBuilder.java   
private static AnnotatedClass buildAnnotatedClass(Method method, Class<?> declaringClass,
                                                  SerializationConfig serializationConfig)
    throws InvocationTargetException, IllegalAccessException {
    if (method.getParameterTypes()[0] == Class.class) {
        return buildOldAnnotatedClass(method, declaringClass, serializationConfig);
    } else if (method.getParameterTypes()[0] == JavaType.class) {
        return buildNewAnnotatedClass(method, declaringClass, serializationConfig);
    } else {
        throw new InternalException(CANNOT_FIND_PROPER_METHOD);
    }
}
项目:katharsis-framework    文件:AnnotatedClassBuilder.java   
private static AnnotatedClass buildOldAnnotatedClass(Method method, Class<?> declaringClass,
                                                     SerializationConfig serializationConfig)
    throws InvocationTargetException, IllegalAccessException {
    boolean useAnnotations = serializationConfig.isAnnotationProcessingEnabled();
    AnnotationIntrospector aintr = useAnnotations ? serializationConfig.getAnnotationIntrospector() : null;
    return AnnotatedClass.class.cast(method.invoke(null, declaringClass, aintr, serializationConfig));
}
项目:katharsis-framework    文件:AnnotatedFieldBuilder.java   
public static AnnotatedField build(AnnotatedClass annotatedClass, Field field, AnnotationMap annotationMap) {
    for(Constructor<?> constructor : AnnotatedField.class.getConstructors()) {
        try {
            return buildAnnotatedField(annotatedClass, field, annotationMap, constructor);
        } catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
            throw new InternalException("Exception while building " + AnnotatedField.class.getCanonicalName(), e);
        }
    }
    throw new InternalException(CANNOT_FIND_PROPER_CONSTRUCTOR);
}
项目:katharsis-framework    文件:AnnotatedFieldBuilder.java   
private static AnnotatedField buildAnnotatedField(AnnotatedClass annotatedClass, Field field,
                                                  AnnotationMap annotationMap, Constructor<?> constructor)
        throws IllegalAccessException, InstantiationException, InvocationTargetException {
    Class<?> firstParameterType = constructor.getParameterTypes()[0];
    if (firstParameterType == AnnotatedClass.class ||
            "TypeResolutionContext".equals(firstParameterType.getSimpleName())) {
        return (AnnotatedField) constructor.newInstance(annotatedClass, field, annotationMap);
    } else {
        throw new InternalException(CANNOT_FIND_PROPER_CONSTRUCTOR);
    }
}
项目:katharsis-framework    文件:AnnotatedMethodBuilder.java   
public static AnnotatedMethod build(AnnotatedClass annotatedClass, Method method, AnnotationMap annotationMap,
                                    AnnotationMap[] paramAnnotations) {
    for(Constructor<?> constructor : AnnotatedMethod.class.getConstructors()) {
        try {
            return buildAnnotatedField(annotatedClass, method, annotationMap, paramAnnotations, constructor);
        } catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
            throw new InternalException("Exception while building " + AnnotatedMethod.class.getCanonicalName(), e);
        }
    }
    throw new InternalException(CANNOT_FIND_PROPER_CONSTRUCTOR);
}
项目:katharsis-framework    文件:AnnotatedMethodBuilder.java   
private static AnnotatedMethod buildAnnotatedField(AnnotatedClass annotatedClass, Method method,
                                                   AnnotationMap annotationMap, AnnotationMap[] paramAnnotations,
                                                   Constructor<?> constructor)
        throws IllegalAccessException, InstantiationException, InvocationTargetException {
    Class<?> firstParameterType = constructor.getParameterTypes()[0];
    if (firstParameterType == AnnotatedClass.class ||
            "TypeResolutionContext".equals(firstParameterType.getSimpleName())) {
        return (AnnotatedMethod) constructor.newInstance(annotatedClass, method, annotationMap, paramAnnotations);
    } else {
        throw new InternalException(CANNOT_FIND_PROPER_CONSTRUCTOR);
    }
}
项目:endpoints-java    文件:ApiAnnotationIntrospector.java   
@Nullable
private Transformer<?, ?> findSerializerInstance(Annotated a) {
  if (a instanceof AnnotatedClass) {
    AnnotatedClass clazz = (AnnotatedClass) a;
    List<Class<? extends Transformer<?, ?>>> serializerClasses =
        Serializers.getSerializerClasses(clazz.getRawType(), config);
    if (!serializerClasses.isEmpty()) {
      return Serializers.instantiate(serializerClasses.get(0), TypeToken.of(a.getRawType()));
    }
  }
  return null;
}
项目:evt-bridge    文件:ElasticSearchAnnotationIntrospector.java   
private Object findSerializerToUse(Annotated a) {
    if (a instanceof AnnotatedField || a instanceof AnnotatedMethod) {
        IndexableComponent indexableComponent = a.getAnnotation(IndexableComponent.class);
        if (indexableComponent != null && indexableComponent.serializer() != JsonSerializer.class) {
            return indexableComponent.serializer();
        }

        IndexableProperty indexableProperty = a.getAnnotation(IndexableProperty.class);
        if (indexableProperty != null) {
            if (indexableProperty.serializer() != JsonSerializer.class) {
                return indexableProperty.serializer();
            }
            if (isDate(a)) {  // use custom date serializer
                return DateSerializer.class;
            }

        }
        IndexableProperties indexableProperties = a.getAnnotation(IndexableProperties.class);
        if (indexableProperties != null && indexableProperties.serializer() != JsonSerializer.class) {
            return indexableProperties.serializer();
        }

    } else if (a instanceof AnnotatedClass) {  // handle class
        Indexable indexable = a.getAnnotation(Indexable.class);
        if (indexable != null && indexable.serializer() != JsonSerializer.class) {
            return indexable.serializer();
        }
    }
    return null;
}
项目:evt-bridge    文件:ElasticSearchAnnotationIntrospector.java   
@SuppressWarnings("unchecked")
private Class<? extends JsonDeserializer<?>> findDeserializerToUse(Annotated a) {
    if (a instanceof AnnotatedField || a instanceof AnnotatedMethod) {
        IndexableComponent indexableComponent = a.getAnnotation(IndexableComponent.class);
        if (indexableComponent != null && indexableComponent.deserializer() != JsonDeserializer.class) {
            return (Class<? extends JsonDeserializer<?>>) indexableComponent.deserializer();
        }

        IndexableProperty indexableProperty = a.getAnnotation(IndexableProperty.class);
        if (indexableProperty != null) {
            if (indexableProperty.deserializer() != JsonDeserializer.class) {
                return (Class<? extends JsonDeserializer<?>>) indexableProperty.deserializer();
            }
            if (isDate(a)) { // use custom date deserializer
                return DateDeserializer.class;
            }
            if (indexableProperty.type().equals(TypeEnum.JSON)) {  // use custom deserializer for raw json field
                return RawJsonDeSerializer.class;
            }
        }

        IndexableProperties indexableProperties = a.getAnnotation(IndexableProperties.class);
        if (indexableProperties != null && indexableProperties.deserializer() != JsonDeserializer.class) {
            return (Class<? extends JsonDeserializer<?>>) indexableProperties.deserializer();
        }
    } else if (a instanceof AnnotatedClass) {  // handle class
        Indexable indexable = a.getAnnotation(Indexable.class);
        if (indexable != null && indexable.deserializer() != JsonDeserializer.class) {
            return (Class<? extends JsonDeserializer<?>>) indexable.deserializer();
        }
    }
    return null;
}
项目:bootique    文件:BQTimeModule.java   
@Override
public void setupModule(SetupContext context) {
    super.setupModule(context);
    context.addValueInstantiators(new ValueInstantiators.Base() {
        @Override
        public ValueInstantiator findValueInstantiator(DeserializationConfig config,
                                                       BeanDescription beanDesc, ValueInstantiator defaultInstantiator) {
            Class<?> raw = beanDesc.getBeanClass();
            // 15-May-2015, tatu: In theory not safe, but in practice we do need to do "fuzzy" matching
            // because we will (for now) be getting a subtype, but in future may want to downgrade
            // to the common base type. Even more, serializer may purposefully force use of base type.
            // So... in practice it really should always work, in the end. :)
            if (ZoneId.class.isAssignableFrom(raw)) {
                // let's assume we should be getting "empty" StdValueInstantiator here:
                if (defaultInstantiator instanceof StdValueInstantiator) {
                    StdValueInstantiator inst = (StdValueInstantiator) defaultInstantiator;
                    // one further complication: we need ZoneId info, not sub-class
                    AnnotatedClass ac;
                    if (raw == ZoneId.class) {
                        ac = beanDesc.getClassInfo();
                    } else {
                        // we don't need Annotations, so constructing directly is fine here
                        // even if it's not generally recommended
                        ac = AnnotatedClass.construct(ZoneId.class, null, null);
                    }
                    if (!inst.canCreateFromString()) {
                        AnnotatedMethod factory = _findFactory(ac, "of", String.class);
                        if (factory != null) {
                            inst.configureFromStringCreator(factory);
                        }
                        // otherwise... should we indicate an error?
                    }
                    // return ZoneIdInstantiator.construct(config, beanDesc, defaultInstantiator);
                }
            }
            return defaultInstantiator;
        }
    });
}
项目:core-ng-project    文件:JSONAnnotationIntrospector.java   
@Override
public VisibilityChecker<?> findAutoDetectVisibility(AnnotatedClass annotatedClass, VisibilityChecker<?> checker) {
    return checker.withFieldVisibility(Visibility.PUBLIC_ONLY)
                  .withSetterVisibility(Visibility.NONE)
                  .withGetterVisibility(Visibility.NONE)
                  .withIsGetterVisibility(Visibility.NONE);
}
项目:QuizUpWinner    文件:StdSubtypeResolver.java   
public Collection<NamedType> collectAndResolveSubtypes(AnnotatedMember paramAnnotatedMember, MapperConfig<?> paramMapperConfig, AnnotationIntrospector paramAnnotationIntrospector, JavaType paramJavaType)
{
  Class localClass;
  if (paramJavaType == null)
    localClass = paramAnnotatedMember.getRawType();
  else
    localClass = paramJavaType.getRawClass();
  HashMap localHashMap = new HashMap();
  if (this._registeredSubtypes != null)
  {
    Iterator localIterator2 = this._registeredSubtypes.iterator();
    while (localIterator2.hasNext())
    {
      NamedType localNamedType3 = (NamedType)localIterator2.next();
      if (localClass.isAssignableFrom(localNamedType3.getType()))
        _collectAndResolve(AnnotatedClass.constructWithoutSuperTypes(localNamedType3.getType(), paramAnnotationIntrospector, paramMapperConfig), localNamedType3, paramMapperConfig, paramAnnotationIntrospector, localHashMap);
    }
  }
  List localList = paramAnnotationIntrospector.findSubtypes(paramAnnotatedMember);
  if (localList != null)
  {
    Iterator localIterator1 = localList.iterator();
    while (localIterator1.hasNext())
    {
      NamedType localNamedType2 = (NamedType)localIterator1.next();
      _collectAndResolve(AnnotatedClass.constructWithoutSuperTypes(localNamedType2.getType(), paramAnnotationIntrospector, paramMapperConfig), localNamedType2, paramMapperConfig, paramAnnotationIntrospector, localHashMap);
    }
  }
  NamedType localNamedType1 = new NamedType(localClass, null);
  _collectAndResolve(AnnotatedClass.constructWithoutSuperTypes(localClass, paramAnnotationIntrospector, paramMapperConfig), localNamedType1, paramMapperConfig, paramAnnotationIntrospector, localHashMap);
  return new ArrayList(localHashMap.values());
}