Class: Squash::Java::Package

Inherits:
Object
  • Object
show all
Defined in:
lib/squash/java/namespace.rb

Overview

Represents a Java package.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#childrenArray<Squash::Java::Package> (readonly)

Returns Packages nested underneath this package (see #parent).

Returns:



316
317
318
# File 'lib/squash/java/namespace.rb', line 316

def children
  @children
end

#classesArray<Squash::Java::Class> (readonly)

Returns Classes belonging to this package.

Returns:



319
320
321
# File 'lib/squash/java/namespace.rb', line 319

def classes
  @classes
end

#nameString (readonly)

Returns The last part of the package name (e.g., “bar” for package “com.foo.bar”).

Returns:

  • (String)

    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

#obfuscationString?

Returns The obfuscated package name (e.g., “A” for “com.foo.A”).

Returns:

  • (String, nil)

    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

#parentSquash::Java::Package (readonly)

Returns The parent package (e.g., package “com.foo” for “com.foo.bar”).

Returns:



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.

Parameters:

  • identifier (String)

    The package name relative to this package. If finding package “com.foo.bar”, pass “foo.bar” to Package “com”.

Returns:



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.

Parameters:

  • identifier (String)

    The package name relative to this package (parts may be obfuscated). If finding package “com.A.B”, pass “A.B” to package “com”.

Returns:



355
356
357
358
359
360
361
362
363
364
# 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) ⇒ Squash::Java::Package

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

Parameters:

  • identifier (String)

    The package name relative to this package. If finding package “com.foo.bar”, pass “foo.bar” to Package “com”.

Returns:



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_nameString

Returns The full name of this package (e.g., “com.foo.bar”).

Returns:

  • (String)

    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

#inspectObject



390
# File 'lib/squash/java/namespace.rb', line 390

def inspect() "#<#{self.class.to_s} #{full_name}>" end

#subpathObject



393
# File 'lib/squash/java/namespace.rb', line 393

def subpath() parent ? "#{parent.subpath}/#{name}" : name end