Class: JavaClass::Field

Inherits:
Member
  • Object
show all
Defined in:
lib/javaclass/member.rb

Overview

Field

Instance Attribute Summary

Attributes inherited from Member

#access_flag, #attributes, #descriptor_index, #java_class, #name_index

Instance Method Summary collapse

Methods inherited from Member

#descriptor, #name, #to_bytes

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) ⇒ Field

コンストラクタ

*java_class::Fieldの所有者であるJavaクラス



69
70
71
# File 'lib/javaclass/member.rb', line 69

def initialize( java_class )
  super( java_class )
end

Instance Method Details

#static_valueObject

定数フィールドの初期値を取得する

戻り値::定数フィールドの初期値。定数でない場合や初期値が設定されていない場合nil



77
78
79
# File 'lib/javaclass/member.rb', line 77

def static_value 
  (attributes.key? "ConstantValue") ? attributes["ConstantValue"].value : nil
end

#to_sObject



80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/javaclass/member.rb', line 80

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" } 
  datas = []
  datas << access_flag.to_s if access_flag.to_s.length > 0
  datas << convert_field_descriptor(descriptor)
  datas << name
  str << datas.join(" ")
  str << " = " << attributes["ConstantValue"].to_s if attributes.key? "ConstantValue"
  return str
end