Class: Rubernate::Bytecode::ProxyClass
- Inherits:
-
Object
- Object
- Rubernate::Bytecode::ProxyClass
- Defined in:
- lib/rubernate/bytecode.rb
Overview
Representation of the generated class
Instance Attribute Summary collapse
-
#class_file ⇒ Object
Returns the value of attribute class_file.
-
#clazz ⇒ Object
Returns the value of attribute clazz.
-
#const_pool ⇒ Object
Returns the value of attribute const_pool.
-
#ct_class ⇒ Object
Returns the value of attribute ct_class.
-
#frozen ⇒ Object
Returns the value of attribute frozen.
Instance Method Summary collapse
- #add_annotation(field, name) ⇒ Object
-
#add_parameter(type, name) ⇒ Object
This wild add a parammeter to given class and generates te setter.
-
#add_simple(type, name) ⇒ Object
add simple parameter to a field (see #add_parameter).
-
#initialize(ct_class) ⇒ ProxyClass
constructor
A new instance of ProxyClass.
-
#to_class ⇒ Object
@return java byte code generated class.
Constructor Details
#initialize(ct_class) ⇒ ProxyClass
Returns a new instance of ProxyClass.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/rubernate/bytecode.rb', line 49 def initialize(ct_class) self.ct_class = ct_class self.frozen = false java_import 'javassist.bytecode.ClassFile' java_import 'javassist.bytecode.AnnotationsAttribute' java_import 'javassist.bytecode.annotation.Annotation' java_import 'javassist.bytecode.annotation.StringMemberValue' self.class_file = self.ct_class.getClassFile self.const_pool = self.class_file.getConstPool ann_attr = AnnotationsAttribute.new(self.const_pool, AnnotationsAttribute.visibleTag) ann = Annotation.new("javax.persistence.Entity",self.const_pool) ann.add_member_value "name", StringMemberValue.new(self.ct_class.name,self.const_pool) ann_attr.set_annotation ann self.class_file.addAttribute(ann_attr) end |
Instance Attribute Details
#class_file ⇒ Object
Returns the value of attribute class_file.
47 48 49 |
# File 'lib/rubernate/bytecode.rb', line 47 def class_file @class_file end |
#clazz ⇒ Object
Returns the value of attribute clazz.
47 48 49 |
# File 'lib/rubernate/bytecode.rb', line 47 def clazz @clazz end |
#const_pool ⇒ Object
Returns the value of attribute const_pool.
47 48 49 |
# File 'lib/rubernate/bytecode.rb', line 47 def const_pool @const_pool end |
#ct_class ⇒ Object
Returns the value of attribute ct_class.
47 48 49 |
# File 'lib/rubernate/bytecode.rb', line 47 def ct_class @ct_class end |
#frozen ⇒ Object
Returns the value of attribute frozen.
47 48 49 |
# File 'lib/rubernate/bytecode.rb', line 47 def frozen @frozen end |
Instance Method Details
#add_annotation(field, name) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/rubernate/bytecode.rb', line 73 def add_annotation(field,name) ann_attr = AnnotationsAttribute.new(self.const_pool, AnnotationsAttribute.visibleTag) ann = Annotation.new(name,self.const_pool) ann_attr.set_annotation ann field.getFieldInfo.addAttribute ann_attr end |
#add_parameter(type, name) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/rubernate/bytecode.rb', line 93 def add_parameter(type,name) java_import 'javassist.CtField' java_import 'javassist.CtMethod' java_import 'javassist.Modifier' java_import 'javax.persistence.Basic' field = CtField.make("private #{type} #{name};",self.ct_class) self.ct_class.add_field(field) get = CtMethod.make(" public #{type} get#{name.capitalize}(){ return #{name}; }",self.ct_class) set = CtMethod.make(" public void set#{name.capitalize}(#{type} #{name}){ this.#{name} = #{name}; }",self.ct_class) self.ct_class.add_method(get) self.ct_class.add_method(set) return field end |
#add_simple(type, name) ⇒ Object
add simple parameter to a field (see #add_parameter)
83 84 85 |
# File 'lib/rubernate/bytecode.rb', line 83 def add_simple(type,name) add_parameter(Rubernate::Bytecode.mapped_types[type],name) end |
#to_class ⇒ Object
@return java byte code generated class
111 112 113 |
# File 'lib/rubernate/bytecode.rb', line 111 def to_class self.ct_class.to_class end |