-
Notifications
You must be signed in to change notification settings - Fork 0
/
EmptyMethodInspection.java
57 lines (50 loc) · 1.55 KB
/
EmptyMethodInspection.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
package org.scanl.plugins.tsdetect.inspections;
import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.psi.*;
import org.jetbrains.annotations.NotNull;
import org.scanl.plugins.tsdetect.model.SmellType;
import org.scanl.plugins.tsdetect.quickfixes.QuickFixComment;
import org.scanl.plugins.tsdetect.quickfixes.QuickFixRemove;
import java.util.Objects;
/**
* Empty Method Inspection
* Looks for test methods that are empty
*/
public class EmptyMethodInspection extends SmellInspection{
@Override
public @NotNull PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) {
return new JavaElementVisitor() {
@Override
public void visitMethod(PsiMethod method) {
if (method.getBody() == null)
return;
if (hasSmell(method))
holder.registerProblem(method, getDescription(),
new QuickFixRemove(getResourceName("FIX.REMOVE")),
new QuickFixComment(getResourceName("FIX.COMMENT")));
}
};
}
/**
* Determines if the PSI Method is empty or not
* @param element the method being looked for to see if it has smells
* @return if the PSI Method is empty or not
*/
@Override
public boolean hasSmell(PsiElement element) {
if (!shouldTestElement(element)) return false;
if(element instanceof PsiMethod) {
PsiMethod method = (PsiMethod) element;
return Objects.requireNonNull(method.getBody()).isEmpty();
}
return false;
}
/**
* Gets the matching smell type enum
* @return The Smell Type Enum
*/
@Override
public SmellType getSmellType() {
return SmellType.EMPTY_TEST;
}
}