001/*
002 * SPDX-FileCopyrightText: none
003 * SPDX-License-Identifier: CC0-1.0
004 */
005
006package gov.nist.secauto.metaschema.schemagen;
007
008import gov.nist.secauto.metaschema.core.model.IAssemblyDefinition;
009import gov.nist.secauto.metaschema.core.model.IDefinition;
010import gov.nist.secauto.metaschema.core.model.IModule;
011
012import java.io.IOException;
013import java.util.Collection;
014import java.util.Locale;
015
016import edu.umd.cs.findbugs.annotations.NonNull;
017import edu.umd.cs.findbugs.annotations.Nullable;
018
019public interface IGenerationState<WRITER> {
020  @NonNull
021  IModule getModule();
022
023  @NonNull
024  WRITER getWriter();
025
026  @NonNull
027  default Collection<? extends IAssemblyDefinition> getRootDefinitions() {
028    return getModule().getExportedRootAssemblyDefinitions();
029  }
030
031  boolean isInline(@NonNull IDefinition definition);
032
033  void flushWriter() throws IOException;
034
035  @NonNull
036  String getTypeNameForDefinition(@NonNull IDefinition definition, @Nullable String suffix);
037
038  @NonNull
039  static CharSequence toCamelCase(String text) {
040    StringBuilder builder = new StringBuilder();
041    for (String segment : text.split("\\p{Punct}")) {
042      if (segment.length() > 0) {
043        builder.append(segment.substring(0, 1).toUpperCase(Locale.ROOT));
044      }
045      if (segment.length() > 1) {
046        builder.append(segment.substring(1).toLowerCase(Locale.ROOT));
047      }
048    }
049    return builder;
050  }
051}