use of org.opengrok.indexer.analysis.WriteXrefArgs in project OpenGrok by OpenGrok.
the class PhpXrefTest method basicSingleQuotedStringTest.
@Test
public void basicSingleQuotedStringTest() throws IOException {
String s = "<?php define(\"FOO\", 'BAR\\'\"'); $foo='bar'; $hola=\"ls\"; $hola=''; $hola=\"\";";
Writer w = new StringWriter();
PhpAnalyzerFactory fac = new PhpAnalyzerFactory();
AbstractAnalyzer analyzer = fac.getAnalyzer();
WriteXrefArgs xargs = new WriteXrefArgs(new StringReader(s), w);
Xrefer xref = analyzer.writeXref(xargs);
assertLinesEqual("PHP quoting", "<a class=\"l\" name=\"1\" href=\"#1\">1</a><strong><?php</strong> " + "<a href=\"/source/s?defs=define\" class=\"intelliWindow-symbol\" " + "data-definition-place=\"undefined-in-file\">define</a>(<span class=\"s\">"FOO"</span>," + " <span class=\"s\">'BAR<strong>\\'</strong>"'</span>); " + "$<a href=\"/source/s?defs=foo\" class=\"intelliWindow-symbol\" " + "data-definition-place=\"undefined-in-file\">foo</a>=<span class=\"s\">'bar'</span>; " + "$<a href=\"/source/s?defs=hola\" class=\"intelliWindow-symbol\" " + "data-definition-place=\"undefined-in-file\">hola</a>=<span class=\"s\">"ls"</span>; " + "$<a href=\"/source/s?defs=hola\" class=\"intelliWindow-symbol\" " + "data-definition-place=\"undefined-in-file\">hola</a>=<span class=\"s\">''</span>; " + "$<a href=\"/source/s?defs=hola\" class=\"intelliWindow-symbol\" " + "data-definition-place=\"undefined-in-file\">hola</a>=<span class=\"s\">""</span>;", w.toString());
assertEquals(1, xref.getLOC(), "PHP LOC");
}
use of org.opengrok.indexer.analysis.WriteXrefArgs in project OpenGrok by OpenGrok.
the class HaskellXrefTest method basicTest.
@Test
public void basicTest() throws IOException {
String s = "putStrLn \"Hello, world!\"";
Writer w = new StringWriter();
HaskellAnalyzerFactory fac = new HaskellAnalyzerFactory();
AbstractAnalyzer analyzer = fac.getAnalyzer();
WriteXrefArgs xargs = new WriteXrefArgs(new StringReader(s), w);
Xrefer xref = analyzer.writeXref(xargs);
assertLinesEqual("Haskell basicTest", "<a class=\"l\" name=\"1\" href=\"#1\">1</a>" + "<a href=\"/source/s?defs=putStrLn\" class=\"intelliWindow-symbol\"" + " data-definition-place=\"undefined-in-file\">putStrLn</a>" + " <span class=\"s\">"Hello, world!"</span>\n", w.toString());
assertEquals(1, xref.getLOC(), "Haskell LOC");
}
use of org.opengrok.indexer.analysis.WriteXrefArgs in project OpenGrok by OpenGrok.
the class PlainAnalyzer method analyze.
@Override
public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOException, InterruptedException {
Definitions defs = null;
NullWriter nullWriter = null;
doc.add(new OGKTextField(QueryBuilder.FULL, getReader(src.getStream())));
String fullPath = doc.get(QueryBuilder.FULLPATH);
if (fullPath != null && ctags != null) {
defs = ctags.doCtags(fullPath);
if (defs != null && defs.numberOfSymbols() > 0) {
tryAddingDefs(doc, defs, src);
byte[] tags = defs.serialize();
doc.add(new StoredField(QueryBuilder.TAGS, tags));
}
}
/*
* This is to explicitly use appropriate analyzer's token stream to
* work around #1376: symbols search works like full text search.
*/
JFlexTokenizer symbolTokenizer = symbolTokenizerFactory.get();
OGKTextField ref = new OGKTextField(QueryBuilder.REFS, symbolTokenizer);
symbolTokenizer.setReader(getReader(src.getStream()));
doc.add(ref);
if (scopesEnabled && xrefOut == null) {
/*
* Scopes are generated during xref generation. If xrefs are
* turned off we still need to run writeXref() to produce scopes,
* we use a dummy writer that will throw away any xref output.
*/
nullWriter = new NullWriter();
xrefOut = nullWriter;
}
if (xrefOut != null) {
try (Reader in = getReader(src.getStream())) {
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
WriteXrefArgs args = new WriteXrefArgs(in, xrefOut);
args.setDefs(defs);
args.setProject(project);
CompletableFuture<XrefWork> future = CompletableFuture.supplyAsync(() -> {
try {
return new XrefWork(writeXref(args));
} catch (IOException e) {
return new XrefWork(e);
}
}, env.getIndexerParallelizer().getXrefWatcherExecutor()).orTimeout(env.getXrefTimeout(), TimeUnit.SECONDS);
// Will throw ExecutionException wrapping TimeoutException on timeout.
XrefWork xrefWork = future.get();
Xrefer xref = xrefWork.xrefer;
if (xref != null) {
Scopes scopes = xref.getScopes();
if (scopes.size() > 0) {
byte[] scopesSerialized = scopes.serialize();
doc.add(new StoredField(QueryBuilder.SCOPES, scopesSerialized));
}
String path = doc.get(QueryBuilder.PATH);
addNumLinesLOC(doc, new NumLinesLOC(path, xref.getLineNumber(), xref.getLOC()));
} else {
// Re-throw the exception from writeXref().
throw new IOException(xrefWork.exception);
}
} catch (ExecutionException e) {
throw new InterruptedException("failed to generate xref :" + e);
} finally {
if (nullWriter != null) {
nullWriter.close();
}
}
}
}
use of org.opengrok.indexer.analysis.WriteXrefArgs in project OpenGrok by OpenGrok.
the class XMLAnalyzer method analyze.
@Override
public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOException {
doc.add(new OGKTextField(QueryBuilder.FULL, getReader(src.getStream())));
if (xrefOut != null) {
try (Reader in = getReader(src.getStream())) {
WriteXrefArgs args = new WriteXrefArgs(in, xrefOut);
args.setProject(project);
Xrefer xref = writeXref(args);
String path = doc.get(QueryBuilder.PATH);
addNumLinesLOC(doc, new NumLinesLOC(path, xref.getLineNumber(), xref.getLOC()));
}
}
}
use of org.opengrok.indexer.analysis.WriteXrefArgs in project OpenGrok by OpenGrok.
the class MandocAnalyzer method analyze.
@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
JFlexTokenizer symbolTokenizer = symbolTokenizerFactory.get();
symbolTokenizer.setReader(getReader(src.getStream()));
OGKTextField full = new OGKTextField(QueryBuilder.FULL, symbolTokenizer);
doc.add(full);
if (xrefOut != null) {
try (Reader in = getReader(src.getStream())) {
WriteXrefArgs args = new WriteXrefArgs(in, xrefOut);
args.setProject(project);
Xrefer xref = writeXref(args);
String path = doc.get(QueryBuilder.PATH);
addNumLinesLOC(doc, new NumLinesLOC(path, xref.getLineNumber(), xref.getLOC()));
}
}
}
Aggregations