Skip to content

Commit

Permalink
collections and optionals work now
Browse files Browse the repository at this point in the history
  • Loading branch information
Lavanya Singh committed Feb 10, 2023
1 parent ba1f619 commit be32776
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 320 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,19 @@ public static MethodSpec.Builder createOptionalSetterBuilder(

public static MethodSpec.Builder createItemSetterBuilder(
EnrichedField enriched, Type itemType, TypeMapper typeMapper, ClassName returnClass) {
return createItemSetterBuilder(enriched, itemType, typeMapper, returnClass, Optional.empty());
}

public static MethodSpec.Builder createItemSetterBuilder(
EnrichedField enriched,
Type itemType,
TypeMapper typeMapper,
ClassName returnClass,
Optional<LogSafety> safety) {
FieldSpec field = enriched.poetSpec();
return publicSetter(enriched, returnClass).addParameter(typeMapper.getClassName(itemType), field.name);
return publicSetter(enriched, returnClass)
.addParameter(
typeMapper.getClassName(itemType).annotated(ConjureAnnotations.safety(safety)), field.name);
}

public static MethodSpec.Builder createMapSetterBuilder(
Expand All @@ -98,14 +109,13 @@ public static MethodSpec.Builder publicSetter(EnrichedField enriched, ClassName
.returns(returnClass);
}

public static TypeName widenParameterIfPossible(
TypeName current, Type type, TypeMapper typeMapper, Optional<LogSafety> safety) {
public static TypeName widenParameterIfPossible(TypeName current, Type type, TypeMapper typeMapper) {
// if inner type name is external
if (type.accept(TypeVisitor.IS_LIST)) {
Type innerType = type.accept(TypeVisitor.LIST).getItemType();
TypeName innerTypeName = typeMapper.getClassName(innerType).box();
if (isWidenableContainedType(innerType)) {
innerTypeName = WildcardTypeName.subtypeOf(innerTypeName).annotated(ConjureAnnotations.safety(safety));
innerTypeName = WildcardTypeName.subtypeOf(innerTypeName);
}
return ParameterizedTypeName.get(ClassName.get(Iterable.class), innerTypeName);
}
Expand All @@ -114,7 +124,7 @@ public static TypeName widenParameterIfPossible(
Type innerType = type.accept(TypeVisitor.SET).getItemType();
TypeName innerTypeName = typeMapper.getClassName(innerType).box();
if (isWidenableContainedType(innerType)) {
innerTypeName = WildcardTypeName.subtypeOf(innerTypeName).annotated(ConjureAnnotations.safety(safety));
innerTypeName = WildcardTypeName.subtypeOf(innerTypeName);
}

return ParameterizedTypeName.get(ClassName.get(Iterable.class), innerTypeName);
Expand All @@ -126,19 +136,12 @@ public static TypeName widenParameterIfPossible(
return current;
}
TypeName innerTypeName = typeMapper.getClassName(innerType).box();
WildcardTypeName wildcard =
WildcardTypeName.subtypeOf(innerTypeName).annotated(ConjureAnnotations.safety(safety));
ParameterizedTypeName p = ParameterizedTypeName.get(ClassName.get(Optional.class), wildcard);
return p;
return ParameterizedTypeName.get(ClassName.get(Optional.class), WildcardTypeName.subtypeOf(innerTypeName));
}

return current;
}

public static TypeName widenParameterIfPossible(TypeName current, Type type, TypeMapper typeMapper) {
return widenParameterIfPossible(current, type, typeMapper, Optional.empty());
}

// we want to widen containers of anything that's not a primitive, a conjure reference or an optional
// since we know all of those are final.
public static boolean isWidenableContainedType(Type containedType) {
Expand Down
Loading

0 comments on commit be32776

Please sign in to comment.