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

4.x: Use Hson.Struct instead of Hson.Object to prevent confusion with java.lang.Object #9080

Merged
merged 1 commit into from
Aug 1, 2024
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 @@ -92,16 +92,16 @@ private Stream<TypeInfo> typesToProcess(Set<TypeName> typeNames) {
}

private void storeMetadata() {
List<Hson.Object> root = new ArrayList<>();
List<Hson.Struct> root = new ArrayList<>();

for (var module : moduleTypes.entrySet()) {
String moduleName = module.getKey();
var types = module.getValue();
List<Hson.Object> typeArray = new ArrayList<>();
List<Hson.Struct> typeArray = new ArrayList<>();
types.forEach(it -> newOptions.get(it).write(typeArray));
root.add(Hson.objectBuilder()
root.add(Hson.structBuilder()
.set("module", moduleName)
.setObjects("types", typeArray)
.setStructs("types", typeArray)
.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ String prefix() {
return configured.prefix().orElse(null);
}

void write(List<Hson.Object> typeArray) {
var typeObject = Hson.Object.builder();
void write(List<Hson.Struct> typeArray) {
var typeObject = Hson.Struct.builder();

typeObject.set("type", targetClass());
typeObject.set("annotatedType", annotatedClass());
Expand All @@ -108,11 +108,11 @@ void write(List<Hson.Object> typeArray) {
.collect(Collectors.toList()));
}

List<Hson.Object> options = new ArrayList<>();
List<Hson.Struct> options = new ArrayList<>();
for (ConfiguredProperty property : allProperties) {
writeProperty(options, "", property);
}
typeObject.setObjects("options", options);
typeObject.setStructs("options", options);

typeArray.add(typeObject.build());
}
Expand All @@ -132,11 +132,11 @@ private static String paramsToString(List<TypeName> params) {
.collect(Collectors.joining(", "));
}

private void writeProperty(List<Hson.Object> optionsBuilder,
private void writeProperty(List<Hson.Struct> optionsBuilder,
String prefix,
ConfiguredProperty property) {

var optionBuilder = Hson.Object.builder();
var optionBuilder = Hson.Struct.builder();
if (property.key() != null && !property.key.isBlank()) {
optionBuilder.set("key", prefix(prefix, property.key()));
}
Expand Down Expand Up @@ -181,18 +181,18 @@ private void writeProperty(List<Hson.Object> optionsBuilder,
.forEach(it -> writeProperty(optionsBuilder, finalPrefix, it));
}
if (!property.allowedValues.isEmpty()) {
List<Hson.Object> allowedValues = new ArrayList<>();
List<Hson.Struct> allowedValues = new ArrayList<>();

for (ConfiguredOptionData.AllowedValue allowedValue : property.allowedValues) {
var allowedJson = Hson.Object.builder()
var allowedJson = Hson.Struct.builder()
.set("value", allowedValue.value());
if (!allowedValue.description().isBlank()) {
allowedJson.set("description", allowedValue.description().trim());
}
allowedValues.add(allowedJson.build());
}

optionBuilder.setObjects("allowedValues", allowedValues);
optionBuilder.setStructs("allowedValues", allowedValues);
}

optionsBuilder.add(optionBuilder.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,16 @@ private void storeMetadata() {
This is to allow merging of files - such as when we would want to create on-the-fly
JSON for a project with only its dependencies.
*/
List<Hson.Object> moduleArray = new ArrayList<>();
List<Hson.Struct> moduleArray = new ArrayList<>();

for (var module : moduleTypes.entrySet()) {
String moduleName = module.getKey();
var types = module.getValue();
List<Hson.Object> typeArray = new ArrayList<>();
List<Hson.Struct> typeArray = new ArrayList<>();
types.forEach(it -> newOptions.get(it).write(typeArray));
moduleArray.add(Hson.Object.builder()
moduleArray.add(Hson.Struct.builder()
.set("module", moduleName)
.setObjects("types", typeArray)
.setStructs("types", typeArray)
.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ String prefix() {
return configured.prefix().orElse(null);
}

void write(List<Hson.Object> typeArray) {
var typeObject = Hson.Object.builder();
void write(List<Hson.Struct> typeArray) {
var typeObject = Hson.Struct.builder();

typeObject.set("type", targetClass());
typeObject.set("annotatedType", annotatedClass());
Expand All @@ -108,11 +108,11 @@ void write(List<Hson.Object> typeArray) {
.collect(Collectors.toList()));
}

List<Hson.Object> options = new ArrayList<>();
List<Hson.Struct> options = new ArrayList<>();
for (ConfiguredProperty property : allProperties) {
writeProperty(options, "", property);
}
typeObject.setObjects("options", options);
typeObject.setStructs("options", options);

typeArray.add(typeObject.build());
}
Expand All @@ -132,11 +132,11 @@ private static String paramsToString(List<TypeName> params) {
.collect(Collectors.joining(", "));
}

private void writeProperty(List<Hson.Object> optionsBuilder,
private void writeProperty(List<Hson.Struct> optionsBuilder,
String prefix,
ConfiguredProperty property) {

var optionBuilder = Hson.Object.builder();
var optionBuilder = Hson.Struct.builder();
if (property.key() != null && !property.key.isBlank()) {
optionBuilder.set("key", prefix(prefix, property.key()));
}
Expand Down Expand Up @@ -181,16 +181,16 @@ private void writeProperty(List<Hson.Object> optionsBuilder,
.forEach(it -> writeProperty(optionsBuilder, finalPrefix, it));
}
if (!property.allowedValues.isEmpty()) {
List<Hson.Object> allowedValues = new ArrayList<>();
List<Hson.Struct> allowedValues = new ArrayList<>();

for (ConfiguredOptionData.AllowedValue allowedValue : property.allowedValues) {
allowedValues.add(Hson.Object.builder()
allowedValues.add(Hson.Struct.builder()
.set("value", allowedValue.value())
.set("description", allowedValue.description())
.build());
}

optionBuilder.setObjects("allowedValues", allowedValues);
optionBuilder.setStructs("allowedValues", allowedValues);
}

optionsBuilder.add(optionBuilder.build());
Expand Down
Loading