Java Code Examples for org.jboss.jandex.ClassInfo#hasNoArgsConstructor()
The following examples show how to use
org.jboss.jandex.ClassInfo#hasNoArgsConstructor() .
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: ResteasyCommonProcessor.java From quarkus with Apache License 2.0 | 5 votes |
private void checkProperConstructorInProvider(AnnotationInstance i) { ClassInfo targetClass = i.target().asClass(); if (!targetClass.hasNoArgsConstructor() || targetClass.methods().stream().filter(m -> m.name().equals("<init>")).count() > 1) { LOGGER.warn( "Classes annotated with @Provider should have a single, no-argument constructor, otherwise dependency injection won't work properly. Offending class is " + targetClass); } }
Example 2
Source File: ClassConfigPropertiesUtil.java From quarkus with Apache License 2.0 | 4 votes |
/** * @return true if the configuration class needs validation */ static boolean addProducerMethodForClassConfigProperties(ClassLoader classLoader, ClassInfo configPropertiesClassInfo, ClassCreator producerClassCreator, String prefixStr, ConfigProperties.NamingStrategy namingStrategy, boolean failOnMismatchingMember, boolean needsQualifier, IndexView applicationIndex, BuildProducer<ReflectiveMethodBuildItem> reflectiveMethods, BuildProducer<ConfigPropertyBuildItem> configProperties) { if (!configPropertiesClassInfo.hasNoArgsConstructor()) { throw new IllegalArgumentException( "Class " + configPropertiesClassInfo + " which is annotated with " + DotNames.CONFIG_PROPERTIES + " must contain a no-arg constructor"); } String configObjectClassStr = configPropertiesClassInfo.name().toString(); boolean needsValidation = needsValidation(); String[] produceMethodParameterTypes = new String[needsValidation ? 2 : 1]; produceMethodParameterTypes[0] = Config.class.getName(); if (needsValidation) { produceMethodParameterTypes[1] = VALIDATOR_CLASS; } /* * Add a method like this: * * @Produces * * @Default // (or @ConfigPrefix qualifier) * public SomeClass produceSomeClass(Config config) { * * } * * or * * @Produces * * @Default // (or @ConfigPrefix qualifier) * public SomeClass produceSomeClass(Config config, Validator validator) { * * } */ String methodName = "produce" + configPropertiesClassInfo.name().withoutPackagePrefix(); if (needsQualifier) { // we need to differentiate the different producers of the same class methodName = methodName + "WithPrefix" + HashUtil.sha1(prefixStr); } try (MethodCreator methodCreator = producerClassCreator.getMethodCreator( methodName, configObjectClassStr, produceMethodParameterTypes)) { methodCreator.addAnnotation(Produces.class); if (needsQualifier) { methodCreator.addAnnotation(AnnotationInstance.create(DotNames.CONFIG_PREFIX, null, new AnnotationValue[] { AnnotationValue.createStringValue("value", prefixStr) })); } else { methodCreator.addAnnotation(Default.class); } ResultHandle configObject = populateConfigObject(classLoader, configPropertiesClassInfo, prefixStr, namingStrategy, failOnMismatchingMember, methodCreator, applicationIndex, reflectiveMethods, configProperties); if (needsValidation) { createValidationCodePath(methodCreator, configObject, prefixStr); } else { methodCreator.returnValue(configObject); } } return needsValidation; }
Example 3
Source File: LiquibaseProcessor.java From quarkus with Apache License 2.0 | 4 votes |
/** * The default service loader is super slow * * As part of the extension build we index liquibase, then we use this index to find all implementations of services */ @BuildStep(onlyIfNot = NativeBuild.class) @Record(STATIC_INIT) public void fastServiceLoader(LiquibaseRecorder recorder, List<JdbcDataSourceBuildItem> jdbcDataSourceBuildItems) throws IOException { DotName liquibaseServiceName = DotName.createSimple(LiquibaseService.class.getName()); try (InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("META-INF/liquibase.idx")) { IndexReader reader = new IndexReader(in); Index index = reader.read(); Map<String, List<String>> services = new HashMap<>(); for (Class<?> c : Arrays.asList(liquibase.diff.compare.DatabaseObjectComparator.class, liquibase.parser.NamespaceDetails.class, liquibase.precondition.Precondition.class, liquibase.database.Database.class, liquibase.parser.ChangeLogParser.class, liquibase.change.Change.class, liquibase.snapshot.SnapshotGenerator.class, liquibase.changelog.ChangeLogHistoryService.class, liquibase.datatype.LiquibaseDataType.class, liquibase.executor.Executor.class, liquibase.lockservice.LockService.class, liquibase.sqlgenerator.SqlGenerator.class, liquibase.license.LicenseService.class)) { List<String> impls = new ArrayList<>(); services.put(c.getName(), impls); Set<ClassInfo> classes = new HashSet<>(); if (c.isInterface()) { classes.addAll(index.getAllKnownImplementors(DotName.createSimple(c.getName()))); } else { classes.addAll(index.getAllKnownSubclasses(DotName.createSimple(c.getName()))); } for (ClassInfo found : classes) { if (Modifier.isAbstract(found.flags()) || Modifier.isInterface(found.flags()) || !found.hasNoArgsConstructor() || !Modifier.isPublic(found.flags())) { continue; } AnnotationInstance annotationInstance = found.classAnnotation(liquibaseServiceName); if (annotationInstance == null || !annotationInstance.value("skip").asBoolean()) { impls.add(found.name().toString()); } } } //if we know what DB types are in use we limit them //this gives a huge startup time boost //otherwise it generates SQL for every DB boolean allKnown = true; Set<String> databases = new HashSet<>(); for (JdbcDataSourceBuildItem i : jdbcDataSourceBuildItems) { String known = KIND_TO_IMPL.get(i.getDbKind()); if (known == null) { allKnown = false; } else { databases.add(known); } } if (allKnown) { services.put(Database.class.getName(), new ArrayList<>(databases)); } recorder.setJvmServiceImplementations(services); } }
Example 4
Source File: LiquibaseProcessor.java From keycloak with Apache License 2.0 | 4 votes |
@Record(ExecutionTime.STATIC_INIT) @BuildStep void configure(KeycloakRecorder recorder) { DotName liquibaseServiceName = DotName.createSimple(LiquibaseService.class.getName()); Map<String, List<String>> services = new HashMap<>(); try (InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("META-INF/liquibase.idx")) { IndexReader reader = new IndexReader(in); Index index = reader.read(); for (Class<?> c : Arrays.asList(liquibase.diff.compare.DatabaseObjectComparator.class, liquibase.parser.NamespaceDetails.class, liquibase.precondition.Precondition.class, Database.class, ChangeLogParser.class, liquibase.change.Change.class, liquibase.snapshot.SnapshotGenerator.class, liquibase.changelog.ChangeLogHistoryService.class, liquibase.datatype.LiquibaseDataType.class, liquibase.executor.Executor.class, LockService.class, SqlGenerator.class)) { List<String> impls = new ArrayList<>(); services.put(c.getName(), impls); Set<ClassInfo> classes = new HashSet<>(); if (c.isInterface()) { classes.addAll(index.getAllKnownImplementors(DotName.createSimple(c.getName()))); } else { classes.addAll(index.getAllKnownSubclasses(DotName.createSimple(c.getName()))); } for (ClassInfo found : classes) { if (Modifier.isAbstract(found.flags()) || Modifier.isInterface(found.flags()) || !found.hasNoArgsConstructor() || !Modifier.isPublic(found.flags())) { continue; } AnnotationInstance annotationInstance = found.classAnnotation(liquibaseServiceName); if (annotationInstance == null || !annotationInstance.value("skip").asBoolean()) { impls.add(found.name().toString()); } } } } catch (IOException cause) { throw new RuntimeException("Failed to get liquibase jandex index", cause); } services.put(Logger.class.getName(), Arrays.asList(KeycloakLogger.class.getName())); services.put(LockService.class.getName(), Arrays.asList(DummyLockService.class.getName())); services.put(ChangeLogParser.class.getName(), Arrays.asList(XMLChangeLogSAXParser.class.getName())); services.get(SqlGenerator.class.getName()).add(CustomInsertLockRecordGenerator.class.getName()); services.get(SqlGenerator.class.getName()).add(CustomLockDatabaseChangeLogGenerator.class.getName()); recorder.configureLiquibase(services); }