You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .claude/commands/jspecify-annotate.md
+68-1Lines changed: 68 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,14 @@ Note that JSpecify is already used in this repository so it's already imported.
4
4
5
5
If you see a builder static class, you can label it `@NullUnmarked` and not need to do anymore for this static class in terms of annotations.
6
6
7
+
## Batch Size and Prioritization
8
+
9
+
Annotate approximately 10 classes per batch for optimal context management. Start with interface/simple classes first, then tackle complex classes with builders. This helps identify patterns early.
10
+
11
+
## Exploration Phase
12
+
13
+
Before annotating, use `grep` to search for how each class is instantiated (e.g., `grep -r "new Comment"`) to understand which parameters can be null. Check constructor calls, method returns, and field assignments to inform your nullability decisions.
14
+
7
15
Analyze this Java class and add JSpecify annotations based on:
8
16
1. Set the class to be `@NullMarked`
9
17
2. Remove all the redundant `@NonNull` annotations that IntelliJ added
@@ -14,14 +22,73 @@ Analyze this Java class and add JSpecify annotations based on:
14
22
15
23
IntelliJ's infer nullity code analysis isn't comprehensive so feel free to make corrections.
16
24
25
+
## Pattern Examples
26
+
27
+
Here are concrete examples of common annotation patterns:
public @NullableSourceLocationgetSourceLocation() {
52
+
return sourceLocation;
53
+
}
54
+
}
55
+
```
56
+
57
+
**Class with nullable return type:**
58
+
```java
59
+
@PublicApi
60
+
@NullMarked
61
+
publicclassContainer {
62
+
public @NullableNodegetChildOrNull(Stringkey) {
63
+
// May return null
64
+
return children.get(key);
65
+
}
66
+
}
67
+
```
68
+
69
+
**Builder with @NullUnmarked:**
70
+
```java
71
+
@PublicApi
72
+
@NullMarked
73
+
publicclassMyClass {
74
+
@NullUnmarked
75
+
publicstaticclassBuilder {
76
+
// No further annotations needed in builder
77
+
}
78
+
}
79
+
```
80
+
17
81
## GraphQL Specification Compliance
18
82
This is a GraphQL implementation. When determining nullability, consult the GraphQL specification (https://spec.graphql.org/draft/) for the relevant concept. Key principles:
19
83
20
84
The spec defines which elements are required (non-null) vs optional (nullable). Look for keywords like "MUST" to indicate when an element is required, and conditional words such as "IF" to indicate when an element is optional.
21
85
22
86
If a class implements or represents a GraphQL specification concept, prioritize the spec's nullability requirements over what IntelliJ inferred.
23
87
24
-
## How to validate
88
+
## Validation Strategy
89
+
90
+
Run `./gradlew compileJava` after every 3-5 classes annotated, not just at the end. This catches issues early and makes debugging easier.
91
+
25
92
Finally, please check all this works by running the NullAway compile check.
26
93
27
94
If you find NullAway errors, try and make the smallest possible change to fix them. If you must, you can use assertNotNull. Make sure to include a message as well.
0 commit comments