-
Notifications
You must be signed in to change notification settings - Fork 16
/
MainParser.java
123 lines (108 loc) · 3.55 KB
/
MainParser.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package edu.lu.uni.serval;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import edu.lu.uni.serval.akka.method.parser.MultipleShreadParser;
import edu.lu.uni.serval.method.parser.MethodParser;
import edu.lu.uni.serval.utils.FileHelper;
/**
* Examples of the tool: parse methods.
*
* @author kui.liu
*
*/
public class MainParser {
public static void main(String[] args) {
MainParser parser = new MainParser();
try {
/*
* Parse Java code methods with multiple threads.
* The input is all obtained Java code files of one Java project.
* It needs to merge all output data if using this choice.
*
*/
List<String> projectNames = readProjects();
int i = Integer.valueOf(args[0]); // 0 - 429: 430 Java projects.
if (i >= projectNames.size()) {
System.out.println("Wrong parameter: " + args[0]);
return;
}
String projectName = projectNames.get(i);
String project = Configuration.JAVA_FILES_PATH + projectName + ".txt";
if (! new File(project).exists()) {
project = Configuration.JAVA_REPOS_PATH + projectName;
}
parser.parseMethodsWithMultipleThreads(project, projectName);
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Parse method bodies: tokenize and vectorize method bodies.
*
* @throws IOException
*/
public void parseMethodsWithSingleThread() throws IOException {
List<String> projects = Configuration.PROJECTS;
String outputPath = Configuration.TOKENIZED_METHODS_PATH;
// Clear existing output data generated at the last time.
FileHelper.deleteDirectory(outputPath);
MethodParser mp = new MethodParser();
mp.parseProjects(projects, outputPath);
}
/**
* Parse method bodies with multiple threads.
*
* One thread is used to parse one project.
*
* @throws IOException
*/
public void parseMethodsWithMultipleThreads() throws IOException {
List<String> projects = Configuration.PROJECTS;
String outputPath = Configuration.TOKENIZED_METHODS_PATH;
// Clear existing output data generated at the last time.
FileHelper.deleteDirectory(outputPath);
int numberOfWorkers = 430;
MultipleShreadParser parser = new MultipleShreadParser(projects, outputPath, numberOfWorkers);
parser.parseMethods();
}
/**
* Parse method bodies with multiple threads.
* @throws IOException
*/
public void parseMethodsWithMultipleThreads(String allJavaFilesFile) throws IOException {
String outputPath = Configuration.TOKENIZED_METHODS_PATH;
int numberOfWorkers = 1000;
MultipleShreadParser parser = new MultipleShreadParser(allJavaFilesFile, outputPath, numberOfWorkers);
parser.parseMethods();
}
/**
* Parse method bodies with multiple threads.
*
* @throws IOException
*/
public void parseMethodsWithMultipleThreads(String project, String projectName) throws IOException {
String outputPath = Configuration.TOKENIZED_METHODS_PATH + projectName + "/";
int numberOfWorkers = 1000;
MultipleShreadParser parser = new MultipleShreadParser(project, outputPath, numberOfWorkers);
parser.parseMethods();
}
private static List<String> readProjects() throws IOException {
String content = FileHelper.readFile(Configuration.JAVA_REPO_NAMES_FILE);
List<String> list = new ArrayList<>();
BufferedReader reader = new BufferedReader(new StringReader(content));
try {
String line = null;
while ((line = reader.readLine()) != null) {
list.add(line);
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
return list;
}
}