Skip to content

Commit 2c84d07

Browse files
authored
CORDA-704: Implement @DoNotImplement annotation (corda#1903)
* Enhance the API Scanner plugin to monitor class annotations. * Implement @DoNotImplement annotation, and apply it. * Update API definition. * Update API change detection to handle @DoNotImplement. * Document the `@DoNotImplement` annotation.
1 parent 3dd09fd commit 2c84d07

File tree

29 files changed

+402
-266
lines changed

29 files changed

+402
-266
lines changed

.ci/api-current.txt

Lines changed: 255 additions & 253 deletions
Large diffs are not rendered by default.

.ci/check-api-changes.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,15 @@ if [ $removalCount -gt 0 ]; then
3030
fi
3131

3232
# Adding new abstract methods could also break the API.
33-
newAbstracts=$(echo "$diffContents" | grep "^+" | grep "\(public\|protected\) abstract")
33+
# However, first exclude anything with the @DoNotImplement annotation.
34+
35+
function forUserImpl() {
36+
awk '/DoNotImplement/,/^##/{ next }{ print }' $1
37+
}
38+
39+
userDiffContents=`diff -u <(forUserImpl $apiCurrent) <(forUserImpl $APIHOME/../build/api/api-corda-*.txt) | tail --lines=+3`
40+
41+
newAbstracts=$(echo "$userDiffContents" | grep "^+" | grep "\(public\|protected\) abstract")
3442
abstractCount=`grep -v "^$" <<EOF | wc -l
3543
$newAbstracts
3644
EOF

client/rpc/src/main/kotlin/net/corda/client/rpc/RPCConnection.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package net.corda.client.rpc
22

3+
import net.corda.core.DoNotImplement
34
import net.corda.core.messaging.RPCOps
45
import java.io.Closeable
56

@@ -10,6 +11,7 @@ import java.io.Closeable
1011
* [Closeable.close] may be used to shut down the connection and release associated resources. It is an
1112
* alias for [notifyServerAndClose].
1213
*/
14+
@DoNotImplement
1315
interface RPCConnection<out I : RPCOps> : Closeable {
1416
/**
1517
* Holds a synthetic class that automatically forwards method calls to the server, and returns the response.

constants.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
gradlePluginsVersion=2.0.5
1+
gradlePluginsVersion=2.0.6
22
kotlinVersion=1.1.50
33
guavaVersion=21.0
44
bouncycastleVersion=1.57
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package net.corda.core
2+
3+
import java.lang.annotation.Inherited
4+
5+
/**
6+
* This annotation is for interfaces and abstract classes that provide Corda functionality
7+
* to user applications. Future versions of Corda may add new methods to such interfaces and
8+
* classes, but will not remove or modify existing methods.
9+
*
10+
* Adding new methods does not break Corda's API compatibility guarantee because applications
11+
* should not implement or extend anything annotated with [DoNotImplement]. These classes are
12+
* only meant to be implemented by Corda itself.
13+
*/
14+
@Retention(AnnotationRetention.BINARY)
15+
@Target(AnnotationTarget.CLASS)
16+
@MustBeDocumented
17+
@Inherited
18+
annotation class DoNotImplement

core/src/main/kotlin/net/corda/core/cordapp/Cordapp.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package net.corda.core.cordapp
22

3+
import net.corda.core.DoNotImplement
34
import net.corda.core.flows.FlowLogic
45
import net.corda.core.schemas.MappedSchema
56
import net.corda.core.serialization.SerializationWhitelist
@@ -17,13 +18,14 @@ import java.net.URL
1718
* @property contractClassNames List of contracts
1819
* @property initiatedFlows List of initiatable flow classes
1920
* @property rpcFlows List of RPC initiable flows classes
20-
* @property serviceFlows List of [CordaService] initiable flows classes
21+
* @property serviceFlows List of [net.corda.core.node.services.CordaService] initiable flows classes
2122
* @property schedulableFlows List of flows startable by the scheduler
22-
* @property servies List of RPC services
23+
* @property services List of RPC services
2324
* @property serializationWhitelists List of Corda plugin registries
2425
* @property customSchemas List of custom schemas
2526
* @property jarPath The path to the JAR for this CorDapp
2627
*/
28+
@DoNotImplement
2729
interface Cordapp {
2830
val name: String
2931
val contractClassNames: List<String>

core/src/main/kotlin/net/corda/core/cordapp/CordappProvider.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package net.corda.core.cordapp
22

3+
import net.corda.core.DoNotImplement
34
import net.corda.core.contracts.ContractClassName
45
import net.corda.core.node.services.AttachmentId
56

67
/**
78
* Provides access to what the node knows about loaded applications.
89
*/
10+
@DoNotImplement
911
interface CordappProvider {
1012
/**
1113
* Exposes the current CorDapp context which will contain information and configuration of the CorDapp that

core/src/main/kotlin/net/corda/core/flows/FlowLogicRef.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package net.corda.core.flows
22

3-
import net.corda.core.crypto.SecureHash
3+
import net.corda.core.DoNotImplement
44
import net.corda.core.serialization.CordaSerializable
55

66
/**
77
* The public factory interface for creating validated FlowLogicRef instances as part of the scheduling framework.
88
* Typically this would be used from within the nextScheduledActivity method of a QueryableState to specify
99
* the flow to run at the scheduled time.
1010
*/
11+
@DoNotImplement
1112
interface FlowLogicRefFactory {
1213
fun create(flowClass: Class<out FlowLogic<*>>, vararg args: Any?): FlowLogicRef
1314
}
@@ -24,4 +25,5 @@ class IllegalFlowLogicException(type: Class<*>, msg: String) : IllegalArgumentEx
2425
*/
2526
// TODO: align this with the existing [FlowRef] in the bank-side API (probably replace some of the API classes)
2627
@CordaSerializable
28+
@DoNotImplement
2729
interface FlowLogicRef

core/src/main/kotlin/net/corda/core/flows/FlowSession.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package net.corda.core.flows
22

33
import co.paralleluniverse.fibers.Suspendable
4+
import net.corda.core.DoNotImplement
45
import net.corda.core.identity.Party
56
import net.corda.core.utilities.UntrustworthyData
67

@@ -41,6 +42,7 @@ import net.corda.core.utilities.UntrustworthyData
4142
* will become
4243
* otherSideSession.send(something)
4344
*/
45+
@DoNotImplement
4446
abstract class FlowSession {
4547
/**
4648
* The [Party] on the other side of this session. In the case of a session created by [FlowLogic.initiateFlow]

core/src/main/kotlin/net/corda/core/identity/AbstractParty.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package net.corda.core.identity
22

3+
import net.corda.core.DoNotImplement
34
import net.corda.core.contracts.PartyAndReference
45
import net.corda.core.serialization.CordaSerializable
56
import net.corda.core.utilities.OpaqueBytes
@@ -10,6 +11,7 @@ import java.security.PublicKey
1011
* the party. In most cases [Party] or [AnonymousParty] should be used, depending on use-case.
1112
*/
1213
@CordaSerializable
14+
@DoNotImplement
1315
abstract class AbstractParty(val owningKey: PublicKey) {
1416
/** Anonymised parties do not include any detail apart from owning key, so equality is dependent solely on the key */
1517
override fun equals(other: Any?): Boolean = other === this || other is AbstractParty && other.owningKey == owningKey

0 commit comments

Comments
 (0)