/* BSD 2-Clause License - see OPAL/LICENSE for details. */ package org.opalj package da import scala.io.Source import scala.xml.Node import scala.xml.NodeSeq import scala.xml.Text import scala.xml.Unparsed import org.opalj.io.process import org.opalj.bi.AccessFlags import org.opalj.bi.reader.Constant_PoolAbstractions import org.opalj.bi.ACC_PUBLIC import org.opalj.bi.ACC_SUPER /** * @author Michael Eichberg * @author Wael Alkhatib * @author Isbel Isbel * @author Noorulla Sharief * @author Andre Pacak */ case class ClassFile( constant_pool: Constant_Pool, minor_version: Int, major_version: Int, access_flags: Int = ACC_PUBLIC.mask | ACC_SUPER.mask, this_class: Constant_Pool_Index, super_class: Constant_Pool_Index, interfaces: Interfaces = NoInterfaces, fields: Fields = NoFields, methods: Methods = NoMethods, attributes: Attributes = NoAttributes ) { assert({ val cp0 = constant_pool(0) (cp0 eq null) || cp0.isInstanceOf[Constant_PoolAbstractions#DeferredActionsStore] }) /** * Size of the class file in bytes. */ def size: Int = { 4 + // magic 2 + // minor_version 2 + // major_version 2 + // constant_pool_count { val cpIt = constant_pool.iterator cpIt.next() // the first entry is always empty in the class file cpIt. filter(_ ne null /*handles the case of Constant_Long and Constant_Double*/ ). map(_.size). sum } + 2 + // access_flags 2 + // this_class 2 + // super_class 2 + // interfaces count interfaces.length * 2 + // interfaces[interfaces_count] 2 + // fields_count fields.view.map(_.size).sum + 2 + // methods_count methods.view.map(_.size).sum + 2 + // attributes_count attributes.view.map(_.size).sum } def jdkVersion: String = org.opalj.bi.jdkVersion(major_version) private[this] implicit val cp = constant_pool /** * The fully qualified name of this class in Java notation (i.e., using dots * to seperate packages.) */ final val thisType: ObjectTypeInfo = cp(this_class).asConstantClass.asJavaClassOrInterfaceType final val superTypes = { { if (super_class != 0) Seq( Text("extends "), asJavaObjectType(cp(super_class).toString).asSpan("extends"), Text(" ") ) else NodeSeq.Empty } ++ { if (interfaces.nonEmpty) Seq( Text("implements "), asJavaObjectType(cp(interfaces.head).toString).asSpan("implements"), interfaces.tail.map { i => Seq(Text(", "), asJavaObjectType(cp(i).toString).asSpan("implements")) } ) else NodeSeq.Empty } } /** * Converts the constant pool to (x)HTML5. */ def cpToXHTML: Node = { val cpEntries = for { cpIndex <- 1 until constant_pool.length cpNode = cp(cpIndex) if cpNode != null /* <= need for constant_double/_long entries */ } yield {