Skip to content

Commit cbc0f56

Browse files
Initial version (with small improvements) (#2)
Co-authored-by: Alexander Staeding <alexanderstaeding@gmail.com>
1 parent 7718299 commit cbc0f56

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+6132
-1
lines changed

build.gradle.kts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import org.sourcegrade.submitter.submit
33
plugins {
44
java
55
application
6-
id("org.sourcegrade.style") version "1.2.0"
76
id("org.sourcegrade.submitter") version "0.4.0"
87
}
98

@@ -19,6 +18,7 @@ submit {
1918
studentId = "ab12cdef"
2019
firstName = "sol_first"
2120
lastName = "sol_last"
21+
requireTests = false
2222
}
2323

2424
val grader: SourceSet by sourceSets.creating {
@@ -32,6 +32,9 @@ dependencies {
3232
"graderCompileOnly"("org.sourcegrade:jagr-launcher:0.4.0") {
3333
exclude("org.jetbrains", "annotations")
3434
}
35+
"graderImplementation"("fr.inria.gforge.spoon:spoon-core:10.0.0")
36+
"graderImplementation"("org.mockito:mockito-core:4.3.1")
37+
"graderImplementation"("org.ow2.asm:asm-util:9.2")
3538
testImplementation("org.junit.jupiter:junit-jupiter:5.8.2")
3639
}
3740

graders

Whitespace-only changes.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package h08;
2+
3+
import org.jetbrains.annotations.Nullable;
4+
import org.objectweb.asm.ClassReader;
5+
import org.objectweb.asm.ClassVisitor;
6+
import org.objectweb.asm.ClassWriter;
7+
import org.objectweb.asm.MethodVisitor;
8+
import org.objectweb.asm.Opcodes;
9+
import org.sourcegrade.jagr.api.testing.ClassTransformer;
10+
11+
/**
12+
* verifier for h08.
13+
*/
14+
public class ExceptionConstructorVerifier implements ClassTransformer {
15+
16+
public static @Nullable String descriptor = null;
17+
public static @Nullable Boolean isVar2 = null;
18+
public static final String correctDescriptor = "(Ljava/util/Calendar;Z)V";
19+
20+
public static void handleConstructor(String descriptor, boolean correctConstructor) {
21+
ExceptionConstructorVerifier.descriptor = descriptor;
22+
ExceptionConstructorVerifier.isVar2 = correctConstructor;
23+
}
24+
25+
public static void handleConstructor(String descriptor) {
26+
ExceptionConstructorVerifier.descriptor = descriptor;
27+
isVar2 = null; // is incorrect and could not be determined
28+
}
29+
30+
public static void reset() {
31+
descriptor = null;
32+
isVar2 = null;
33+
}
34+
35+
@Override
36+
public String getName() {
37+
return null;
38+
}
39+
40+
@Override
41+
public void transform(ClassReader reader, ClassWriter writer) {
42+
if (reader.getClassName().equals("h08/BadUpdateTimeException")) {
43+
reader.accept(new CV(writer), 0);
44+
} else {
45+
reader.accept(writer, 0);
46+
}
47+
}
48+
49+
static class CV extends ClassVisitor {
50+
51+
public CV(ClassVisitor classVisitor) {
52+
super(Opcodes.ASM9, classVisitor);
53+
}
54+
55+
@Override
56+
public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
57+
if (name.equals("<init>")) {
58+
return new MV(super.visitMethod(access, name, descriptor, signature, exceptions), descriptor);
59+
}
60+
return super.visitMethod(access, name, descriptor, signature, exceptions);
61+
}
62+
63+
static class MV extends MethodVisitor {
64+
65+
final String descriptor;
66+
67+
public MV(MethodVisitor methodVisitor, String descriptor) {
68+
super(Opcodes.ASM9, methodVisitor);
69+
this.descriptor = descriptor;
70+
}
71+
72+
@Override
73+
public void visitCode() {
74+
visitLdcInsn(descriptor);
75+
final String handleConstructorDescriptor;
76+
if (descriptor.equals(correctDescriptor)) {
77+
// correct constructor
78+
visitVarInsn(Opcodes.ILOAD, 2);
79+
handleConstructorDescriptor = "(Ljava/lang/String;Z)V";
80+
} else {
81+
handleConstructorDescriptor = "(Ljava/lang/String;)V";
82+
}
83+
visitMethodInsn(
84+
Opcodes.INVOKESTATIC,
85+
"h08/ExceptionConstructorVerifier",
86+
"handleConstructor",
87+
handleConstructorDescriptor,
88+
false
89+
);
90+
super.visitCode();
91+
}
92+
}
93+
}
94+
}

0 commit comments

Comments
 (0)