class Squash::Java::Package

Represents a Java package.

Attributes

children[R]

@return [Array<Squash::Java::Package>] Packages nested underneath this

package (see {#parent}).
classes[R]

@return [Array<Squash::Java::Class>] Classes belonging to this package.

name[R]

@return [String] The last part of the package name (e.g., “bar” for package

"com.foo.bar").
obfuscation[R]

@return [String, nil] The obfuscated package name (e.g., “A” for

"com.foo.A").
parent[R]

@return [Squash::Java::Package] The parent package (e.g., package “com.foo”

for "com.foo.bar").

Public Class Methods

new(name, parent=nil) click to toggle source

@private

# 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

Public Instance Methods

find(identifier) click to toggle source

Finds a package underneath this package.

@param [String] identifier The package name relative to this package. If

finding package "com.foo.bar", pass "foo.bar" to Package "com".

@return [Squash::Java::Package, nil] The matching package, if found.

# 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) click to toggle source

Finds a package by obfuscated (or non-obfuscated) name relative to this package.

@param [String] identifier The package name relative to this package (parts

may be obfuscated). If finding package "com.A.B", pass "A.B" to package
"com".

@return [Squash::Java::Package, nil] The matching package, if found.

# File lib/squash/java/namespace.rb, line 355
def find_obfuscated(identifier)
  parts = identifier.split('.')
  name  = parts.shift
  child = children.detect { |pkg| pkg.obfuscation == name || pkg.name == name }
  if parts.empty?
    child
  else
    child ? child.find_obfuscated(parts.join('.')) : nil
  end
end
find_or_create(identifier) click to toggle source

**Finds or creates** A package underneath this package.

@param [String] identifier The package name relative to this package. If

finding package "com.foo.bar", pass "foo.bar" to Package "com".

@return [Squash::Java::Package] The matching package, or the newly created

package.
# 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() click to toggle source

@return [String] The full name of this package (e.g., “com.foo.bar”).

# File lib/squash/java/namespace.rb, line 387
def full_name() parent ? "#{parent.full_name}.#{name}" : name end
inspect() click to toggle source

@private

# File lib/squash/java/namespace.rb, line 390
def inspect() "#<#{self.class.to_s} #{full_name}>" end
obfuscation=(name) click to toggle source

Sets the method's obfuscation. @raise [ArgumentError] If the obfuscation is taken by another class or in

package the same namespace.
# File lib/squash/java/namespace.rb, line 303
def obfuscation=(name)
  if (package = parent.children.detect { |p| p.obfuscation == name })
    raise ArgumentError, "Tried to assign obfuscation #{name} to #{package.inspect} and #{inspect}"
  end
  @obfuscation = name
end
subpath() click to toggle source

@private

# File lib/squash/java/namespace.rb, line 393
def subpath() parent ? "#{parent.subpath}/#{name}" : name end