Class: JavaClass::JavaVMName
- Includes:
- JavaQualifiedNameDelegation
- Defined in:
- lib/javaclass/java_name.rb
Overview
A class name from the JVM. That is a/b/C
. These names are read from the constant pool. Atoms and arrays are expressed as JVM names as well.
- Author
-
Peter Kofler
Constant Summary collapse
- SEPARATOR =
'/'
- SEPARATOR_REGEX =
Regexp::escape(SEPARATOR)
- ARRAY_REGEX =
/^\[+L(.+);$|^\[+([A-Z])$/
- VALID_REGEX =
/^ (?: #{JavaLanguage::IDENTIFIER_REGEX}#{SEPARATOR_REGEX} )* #{JavaLanguage::IDENTIFIER_REGEX} $/x
- ATOMS =
Mapping of atoms to wrappers.
{ 'B' => 'java/lang/Byte', 'S' => 'java/lang/Short', 'I' => 'java/lang/Integer', 'J' => 'java/lang/Long', 'F' => 'java/lang/Float', 'D' => 'java/lang/Double', 'Z' => 'java/lang/Booleam', 'C' => 'java/lang/Character' }
Constants inherited from String
Class Method Summary collapse
-
.valid?(string) ⇒ Boolean
Is string a valid JVM name?.
Instance Method Summary collapse
-
#array? ⇒ Boolean
Is this a bytecode array, e.g.
-
#initialize(string, qualified = nil) ⇒ JavaVMName
constructor
Create a new JVM name string with optional qualified class which may be available.
- #to_class_file ⇒ Object
- #to_classname ⇒ Object
- #to_java_file ⇒ Object
- #to_jvmname ⇒ Object
Methods included from JavaQualifiedNameDelegation
Methods included from DelegateDirective
Methods inherited from String
#double, #hexdump, #single, #to_javaname, #u1, #u2, #u2rep, #u4, #u8
Constructor Details
#initialize(string, qualified = nil) ⇒ JavaVMName
Create a new JVM name string with optional qualified class which may be available.
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/javaclass/java_name.rb', line 213 def initialize(string, qualified=nil) super string if string =~ ARRAY_REGEX @is_array = string[/^\[+/].length string = string.sub(ARRAY_REGEX, '\1\2') if string =~ /^[BSIJFDZC]$/ @is_atom = string string = ATOMS[string] else @is_atom = false end else @is_array = false end if string =~ VALID_REGEX @jvm_name = string else raise ArgumentError, "#{string} is no valid JVM name" end @qualified_name = qualified @class_name = nil end |
Class Method Details
.valid?(string) ⇒ Boolean
Is string a valid JVM name?
208 209 210 |
# File 'lib/javaclass/java_name.rb', line 208 def self.valid?(string) string =~ ARRAY_REGEX || string =~ VALID_REGEX end |
Instance Method Details
#array? ⇒ Boolean
Is this a bytecode array, e.g. represented by [B
.
241 242 243 |
# File 'lib/javaclass/java_name.rb', line 241 def array? @is_array end |
#to_class_file ⇒ Object
263 264 265 266 267 268 269 270 271 |
# File 'lib/javaclass/java_name.rb', line 263 def to_class_file return @class_name if @class_name new_val = JavaClassFileName.new(@jvm_name + JavaLanguage::CLASS, @qualified_name) if frozen? new_val else @class_name = new_val end end |
#to_classname ⇒ Object
245 246 247 248 249 250 251 252 253 |
# File 'lib/javaclass/java_name.rb', line 245 def to_classname return @qualified_name if @qualified_name new_val = JavaQualifiedName.new(@jvm_name.gsub(SEPARATOR, JavaLanguage::SEPARATOR), self, nil) if frozen? new_val else @qualified_name = new_val end end |
#to_java_file ⇒ Object
259 260 261 |
# File 'lib/javaclass/java_name.rb', line 259 def to_java_file @jvm_name + JavaLanguage::SOURCE end |
#to_jvmname ⇒ Object
255 256 257 |
# File 'lib/javaclass/java_name.rb', line 255 def to_jvmname self end |