Class LoosePackageCouplingRule

  • All Implemented Interfaces:
    JavaParserVisitor, net.sourceforge.pmd.lang.rule.ImmutableLanguage, net.sourceforge.pmd.properties.PropertySource, net.sourceforge.pmd.Rule

    public class LoosePackageCouplingRule
    extends AbstractJavaRule
    The loose package coupling Rule can be used to ensure coupling outside of a package hierarchy is minimized to all but an allowed set of classes from within the package hierarchy.

    For example, supposed you have the following package hierarchy:

    • org.sample
    • org.sample.impl
    • org.sample.util
    And the allowed class org.sample.SampleInterface.

    This rule can be used to ensure that all classes within the org.sample package and its sub-packages are not used outside of the org.sample package hierarchy. Further, the only allowed usage outside of a class in the org.sample hierarchy would be via org.sample.SampleInterface.

    • Field Detail

      • PACKAGES_DESCRIPTOR

        public static final net.sourceforge.pmd.properties.PropertyDescriptor<java.util.List<java.lang.String>> PACKAGES_DESCRIPTOR
      • CLASSES_DESCRIPTOR

        public static final net.sourceforge.pmd.properties.PropertyDescriptor<java.util.List<java.lang.String>> CLASSES_DESCRIPTOR
    • Constructor Detail

      • LoosePackageCouplingRule

        public LoosePackageCouplingRule()
    • Method Detail

      • getRestrictedPackages

        protected java.util.List<java.lang.String> getRestrictedPackages()
      • isContainingPackage

        protected boolean isContainingPackage​(java.lang.String pkg1,
                                              java.lang.String pkg2)
      • checksNothing

        public boolean checksNothing()
      • dysfunctionReason

        public java.lang.String dysfunctionReason()
        Specified by:
        dysfunctionReason in interface net.sourceforge.pmd.properties.PropertySource
        Overrides:
        dysfunctionReason in class net.sourceforge.pmd.properties.AbstractPropertySource
        See Also:
        PropertySource.dysfunctionReason()