Java Code Examples for org.jboss.jandex.ClassInfo#superClassType()

The following examples show how to use org.jboss.jandex.ClassInfo#superClassType() . 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: ValueResolverGenerator.java    From quarkus with Apache License 2.0 6 votes vote down vote up
static boolean hasCompletionStageInTypeClosure(ClassInfo classInfo,
        IndexView index) {

    if (classInfo == null) {
        // TODO cannot perform analysis
        return false;
    }
    if (classInfo.name().equals(COMPLETION_STAGE)) {
        return true;
    }
    // Interfaces
    for (Type interfaceType : classInfo.interfaceTypes()) {
        ClassInfo interfaceClassInfo = index.getClassByName(interfaceType.name());
        if (interfaceClassInfo != null && hasCompletionStageInTypeClosure(interfaceClassInfo, index)) {
            return true;
        }
    }
    // Superclass
    if (classInfo.superClassType() != null) {
        ClassInfo superClassInfo = index.getClassByName(classInfo.superName());
        if (superClassInfo != null && hasCompletionStageInTypeClosure(superClassInfo, index)) {
            return true;
        }
    }
    return false;
}
 
Example 2
Source File: MethodNameParser.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private List<ClassInfo> getMappedSuperClassInfos(IndexView indexView, ClassInfo entityClass) {
    List<ClassInfo> mappedSuperClassInfos = new ArrayList<>(3);
    Type superClassType = entityClass.superClassType();
    while (superClassType != null && !superClassType.name().equals(DotNames.OBJECT)) {
        ClassInfo superClass = indexView.getClassByName(entityClass.superName());
        if (superClass.classAnnotation(DotNames.JPA_MAPPED_SUPERCLASS) != null) {
            mappedSuperClassInfos.add(superClass);
        }

        if (superClassType.kind() == Kind.CLASS) {
            superClassType = indexView.getClassByName(superClassType.name()).superClassType();
        } else if (superClassType.kind() == Kind.PARAMETERIZED_TYPE) {
            ParameterizedType parameterizedType = superClassType.asParameterizedType();
            superClassType = parameterizedType.owner();
        }
    }
    if (mappedSuperClassInfos.size() > 0) {
        return mappedSuperClassInfos;
    }
    return Collections.emptyList();
}
 
Example 3
Source File: JandexUtil.java    From quarkus with Apache License 2.0 6 votes vote down vote up
/**
 * Returns true if the given Jandex ClassInfo is a subclass of the given <tt>parentName</tt>. Note that this will
 * not check interfaces.
 * 
 * @param index the index to use to look up super classes.
 * @param info the ClassInfo we want to check.
 * @param parentName the name of the superclass we want to find.
 * @return true if the given ClassInfo has <tt>parentName</tt> as a superclass.
 * @throws BuildException if one of the superclasses is not indexed.
 */
public static boolean isSubclassOf(IndexView index, ClassInfo info, DotName parentName) throws BuildException {
    if (info.superName().equals(DOTNAME_OBJECT)) {
        return false;
    }
    if (info.superName().equals(parentName)) {
        return true;
    }

    // climb up the hierarchy of classes
    Type superType = info.superClassType();
    ClassInfo superClass = index.getClassByName(superType.name());
    if (superClass == null) {
        // this can happens if the parent is not inside the Jandex index
        throw new BuildException("The class " + superType.name() + " is not inside the Jandex index",
                Collections.emptyList());
    }
    return isSubclassOf(index, superClass, parentName);
}
 
Example 4
Source File: JandexUtil.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
/**
 * Builds an insertion-order map of a class's inheritance chain, starting
 * with the klazz argument.
 *
 * @param index index for superclass retrieval
 * @param klazz the class to retrieve inheritance
 * @param type type of the klazz
 * @return map of a class's inheritance chain/ancestry
 */
public static Map<ClassInfo, Type> inheritanceChain(IndexView index, ClassInfo klazz, Type type) {
    Map<ClassInfo, Type> chain = new LinkedHashMap<>();

    do {
        chain.put(klazz, type);
    } while ((type = klazz.superClassType()) != null &&
            (klazz = index.getClassByName(TypeUtil.getName(type))) != null);

    return chain;
}
 
Example 5
Source File: Methods.java    From quarkus with Apache License 2.0 5 votes vote down vote up
static void addDelegatingMethods(IndexView index, ClassInfo classInfo, Map<Methods.MethodKey, MethodInfo> methods) {
    // TODO support interfaces default methods
    if (classInfo != null) {
        for (MethodInfo method : classInfo.methods()) {
            if (skipForClientProxy(method)) {
                continue;
            }
            methods.computeIfAbsent(new Methods.MethodKey(method), key -> {
                // If parameterized try to resolve the type variables
                Type returnType = key.method.returnType();
                Type[] params = new Type[key.method.parameters().size()];
                for (int i = 0; i < params.length; i++) {
                    params[i] = key.method.parameters().get(i);
                }
                List<TypeVariable> typeVariables = key.method.typeParameters();
                return MethodInfo.create(classInfo, key.method.name(), params, returnType, key.method.flags(),
                        typeVariables.toArray(new TypeVariable[] {}),
                        key.method.exceptions().toArray(Type.EMPTY_ARRAY));
            });
        }
        // Interfaces
        for (Type interfaceType : classInfo.interfaceTypes()) {
            ClassInfo interfaceClassInfo = getClassByName(index, interfaceType.name());
            if (interfaceClassInfo != null) {
                addDelegatingMethods(index, interfaceClassInfo, methods);
            }
        }
        if (classInfo.superClassType() != null) {
            ClassInfo superClassInfo = getClassByName(index, classInfo.superName());
            if (superClassInfo != null) {
                addDelegatingMethods(index, superClassInfo, methods);
            }
        }
    }
}
 
Example 6
Source File: BeanInfo.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private void addClassLevelBindings(ClassInfo classInfo, Collection<AnnotationInstance> bindings) {
    beanDeployment.getAnnotations(classInfo).stream()
            .filter(a -> beanDeployment.getInterceptorBinding(a.name()) != null
                    && bindings.stream().noneMatch(e -> e.name().equals(a.name())))
            .forEach(a -> bindings.add(a));
    if (classInfo.superClassType() != null && !classInfo.superClassType().name().equals(DotNames.OBJECT)) {
        ClassInfo superClass = getClassByName(beanDeployment.getIndex(), classInfo.superName());
        if (superClass != null) {
            addClassLevelBindings(superClass, bindings);
        }
    }
}
 
Example 7
Source File: HibernateSearchElasticsearchProcessor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static void addReflectiveClass(IndexView index, Set<DotName> reflectiveClassCollector,
        Set<Type> reflectiveTypeCollector, ClassInfo classInfo) {
    if (skipClass(classInfo.name(), reflectiveClassCollector)) {
        return;
    }

    reflectiveClassCollector.add(classInfo.name());

    for (ClassInfo subclass : index.getAllKnownSubclasses(classInfo.name())) {
        reflectiveClassCollector.add(subclass.name());
    }
    for (ClassInfo implementor : index.getAllKnownImplementors(classInfo.name())) {
        reflectiveClassCollector.add(implementor.name());
    }

    Type superClassType = classInfo.superClassType();
    while (superClassType != null && !superClassType.name().toString().equals("java.lang.Object")) {
        reflectiveClassCollector.add(superClassType.name());
        if (superClassType instanceof ClassType) {
            superClassType = index.getClassByName(superClassType.name()).superClassType();
        } else if (superClassType instanceof ParameterizedType) {
            ParameterizedType parameterizedType = superClassType.asParameterizedType();
            for (Type typeArgument : parameterizedType.arguments()) {
                addReflectiveType(index, reflectiveClassCollector, reflectiveTypeCollector, typeArgument);
            }
            superClassType = parameterizedType.owner();
        }
    }
}
 
Example 8
Source File: CamelDeploymentSettingsBuilderProcessor.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
private boolean annotationTargetIsCamelApi(AnnotationTarget target) {
    /**
     * Verify whether an annotation is applied to org.apache.camel types. If the declaring class
     * has the org.apache.camel package prefix, it is ignored since we are only interested in
     * annotations declared within user classes.
     */
    if (target != null) {
        if (target.kind().equals(Kind.CLASS)) {
            ClassInfo classInfo = target.asClass();
            if (isCamelApi(classInfo.name())) {
                return false;
            }

            Type superType = classInfo.superClassType();
            if (superType != null && isCamelApi(superType.name())) {
                return true;
            }

            return classInfo.interfaceNames().stream().anyMatch(interfaceName -> isCamelApi(interfaceName));
        } else if (target.kind().equals(Kind.FIELD)) {
            FieldInfo fieldInfo = target.asField();
            return !isCamelApi(fieldInfo.declaringClass().name()) && isCamelApi(fieldInfo.type().name());
        } else if (target.kind().equals(Kind.METHOD)) {
            MethodInfo methodInfo = target.asMethod();
            return !isCamelApi(methodInfo.declaringClass().name()) && isCamelApi(methodInfo.returnType().name());
        }
    }
    return false;
}
 
Example 9
Source File: JandexUtil.java    From quarkus with Apache License 2.0 4 votes vote down vote up
/**
 * Finds the type arguments passed from the starting type to the given target type, mapping
 * generics when found, on the way down. Returns null if not found.
 */
private static List<Type> findParametersRecursively(Type type, DotName target,
        Set<DotName> visitedTypes, IndexView index) {
    DotName name = type.name();
    // cache results first
    if (!visitedTypes.add(name)) {
        return null;
    }

    // always end at Object
    if (DOTNAME_OBJECT.equals(name)) {
        return null;
    }

    final ClassInfo inputClassInfo = fetchFromIndex(name, index);

    // look at the current type
    if (target.equals(name)) {
        Type thisType = getType(inputClassInfo, index);
        if (thisType.kind() == Kind.CLASS)
            return Collections.emptyList();
        else
            return thisType.asParameterizedType().arguments();
    }

    // superclasses first
    Type superClassType = inputClassInfo.superClassType();
    List<Type> superResult = findParametersRecursively(superClassType, target, visitedTypes, index);
    if (superResult != null) {
        // map any returned type parameters to our type arguments on the way down
        return mapTypeArguments(superClassType, superResult, index);
    }

    // interfaces second
    for (Type interfaceType : inputClassInfo.interfaceTypes()) {
        List<Type> ret = findParametersRecursively(interfaceType, target, visitedTypes, index);
        if (ret != null) {
            // map any returned type parameters to our type arguments on the way down
            return mapTypeArguments(interfaceType, ret, index);
        }
    }

    // not found
    return null;
}