示例#1
0
func (self *Class) copyMethods(cf *classfile.ClassFile) {
	self.methods = make([]*Method, len(cf.Methods()))
	for i, methodInfo := range cf.Methods() {
		self.methods[i] = newMethod(self, methodInfo)
		self.methods[i].slot = uint(i)
	}
}
示例#2
0
func newClass(cf *classfile.ClassFile) *Class {
	class := &Class{}
	class.initCond = sync.NewCond(&sync.Mutex{})
	class.accessFlags = cf.AccessFlags()
	class.copyConstantPool(cf)
	class.copyClassNames(cf)
	class.copyFields(cf)
	class.copyMethods(cf)
	class.copyAttributes(cf)
	return class
}
示例#3
0
func getEnclosingMethod(cf *classfile.ClassFile) *EnclosingMethod {
	if emAttr := cf.EnclosingMethodAttribute(); emAttr != nil {
		methodName, methodDescriptor := emAttr.MethodNameAndDescriptor()
		return &EnclosingMethod{
			className:        emAttr.ClassName(),
			methodName:       methodName,
			methodDescriptor: methodDescriptor,
		}
	}
	return nil
}
示例#4
0
func handleClassfile(cf *classfile.ClassFile) {
	for _, m := range cf.Methods() {
		if isNative(m) {
			if isStatic(m) {
				fmt.Printf("%v.%v%v\n", cf.ClassName(), m.Name(), m.Descriptor())
			} else {
				fmt.Printf("%v#%v%v\n", cf.ClassName(), m.Name(), m.Descriptor())
			}
		}
	}
}
示例#5
0
func getSignature(cf *classfile.ClassFile) string {
	if sigAttr := cf.SignatureAttribute(); sigAttr != nil {
		return sigAttr.Signature()
	}
	return ""
}
示例#6
0
func getSourceFile(cf *classfile.ClassFile) string {
	if sfAttr := cf.SourceFileAttribute(); sfAttr != nil {
		return sfAttr.FileName()
	}
	return "Unknown" // todo
}
示例#7
0
func (self *Class) copyAttributes(cf *classfile.ClassFile) {
	self.sourceFile = getSourceFile(cf)
	self.signature = getSignature(cf)
	self.annotationData = cf.RuntimeVisibleAnnotationsAttributeData()
	self.enclosingMethod = getEnclosingMethod(cf)
}
示例#8
0
func (self *Class) copyFields(cf *classfile.ClassFile) {
	self.fields = make([]*Field, len(cf.Fields()))
	for i, fieldInfo := range cf.Fields() {
		self.fields[i] = newField(self, fieldInfo)
	}
}
示例#9
0
func (self *Class) copyClassNames(cf *classfile.ClassFile) {
	self.name = cf.ClassName()
	self.superClassName = cf.SuperClassName()
	self.interfaceNames = cf.InterfaceNames()
}
示例#10
0
func (self *Class) copyConstantPool(cf *classfile.ClassFile) {
	self.constantPool = newConstantPool(self, cf.ConstantPool())
}