Skip to content

Commit 075d8b6

Browse files
committed
refact: ensure consistent placement of @Nullable annotation
1 parent 7ea2e74 commit 075d8b6

76 files changed

Lines changed: 256 additions & 371 deletions

File tree

Some content is hidden

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

org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/AttributedScopeStack.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ final class AttributedScopeStack {
3434
record Frame(int encodedTokenAttributes, List<String> scopeNames) {
3535
}
3636

37-
@Nullable
38-
static AttributedScopeStack fromExtension(final @Nullable AttributedScopeStack namesScopeList,
37+
static @Nullable AttributedScopeStack fromExtension(final @Nullable AttributedScopeStack namesScopeList,
3938
final List<AttributedScopeStack.Frame> contentNameScopesList) {
4039
var current = namesScopeList;
4140
@Nullable

org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/BasicScopeAttributesProvider.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ final class BasicScopeAttributesProvider {
4141

4242
private final ConcurrentMap<String /*scopeName*/, BasicScopeAttributes> cache = new ConcurrentHashMap<>();
4343

44-
BasicScopeAttributesProvider(final int initialLanguage, @Nullable final Map<String, Integer> embeddedLanguages) {
44+
BasicScopeAttributesProvider(final int initialLanguage, final @Nullable Map<String, Integer> embeddedLanguages) {
4545
this._defaultAttributes = new BasicScopeAttributes(initialLanguage, OptionalStandardTokenType.NotSet);
4646
this._embeddedLanguagesMatcher = new ScopeMatcher<>(defaultIfNull(embeddedLanguages, Collections.emptyMap()));
4747
}
@@ -50,7 +50,7 @@ BasicScopeAttributes getDefaultAttributes() {
5050
return this._defaultAttributes;
5151
}
5252

53-
BasicScopeAttributes getBasicScopeAttributes(@Nullable final String scopeName) {
53+
BasicScopeAttributes getBasicScopeAttributes(final @Nullable String scopeName) {
5454
if (scopeName == null) {
5555
return BasicScopeAttributesProvider._NULL_SCOPE_METADATA;
5656
}
@@ -92,8 +92,7 @@ private int _scopeToLanguage(final String scopeName) {
9292
private static final class ScopeMatcher<TValue> {
9393

9494
private final Map<String, TValue> values;
95-
@Nullable
96-
private final Pattern scopesRegExp;
95+
private final @Nullable Pattern scopesRegExp;
9796

9897
ScopeMatcher(final Map<String, TValue> values) {
9998
if (values.isEmpty()) {

org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/Grammar.java

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,30 +63,27 @@ public final class Grammar implements IGrammar, IRuleFactoryHelper {
6363

6464
private final String rootScopeName;
6565

66-
@Nullable
67-
private RuleId _rootId;
66+
private @Nullable RuleId _rootId;
6867
private int _lastRuleId = 0;
6968
private final Map<RuleId, @Nullable Rule> _ruleId2desc = new HashMap<>();
7069
private final Map<String /*scopeName*/, IRawGrammar> includedGrammars = new HashMap<>();
7170
private final IGrammarRepository _grammarRepository;
7271
private final IRawGrammar _grammar;
7372
final IThemeProvider themeProvider;
7473

75-
@Nullable
76-
private List<Injection> _injections;
74+
private @Nullable List<Injection> _injections;
7775
private final BasicScopeAttributesProvider _basicScopeAttributesProvider;
7876
private final List<TokenTypeMatcher> _tokenTypeMatchers = new ArrayList<>();
7977

80-
@Nullable
81-
private final BalancedBracketSelectors balancedBracketSelectors;
78+
private final @Nullable BalancedBracketSelectors balancedBracketSelectors;
8279

8380
public Grammar(
8481
final String rootScopeName,
8582
final IRawGrammar grammar,
8683
final int initialLanguage,
87-
@Nullable final Map<String, Integer> embeddedLanguages,
88-
@Nullable final Map<String, Integer> tokenTypes,
89-
@Nullable final BalancedBracketSelectors balancedBracketSelectors,
84+
final @Nullable Map<String, Integer> embeddedLanguages,
85+
final @Nullable Map<String, Integer> tokenTypes,
86+
final @Nullable BalancedBracketSelectors balancedBracketSelectors,
9087
final IGrammarRepository grammarRepository,
9188
final IThemeProvider themeProvider) {
9289

@@ -220,8 +217,7 @@ public Rule getRule(final RuleId ruleId) {
220217
}
221218

222219
@Override
223-
@Nullable
224-
public IRawGrammar getExternalGrammar(final String scopeName, @Nullable final IRawRepository repository) {
220+
public @Nullable IRawGrammar getExternalGrammar(final String scopeName, final @Nullable IRawRepository repository) {
225221
if (this.includedGrammars.containsKey(scopeName)) {
226222
return this.includedGrammars.get(scopeName);
227223
}
@@ -236,7 +232,7 @@ public IRawGrammar getExternalGrammar(final String scopeName, @Nullable final IR
236232
return null;
237233
}
238234

239-
private IRawGrammar initGrammar(IRawGrammar grammar, @Nullable final IRawRule base) {
235+
private IRawGrammar initGrammar(IRawGrammar grammar, final @Nullable IRawRule base) {
240236
grammar = ObjectCloner.deepClone(grammar);
241237

242238
final var repo = grammar.getRepository();
@@ -254,8 +250,8 @@ public ITokenizeLineResult<IToken[]> tokenizeLine(final String lineText) {
254250

255251
@Override
256252
public ITokenizeLineResult<IToken[]> tokenizeLine(final String lineText,
257-
@Nullable final IStateStack prevState,
258-
@Nullable final Duration timeLimit) {
253+
final @Nullable IStateStack prevState,
254+
final @Nullable Duration timeLimit) {
259255
return _tokenize(lineText, (StateStack) prevState, false, timeLimit);
260256
}
261257

@@ -265,8 +261,8 @@ public ITokenizeLineResult<int[]> tokenizeLine2(final String lineText) {
265261
}
266262

267263
@Override
268-
public ITokenizeLineResult<int[]> tokenizeLine2(final String lineText, @Nullable final IStateStack prevState,
269-
@Nullable final Duration timeLimit) {
264+
public ITokenizeLineResult<int[]> tokenizeLine2(final String lineText, final @Nullable IStateStack prevState,
265+
final @Nullable Duration timeLimit) {
270266
return _tokenize(lineText, (StateStack) prevState, true, timeLimit);
271267
}
272268

@@ -275,7 +271,7 @@ private <T> T _tokenize(
275271
String lineText,
276272
@Nullable StateStack prevState,
277273
final boolean emitBinaryTokens,
278-
@Nullable final Duration timeLimit) {
274+
final @Nullable Duration timeLimit) {
279275
var rootId = this._rootId;
280276
if (rootId == null) {
281277
rootId = this._rootId = RuleFactory.getCompiledRuleId(
@@ -358,8 +354,7 @@ private <T> T _tokenize(
358354
}
359355

360356
@Override
361-
@Nullable
362-
public String getName() {
357+
public @Nullable String getName() {
363358
return _grammar.getName();
364359
}
365360

org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokenizer.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,7 @@ private void scanNext() {
305305
}
306306
}
307307

308-
@Nullable
309-
private MatchResult matchRule(final Grammar grammar, final OnigString lineText, final boolean isFirstLine, final int linePos,
308+
private @Nullable MatchResult matchRule(final Grammar grammar, final OnigString lineText, final boolean isFirstLine, final int linePos,
310309
final StateStack stack, final int anchorPosition) {
311310
final var rule = stack.getRule(grammar);
312311
final var ruleScanner = rule.compileAG(grammar, stack.endRule, isFirstLine, linePos == anchorPosition);
@@ -319,8 +318,7 @@ private MatchResult matchRule(final Grammar grammar, final OnigString lineText,
319318
return null;
320319
}
321320

322-
@Nullable
323-
private MatchResult matchRuleOrInjections(final Grammar grammar, final OnigString lineText, final boolean isFirstLine,
321+
private @Nullable MatchResult matchRuleOrInjections(final Grammar grammar, final OnigString lineText, final boolean isFirstLine,
324322
final int linePos, final StateStack stack, final int anchorPosition) {
325323
// Look for normal grammar rule
326324
final MatchResult matchResult = matchRule(grammar, lineText, isFirstLine, linePos, stack, anchorPosition);
@@ -355,9 +353,8 @@ private MatchResult matchRuleOrInjections(final Grammar grammar, final OnigStrin
355353
return matchResult;
356354
}
357355

358-
@Nullable
359-
private MatchInjectionsResult matchInjections(final List<Injection> injections, final Grammar grammar, final OnigString lineText,
360-
final boolean isFirstLine, final int linePos, final StateStack stack, final int anchorPosition) {
356+
private @Nullable MatchInjectionsResult matchInjections(final List<Injection> injections, final Grammar grammar,
357+
final OnigString lineText, final boolean isFirstLine, final int linePos, final StateStack stack, final int anchorPosition) {
361358

362359
// The lower the better
363360
var bestMatchRating = Integer.MAX_VALUE;

org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/LineTokens.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,12 @@ public String toString() {
105105

106106
private final List<TokenTypeMatcher> _tokenTypeOverrides;
107107

108-
@Nullable
109-
private final BalancedBracketSelectors balancedBracketSelectors;
108+
private final @Nullable BalancedBracketSelectors balancedBracketSelectors;
110109

111110
LineTokens(final boolean emitBinaryTokens,
112111
final String lineText,
113112
final List<TokenTypeMatcher> tokenTypeOverrides,
114-
@Nullable final BalancedBracketSelectors balancedBracketSelectors) {
113+
final @Nullable BalancedBracketSelectors balancedBracketSelectors) {
115114

116115
this._emitBinaryTokens = emitBinaryTokens;
117116
this._tokenTypeOverrides = tokenTypeOverrides;
@@ -130,7 +129,7 @@ void produce(final StateStack stack, final int endIndex) {
130129
this.produceFromScopes(stack.contentNameScopesList, endIndex);
131130
}
132131

133-
void produceFromScopes(@Nullable final AttributedScopeStack scopesList, final int endIndex) {
132+
void produceFromScopes(final @Nullable AttributedScopeStack scopesList, final int endIndex) {
134133
if (this._lastTokenEndIndex >= endIndex) {
135134
return;
136135
}

org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/ScopeStack.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
*/
3030
public final class ScopeStack {
3131

32-
@Nullable
33-
static ScopeStack push(@Nullable ScopeStack path, final List<String> scopeNames) {
32+
static @Nullable ScopeStack push(@Nullable ScopeStack path, final List<String> scopeNames) {
3433
for (final var name : scopeNames) {
3534
path = new ScopeStack(path, name);
3635
}
@@ -41,20 +40,18 @@ public static ScopeStack from(final String first) {
4140
return new ScopeStack(null, first);
4241
}
4342

44-
@Nullable
45-
public static ScopeStack from(final String... segments) {
43+
public static @Nullable ScopeStack from(final String... segments) {
4644
ScopeStack result = null;
4745
for (final String segment : segments) {
4846
result = new ScopeStack(result, segment);
4947
}
5048
return result;
5149
}
5250

53-
@Nullable
54-
public final ScopeStack parent;
51+
public final @Nullable ScopeStack parent;
5552
public final String scopeName;
5653

57-
ScopeStack(@Nullable final ScopeStack parent, final String scopeName) {
54+
ScopeStack(final @Nullable ScopeStack parent, final String scopeName) {
5855
this.parent = parent;
5956
this.scopeName = scopeName;
6057
}
@@ -92,7 +89,7 @@ public boolean isExtending(final ScopeStack other) {
9289
return parent.isExtending(other);
9390
}
9491

95-
List<String> getExtensionIfDefined(@Nullable final ScopeStack base) {
92+
List<String> getExtensionIfDefined(final @Nullable ScopeStack base) {
9693
final var result = new ArrayList<String>();
9794
@Nullable
9895
ScopeStack item = this;

org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/StateStack.java

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ record Frame(
8181
/**
8282
* The previous state on the stack (or null for the root state).
8383
*/
84-
@Nullable
85-
private final StateStack parent;
84+
private final @Nullable StateStack parent;
8685

8786
/**
8887
* The state (rule) that this element represents.
@@ -97,31 +96,28 @@ record Frame(
9796
/**
9897
* The "pop" (end) condition for this state in case that it was dynamically generated through captured text.
9998
*/
100-
@Nullable
101-
final String endRule;
99+
final @Nullable String endRule;
102100

103101
/**
104102
* The list of scopes containing the "name" for this state.
105103
*/
106-
@Nullable
107-
final AttributedScopeStack nameScopesList;
104+
final @Nullable AttributedScopeStack nameScopesList;
108105

109106
/**
110107
* The list of scopes containing the "contentName" (besides "name") for this state.
111108
* This list **must** contain as an element `scopeName`.
112109
*/
113-
@Nullable
114-
final AttributedScopeStack contentNameScopesList;
110+
final @Nullable AttributedScopeStack contentNameScopesList;
115111

116112
StateStack(
117-
@Nullable final StateStack parent,
113+
final @Nullable StateStack parent,
118114
final RuleId ruleId,
119115
final int enterPos,
120116
final int anchorPos,
121117
final boolean beginRuleCapturedEOL,
122-
@Nullable final String endRule,
123-
@Nullable final AttributedScopeStack nameScopesList,
124-
@Nullable final AttributedScopeStack contentNameScopesList) {
118+
final @Nullable String endRule,
119+
final @Nullable AttributedScopeStack nameScopesList,
120+
final @Nullable AttributedScopeStack contentNameScopesList) {
125121

126122
this.parent = parent;
127123
this.ruleId = ruleId;
@@ -135,7 +131,7 @@ record Frame(
135131
}
136132

137133
@Override
138-
public boolean equals(@Nullable final Object other) {
134+
public boolean equals(final @Nullable Object other) {
139135
if (other instanceof final StateStack otherState) {
140136
return _equals(this, otherState);
141137
}
@@ -224,9 +220,9 @@ StateStack push(
224220
final int enterPos,
225221
final int anchorPos,
226222
final boolean beginRuleCapturedEOL,
227-
@Nullable final String endRule,
228-
@Nullable final AttributedScopeStack nameScopesList,
229-
@Nullable final AttributedScopeStack contentNameScopesList) {
223+
final @Nullable String endRule,
224+
final @Nullable AttributedScopeStack nameScopesList,
225+
final @Nullable AttributedScopeStack contentNameScopesList) {
230226
return new StateStack(
231227
this,
232228
ruleId,
@@ -324,7 +320,7 @@ Frame toStateStackFrame() {
324320
: Collections.emptyList());
325321
}
326322

327-
public static StateStack pushFrame(@Nullable final StateStack self, final Frame frame) {
323+
public static StateStack pushFrame(final @Nullable StateStack self, final Frame frame) {
328324
final var namesScopeList = AttributedScopeStack.fromExtension(self == null ? null : self.nameScopesList,
329325
frame.nameScopesList);
330326
final var enterPos = frame.enterPos;

org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/dependencies/ScopeDependencyProcessor.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,15 @@ private static class Context {
148148
}
149149

150150
private static final class ContextWithRepository extends Context {
151-
@Nullable
152-
final IRawRepository repository;
153151

154-
ContextWithRepository(final Context context, @Nullable final IRawRepository repository) {
152+
final @Nullable IRawRepository repository;
153+
154+
ContextWithRepository(final Context context, final @Nullable IRawRepository repository) {
155155
super(context.baseGrammar, context.selfGrammar);
156156
this.repository = repository;
157157
}
158158

159-
ContextWithRepository(final IRawGrammar baseGrammar, final IRawGrammar selfGrammar, @Nullable final IRawRepository repository) {
159+
ContextWithRepository(final IRawGrammar baseGrammar, final IRawGrammar selfGrammar, final @Nullable IRawRepository repository) {
160160
super(baseGrammar, selfGrammar);
161161
this.repository = repository;
162162
}
@@ -227,8 +227,7 @@ private void collectExternalReferencesInRules(
227227
break;
228228
case TopLevelReference:
229229
case TopLevelRepositoryReference:
230-
@Nullable
231-
final IRawGrammar selfGrammar = reference.scopeName.equals(context.selfGrammar.getScopeName())
230+
final @Nullable IRawGrammar selfGrammar = reference.scopeName.equals(context.selfGrammar.getScopeName())
232231
? context.selfGrammar
233232
: reference.scopeName.equals(context.baseGrammar.getScopeName())
234233
? context.baseGrammar

org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/raw/IRawRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
public interface IRawRepository {
2828

29-
static IRawRepository merge(@Nullable final IRawRepository... sources) {
29+
static IRawRepository merge(final @Nullable IRawRepository... sources) {
3030
final var merged = new RawRepository();
3131
for (final var source : sources) {
3232
if (source == null)

org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/raw/RawGrammar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public String getScopeName() {
108108
}
109109

110110
@Override
111-
public @Nullable Object put(final String key, @Nullable final Object value) {
111+
public @Nullable Object put(final String key, final @Nullable Object value) {
112112
if (FILE_TYPES.equals(key))
113113
fileTypes = null;
114114

0 commit comments

Comments
 (0)