Esempio n. 1
0
 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;
 }
Esempio n. 2
0
 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;
 }
Esempio n. 3
0
 /** @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);
 }
Esempio n. 4
0
  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");
        }
      }
    }
  }
  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());
  }
Esempio n. 6
0
  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();
  }
 /**
  * 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);
 }