Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Commit

Permalink
Fix constructor @NotNull.
Browse files Browse the repository at this point in the history
  • Loading branch information
gchallen committed Oct 8, 2022
1 parent bbd20fc commit a8135f4
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}
subprojects {
group = "com.github.cs125-illinois.questioner"
version = "2022.10.1"
version = "2022.10.2"
tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_17.toString()
Expand Down
40 changes: 40 additions & 0 deletions lib/src/test/kotlin/TestValidation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
})
118 changes: 118 additions & 0 deletions lib/src/test/resources/questions.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "[email protected]",
"javaDescription": "<p>Testing @NotNull annotation on constructor parameters.</p>",
"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 = \"[email protected]\", 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": "[email protected]",
"version": "2022.10.0",
"packageName": "com.examples.withconstructornotnull",
"languages": [
"java"
],
"descriptions": {
"java": "<p>Testing @NotNull annotation on constructor parameters.</p>"
},
"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",
Expand Down
9 changes: 9 additions & 0 deletions plugin/src/main/kotlin/save/ParseJava.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=2022.10.1
version=2022.10.2

0 comments on commit a8135f4

Please sign in to comment.