Java Code Examples for org.jboss.jandex.DotName#toString()

The following examples show how to use org.jboss.jandex.DotName#toString() . 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: ArcProcessor.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Override
public boolean test(T t) {
    final DotName dotName = getDotName(t);
    if (applicationClassesIndex.getClassByName(dotName) != null) {
        return true;
    }
    if (generatedClassNames.contains(dotName)) {
        return true;
    }
    String className = dotName.toString();
    if (!applicationClassPredicateBuildItems.isEmpty()) {
        for (ApplicationClassPredicateBuildItem predicate : applicationClassPredicateBuildItems) {
            if (predicate.test(className)) {
                return true;
            }
        }
    }
    if (testClassPredicate.isPresent()) {
        if (testClassPredicate.get().getPredicate().test(className)) {
            return true;
        }
    }
    return false;
}
 
Example 2
Source File: FilteredIndexView.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
public MatchHandler(DotName className) {
    this.className = className;
    this.fqcn = className.toString();
    this.simpleName = className.withoutPackagePrefix();
    final int index = fqcn.lastIndexOf('.');
    this.packageName = index > -1 ? fqcn.substring(0, index) : "";

    this.classExclGroup = matchingGroup(fqcn, scanExcludeClasses);
    this.classInclGroup = matchingGroup(fqcn, scanClasses);
    this.pkgExclGroup = matchingGroup(packageName, scanExcludePackages);
    this.pkgInclGroup = matchingGroup(packageName, scanPackages);
}
 
Example 3
Source File: DotNames.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public static String packageName(DotName dotName) {
    String name = dotName.toString();
    int index = name.lastIndexOf('.');
    if (index == -1) {
        return "";
    }
    return name.substring(0, index);
}
 
Example 4
Source File: AnnotationLiteralGenerator.java    From quarkus with Apache License 2.0 5 votes vote down vote up
static String generatedSharedName(DotName annotationName) {
    // when the annotation is a java.lang annotation we need to use a different package in which to generate the literal
    // otherwise a security exception will be thrown when the literal is loaded
    String nameToUse = isJavaLang(annotationName.toString())
            ? AbstractGenerator.DEFAULT_PACKAGE + annotationName.withoutPackagePrefix()
            : annotationName.toString();

    // com.foo.MyQualifier -> com.foo.MyQualifier1_Shared_AnnotationLiteral
    return nameToUse + SHARED_SUFFIX + ANNOTATION_LITERAL_SUFFIX;
}
 
Example 5
Source File: ValueResolverGenerator.java    From quarkus with Apache License 2.0 5 votes vote down vote up
static String packageName(DotName dotName) {
    String name = dotName.toString();
    int index = name.lastIndexOf('.');
    if (index == -1) {
        return "";
    }
    return name.substring(0, index);
}
 
Example 6
Source File: CustomQueryMethodsAdder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private DotName createImplDotName(DotName ifaceName) {
    String fullName = ifaceName.toString();

    // package name: must be in the same package as the interface
    final int index = fullName.lastIndexOf('.');
    String packageName = "";
    if (index > 0 && index < fullName.length() - 1) {
        packageName = fullName.substring(0, index) + ".";
    }

    return DotName.createSimple(packageName
            + (ifaceName.isInner() ? ifaceName.local() : ifaceName.withoutPackagePrefix()) + "_"
            + HashUtil.sha1(ifaceName.toString()));
}
 
Example 7
Source File: JpaJandexScavenger.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static boolean isIgnored(DotName classDotName) {
    String className = classDotName.toString();
    if (className.startsWith("java.util.") || className.startsWith("java.lang.")
            || className.startsWith("org.hibernate.engine.spi.")) {
        return true;
    }
    return false;
}
 
Example 8
Source File: JpaJandexScavenger.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static boolean isInJavaPackage(DotName classDotName) {
    String className = classDotName.toString();
    if (className.startsWith("java.")) {
        return true;
    }
    return false;
}
 
Example 9
Source File: ResteasyServerCommonProcessor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static String packageName(DotName dotName) {
    final String className = dotName.toString();
    final int index = className.lastIndexOf('.');
    if (index > 0 && index < className.length() - 1) {
        return className.substring(0, index);
    }
    return null;
}
 
Example 10
Source File: ReflectiveHierarchyBuildItem.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Override
public boolean test(DotName dotName) {
    String name = dotName.toString();
    if (PRIMITIVE.contains(name)) {
        return true;
    }
    for (String containerPackageName : DEFAULT_IGNORED_PACKAGES) {
        if (name.startsWith(containerPackageName)) {
            return !WHITELISTED_FROM_IGNORED_PACKAGES.contains(name);
        }
    }
    return false;
}
 
Example 11
Source File: Serianalyzer.java    From serianalyzer with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param ci
 * @throws SerianalyzerException
 */
private void checkClass ( ClassInfo ci ) throws SerianalyzerException {
    DotName dname = ci.name();
    String dnameString = dname.toString();
    try ( InputStream data = this.input.getClassData(dnameString) ) {
        if ( data == null ) {
            log.error("No class data for " + dname); //$NON-NLS-1$
            return;
        }
        boolean serializable = this.isTypeSerializable(this.getIndex(), dnameString);
        ClassReader cr = new ClassReader(data);
        if ( log.isTraceEnabled() ) {
            log.trace("Adding " + dnameString); //$NON-NLS-1$
        }
        SerianalyzerClassSerializationVisitor visitor = new SerianalyzerClassSerializationVisitor(this, dnameString, serializable);
        cr.accept(visitor, 0);
        if ( serializable ) {
            ClassInfo classByName = this.input.getIndex().getClassByName(ci.superName());
            if ( classByName == null ) {
                log.error("Failed to locate super class " + ci.superName()); //$NON-NLS-1$
                return;
            }
            checkClass(classByName);
        }
        else if ( !visitor.isFoundDefaultConstructor() && log.isTraceEnabled() ) {
            log.trace("No default constructor found in first non-serializable parent " + dname); //$NON-NLS-1$
        }
    }
    catch ( IOException e ) {
        throw new SerianalyzerException("Failed to read class data" + dname, e); //$NON-NLS-1$
    }
}
 
Example 12
Source File: Serianalyzer.java    From serianalyzer with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param ref
 * @param retType
 */
public void instantiable ( MethodReference ref, Type retType ) {
    if ( this.input.getConfig().isWhitelisted(ref) ) {
        return;
    }
    if ( retType.getSort() == Type.OBJECT ) {
        String className = retType.getClassName();
        DotName typeName = DotName.createSimple(className);
        ClassInfo classByName = this.input.getIndex().getClassByName(typeName);
        if ( classByName != null ) {
            if ( !"java.lang.Object".equals(className) && !this.isTypeSerializable(this.getIndex(), className) ) { //$NON-NLS-1$
                if ( ( Modifier.isInterface(classByName.flags()) || Modifier.isAbstract(classByName.flags()) )
                        && this.input.getConfig().isNastyBase(className) ) {
                    return;
                }

                for ( DotName ifname : classByName.interfaceNames() ) {
                    String ifStr = ifname.toString();
                    if ( !this.input.getConfig().isNastyBase(ifStr) ) {
                        this.state.trackInstantiable(ifStr, ref, this.input.getConfig(), false);
                    }
                }

                this.state.trackInstantiable(className, ref, this.input.getConfig(), false);
            }
        }
    }
}
 
Example 13
Source File: MethodReference.java    From serianalyzer with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param name
 * @return a new method reference for the given target type
 */
public MethodReference adaptToType ( DotName name ) {
    MethodReference ref = new MethodReference(name.toString(), false, this.getMethod(), this.stat, this.getSignature());
    if ( this.calleeTaint ) {
        ref.taintCallee();
    }

    ref.parameterTaint = this.parameterTaint;
    ref.parameterReturnTaint = this.parameterReturnTaint;

    if ( this.argumentTypes != null ) {
        ref.argumentTypes = this.argumentTypes.clone();
    }
    return ref;
}
 
Example 14
Source File: StockMethodsAdder.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public void add(ClassCreator classCreator, FieldDescriptor entityClassFieldDescriptor,
        String generatedClassName, ClassInfo repositoryToImplement, DotName entityDotName, String idTypeStr) {

    Set<MethodInfo> methodsOfExtendedSpringDataRepositories = methodsOfExtendedSpringDataRepositories(
            repositoryToImplement);
    Set<MethodInfo> stockMethodsAddedToInterface = stockMethodsAddedToInterface(repositoryToImplement);
    Set<MethodInfo> allMethodsToBeImplemented = new HashSet<>(methodsOfExtendedSpringDataRepositories);
    allMethodsToBeImplemented.addAll(stockMethodsAddedToInterface);

    Map<MethodDescriptor, Boolean> allMethodsToBeImplementedToResult = new HashMap<>();
    for (MethodInfo methodInfo : allMethodsToBeImplemented) {
        allMethodsToBeImplementedToResult.put(GenerationUtil.toMethodDescriptor(generatedClassName, methodInfo), false);
    }

    String entityTypeStr = entityDotName.toString();

    // for all Spring Data repository methods we know how to implement, check if the generated class actually needs the method
    // and if so generate the implementation while also keeping the proper records

    generateSave(classCreator, entityClassFieldDescriptor, generatedClassName, entityDotName, entityTypeStr,
            allMethodsToBeImplementedToResult);
    generateSaveAndFlush(classCreator, entityClassFieldDescriptor, generatedClassName, entityDotName, entityTypeStr,
            allMethodsToBeImplementedToResult);
    generateSaveAll(classCreator, entityClassFieldDescriptor, generatedClassName, entityDotName, entityTypeStr,
            allMethodsToBeImplementedToResult);
    generateFlush(classCreator, generatedClassName, allMethodsToBeImplementedToResult);
    generateFindById(classCreator, entityClassFieldDescriptor, generatedClassName, entityTypeStr, idTypeStr,
            allMethodsToBeImplementedToResult);
    generateExistsById(classCreator, entityClassFieldDescriptor, generatedClassName, entityTypeStr, idTypeStr,
            allMethodsToBeImplementedToResult);
    generateGetOne(classCreator, entityClassFieldDescriptor, generatedClassName, entityTypeStr, idTypeStr,
            allMethodsToBeImplementedToResult);
    generateFindAll(classCreator, entityClassFieldDescriptor, generatedClassName, entityTypeStr,
            allMethodsToBeImplementedToResult);
    generateFindAllWithSort(classCreator, entityClassFieldDescriptor, generatedClassName, entityTypeStr,
            allMethodsToBeImplementedToResult);
    generateFindAllWithPageable(classCreator, entityClassFieldDescriptor, generatedClassName, entityTypeStr,
            allMethodsToBeImplementedToResult);
    generateFindAllById(classCreator, entityClassFieldDescriptor, generatedClassName, entityDotName, entityTypeStr,
            idTypeStr, allMethodsToBeImplementedToResult);
    generateCount(classCreator, entityClassFieldDescriptor, generatedClassName, allMethodsToBeImplementedToResult);
    generateDeleteById(classCreator, entityClassFieldDescriptor, generatedClassName, entityTypeStr, idTypeStr,
            allMethodsToBeImplementedToResult);
    generateDelete(classCreator, generatedClassName, entityTypeStr, allMethodsToBeImplementedToResult);
    generateDeleteAllWithIterable(classCreator, generatedClassName, entityTypeStr, allMethodsToBeImplementedToResult);
    generateDeleteAll(classCreator, entityClassFieldDescriptor, generatedClassName, allMethodsToBeImplementedToResult);

    handleUnimplementedMethods(classCreator, allMethodsToBeImplementedToResult);
}
 
Example 15
Source File: SpringDataRepositoryCreator.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public void implementCrudRepository(ClassInfo repositoryToImplement) {
    Map.Entry<DotName, DotName> extraTypesResult = extractIdAndEntityTypes(repositoryToImplement);

    String idTypeStr = extraTypesResult.getKey().toString();
    DotName entityDotName = extraTypesResult.getValue();
    String entityTypeStr = entityDotName.toString();

    ClassInfo entityClassInfo = index.getClassByName(entityDotName);
    if (entityClassInfo == null) {
        throw new IllegalStateException("Entity " + entityDotName + " was not part of the Quarkus index");
    }

    // handle the fragment repositories
    // Spring Data allows users to define (and implement their own interfaces containing data access related methods)
    // that can then be used along with any of the typical Spring Data repository interfaces in the final
    // repository in order to compose functionality

    List<DotName> interfaceNames = repositoryToImplement.interfaceNames();
    List<DotName> fragmentNamesToImplement = new ArrayList<>(interfaceNames.size());
    for (DotName interfaceName : interfaceNames) {
        if (!DotNames.SUPPORTED_REPOSITORIES.contains(interfaceName)) {
            fragmentNamesToImplement.add(interfaceName);
        }
    }

    Map<String, FieldDescriptor> fragmentImplNameToFieldDescriptor = new HashMap<>();
    String repositoryToImplementStr = repositoryToImplement.name().toString();
    String generatedClassName = repositoryToImplementStr + "_" + HashUtil.sha1(repositoryToImplementStr) + "Impl";
    try (ClassCreator classCreator = ClassCreator.builder().classOutput(classOutput)
            .className(generatedClassName)
            .interfaces(repositoryToImplementStr)
            .build()) {
        classCreator.addAnnotation(ApplicationScoped.class);

        FieldCreator entityClassFieldCreator = classCreator.getFieldCreator("entityClass", Class.class.getName())
                .setModifiers(Modifier.PRIVATE | Modifier.FINAL);

        // create an instance field of type Class for each one of the implementations of the custom interfaces
        createCustomImplFields(classCreator, fragmentNamesToImplement, index, fragmentImplNameToFieldDescriptor);

        // initialize all class fields in the constructor
        try (MethodCreator ctor = classCreator.getMethodCreator("<init>", "V")) {
            ctor.invokeSpecialMethod(MethodDescriptor.ofMethod(Object.class, "<init>", void.class), ctor.getThis());
            // initialize the entityClass field
            ctor.writeInstanceField(entityClassFieldCreator.getFieldDescriptor(), ctor.getThis(),
                    ctor.loadClass(entityTypeStr));
            ctor.returnValue(null);
        }

        // for every method we add we need to make sure that we only haven't added it before
        // we first add custom methods (as per Spring Data implementation) thus ensuring that user provided methods
        // always override stock methods from the Spring Data repository interfaces

        fragmentMethodsAdder.add(classCreator, generatedClassName, fragmentNamesToImplement,
                fragmentImplNameToFieldDescriptor);

        stockMethodsAdder.add(classCreator, entityClassFieldCreator.getFieldDescriptor(), generatedClassName,
                repositoryToImplement, entityDotName, idTypeStr);
        derivedMethodsAdder.add(classCreator, entityClassFieldCreator.getFieldDescriptor(), generatedClassName,
                repositoryToImplement, entityClassInfo);
        customQueryMethodsAdder.add(classCreator, entityClassFieldCreator.getFieldDescriptor(),
                repositoryToImplement, entityClassInfo);
    }
}
 
Example 16
Source File: AmazonLambdaProcessor.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@BuildStep
List<AmazonLambdaBuildItem> discover(CombinedIndexBuildItem combinedIndexBuildItem,
        Optional<ProvidedAmazonLambdaHandlerBuildItem> providedLambda,
        BuildProducer<AdditionalBeanBuildItem> additionalBeanBuildItemBuildProducer,
        BuildProducer<ReflectiveHierarchyBuildItem> reflectiveHierarchy,
        BuildProducer<ReflectiveClassBuildItem> reflectiveClassBuildItemBuildProducer) throws BuildException {

    Collection<ClassInfo> allKnownImplementors = combinedIndexBuildItem.getIndex().getAllKnownImplementors(REQUEST_HANDLER);
    allKnownImplementors.addAll(combinedIndexBuildItem.getIndex()
            .getAllKnownImplementors(REQUEST_STREAM_HANDLER));
    allKnownImplementors.addAll(combinedIndexBuildItem.getIndex()
            .getAllKnownSubclasses(SKILL_STREAM_HANDLER));

    if (allKnownImplementors.size() > 0 && providedLambda.isPresent()) {
        throw new BuildException(
                "Multiple handler classes.  You have a custom handler class and the " + providedLambda.get().getProvider()
                        + " extension.  Please remove one of them from your deployment.",
                Collections.emptyList());

    }
    AdditionalBeanBuildItem.Builder builder = AdditionalBeanBuildItem.builder().setUnremovable();
    List<AmazonLambdaBuildItem> ret = new ArrayList<>();

    for (ClassInfo info : allKnownImplementors) {
        if (Modifier.isAbstract(info.flags())) {
            continue;
        }

        final DotName name = info.name();
        final String lambda = name.toString();
        builder.addBeanClass(lambda);
        reflectiveClassBuildItemBuildProducer.produce(new ReflectiveClassBuildItem(true, false, lambda));

        String cdiName = null;
        AnnotationInstance named = info.classAnnotation(NAMED);
        if (named != null) {
            cdiName = named.value().asString();
        }

        ClassInfo current = info;
        boolean done = false;
        boolean streamHandler = info.superName().equals(SKILL_STREAM_HANDLER) ? true : false;
        while (current != null && !done) {
            for (MethodInfo method : current.methods()) {
                if (method.name().equals("handleRequest")) {
                    if (method.parameters().size() == 3) {
                        streamHandler = true;
                        done = true;
                        break;
                    } else if (method.parameters().size() == 2
                            && !method.parameters().get(0).name().equals(DotName.createSimple(Object.class.getName()))) {
                        reflectiveHierarchy.produce(new ReflectiveHierarchyBuildItem(method.parameters().get(0)));
                        reflectiveHierarchy.produce(new ReflectiveHierarchyBuildItem(method.returnType()));
                        done = true;
                        break;
                    }
                }
            }
            current = combinedIndexBuildItem.getIndex().getClassByName(current.superName());
        }
        ret.add(new AmazonLambdaBuildItem(lambda, cdiName, streamHandler));
    }
    additionalBeanBuildItemBuildProducer.produce(builder.build());
    reflectiveClassBuildItemBuildProducer
            .produce(new ReflectiveClassBuildItem(true, true, true, FunctionError.class));
    return ret;
}