public Generator()

in tooling/rib-intellij-plugin/src/main/java/com/uber/presidio/intellij_plugin/generator/Generator.java [63:108]


  public Generator(String packageName, String ribName, boolean isKotlin, String templateName) {
    this.packageName = packageName;
    this.ribName = ribName;
    this.isKotlin = isKotlin;

    templateValuesMap = new HashMap<String, String>();
    templateValuesMap.put(TEMPLATE_TOKEN_PACKAGE_NAME, packageName);
    templateValuesMap.put(TEMPLATE_TOKEN_RIBLET_NAME, ribName);
    templateValuesMap.put(TEMPLATE_TOKEN_RIBLET_NAME_TO_LOWER, ribName.toLowerCase());

    try {
      String[] resources = getResourceListing(this.getClass(), "partials/");
      for (String resourceName : resources) {
        if (resourceName == null || resourceName.length() == 0) {
          continue;
        }
        InputStream resourceAsStream =
            Generator.class.getResourceAsStream("/partials/" + resourceName);
        String resourceContents =
            Preconditions.checkNotNull(
                CharStreams.toString(new InputStreamReader(resourceAsStream, Charsets.UTF_8)));
        templateValuesMap.put(String.format("partial: %s", resourceName), resourceContents);
      }
    } catch (IOException e) {
      throw new RuntimeException(e);
    } catch (URISyntaxException e) {
      throw new RuntimeException(e);
    }
    try {
      // Need to use getResourceAsStream() since we may be reading resources from inside a jar.
      // Class.getResource() doesn't work in this scenario.

      String resource = "/templates/java/" + templateName + ".java.template";

      if (isKotlin) {
        resource = "/templates/kotlin/" + templateName + ".kt.template";
      }

      InputStream resourceAsStream1 = Generator.class.getResourceAsStream(resource);
      templateString =
          Preconditions.checkNotNull(
              CharStreams.toString(new InputStreamReader(resourceAsStream1, Charsets.UTF_8)));
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }