@Test public void testSchemaInPersistenceMetadata() { Index index = getMockedIndex("default-schema.xml"); index.printAnnotations(); // Global Configuration should be accessed like this, not from ClassInfo List<AnnotationInstance> annotationInstanceList = index.getAnnotations(JPADotNames.TABLE_GENERATOR); assertNotNull(annotationInstanceList); assertEquals(1, annotationInstanceList.size()); AnnotationInstance generator = annotationInstanceList.get(0); assertEquals("TABLE_GEN", generator.value("name").asString()); assertEquals("ANNOTATION_CATALOG", generator.value("catalog").asString()); assertEquals("ANNOTATION_SCHEMA", generator.value("schema").asString()); annotationInstanceList = index.getAnnotations(JPADotNames.SEQUENCE_GENERATOR); assertNotNull(annotationInstanceList); assertEquals(1, annotationInstanceList.size()); generator = annotationInstanceList.get(0); assertEquals("SEQ_GEN", generator.value("name").asString()); assertEquals("XML_CATALOG", generator.value("catalog").asString()); assertEquals("XML_SCHEMA", generator.value("schema").asString()); assertEquals(123, generator.value("initialValue").asInt()); // Book and Author and Topic are all not defined @Table // but orm xml defines default schema and catalog in persistence-unit-metadata // so, we have to mock @Table for entities, Book and Author but not Topic which is a Embeddable annotationInstanceList = index.getAnnotations(JPADotNames.TABLE); assertNotNull(annotationInstanceList); assertEquals(2, annotationInstanceList.size()); for (AnnotationInstance table : annotationInstanceList) { assertEquals("XML_CATALOG", table.value("catalog").asString()); assertEquals("XML_SCHEMA", table.value("schema").asString()); } }
/** * Entity has a @AttributeOverride on property topic and this property also has a * <attribute-override> in orm.xml but with different name by jpa override rules, this two * attribute-override should be merged into one @AttributeOverrides */ @Test public void testAttributeOverride() { Index index = getMockedIndex("AttributeOverride.xml"); DotName className = DotName.createSimple(Book.class.getName()); index.printAnnotations(); assertHasNoAnnotation(index, className, JPADotNames.ATTRIBUTE_OVERRIDE); assertAnnotationValue( index, className, JPADotNames.ATTRIBUTE_OVERRIDES, new AnnotationValueChecker() { @Override public void check(AnnotationInstance annotationInstance) { AnnotationValue value = annotationInstance.value(); assertNotNull(value); AnnotationInstance[] annotationInstances = value.asNestedArray(); assertEquals(2, annotationInstances.length); AnnotationInstance ai = annotationInstances[0]; String name = ai.value("name").asString(); AnnotationValue columnValue = ai.value("column").asNested().value("name"); if (name.equals("title")) { assertEquals("TOC_TITLE", columnValue.asString()); } else if (name.equals("summary")) { assertEquals("TOPIC_SUMMARY", columnValue.asString()); } else { fail( "AttributeOverride's name is " + name + ", should be either 'title' or 'summary'"); } } }); }
@Test public void testSchemaInEntityMapping() { Index index = getMockedIndex("default-schema2.xml"); index.printAnnotations(); // Global Configuration should be accessed like this, not from ClassInfo List<AnnotationInstance> annotationInstanceList = index.getAnnotations(JPADotNames.TABLE_GENERATOR); assertNotNull(annotationInstanceList); assertEquals(1, annotationInstanceList.size()); AnnotationInstance generator = annotationInstanceList.get(0); assertEquals("TABLE_GEN", generator.value("name").asString()); assertEquals("ANNOTATION_CATALOG", generator.value("catalog").asString()); assertEquals("ANNOTATION_SCHEMA", generator.value("schema").asString()); annotationInstanceList = index.getAnnotations(JPADotNames.SEQUENCE_GENERATOR); assertNotNull(annotationInstanceList); assertEquals(1, annotationInstanceList.size()); generator = annotationInstanceList.get(0); assertEquals("SEQ_GEN", generator.value("name").asString()); assertNull(generator.value("catalog")); assertNull(generator.value("schema")); assertEquals(123, generator.value("initialValue").asInt()); annotationInstanceList = index.getAnnotations(JPADotNames.TABLE); assertNotNull(annotationInstanceList); assertEquals(0, annotationInstanceList.size()); }
/** @see {@link Index#getClassByName(org.jboss.jandex.DotName)} */ public ClassInfo getClassByName(final DotName className) { for (Index index : indexes) { final ClassInfo info = index.getClassByName(className); if (info != null) { return info; } } return null; }
/** @see {@link org.jboss.jandex.Index#getKnownClasses()} */ public Collection<ClassInfo> getKnownClasses() { final List<ClassInfo> allKnown = new ArrayList<ClassInfo>(); for (Index index : indexes) { final Collection<ClassInfo> list = index.getKnownClasses(); if (list != null) { allKnown.addAll(list); } } return Collections.unmodifiableCollection(allKnown); }
/** @see {@link Index#getKnownSubclasses(org.jboss.jandex.DotName)} */ public List<ClassInfo> getKnownSubclasses(final DotName className) { final List<ClassInfo> allKnown = new ArrayList<ClassInfo>(); for (Index index : indexes) { final List<ClassInfo> list = index.getKnownSubclasses(className); if (list != null) { allKnown.addAll(list); } } return Collections.unmodifiableList(allKnown); }
/** @see {@link Index#getAnnotations(org.jboss.jandex.DotName)} */ public List<AnnotationInstance> getAnnotations(final DotName annotationName) { final List<AnnotationInstance> allInstances = new ArrayList<AnnotationInstance>(); for (Index index : indexes) { final List<AnnotationInstance> list = index.getAnnotations(annotationName); if (list != null) { allInstances.addAll(list); } } return Collections.unmodifiableList(allInstances); }
@Test public void testEntityMetadataComplete() { Index index = getMockedIndex("entity-metadata-complete.xml"); DotName authorName = DotName.createSimple(Author.class.getName()); ClassInfo authorClassInfo = index.getClassByName(authorName); assertHasAnnotation(index, authorName, JPADotNames.ENTITY); assertHasAnnotation(index, authorName, JPADotNames.ID_CLASS); assertEquals(2, authorClassInfo.annotations().size()); DotName bookName = DotName.createSimple(Book.class.getName()); assertHasAnnotation(index, bookName, JPADotNames.ENTITY); }
@Test public void testOverrideToMappedSuperClass() { Index index = getMockedIndex("override-to-mappedsuperclass.xml"); index.printAnnotations(); DotName authorName = DotName.createSimple(Author.class.getName()); assertHasAnnotation(index, authorName, JPADotNames.ENTITY); assertHasNoAnnotation(index, authorName, JPADotNames.TABLE); DotName bookName = DotName.createSimple(Book.class.getName()); assertHasAnnotation(index, bookName, JPADotNames.MAPPED_SUPERCLASS); assertHasNoAnnotation(index, bookName, JPADotNames.TABLE); }
// TODO verify that association exists. See former VerifyFetchProfileReferenceSecondPass public static void bind(MetadataImpl metadata, Index jandex) { for (AnnotationInstance fetchProfile : jandex.getAnnotations(HibernateDotNames.FETCH_PROFILE)) { bind(metadata, fetchProfile); } for (AnnotationInstance fetchProfiles : jandex.getAnnotations(HibernateDotNames.FETCH_PROFILES)) { for (AnnotationInstance fetchProfile : JandexHelper.getValueAsArray(fetchProfiles, "value")) { bind(metadata, fetchProfile); } } }
private static ClassInfo getModuleInfo(final Index index, final String moduleName) { // we need to escape any java keyword from the package list String quotedModuleName = JVMModuleUtil.quoteJavaKeywords(moduleName); DotName moduleClassName = DotName.createSimple(quotedModuleName + ".$module_"); ClassInfo ret = index.getClassByName(moduleClassName); if (ret == null) { // read previous module descriptor name moduleClassName = DotName.createSimple(quotedModuleName + ".module_"); ret = index.getClassByName(moduleClassName); } return ret; }
/** * Binds all {@link org.hibernate.annotations.TypeDef} and {@link TypeDefs} annotations to the * supplied metadata. * * @param metadata the global metadata * @param jandex the jandex jandex */ public static void bind(MetadataImplementor metadata, Index jandex) { for (AnnotationInstance typeDef : jandex.getAnnotations(HibernateDotNames.TYPE_DEF)) { bind(metadata, typeDef); } for (AnnotationInstance typeDefs : jandex.getAnnotations(HibernateDotNames.TYPE_DEFS)) { AnnotationInstance[] typeDefAnnotations = JandexHelper.getValue(typeDefs, "value", AnnotationInstance[].class); for (AnnotationInstance typeDef : typeDefAnnotations) { bind(metadata, typeDef); } } }
private void dumpIndex(File source) throws IOException { FileInputStream input = new FileInputStream(source); IndexReader reader = new IndexReader(input); long start = System.currentTimeMillis(); Index index = reader.read(); long end = System.currentTimeMillis() - start; index.printAnnotations(); index.printSubclasses(); System.out.printf("\nRead %s in %.04f seconds\n", source.getName(), end / 1000.0); }
@Test public void testDefaultCascadePersist() { Default defaults = new Default(); defaults.setCascadePersist(true); Index index = getIndex(); Map<DotName, List<AnnotationInstance>> annotations = new HashMap<DotName, List<AnnotationInstance>>(); annotations.putAll( index.getClassByName(DotName.createSimple(Parent.class.getName())).annotations()); assertEquals(4, annotations.size()); assertEquals(1, annotations.get(JPADotNames.ENTITY).size()); assertEquals(1, annotations.get(JPADotNames.ID).size()); assertEquals(1, annotations.get(JPADotNames.ONE_TO_MANY).size()); assertEquals(1, annotations.get(JPADotNames.MANY_TO_ONE).size()); DefaultConfigurationHelper.INSTANCE.applyDefaults(annotations, defaults); assertEquals(4, annotations.size()); assertEquals(1, annotations.get(JPADotNames.ENTITY).size()); assertEquals(1, annotations.get(JPADotNames.ID).size()); assertEquals(1, annotations.get(JPADotNames.ONE_TO_MANY).size()); assertEquals(1, annotations.get(JPADotNames.MANY_TO_ONE).size()); AnnotationInstance oneToMany = annotations.get(JPADotNames.ONE_TO_MANY).get(0); String[] cascadeTypes = oneToMany.value("cascade").asEnumArray(); assertArrayEquals(new String[] {"ALL", "DETACH", "PERSIST"}, cascadeTypes); AnnotationInstance manyToOne = annotations.get(JPADotNames.MANY_TO_ONE).get(0); cascadeTypes = manyToOne.value("cascade").asEnumArray(); assertArrayEquals(new String[] {"PERSIST"}, cascadeTypes); annotations.clear(); annotations.putAll( index.getClassByName(DotName.createSimple(Child.class.getName())).annotations()); assertEquals(3, annotations.size()); assertEquals(1, annotations.get(JPADotNames.ENTITY).size()); assertEquals(1, annotations.get(JPADotNames.ID).size()); assertEquals(1, annotations.get(JPADotNames.MANY_TO_ONE).size()); DefaultConfigurationHelper.INSTANCE.applyDefaults(annotations, defaults); assertEquals(3, annotations.size()); assertEquals(1, annotations.get(JPADotNames.ENTITY).size()); assertEquals(1, annotations.get(JPADotNames.ID).size()); assertEquals(1, annotations.get(JPADotNames.MANY_TO_ONE).size()); manyToOne = annotations.get(JPADotNames.MANY_TO_ONE).get(0); cascadeTypes = manyToOne.value("cascade").asEnumArray(); assertArrayEquals(new String[] {"PERSIST", "ALL", "DETACH"}, cascadeTypes); }
@Test public void testPersistenceUnitMetadataMetadataComplete() { JaxbEntity author = new JaxbEntity(); author.setClazz(Author.class.getName()); IndexBuilder indexBuilder = getIndexBuilder(); EntityMappingsMocker.Default defaults = new EntityMappingsMocker.Default(); defaults.setMetadataComplete(true); EntityMocker entityMocker = new EntityMocker(indexBuilder, author, defaults); entityMocker.preProcess(); entityMocker.process(); Index index = indexBuilder.build(new EntityMappingsMocker.Default()); DotName className = DotName.createSimple(Author.class.getName()); ClassInfo classInfo = index.getClassByName(className); assertEquals(1, classInfo.annotations().size()); assertHasAnnotation(index, className, JPADotNames.ENTITY); }
@Override @SuppressWarnings({"unchecked"}) public void prepare(MetadataSources sources) { // create a jandex index from the annotated classes Indexer indexer = new Indexer(); for (Class<?> clazz : sources.getAnnotatedClasses()) { indexClass(indexer, clazz.getName().replace('.', '/') + ".class"); } // add package-info from the configured packages for (String packageName : sources.getAnnotatedPackages()) { indexClass(indexer, packageName.replace('.', '/') + "/package-info.class"); } index = indexer.complete(); List<JaxbRoot<XMLEntityMappings>> mappings = new ArrayList<JaxbRoot<XMLEntityMappings>>(); for (JaxbRoot<?> root : sources.getJaxbRootList()) { if (root.getRoot() instanceof XMLEntityMappings) { mappings.add((JaxbRoot<XMLEntityMappings>) root); } } if (!mappings.isEmpty()) { // process the xml configuration final OrmXmlParser ormParser = new OrmXmlParser(metadata); index = ormParser.parseAndUpdateIndex(mappings, index); } if (index.getAnnotations(PseudoJpaDotNames.DEFAULT_DELIMITED_IDENTIFIERS) != null) { metadata.setGloballyQuotedIdentifiers(true); } }
public static boolean hasClassesFromPackage(final Index index, final String pck) { for (ClassInfo ci : index.getKnownClasses()) { if (ci.name().toString().startsWith(pck)) { return true; } } return false; }
@Test public void testDefaultSchemaToAnnotationInstance() { Default defaults = new Default(); defaults.setSchema("hib_schema"); defaults.setCatalog("hib_catalog"); Index index = getIndex(); Map<DotName, List<AnnotationInstance>> annotations = new HashMap<DotName, List<AnnotationInstance>>(); annotations.putAll( index.getClassByName(DotName.createSimple(Parent.class.getName())).annotations()); assertEquals(4, annotations.size()); assertEquals(1, annotations.get(JPADotNames.ENTITY).size()); assertEquals(1, annotations.get(JPADotNames.ID).size()); assertEquals(1, annotations.get(JPADotNames.ONE_TO_MANY).size()); assertEquals(1, annotations.get(JPADotNames.MANY_TO_ONE).size()); DefaultConfigurationHelper.INSTANCE.applyDefaults(annotations, defaults); assertEquals(5, annotations.size()); assertEquals(1, annotations.get(JPADotNames.ENTITY).size()); assertEquals(1, annotations.get(JPADotNames.ID).size()); assertEquals(1, annotations.get(JPADotNames.ONE_TO_MANY).size()); assertEquals(1, annotations.get(JPADotNames.MANY_TO_ONE).size()); assertEquals(1, annotations.get(JPADotNames.TABLE).size()); AnnotationInstance table = annotations.get(JPADotNames.TABLE).get(0); assertEquals("hib_schema", table.value("schema").asString()); assertEquals("hib_catalog", table.value("catalog").asString()); annotations.clear(); annotations.putAll( index.getClassByName(DotName.createSimple(Name.class.getName())).annotations()); DefaultConfigurationHelper.INSTANCE.applyDefaults(annotations, defaults); assertEquals(1, annotations.size()); assertEquals(1, annotations.get(JPADotNames.SECONDARY_TABLES).size()); AnnotationInstance[] secondaryTables = annotations.get(JPADotNames.SECONDARY_TABLES).get(0).value().asNestedArray(); assertEquals(2, secondaryTables.length); AnnotationInstance secondaryTable = secondaryTables[0]; String name = secondaryTable.value("name").asString(); if (name.equals("sec1")) { assertSt1(secondaryTable); assertSt2(secondaryTables[1]); } else { assertSt1(secondaryTables[1]); assertSt2(secondaryTable); } }
private static boolean isWebserviceEndpoint( final ServletMetaData servletMD, final List<Index> annotationIndexes) { final String endpointClassName = ASHelper.getEndpointName(servletMD); if (isJSP(endpointClassName)) return false; final DotName endpointDN = DotName.createSimple(endpointClassName); ClassInfo endpointClassInfo = null; for (final Index index : annotationIndexes) { endpointClassInfo = index.getClassByName(endpointDN); if (endpointClassInfo != null) { if (endpointClassInfo.annotations().containsKey(WEB_SERVICE_ANNOTATION)) return true; if (endpointClassInfo.annotations().containsKey(WEB_SERVICE_PROVIDER_ANNOTATION)) return true; } } return false; }
private Set<String> getMembers(Index index) { HashSet<String> members = new HashSet<>(); for (ClassInfo cls : index.getKnownClasses()) { if (shouldAddMember(cls)) { members.add(classNameToDeclName(cls.name().toString())); } } return members; }
void collectGlobalConfigurationFromIndex(GlobalAnnotations globalAnnotations) { for (DotName annName : DefaultConfigurationHelper.GLOBAL_ANNOTATIONS) { List<AnnotationInstance> annotationInstanceList = index.getAnnotations(annName); if (MockHelper.isNotEmpty(annotationInstanceList)) { globalAnnotations.addIndexedAnnotationInstance(annotationInstanceList); } } globalAnnotations.filterIndexedAnnotations(); }
/** * If {@code xml-mapping-metadata-complete} is defined in PersistenceUnitMetadata, we create a new * empty {@link Index} here. */ void mappingMetadataComplete() { LOG.debug( "xml-mapping-metadata-complete is specified in persistence-unit-metadata, ignore JPA annotations."); index = Index.create( new HashMap<DotName, List<AnnotationInstance>>(), new HashMap<DotName, List<ClassInfo>>(), new HashMap<DotName, List<ClassInfo>>(), new HashMap<DotName, ClassInfo>()); }
private void writeClasses(PackedDataOutputStream stream, Index index) throws IOException { Collection<ClassInfo> classes = index.getKnownClasses(); stream.writePackedU32(classes.size()); for (ClassInfo clazz : classes) { stream.writePackedU32(positionOf(clazz.name())); stream.writePackedU32(clazz.superName() == null ? 0 : positionOf(clazz.superName())); stream.writeShort(clazz.flags()); DotName[] interfaces = clazz.interfaces(); stream.writePackedU32(interfaces.length); for (DotName intf : interfaces) stream.writePackedU32(positionOf(intf)); Set<Entry<DotName, List<AnnotationTarget>>> entrySet = clazz.annotations().entrySet(); stream.writePackedU32(entrySet.size()); for (Entry<DotName, List<AnnotationTarget>> entry : entrySet) { stream.writePackedU32(positionOf(entry.getKey())); List<AnnotationTarget> targets = entry.getValue(); stream.writePackedU32(targets.size()); for (AnnotationTarget target : targets) { if (target instanceof FieldInfo) { FieldInfo field = (FieldInfo) target; stream.writeByte(FIELD_TAG); stream.writePackedU32(positionOf(field.name())); writeType(stream, field.type()); stream.writeShort(field.flags()); } else if (target instanceof MethodInfo) { MethodInfo method = (MethodInfo) target; stream.writeByte(METHOD_TAG); stream.writePackedU32(positionOf(method.name())); stream.writePackedU32(method.args().length); for (int i = 0; i < method.args().length; i++) { writeType(stream, method.args()[i]); } writeType(stream, method.returnType()); stream.writeShort(method.flags()); } else if (target instanceof MethodParameterInfo) { MethodParameterInfo param = (MethodParameterInfo) target; MethodInfo method = param.method(); stream.writeByte(METHOD_PARAMATER_TAG); stream.writePackedU32(positionOf(method.name())); stream.writePackedU32(method.args().length); for (int i = 0; i < method.args().length; i++) { writeType(stream, method.args()[i]); } writeType(stream, method.returnType()); stream.writeShort(method.flags()); stream.writePackedU32(param.position()); } else if (target instanceof ClassInfo) { stream.writeByte(CLASS_TAG); } else throw new IllegalStateException("Unknown target"); } } } }
public static boolean isJaxwsService(final ClassInfo current, final Index index) { ClassInfo tmp = current; while (tmp != null) { final DotName superName = tmp.superName(); if (JAXWS_SERVICE_CLASS.equals(superName)) { return true; } tmp = index.getClassByName(superName); } return false; }
/** * 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); }
public Map<DotName, List<AnnotationInstance>> getIndexedAnnotations(DotName name) { Map<DotName, List<AnnotationInstance>> map = indexedClassInfoAnnotationsMap.get(name); if (map == null) { ClassInfo ci = index.getClassByName(name); if (ci == null || ci.annotations() == null) { map = Collections.emptyMap(); } else { map = new HashMap<DotName, List<AnnotationInstance>>(ci.annotations()); // here we ignore global annotations for (DotName globalAnnotationName : DefaultConfigurationHelper.GLOBAL_ANNOTATIONS) { if (map.containsKey(globalAnnotationName)) { map.put(globalAnnotationName, Collections.<AnnotationInstance>emptyList()); } } } indexedClassInfoAnnotationsMap.put(name, map); } return map; }
private BeanDeploymentArchiveImpl createBeanDeploymentArchive( final Index index, BeanArchiveMetadata beanArchiveMetadata, Module module, String beanArchivePrefix) throws DeploymentUnitProcessingException { Set<String> classNames = new HashSet<String>(); // index may be null if a war has a beans.xml but no WEB-INF/classes if (index != null) { for (ClassInfo classInfo : index.getKnownClasses()) { classNames.add(classInfo.name().toString()); } } return new BeanDeploymentArchiveImpl( classNames, beanArchiveMetadata.getBeansXml(), module, beanArchivePrefix + beanArchiveMetadata.getResourceRoot().getRoot().getPathName()); }
@Override public Collection<Annotation> getAnnotation(Class<?> annotationClass) { List<AnnotationInstance> instances = backingRepository.getAnnotations(DotName.createSimple(annotationClass.getName())); ArrayList<Annotation> annotations = new ArrayList<Annotation>(instances.size()); for (AnnotationInstance instance : instances) { AnnotationTarget target = instance.target(); Annotation annotation = null; if (target instanceof MethodInfo) { MethodInfo m = (MethodInfo) target; List<String> parameterTypes = new ArrayList<String>(m.args().length); for (Type type : m.args()) { parameterTypes.add(type.toString()); } String declaringClass = m.declaringClass().name().toString(); annotation = new AnnotationImpl( declaringClass, cl, parameterTypes, m.name(), true, false, annotationClass); } if (target instanceof FieldInfo) { FieldInfo f = (FieldInfo) target; String declaringClass = f.declaringClass().name().toString(); annotation = new AnnotationImpl(declaringClass, cl, null, f.name(), false, true, annotationClass); } if (target instanceof ClassInfo) { ClassInfo c = (ClassInfo) target; annotation = new AnnotationImpl(c.name().toString(), cl, null, null, false, false, annotationClass); } if (annotation != null) { annotations.add(annotation); } } annotations.trimToSize(); if (annotations.size() == 0) { return null; } else { return Collections.unmodifiableList(annotations); } }
ClassInfo createClassInfo(String className) { if (StringHelper.isEmpty(className)) { throw new AssertionFailure("Class Name used to create ClassInfo is empty."); } DotName classDotName = DotName.createSimple(className); if (classes.containsKey(classDotName)) { // classInfoAnnotationsMap.put( classDotName, new HashMap<DotName, // List<AnnotationInstance>>(classes.get( classDotName ).annotations()) ); return classes.get(classDotName); } Class clazz = serviceRegistry.getService(ClassLoaderService.class).classForName(className); DotName superName = null; DotName[] interfaces = null; short access_flag; ClassInfo annClassInfo = index.getClassByName(classDotName); if (annClassInfo != null) { superName = annClassInfo.superName(); interfaces = annClassInfo.interfaces(); access_flag = annClassInfo.flags(); } else { Class superClass = clazz.getSuperclass(); if (superClass != null) { superName = DotName.createSimple(superClass.getName()); } Class[] classInterfaces = clazz.getInterfaces(); if (classInterfaces != null && classInterfaces.length > 0) { interfaces = new DotName[classInterfaces.length]; for (int i = 0; i < classInterfaces.length; i++) { interfaces[i] = DotName.createSimple(classInterfaces[i].getName()); } } access_flag = (short) (clazz.getModifiers() | 0x20); // (modifiers | ACC_SUPER) } Map<DotName, List<AnnotationInstance>> map = new HashMap<DotName, List<AnnotationInstance>>(); classInfoAnnotationsMap.put(classDotName, map); ClassInfo classInfo = ClassInfo.create(classDotName, superName, access_flag, interfaces, map); classes.put(classDotName, classInfo); addSubClasses(superName, classInfo); addImplementors(interfaces, classInfo); return classInfo; }
private void buildTables(Index index) { pool = new StrongInternPool<String>(); classTable = new TreeMap<DotName, Integer>(); // Build the pool for all strings for (ClassInfo clazz : index.getKnownClasses()) { addClassName(clazz.name()); if (clazz.superName() != null) addClassName(clazz.superName()); for (DotName intf : clazz.interfaces()) addClassName(intf); for (Entry<DotName, List<AnnotationTarget>> entry : clazz.annotations().entrySet()) { addClassName(entry.getKey()); for (AnnotationTarget target : entry.getValue()) { if (target instanceof FieldInfo) { FieldInfo field = (FieldInfo) target; intern(field.name()); addClassName(field.type().name()); } else if (target instanceof MethodInfo) { MethodInfo method = (MethodInfo) target; intern(method.name()); for (Type type : method.args()) addClassName(type.name()); addClassName(method.returnType().name()); } else if (target instanceof MethodParameterInfo) { MethodParameterInfo param = (MethodParameterInfo) target; intern(param.method().name()); for (Type type : param.method().args()) addClassName(type.name()); addClassName(param.method().returnType().name()); } } } } poolIndex = pool.index(); }