Java Code Examples for org.jboss.jandex.FieldInfo#type()

The following examples show how to use org.jboss.jandex.FieldInfo#type() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Types.java    From quarkus with Apache License 2.0 6 votes vote down vote up
static Set<Type> getProducerFieldTypeClosure(FieldInfo producerField, BeanDeployment beanDeployment) {
    Set<Type> types;
    Type fieldType = producerField.type();
    if (fieldType.kind() == Kind.PRIMITIVE || fieldType.kind() == Kind.ARRAY) {
        types = new HashSet<>();
        types.add(fieldType);
        types.add(OBJECT_TYPE);
    } else {
        ClassInfo fieldClassInfo = getClassByName(beanDeployment.getIndex(), producerField.type());
        if (fieldClassInfo == null) {
            throw new IllegalArgumentException("Producer field type not found in index: " + producerField.type().name());
        }
        if (Kind.CLASS.equals(fieldType.kind())) {
            types = getTypeClosure(fieldClassInfo, producerField, Collections.emptyMap(), beanDeployment, null);
        } else if (Kind.PARAMETERIZED_TYPE.equals(fieldType.kind())) {
            types = getTypeClosure(fieldClassInfo, producerField,
                    buildResolvedMap(fieldType.asParameterizedType().arguments(), fieldClassInfo.typeParameters(),
                            Collections.emptyMap(), beanDeployment.getIndex()),
                    beanDeployment, null);
        } else {
            throw new IllegalArgumentException("Unsupported return type");
        }
    }
    return restrictBeanTypes(types, beanDeployment.getAnnotations(producerField));
}
 
Example 2
Source File: ResteasyCommonProcessor.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private void checkProperConfigAccessInProvider(AnnotationInstance instance) {
    List<AnnotationInstance> configPropertyInstances = instance.target().asClass().annotations()
            .get(ResteasyDotNames.CONFIG_PROPERTY);
    if (configPropertyInstances == null) {
        return;
    }
    for (AnnotationInstance configPropertyInstance : configPropertyInstances) {
        if (configPropertyInstance.target().kind() != AnnotationTarget.Kind.FIELD) {
            continue;
        }
        FieldInfo field = configPropertyInstance.target().asField();
        Type fieldType = field.type();
        if (ResteasyDotNames.CDI_INSTANCE.equals(fieldType.name())) {
            continue;
        }
        LOGGER.warn(
                "Directly injecting a @" + ResteasyDotNames.CONFIG_PROPERTY.withoutPackagePrefix()
                        + " into a JAX-RS provider may lead to unexpected results. To ensure proper results, please change the type of the field to "
                        + ParameterizedType.create(ResteasyDotNames.CDI_INSTANCE, new Type[] { fieldType }, null)
                        + ". Offending field is '" + field.name() + "' of class '" + field.declaringClass() + "'");
    }
}
 
Example 3
Source File: IgnoreTests.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testIgnore_jsonIgnorePropertiesOnField() throws IOException, JSONException {
    String name = IgnoreTestContainer.class.getName();
    FieldInfo fieldInfo = getFieldFromKlazz(name, "jipOnFieldTest");
    OpenApiDataObjectScanner scanner = new OpenApiDataObjectScanner(index, fieldInfo, fieldInfo.type());

    Schema result = scanner.process();

    printToConsole(name, result);
    assertJsonEquals(name, "ignore.jsonIgnorePropertiesOnField.expected.json", result);
}
 
Example 4
Source File: TypeResolver.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
private TypeResolver(String propertyName, FieldInfo field, Deque<Map<String, Type>> resolutionStack) {
    this.propertyName = propertyName;
    this.field = field;
    this.resolutionStack = resolutionStack;

    if (field != null) {
        this.leaf = field.type();
        targets.add(field);
    } else {
        this.leaf = null;
    }
}
 
Example 5
Source File: FieldCreator.java    From smallrye-graphql with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a field from a public field.
 * Used by Type and Input
 * 
 * @param direction the direction (in/out)
 * @param fieldInfo the java property
 * @return a Field model object
 */
public Optional<Field> createFieldForPojo(Direction direction, FieldInfo fieldInfo) {
    if (Modifier.isPublic(fieldInfo.flags())) {
        Annotations annotationsForPojo = Annotations.getAnnotationsForPojo(direction, fieldInfo);

        if (!IgnoreHelper.shouldIgnore(annotationsForPojo, fieldInfo)) {

            // Name
            String name = getFieldName(direction, annotationsForPojo, fieldInfo.name());

            // Field Type
            Type fieldType = fieldInfo.type();

            // Description
            Optional<String> maybeDescription = DescriptionHelper.getDescriptionForField(annotationsForPojo, fieldType);

            Reference reference = referenceCreator.createReferenceForPojoField(direction, fieldType, fieldType,
                    annotationsForPojo);

            Field field = new Field(fieldInfo.name(),
                    MethodHelper.getPropertyName(direction, fieldInfo.name()),
                    name,
                    maybeDescription.orElse(null),
                    reference);

            // NotNull
            if (NonNullHelper.markAsNonNull(fieldType, annotationsForPojo)) {
                field.setNotNull(true);
            }

            // Array
            field.setArray(ArrayCreator.createArray(fieldType, fieldType).orElse(null));

            // TransformInfo
            field.setTransformInfo(FormatHelper.getFormat(fieldType, annotationsForPojo).orElse(null));

            // MappingInfo
            field.setMappingInfo(MappingHelper.getMapping(field, annotationsForPojo).orElse(null));

            // Default Value
            field.setDefaultValue(DefaultValueHelper.getDefaultValue(annotationsForPojo).orElse(null));

            return Optional.of(field);
        }
        return Optional.empty();
    }
    return Optional.empty();
}
 
Example 6
Source File: FieldCreator.java    From smallrye-graphql with Apache License 2.0 4 votes vote down vote up
private static Type getFieldType(FieldInfo fieldInfo, Type defaultType) {
    if (fieldInfo == null) {
        return defaultType;
    }
    return fieldInfo.type();
}