Java Code Examples for org.jboss.jandex.DotName#createSimple()
The following examples show how to use
org.jboss.jandex.DotName#createSimple() .
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: SmallRyeGraphQLProcessor.java From quarkus with Apache License 2.0 | 6 votes |
@Record(ExecutionTime.STATIC_INIT) @BuildStep void buildExecutionService( BuildProducer<ReflectiveClassBuildItem> reflectiveClassProducer, BuildProducer<ReflectiveHierarchyBuildItem> reflectiveHierarchyProducer, SmallRyeGraphQLRecorder recorder, BeanContainerBuildItem beanContainer, CombinedIndexBuildItem combinedIndex) { IndexView index = combinedIndex.getIndex(); Schema schema = SchemaBuilder.build(index); recorder.createExecutionService(beanContainer.getValue(), schema); // Make sure the complex object from the application can work in native mode for (String c : getClassesToRegisterForReflection(schema)) { DotName name = DotName.createSimple(c); org.jboss.jandex.Type type = org.jboss.jandex.Type.create(name, org.jboss.jandex.Type.Kind.CLASS); reflectiveHierarchyProducer.produce(new ReflectiveHierarchyBuildItem(type, index)); } // Make sure the GraphQL Java classes needed for introspection can work in native mode reflectiveClassProducer.produce(new ReflectiveClassBuildItem(true, true, getGraphQLJavaClasses())); }
Example 2
Source File: SwaggerArchivePreparer.java From thorntail with Apache License 2.0 | 6 votes |
/** * Extract the package information from the given {@code ClassInfo} object. * * @param classInfo the class metadata. * @param packages the collection to which we need to add the package information. */ private static void extractAndAddPackageInfo(ClassInfo classInfo, Set<String> packages, IndexView indexView) { if (classInfo == null) { return; } // Check if we were given an abstract class / interface, in which case we need to check the IndexView to see if there // is an implementation or not. String className = classInfo.name().toString(); if (indexView != null) { DotName dotName = DotName.createSimple(className); if (Modifier.isInterface(classInfo.flags())) { indexView.getAllKnownImplementors(dotName).forEach(ci -> extractAndAddPackageInfo(ci, packages, indexView)); } else if (Modifier.isAbstract(classInfo.flags())) { indexView.getAllKnownSubclasses(dotName).forEach(ci -> extractAndAddPackageInfo(ci, packages, indexView)); } } StringBuilder builder = new StringBuilder(className).reverse(); int idx = builder.indexOf("."); if (idx != -1) { builder.delete(0, idx + 1); } packages.add(builder.reverse().toString()); }
Example 3
Source File: PolicyProcessor.java From camel-quarkus with Apache License 2.0 | 5 votes |
@BuildStep void bannedReflectiveClasses( CombinedIndexBuildItem combinedIndex, List<ReflectiveClassBuildItem> reflectiveClasses, List<UnbannedReflectiveBuildItem> unbannedReflectives, BuildProducer<GeneratedResourceBuildItem> dummy // to force the execution of this method ) { final DotName uriParamsDotName = DotName.createSimple("org.apache.camel.spi.UriParams"); final Set<String> bannedClassNames = combinedIndex.getIndex() .getAnnotations(uriParamsDotName) .stream() .filter(ai -> ai.target().kind() == Kind.CLASS) .map(ai -> ai.target().asClass().name().toString()) .collect(Collectors.toSet()); final Set<String> unbannedClassNames = unbannedReflectives.stream() .map(UnbannedReflectiveBuildItem::getClassNames) .flatMap(Collection::stream) .collect(Collectors.toSet()); Set<String> violations = reflectiveClasses.stream() .map(ReflectiveClassBuildItem::getClassNames) .flatMap(Collection::stream) .filter(cl -> !unbannedClassNames.contains(cl)) .filter(bannedClassNames::contains) .collect(Collectors.toSet()); if (!violations.isEmpty()) { throw new IllegalStateException( "The following classes should either be whitelisted via an UnbannedReflectiveBuildItem or they should not be registered for reflection via ReflectiveClassBuildItem: " + violations); } }
Example 4
Source File: MethodReference.java From serianalyzer with GNU General Public License v3.0 | 5 votes |
/** * @return the typeName */ public DotName getTypeName () { if ( this.nameCache == null ) { this.nameCache = DotName.createSimple(this.typeName); } return this.nameCache; }
Example 5
Source File: CustomQueryMethodsAdder.java From quarkus with Apache License 2.0 | 5 votes |
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 6
Source File: NarayanaSTMProcessor.java From quarkus with Apache License 2.0 | 5 votes |
@BuildStep NativeImageProxyDefinitionBuildItem stmProxies() { final DotName TRANSACTIONAL = DotName.createSimple(Transactional.class.getName()); IndexView index = combinedIndexBuildItem.getIndex(); Collection<String> proxies = new ArrayList<>(); for (AnnotationInstance stm : index.getAnnotations(TRANSACTIONAL)) { if (AnnotationTarget.Kind.CLASS.equals(stm.target().kind())) { DotName name = stm.target().asClass().name(); proxies.add(name.toString()); log.debugf("Registering transactional interface %s%n", name); for (ClassInfo ci : index.getAllKnownImplementors(name)) { reflectiveHierarchyClass.produce( new ReflectiveHierarchyBuildItem(Type.create(ci.name(), Type.Kind.CLASS))); } } } String[] classNames = proxies.toArray(new String[0]); reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, classNames)); return new NativeImageProxyDefinitionBuildItem(classNames); }
Example 7
Source File: Serianalyzer.java From serianalyzer with GNU General Public License v3.0 | 5 votes |
/** * @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 8
Source File: KeycloakAdminClientProcessor.java From quarkus with Apache License 2.0 | 5 votes |
@BuildStep ReflectiveHierarchyIgnoreWarningBuildItem marker(BuildProducer<AdditionalApplicationArchiveMarkerBuildItem> prod) { prod.produce(new AdditionalApplicationArchiveMarkerBuildItem("org/keycloak/admin/client/")); prod.produce(new AdditionalApplicationArchiveMarkerBuildItem("org/keycloak/representations")); return new ReflectiveHierarchyIgnoreWarningBuildItem(new ReflectiveHierarchyIgnoreWarningBuildItem.DotNameExclusion( DotName.createSimple(MultivaluedHashMap.class.getName()))); }
Example 9
Source File: IgnoreTests.java From smallrye-open-api with Apache License 2.0 | 5 votes |
@Test public void testIgnore_jsonIgnoreField() throws IOException, JSONException { DotName name = DotName.createSimple(JsonIgnoreOnFieldExample.class.getName()); OpenApiDataObjectScanner scanner = new OpenApiDataObjectScanner(index, ClassType.create(name, Type.Kind.CLASS)); Schema result = scanner.process(); printToConsole(name.local(), result); assertJsonEquals(name.local(), "ignore.jsonIgnoreField.expected.json", result); }
Example 10
Source File: KitchenSinkTest.java From smallrye-open-api with Apache License 2.0 | 5 votes |
/** * Test to ensure scanner doesn't choke on various declaration types and patterns. * * This doesn't have any explicit assertions: it is designed to discover * any permutations or configurations that cause exceptions. * * It is to validate the scanner doesn't break rather than strictly assessing correctness. */ @Test public void testKitchenSink() throws IOException { DotName kitchenSink = DotName.createSimple(KitchenSink.class.getName()); OpenApiDataObjectScanner scanner = new OpenApiDataObjectScanner(index, ClassType.create(kitchenSink, Type.Kind.CLASS)); LOG.debugv("Scanning top-level entity: {0}", KitchenSink.class.getName()); printToConsole(kitchenSink.local(), scanner.process()); }
Example 11
Source File: TypeUtilTest.java From smallrye-open-api with Apache License 2.0 | 5 votes |
@Test public void testIsA_SubjectSameAsObject() { final Class<?> subjectClass = MapContainer.class; final DotName subjectName = DotName.createSimple(subjectClass.getName()); Index index = indexOf(subjectClass); ClassInfo subjectInfo = index.getClassByName(subjectName); Type testSubject = subjectInfo.field("theMap").type(); boolean result = TypeUtil.isA(index, testSubject, TYPE_MAP); assertTrue(result); }
Example 12
Source File: HibernateUserTypeProcessor.java From quarkus with Apache License 2.0 | 5 votes |
@BuildStep public void build(BuildProducer<ReflectiveClassBuildItem> reflectiveClass, CombinedIndexBuildItem combinedIndexBuildItem) { IndexView index = combinedIndexBuildItem.getIndex(); final Set<String> userTypes = new HashSet<>(); Collection<AnnotationInstance> typeAnnotationInstances = index.getAnnotations(TYPE); Collection<AnnotationInstance> typeDefinitionAnnotationInstances = index.getAnnotations(TYPE_DEFINITION); Collection<AnnotationInstance> typeDefinitionsAnnotationInstances = index.getAnnotations(TYPE_DEFINITIONS); userTypes.addAll(getUserTypes(typeDefinitionAnnotationInstances)); for (AnnotationInstance typeDefinitionAnnotationInstance : typeDefinitionsAnnotationInstances) { final AnnotationValue typeDefinitionsAnnotationValue = typeDefinitionAnnotationInstance.value(); if (typeDefinitionsAnnotationValue == null) { continue; } userTypes.addAll(getUserTypes(Arrays.asList(typeDefinitionsAnnotationValue.asNestedArray()))); } for (AnnotationInstance typeAnnotationInstance : typeAnnotationInstances) { final AnnotationValue typeValue = typeAnnotationInstance.value(TYPE_VALUE); if (typeValue == null) { continue; } final String type = typeValue.asString(); final DotName className = DotName.createSimple(type); if (index.getClassByName(className) == null) { continue; // Either already registered through TypeDef annotation scanning or not present in the index } userTypes.add(type); } if (!userTypes.isEmpty()) { reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, userTypes.toArray(new String[] {}))); } }
Example 13
Source File: ApplicationArchivesBuildItem.java From quarkus with Apache License 2.0 | 5 votes |
/** * Returns the archive that contains the given class name, or null if the class cannot be found * * @param className The class name * @return The application archive */ public ApplicationArchive containingArchive(String className) { DotName name = DotName.createSimple(className); if (root.getIndex().getClassByName(name) != null) { return root; } for (ApplicationArchive i : applicationArchives) { if (i.getIndex().getClassByName(name) != null) { return i; } } return null; }
Example 14
Source File: CacheDeploymentConstants.java From quarkus with Apache License 2.0 | 4 votes |
private static DotName dotName(Class<?> annotationClass) { return DotName.createSimple(annotationClass.getName()); }
Example 15
Source File: JandexUtilTest.java From quarkus with Apache License 2.0 | 4 votes |
private static DotName name(Class<?> klass) { return DotName.createSimple(klass.getName()); }
Example 16
Source File: ScopeInfo.java From quarkus with Apache License 2.0 | 4 votes |
public ScopeInfo(Class<? extends Annotation> clazz, boolean isNormal) { this.dotName = DotName.createSimple(clazz.getName()); this.isNormal = isNormal; declaresInherited = clazz.getAnnotation(Inherited.class) != null; }
Example 17
Source File: SesProcessor.java From quarkus with Apache License 2.0 | 4 votes |
@Override protected DotName asyncClientName() { return DotName.createSimple(SesAsyncClient.class.getName()); }
Example 18
Source File: TypesTest.java From quarkus with Apache License 2.0 | 4 votes |
@Test public void testGetTypeClosure() throws IOException { IndexView index = Basics.index(Foo.class, Baz.class, Producer.class, Object.class, List.class, Collection.class, Iterable.class); DotName bazName = DotName.createSimple(Baz.class.getName()); DotName fooName = DotName.createSimple(Foo.class.getName()); DotName producerName = DotName.createSimple(Producer.class.getName()); ClassInfo fooClass = index.getClassByName(fooName); Map<ClassInfo, Map<TypeVariable, Type>> resolvedTypeVariables = new HashMap<>(); BeanDeployment dummyDeployment = BeanProcessor.builder().setIndex(index).build().getBeanDeployment(); // Baz, Foo<String>, Object Set<Type> bazTypes = Types.getTypeClosure(index.getClassByName(bazName), null, Collections.emptyMap(), dummyDeployment, resolvedTypeVariables::put); assertEquals(3, bazTypes.size()); assertTrue(bazTypes.contains(Type.create(bazName, Kind.CLASS))); assertTrue(bazTypes.contains(ParameterizedType.create(fooName, new Type[] { Type.create(DotName.createSimple(String.class.getName()), Kind.CLASS) }, null))); assertEquals(resolvedTypeVariables.size(), 1); assertTrue(resolvedTypeVariables.containsKey(fooClass)); assertEquals(resolvedTypeVariables.get(fooClass).get(fooClass.typeParameters().get(0)), Type.create(DotName.createSimple(String.class.getName()), Kind.CLASS)); resolvedTypeVariables.clear(); // Foo<T>, Object Set<Type> fooTypes = Types.getClassBeanTypeClosure(fooClass, dummyDeployment); assertEquals(2, fooTypes.size()); for (Type t : fooTypes) { if (t.kind().equals(Kind.PARAMETERIZED_TYPE)) { ParameterizedType fooType = t.asParameterizedType(); assertEquals("T", fooType.arguments().get(0).asTypeVariable().identifier()); assertEquals(DotNames.OBJECT, fooType.arguments().get(0).asTypeVariable().bounds().get(0).name()); } } ClassInfo producerClass = index.getClassByName(producerName); String producersName = "produce"; MethodInfo producerMethod = producerClass.method(producersName); // Object is the sole type Set<Type> producerMethodTypes = Types.getProducerMethodTypeClosure(producerMethod, dummyDeployment); assertEquals(1, producerMethodTypes.size()); // Object is the sole type FieldInfo producerField = producerClass.field(producersName); Set<Type> producerFieldTypes = Types.getProducerFieldTypeClosure(producerField, dummyDeployment); assertEquals(1, producerFieldTypes.size()); }
Example 19
Source File: SesProcessor.java From quarkus with Apache License 2.0 | 4 votes |
@Override protected DotName syncClientName() { return DotName.createSimple(SesClient.class.getName()); }
Example 20
Source File: ArcProcessor.java From quarkus with Apache License 2.0 | 4 votes |
@BuildStep BeanDefiningAnnotationBuildItem quarkusMain() { return new BeanDefiningAnnotationBuildItem(DotName.createSimple(QuarkusMain.class.getName()), DotNames.SINGLETON); }