670N/A/*
670N/A * CDDL HEADER START
670N/A *
670N/A * The contents of this file are subject to the terms of the
670N/A * Common Development and Distribution License (the "License").
670N/A * You may not use this file except in compliance with the License.
670N/A *
670N/A * See LICENSE.txt included in this distribution for the specific
670N/A * language governing permissions and limitations under the License.
670N/A *
670N/A * When distributing Covered Code, include this CDDL HEADER in each
670N/A * file and include the License file at LICENSE.txt.
670N/A * If applicable, add the following below this CDDL HEADER, with the
670N/A * fields enclosed by brackets "[]" replaced with your own identifying
670N/A * information: Portions Copyright [yyyy] [name of copyright owner]
670N/A *
670N/A * CDDL HEADER END
670N/A */
670N/A
670N/A/*
1380N/A * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
670N/A */
670N/Apackage org.opensolaris.opengrok.analysis.c;
670N/A
670N/Aimport java.io.IOException;
670N/Aimport java.io.Reader;
670N/Aimport java.io.StringReader;
953N/A
670N/Aimport org.apache.lucene.analysis.TokenStream;
670N/Aimport org.apache.lucene.document.Document;
670N/Aimport org.apache.lucene.document.Field;
1127N/Aimport org.opensolaris.opengrok.analysis.Definitions;
670N/Aimport org.opensolaris.opengrok.analysis.FileAnalyzerFactory;
1384N/Aimport org.opensolaris.opengrok.analysis.XrefWriter;
670N/Aimport org.opensolaris.opengrok.analysis.plain.PlainAnalyzer;
670N/Aimport org.opensolaris.opengrok.configuration.Project;
670N/Aimport org.opensolaris.opengrok.history.Annotation;
670N/A
670N/A/**
670N/A * An Analyzer for C++ files
1380N/A * @author Trond Norbye
670N/A */
670N/Apublic class CxxAnalyzer extends PlainAnalyzer {
670N/A /** Creates a new instance of CAnalyzer */
670N/A CxxSymbolTokenizer cref;
670N/A CxxXref xref;
670N/A Reader dummy = new StringReader("");
670N/A
670N/A protected CxxAnalyzer(FileAnalyzerFactory factory) {
670N/A super(factory);
670N/A cref = new CxxSymbolTokenizer(dummy);
670N/A xref = new CxxXref(dummy);
670N/A }
670N/A
957N/A @Override
957N/A public void analyze(Document doc, Reader in) throws IOException {
670N/A super.analyze(doc, in);
670N/A doc.add(new Field("refs", dummy));
1190N/A }
1190N/A
1380N/A @Override
1380N/A public TokenStream overridableTokenStream(String fieldName, Reader reader) {
670N/A if("refs".equals(fieldName)) {
670N/A cref.reInit(super.content, super.len);
670N/A return cref;
670N/A }
1380N/A return super.overridableTokenStream(fieldName, reader);
670N/A }
670N/A
670N/A /**
670N/A * Write a cross referenced HTML file.
670N/A * @param out Writer to write HTML cross-reference
670N/A */
1384N/A public void writeXref(XrefWriter out) throws IOException {
670N/A xref.reInit(content, len);
670N/A xref.project = project;
670N/A xref.setDefs(defs);
670N/A xref.write(out);
670N/A }
1190N/A
670N/A /**
670N/A * Write a cross referenced HTML file reads the source from in
670N/A * @param in Input source
670N/A * @param out Output xref writer
1127N/A * @param defs definitions for the file (could be null)
670N/A * @param annotation annotation for the file (could be null)
670N/A */
1384N/A static void writeXref(Reader in, XrefWriter out, Definitions defs,
670N/A Annotation annotation, Project project) throws IOException {
670N/A CxxXref xref = new CxxXref(in);
670N/A xref.annotation = annotation;
670N/A xref.project = project;
1127N/A xref.setDefs(defs);
670N/A xref.write(out);
670N/A }
670N/A}