Skip to content

Commit

Permalink
refactor: pass TypeRef instead of Optional to CustomResourceInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
metacosm authored and manusa committed Mar 12, 2021
1 parent 1172840 commit afab4f4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class CustomResourceInfo {

public CustomResourceInfo(String group, String version, String kind, String singular,
String plural, String[] shortNames, boolean storage, boolean served,
Scope scope, Optional<TypeRef> status, TypeDef definition, String crClassName,
Scope scope, TypeRef status, TypeDef definition, String crClassName,
String specClassName, String statusClassName) {
this.group = group;
this.version = version;
Expand All @@ -58,7 +58,7 @@ public CustomResourceInfo(String group, String version, String kind, String sing
this.storage = storage;
this.served = served;
this.scope = scope;
this.status = status;
this.status = Optional.ofNullable(status);
this.definition = definition;
this.crClassName = crClassName;
this.specClassName = specClassName;
Expand Down Expand Up @@ -157,7 +157,7 @@ public static CustomResourceInfo fromClass(Class<? extends CustomResource> custo

// this works because CustomResource is an abstract class
String specClassName = null, statusClassName = null;
Optional<TypeRef> statusType = Optional.empty();
TypeRef statusType = null;
if (genericSuperclass instanceof ParameterizedType) {
final Type[] types = ((ParameterizedType) genericSuperclass).getActualTypeArguments();
if (types.length == 2) {
Expand All @@ -168,7 +168,7 @@ public static CustomResourceInfo fromClass(Class<? extends CustomResource> custo
// load status class
final Class<?> statusClass = Thread.currentThread().getContextClassLoader()
.loadClass(statusClassName);
statusType = Optional.of(ClassTo.TYPEDEF.apply(statusClass).toReference());
statusType = ClassTo.TYPEDEF.apply(statusClass).toReference();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ private CustomResourceInfo toCustomResourceInfo(TypeElement customResource) {
}
final TypeElement spec = ((TypeElement) ((DeclaredType) typeArguments.get(0)).asElement());
final TypeElement status = ((TypeElement) ((DeclaredType) typeArguments.get(1)).asElement());
Optional<TypeRef> statusType = Optional.empty();
TypeRef statusType = null;
if (!status.getQualifiedName().contentEquals(Void.class.getCanonicalName())) {
statusType = Optional.of(ElementTo.TYPEDEF.apply(status).toReference());
statusType = ElementTo.TYPEDEF.apply(status).toReference();
}

final String group = customResource.getAnnotation(Group.class).value();
Expand Down

0 comments on commit afab4f4

Please sign in to comment.