Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement support for interfaces #7

Merged
merged 1 commit into from
Dec 13, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/main/scala/cafebabe/ClassFile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/main/scala/cafebabe/InterfaceInfo.scala
Original file line number Diff line number Diff line change
@@ -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
}
}