12
12
import org .hibernate .Incubating ;
13
13
import org .hibernate .internal .util .StringHelper ;
14
14
15
+ import org .checkerframework .checker .nullness .qual .Nullable ;
16
+
17
+ import static org .hibernate .internal .util .NullnessUtil .castNonNull ;
18
+
15
19
/**
16
20
* A compound name where the root path element is an entity name or a collection role
17
21
* and each the path sub-path from the root references a domain or mapping model part
23
27
public class NavigablePath implements DotIdentifierSequence , Serializable {
24
28
public static final String IDENTIFIER_MAPPER_PROPERTY = "_identifierMapper" ;
25
29
26
- private final NavigablePath parent ;
30
+ private final @ Nullable NavigablePath parent ;
27
31
private final String localName ;
28
- private final String alias ;
32
+ private final @ Nullable String alias ;
29
33
private final String identifierForTableGroup ;
30
34
private final FullPathCalculator fullPathCalculator ;
31
35
private final int hashCode ;
@@ -34,7 +38,7 @@ public NavigablePath(String localName) {
34
38
this ( localName , null );
35
39
}
36
40
37
- public NavigablePath (String rootName , String alias ) {
41
+ public NavigablePath (String rootName , @ Nullable String alias ) {
38
42
this .parent = null ;
39
43
this .alias = alias = StringHelper .nullIfEmpty ( alias );
40
44
this .localName = rootName ;
@@ -49,7 +53,7 @@ public NavigablePath(NavigablePath parent, String navigableName) {
49
53
this ( parent , navigableName , null );
50
54
}
51
55
52
- public NavigablePath (NavigablePath parent , String localName , String alias ) {
56
+ public NavigablePath (NavigablePath parent , String localName , @ Nullable String alias ) {
53
57
assert parent != null ;
54
58
55
59
this .parent = parent ;
@@ -79,9 +83,9 @@ public NavigablePath(NavigablePath parent, String localName, String alias) {
79
83
}
80
84
81
85
public NavigablePath (
82
- NavigablePath parent ,
86
+ @ Nullable NavigablePath parent ,
83
87
String localName ,
84
- String alias ,
88
+ @ Nullable String alias ,
85
89
String identifierForTableGroup ,
86
90
FullPathCalculator fullPathCalculator ,
87
91
int hashCode ) {
@@ -94,7 +98,7 @@ public NavigablePath(
94
98
}
95
99
96
100
@ Override
97
- public NavigablePath getParent () {
101
+ public @ Nullable NavigablePath getParent () {
98
102
return parent instanceof TreatedNavigablePath ? parent .getParent () : parent ;
99
103
}
100
104
@@ -103,7 +107,7 @@ public String getLocalName() {
103
107
return localName ;
104
108
}
105
109
106
- public String getAlias () {
110
+ public @ Nullable String getAlias () {
107
111
return alias ;
108
112
}
109
113
@@ -121,7 +125,7 @@ public int hashCode() {
121
125
}
122
126
123
127
@ Override
124
- public boolean equals (Object other ) {
128
+ public boolean equals (@ Nullable Object other ) {
125
129
if ( this == other ) {
126
130
return true ;
127
131
}
@@ -175,14 +179,14 @@ public NavigablePath treatAs(String entityName, String alias) {
175
179
return new TreatedNavigablePath ( this , entityName , alias );
176
180
}
177
181
178
- public NavigablePath getRealParent () {
182
+ public @ Nullable NavigablePath getRealParent () {
179
183
return parent ;
180
184
}
181
185
182
186
/**
183
187
* Determine whether this path is part of the given path's parent
184
188
*/
185
- public boolean isParent (NavigablePath navigablePath ) {
189
+ public boolean isParent (@ Nullable NavigablePath navigablePath ) {
186
190
while ( navigablePath != null ) {
187
191
if ( this .equals ( navigablePath .getParent () ) ) {
188
192
return true ;
@@ -195,14 +199,15 @@ public boolean isParent(NavigablePath navigablePath) {
195
199
/**
196
200
* Determine whether the given path is a suffix of this path
197
201
*/
198
- public boolean isSuffix (DotIdentifierSequence dotIdentifierSequence ) {
202
+ public boolean isSuffix (@ Nullable DotIdentifierSequence dotIdentifierSequence ) {
199
203
if ( dotIdentifierSequence == null ) {
200
204
return true ;
201
205
}
202
206
if ( !localNamesMatch ( dotIdentifierSequence ) ) {
203
207
return false ;
204
208
}
205
- return getParent () != null && getParent ().isSuffix ( dotIdentifierSequence .getParent () );
209
+ NavigablePath parent = getParent ();
210
+ return parent != null && parent .isSuffix ( dotIdentifierSequence .getParent () );
206
211
}
207
212
208
213
/**
@@ -216,23 +221,24 @@ public boolean isSuffix(DotIdentifierSequence dotIdentifierSequence) {
216
221
* or null if the NavigablePath does not contain the suffix.
217
222
*
218
223
*/
219
- public NavigablePath trimSuffix (DotIdentifierSequence suffix ) {
224
+ public @ Nullable NavigablePath trimSuffix (@ Nullable DotIdentifierSequence suffix ) {
220
225
if ( suffix == null ) {
221
226
return this ;
222
227
}
223
228
if ( !getLocalName ().equals ( suffix .getLocalName () ) ) {
224
229
return null ;
225
230
}
226
- if ( getParent () != null ) {
227
- return getParent ().trimSuffix ( suffix .getParent () );
231
+ NavigablePath parent = getParent ();
232
+ if ( parent != null ) {
233
+ return parent .trimSuffix ( suffix .getParent () );
228
234
}
229
235
return null ;
230
236
}
231
237
232
238
/**
233
239
* Determine whether this path is part of the given path's parent
234
240
*/
235
- public boolean isParentOrEqual (NavigablePath navigablePath ) {
241
+ public boolean isParentOrEqual (@ Nullable NavigablePath navigablePath ) {
236
242
while ( navigablePath != null ) {
237
243
if ( this .equals ( navigablePath ) ) {
238
244
return true ;
@@ -242,15 +248,15 @@ public boolean isParentOrEqual(NavigablePath navigablePath) {
242
248
return false ;
243
249
}
244
250
245
- public boolean pathsMatch (NavigablePath p ) {
251
+ public boolean pathsMatch (@ Nullable NavigablePath p ) {
246
252
return this == p || p != null && localName .equals ( p .localName )
247
253
&& ( parent == null ? p .parent == null && Objects .equals ( alias , p .alias ) : parent .pathsMatch ( p .parent ) );
248
254
}
249
255
250
256
/**
251
257
* Ignores aliases in the resulting String
252
258
*/
253
- public String relativize (NavigablePath base ) {
259
+ public @ Nullable String relativize (NavigablePath base ) {
254
260
// e.g.
255
261
// - base = Root.sub
256
262
// - this = Root.sub.stuff
@@ -284,7 +290,7 @@ public void collectPath(String path) {
284
290
buffer .append ( path );
285
291
}
286
292
287
- public String resolve () {
293
+ public @ Nullable String resolve () {
288
294
if ( buffer == null ) {
289
295
// Return an empty string instead of null in case the two navigable paths are equal
290
296
return matchedBase ? "" : null ;
@@ -323,24 +329,24 @@ public String toString() {
323
329
*/
324
330
@ FunctionalInterface
325
331
protected interface FullPathCalculator extends Serializable {
326
- String calculateFullPath (NavigablePath parent , String localName , String alias );
332
+ String calculateFullPath (@ Nullable NavigablePath parent , String localName , @ Nullable String alias );
327
333
}
328
334
329
335
/**
330
336
* The pattern used for root NavigablePaths
331
337
*/
332
- protected static String calculateRootFullPath (NavigablePath parent , String rootName , String alias ) {
338
+ protected static String calculateRootFullPath (@ Nullable NavigablePath parent , String rootName , @ Nullable String alias ) {
333
339
assert parent == null ;
334
340
return alias == null ? rootName : rootName + "(" + alias + ")" ;
335
341
}
336
342
337
343
/**
338
344
* The normal pattern used for the "full path"
339
345
*/
340
- private static String calculateNormalFullPath (NavigablePath parent , String localName , String alias ) {
346
+ private static String calculateNormalFullPath (@ Nullable NavigablePath parent , String localName , @ Nullable String alias ) {
341
347
assert parent != null ;
342
348
343
- final String parentFullPath = parent .getFullPath ();
349
+ final String parentFullPath = castNonNull ( parent ) .getFullPath ();
344
350
final String baseFullPath = StringHelper .isEmpty ( parentFullPath )
345
351
? localName
346
352
: parentFullPath + "." + localName ;
@@ -350,7 +356,7 @@ private static String calculateNormalFullPath(NavigablePath parent, String local
350
356
/**
351
357
* Pattern used for `_identifierMapper`
352
358
*/
353
- protected static String calculateIdMapperFullPath (NavigablePath parent , String localName , String alias ) {
359
+ protected static String calculateIdMapperFullPath (@ Nullable NavigablePath parent , String localName , @ Nullable String alias ) {
354
360
return parent != null ? parent .getFullPath () : "" ;
355
361
}
356
362
}
0 commit comments