Skip to content

Commit

Permalink
Added a few missing @Nullable annotations to JavaType
Browse files Browse the repository at this point in the history
  • Loading branch information
knutwannheden committed Dec 5, 2024
1 parent efc38e3 commit 6530337
Showing 1 changed file with 49 additions and 46 deletions.
95 changes: 49 additions & 46 deletions rewrite-java/src/main/java/org/openrewrite/java/tree/JavaType.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
*/
package org.openrewrite.java.tree;

import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.With;
Expand Down Expand Up @@ -102,15 +105,15 @@ public MultiCatch(@Nullable List<JavaType> throwableTypes) {
this.throwableTypes = arrayOrNullIfEmpty(throwableTypes, EMPTY_JAVA_TYPE_ARRAY);
}

MultiCatch(JavaType @Nullable[] throwableTypes) {
MultiCatch(JavaType @Nullable [] throwableTypes) {
this.throwableTypes = nullIfEmpty(throwableTypes);
}

@JsonCreator
MultiCatch() {
}

private JavaType[] throwableTypes;
private JavaType @Nullable [] throwableTypes;

public List<JavaType> getThrowableTypes() {
if (throwableTypes == null) {
Expand Down Expand Up @@ -143,15 +146,15 @@ public Intersection(@Nullable List<JavaType> bounds) {
this.bounds = arrayOrNullIfEmpty(bounds, EMPTY_JAVA_TYPE_ARRAY);
}

Intersection(JavaType @Nullable[] throwableTypes) {
Intersection(JavaType @Nullable [] throwableTypes) {
this.bounds = nullIfEmpty(throwableTypes);
}

@JsonCreator
Intersection() {
}

private JavaType[] bounds;
private JavaType @Nullable [] bounds;

public List<JavaType> getBounds() {
if (bounds == null) {
Expand Down Expand Up @@ -320,16 +323,16 @@ public String getPackageName() {

public boolean isAssignableTo(String fullyQualifiedName) {
return TypeUtils.fullyQualifiedNamesAreEqual(getFullyQualifiedName(), fullyQualifiedName) ||
getInterfaces().stream().anyMatch(anInterface -> anInterface.isAssignableTo(fullyQualifiedName)) ||
(getSupertype() != null && getSupertype().isAssignableTo(fullyQualifiedName));
getInterfaces().stream().anyMatch(anInterface -> anInterface.isAssignableTo(fullyQualifiedName)) ||
(getSupertype() != null && getSupertype().isAssignableTo(fullyQualifiedName));
}

public boolean isAssignableFrom(@Nullable JavaType type) {
if (type instanceof FullyQualified) {
FullyQualified clazz = (FullyQualified) type;
return TypeUtils.fullyQualifiedNamesAreEqual(getFullyQualifiedName(), clazz.getFullyQualifiedName()) ||
isAssignableFrom(clazz.getSupertype()) ||
clazz.getInterfaces().stream().anyMatch(this::isAssignableFrom);
isAssignableFrom(clazz.getSupertype()) ||
clazz.getInterfaces().stream().anyMatch(this::isAssignableFrom);
} else if (type instanceof GenericTypeVariable) {
GenericTypeVariable generic = (GenericTypeVariable) type;
for (JavaType bound : generic.getBounds()) {
Expand Down Expand Up @@ -372,7 +375,7 @@ class Class extends FullyQualified {
Kind kind;

@NonFinal
JavaType @Nullable[] typeParameters;
JavaType @Nullable [] typeParameters;

@With
@Nullable
Expand All @@ -386,7 +389,7 @@ class Class extends FullyQualified {


@NonFinal
FullyQualified @Nullable[] annotations;
FullyQualified @Nullable [] annotations;

public Class(@Nullable Integer managedReference, long flagsBitMap, String fullyQualifiedName,
Kind kind, @Nullable List<JavaType> typeParameters, @Nullable FullyQualified supertype, @Nullable FullyQualified owningClass,
Expand All @@ -408,9 +411,9 @@ public Class(@Nullable Integer managedReference, long flagsBitMap, String fullyQ
}

Class(@Nullable Integer managedReference, long flagsBitMap, String fullyQualifiedName,
Kind kind, JavaType @Nullable[] typeParameters, @Nullable FullyQualified supertype, @Nullable FullyQualified owningClass,
FullyQualified @Nullable[] annotations, FullyQualified @Nullable[] interfaces,
Variable @Nullable[] members, Method @Nullable[] methods) {
Kind kind, JavaType @Nullable [] typeParameters, @Nullable FullyQualified supertype, @Nullable FullyQualified owningClass,
FullyQualified @Nullable [] annotations, FullyQualified @Nullable [] interfaces,
Variable @Nullable [] members, Method @Nullable [] methods) {
this.managedReference = managedReference;
this.flagsBitMap = flagsBitMap & Flag.VALID_CLASS_FLAGS;
this.fullyQualifiedName = fullyQualifiedName;
Expand Down Expand Up @@ -445,7 +448,7 @@ public Class withAnnotations(@Nullable List<FullyQualified> annotations) {


@NonFinal
FullyQualified @Nullable[] interfaces;
FullyQualified @Nullable [] interfaces;

@Override
public List<FullyQualified> getInterfaces() {
Expand All @@ -463,7 +466,7 @@ public Class withInterfaces(@Nullable List<FullyQualified> interfaces) {


@NonFinal
Variable @Nullable[] members;
Variable @Nullable [] members;

@Override
public List<Variable> getMembers() {
Expand All @@ -481,7 +484,7 @@ public Class withMembers(@Nullable List<Variable> members) {


@NonFinal
Method @Nullable[] methods;
Method @Nullable [] methods;

@Override
public List<Method> getMethods() {
Expand Down Expand Up @@ -554,9 +557,9 @@ public Class unsafeSet(@Nullable List<JavaType> typeParameters, @Nullable FullyQ
return this;
}

public Class unsafeSet(JavaType @Nullable[] typeParameters, @Nullable FullyQualified supertype, @Nullable FullyQualified owningClass,
FullyQualified @Nullable[] annotations, FullyQualified @Nullable[] interfaces,
Variable @Nullable[] members, Method @Nullable[] methods) {
public Class unsafeSet(JavaType @Nullable [] typeParameters, @Nullable FullyQualified supertype, @Nullable FullyQualified owningClass,
FullyQualified @Nullable [] annotations, FullyQualified @Nullable [] interfaces,
Variable @Nullable [] members, Method @Nullable [] methods) {
//noinspection DuplicatedCode
this.typeParameters = ListUtils.nullIfEmpty(typeParameters);
this.supertype = supertype;
Expand All @@ -574,7 +577,7 @@ public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
Class aClass = (Class) o;
return TypeUtils.fullyQualifiedNamesAreEqual(fullyQualifiedName, aClass.fullyQualifiedName) &&
(typeParameters == null && aClass.typeParameters == null || typeParameters != null && Arrays.equals(typeParameters, aClass.typeParameters));
(typeParameters == null && aClass.typeParameters == null || typeParameters != null && Arrays.equals(typeParameters, aClass.typeParameters));
}

@Override
Expand Down Expand Up @@ -639,7 +642,7 @@ class Parameterized extends FullyQualified {
FullyQualified type;

@NonFinal
JavaType @Nullable[] typeParameters;
JavaType @Nullable [] typeParameters;

public Parameterized(@Nullable Integer managedReference, @Nullable FullyQualified type,
@Nullable List<JavaType> typeParameters) {
Expand All @@ -651,7 +654,7 @@ public Parameterized(@Nullable Integer managedReference, @Nullable FullyQualifie
}

Parameterized(@Nullable Integer managedReference, @Nullable FullyQualified type,
JavaType @Nullable[] typeParameters) {
JavaType @Nullable [] typeParameters) {
this.managedReference = managedReference;
this.type = unknownIfNull(type);
this.typeParameters = nullIfEmpty(typeParameters);
Expand Down Expand Up @@ -691,7 +694,7 @@ public Parameterized unsafeSet(@Nullable FullyQualified type, @Nullable List<Jav
return this;
}

public Parameterized unsafeSet(@Nullable FullyQualified type, JavaType @Nullable[] typeParameters) {
public Parameterized unsafeSet(@Nullable FullyQualified type, JavaType @Nullable [] typeParameters) {
assert type != this;
this.type = unknownIfNull(type);
this.typeParameters = ListUtils.nullIfEmpty(typeParameters);
Expand Down Expand Up @@ -791,7 +794,7 @@ class GenericTypeVariable implements JavaType {
Variance variance;

@NonFinal
JavaType @Nullable[] bounds;
JavaType @Nullable [] bounds;

public GenericTypeVariable(@Nullable Integer managedReference, String name, Variance variance, @Nullable List<JavaType> bounds) {
this(
Expand All @@ -802,7 +805,7 @@ public GenericTypeVariable(@Nullable Integer managedReference, String name, Vari
);
}

GenericTypeVariable(@Nullable Integer managedReference, String name, Variance variance, JavaType @Nullable[] bounds) {
GenericTypeVariable(@Nullable Integer managedReference, String name, Variance variance, JavaType @Nullable [] bounds) {
this.managedReference = managedReference;
this.name = name;
this.variance = variance;
Expand Down Expand Up @@ -838,7 +841,7 @@ public GenericTypeVariable unsafeSet(String name, Variance variance, @Nullable L
return this;
}

public GenericTypeVariable unsafeSet(String name, Variance variance, JavaType @Nullable[] bounds) {
public GenericTypeVariable unsafeSet(String name, Variance variance, JavaType @Nullable [] bounds) {
this.name = name;
this.variance = variance;
this.bounds = ListUtils.nullIfEmpty(bounds);
Expand All @@ -851,7 +854,7 @@ public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
GenericTypeVariable that = (GenericTypeVariable) o;
return name.equals(that.name) && variance == that.variance &&
(variance == Variance.INVARIANT && bounds == null && that.bounds == null || bounds != null && Arrays.equals(bounds, that.bounds));
(variance == Variance.INVARIANT && bounds == null && that.bounds == null || bounds != null && Arrays.equals(bounds, that.bounds));
}

@Override
Expand Down Expand Up @@ -879,9 +882,9 @@ class Array implements JavaType {


@NonFinal
FullyQualified @Nullable[] annotations;
FullyQualified @Nullable [] annotations;

public Array(@Nullable Integer managedReference, @Nullable JavaType elemType, FullyQualified @Nullable[] annotations) {
public Array(@Nullable Integer managedReference, @Nullable JavaType elemType, FullyQualified @Nullable [] annotations) {
this.managedReference = managedReference;
this.elemType = unknownIfNull(elemType);
this.annotations = ListUtils.nullIfEmpty(annotations);
Expand Down Expand Up @@ -913,7 +916,7 @@ public Array unsafeSetManagedReference(Integer id) {
return this;
}

public Array unsafeSet(JavaType elemType, FullyQualified @Nullable[] annotations) {
public Array unsafeSet(JavaType elemType, FullyQualified @Nullable [] annotations) {
this.elemType = unknownIfNull(elemType);
this.annotations = ListUtils.nullIfEmpty(annotations);
return this;
Expand Down Expand Up @@ -1099,16 +1102,16 @@ class Method implements JavaType {


@NonFinal
String @Nullable[] parameterNames;
String @Nullable [] parameterNames;

@NonFinal
JavaType @Nullable[] parameterTypes;
JavaType @Nullable [] parameterTypes;

@NonFinal
FullyQualified @Nullable[] thrownExceptions;
FullyQualified @Nullable [] thrownExceptions;

@NonFinal
FullyQualified @Nullable[] annotations;
FullyQualified @Nullable [] annotations;

@Incubating(since = "7.34.0")
@Nullable
Expand Down Expand Up @@ -1142,9 +1145,9 @@ public Method(@Nullable Integer managedReference, long flagsBitMap, @Nullable Fu
}

public Method(@Nullable Integer managedReference, long flagsBitMap, @Nullable FullyQualified declaringType, String name,
@Nullable JavaType returnType, String @Nullable[] parameterNames,
JavaType @Nullable[] parameterTypes, FullyQualified @Nullable[] thrownExceptions,
FullyQualified @Nullable[] annotations, @Nullable List<String> defaultValue) {
@Nullable JavaType returnType, String @Nullable [] parameterNames,
JavaType @Nullable [] parameterTypes, FullyQualified @Nullable [] thrownExceptions,
FullyQualified @Nullable [] annotations, @Nullable List<String> defaultValue) {
this.managedReference = managedReference;
this.flagsBitMap = flagsBitMap & Flag.VALID_FLAGS;
this.declaringType = unknownIfNull(declaringType);
Expand Down Expand Up @@ -1182,9 +1185,9 @@ public Method unsafeSet(@Nullable FullyQualified declaringType,

public Method unsafeSet(@Nullable FullyQualified declaringType,
@Nullable JavaType returnType,
JavaType @Nullable[] parameterTypes,
FullyQualified @Nullable[] thrownExceptions,
FullyQualified @Nullable[] annotations) {
JavaType @Nullable [] parameterTypes,
FullyQualified @Nullable [] thrownExceptions,
FullyQualified @Nullable [] annotations) {
this.declaringType = unknownIfNull(declaringType);
this.returnType = unknownIfNull(returnType);
this.parameterTypes = ListUtils.nullIfEmpty(parameterTypes);
Expand Down Expand Up @@ -1355,9 +1358,9 @@ public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
Method method = (Method) o;
return Objects.equals(declaringType, method.declaringType) &&
name.equals(method.name) &&
Objects.equals(returnType, method.returnType) &&
Arrays.equals(parameterTypes, method.parameterTypes);
name.equals(method.name) &&
Objects.equals(returnType, method.returnType) &&
Arrays.equals(parameterTypes, method.parameterTypes);
}

@Override
Expand Down Expand Up @@ -1393,7 +1396,7 @@ class Variable implements JavaType {
JavaType type;

@NonFinal
FullyQualified @Nullable[] annotations;
FullyQualified @Nullable [] annotations;

public Variable(@Nullable Integer managedReference, long flagsBitMap, String name, @Nullable JavaType owner,
@Nullable JavaType type, @Nullable List<FullyQualified> annotations) {
Expand All @@ -1408,7 +1411,7 @@ public Variable(@Nullable Integer managedReference, long flagsBitMap, String nam
}

Variable(@Nullable Integer managedReference, long flagsBitMap, String name, @Nullable JavaType owner,
@Nullable JavaType type, FullyQualified @Nullable[] annotations) {
@Nullable JavaType type, FullyQualified @Nullable [] annotations) {
this.managedReference = managedReference;
this.flagsBitMap = flagsBitMap & Flag.VALID_FLAGS;
this.name = name;
Expand Down

0 comments on commit 6530337

Please sign in to comment.