1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * See LICENSE.txt included in this distribution for the specific 9 * language governing permissions and limitations under the License. 10 * 11 * When distributing Covered Code, include this CDDL HEADER in each 12 * file and include the License file at LICENSE.txt. 13 * If applicable, add the following below this CDDL HEADER, with the 14 * fields enclosed by brackets "[]" replaced with your own identifying 15 * information: Portions Copyright [yyyy] [name of copyright owner] 16 * 17 * CDDL HEADER END 18 */ 19 20 /* 21 * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved. 22 * Portions Copyright (c) 2017, 2020, Chris Fraire <cfraire@me.com>. 23 */ 24 package org.opengrok.indexer.analysis.plain; 25 26 import java.io.Reader; 27 import java.util.function.Supplier; 28 29 import org.opengrok.indexer.analysis.AnalyzerFactory; 30 import org.opengrok.indexer.analysis.JFlexTokenizer; 31 import org.opengrok.indexer.analysis.JFlexXref; 32 33 /** 34 * 35 * @author Lubos Kosco 36 * 37 * This class should abstract all analysers that deal with source code. 38 * Source code is specific that it has definitions and references. 39 * Source code has custom xref generators, depending on symbols. 40 * This class should mark the classes that can provide defs and refs. 41 * NOTE: SymbolTokenizer gets set for #1376 in PlainAnalyzer::analyze 42 * and not part of this class anymore due to changes in lucene 6 . 43 * 44 * Anything shared just for source code analyzers should be here, 45 * also all interfaces for source code analyzer should start here. 46 * 47 * Any child is forced to provide necessary xref and symbol tokenizers, 48 * if it fails to do so it will automatically behave like PlainAnalyzer. 49 */ 50 public abstract class AbstractSourceCodeAnalyzer extends PlainAnalyzer { 51 52 /** 53 * Creates a new instance of abstract analyzer. 54 * @param factory defined instance for the analyzer 55 * @param symbolTokenizerFactory defined instance for the analyzer 56 */ AbstractSourceCodeAnalyzer(AnalyzerFactory factory, Supplier<JFlexTokenizer> symbolTokenizerFactory)57 protected AbstractSourceCodeAnalyzer(AnalyzerFactory factory, 58 Supplier<JFlexTokenizer> symbolTokenizerFactory) { 59 super(factory, symbolTokenizerFactory); 60 } 61 62 /** 63 * Create an xref for the language supported by this analyzer. 64 * @param reader the data to produce xref for 65 * @return an xref instance 66 */ 67 @Override newXref(Reader reader)68 protected abstract JFlexXref newXref(Reader reader); 69 } 70