Coverage Report - th.co.edge.jseq.ClassExclusionFilter
 
Classes in this File Line Coverage Branch Coverage Complexity
ClassExclusionFilter
100%
14/14
100%
10/10
2
 
 1  
 /*
 2  
  * Copyright (c) 2003-2008, by Henrik Arro and Contributors
 3  
  *
 4  
  * This file is part of JSeq, a tool to automatically create
 5  
  * sequence diagrams by tracing program execution.
 6  
  *
 7  
  * See <http://jseq.sourceforge.net> for more information.
 8  
  *
 9  
  * JSeq is free software: you can redistribute it and/or modify
 10  
  * it under the terms of the GNU Lesser General Public License as
 11  
  * published by the Free Software Foundation, either version 3 of
 12  
  * the License, or (at your option) any later version.
 13  
  *
 14  
  * JSeq is distributed in the hope that it will be useful,
 15  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 17  
  * GNU Lesser General Public License for more details.
 18  
  *
 19  
  * You should have received a copy of the GNU Lesser General Public License
 20  
  * along with JSeq. If not, see <http://www.gnu.org/licenses/>.
 21  
  */
 22  
 
 23  
 package th.co.edge.jseq;
 24  
 
 25  
 /**
 26  
  * A <code>Filter</code> that only accepts <code>Activation</code>s with
 27  
  * method names that do not match a given exclude pattern.
 28  
  */
 29  
 public class ClassExclusionFilter implements ActivationList.Filter {
 30  
     private String excludePattern;
 31  
 
 32  
     /**
 33  
      * Creates a new <code>ClassExclusionFilter</code> with the given method
 34  
      * name exclude pattern. If the pattern starts or ends with "*", all method
 35  
      * names with the correct suffix or prefix, respectively, are accepted.
 36  
      *
 37  
      * <p>
 38  
      * For example, the pattern "foo.Bar.baz" would only match a method named
 39  
      * "baz" in the class foo.bar, "*.baz" would match any method named "baz" in
 40  
      * any class, and "foo.Bar.*" would match all method in the class foo.Bar.
 41  
      *
 42  
      * @param excludePattern
 43  
      *            the exclude pattern to use for this filter instance, possibly
 44  
      *            starting or ending with the wildcard "*"
 45  
      */
 46  5
     public ClassExclusionFilter(String excludePattern) {
 47  5
         this.excludePattern = excludePattern;
 48  5
     }
 49  
 
 50  
     /**
 51  
      * Returns <code>true</code> if and only if the given
 52  
      * <code>Activation</code> represents a method call where the class name
 53  
      * plus method name matches the exclude pattern used by this filter.
 54  
      *
 55  
      * @param activation
 56  
      *            the <code>Activation</code> to check for matching method
 57  
      *            name
 58  
      *
 59  
      * @return <code>true</code> if <code>activation</code> represents a
 60  
      *         method call that matches the exclude pattern used by this filter
 61  
      */
 62  
     public boolean accept(Activation activation) {
 63  19
         String fullMethodName =
 64  
                 activation.getClassName() + "." + activation.getMethod().name();
 65  19
         boolean accepted = true;
 66  19
         if (excludePattern.endsWith("*")) {
 67  15
             String prefix =
 68  
                     excludePattern.substring(0, excludePattern.length() - 1);
 69  15
             accepted = !fullMethodName.startsWith(prefix);
 70  15
         } else if (excludePattern.startsWith("*")) {
 71  2
             String suffix = excludePattern.substring(1);
 72  2
             accepted = !fullMethodName.endsWith(suffix);
 73  2
         } else {
 74  2
             accepted = !fullMethodName.equals(excludePattern);
 75  
         }
 76  19
         return accepted;
 77  
     }
 78  
 }