Skip to content

Commit 1515b2f

Browse files
authored
Merge pull request #1845 from idodeclare/feature/refactor_statics
Drop static writeXref()s; use existing thread-cached analyzers instead
2 parents c527202 + 9b3f749 commit 1515b2f

File tree

76 files changed

+229
-900
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+229
-900
lines changed

.gitignore

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
*~
2-
nbproject/*~
2+
*.swp
33
/nbproject/configs/*.properties
4-
opengrok-web-nbproject/nbproject/*~
5-
opengrok-web-nbproject/nbproject/build-impl.xml~
64
tags
75
TAGS
86
build
@@ -39,8 +37,6 @@ webrev
3937
opengrok-web-nbproject/nbproject/private/
4038
opengrok-web-nbproject/nbproject/genfiles.properties
4139
run_my.bat
42-
*.xml~
43-
opengrok-web-nbproject/nbproject/build-impl.xml~
4440
build.bat
4541
jacoco
4642
jacoco.exec

src/org/opensolaris/opengrok/analysis/AnalyzerGuru.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,14 @@ public static void writeXref(FileAnalyzerFactory factory, Reader in,
462462
// spaces to match the project's tab settings.
463463
input = ExpandTabsReader.wrap(in, project);
464464
}
465-
factory.writeXref(input, out, defs, annotation, project);
465+
466+
WriteXrefArgs args = new WriteXrefArgs(input, out);
467+
args.setDefs(defs);
468+
args.setAnnotation(annotation);
469+
args.setProject(project);
470+
471+
FileAnalyzer analyzer = factory.getAnalyzer();
472+
analyzer.writeXref(args);
466473
}
467474

468475
/**

src/org/opensolaris/opengrok/analysis/FileAnalyzer.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
/*
2121
* Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
2222
* Use is subject to license terms.
23+
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
2324
*/
2425
package org.opensolaris.opengrok.analysis;
2526

@@ -182,6 +183,18 @@ public String getFileTypeName() {
182183
public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOException {
183184
// not used
184185
}
186+
187+
/**
188+
* Derived classes should override to write a cross referenced HTML file
189+
* for the specified args.
190+
* @param args a defined instance
191+
* @return the instance used to write the cross-referencing
192+
* @throws java.io.IOException if an error occurs
193+
*/
194+
public JFlexXref writeXref(WriteXrefArgs args) throws IOException {
195+
throw new UnsupportedOperationException(
196+
"Base FileAnalyzer cannot write xref");
197+
}
185198

186199
// you analyzer HAS to override this to get proper symbols in results
187200
protected JFlexTokenizer SymbolTokenizer;

src/org/opensolaris/opengrok/analysis/FileAnalyzerFactory.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,10 @@
2525

2626
import java.io.IOException;
2727
import java.io.InputStream;
28-
import java.io.Reader;
29-
import java.io.Writer;
3028
import java.util.Arrays;
3129
import java.util.Collections;
3230
import java.util.List;
3331
import org.opensolaris.opengrok.analysis.FileAnalyzer.Genre;
34-
import org.opensolaris.opengrok.configuration.Project;
35-
import org.opensolaris.opengrok.history.Annotation;
3632

3733
/**
3834
* Factory class which creates a {@code FileAnalyzer} object and
@@ -241,18 +237,4 @@ protected interface Matcher {
241237
FileAnalyzerFactory isMagic(byte[] contents, InputStream in)
242238
throws IOException;
243239
}
244-
245-
/**
246-
* Write a cross referenced HTML file. Reads the source from {@code in}.
247-
* @param in input source
248-
* @param out output xref writer
249-
* @param defs definitions for the file (could be {@code null})
250-
* @param annotation annotation for the file (could be {@code null})
251-
* @param project project the file belongs to (could be {@code null})
252-
* @throws java.io.IOException if an error occurs
253-
*/
254-
public void writeXref(Reader in, Writer out, Definitions defs, Annotation annotation, Project project)
255-
throws IOException {
256-
throw new UnsupportedOperationException("Not yet implemented");
257-
}
258240
}

src/org/opensolaris/opengrok/analysis/TextAnalyzer.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,13 @@
1919

2020
/*
2121
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
2223
*/
2324
package org.opensolaris.opengrok.analysis;
2425

25-
import java.io.BufferedInputStream;
2626
import java.io.IOException;
2727
import java.io.InputStream;
28-
import java.io.InputStreamReader;
2928
import java.io.Reader;
30-
import java.nio.charset.Charset;
3129
import org.opensolaris.opengrok.util.IOUtils;
3230

3331
public abstract class TextAnalyzer extends FileAnalyzer {
@@ -36,6 +34,33 @@ public TextAnalyzer(FileAnalyzerFactory factory) {
3634
super(factory);
3735
}
3836

37+
/**
38+
* Write a cross referenced HTML file reads the source from in
39+
* @param args a defined instance
40+
* @return the instance used to write the cross-referencing
41+
* @throws IOException if an I/O error occurs
42+
*/
43+
@Override
44+
public JFlexXref writeXref(WriteXrefArgs args) throws IOException {
45+
if (args == null) throw new IllegalArgumentException("`args' is null");
46+
JFlexXref xref = newXref(args.getIn());
47+
xref.setDefs(args.getDefs());
48+
xref.setScopesEnabled(scopesEnabled);
49+
xref.setFoldingEnabled(foldingEnabled);
50+
xref.annotation = args.getAnnotation();
51+
xref.project = args.getProject();
52+
xref.write(args.getOut());
53+
return xref;
54+
}
55+
56+
/**
57+
* Derived classes should implement to create an xref for the language
58+
* supported by this analyzer.
59+
* @param reader the data to produce xref for
60+
* @return an xref instance
61+
*/
62+
protected abstract JFlexXref newXref(Reader reader);
63+
3964
protected Reader getReader(InputStream stream) throws IOException {
4065
return IOUtils.createBOMStrippedReader(stream);
4166
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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) 2017, Chris Fraire <[email protected]>.
22+
*/
23+
package org.opensolaris.opengrok.analysis;
24+
25+
import java.io.Reader;
26+
import java.io.Writer;
27+
import org.opensolaris.opengrok.configuration.Project;
28+
import org.opensolaris.opengrok.history.Annotation;
29+
30+
/**
31+
* Represents the arguments for the
32+
* {@link org.opensolaris.opengrok.analysis.FileAnalyzer#writeXref(org.opensolaris.opengrok.analysis.WriteXrefArgs)}
33+
* method.
34+
*/
35+
public class WriteXrefArgs {
36+
private final Reader in;
37+
private final Writer out;
38+
private Definitions defs;
39+
private Annotation annotation;
40+
private Project project;
41+
42+
/**
43+
* Initializes an instance of {@link WriteXrefArgs} for the required
44+
* arguments.
45+
* @param in a defined instance
46+
* @param out a defined instance
47+
* @throws IllegalArgumentException thrown if any argument is null.
48+
*/
49+
public WriteXrefArgs(Reader in, Writer out) {
50+
if (in == null) throw new IllegalArgumentException("`in' is null");
51+
if (out == null) throw new IllegalArgumentException("`out' is null");
52+
this.in = in;
53+
this.out = out;
54+
}
55+
56+
public Reader getIn() { return in; }
57+
public Writer getOut() { return out; }
58+
59+
public Definitions getDefs() { return defs; }
60+
public void setDefs(Definitions value) { defs = value; }
61+
62+
public Annotation getAnnotation() { return annotation; }
63+
public void setAnnotation(Annotation value) { annotation = value; }
64+
65+
public Project getProject() { return project; }
66+
public void setProject(Project value) { project = value; }
67+
}

src/org/opensolaris/opengrok/analysis/c/CAnalyzer.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,11 @@
2222
*/
2323
package org.opensolaris.opengrok.analysis.c;
2424

25-
import java.io.IOException;
2625
import java.io.Reader;
27-
import java.io.Writer;
28-
import org.opensolaris.opengrok.analysis.Definitions;
2926
import org.opensolaris.opengrok.analysis.FileAnalyzer;
3027
import org.opensolaris.opengrok.analysis.FileAnalyzerFactory;
3128
import org.opensolaris.opengrok.analysis.JFlexXref;
3229
import org.opensolaris.opengrok.analysis.plain.AbstractSourceCodeAnalyzer;
33-
import org.opensolaris.opengrok.configuration.Project;
34-
import org.opensolaris.opengrok.history.Annotation;
3530

3631
/**
3732
* An Analyzer for C/C++/Java type of files
@@ -60,9 +55,4 @@ protected JFlexXref newXref(Reader reader) {
6055
protected boolean supportsScopes() {
6156
return true;
6257
}
63-
64-
static void writeXref(Reader in, Writer out, Definitions defs, Annotation annotation, Project project) throws IOException {
65-
CXref xref = new CXref(in);
66-
AbstractSourceCodeAnalyzer.writeXref(xref, in, out, defs, annotation, project);
67-
}
6858
}

src/org/opensolaris/opengrok/analysis/c/CAnalyzerFactory.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,9 @@
2323

2424
package org.opensolaris.opengrok.analysis.c;
2525

26-
import java.io.IOException;
27-
import java.io.Reader;
28-
import java.io.Writer;
29-
import org.opensolaris.opengrok.analysis.Definitions;
3026
import org.opensolaris.opengrok.analysis.FileAnalyzer;
3127
import org.opensolaris.opengrok.analysis.FileAnalyzer.Genre;
3228
import org.opensolaris.opengrok.analysis.FileAnalyzerFactory;
33-
import org.opensolaris.opengrok.configuration.Project;
34-
import org.opensolaris.opengrok.history.Annotation;
3529

3630
public class CAnalyzerFactory extends FileAnalyzerFactory {
3731

@@ -59,10 +53,4 @@ public CAnalyzerFactory() {
5953
protected FileAnalyzer newAnalyzer() {
6054
return new CAnalyzer(this);
6155
}
62-
63-
@Override
64-
public void writeXref(Reader in, Writer out, Definitions defs, Annotation annotation, Project project)
65-
throws IOException {
66-
CAnalyzer.writeXref(in, out, defs, annotation, project);
67-
}
6856
}

src/org/opensolaris/opengrok/analysis/c/CxxAnalyzer.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,11 @@
2222
*/
2323
package org.opensolaris.opengrok.analysis.c;
2424

25-
import java.io.IOException;
2625
import java.io.Reader;
27-
import java.io.Writer;
28-
import org.opensolaris.opengrok.analysis.Definitions;
2926
import org.opensolaris.opengrok.analysis.FileAnalyzer;
3027
import org.opensolaris.opengrok.analysis.FileAnalyzerFactory;
3128
import org.opensolaris.opengrok.analysis.JFlexXref;
3229
import org.opensolaris.opengrok.analysis.plain.AbstractSourceCodeAnalyzer;
33-
import org.opensolaris.opengrok.configuration.Project;
34-
import org.opensolaris.opengrok.history.Annotation;
3530

3631
/**
3732
* An Analyzer for C++ files
@@ -58,9 +53,4 @@ protected JFlexXref newXref(Reader reader) {
5853
protected boolean supportsScopes() {
5954
return true;
6055
}
61-
62-
static void writeXref(Reader in, Writer out, Definitions defs, Annotation annotation, Project project) throws IOException {
63-
CxxXref xref = new CxxXref(in);
64-
AbstractSourceCodeAnalyzer.writeXref(xref, in, out, defs, annotation, project);
65-
}
6656
}

src/org/opensolaris/opengrok/analysis/c/CxxAnalyzerFactory.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,9 @@
2222
*/
2323
package org.opensolaris.opengrok.analysis.c;
2424

25-
import java.io.IOException;
26-
import java.io.Reader;
27-
import java.io.Writer;
28-
import org.opensolaris.opengrok.analysis.Definitions;
2925
import org.opensolaris.opengrok.analysis.FileAnalyzer;
3026
import org.opensolaris.opengrok.analysis.FileAnalyzer.Genre;
3127
import org.opensolaris.opengrok.analysis.FileAnalyzerFactory;
32-
import org.opensolaris.opengrok.configuration.Project;
33-
import org.opensolaris.opengrok.history.Annotation;
3428

3529
public class CxxAnalyzerFactory extends FileAnalyzerFactory {
3630

@@ -56,10 +50,4 @@ public CxxAnalyzerFactory() {
5650
protected FileAnalyzer newAnalyzer() {
5751
return new CxxAnalyzer(this);
5852
}
59-
60-
@Override
61-
public void writeXref(Reader in, Writer out, Definitions defs, Annotation annotation, Project project)
62-
throws IOException {
63-
CxxAnalyzer.writeXref(in, out, defs, annotation, project);
64-
}
6553
}

0 commit comments

Comments
 (0)