PsiBuilder (final PsiBuilder builder, final Predicate<? super Pair<IElementType, String>> condition) { return new PsiBuilderAdapter(builder) { @Override public IElementType getTokenType() { final Pair<IElementType, String> input = Pair.create(builder.getTokenType(), builder.getTokenText()); return condition.test(input) ? null : super.getTokenType(); } @Override public boolean eof() { final Pair<IElementType, String> input = Pair.create(builder.getTokenType(), builder.getTokenText()); return condition.test(input) || super.eof(); } }; }