1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package gov.nist.secauto.metaschema.schemagen;
7   
8   import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition;
9   import gov.nist.secauto.metaschema.core.model.IDefinition;
10  import gov.nist.secauto.metaschema.core.model.IModule;
11  
12  import java.io.IOException;
13  import java.util.Collection;
14  import java.util.Locale;
15  
16  import edu.umd.cs.findbugs.annotations.NonNull;
17  import edu.umd.cs.findbugs.annotations.Nullable;
18  
19  public interface IGenerationState<WRITER> {
20    @NonNull
21    IModule getModule();
22  
23    @NonNull
24    WRITER getWriter();
25  
26    @NonNull
27    default Collection<? extends IAssemblyDefinition> getRootDefinitions() {
28      return getModule().getExportedRootAssemblyDefinitions();
29    }
30  
31    boolean isInline(@NonNull IDefinition definition);
32  
33    void flushWriter() throws IOException;
34  
35    @NonNull
36    String getTypeNameForDefinition(@NonNull IDefinition definition, @Nullable String suffix);
37  
38    @NonNull
39    static CharSequence toCamelCase(String text) {
40      StringBuilder builder = new StringBuilder();
41      for (String segment : text.split("\\p{Punct}")) {
42        if (segment.length() > 0) {
43          builder.append(segment.substring(0, 1).toUpperCase(Locale.ROOT));
44        }
45        if (segment.length() > 1) {
46          builder.append(segment.substring(1).toLowerCase(Locale.ROOT));
47        }
48      }
49      return builder;
50    }
51  }