@Test public void testPublicAndFinalMethods() throws Exception { MethodModifierMatcher publicMethodsMatcher = new MethodModifierMatcher(AccessFlag.PUBLIC); MethodModifierMatcher protectedMethodsMatcher = new MethodModifierMatcher(AccessFlag.FINAL); AndMatcher orMatcher = new AndMatcher(publicMethodsMatcher, protectedMethodsMatcher); CtClass ctClass = pool.get(PublicFinalModifiers.class.getCanonicalName()); CtBehavior ctBehavior = ctClass.getDeclaredMethod("isNegative"); assertTrue(orMatcher.matches(ctBehavior)); ctClass = pool.get(PublicModifiers.class.getCanonicalName()); ctBehavior = ctClass.getDeclaredMethod("isNegative"); assertFalse(orMatcher.matches(ctBehavior)); ctClass = pool.get(ProtectedModifiers.class.getCanonicalName()); ctBehavior = ctClass.getDeclaredMethod("isNegative"); assertFalse(orMatcher.matches(ctBehavior)); ctClass = pool.get(PrivateModifiers.class.getCanonicalName()); ctBehavior = ctClass.getDeclaredMethod("isNegative"); assertFalse(orMatcher.matches(ctBehavior)); }
@Override public boolean matches(final CtClass ctClass) { for (IMatcher mat : this.matchers) { if (!mat.matches(ctClass)) { return false; } } return true; }
AndMatcher implements IMatcher { @Override public boolean matches(final CtClass ctClass) { for (IMatcher mat : this.matchers) { if (!mat.matches(ctClass)) { return false; } } return true; } }
AndMatcher implements IMatcher { @Override public boolean matches(final CtClass ctClass) { for (IMatcher mat : this.matchers) { if (!mat.matches(ctClass)) { return false; } } return true; } AndMatcher(final IMatcher... matchers); }
AndMatcher implements IMatcher { @Override public boolean matches(final CtClass ctClass) { for (IMatcher mat : this.matchers) { if (!mat.matches(ctClass)) { return false; } } return true; } AndMatcher(final IMatcher... matchers); @Override boolean matches(final CtClass ctClass); @Override boolean matches(final CtBehavior ctBehavior); @Override boolean matches(final CtField ctField); }
AndMatcher implements IMatcher { @Override public boolean matches(final CtClass ctClass) { for (IMatcher mat : this.matchers) { if (!mat.matches(ctClass)) { return false; } } return true; } AndMatcher(final IMatcher... matchers); @Override boolean matches(final CtClass ctClass); @Override boolean matches(final CtBehavior ctBehavior); @Override boolean matches(final CtField ctField);  }