Class: JavaClass::Method
Overview
Method
Instance Attribute Summary
Attributes inherited from Member
#access_flag, #attributes, #descriptor_index, #java_class, #name_index
Instance Method Summary collapse
-
#exceptions ⇒ Object
メソッドで発生する例外のクラス名を配列で取得する.
-
#initialize(java_class) ⇒ Method
constructor
コンストラクタ.
-
#parameter_annotations(index) ⇒ Object
指定したパラメータに設定されているアノテーションを配列で取得する。.
-
#parameters ⇒ Object
引数のクラス名を配列で取得する.
-
#return_type ⇒ Object
メソッドの戻り値クラス名を取得する.
- #to_s ⇒ Object
Methods inherited from Member
Methods included from Item
#annotations, #deprecated?, #signature
Methods included from Converters
convert_code, convert_field_descriptor, convert_method_descriptor
Methods included from Base
#==, #===, #dump, #eql?, #hash, #to_byte
Constructor Details
#initialize(java_class) ⇒ Method
コンストラクタ
*java_class::Methodの所有者であるJavaクラス
104 105 106 |
# File 'lib/javaclass/member.rb', line 104 def initialize( java_class ) super( java_class ) end |
Instance Method Details
#exceptions ⇒ Object
メソッドで発生する例外のクラス名を配列で取得する
戻り値::メソッドで発生する例外クラス名の配列
113 114 115 116 |
# File 'lib/javaclass/member.rb', line 113 def exceptions (attributes.key? "Exceptions") ? attributes["Exceptions"].exceptions.map{|i|i.name} : [] end |
#parameter_annotations(index) ⇒ Object
指定したパラメータに設定されているアノテーションを配列で取得する。
戻り値::アノテーションの配列
138 139 140 141 142 143 144 |
# File 'lib/javaclass/member.rb', line 138 def parameter_annotations(index) ['RuntimeVisibleParameterAnnotations', 'RuntimeInvisibleParameterAnnotations'].inject([]) { |l, k| l.concat( attributes[k][index] ) if attributes.key? k l } end |
#parameters ⇒ Object
引数のクラス名を配列で取得する
戻り値::引数のクラス名の配列
122 123 124 |
# File 'lib/javaclass/member.rb', line 122 def parameters convert_method_descriptor( descriptor )[:args] end |
#return_type ⇒ Object
メソッドの戻り値クラス名を取得する
戻り値::メソッドの戻り値クラス名
130 131 132 |
# File 'lib/javaclass/member.rb', line 130 def return_type convert_method_descriptor( descriptor )[:return] end |
#to_s ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/javaclass/member.rb', line 146 def to_s str = "" str << attributes["Signature"].to_s << "\n" if attributes.key? "Signature" str << "// !deprecated!\n" if deprecated? str << annotations.inject( "" ){|s, e| s << e.to_s << "\n" } d = convert_method_descriptor( descriptor ) i = 0 args = d[:args].map(){|item| a = parameter_annotations(i) tmp = a.length > 0 ? a.map(){|a| a.to_s}.join("\n") << " " : "" i+=1 tmp << "#{item} arg#{i}" }.join(", ") datas = [] datas << access_flag.to_s if access_flag.to_s.length > 0 datas << d[:return] datas << name datas << "(" datas << args datas << ")" str << datas.join(" ") str << "\n" << attributes["Exceptions"].to_s if attributes.key? "Exceptions" if ( attributes.key? "Code") str << " {\n" codes = attributes["Code"] local_types = codes.attributes["LocalVariableTypeTable"] if codes.attributes.key? "LocalVariableTypeTable" if codes.attributes.key? "LocalVariableTable" codes.attributes["LocalVariableTable"].local_variable_table.each {|l| type = local_types.find_by_index(l.index) if local_types != nil str << " // signature " << type.signature << "\n" if type != nil str << " " << convert_field_descriptor(l.descriptor) str << " " << l.name << ";\n" } end str << "\n" lines = codes.attributes["LineNumberTable"] if codes.attributes.key? "LineNumberTable" codes.codes.each_index {|i| str << " " << codes.codes[i].to_s str << " // #{lines.line_number(i)}" if lines != nil && lines.line_number(i) != nil str << "\n"; } str << "}" end str << " #{attributes['AnnotationDefault'].to_s}" if attributes.key? 'AnnotationDefault' return str end |