Skip to content

Commit 8caf50c

Browse files
committed
Introduce @Contract annotation
1 parent a3d2a2b commit 8caf50c

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

gradle/plugins/common/src/main/kotlin/junitbuild.java-nullability-conventions.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ tasks.withType<JavaCompile>().configureEach {
5454
enable()
5555
}
5656
isJSpecifyMode = true
57+
customContractAnnotations.add("org.junit.platform.commons.annotation.Contract")
58+
checkContracts = true
5759
}
5860
}
5961
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2015-2025 the original author or authors.
3+
*
4+
* All rights reserved. This program and the accompanying materials are
5+
* made available under the terms of the Eclipse Public License v2.0 which
6+
* accompanies this distribution and is available at
7+
*
8+
* https://www.eclipse.org/legal/epl-v20.html
9+
*/
10+
11+
package org.junit.platform.commons.annotation;
12+
13+
import static org.apiguardian.api.API.Status.INTERNAL;
14+
15+
import java.lang.annotation.Documented;
16+
import java.lang.annotation.ElementType;
17+
import java.lang.annotation.Target;
18+
19+
import org.apiguardian.api.API;
20+
21+
/**
22+
* Specifies some aspects of the annotated method's behavior to be used by tools
23+
* for data flow analysis.
24+
*
25+
* @since 6.0
26+
* @see <a href="https://github.com/JetBrains/java-annotations/blob/2a28eab73042023559d2ec4cd00d6779213b6425/src/jvmMain/java/org/jetbrains/annotations/Contract.java">org.jetbrains.annotations.Contract</a>
27+
* @see <a href="https://github.com/uber/NullAway/wiki/Configuration#custom-contract-annotations">NullAway custom contract annotations</a>
28+
*/
29+
@Documented
30+
@Target(ElementType.METHOD)
31+
@API(status = INTERNAL, since = "6.0")
32+
public @interface Contract {
33+
34+
/**
35+
* Contains the contract clauses describing causal relations between call
36+
* arguments and the returned value.
37+
*/
38+
String value();
39+
40+
}

0 commit comments

Comments
 (0)