Merge "Sort the enum types alphabetically." into main

This commit is contained in:
Treehugger Robot 2024-03-19 02:37:16 +00:00 committed by Android (Google) Code Review
commit c26e3123f3
2 changed files with 966 additions and 955 deletions

View file

@ -47,7 +47,9 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.lang.reflect.Field;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
@ -321,7 +323,6 @@ public final class EmuMetadataGenerator {
ValueField field = new ValueField(name, propertyId);
List<JavadocBlockTag> blockTags = doc.getBlockTags();
List<Integer> dataEnums = new ArrayList<>();
for (int j = 0; j < blockTags.size(); j++) {
String commentTagName = blockTags.get(j).getTagName();
String commentTagContent = blockTags.get(j).getContent().toText();
@ -344,6 +345,16 @@ public final class EmuMetadataGenerator {
enumTypes.add(dataEnum);
}
// Sort the enum types based on their packageName, name.
// Make sure VehicleProperty is always at the first.
Collections.sort(enumTypes.subList(1, enumTypes.size()), (Enum enum1, Enum enum2) -> {
var collator = Collator.getInstance();
if (enum1.packageName.equals(enum2.packageName)) {
return collator.compare(enum1.name, enum2.name);
}
return collator.compare(enum1.packageName, enum2.packageName);
});
// Output enumTypes as JSON to output.
JSONArray jsonEnums = new JSONArray();
for (int i = 0; i < enumTypes.size(); i++) {