Skip to content

Instantly share code, notes, and snippets.

@DylanLukes DylanLukes/AnnotationTests.kt Secret
Last active May 15, 2019

Embed
What would you like to do?
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)
}
}
}
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"
}
}
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.
}
}
// empty currently
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
You can’t perform that action at this time.