12
12
import java .util .ArrayList ;
13
13
import java .util .List ;
14
14
import java .util .concurrent .Callable ;
15
+ import com .google .gson .Gson ;
15
16
16
17
class ExtractFeaturesTask implements Callable <Void > {
17
- private final CommandLineValues m_CommandLineValues ;
18
+ private final CommandLineValues commandLineValues ;
18
19
private final Path filePath ;
19
20
20
21
public ExtractFeaturesTask (CommandLineValues commandLineValues , Path path ) {
21
- m_CommandLineValues = commandLineValues ;
22
+ this . commandLineValues = commandLineValues ;
22
23
this .filePath = path ;
23
24
}
24
25
@@ -49,8 +50,8 @@ public void processFile() {
49
50
private ArrayList <ProgramFeatures > extractSingleFile () throws IOException {
50
51
String code ;
51
52
52
- if (m_CommandLineValues .MaxFileLength > 0 &&
53
- Files .lines (filePath , Charset .defaultCharset ()).count () > m_CommandLineValues .MaxFileLength ) {
53
+ if (commandLineValues .MaxFileLength > 0 &&
54
+ Files .lines (filePath , Charset .defaultCharset ()).count () > commandLineValues .MaxFileLength ) {
54
55
return new ArrayList <>();
55
56
}
56
57
try {
@@ -59,7 +60,7 @@ private ArrayList<ProgramFeatures> extractSingleFile() throws IOException {
59
60
e .printStackTrace ();
60
61
code = Common .EmptyString ;
61
62
}
62
- FeatureExtractor featureExtractor = new FeatureExtractor (m_CommandLineValues );
63
+ FeatureExtractor featureExtractor = new FeatureExtractor (commandLineValues , this . filePath );
63
64
64
65
return featureExtractor .extractFeatures (code );
65
66
}
@@ -74,8 +75,14 @@ public String featuresToString(ArrayList<ProgramFeatures> features) {
74
75
for (ProgramFeatures singleMethodFeatures : features ) {
75
76
StringBuilder builder = new StringBuilder ();
76
77
77
- String toPrint = singleMethodFeatures .toString ();
78
- if (m_CommandLineValues .PrettyPrint ) {
78
+ String toPrint ;
79
+ if (commandLineValues .JsonOutput ) {
80
+ toPrint = new Gson ().toJson (singleMethodFeatures );
81
+ }
82
+ else {
83
+ toPrint = singleMethodFeatures .toString ();
84
+ }
85
+ if (commandLineValues .PrettyPrint ) {
79
86
toPrint = toPrint .replace (" " , "\n \t " );
80
87
}
81
88
builder .append (toPrint );
0 commit comments