JFlexTokenizer.java revision 1185
349N/A/*
349N/A * CDDL HEADER START
349N/A *
349N/A * The contents of this file are subject to the terms of the
349N/A * Common Development and Distribution License (the "License").
349N/A * You may not use this file except in compliance with the License.
349N/A *
349N/A * See LICENSE.txt included in this distribution for the specific
349N/A * language governing permissions and limitations under the License.
349N/A *
349N/A * When distributing Covered Code, include this CDDL HEADER in each
349N/A * file and include the License file at LICENSE.txt.
349N/A * If applicable, add the following below this CDDL HEADER, with the
349N/A * fields enclosed by brackets "[]" replaced with your own identifying
349N/A * information: Portions Copyright [yyyy] [name of copyright owner]
349N/A *
349N/A * CDDL HEADER END
349N/A */
349N/A
349N/A/*
349N/A * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
349N/A */
349N/A
349N/Apackage org.opensolaris.opengrok.analysis;
349N/A
349N/Aimport java.io.CharArrayReader;
350N/Aimport java.io.IOException;
350N/Aimport java.io.Reader;
350N/Aimport org.apache.lucene.analysis.Tokenizer;
350N/Aimport org.apache.lucene.analysis.tokenattributes.OffsetAttribute;
350N/Aimport org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
350N/Aimport org.apache.lucene.analysis.tokenattributes.TermAttribute;
349N/A
349N/A/**
349N/A * this class was created because of lucene 2.4.1 update which introduced char[] in Tokens instead of String
349N/A * lucene 3.0.0 uses AttributeSource instead of Tokens to make things even easier :-D
349N/A *
349N/A * Generally this is a "template" for all new Tokenizers, so be carefull when changing it,
349N/A * it will impact almost ALL symbol tokenizers in OpenGrok ...
350N/A *
349N/A * Created on August 24, 2009
349N/A * @author Lubos Kosco
349N/A */
349N/A
349N/Apublic abstract class JFlexTokenizer extends Tokenizer {
349N/A
349N/A // default jflex scanner methods and variables
349N/A abstract public boolean yylex() throws IOException;
349N/A abstract public void yyreset(Reader reader);
349N/A abstract public void yyclose() throws IOException;
349N/A
349N/A /**
349N/A * Reinitialize the tokenizer with new contents.
349N/A *
349N/A * @param contents a char buffer with text to tokenize
349N/A * @param length the number of characters to use from the char buffer
349N/A */
349N/A public final void reInit(char[] contents, int length) {
349N/A yyreset(new CharArrayReader(contents, 0, length));
349N/A }
349N/A
349N/A @Override
349N/A public final void close() throws IOException {
349N/A yyclose();
349N/A }
349N/A
349N/A protected TermAttribute termAtt= addAttribute(TermAttribute.class);
349N/A protected OffsetAttribute offsetAtt= addAttribute(OffsetAttribute.class);
349N/A protected PositionIncrementAttribute posIncrAtt= addAttribute(PositionIncrementAttribute.class);
349N/A
349N/A /**
349N/A * This will reinitalize internal AttributeImpls, or it returns false if end of input Reader ...
349N/A * @return false if no more tokens, otherwise true
349N/A * @throws java.io.IOException
349N/A */
349N/A @Override
349N/A public boolean incrementToken() throws java.io.IOException {
349N/A return this.yylex();
349N/A }
349N/A
349N/A protected void setAttribs(String str, int start, int end) {
349N/A //FIXME increasing below by one(default) might be tricky, need more analysis
349N/A this.posIncrAtt.setPositionIncrement(1);
349N/A this.termAtt.setTermBuffer(str);
349N/A this.offsetAtt.setOffset(start, end);
349N/A }
349N/A}
349N/A