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