-
Notifications
You must be signed in to change notification settings - Fork 0
/
MaximusIudex.java
103 lines (92 loc) · 3.8 KB
/
MaximusIudex.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
package edu.vtc.guppitus;
import com.sun.istack.internal.NotNull;
import java.lang.reflect.Method;
/**
* Checks given class for annotated reviewed methods that have been marked with specified problems.
* Created by Seth Lunn on 6/6/2017.
*/
class MaximusIudex {
/**
* Checks class for reviewed methods or nested classes that have specified problems.
* @param className The name of the class being checked
* @param problems list of specified problems
*/
static void censorCheck(@NotNull String className, @NotNull String[] problems)
{
try {
//TODO improve pkg handling
Class reflectClass = Class.forName("edu.vtc.guppitus." + className);
System.out.println("Class " + reflectClass.getName() + "found.");
//If class has not been reviewed, then check for reviewed methods and nested classes
if (!reflectClass.isAnnotationPresent(Censor.class)) {
checkMethods(reflectClass, problems);
checkNestedClasses(reflectClass, problems);
}
} catch (ClassNotFoundException ex) {
System.out.println(ex.toString());
}
}
/**
* checks methods within a class for reviewed status.
* @param reflectedClass the class containing methods to be checked for annotation
* @param problems list of problems being checked for.
*/
private static void checkMethods(@NotNull Class reflectedClass, @NotNull String[] problems)
{
Method[] classMethods = reflectedClass.getMethods();
for (Method method : classMethods) {
if (method.isAnnotationPresent(Censor.class)){
checkProblems(method, problems);
}
if (method.isAnnotationPresent(Censors.class)) {
checkProblemsRepeat(method, problems);
}
}
}
/**
* checks the annotation for list of problems. If the method is marked with matching problems, a string is printed.
* @param reviews the method being checked
* @param problems problems being checked
*/
private static void checkProblems(@NotNull Method reviews, @NotNull String[] problems)
{
Censor annot = reviews.getAnnotation(Censor.class);
for(Problems problem: annot.reviewedProblems()){
for(String name : problems) {
if (problem.toString().equalsIgnoreCase(name)) {
System.out.println(reviews.getName()+" has a " + problem.toString() + " problem.");
}
}
}
}
/**
* checks the annotation for list of problems. If the method is marked with matching problems, a string is printed.
* @param reviews the method being checked
* @param problems problems being checked
*/
private static void checkProblemsRepeat(@NotNull Method reviews, @NotNull String[] problems)
{
Censors annot = reviews.getAnnotation(Censors.class);
for(Censor review : annot.value()){
for(Problems problem: review.reviewedProblems()){
for(String name : problems) {
if (problem.toString().equalsIgnoreCase(name)) {
System.out.println(reviews.getName()+" has a " + problem.toString() + " problem.");
}
}
}
}
}
/**
* Checks nested class for matching problems in review annotation
* @param reflectedClass the parent class
* @param problems the list of problems being checked for.
*/
private static void checkNestedClasses(@NotNull Class reflectedClass, @NotNull String[] problems)
{
Class[] classClasses = reflectedClass.getDeclaredClasses();
for (Class classy : classClasses) {
checkMethods(classy, problems);
}
}
}