41
41
import org .apache .bcel .classfile .ConstantDouble ;
42
42
import org .apache .bcel .classfile .ConstantFloat ;
43
43
import org .apache .bcel .classfile .ConstantInteger ;
44
- import org .apache .bcel .classfile .ConstantInvokeDynamic ;
45
44
import org .apache .bcel .classfile .ConstantLong ;
46
- import org .apache .bcel .classfile .ConstantMethodHandle ;
47
45
import org .apache .bcel .classfile .ConstantMethodType ;
48
46
import org .apache .bcel .classfile .ConstantModule ;
49
47
import org .apache .bcel .classfile .ConstantNameAndType ;
60
58
import org .apache .lucene .document .Field .Store ;
61
59
import org .opensolaris .opengrok .analysis .FileAnalyzer ;
62
60
import org .opensolaris .opengrok .analysis .FileAnalyzerFactory ;
63
- import org .opensolaris .opengrok .analysis .IteratorReader ;
64
61
import org .opensolaris .opengrok .analysis .OGKTextField ;
65
- import org .opensolaris .opengrok .analysis .OGKTextVecField ;
66
62
import org .opensolaris .opengrok .analysis .StreamSource ;
67
63
import org .opensolaris .opengrok .configuration .RuntimeEnvironment ;
68
64
import org .opensolaris .opengrok .logger .LoggerFactory ;
@@ -94,36 +90,36 @@ protected JavaClassAnalyzer(FileAnalyzerFactory factory) {
94
90
* Gets a version number to be used to tag processed documents so that
95
91
* re-analysis can be re-done later if a stored version number is different
96
92
* from the current implementation.
97
- * @return 20180112_00
93
+ * @return 20180612_00
98
94
*/
99
95
@ Override
100
96
protected int getSpecializedVersionNo () {
101
- return 20180112_00 ; // Edit comment above too!
97
+ return 20180612_00 ; // Edit comment above too!
102
98
}
103
99
104
100
@ Override
105
101
public void analyze (Document doc , StreamSource src , Writer xrefOut ) throws IOException {
106
102
try (InputStream in = src .getStream ()) {
107
- analyze (doc , in , xrefOut );
103
+ analyze (doc , in , xrefOut , null );
108
104
}
109
105
}
110
106
111
- void analyze (Document doc , InputStream in , Writer xrefOut ) throws IOException {
107
+ void analyze (Document doc , InputStream in , Writer xrefOut ,
108
+ JFieldBuilder jfbuilder ) throws IOException {
112
109
List <String > defs = new ArrayList <>();
113
110
List <String > refs = new ArrayList <>();
114
111
List <String > full = new ArrayList <>();
115
112
116
- StringWriter dout = new StringWriter ();
117
- StringWriter rout = new StringWriter ();
118
- StringWriter fout = new StringWriter ();
119
-
120
- /**
121
- * The JarAnalyzer uses JavaClassAnalyzer, so if a DEFS, REFS, or FULL
122
- * field exists already, then append to it.
123
- */
124
- useExtantValue (dout , doc , QueryBuilder .DEFS );
125
- useExtantValue (rout , doc , QueryBuilder .REFS );
126
- useExtantValue (fout , doc , QueryBuilder .FULL );
113
+ StringWriter dout , rout , fout ;
114
+ if (jfbuilder == null ) {
115
+ dout = new StringWriter ();
116
+ rout = new StringWriter ();
117
+ fout = new StringWriter ();
118
+ } else {
119
+ dout = jfbuilder .write (QueryBuilder .DEFS );
120
+ rout = jfbuilder .write (QueryBuilder .REFS );
121
+ fout = jfbuilder .write (QueryBuilder .FULL );
122
+ }
127
123
128
124
ClassParser classparser = new ClassParser (in ,
129
125
doc .get (QueryBuilder .PATH ));
@@ -140,25 +136,20 @@ void analyze(Document doc, InputStream in, Writer xrefOut) throws IOException {
140
136
}
141
137
}
142
138
143
- appendValues (dout , defs , "" );
144
- appendValues (rout , refs , "" );
145
- appendValues (fout , full , "// " );
139
+ appendValues (dout , defs );
140
+ appendValues (rout , refs );
141
+ appendValues (fout , full );
146
142
147
- /**
148
- * Unlike other analyzers, which rely on the full content existing to be
149
- * accessed at a file system location identified by PATH, *.class and
150
- * *.jar files have virtual content which is stored here (Store.YES) for
151
- * analyzer convenience.
152
- */
143
+ if (jfbuilder == null ) {
144
+ String dstr = dout .toString ();
145
+ doc .add (new OGKTextField (QueryBuilder .DEFS , dstr , Store .NO ));
153
146
154
- String dstr = dout .toString ();
155
- doc .add (new OGKTextField (QueryBuilder .DEFS , dstr , Store .YES ));
147
+ String rstr = rout .toString ();
148
+ doc .add (new OGKTextField (QueryBuilder .REFS , rstr , Store .NO ));
156
149
157
- String rstr = rout .toString ();
158
- doc .add (new OGKTextField (QueryBuilder .REFS , rstr , Store .YES ));
159
-
160
- String fstr = fout .toString ();
161
- doc .add (new OGKTextField (QueryBuilder .FULL , fstr , Store .YES ));
150
+ String fstr = fout .toString ();
151
+ doc .add (new OGKTextField (QueryBuilder .FULL , fstr , Store .NO ));
152
+ }
162
153
}
163
154
164
155
@@ -565,19 +556,8 @@ public String constantToString(Constant c, ConstantPool cp, int[] v)
565
556
return str ;
566
557
}
567
558
568
- private static void useExtantValue (StringWriter accum , Document doc ,
569
- String field ) {
570
- String extantValue = doc .get (field );
571
- if (extantValue != null ) {
572
- doc .removeFields (field );
573
- accum .append (extantValue );
574
- }
575
- }
576
-
577
- private static void appendValues (StringWriter accum , List <String > full ,
578
- String lede ) {
559
+ private static void appendValues (StringWriter accum , List <String > full ) {
579
560
for (String fl : full ) {
580
- accum .write (lede );
581
561
accum .write (fl );
582
562
accum .write (EOL );
583
563
}
0 commit comments