Class: JavaClass::ClassFile::ClassVersion
- Inherits:
-
Object
- Object
- 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 19 |
# File 'lib/javaclass/classfile/class_version.rb', line 15 def initialize(data, start=4) # parsing @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.
38 39 40 |
# File 'lib/javaclass/classfile/class_version.rb', line 38 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.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/javaclass/classfile/class_version.rb', line 43 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 v == 46.0 # JDK 1.2=46 '1.2' elsif v == 47.0 # JDK 1.3=47 '1.3' elsif v == 48.0 # JDK 1.4=48 '1.4' elsif v == 49.0 # J2SE 5.0=49 '1.5' elsif v == 50.0 # J2SE 6.0=50 '1.6' else 'unknown' end end |
#to_f ⇒ Object
Return the version as major
.minor
float.
27 28 29 30 31 32 33 34 35 |
# File 'lib/javaclass/classfile/class_version.rb', line 27 def to_f if @minor <= 0 denom = 1.0 else denom = 1.0 * 10**(Math.log10(@minor).floor + 1) end @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).
22 23 24 |
# File 'lib/javaclass/classfile/class_version.rb', line 22 def to_s "#{@major}.#{@minor}" end |