Skip to content

Commit 8c5a615

Browse files
author
Paulo B. Costa
authored
Merge pull request #21 from costabatista/T-023
first release
2 parents 64cec68 + db37168 commit 8c5a615

File tree

6 files changed

+86
-141
lines changed

6 files changed

+86
-141
lines changed

project_analyses/reader/project_reader.py

Lines changed: 0 additions & 85 deletions
This file was deleted.

simitrieve/src/main/java/ml/paulobatista/simitrieve/App.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class App {
2222
public static void main(String[] args) {
2323

2424
CMDManager cmdManager = new CMDManager(args);
25-
Process process = cmdManager.getProcess();
25+
Process process = cmdManager.getProcess(args[0]);
2626
Project project = new ProjectFactory().getProject(cmdManager.getProjectPath(), cmdManager.getProjectName(),
2727
process.getProgrammingLanguage());
2828
project.setVersion(cmdManager.getProjectVersion());

simitrieve/src/main/java/ml/paulobatista/simitrieve/cmd/CMDManager.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,22 @@ public CMDManager(String[] args) {
4646
}
4747
}
4848

49-
public Process getProcess() {
49+
public Process getProcess(String typeOfProcess) {
5050
Process process = new Process();
51-
process.setComment(getProcessComments());
52-
process.setCamelCase(getProcessCamelCase());
53-
process.setStem(getProcessStemming());
54-
process.setQuantile(getProcessQuantile());
55-
process.setNormalization(getProcessNormalization());
56-
process.setProgrammingLanguage(getProcessProgrammingLanguage());
51+
if (typeOfProcess.equals("feature")) {
52+
process.setProgrammingLanguage(getProcessProgrammingLanguage());
53+
} else if (typeOfProcess.equals("similarity")) {
54+
process.setComment(getProcessComments());
55+
process.setCamelCase(getProcessCamelCase());
56+
process.setStem(getProcessStemming());
57+
process.setQuantile(getProcessQuantile());
58+
process.setNormalization(getProcessNormalization());
59+
process.setProgrammingLanguage(getProcessProgrammingLanguage());
60+
}
61+
else {
62+
System.out.println("This operation cannot be recognized");
63+
System.exit(-1);
64+
}
5765

5866
return process;
5967
}

simitrieve/src/main/java/ml/paulobatista/simitrieve/error/Error.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ public enum Error {
1212
PROJECT_VERSION_IS_NULL(9),
1313
TOKENLIST_DO_NOT_CONTAINS_VALUE_ERROR(10),
1414
DICTIONARY_READING_ERROR(11),
15-
COMMAND_LINE_PARAMETER_ERROR(12);
15+
COMMAND_LINE_PARAMETER_ERROR(12),
16+
REMOVE_COMMENTS_ERROR(13);
1617

1718

1819

simitrieve/src/main/java/ml/paulobatista/simitrieve/error/ErrorHandler.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,10 @@ public static void errorInCMD(String parameter) {
6666
System.exit(Error.COMMAND_LINE_PARAMETER_ERROR.getCode());
6767
}
6868

69+
public static void removeCommentsError() {
70+
System.out.println("Unexpected error: Error while is removing comment from source code" );
71+
System.exit(Error.REMOVE_COMMENTS_ERROR.getCode());
72+
}
73+
6974

7075
}

simitrieve/src/main/java/ml/paulobatista/simitrieve/filter/CommentRemover.java

Lines changed: 63 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -51,45 +51,48 @@ public List<String> removePythonComments(List<String> sourceCode) {
5151
String patternComment_2 = ".*\"\"\".*";
5252
String inLineComment_2 = ".*'''.*'''.*";
5353
String inLineComment_3 = ".*\"\"\".*\"\"\".*";
54+
try {
55+
for (int index = 0; index < sizeOfCode; index++) {
56+
codeLine = sourceCode.get(index);
57+
58+
if (codeLine.matches(inLineComment_1)) {
59+
codeLine = codeLine.replaceAll("#.*", "");
60+
filtered.add(codeLine);
61+
} else if (codeLine.matches(inLineComment_2)) {
62+
codeLine = codeLine.replaceAll("'''.*'''", "");
63+
filtered.add(codeLine);
64+
} else if (codeLine.matches(inLineComment_3)) {
65+
codeLine = codeLine.replaceAll("\"\"\".*\"\"\"", "");
66+
filtered.add(codeLine);
67+
} else if (codeLine.matches(patternComment_1)) {
68+
codeLine = codeLine.replaceAll("'''.*", "");
69+
filtered.add(codeLine);
70+
71+
while (!codeLine.matches(patternComment_1) && index < sizeOfCode) {
72+
codeLine = sourceCode.get(index);
73+
index++;
74+
}
5475

55-
for (int index = 0; index < sizeOfCode; index++) {
56-
codeLine = sourceCode.get(index);
57-
58-
if (codeLine.matches(inLineComment_1)) {
59-
codeLine = codeLine.replaceAll("#.*", "");
60-
filtered.add(codeLine);
61-
} else if (codeLine.matches(inLineComment_2)) {
62-
codeLine = codeLine.replaceAll("'''.*'''", "");
63-
filtered.add(codeLine);
64-
} else if (codeLine.matches(inLineComment_3)) {
65-
codeLine = codeLine.replaceAll("\"\"\".*\"\"\"", "");
66-
filtered.add(codeLine);
67-
} else if (codeLine.matches(patternComment_1)) {
68-
codeLine = codeLine.replaceAll("'''.*", "");
69-
filtered.add(codeLine);
70-
71-
while (!codeLine.matches(patternComment_1)) {
72-
index++;
73-
codeLine = sourceCode.get(index);
74-
}
75-
76-
codeLine = codeLine.replaceAll(".*'''", "");
77-
filtered.add(codeLine);
78-
} else if (codeLine.matches(patternComment_2)) {
79-
codeLine = codeLine.replaceAll("\"\"\".*", "");
80-
filtered.add(codeLine);
76+
codeLine = codeLine.replaceAll(".*'''", "");
77+
filtered.add(codeLine);
78+
} else if (codeLine.matches(patternComment_2)) {
79+
codeLine = codeLine.replaceAll("\"\"\".*", "");
80+
filtered.add(codeLine);
8181

82-
while (!codeLine.matches(patternComment_2)) {
83-
index++;
84-
codeLine = sourceCode.get(index);
85-
}
82+
while (!codeLine.matches(patternComment_2) && index < sizeOfCode) {
83+
codeLine = sourceCode.get(index);
84+
index++;
85+
}
8686

87-
codeLine = codeLine.replaceAll(".*\"\"\"", "");
87+
codeLine = codeLine.replaceAll(".*\"\"\"", "");
8888

89-
filtered.add(codeLine);
90-
} else {
91-
filtered.add(codeLine);
89+
filtered.add(codeLine);
90+
} else {
91+
filtered.add(codeLine);
92+
}
9293
}
94+
} catch (Exception e) {
95+
e.getMessage();
9396
}
9497

9598
return filtered;
@@ -141,38 +144,51 @@ public List<String> removeJavascriptComments(List<String> sourceCode) {
141144

142145
private List<String> removeCommentJavaCppJavascriptPattern(List<String> sourceCode) {
143146
List<String> filtered = null;
147+
filtered = new ArrayList<>();
144148
try {
145-
filtered = new ArrayList<>();
149+
146150
for (int i = 0; i < sourceCode.size(); i++) {
147151
String line = sourceCode.get(i);
148152
if (line.matches(".*//.*")) {
149-
line = line.split("//")[0];
153+
if (line.split("//") != null) {
154+
line = line.split("//")[0];
155+
}
156+
150157
} else if (line.matches(".+/\\*.*\\*/.+")) {
151-
line = line.split("/\\*.*\\*/")[0] + " " + line.split("/\\*.*\\*/")[1];
158+
if (line.split("/\\*.*\\*/")[0] != null && line.split("/\\*.*\\*/")[1] != null) {
159+
line = line.split("/\\*.*\\*/")[0] + " " + line.split("/\\*.*\\*/")[1];
160+
}
161+
152162
} else if (line.matches("\\s*/\\*.*\\*/\\s*")) {
153163
line = "";
154164
} else if (line.matches(".+/\\*.*\\*/\\s*")) {
155-
line = line.split("/\\*.*\\*/\\s*")[0];
165+
if (line.split("/\\*.*\\*/\\s*")[0] != null) {
166+
line = line.split("/\\*.*\\*/\\s*")[0];
167+
}
168+
156169
} else if (line.matches(".*/\\*.*")) {
157-
while (!line.matches(".*\\*/.*")) {
158-
i++;
170+
while (!line.matches(".*\\*/.*") && i < sourceCode.size()) {
159171
line = sourceCode.get(i);
172+
i++;
160173
}
161-
if (line.matches(".*\\*/")) {
162-
line = "";
163-
} else if (line.matches(".*\\*/.+")) {
164-
line = line.split(".*\\*/")[0];
174+
if (line.matches(".*\\*/.+")) {
175+
if (line.split(".*\\*/")[1] != null) {
176+
line = line.split(".*\\*/")[1];
177+
}
165178
}
166179
}
167180
filtered.add(line);
168181
}
169182
} catch (Exception e) {
170-
System.out.println("In CommmentRemover:");
171-
System.out.println(e.getMessage());
183+
// System.out.println("In CommmentRemover:");
184+
// System.out.println(e.getCause());
185+
e.getStackTrace();
172186
// error threat
173187
}
174188

175-
// whether filtered equals null appoint an error.
189+
// if (filtered == null || filtered.isEmpty()) {
190+
// ErrorHandler.removeCommentsError();
191+
// }
176192
return filtered;
177193
}
178194
}

0 commit comments

Comments
 (0)