PsiMatcherExpression (@PsiModifier.ModifierConstant final String modifier, final boolean shouldHave) { return new PsiMatcherExpression() { @Override public Boolean match(PsiElement element) { PsiModifierListOwner owner = element instanceof PsiModifierListOwner ? (PsiModifierListOwner) element : null; if (owner != null && owner.hasModifierProperty(modifier) == shouldHave) return Boolean.TRUE; return Boolean.FALSE; } }; }