Skip to content

Commit

Permalink
skip default case in throws documented check #489
Browse files Browse the repository at this point in the history
  • Loading branch information
Luro02 committed May 16, 2024
1 parent 2b15e2c commit 97adfa6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import de.firemage.autograder.core.integrated.IntegratedCheck;
import de.firemage.autograder.core.integrated.SpoonUtil;
import de.firemage.autograder.core.integrated.StaticAnalysis;
import spoon.reflect.code.CtAbstractSwitch;
import spoon.reflect.code.CtCase;
import spoon.reflect.code.CtConstructorCall;
import spoon.reflect.code.CtJavaDoc;
import spoon.reflect.code.CtJavaDocTag;
Expand Down Expand Up @@ -39,6 +41,12 @@ private void checkCtExecutable(CtExecutable<?> ctExecutable) {
List<CtThrow> ctThrows = ctExecutable.filterChildren(CtThrow.class::isInstance)
.map(CtThrow.class::cast).list();
for (CtThrow ctThrow : ctThrows) {
CtCase<?> ctParentCase = ctThrow.getParent(CtCase.class);
// skip default cases in switch statements
if (ctParentCase != null && ctParentCase.getCaseExpressions().isEmpty()) {
continue;
}

if (ctThrow.getThrownExpression() instanceof CtConstructorCall<?> ctConstructorCall) {
String name = ctConstructorCall.getType().getSimpleName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,17 @@ private static void b() {
public static void c() {
throw new IllegalArgumentException("Error"); /*# ok #*/
}

/**
* Does some things
*/
public static void doesSomething(String foo) {
switch (foo) {
case "a":
System.out.println("a");
break;
default:
throw new IllegalArgumentException("Error"); /*# ok #*/
}
}
}

0 comments on commit 97adfa6

Please sign in to comment.