Module: JavaClass::PackageLogic
- Included in:
- JavaPackageName, JavaQualifiedName
- Defined in:
- lib/javaclass/java_name.rb
Overview
Mixin with logic to work with Java package names. The “mixer” needs to declare a String field @package.
- Author
-
Peter Kofler
Instance Method Summary collapse
-
#in_jdk? ⇒ Boolean
Is this package or class in the JDK? Return the first JDK package this is inside or
nil
. -
#package ⇒ Object
Return the package name of a classname or the name of the package.
-
#same_or_subpackage_of?(packages) ⇒ Boolean
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 .). -
#subpackage_of?(packages) ⇒ Boolean
Return
true
if this class is in a subpackage of the given Java packages .
Instance Method Details
#in_jdk? ⇒ Boolean
Is this package or class in the JDK? Return the first JDK package this is inside or nil
.
28 29 30 31 32 33 34 35 36 |
# 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 ⇒ Object
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.
12 13 14 |
# File 'lib/javaclass/java_name.rb', line 12 def package @package end |
#same_or_subpackage_of?(packages) ⇒ Boolean
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 .).
18 19 20 |
# 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) ⇒ Boolean
Return true
if this class is in a subpackage of the given Java packages .
23 24 25 |
# File 'lib/javaclass/java_name.rb', line 23 def subpackage_of?(packages) packages.find {|pkg| @package =~ /^#{Regexp.escape(pkg)}#{JavaLanguage::SEPARATOR_REGEX}/ } != nil end |