package net.divlight.retainer;

import java.util.ArrayList;
import java.util.List;

public class ObjectClassNameBuilder {
    private static final String RETAINER_CLASS_SUFFIX = "_Retainer";

    private final String targetClassSimpleName;
    private final List<String> enclosingClassSimpleNames = new ArrayList<>();

    public ObjectClassNameBuilder(String targetClassSimpleName) {
        this.targetClassSimpleName = targetClassSimpleName;
    }

    public ObjectClassNameBuilder addEnclosingClassSimpleName(String enclosingClassSimpleName) {
        enclosingClassSimpleNames.add(enclosingClassSimpleName);
        return this;
    }

    public String build() {
        String name = "";
        for (String enclosingClassSimpleName : enclosingClassSimpleNames) {
            name += enclosingClassSimpleName + "$";
        }
        return name + targetClassSimpleName + RETAINER_CLASS_SUFFIX;
    }
}

@@ -53,16 +53,46 @@
 ayList;%0A
+import java.util.Collections;%0A
 import j
@@ -719,16 +719,72 @@
 e = %22%22;%0A
+        Collections.reverse(enclosingClassSimpleNames);%0A
         

Fix an issue that generated object name may be improper #5