/** * Match the specified candidate against the configured patterns. * @param signatureString "java.lang.Object.hashCode" style signature * @return whether the candidate matches at least one of the specified patterns */ protected boolean matchesPattern(String signatureString) { for (int i = 0; i < this.patterns.length; i++) { boolean matched = matches(signatureString, i); if (matched) { for (int j = 0; j < this.excludedPatterns.length; j++) { boolean excluded = matchesExclusion(signatureString, j); if (excluded) { return false; } } return true; } } return false; }
protected void exactMatchTests(AbstractRegexpMethodPointcut rpc) throws Exception { // assumes rpc.setPattern("java.lang.Object.hashCode"); assertTrue(rpc.matches(Object.class.getMethod("hashCode"), String.class)); assertTrue(rpc.matches(Object.class.getMethod("hashCode"), Object.class)); assertFalse(rpc.matches(Object.class.getMethod("wait"), Object.class)); }
@Test public void testMatchesObjectClass() throws Exception { rpc.setPattern("java.lang.Object.*"); assertTrue(rpc.matches(Exception.class.getMethod("hashCode"), IOException.class)); // Doesn't match a method from Throwable assertFalse(rpc.matches(Exception.class.getMethod("getMessage"), Exception.class)); }
/** * Match the specified candidate against the configured patterns. * @param signatureString "java.lang.Object.hashCode" style signature * @return whether the candidate matches at least one of the specified patterns */ protected boolean matchesPattern(String signatureString) { for (int i = 0; i < this.patterns.length; i++) { boolean matched = matches(signatureString, i); if (matched) { for (int j = 0; j < this.excludedPatterns.length; j++) { boolean excluded = matchesExclusion(signatureString, j); if (excluded) { return false; } } return true; } } return false; }
/** * Match the specified candidate against the configured patterns. * @param signatureString "java.lang.Object.hashCode" style signature * @return whether the candidate matches at least one of the specified patterns */ protected boolean matchesPattern(String signatureString) { for (int i = 0; i < this.patterns.length; i++) { boolean matched = matches(signatureString, i); if (matched) { for (int j = 0; j < this.excludedPatterns.length; j++) { boolean excluded = matchesExclusion(signatureString, j); if (excluded) { return false; } } return true; } } return false; }
/** * Try to match the regular expression against the fully qualified name * of the method's declaring class, plus the name of the method. * Note that the declaring class is that class that originally declared * the method, not necessarily the class that's currently exposing it. * <p>For example, "java.lang.Object.hashCode" matches any subclass * of Object's <code>hashCode()</code> method. */ public final boolean matches(Method method, Class targetClass) { // TODO use target class here? String patt = method.getDeclaringClass().getName() + "." + method.getName(); for (int i = 0; i < this.patterns.length; i++) { boolean matched = matches(patt, i); if (matched) { return true; } } return false; }