net.sourceforge.cobertura.metrics.api.location
Class SourceLocationFilter

java.lang.Object
  extended by net.sourceforge.cobertura.metrics.api.location.SourceLocationFilter

public class SourceLocationFilter
extends Object

Filter separating valid from invalid SourceLocation instances.

Author:
Lennart Jörelid, jGuru Europe AB

Constructor Summary
SourceLocationFilter()
          Creates a SourceLocationFilter instance which accepts all SourceLocations.
SourceLocationFilter(String packagePattern)
          Creates a SourceLocationFilter instance with the supplied Java regular expression to be applied within package scope.
SourceLocationFilter(String packagePattern, String classPattern)
          Creates a SourceLocationFilter instance with the supplied Java regular expressions to be applied within the appropriate scope.
SourceLocationFilter(String packagePattern, String classPattern, String methodPattern)
          Creates a SourceLocationFilter instance with the supplied Java regular expressions to be applied within the appropriate scope.
SourceLocationFilter(String packagePattern, String classPattern, String methodPattern, String lineNumberPattern)
          Creates a SourceLocationFilter instance with the supplied Java regular expressions to be applied within the appropriate scope.
SourceLocationFilter(String packagePattern, String classPattern, String methodPattern, String lineNumberPattern, String branchSegmentPattern)
          Creates a SourceLocationFilter instance with the supplied Java regular expressions to be applied within the appropriate scope.
 
Method Summary
 boolean accept(SourceLocation candidate)
          
static String escapeDots(String patternWithDots)
          Convenience method which translates a string containing dots ("."), such as a java package name, to a valid Java Regular Expressions where the dots are interpreted literally.
static String getPattern(Package thePackage, boolean includeSubPackages)
          Convenience method to generate a Java Regular Expression pattern string which includes the supplied Package, and optionally all subpackages to it.
 LocationScope getScope()
          Retrieves the lowest LocationScope used to filter incoming SourceLocations.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SourceLocationFilter

public SourceLocationFilter()
Creates a SourceLocationFilter instance which accepts all SourceLocations.


SourceLocationFilter

public SourceLocationFilter(String packagePattern)
Creates a SourceLocationFilter instance with the supplied Java regular expression to be applied within package scope. No pattern may be null or empty.

Parameters:
packagePattern - The regexp to be matched to SourceLocation package properties.

SourceLocationFilter

public SourceLocationFilter(String packagePattern,
                            String classPattern)
Creates a SourceLocationFilter instance with the supplied Java regular expressions to be applied within the appropriate scope. No pattern may be null or empty.

Parameters:
packagePattern - The regexp to be matched to SourceLocation package properties.
classPattern - The regexp to be matched to SourceLocation class properties.

SourceLocationFilter

public SourceLocationFilter(String packagePattern,
                            String classPattern,
                            String methodPattern)
Creates a SourceLocationFilter instance with the supplied Java regular expressions to be applied within the appropriate scope. No pattern may be null or empty.

Parameters:
packagePattern - The regexp to be matched to SourceLocation package properties.
classPattern - The regexp to be matched to SourceLocation class properties.
methodPattern - The regexp to be matched to SourceLocation method properties.

SourceLocationFilter

public SourceLocationFilter(String packagePattern,
                            String classPattern,
                            String methodPattern,
                            String lineNumberPattern)
Creates a SourceLocationFilter instance with the supplied Java regular expressions to be applied within the appropriate scope. No pattern may be null or empty.

Parameters:
packagePattern - The regexp to be matched to SourceLocation package properties.
classPattern - The regexp to be matched to SourceLocation class properties.
methodPattern - The regexp to be matched to SourceLocation method properties.
lineNumberPattern - The regexp to be matched to SourceLocation line number properties.

SourceLocationFilter

public SourceLocationFilter(String packagePattern,
                            String classPattern,
                            String methodPattern,
                            String lineNumberPattern,
                            String branchSegmentPattern)
Creates a SourceLocationFilter instance with the supplied Java regular expressions to be applied within the appropriate scope. No pattern may be null or empty.

Parameters:
packagePattern - The regexp to be matched to SourceLocation package properties.
classPattern - The regexp to be matched to SourceLocation class properties.
methodPattern - The regexp to be matched to SourceLocation method properties.
lineNumberPattern - The regexp to be matched to SourceLocation line number properties.
branchSegmentPattern - The regexp to be matched to SourceLocation branch segment index properties.
Method Detail

getScope

public final LocationScope getScope()
Retrieves the lowest LocationScope used to filter incoming SourceLocations. For example, if this SourceLocationFilter has LocationScope.CLASS , then package name and class name attributes are used to filter SourceLocations (but method, lineNumber and segment attributes are not).

Returns:
The lowest scope used to filter SourceLocation instances, implying that Patterns for the given scope and all above it are used to filter SourceLocations.

accept

public boolean accept(SourceLocation candidate)


escapeDots

public static String escapeDots(String patternWithDots)
Convenience method which translates a string containing dots ("."), such as a java package name, to a valid Java Regular Expressions where the dots are interpreted literally.

Parameters:
patternWithDots - The pattern containing verbatim dots (such as "com.foo.bar.some.package").
Returns:
The pattern, transformed to a Java Regular Expression requiring the dots verbatim For example, "com.foo.bar.some.package" would be transformed into "com\\.foo\\.bar\\.some\\.package"

getPattern

public static String getPattern(Package thePackage,
                                boolean includeSubPackages)
Convenience method to generate a Java Regular Expression pattern string which includes the supplied Package, and optionally all subpackages to it.

Parameters:
thePackage - The Package to acquire a filter for. Cannot be null.
includeSubPackages - if true, generates a pattern string which accepts/hits subpackages of the supplied Package in addition to the given Package.
Returns:
a Java Regular Expression pattern string which includes the supplied Package, and optionally all subpackages to it.


Copyright © 2013–2015 Cobertura. All rights reserved.