diff --git a/build.gradle.kts b/build.gradle.kts index f864eb1..0ef0bdc 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ plugins { } subprojects { group = "com.github.cs125-illinois.questioner" - version = "2022.10.1" + version = "2022.10.2" tasks.withType { kotlinOptions { jvmTarget = JavaVersion.VERSION_17.toString() diff --git a/lib/src/test/kotlin/TestValidation.kt b/lib/src/test/kotlin/TestValidation.kt index 7aabfac..de85b4b 100644 --- a/lib/src/test/kotlin/TestValidation.kt +++ b/lib/src/test/kotlin/TestValidation.kt @@ -57,4 +57,44 @@ class TestValidation : StringSpec({ report!!.requiredTestCount shouldBeGreaterThan 0 } } + "constructor @NotNull should work" { + validator.validate("Test Constructor NotNull", force = true, testing = true) + .also { (question, report) -> + question.validated shouldBe true + report shouldNotBe null + report!!.requiredTestCount shouldBeGreaterThan 0 + } + } + "empty constructor should work" { + validator.validate("Test Empty Constructor", force = true, testing = true) + .also { (question, report) -> + question.validated shouldBe true + report shouldNotBe null + report!!.requiredTestCount shouldBeGreaterThan 0 + } + } + "feature checks should work" { + validator.validate("With Feature Check", force = true, testing = true) + .also { (question, report) -> + question.validated shouldBe true + report shouldNotBe null + report!!.requiredTestCount shouldBeGreaterThan 0 + } + } + "getters and setters should work" { + validator.validate("Classroom Getters and Setters", force = true, testing = true) + .also { (question, report) -> + question.validated shouldBe true + report shouldNotBe null + report!!.requiredTestCount shouldBeGreaterThan 0 + } + } + "template imports should work" { + validator.validate("With Template Imports", force = true, testing = true) + .also { (question, report) -> + question.validated shouldBe true + report shouldNotBe null + report!!.requiredTestCount shouldBeGreaterThan 0 + } + } }) \ No newline at end of file diff --git a/lib/src/test/resources/questions.json b/lib/src/test/resources/questions.json index a7fab6e..b5dd99f 100644 --- a/lib/src/test/resources/questions.json +++ b/lib/src/test/resources/questions.json @@ -2547,6 +2547,124 @@ }, "fauxStatic": false }, + "Test Constructor NotNull": { + "name": "Test Constructor NotNull", + "type": "KLASS", + "klass": "Question", + "metadata": { + "contentHash": "5cdd4a7677f73f34f915e08ec0f5f11b", + "packageName": "com.examples.withconstructornotnull", + "version": "2022.10.0", + "author": "challen@illinois.edu", + "javaDescription": "

Testing @NotNull annotation on constructor parameters.

", + "usedFiles": [], + "templateImports": [], + "focused": true + }, + "annotatedControls": {}, + "question": { + "klass": "Question", + "contents": "import edu.illinois.cs.cs125.jenisol.core.NotNull;\nimport edu.illinois.cs.cs125.questioner.lib.Correct;\n\n/*\n * Testing @NotNull annotation on constructor parameters.\n */\n\n@Correct(name = \"Test Constructor NotNull\", version = \"2022.10.0\", author = \"challen@illinois.edu\", focused = true)\npublic class Question {\n private final int stringLength;\n\n public Question(@NotNull String value) {\n stringLength = value.length();\n }\n\n public int getStringLength() {\n return stringLength;\n }\n}", + "language": "java", + "path": "/Users/challen/code/questioner-problems/src/main/java/com/examples/withconstructornotnull/Question.java" + }, + "correct": { + "klass": "Question", + "contents": "public class Question {\n private final int stringLength;\n\n public Question(String value) {\n stringLength = value.length();\n }\n\n public int getStringLength() {\n return stringLength;\n }\n}\n", + "language": "java", + "path": "/Users/challen/code/questioner-problems/src/main/java/com/examples/withconstructornotnull/Question.java", + "complexity": 2, + "features": { + "featureMap": { + "VARIABLE_REASSIGNMENTS": 1, + "METHOD": 1, + "RETURN": 1, + "CONSTRUCTOR": 1, + "GETTER": 1, + "STRING": 1, + "CLASS": 1, + "VISIBILITY_MODIFIERS": 4, + "FINAL_FIELD": 1, + "DOT_NOTATION": 1, + "DOTTED_METHOD_CALL": 1 + }, + "importList": [], + "typeList": [ + "int", + "String" + ], + "identifierList": [], + "dottedMethodList": [ + "length" + ] + }, + "lineCount": { + "source": 9, + "comment": 0, + "blank": 3 + }, + "expectedDeadCount": 0 + }, + "alternativeSolutions": [], + "incorrect": [], + "common": [], + "importWhitelist": [], + "importBlacklist": [], + "slug": "test-constructor-notnull", + "hasKotlin": false, + "published": { + "name": "Test Constructor NotNull", + "type": "KLASS", + "path": "test-constructor-notnull", + "author": "challen@illinois.edu", + "version": "2022.10.0", + "packageName": "com.examples.withconstructornotnull", + "languages": [ + "java" + ], + "descriptions": { + "java": "

Testing @NotNull annotation on constructor parameters.

" + }, + "complexity": { + "java": 2 + }, + "features": { + "java": { + "featureMap": { + "VARIABLE_REASSIGNMENTS": 1, + "METHOD": 1, + "RETURN": 1, + "CONSTRUCTOR": 1, + "GETTER": 1, + "STRING": 1, + "CLASS": 1, + "VISIBILITY_MODIFIERS": 4, + "FINAL_FIELD": 1, + "DOT_NOTATION": 1, + "DOTTED_METHOD_CALL": 1 + }, + "importList": [], + "typeList": [ + "int", + "String" + ], + "identifierList": [], + "dottedMethodList": [ + "length" + ] + } + }, + "lineCounts": { + "java": { + "source": 9, + "comment": 0, + "blank": 3 + } + }, + "templateImports": [] + }, + "fauxStatic": false + }, "With Imports": { "name": "With Imports", "type": "KLASS", diff --git a/plugin/src/main/kotlin/save/ParseJava.kt b/plugin/src/main/kotlin/save/ParseJava.kt index 921fb22..8958717 100644 --- a/plugin/src/main/kotlin/save/ParseJava.kt +++ b/plugin/src/main/kotlin/save/ParseJava.kt @@ -540,6 +540,15 @@ $cleanContent } } } + classBodyDeclaration.memberDeclaration()?.constructorDeclaration()?.also { constructorDeclaration -> + constructorDeclaration.formalParameters()?.formalParameterList()?.formalParameter()?.forEach { parameters -> + parameters.variableModifier().mapNotNull { it.annotation() }.forEach { annotation -> + if (annotation.qualifiedName()?.asString()!! in annotationsToSnip) { + toSnip.add(annotation.start.startIndex..annotation.stop.stopIndex) + } + } + } + } } return@runBlocking contents diff --git a/server/src/main/resources/edu.illinois.cs.cs125.questioner.server.version b/server/src/main/resources/edu.illinois.cs.cs125.questioner.server.version index 2e60882..ead55ee 100644 --- a/server/src/main/resources/edu.illinois.cs.cs125.questioner.server.version +++ b/server/src/main/resources/edu.illinois.cs.cs125.questioner.server.version @@ -1 +1 @@ -version=2022.10.1 \ No newline at end of file +version=2022.10.2 \ No newline at end of file