Example #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)
	}
}
Example #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
}
Example #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
}
Example #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())
			}
		}
	}
}
Example #5
0
func getSignature(cf *classfile.ClassFile) string {
	if sigAttr := cf.SignatureAttribute(); sigAttr != nil {
		return sigAttr.Signature()
	}
	return ""
}
Example #6
0
func getSourceFile(cf *classfile.ClassFile) string {
	if sfAttr := cf.SourceFileAttribute(); sfAttr != nil {
		return sfAttr.FileName()
	}
	return "Unknown" // todo
}
Example #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)
}
Example #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)
	}
}
Example #9
0
func (self *Class) copyClassNames(cf *classfile.ClassFile) {
	self.name = cf.ClassName()
	self.superClassName = cf.SuperClassName()
	self.interfaceNames = cf.InterfaceNames()
}
Example #10
0
func (self *Class) copyConstantPool(cf *classfile.ClassFile) {
	self.constantPool = newConstantPool(self, cf.ConstantPool())
}