Class: Squash::Java::Package
- Inherits:
-
Object
- Object
- Squash::Java::Package
- Defined in:
- lib/squash/java/namespace.rb
Overview
Represents a Java package.
Instance Attribute Summary collapse
-
#children ⇒ Array<Squash::Java::Package>
readonly
Packages nested underneath this package (see #parent).
-
#classes ⇒ Array<Squash::Java::Class>
readonly
Classes belonging to this package.
-
#name ⇒ String
readonly
The last part of the package name (e.g., “bar” for package “com.foo.bar”).
-
#obfuscation ⇒ String?
The obfuscated package name (e.g., “A” for “com.foo.A”).
-
#parent ⇒ Squash::Java::Package
readonly
The parent package (e.g., package “com.foo” for “com.foo.bar”).
Instance Method Summary collapse
-
#find(identifier) ⇒ Squash::Java::Package?
Finds a package underneath this package.
-
#find_obfuscated(identifier) ⇒ Squash::Java::Package?
Finds a package by obfuscated (or non-obfuscated) name relative to this package.
-
#find_or_create(identifier) ⇒ Squash::Java::Package
**Finds or creates** A package underneath this package.
-
#full_name ⇒ String
The full name of this package (e.g., “com.foo.bar”).
-
#initialize(name, parent = nil) ⇒ Package
constructor
A new instance of Package.
- #inspect ⇒ Object
- #subpath ⇒ Object
Constructor Details
#initialize(name, parent = nil) ⇒ Package
Returns a new instance of Package.
322 323 324 325 326 327 328 |
# File 'lib/squash/java/namespace.rb', line 322 def initialize(name, parent=nil) @name = name @parent = parent @parent.children << self if @parent @children = Set.new @classes = Set.new end |
Instance Attribute Details
#children ⇒ Array<Squash::Java::Package> (readonly)
Returns Packages nested underneath this package (see #parent).
316 317 318 |
# File 'lib/squash/java/namespace.rb', line 316 def children @children end |
#classes ⇒ Array<Squash::Java::Class> (readonly)
Returns Classes belonging to this package.
319 320 321 |
# File 'lib/squash/java/namespace.rb', line 319 def classes @classes end |
#name ⇒ String (readonly)
Returns The last part of the package name (e.g., “bar” for package “com.foo.bar”).
293 294 295 |
# File 'lib/squash/java/namespace.rb', line 293 def name @name end |
#obfuscation ⇒ String?
Returns The obfuscated package name (e.g., “A” for “com.foo.A”).
297 298 299 |
# File 'lib/squash/java/namespace.rb', line 297 def obfuscation @obfuscation end |
#parent ⇒ Squash::Java::Package (readonly)
Returns The parent package (e.g., package “com.foo” for “com.foo.bar”).
312 313 314 |
# File 'lib/squash/java/namespace.rb', line 312 def parent @parent end |
Instance Method Details
#find(identifier) ⇒ Squash::Java::Package?
Finds a package underneath this package.
336 337 338 339 340 341 342 343 344 345 |
# File 'lib/squash/java/namespace.rb', line 336 def find(identifier) parts = identifier.split('.') name = parts.shift child = children.detect { |pkg| pkg.name == name } if parts.empty? child else child ? child.find(parts.join('.')) : nil end end |
#find_obfuscated(identifier) ⇒ Squash::Java::Package?
Finds a package by obfuscated (or non-obfuscated) name relative to this package.
355 356 357 358 359 360 361 362 363 364 |
# File 'lib/squash/java/namespace.rb', line 355 def (identifier) parts = identifier.split('.') name = parts.shift child = children.detect { |pkg| pkg.obfuscation == name || pkg.name == name } if parts.empty? child else child ? child.(parts.join('.')) : nil end end |
#find_or_create(identifier) ⇒ Squash::Java::Package
**Finds or creates** A package underneath this package.
373 374 375 376 377 378 379 380 381 382 383 384 |
# File 'lib/squash/java/namespace.rb', line 373 def find_or_create(identifier) parts = identifier.split('.') name = parts.shift if ('A'..'Z').include? name[0, 1] # class raise "Unexpected class midway through identifier" unless parts.empty? classes.detect { |cl| cl.name == name } || Squash::Java::Class.new(self, name) else # package child = children.detect { |pkg| pkg.name == name } || Squash::Java::Package.new(name, self) parts.empty? ? child : child.find_or_create(parts.join('.')) end end |
#full_name ⇒ String
Returns The full name of this package (e.g., “com.foo.bar”).
387 |
# File 'lib/squash/java/namespace.rb', line 387 def full_name() parent ? "#{parent.full_name}.#{name}" : name end |
#inspect ⇒ Object
390 |
# File 'lib/squash/java/namespace.rb', line 390 def inspect() "#<#{self.class.to_s} #{full_name}>" end |
#subpath ⇒ Object
393 |
# File 'lib/squash/java/namespace.rb', line 393 def subpath() parent ? "#{parent.subpath}/#{name}" : name end |