Skip to content

Commit

Permalink
Fix #2030 : all new from createComponents()
Browse files Browse the repository at this point in the history
  • Loading branch information
idodeclare authored and Vladimir Kotal committed Feb 17, 2020
1 parent 5050c4d commit 9cd38b9
Show file tree
Hide file tree
Showing 41 changed files with 124 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@
/*
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
* Portions Copyright (c) 2017-2019, Chris Fraire <cfraire@me.com>.
* Portions Copyright (c) 2017-2020, Chris Fraire <cfraire@me.com>.
*/
package org.opengrok.indexer.analysis;

import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.io.Writer;
import java.util.function.Supplier;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.document.Document;
Expand All @@ -40,8 +42,7 @@ public abstract class AbstractAnalyzer extends Analyzer {

public static final Reader DUMMY_READER = new StringReader("");
protected AnalyzerFactory factory;
// you analyzer HAS to override this to get proper symbols in results
protected JFlexTokenizer symbolTokenizer;
protected Supplier<JFlexTokenizer> symbolTokenizerFactory;
protected Project project;
protected Ctags ctags;
protected boolean scopesEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
/*
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
* Portions Copyright (c) 2017-2019, Chris Fraire <cfraire@me.com>.
* Portions Copyright (c) 2017-2020, Chris Fraire <cfraire@me.com>.
*/
package org.opengrok.indexer.analysis;

import java.io.IOException;
import java.io.Writer;
import java.util.Locale;
import java.util.function.Supplier;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.lucene.analysis.Analyzer;
Expand All @@ -44,7 +45,7 @@
*
* An Analyzer for a filetype provides
* <ol>
* <li>the file extentions and magic numbers it analyzes</li>
* <li>the file extensions and magic numbers it analyzes</li>
* <li>a lucene document listing the fields it can support</li>
* <li>TokenStreams for each of the field it said requires tokenizing in 2</li>
* <li>cross reference in HTML format</li>
Expand Down Expand Up @@ -100,27 +101,27 @@ public FileAnalyzer(AnalyzerFactory factory) {
throw new IllegalArgumentException("`factory' is null");
}
this.factory = factory;
this.symbolTokenizer = createPlainSymbolTokenizer();
this.symbolTokenizerFactory = this::createPlainSymbolTokenizer;
}

/**
* Creates a new instance of {@link FileAnalyzer}.
*
* @param factory defined instance for the analyzer
* @param symbolTokenizer a defined instance relevant for the file
* @param symbolTokenizerFactory a defined instance relevant for the file
*/
protected FileAnalyzer(AnalyzerFactory factory,
JFlexTokenizer symbolTokenizer) {
Supplier<JFlexTokenizer> symbolTokenizerFactory) {

super(Analyzer.PER_FIELD_REUSE_STRATEGY);
if (factory == null) {
throw new IllegalArgumentException("`factory' is null");
}
if (symbolTokenizer == null) {
throw new IllegalArgumentException("`symbolTokenizer' is null");
if (symbolTokenizerFactory == null) {
throw new IllegalArgumentException("symbolTokenizerFactory is null");
}
this.factory = factory;
this.symbolTokenizer = symbolTokenizer;
this.symbolTokenizerFactory = symbolTokenizerFactory;
}

/**
Expand Down Expand Up @@ -185,7 +186,7 @@ protected TokenStreamComponents createComponents(String fieldName) {
return new HistoryAnalyzer().createComponents(fieldName);
//below is set by PlainAnalyzer to workaround #1376 symbols search works like full text search
case QueryBuilder.REFS: {
return new TokenStreamComponents(symbolTokenizer);
return new TokenStreamComponents(symbolTokenizerFactory.get());
}
case QueryBuilder.DEFS:
return new TokenStreamComponents(createPlainSymbolTokenizer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@

/*
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2017-2018, Chris Fraire <cfraire@me.com>.
* Portions Copyright (c) 2017-2018, 2020, Chris Fraire <cfraire@me.com>.
*/
package org.opengrok.indexer.analysis;

import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.util.function.Supplier;

import org.opengrok.indexer.util.IOUtils;

public abstract class TextAnalyzer extends FileAnalyzer {
Expand All @@ -42,11 +44,11 @@ protected TextAnalyzer(AnalyzerFactory factory) {
/**
* Creates a new instance of {@link TextAnalyzer}.
* @param factory defined instance for the analyzer
* @param symbolTokenizer defined instance for the analyzer
* @param symbolTokenizerFactory defined instance for the analyzer
*/
protected TextAnalyzer(AnalyzerFactory factory,
JFlexTokenizer symbolTokenizer) {
super(factory, symbolTokenizer);
Supplier<JFlexTokenizer> symbolTokenizerFactory) {
super(factory, symbolTokenizerFactory);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

/*
* Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2017-2019, Chris Fraire <cfraire@me.com>.
* Portions Copyright (c) 2017-2020, Chris Fraire <cfraire@me.com>.
*/
package org.opengrok.indexer.analysis.ada;

Expand All @@ -43,7 +43,7 @@ public class AdaAnalyzer extends AbstractSourceCodeAnalyzer {
* @param factory defined instance for the analyzer
*/
protected AdaAnalyzer(AnalyzerFactory factory) {
super(factory, new JFlexTokenizer(new AdaSymbolTokenizer(
super(factory, () -> new JFlexTokenizer(new AdaSymbolTokenizer(
AbstractAnalyzer.DUMMY_READER)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2017-2019, Chris Fraire <cfraire@me.com>.
* Copyright (c) 2017-2020, Chris Fraire <cfraire@me.com>.
*/

package org.opengrok.indexer.analysis.asm;
Expand All @@ -41,7 +41,8 @@ public class AsmAnalyzer extends AbstractSourceCodeAnalyzer {
* @param factory instance
*/
protected AsmAnalyzer(AnalyzerFactory factory) {
super(factory, new JFlexTokenizer(new AsmSymbolTokenizer(AbstractAnalyzer.DUMMY_READER)));
super(factory, () -> new JFlexTokenizer(new AsmSymbolTokenizer(
AbstractAnalyzer.DUMMY_READER)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

/*
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2017-2019, Chris Fraire <cfraire@me.com>.
* Portions Copyright (c) 2017-2020, Chris Fraire <cfraire@me.com>.
*/
package org.opengrok.indexer.analysis.c;

Expand All @@ -44,7 +44,7 @@ public class CAnalyzer extends AbstractSourceCodeAnalyzer {
* @param factory defined instance for the analyzer
*/
protected CAnalyzer(AnalyzerFactory factory) {
super(factory, new JFlexTokenizer(new CSymbolTokenizer(
super(factory, () -> new JFlexTokenizer(new CSymbolTokenizer(
AbstractAnalyzer.DUMMY_READER)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

/*
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2017-2019, Chris Fraire <cfraire@me.com>.
* Portions Copyright (c) 2017-2020, Chris Fraire <cfraire@me.com>.
*/
package org.opengrok.indexer.analysis.c;

Expand All @@ -42,7 +42,7 @@ public class CxxAnalyzer extends AbstractSourceCodeAnalyzer {
* @param factory defined instance for the analyzer
*/
protected CxxAnalyzer(AnalyzerFactory factory) {
super(factory, new JFlexTokenizer(new CxxSymbolTokenizer(
super(factory, () -> new JFlexTokenizer(new CxxSymbolTokenizer(
AbstractAnalyzer.DUMMY_READER)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

/*
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2017-2019, Chris Fraire <cfraire@me.com>.
* Portions Copyright (c) 2017-2020, Chris Fraire <cfraire@me.com>.
*/
package org.opengrok.indexer.analysis.clojure;

Expand All @@ -33,7 +33,7 @@
public class ClojureAnalyzer extends AbstractSourceCodeAnalyzer {

protected ClojureAnalyzer(AnalyzerFactory factory) {
super(factory, new JFlexTokenizer(new ClojureSymbolTokenizer(
super(factory, () -> new JFlexTokenizer(new ClojureSymbolTokenizer(
AbstractAnalyzer.DUMMY_READER)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

/*
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2017-2019, Chris Fraire <cfraire@me.com>.
* Portions Copyright (c) 2017-2020, Chris Fraire <cfraire@me.com>.
*/
package org.opengrok.indexer.analysis.csharp;

Expand All @@ -37,7 +37,7 @@
public class CSharpAnalyzer extends AbstractSourceCodeAnalyzer {

protected CSharpAnalyzer(AnalyzerFactory factory) {
super(factory, new JFlexTokenizer(new CSharpSymbolTokenizer(
super(factory, () -> new JFlexTokenizer(new CSharpSymbolTokenizer(
AbstractAnalyzer.DUMMY_READER)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

/*
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2017-2019, Chris Fraire <cfraire@me.com>.
* Portions Copyright (c) 2017-2020, Chris Fraire <cfraire@me.com>.
*/
package org.opengrok.indexer.analysis.document;

Expand Down Expand Up @@ -47,7 +47,7 @@ public class MandocAnalyzer extends TextAnalyzer {
* @param factory defined instance for the analyzer
*/
protected MandocAnalyzer(AnalyzerFactory factory) {
super(factory, new JFlexTokenizer(new TroffFullTokenizer(
super(factory, () -> new JFlexTokenizer(new TroffFullTokenizer(
AbstractAnalyzer.DUMMY_READER)));
}

Expand Down Expand Up @@ -77,9 +77,9 @@ public void analyze(Document doc, StreamSource src, Writer xrefOut)

// this is to explicitly use appropriate analyzers tokenstream to
// workaround #1376 symbols search works like full text search
this.symbolTokenizer.setReader(getReader(src.getStream()));
OGKTextField full = new OGKTextField(QueryBuilder.FULL,
symbolTokenizer);
JFlexTokenizer symbolTokenizer = symbolTokenizerFactory.get();
symbolTokenizer.setReader(getReader(src.getStream()));
OGKTextField full = new OGKTextField(QueryBuilder.FULL, symbolTokenizer);
doc.add(full);

if (xrefOut != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

/*
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2017-2019, Chris Fraire <cfraire@me.com>.
* Portions Copyright (c) 2017-2020, Chris Fraire <cfraire@me.com>.
*/
package org.opengrok.indexer.analysis.document;

Expand Down Expand Up @@ -50,7 +50,7 @@ public class TroffAnalyzer extends TextAnalyzer {
* @param factory defined instance for the analyzer
*/
protected TroffAnalyzer(AnalyzerFactory factory) {
super(factory, new JFlexTokenizer(new TroffFullTokenizer(
super(factory, () -> new JFlexTokenizer(new TroffFullTokenizer(
AbstractAnalyzer.DUMMY_READER)));
}

Expand All @@ -75,10 +75,10 @@ protected int getSpecializedVersionNo() {

@Override
public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOException {
//this is to explicitly use appropriate analyzers tokenstream to workaround #1376 symbols search works like full text search
this.symbolTokenizer.setReader(getReader(src.getStream()));
OGKTextField full = new OGKTextField(QueryBuilder.FULL,
symbolTokenizer);
//this is to explicitly use appropriate analyzers tokenstream to workaround #1376 symbols search works like full text search
JFlexTokenizer symbolTokenizer = symbolTokenizerFactory.get();
symbolTokenizer.setReader(getReader(src.getStream()));
OGKTextField full = new OGKTextField(QueryBuilder.FULL, symbolTokenizer);
doc.add(full);

if (xrefOut != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2017-2019, Chris Fraire <cfraire@me.com>.
* Copyright (c) 2017-2020, Chris Fraire <cfraire@me.com>.
*/

package org.opengrok.indexer.analysis.eiffel;
Expand All @@ -40,7 +40,7 @@ public class EiffelAnalyzer extends AbstractSourceCodeAnalyzer {
* @param factory instance
*/
protected EiffelAnalyzer(AnalyzerFactory factory) {
super(factory, new JFlexTokenizer(new EiffelSymbolTokenizer(
super(factory, () -> new JFlexTokenizer(new EiffelSymbolTokenizer(
AbstractAnalyzer.DUMMY_READER)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

/*
* Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2017-2019, Chris Fraire <cfraire@me.com>.
* Portions Copyright (c) 2017-2020, Chris Fraire <cfraire@me.com>.
*/

package org.opengrok.indexer.analysis.erlang;
Expand All @@ -38,7 +38,7 @@ public class ErlangAnalyzer extends AbstractSourceCodeAnalyzer {
* @param factory defined instance for the analyzer
*/
protected ErlangAnalyzer(AnalyzerFactory factory) {
super(factory, new JFlexTokenizer(new ErlangSymbolTokenizer(
super(factory, () -> new JFlexTokenizer(new ErlangSymbolTokenizer(
AbstractAnalyzer.DUMMY_READER)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

/*
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2017-2019, Chris Fraire <cfraire@me.com>.
* Portions Copyright (c) 2017-2020, Chris Fraire <cfraire@me.com>.
*/
package org.opengrok.indexer.analysis.fortran;

Expand All @@ -37,7 +37,7 @@
public class FortranAnalyzer extends AbstractSourceCodeAnalyzer {

FortranAnalyzer(FortranAnalyzerFactory factory) {
super(factory, new JFlexTokenizer(new FortranSymbolTokenizer(
super(factory, () -> new JFlexTokenizer(new FortranSymbolTokenizer(
AbstractAnalyzer.DUMMY_READER)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

/*
* Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2017-2019, Chris Fraire <cfraire@me.com>.
* Portions Copyright (c) 2017-2020, Chris Fraire <cfraire@me.com>.
*/

package org.opengrok.indexer.analysis.golang;
Expand All @@ -42,7 +42,7 @@ public class GolangAnalyzer extends AbstractSourceCodeAnalyzer {
* @param factory defined instance for the analyzer
*/
protected GolangAnalyzer(AnalyzerFactory factory) {
super(factory, new JFlexTokenizer(new GolangSymbolTokenizer(
super(factory, () -> new JFlexTokenizer(new GolangSymbolTokenizer(
AbstractAnalyzer.DUMMY_READER)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

/*
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2017-2019, Chris Fraire <cfraire@me.com>.
* Portions Copyright (c) 2017-2020, Chris Fraire <cfraire@me.com>.
*/

package org.opengrok.indexer.analysis.haskell;
Expand All @@ -41,7 +41,7 @@ public class HaskellAnalyzer extends AbstractSourceCodeAnalyzer {
* @param factory defined instance for the analyzer
*/
protected HaskellAnalyzer(AnalyzerFactory factory) {
super(factory, new JFlexTokenizer(new HaskellSymbolTokenizer(
super(factory, () -> new JFlexTokenizer(new HaskellSymbolTokenizer(
AbstractAnalyzer.DUMMY_READER)));
}

Expand Down
Loading

0 comments on commit 9cd38b9

Please sign in to comment.