Class: JavaClass::ClassFile::ClassVersion
- Defined in:
- lib/javaclass/classfile/class_version.rb
Overview
Version of a class file.
- Author
-
Peter Kofler
- See
-
java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html#75883
Instance Attribute Summary collapse
-
#major ⇒ Object
readonly
Returns the value of attribute major.
-
#minor ⇒ Object
readonly
ZenTest FULL to find method to_s.
Instance Method Summary collapse
-
#dump ⇒ Object
Return a debug output of this version.
-
#initialize(data, start = 4) ⇒ ClassVersion
constructor
Extract the class version from the bytes data starting at position start (which is usually 4).
-
#jdk_version ⇒ Object
Return the JDK version corresponding to this version like “1.6” or “unknown” if none matched.
-
#to_f ⇒ Object
Return the version as
major
.minor
float. -
#to_s ⇒ Object
Return the class file version as
major
.minor
string like 48.0 (Java 1.4) or 50.0 (Java 6).
Constructor Details
#initialize(data, start = 4) ⇒ ClassVersion
Extract the class version from the bytes data starting at position start (which is usually 4).
15 16 17 18 |
# File 'lib/javaclass/classfile/class_version.rb', line 15 def initialize(data, start=4) @minor = data.u2(start) @major = data.u2(start+2) end |
Instance Attribute Details
#major ⇒ Object (readonly)
Returns the value of attribute major.
12 13 14 |
# File 'lib/javaclass/classfile/class_version.rb', line 12 def major @major end |
#minor ⇒ Object (readonly)
ZenTest FULL to find method to_s
11 12 13 |
# File 'lib/javaclass/classfile/class_version.rb', line 11 def minor @minor end |
Instance Method Details
#dump ⇒ Object
Return a debug output of this version.
40 41 42 |
# File 'lib/javaclass/classfile/class_version.rb', line 40 def dump [" minor version: #{@minor}", " major version: #{@major}"] end |
#jdk_version ⇒ Object
Return the JDK version corresponding to this version like “1.6” or “unknown” if none matched.
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/javaclass/classfile/class_version.rb', line 45 def jdk_version v = to_f if v >= 45.0 && v <= 45.3 # 1.0.2 supports class file format versions 45.0 through 45.3 inclusive. '1.0' elsif v > 45.3 && v <= 45.65535 # 1.1.X can support class file formats of versions in the range 45.0 through 45.65535 inclusive '1.1' elsif @major >= 46 && @minor == 0 "1.#{@major-44}" else 'unknown' end end |
#to_f ⇒ Object
Return the version as major
.minor
float.
26 27 28 |
# File 'lib/javaclass/classfile/class_version.rb', line 26 def to_f @major + @minor/denom end |
#to_s ⇒ Object
Return the class file version as major
.minor
string like 48.0 (Java 1.4) or 50.0 (Java 6).
21 22 23 |
# File 'lib/javaclass/classfile/class_version.rb', line 21 def to_s "#{@major}.#{@minor}" end |