本文整理汇总了Java中org.jboss.jandex.Index类的典型用法代码示例。如果您正苦于以下问题:Java Index类的具体用法?Java Index怎么用?Java Index使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Index类属于org.jboss.jandex包,在下文中一共展示了Index类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findRootEntityClassInfo
import org.jboss.jandex.Index; //导入依赖的package包/类
/**
* Finds the root entity starting at the entity given by {@code info}. The root entity is not the highest superclass
* in a java type sense, but the highest superclass which is also an entity (annotated w/ {@code @Entity}.
*
* @param index the annotation repository
* @param info the class info representing an entity
*
* @return Finds the root entity starting at the entity given by {@code info}
*/
private static ClassInfo findRootEntityClassInfo(Index index, ClassInfo info) {
ClassInfo rootEntity = info;
DotName superName = info.superName();
ClassInfo tmpInfo;
// walk up the hierarchy until java.lang.Object
while ( !OBJECT.equals( superName ) ) {
tmpInfo = index.getClassByName( superName );
if ( isEntityClass( tmpInfo ) ) {
rootEntity = tmpInfo;
}
superName = tmpInfo.superName();
}
return rootEntity;
}
示例2: build
import org.jboss.jandex.Index; //导入依赖的package包/类
/**
* Build new {@link Index} with mocked annotations from orm.xml.
* This method should be only called once per {@org.hibernate.metamodel.source.annotations.xml.mocker.IndexBuilder IndexBuilder} instance.
*
* @param globalDefaults Global defaults from <persistence-unit-metadata>, or null.
*
* @return Index.
*/
Index build(EntityMappingsMocker.Default globalDefaults) {
//merge annotations that not overrided by xml into the new Index
for ( ClassInfo ci : index.getKnownClasses() ) {
DotName name = ci.name();
if ( indexedClassInfoAnnotationsMap.containsKey( name ) ) {
//this class has been overrided by orm.xml
continue;
}
if ( ci.annotations() != null && !ci.annotations().isEmpty() ) {
Map<DotName, List<AnnotationInstance>> tmp = new HashMap<DotName, List<AnnotationInstance>>( ci.annotations() );
DefaultConfigurationHelper.INSTANCE.applyDefaults( tmp, globalDefaults );
mergeAnnotationMap( tmp, annotations );
classes.put( name, ci );
if ( ci.superName() != null ) {
addSubClasses( ci.superName(), ci );
}
if ( ci.interfaces() != null && ci.interfaces().length > 0 ) {
addImplementors( ci.interfaces(), ci );
}
}
}
return Index.create(
annotations, subclasses, implementors, classes
);
}
示例3: implementsMethodRecursive
import org.jboss.jandex.Index; //导入依赖的package包/类
/**
*
* @param i
* @param methodReference
* @param ci
* @return whether any superclass implements the method
*/
public static boolean implementsMethodRecursive ( Index i, MethodReference methodReference, ClassInfo ci ) {
if ( implementsMethod(methodReference, ci) ) {
return true;
}
DotName superName = ci.superName();
if ( superName != null ) {
ClassInfo superByName = i.getClassByName(superName);
if ( superByName == null || "java.lang.Object".equals(superByName.name().toString()) ) { //$NON-NLS-1$
return false;
}
return implementsMethodRecursive(i, methodReference, superByName);
}
return false;
}
示例4: createIndex
import org.jboss.jandex.Index; //导入依赖的package包/类
/**
* Creates an annotation index for the given entity type
*/
public synchronized static Index createIndex(Class<?> type) {
Index index = indices.get(type);
if (index == null) {
try {
Indexer indexer = new Indexer();
Class<?> currentType = type;
while ( currentType != null ) {
String className = currentType.getName().replace(".", "/") + ".class";
InputStream stream = type.getClassLoader()
.getResourceAsStream(className);
indexer.index(stream);
currentType = currentType.getSuperclass();
}
index = indexer.complete();
indices.put(type, index);
} catch (IOException e) {
throw new RuntimeException("Failed to initialize Indexer", e);
}
}
return index;
}
示例5: getKnownImplementors
import org.jboss.jandex.Index; //导入依赖的package包/类
private void getKnownImplementors(DotName name, Set<ClassInfo> allKnown, Set<DotName> subInterfacesToProcess,
Set<DotName> processedClasses) {
for (Index index : indexes) {
final List<ClassInfo> list = index.getKnownDirectImplementors(name);
if (list != null) {
for (final ClassInfo clazz : list) {
final DotName className = clazz.name();
if (!processedClasses.contains(className)) {
if (Modifier.isInterface(clazz.flags())) {
subInterfacesToProcess.add(className);
} else {
if (!allKnown.contains(clazz)) {
allKnown.add(clazz);
processedClasses.add(className);
getAllKnownSubClasses(className, allKnown, processedClasses);
}
}
}
}
}
}
}
示例6: getAnnotationIndexes
import org.jboss.jandex.Index; //导入依赖的package包/类
public static Map<ResourceRoot, Index> getAnnotationIndexes(final DeploymentUnit deploymentUnit) {
final List<ResourceRoot> allResourceRoots = new ArrayList<ResourceRoot>();
allResourceRoots.addAll(deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS));
allResourceRoots.add(deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT));
Map<ResourceRoot, Index> indexes = new HashMap<ResourceRoot, Index>();
for (ResourceRoot resourceRoot : allResourceRoots) {
if (resourceRoot == null)
continue;
Index index = resourceRoot.getAttachment(Attachments.ANNOTATION_INDEX);
if (index != null) {
indexes.put(resourceRoot, index);
}
}
return indexes;
}
示例7: calculateModuleIndex
import org.jboss.jandex.Index; //导入依赖的package包/类
private Index calculateModuleIndex(final Module module) throws ModuleLoadException, IOException {
final Indexer indexer = new Indexer();
final PathFilter filter = PathFilters.getDefaultImportFilter();
final Iterator<Resource> iterator = module.iterateResources(filter);
while (iterator.hasNext()) {
Resource resource = iterator.next();
if(resource.getName().endsWith(".class")) {
try (InputStream in = resource.openStream()) {
indexer.index(in);
} catch (Exception e) {
ServerLogger.DEPLOYMENT_LOGGER.cannotIndexClass(resource.getName(), resource.getURL().toExternalForm(), e);
}
}
}
return indexer.complete();
}
示例8: buildCompositeIndex
import org.jboss.jandex.Index; //导入依赖的package包/类
public static CompositeIndex buildCompositeIndex(Module module) {
try {
final Enumeration<URL> resources = module.getClassLoader().getResources(INDEX_LOCATION);
if (!resources.hasMoreElements()) {
return null;
}
final Set<Index> indexes = new HashSet<Index>();
while (resources.hasMoreElements()) {
final URL url = resources.nextElement();
InputStream stream = url.openStream();
try {
IndexReader reader = new IndexReader(stream);
indexes.add(reader.read());
} finally {
stream.close();
}
}
return new CompositeIndex(indexes);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例9: findOverrideMethods
import org.jboss.jandex.Index; //导入依赖的package包/类
private static List<MethodInfo> findOverrideMethods(final Index index, final ClassInfo clasz,
final MethodInfo methodToFind, final int level) {
final List<MethodInfo> methods = new ArrayList<>();
if (clasz != null) {
// Super classes
if (level > 0) {
addIfFound(index, clasz, methodToFind, methods);
}
// Check interfaces
methods.addAll(findInterfaceMethods(index, clasz, methodToFind));
// Check super class
final DotName superName = clasz.superName();
final ClassInfo superClass = index.getClassByName(superName);
methods.addAll(findOverrideMethods(index, superClass, methodToFind, (level + 1)));
}
return methods;
}
示例10: testHasNullabilityInfoOnAllMethodsFalse
import org.jboss.jandex.Index; //导入依赖的package包/类
@Test
public void testHasNullabilityInfoOnAllMethodsFalse() {
// PREPARE
final Index index = index(getClass().getClassLoader(), InvalidNullabilityClass.class.getName());
// TEST + VERIFY
try {
assertThat(index).hasNullabilityInfoOnAllMethods();
} catch (final AssertionError ex) {
assertThat(ex.getMessage())
.isEqualTo(
"A parameter or the return value has neither a @NotNull nor a @Nullable annotation:\n"
+ "org.fuin.units4j.JandexAssertTest$InvalidNullabilityClass\tvoid <init>(java.lang.String)\tParameter #0 (java.lang.String)\n"
+ "org.fuin.units4j.JandexAssertTest$InvalidNullabilityClass\tvoid b(java.lang.String)\tParameter #0 (java.lang.String)\n"
+ "org.fuin.units4j.JandexAssertTest$InvalidNullabilityClass\tjava.lang.String c(java.lang.String)\tReturn type (java.lang.String)\n"
+ "org.fuin.units4j.JandexAssertTest$InvalidNullabilityClass\tjava.lang.String c(java.lang.String)\tParameter #0 (java.lang.String)\n");
}
}
示例11: findPersistenceTypeNames
import org.jboss.jandex.Index; //导入依赖的package包/类
private Set<String> findPersistenceTypeNames(PersistenceUnitMetadata pu) {
synchronized (CACHED_TYPENAMES) {
Set<String> typeNames = CACHED_TYPENAMES.get(pu);
if (typeNames != null) {
return typeNames;
}
}
Set<String> persistenceTypeNames = new HashSet<String>();
for (Map.Entry<URL, Index> entry : pu.getAnnotationIndex().entrySet()) {
List<AnnotationInstance> instances = entry.getValue().getAnnotations(DotName.createSimple(Entity.class.getName()));
for (AnnotationInstance instance : instances) {
AnnotationTarget target = instance.target();
if (target instanceof ClassInfo) {
ClassInfo classInfo = (ClassInfo) target;
persistenceTypeNames.add(classInfo.name().toString());
}
}
}
synchronized (CACHED_TYPENAMES) {
CACHED_TYPENAMES.put(pu, persistenceTypeNames);
}
return persistenceTypeNames;
}
示例12: analyzeClasses
import org.jboss.jandex.Index; //导入依赖的package包/类
private void analyzeClasses(URLClassLoader classLoader, List<String> classNames)
throws IOException, MojoExecutionException {
Map<String, String> paths = new LinkedHashMap<String, String>();
for (String className : classNames) {
getLog().debug("- Scanning class: " + className);
Index index = getIndexForClass(classLoader, className);
List<AnnotationInstance> annotations = index.getAnnotations(PATH_ANNOTATION);
process(paths, className, annotations);
}
for (String key : paths.keySet())
getLog().debug(key);
}
示例13: indexForClass
import org.jboss.jandex.Index; //导入依赖的package包/类
/**
* Creates a jandex index for the specified classes
*
* @param classLoaderService class loader service
* @param classes the classes to index
*
* @return an annotation repository w/ all the annotation discovered in the specified classes
*/
public static Index indexForClass(ClassLoaderService classLoaderService, Class<?>... classes) {
Indexer indexer = new Indexer();
for ( Class<?> clazz : classes ) {
InputStream stream = classLoaderService.locateResourceStream(
clazz.getName().replace( '.', '/' ) + ".class"
);
try {
indexer.index( stream );
}
catch ( IOException e ) {
StringBuilder builder = new StringBuilder();
builder.append( "[" );
int count = 0;
for ( Class<?> c : classes ) {
builder.append( c.getName() );
if ( count < classes.length - 1 ) {
builder.append( "," );
}
count++;
}
builder.append( "]" );
throw new HibernateException( "Unable to create annotation index for " + builder.toString() );
}
}
return indexer.complete();
}
示例14: addMappedSuperclasses
import org.jboss.jandex.Index; //导入依赖的package包/类
private static void addMappedSuperclasses(Index index, ClassInfo info, List<ClassInfo> classInfoList) {
DotName superName = info.superName();
ClassInfo tmpInfo;
// walk up the hierarchy until java.lang.Object
while ( !OBJECT.equals( superName ) ) {
tmpInfo = index.getClassByName( superName );
if ( isMappedSuperclass( tmpInfo ) ) {
classInfoList.add( tmpInfo );
}
superName = tmpInfo.superName();
}
}
示例15: AnnotationBindingContextImpl
import org.jboss.jandex.Index; //导入依赖的package包/类
public AnnotationBindingContextImpl(MetadataImplementor metadata, Index index) {
this.metadata = metadata;
this.classLoaderService = new ValueHolder<ClassLoaderService>(
new ValueHolder.DeferredInitializer<ClassLoaderService>() {
@Override
public ClassLoaderService initialize() {
return AnnotationBindingContextImpl.this.metadata
.getServiceRegistry()
.getService( ClassLoaderService.class );
}
}
);
this.index = index;
}