diff --git a/src/main/scala/cafebabe/ClassFile.scala b/src/main/scala/cafebabe/ClassFile.scala index fba3e53..f97407b 100644 --- a/src/main/scala/cafebabe/ClassFile.scala +++ b/src/main/scala/cafebabe/ClassFile.scala @@ -28,12 +28,14 @@ class ClassFile(val className: String, parentName: Option[String] = None) extend private var fields: List[FieldInfo] = Nil private var methods: List[MethodInfo] = Nil + private var interfaces: List[InterfaceInfo] = Nil + private var attributes : List[AttributeInfo] = Nil - // TODO - private var interfacesCount: U2 = 0 - private var interfaces: List[U1] = Nil + def addInterface(name: String) { + val nameIndex = constantPool.addClass(constantPool.addString(name)) - private var attributes : List[AttributeInfo] = Nil + interfaces = InterfaceInfo(name, nameIndex) :: interfaces + } private var _srcNameWasSet = false /** Attaches the name of the original source file to the class file. */ @@ -140,7 +142,7 @@ class ClassFile(val className: String, parentName: Option[String] = None) extend accessFlags << thisClass << superClass << - interfacesCount << + interfaces.size.asInstanceOf[U2] << interfaces.reverse << fields.size.asInstanceOf[U2] << fields << methods.size.asInstanceOf[U2] << methods << attributes.size.asInstanceOf[U2] << attributes diff --git a/src/main/scala/cafebabe/InterfaceInfo.scala b/src/main/scala/cafebabe/InterfaceInfo.scala new file mode 100644 index 0000000..1820a4d --- /dev/null +++ b/src/main/scala/cafebabe/InterfaceInfo.scala @@ -0,0 +1,9 @@ +package cafebabe + +import ClassFileTypes._ + +case class InterfaceInfo(interfaceName: String, nameIndex: U2) extends Streamable { + override def toStream(stream: ByteStream): ByteStream = { + stream << nameIndex + } +}