LinkageOptimizations #48

Zusammengeführt
Lixfel hat 5 Commits von LinkageOptimizations nach master 2023-03-01 20:07:48 +01:00 zusammengeführt
Nur Änderungen aus Commit 4f4caac67f werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -173,18 +173,15 @@ public class LinkageProcessor extends AbstractProcessor {
Map<String, MethodBuilder> methods = new HashMap<>();
for (Map.Entry<Set<String>, List<TypeElement>> entry : groupedByChecks.entrySet()) {
Map<String, Map<LinkageType, List<TypeElement>>> groupedByMethod = new HashMap<>();
Map<String, Map<TypeElement, List<LinkageType>>> groupedByMethod = new HashMap<>();
for (TypeElement typeElement : entry.getValue()) {
for (Map.Entry<String, List<LinkageType>> linkages : getLinkagesOfType(typeElement).entrySet()) {
Map<LinkageType, List<TypeElement>> internalGroup = groupedByMethod.computeIfAbsent(linkages.getKey(), s -> new HashMap<>());
for (LinkageType linkageType : linkages.getValue()) {
List<TypeElement> list = internalGroup.computeIfAbsent(linkageType, s -> new ArrayList<>());
list.add(typeElement);
}
groupedByMethod.computeIfAbsent(linkages.getKey(), ignored -> new HashMap<>())
.put(typeElement, linkages.getValue());
}
}
for (Map.Entry<String, Map<LinkageType, List<TypeElement>>> group : groupedByMethod.entrySet()) {
for (Map.Entry<String, Map<TypeElement, List<LinkageType>>> group : groupedByMethod.entrySet()) {
MethodBuilder method = methods.computeIfAbsent(group.getKey(), s -> {
MethodBuilder methodBuilder = new MethodBuilder(s, "void");
buildPlan.addMethod(methodBuilder);
@ -192,10 +189,17 @@ public class LinkageProcessor extends AbstractProcessor {
});
if (!entry.getKey().isEmpty()) method.addLine("if (" + String.join(" && ", entry.getKey()) + ") {");
for (Map.Entry<LinkageType, List<TypeElement>> toGenerate : group.getValue().entrySet()) {
toGenerate.getValue().forEach(typeElement -> {
for (Map.Entry<TypeElement, List<LinkageType>> toGenerate : group.getValue().entrySet()) {
TypeElement typeElement = toGenerate.getKey();
String instance = getElement(typeElement, neededFields);
if (toGenerate.getValue().size() > 1 && instance.startsWith("new ")) {
method.addLine(typeElement.getSimpleName() + " local" + typeElement.getSimpleName().toString() + " = " + instance + ";");
instance = "local" + typeElement.getSimpleName().toString();
}
String finalInstance = instance;
toGenerate.getValue().forEach(linkageType -> {
buildPlan.addImport(typeElement.getQualifiedName().toString());
toGenerate.getKey().generateCode(buildPlan, method, getElement(typeElement, neededFields), typeElement);
linkageType.generateCode(buildPlan, method, finalInstance, typeElement);
});
}
if (!entry.getKey().isEmpty()) method.addLine("}");