Skip to content

Commit f3028fc

Browse files
committed
Style: Place nullable annotation next to return value
1 parent 6906192 commit f3028fc

File tree

13 files changed

+40
-76
lines changed

13 files changed

+40
-76
lines changed

src/main/java/ch/jalu/typeresolver/CommonTypeUtils.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ public static boolean hasExplicitUpperBound(WildcardType wildcardType) {
5353
* @param type the type to return as class if possible
5454
* @return the type as class, or null if not applicable
5555
*/
56-
@Nullable
57-
public static Class<?> getDefinitiveClass(Type type) {
56+
public static @Nullable Class<?> getDefinitiveClass(Type type) {
5857
if (type instanceof Class<?>) {
5958
return (Class<?>) type;
6059
} else if (type instanceof ParameterizedType) {

src/main/java/ch/jalu/typeresolver/TypeInfo.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ public Type getType() {
8282
* @param index the index of the type parameter to get (0-based)
8383
* @return the type argument for the given index, null if not applicable
8484
*/
85-
@Nullable
86-
public TypeInfo getTypeArgumentInfo(int index) {
85+
public @Nullable TypeInfo getTypeArgumentInfo(int index) {
8786
if (type instanceof ParameterizedType) {
8887
Type[] typeArguments = ((ParameterizedType) type).getActualTypeArguments();
8988
if (index < typeArguments.length) {
@@ -109,8 +108,7 @@ public TypeInfo getTypeArgumentInfo(int index) {
109108
* @param index the index of the type parameter to get (0-based)
110109
* @return the type argument as safe-to-write class, null if not applicable
111110
*/
112-
@Nullable
113-
public Class<?> getTypeArgumentAsClass(int index) {
111+
public @Nullable Class<?> getTypeArgumentAsClass(int index) {
114112
TypeInfo genericTypeInfo = getTypeArgumentInfo(index);
115113
return genericTypeInfo == null ? null : genericTypeInfo.toClass();
116114
}
@@ -131,8 +129,7 @@ public Class<?> getTypeArgumentAsClass(int index) {
131129
* (e.g. setting a value to a field or adding to a collection);
132130
* null if not applicable
133131
*/
134-
@Nullable
135-
public Class<?> toClass() {
132+
public @Nullable Class<?> toClass() {
136133
return TypeToClassUtils.getSafeToWriteClass(type);
137134
}
138135

@@ -193,8 +190,7 @@ public boolean isAssignableFrom(Class<?> clazz) {
193190
*
194191
* @return the enclosing type, or null if this type is not a nested type
195192
*/
196-
@Nullable
197-
public TypeInfo getEnclosingType() {
193+
public @Nullable TypeInfo getEnclosingType() {
198194
Type enclosingType = null;
199195
if (type instanceof Class<?>) {
200196
enclosingType = ((Class<?>) type).getEnclosingClass();
@@ -210,8 +206,7 @@ public TypeInfo getEnclosingType() {
210206
*
211207
* @return the component type of this array type, or null if this type is not an array
212208
*/
213-
@Nullable
214-
public TypeInfo getComponentType() {
209+
public @Nullable TypeInfo getComponentType() {
215210
Type componentType = null;
216211
if (type instanceof Class<?>) {
217212
componentType = ((Class<?>) type).getComponentType();
@@ -249,8 +244,7 @@ public TypeInfo resolve(Type type) {
249244
* @param clazz the desired superclass to get the info for
250245
* @return the type info of the superclass of the given class, or null if this wrapped type is not a supertype
251246
*/
252-
@Nullable
253-
public TypeInfo resolveSuperclass(Class<?> clazz) {
247+
public @Nullable TypeInfo resolveSuperclass(Class<?> clazz) {
254248
final Class<?> thisClass = toClass();
255249
if (thisClass == null || !clazz.isAssignableFrom(thisClass)) {
256250
return null;
@@ -297,8 +291,7 @@ public void visitAllTypes(Consumer<Type> typeVisitor) {
297291
TypeVisitor.visitAllTypes(type, getOrInitResolver(), typeVisitor);
298292
}
299293

300-
@Nullable
301-
private Type getOwnerTypeForResolvedParameterizedType(Class<?> superclass) {
294+
private @Nullable Type getOwnerTypeForResolvedParameterizedType(Class<?> superclass) {
302295
Class<?> enclosingClass = superclass.getEnclosingClass();
303296
// Return enclosing class without type arguments if the nested class is static (in line with Java behavior)
304297
if (enclosingClass == null || Modifier.isStatic(superclass.getModifiers())) {

src/main/java/ch/jalu/typeresolver/TypeToClassUtils.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ private TypeToClassUtils() {
2727
* @param type the type to process
2828
* @return safe-to-write class of the type, or null if not known
2929
*/
30-
@Nullable
31-
public static Class<?> getSafeToWriteClass(@Nullable Type type) {
30+
public static @Nullable Class<?> getSafeToWriteClass(@Nullable Type type) {
3231
if (type instanceof Class<?>) {
3332
return (Class<?>) type;
3433
} else if (type instanceof ParameterizedType) {
@@ -59,8 +58,7 @@ public static Class<?> getSafeToReadClass(@Nullable Type type) {
5958
return clazz == null ? Object.class : clazz;
6059
}
6160

62-
@Nullable
63-
private static Class<?> getSafeToReadClassOrNull(@Nullable Type type) {
61+
private static @Nullable Class<?> getSafeToReadClassOrNull(@Nullable Type type) {
6462
if (type instanceof Class<?>) {
6563
return (Class<?>) type;
6664
} else if (type instanceof ParameterizedType) {
@@ -88,8 +86,7 @@ private static Class<?> getSafeToReadClassOrNull(@Nullable Type type) {
8886
return null;
8987
}
9088

91-
@Nullable
92-
private static Class<?> getFirstNonNull(Function<Type, Class<?>> converter, Type[] inputs) {
89+
private static @Nullable Class<?> getFirstNonNull(Function<Type, Class<?>> converter, Type[] inputs) {
9390
return Arrays.stream(inputs)
9491
.map(converter)
9592
.filter(Objects::nonNull)

src/main/java/ch/jalu/typeresolver/classutil/ClassTypeCallback.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ public abstract class ClassTypeCallback<R> {
2020
* @param enumClass the enum class
2121
* @return result or null
2222
*/
23-
@Nullable
24-
public R forEnum(Class<? extends Enum<?>> enumClass) {
23+
public @Nullable R forEnum(Class<? extends Enum<?>> enumClass) {
2524
return null;
2625
}
2726

@@ -35,8 +34,7 @@ public R forEnum(Class<? extends Enum<?>> enumClass) {
3534
* @param enumEntryClass the synthetic class of the enum entry
3635
* @return result or null
3736
*/
38-
@Nullable
39-
public R forEnumEntry(Class<? extends Enum<?>> enumClass, Class<? extends Enum<?>> enumEntryClass) {
37+
public @Nullable R forEnumEntry(Class<? extends Enum<?>> enumClass, Class<? extends Enum<?>> enumEntryClass) {
4038
return null;
4139
}
4240

@@ -46,8 +44,7 @@ public R forEnumEntry(Class<? extends Enum<?>> enumClass, Class<? extends Enum<?
4644
* @param annotationClass the annotation class
4745
* @return result or null
4846
*/
49-
@Nullable
50-
public R forAnnotation(Class<? extends Annotation> annotationClass) {
47+
public @Nullable R forAnnotation(Class<? extends Annotation> annotationClass) {
5148
return null;
5249
}
5350

@@ -57,8 +54,7 @@ public R forAnnotation(Class<? extends Annotation> annotationClass) {
5754
* @param primitiveClass the primitive class (or void)
5855
* @return result or null
5956
*/
60-
@Nullable
61-
public R forPrimitiveType(Class<?> primitiveClass) {
57+
public @Nullable R forPrimitiveType(Class<?> primitiveClass) {
6258
return null;
6359
}
6460

@@ -71,8 +67,7 @@ public R forPrimitiveType(Class<?> primitiveClass) {
7167
* @param arrayClass the array class
7268
* @return result or null
7369
*/
74-
@Nullable
75-
public R forArrayType(Class<?> arrayClass) {
70+
public @Nullable R forArrayType(Class<?> arrayClass) {
7671
return null;
7772
}
7873

@@ -82,8 +77,7 @@ public R forArrayType(Class<?> arrayClass) {
8277
* @param interfaceType the interface
8378
* @return result or null
8479
*/
85-
@Nullable
86-
public R forInterface(Class<?> interfaceType) {
80+
public @Nullable R forInterface(Class<?> interfaceType) {
8781
return null;
8882
}
8983

@@ -93,8 +87,7 @@ public R forInterface(Class<?> interfaceType) {
9387
* @param proxyClass the proxy class
9488
* @return result or null
9589
*/
96-
@Nullable
97-
public R forProxyClass(Class<?> proxyClass) {
90+
public @Nullable R forProxyClass(Class<?> proxyClass) {
9891
return null;
9992
}
10093

@@ -104,8 +97,7 @@ public R forProxyClass(Class<?> proxyClass) {
10497
* @param regularClass the Java class
10598
* @return result or null
10699
*/
107-
@Nullable
108-
public R forRegularClass(Class<?> regularClass) {
100+
public @Nullable R forRegularClass(Class<?> regularClass) {
109101
return null;
110102
}
111103
}

src/main/java/ch/jalu/typeresolver/classutil/ClassUtils.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,7 @@ public static String getClassName(@Nullable Object object) {
199199
* @param object the object to inspect, or null
200200
* @return the semantic type (only null if the object was null)
201201
*/
202-
@Nullable
203-
public static Class<?> getSemanticType(@Nullable Object object) {
202+
public static @Nullable Class<?> getSemanticType(@Nullable Object object) {
204203
if (object == null) {
205204
return null;
206205
} else if (object instanceof Enum<?>) {
@@ -296,8 +295,8 @@ public static ClassType getType(Class<?> clazz) {
296295
* @param <R> the callback's result type
297296
* @return the result from the callback (may be null)
298297
*/
299-
@Nullable
300-
public static <R> R processClassByType(@Nullable Class<?> clazz, ClassTypeCallback<? extends R> typeCallback) {
298+
public static <R> @Nullable R processClassByType(@Nullable Class<?> clazz,
299+
ClassTypeCallback<? extends R> typeCallback) {
301300
ClassType type = getType(clazz);
302301
if (type == null) {
303302
return null;

src/main/java/ch/jalu/typeresolver/numbers/NumberTypes.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ private NumberTypes() {
3838
* @param <T> the class's type
3939
* @return the number type for the given class, null if not available
4040
*/
41-
@Nullable
4241
@SuppressWarnings("unchecked")
43-
public static <T> NumberType<T> from(@Nullable Class<T> clazz) {
42+
public static <T> @Nullable NumberType<T> from(@Nullable Class<T> clazz) {
4443
return (NumberType<T>) NUMBER_TYPES_BY_CLASS.get(clazz);
4544
}
4645

@@ -66,8 +65,7 @@ public static Stream<NumberType<?>> streamThroughAll() {
6665
* @param object the object to unwrap
6766
* @return the number value the object could be unwrapped to
6867
*/
69-
@Nullable
70-
public static Number unwrapToStandardNumberType(@Nullable Object object) {
68+
public static @Nullable Number unwrapToStandardNumberType(@Nullable Object object) {
7169
if (object instanceof Character) {
7270
return (int) (Character) object;
7371
} else if (object instanceof Number) {

src/main/java/ch/jalu/typeresolver/numbers/StandardNumberType.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,7 @@ public ValueRangeComparison compareToValueRange(Number number) {
213213
* @param clazz the class to find the number type for
214214
* @return the instance matching the given type, or null if not applicable
215215
*/
216-
@Nullable
217-
public static StandardNumberType fromClass(Class<?> clazz) {
216+
public static @Nullable StandardNumberType fromClass(Class<?> clazz) {
218217
return TYPE_TO_ENUM_ENTRIES.get(PrimitiveType.toReferenceType(clazz));
219218
}
220219

@@ -228,9 +227,8 @@ public static StandardNumberType fromClass(Class<?> clazz) {
228227
* @return the instance matching the given type, or null if not applicable
229228
* @see NumberTypes#from
230229
*/
231-
@Nullable
232230
@SuppressWarnings("unchecked")
233-
public static <T extends Number> NumberType<T> fromNumberClass(@Nullable Class<T> clazz) {
231+
public static <T extends Number> @Nullable NumberType<T> fromNumberClass(@Nullable Class<T> clazz) {
234232
return fromClass(clazz);
235233
}
236234

src/main/java/ch/jalu/typeresolver/numbers/StandardValueRange.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,27 +143,23 @@ public String toString() {
143143
return "StandardValueRange[" + name() + "]";
144144
}
145145

146-
@Nullable
147146
@Override
148-
public BigDecimal getMinValue() {
147+
public @Nullable BigDecimal getMinValue() {
149148
return min;
150149
}
151150

152-
@Nullable
153151
@Override
154-
public BigDecimal getMaxValue() {
152+
public @Nullable BigDecimal getMaxValue() {
155153
return max;
156154
}
157155

158-
@Nullable
159156
@Override
160-
public Number getMinInOwnType() {
157+
public @Nullable Number getMinInOwnType() {
161158
return minInOwnType;
162159
}
163160

164-
@Nullable
165161
@Override
166-
public Number getMaxInOwnType() {
162+
public @Nullable Number getMaxInOwnType() {
167163
return maxInOwnType;
168164
}
169165
}

src/main/java/ch/jalu/typeresolver/numbers/ValueRange.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,22 @@ public interface ValueRange<T> {
1414
/**
1515
* @return the minimum value this type can represent; null if there is no explicit bound
1616
*/
17-
@Nullable
18-
BigDecimal getMinValue();
17+
@Nullable BigDecimal getMinValue();
1918

2019
/**
2120
* @return the maximum value this type can represent; null if there is no explicit bound
2221
*/
23-
@Nullable
24-
BigDecimal getMaxValue();
22+
@Nullable BigDecimal getMaxValue();
2523

2624
/**
2725
* @return the smallest finite value the type can represent, in the type itself (null if the type has no limit)
2826
*/
29-
@Nullable
30-
T getMinInOwnType();
27+
@Nullable T getMinInOwnType();
3128

3229
/**
3330
* @return the largest finite value the type can represent, in the type itself (null if the type has no limit)
3431
*/
35-
@Nullable
36-
T getMaxInOwnType();
32+
@Nullable T getMaxInOwnType();
3733

3834
/**
3935
* @return true if this value can represent decimals, false otherwise

src/main/java/ch/jalu/typeresolver/primitives/PrimitiveType.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ public boolean matches(@Nullable Class<?> clazz) {
8585
* @param clazz the class to search for (primitive or reference type of a primitive-reference class pair)
8686
* @return the corresponding entry, or null if not applicable
8787
*/
88-
@Nullable
89-
public static PrimitiveType from(Class<?> clazz) {
88+
public static @Nullable PrimitiveType from(Class<?> clazz) {
9089
return PRIMITIVES_BY_CLASS.get(clazz);
9190
}
9291

0 commit comments

Comments
 (0)