class JFlexTokenizer extends Tokenizer
    implements SymbolMatchedListener {

    private static final int LUCENE_MAX_TOKEN_LENGTH = 32766;

    private final ScanningSymbolMatcher matcher;
    private boolean didSetAttribsValues;

    /**
     * Initialize an instance, passing a {@link ScanningSymbolMatcher} which
     * will be owned by the {@link JFlexTokenizer}.
     * @param matcher a defined instance
     */
    public JFlexTokenizer(ScanningSymbolMatcher matcher) {
        if (matcher == null) {
            throw new IllegalArgumentException("`matcher' is null");
        }
        this.matcher = matcher;
        matcher.setSymbolMatchedListener(this);
        // The tokenizer will own the matcher, so we won't have to unsubscribe.
    }

    /**
     * Resets the instance and the instance's {@link ScanningSymbolMatcher}.
     * If necessary, users should have first called this instance's
     * {@link #setReader(java.io.Reader)} since the matcher will be
     * reset to the current reader.
     * @throws java.io.IOException in case of I/O error
     */
    @Override
    public void reset() throws IOException {
        super.reset();
        matcher.yyreset(input);
        matcher.reset();
        clearAttributesEtc();
    }

    /**
     * Closes the instance and the instance's {@link ScanningSymbolMatcher}.
     * @throws IOException if any error occurs while closing
     */
    @Override
    public final void close() throws IOException {
        super.close();
        matcher.yyclose();
    }

    private final CharTermAttribute termAtt = addAttribute(
        CharTermAttribute.class);
    private final OffsetAttribute offsetAtt = addAttribute(
        OffsetAttribute.class);
    private final PositionIncrementAttribute posIncrAtt = addAttribute(
        PositionIncrementAttribute.class);

    /**
     * Attempts to advance the stream to the next acceptable token, and updates
     * the appropriate {@link AttributeImpl}s.
     *
     * @return {@code true} if an acceptable token was produced; {@code false}
     * otherwise to indicate end of stream
     * @throws IOException in case of I/O error
     */
    @Override
    public final boolean incrementToken() throws IOException {
        boolean notAtEOF;
        do {
            clearAttributesEtc();
            notAtEOF = matcher.yylex() != matcher.getYYEOF();
        } while (!didSetAttribsValues && notAtEOF);
        return notAtEOF;
    }

    /**
     * Calls {@link #setAttribs(String, long, long)} on the publishing
     * of a {@link SymbolMatchedEvent}.
     * @param evt the event raised
     */
    @Override
    public void symbolMatched(SymbolMatchedEvent evt) {
        setAttribs(evt.getStr(), evt.getStart(), evt.getEnd());
    }

    /**
     * Does nothing.
     * @param evt ignored
     */
    @Override
    public void sourceCodeSeen(SourceCodeSeenEvent evt) {
    }

    /**
     * Clears, and then resets the instances attributes per the specified
     * arguments. If {@code start} or {@code end} is past
     * {@link Integer#MAX_VALUE}, then only the clearing occurs.
     * @param str the matched symbol
     * @param start the match start position
     * @param end the match end position
     */
    protected void setAttribs(String str, long start, long end) {<FILL_FUNCTION_BODY>}

    /**
     * Calls {@link #clearAttributes()}, and also resets some additional tracked
     * state.
     */
    protected void clearAttributesEtc() {
        clearAttributes();
        didSetAttribsValues = false;
    }
}

        clearAttributesEtc();
        if (start < Integer.MAX_VALUE && end < Integer.MAX_VALUE) {

            if (str.length() > LUCENE_MAX_TOKEN_LENGTH) {
                str = str.substring(0, LUCENE_MAX_TOKEN_LENGTH);
                /*
                 * Leave `end` unadjusted. The truncated string will represent
                 * the full source text, similar to how a Lucene synonym is an
                 * alternative representation of full source text.
                 */
            }

            /*
             * FIXME increasing below by one(default) might be tricky, need more
             * analysis after lucene upgrade to 3.5 below is most probably not
             * even needed.
             */
            this.posIncrAtt.setPositionIncrement(1);
            this.termAtt.setEmpty();
            this.termAtt.append(str);
            this.offsetAtt.setOffset((int) start, (int) end);
            this.didSetAttribsValues = true;
        }
    
<no_super_class>