Skip to content

Commit afb027a

Browse files
committed
Add JSpecify to spring-shell-core
Signed-off-by: Piotr Olaszewski <[email protected]>
1 parent 7220f1f commit afb027a

File tree

142 files changed

+1474
-897
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+1474
-897
lines changed

spring-shell-core/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@
6161
<artifactId>jakarta.validation-api</artifactId>
6262
<version>${jakarta.validation-api.version}</version>
6363
</dependency>
64+
<dependency>
65+
<groupId>org.jspecify</groupId>
66+
<artifactId>jspecify</artifactId>
67+
<version>${jspecify.version}</version>
68+
</dependency>
6469

6570
<!-- Test dependencies -->
6671
<dependency>

spring-shell-core/src/main/java/org/springframework/shell/Availability.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,21 @@
1616

1717
package org.springframework.shell;
1818

19+
import org.jspecify.annotations.Nullable;
1920
import org.springframework.util.Assert;
2021

2122
/**
2223
* Indicates whether or not a command is currently available. When not available, provides
2324
* a reason.
2425
*
2526
* @author Eric Bottard
27+
* @author Piotr Olaszewski
2628
*/
2729
public class Availability {
2830

29-
private final String reason;
31+
private final @Nullable String reason;
3032

31-
private Availability(String reason) {
33+
private Availability(@Nullable String reason) {
3234
this.reason = reason;
3335
}
3436

@@ -45,7 +47,7 @@ public boolean isAvailable() {
4547
return reason == null;
4648
}
4749

48-
public String getReason() {
50+
public @Nullable String getReason() {
4951
return reason;
5052
}
5153
}

spring-shell-core/src/main/java/org/springframework/shell/Command.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@
1818

1919
import java.util.Objects;
2020

21+
import org.jspecify.annotations.Nullable;
2122
import org.springframework.util.Assert;
2223
import org.springframework.util.StringUtils;
2324

25+
/**
26+
* @author Piotr Olaszewski
27+
*/
2428
public interface Command {
2529

2630
/**
@@ -45,10 +49,10 @@ public Help(String description) {
4549
this(description, null);
4650
}
4751

48-
public Help(String description, String group) {
49-
this.group = StringUtils.hasText(group) ? group : "";
50-
Assert.isTrue(StringUtils.hasText(description), "Command description cannot be null or empty in group='" + this.group + "'");
52+
public Help(String description, @Nullable String group) {
53+
Assert.isTrue(StringUtils.hasText(description), "Command description cannot be null or empty");
5154
this.description = description;
55+
this.group = StringUtils.hasText(group) ? group : "";
5256
}
5357

5458
public String getDescription() {

spring-shell-core/src/main/java/org/springframework/shell/CommandNotFound.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,25 @@
2020
import java.util.Map;
2121
import java.util.stream.Collectors;
2222

23+
import org.jspecify.annotations.Nullable;
2324
import org.springframework.shell.command.CommandRegistration;
2425

2526
/**
2627
* A result to be handled by the {@link ResultHandler} when no command could be mapped to user input
28+
*
29+
* @author Piotr Olaszewski
2730
*/
2831
public class CommandNotFound extends RuntimeException {
2932

3033
private final List<String> words;
31-
private final Map<String, CommandRegistration> registrations;
32-
private final String text;
34+
private final @Nullable Map<String, CommandRegistration> registrations;
35+
private final @Nullable String text;
3336

3437
public CommandNotFound(List<String> words) {
3538
this(words, null, null);
3639
}
3740

38-
public CommandNotFound(List<String> words, Map<String, CommandRegistration> registrations, String text) {
41+
public CommandNotFound(List<String> words, @Nullable Map<String, CommandRegistration> registrations, @Nullable String text) {
3942
this.words = words;
4043
this.registrations = registrations;
4144
this.text = text;
@@ -60,7 +63,7 @@ public List<String> getWords(){
6063
*
6164
* @return known command registrations
6265
*/
63-
public Map<String, CommandRegistration> getRegistrations() {
66+
public @Nullable Map<String, CommandRegistration> getRegistrations() {
6467
return registrations;
6568
}
6669

@@ -69,7 +72,7 @@ public Map<String, CommandRegistration> getRegistrations() {
6972
*
7073
* @return raw text input
7174
*/
72-
public String getText() {
75+
public @Nullable String getText() {
7376
return text;
7477
}
7578
}

spring-shell-core/src/main/java/org/springframework/shell/CompletingParsedLine.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@
2424
* should be escaped/quoted.
2525
*
2626
* @author Eric Bottard
27+
* @author Piotr Olaszewski
2728
*/
2829
@FunctionalInterface
2930
public interface CompletingParsedLine {
3031

31-
public CharSequence emit(CharSequence candidate);
32+
CharSequence emit(CharSequence candidate);
3233
}

spring-shell-core/src/main/java/org/springframework/shell/CompletionContext.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,19 @@
1616

1717
package org.springframework.shell;
1818

19+
import org.jspecify.annotations.Nullable;
20+
import org.springframework.shell.command.CommandOption;
21+
import org.springframework.shell.command.CommandRegistration;
22+
1923
import java.util.ArrayList;
2024
import java.util.List;
2125
import java.util.stream.Collectors;
2226

23-
import org.springframework.shell.command.CommandOption;
24-
import org.springframework.shell.command.CommandRegistration;
25-
2627
/**
2728
* Represents the buffer context in which completion was triggered.
2829
*
2930
* @author Eric Bottard
31+
* @author Piotr Olaszewski
3032
*/
3133
public class CompletionContext {
3234

@@ -36,17 +38,17 @@ public class CompletionContext {
3638

3739
private final int position;
3840

39-
private final CommandOption commandOption;
41+
private final @Nullable CommandOption commandOption;
4042

41-
private final CommandRegistration commandRegistration;
43+
private final @Nullable CommandRegistration commandRegistration;
4244

4345
/**
4446
*
45-
* @param words words in the buffer, excluding words for the command name
47+
* @param words words in the buffer, excluding words for the command name
4648
* @param wordIndex the index of the word the cursor is in
47-
* @param position the position inside the current word where the cursor is
49+
* @param position the position inside the current word where the cursor is
4850
*/
49-
public CompletionContext(List<String> words, int wordIndex, int position, CommandRegistration commandRegistration, CommandOption commandOption) {
51+
public CompletionContext(List<String> words, int wordIndex, int position, @Nullable CommandRegistration commandRegistration, @Nullable CommandOption commandOption) {
5052
this.words = words;
5153
this.wordIndex = wordIndex;
5254
this.position = position;
@@ -66,11 +68,11 @@ public int getPosition() {
6668
return position;
6769
}
6870

69-
public CommandOption getCommandOption() {
71+
public @Nullable CommandOption getCommandOption() {
7072
return commandOption;
7173
}
7274

73-
public CommandRegistration getCommandRegistration() {
75+
public @Nullable CommandRegistration getCommandRegistration() {
7476
return commandRegistration;
7577
}
7678

@@ -80,19 +82,22 @@ public String upToCursor() {
8082
if (!start.isEmpty()) {
8183
start += " ";
8284
}
83-
start += currentWord().substring(0, position);
85+
String currentWord = currentWord();
86+
if (currentWord != null) {
87+
start += currentWord.substring(0, position);
88+
}
8489
}
8590
return start;
8691
}
8792

8893
/**
8994
* Return the whole word the cursor is in, or {@code null} if the cursor is past the last word.
9095
*/
91-
public String currentWord() {
96+
public @Nullable String currentWord() {
9297
return wordIndex >= 0 && wordIndex < words.size() ? words.get(wordIndex) : null;
9398
}
9499

95-
public String currentWordUpToCursor() {
100+
public @Nullable String currentWordUpToCursor() {
96101
String currentWord = currentWord();
97102
return currentWord != null ? currentWord.substring(0, getPosition()) : null;
98103
}
@@ -101,7 +106,7 @@ public String currentWordUpToCursor() {
101106
* Return a copy of this context, as if the first {@literal nbWords} were not present
102107
*/
103108
public CompletionContext drop(int nbWords) {
104-
return new CompletionContext(new ArrayList<String>(words.subList(nbWords, words.size())), wordIndex - nbWords,
109+
return new CompletionContext(new ArrayList<>(words.subList(nbWords, words.size())), wordIndex - nbWords,
105110
position, commandRegistration, commandOption);
106111
}
107112

@@ -115,7 +120,7 @@ public CompletionContext commandOption(CommandOption commandOption) {
115120
/**
116121
* Return a copy of this context with given command registration.
117122
*/
118-
public CompletionContext commandRegistration(CommandRegistration commandRegistration) {
123+
public CompletionContext commandRegistration(@Nullable CommandRegistration commandRegistration) {
119124
return new CompletionContext(words, wordIndex, position, commandRegistration, commandOption);
120125
}
121126
}

spring-shell-core/src/main/java/org/springframework/shell/CompletionProposal.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@
1616

1717
package org.springframework.shell;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
import java.util.Objects;
2022

2123
/**
2224
* Represents a proposal for TAB completion, made not only of the text to append, but also metadata about the proposal.
2325
*
2426
* @author Eric Bottard
27+
* @author Piotr Olaszewski
2528
*/
2629
public class CompletionProposal {
2730

@@ -38,12 +41,12 @@ public class CompletionProposal {
3841
/**
3942
* The description for the proposal.
4043
*/
41-
private String description;
44+
private @Nullable String description;
4245

4346
/**
4447
* The category of the proposal, which may be used to group proposals together.
4548
*/
46-
private String category;
49+
private @Nullable String category;
4750

4851
/**
4952
* Whether the proposal should bypass escaping and quoting rules. This is useful for command proposals, which can
@@ -79,16 +82,16 @@ public CompletionProposal displayText(String displayText) {
7982
return this;
8083
}
8184

82-
public String description() {
85+
public @Nullable String description() {
8386
return description;
8487
}
8588

86-
public CompletionProposal description(String description) {
89+
public CompletionProposal description(@Nullable String description) {
8790
this.description = description;
8891
return this;
8992
}
9093

91-
public String category() {
94+
public @Nullable String category() {
9295
return category;
9396
}
9497

spring-shell-core/src/main/java/org/springframework/shell/CoreResourcesRuntimeHints.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,20 @@
1515
*/
1616
package org.springframework.shell;
1717

18+
import org.jspecify.annotations.Nullable;
1819
import org.springframework.aot.hint.RuntimeHints;
1920
import org.springframework.aot.hint.RuntimeHintsRegistrar;
2021

2122
/**
2223
* {@link RuntimeHintsRegistrar} for Shell Core resources.
2324
*
2425
* @author Janne Valkealahti
26+
* @author Piotr Olaszewski
2527
*/
2628
class CoreResourcesRuntimeHints implements RuntimeHintsRegistrar {
2729

2830
@Override
29-
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
31+
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
3032
hints.resources().registerPattern("org/springframework/shell/component/*.stg");
3133
}
3234
}

spring-shell-core/src/main/java/org/springframework/shell/DefaultShellApplicationRunner.java

Whitespace-only changes.
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package org.springframework.shell;
22

3+
import org.jspecify.annotations.Nullable;
4+
35
/**
46
* To be implemented by components able to provide a "line" of user input, whether interactively or by batch.
57
*
68
* @author Eric Bottard
9+
* @author Piotr Olaszewski
710
*/
811
public interface InputProvider {
912

@@ -12,5 +15,5 @@ public interface InputProvider {
1215
*
1316
* <p>Returning {@literal null} indicates end of input, requesting shell exit.</p>
1417
*/
15-
Input readInput();
18+
@Nullable Input readInput();
1619
}

0 commit comments

Comments
 (0)