-
-
Save DylanLukes/8c498e7bfa2f198aa8e39afa2432ed64 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package edu.ucsd.dylukes.covenant | |
import edu.ucsd.dylukes.covenant.annotations.Requires | |
import org.junit.jupiter.api.Test | |
import org.junit.jupiter.api.assertThrows | |
import java.lang.RuntimeException | |
@Requires("n >= 0") | |
fun repeatChar(n: Int, c: Char = 'x') { | |
var s = "" | |
for (i in 1..n) { | |
s += c | |
} | |
} | |
class AnnotationTests { | |
@Test | |
fun `Simple annotations work`() { | |
assertThrows<RuntimeException> { | |
repeatChar(-1) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugins { | |
id 'org.jetbrains.kotlin.jvm' version '1.3.31' | |
id 'org.jetbrains.kotlin.kapt' version '1.3.31' | |
} | |
allprojects { | |
apply plugin: 'kotlin' | |
group 'edu.ucsd.dylukes' | |
version '1.0-SNAPSHOT' | |
repositories { | |
mavenCentral() | |
} | |
dependencies { | |
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" | |
} | |
compileKotlin { | |
kotlinOptions.jvmTarget = "1.8" | |
} | |
compileTestKotlin { | |
kotlinOptions.jvmTarget = "1.8" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package edu.ucsd.dylukes.covenant | |
import javax.annotation.processing.* | |
import javax.lang.model.SourceVersion | |
import javax.lang.model.element.TypeElement | |
@MustBeDocumented | |
@Target( | |
AnnotationTarget.FUNCTION, | |
AnnotationTarget.CONSTRUCTOR, | |
AnnotationTarget.PROPERTY_GETTER, | |
AnnotationTarget.PROPERTY_SETTER | |
) | |
@Retention(AnnotationRetention.RUNTIME) | |
annotation class Requires(vararg val predicates: String) | |
@MustBeDocumented | |
@Target( | |
AnnotationTarget.FUNCTION, | |
AnnotationTarget.CONSTRUCTOR, | |
AnnotationTarget.PROPERTY_GETTER, | |
AnnotationTarget.PROPERTY_SETTER | |
) | |
@Retention(AnnotationRetention.RUNTIME) | |
annotation class Ensures(vararg val predicates: String) | |
@MustBeDocumented | |
@Target(AnnotationTarget.CLASS) | |
@Retention(AnnotationRetention.RUNTIME) | |
annotation class Invariant(vararg val predicates: String) | |
@SupportedSourceVersion(SourceVersion.RELEASE_8) | |
@SupportedAnnotationTypes( | |
"edu.ucsd.dylukes.covenant.Requires", | |
"edu.ucsd.dylukes.covenant.Ensures", | |
"edu.ucsd.dylukes.covenant.Invariant" | |
) | |
class ContractAnnotationProcessor : AbstractProcessor() { | |
override fun init(processingEnv: ProcessingEnvironment?) { | |
super.init(processingEnv) | |
println("HELLO WORLD") | |
} | |
override fun process(annotations: MutableSet<out TypeElement>?, roundEnv: RoundEnvironment?): Boolean { | |
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// empty currently |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'kotlin-kapt' | |
dependencies { | |
testImplementation project(':core') | |
kaptTest project(':core') | |
testImplementation "org.junit.jupiter:junit-jupiter-api:5.5.0-M1" | |
testRuntime "org.junit.jupiter:junit-jupiter-engine:5.5.0-M1" | |
} | |
tasks { | |
test { | |
useJUnitPlatform() | |
} | |
} | |
kapt { | |
includeCompileClasspath = false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment