Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply minor cleanups suggested by IntelliJ in generics code #860

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public Boolean visitClassType(Type.ClassType lhsType, Type rhsType) {
Types types = state.getTypes();
// The base type of rhsType may be a subtype of lhsType's base type. In such cases, we must
// compare lhsType against the supertype of rhsType with a matching base type.
rhsType = (Type.ClassType) types.asSuper(rhsType, lhsType.tsym);
rhsType = types.asSuper(rhsType, lhsType.tsym);
// This is impossible, considering the fact that standard Java subtyping succeeds before
// running NullAway
if (rhsType == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public final class GenericsChecks {

/**
* Supplier for the JSpecify {@code @Nullable} annotation. Required since for now, certain checks
* related to generics specifically look for {@code @org.jspecify.ananotations.Nullable}
* related to generics specifically look for {@code @org.jspecify.annotations.Nullable}
* annotations and do not apply to other {@code @Nullable} annotations.
*/
static final Supplier<Type> JSPECIFY_NULLABLE_TYPE_SUPPLIER =
Expand All @@ -64,7 +64,7 @@ public static void checkInstantiationForParameterizedTypedTree(
return;
}
List<? extends Tree> typeArguments = tree.getTypeArguments();
if (typeArguments.size() == 0) {
if (typeArguments.isEmpty()) {
return;
}
Map<Integer, Tree> nullableTypeArguments = new HashMap<>();
Expand Down Expand Up @@ -302,8 +302,7 @@ public static void checkTypeParameterNullnessForAssignability(
Type rhsType = getTreeType(rhsTree, state);

if (lhsType instanceof Type.ClassType && rhsType instanceof Type.ClassType) {
boolean isAssignmentValid =
compareNullabilityAnnotations((Type.ClassType) lhsType, (Type.ClassType) rhsType, state);
boolean isAssignmentValid = compareNullabilityAnnotations(lhsType, rhsType, state);
if (!isAssignmentValid) {
reportInvalidAssignmentInstantiationError(tree, lhsType, rhsType, state, analysis);
}
Expand Down Expand Up @@ -337,8 +336,7 @@ public static void checkTypeParameterNullnessForFunctionReturnType(
if (formalReturnType instanceof Type.ClassType
&& returnExpressionType instanceof Type.ClassType) {
boolean isReturnTypeValid =
compareNullabilityAnnotations(
(Type.ClassType) formalReturnType, (Type.ClassType) returnExpressionType, state);
compareNullabilityAnnotations(formalReturnType, returnExpressionType, state);
if (!isReturnTypeValid) {
reportInvalidReturnTypeError(
retExpr, formalReturnType, returnExpressionType, state, analysis);
Expand Down Expand Up @@ -411,15 +409,13 @@ public static void checkTypeParameterNullnessForConditionalExpression(
// type of the whole expression
if (condExprType instanceof Type.ClassType) {
if (truePartType instanceof Type.ClassType) {
if (!compareNullabilityAnnotations(
(Type.ClassType) condExprType, (Type.ClassType) truePartType, state)) {
if (!compareNullabilityAnnotations(condExprType, truePartType, state)) {
reportMismatchedTypeForTernaryOperator(
truePartTree, condExprType, truePartType, state, analysis);
}
}
if (falsePartType instanceof Type.ClassType) {
if (!compareNullabilityAnnotations(
(Type.ClassType) condExprType, (Type.ClassType) falsePartType, state)) {
if (!compareNullabilityAnnotations(condExprType, falsePartType, state)) {
reportMismatchedTypeForTernaryOperator(
falsePartTree, condExprType, falsePartType, state, analysis);
}
Expand Down Expand Up @@ -458,8 +454,7 @@ public static void compareGenericTypeParameterNullabilityForCall(
Type actualParameter = getTreeType(actualParams.get(i), state);
if (formalParameter instanceof Type.ClassType
&& actualParameter instanceof Type.ClassType) {
if (!compareNullabilityAnnotations(
(Type.ClassType) formalParameter, (Type.ClassType) actualParameter, state)) {
if (!compareNullabilityAnnotations(formalParameter, actualParameter, state)) {
reportInvalidParametersNullabilityError(
formalParameter, actualParameter, actualParams.get(i), state, analysis);
}
Expand All @@ -470,13 +465,12 @@ public static void compareGenericTypeParameterNullabilityForCall(
Type.ArrayType varargsArrayType =
(Type.ArrayType) formalParams.get(formalParams.size() - 1).type;
Type varargsElementType = varargsArrayType.elemtype;
if (varargsElementType.getTypeArguments().size() > 0) {
if (!varargsElementType.getTypeArguments().isEmpty()) {
for (int i = formalParams.size() - 1; i < actualParams.size(); i++) {
Type actualParameter = getTreeType(actualParams.get(i), state);
if (varargsElementType instanceof Type.ClassType
&& actualParameter instanceof Type.ClassType) {
if (!compareNullabilityAnnotations(
(Type.ClassType) varargsElementType, (Type.ClassType) actualParameter, state)) {
if (!compareNullabilityAnnotations(varargsElementType, actualParameter, state)) {
reportInvalidParametersNullabilityError(
varargsElementType, actualParameter, actualParams.get(i), state, analysis);
}
Expand Down Expand Up @@ -786,9 +780,7 @@ private static void checkTypeParameterNullnessForOverridingMethodParameterType(
if (overriddenMethodParameterType instanceof Type.ClassType
&& overridingMethodParameterType instanceof Type.ClassType) {
if (!compareNullabilityAnnotations(
(Type.ClassType) overriddenMethodParameterType,
(Type.ClassType) overridingMethodParameterType,
state)) {
overriddenMethodParameterType, overridingMethodParameterType, state)) {
reportInvalidOverridingMethodParamTypeError(
methodParameters.get(i),
overriddenMethodParameterType,
Expand Down Expand Up @@ -819,9 +811,7 @@ private static void checkTypeParameterNullnessForOverridingMethodReturnType(
}
Preconditions.checkArgument(overridingMethodReturnType instanceof Type.ClassType);
if (!compareNullabilityAnnotations(
(Type.ClassType) overriddenMethodReturnType,
(Type.ClassType) overridingMethodReturnType,
state)) {
overriddenMethodReturnType, overridingMethodReturnType, state)) {
reportInvalidOverridingMethodReturnTypeError(
tree, overriddenMethodReturnType, overridingMethodReturnType, analysis, state);
}
Expand Down