コード例 #1
0
ファイル: IndexWriter.java プロジェクト: baileyje/jandex
  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");
        }
      }
    }
  }
コード例 #2
0
ファイル: IndexWriter.java プロジェクト: baileyje/jandex
  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();
  }