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