-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeReview.java
More file actions
118 lines (102 loc) · 4.1 KB
/
CodeReview.java
File metadata and controls
118 lines (102 loc) · 4.1 KB
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
/**
* This utility will generate a code review report that conforms with the requirements for SER316
*
* The text file should be formatted with each flaw found as follows
*
* file1.java
* FIRST FLAW DESCRIPTION
* CG2 (2-3 characters to describe which violation from code standards chart)
* LOW (2-3 characters to describe importance)
*
* file2.java
* SECOND FLAW DESCRIPTION
* CG2 (2-3 characters to describe which violation from code standards chart
* LOW (2-3 characters to describe importance)
*
* ...
*
* @author Greg Ross
* @version 1.0
*/
import java.util.LinkedList;
import java.io.PrintWriter;
import java.io.File; // Import the File class
import java.io.FileNotFoundException; // Import this class to handle errors
import java.util.Scanner; // Import the Scanner class to read text files
public class CodeReview{
/**
* Stores all the information about each defect
*/
public static class Defect{
int id;
String fileName;
int lineNumber;
String description;
String category;
String severity;
public Defect(int IDNUM, String fNAME, int lineNUM, String desc, String cat, String sev){
id=IDNUM;
fileName=fNAME;
lineNumber=lineNUM;
description=desc;
category=cat;
severity=sev;
}
}
/**
* Main method, input parameter is name of file
* @param args[0] Name of file to read
*/
public static void main(String[] args){
int id=0;
String fileName="";
int lineNumber=0;
String description="";
String category="";
String severity="";
LinkedList<Defect> defectList = new LinkedList<Defect>();
// Read Flaws Document
try{
Scanner in=new Scanner ( new File (args[0]) );
// Go through document 1 line at a time.
while (in.hasNextLine()) {
id++;
fileName=in.nextLine();
lineNumber=Integer.parseInt(in.nextLine());
description=in.nextLine();
category=in.nextLine();
severity = in.nextLine();
defectList.add(new Defect( id, fileName, lineNumber, description, category, severity));
if (in.hasNextLine()) in.nextLine();
}
in.close();
} catch (Exception e){
System.out.println("Could not open "+args[0]);
e.printStackTrace();
}
try{
PrintWriter out= new PrintWriter( args[0]+".md" );
// Output to file
// HEADER
out.printf("``` \n"); //Markdown mark for code to prevent md default formatting
out.printf("%15s %20s %37s %20s \n\n", " ", "____________________", " Code Review Defect List ", "____________________");
out.printf("Reviewer: REVIEWER NAME \t\t\t GH Repo: https://github.com/amehlhase316/Aachen-2\n\n");
// ID Location Problem Description Problem
out.printf("%-10s %-20s %-45s %-20s\n", "ID", " Location", " Problem Description", " Problem");
// ID# FileName LineNumber Description ProblemCategory ProblemSeverity
out.printf("%3s %26s|%-9s %-60s %8s|%-8s\n", "ID#", "fileName", "lineNum", "*Description of the Problem*","category","severity");
out.printf("=== ==========================|========= ============================================================ ======== ========\n");
String rowFormat="%3d %26s Line %-3d %-60s %7s | %7s\n";
// Loop for each flaw
for( Defect defect:defectList){
out.printf(rowFormat, defect.id, defect.fileName, defect.lineNumber, defect.description, defect.category, defect.severity);
}
//Markdown mark for code to prevent md default formatting
out.printf("```");
// Close File
out.close();
} catch (Exception e){ // File failed to be created
e.printStackTrace();
}
} // End of main method
} // End Class Code Review