module JavaClass::PackageLogic

Mixin with logic to work with Java package names. The “mixer” needs to declare a String field @package.

Author

Peter Kofler

Public Instance Methods

in_jdk?() click to toggle source

Is this package or class in the JDK? Return the first JDK package this is inside or nil.

# File lib/javaclass/java_name.rb, line 28
def in_jdk?
  if @package && @package != ''
    package_dot = @package + JavaLanguage::SEPARATOR
    JavaLanguage::JDK_PACKAGES_REGEX.find { |package| package_dot =~ package }
  else
    # default package is never in JDK
    false
  end
end
package() click to toggle source

Return the package name of a classname or the name of the package. Return an empty String if default package. This returns just the plain String.

# File lib/javaclass/java_name.rb, line 12
def package
  @package
end
same_or_subpackage_of?(packages) click to toggle source

Return true if this class is in same or in a subpackage of the given Java packages or if this package is same or a subpackage (with .).

# File lib/javaclass/java_name.rb, line 18
def same_or_subpackage_of?(packages)
  packages.find {|pkg| @package == pkg } != nil || subpackage_of?(packages)
end
subpackage_of?(packages) click to toggle source

Return true if this class is in a subpackage of the given Java packages .

# File lib/javaclass/java_name.rb, line 23
def subpackage_of?(packages)
  packages.find {|pkg| @package =~ /^#{Regexp.escape(pkg)}#{JavaLanguage::SEPARATOR_REGEX}/ } != nil
end

Private Instance Methods

package_remove_trailing_dot!() click to toggle source
# File lib/javaclass/java_name.rb, line 40
def package_remove_trailing_dot!
  @package = @package[0..-2] if @package.size > 0 && @package[-1..-1] == JavaLanguage::SEPARATOR
end