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 accepts only methods with a given fully 27 * qualified name. 28 */ 29 public class MethodFilter implements ActivationList.Filter { 30 private final String className; 31 private final String methodName; 32 33 /** 34 * Creates a new <code>MethodFilter</code> that only accepts methods with 35 * the given fully qualified name. Only exact matches are accepted, there is 36 * no wild-card expansion. 37 * 38 * @param method 39 * the fully qualified method name to accept 40 */ 41 public MethodFilter(String method) { 42 this.className = method.substring(0, method.lastIndexOf(".")); 43 this.methodName = method.substring(method.lastIndexOf(".") + 1); 44 } 45 46 /** 47 * Returns <code>true</code> if and only if the given activation is a call 48 * to a method with the fully qualified name given when creating this 49 * <code>MethodFilter</code>. 50 * 51 * @param activation 52 * the <code>Activation</code> to check 53 * 54 * @return <code>true</code> if <code>activation</code> represents a 55 * call to a method with the name associated with this 56 * <code>MethodFilter</code>, <code>false</code> otherwise 57 */ 58 public boolean accept(Activation activation) { 59 return activation.getClassName().equals(className) 60 && activation.getMethod().name().equals(methodName); 61 } 62 63 /** 64 * Returns the class name associated with this <code>MethodFilter</code>. 65 * 66 * @return the class name associated with this <code>MethodFilter</code> 67 */ 68 public String getClassName() { 69 return className; 70 } 71 72 /** 73 * Returns the unqualified method name associated with this 74 * <code>MethodFilter</code>. 75 * 76 * @return the unqualified method name associated with this 77 * <code>MethodFilter</code> 78 */ 79 public String getMethodName() { 80 return methodName; 81 } 82 }