JetBrains / JetBrains/java-annotations

Advanced @Contract capabilities

オープン
#30 コメント 3 件 リアクション 3 件 担当者 0 名 GitHub で見る
主要言語
Kotlin
スター
463
フォーク
72
PR マージ指標
30日以内にマージされた PR はありません

説明

I was thinking about possible extra possibilities for the `Contract` annotation.
I have this example already; I will add more as I stumble upon them:
Consider this method:
```java
@Contract("CacheReference -> param1; null -> fail; !null -> new")
protected abstract CacheReference advanceIntoCacheRef(Reference reference);
```
The method should do the following things; as described by the contract:
- Throw an NPE, if the parameter is `null`
- Wrap the parameter `Reference` (if not `instanceof CacheReference`, else see next) into a `CacheReference`
- Return first parameter if the first parameter is `instanceof CacheReference` (which is already imported due to return type; return types should be validated by `paramN`)

Now, obviously this contract won't work, because it doesn't know about more things than nulls; really. Given other capabilities of IntelliJ, it should be fairly easy coming up with a simple, standalone concept for advanced `Contract` syntax.

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。