Generator.java

  1. /*
  2.  * Copyright 2015-2016 Providence Authors
  3.  *
  4.  * Licensed to the Apache Software Foundation (ASF) under one
  5.  * or more contributor license agreements. See the NOTICE file
  6.  * distributed with this work for additional information
  7.  * regarding copyright ownership. The ASF licenses this file
  8.  * to you under the Apache License, Version 2.0 (the
  9.  * "License"); you may not use this file except in compliance
  10.  * with the License. You may obtain a copy of the License at
  11.  *
  12.  *   http://www.apache.org/licenses/LICENSE-2.0
  13.  *
  14.  * Unless required by applicable law or agreed to in writing,
  15.  * software distributed under the License is distributed on an
  16.  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17.  * KIND, either express or implied. See the License for the
  18.  * specific language governing permissions and limitations
  19.  * under the License.
  20.  */
  21. package net.morimekta.providence.generator;

  22. import net.morimekta.providence.generator.util.FileManager;
  23. import net.morimekta.providence.reflect.GlobalRegistry;
  24. import net.morimekta.providence.reflect.ProgramRegistry;

  25. import java.io.IOException;
  26. import java.nio.file.Path;
  27. import java.util.Collection;

  28. /**
  29.  */
  30. public abstract class Generator {
  31.     private final FileManager fileManager;

  32.     public Generator(FileManager manager) {
  33.         fileManager = manager;
  34.     }

  35.     /**
  36.      * @return The local file manager.
  37.      */
  38.     protected final FileManager getFileManager() {
  39.         return fileManager;
  40.     }

  41.     /**
  42.      * Each compiler must implement this method.
  43.      *
  44.      * @param registry The typed and scoped registry for the program.
  45.      * @throws IOException If a file could not be written.
  46.      * @throws GeneratorException If some part of the file code could not be generated (invalid content).
  47.      */
  48.     public abstract void generate(ProgramRegistry registry) throws IOException, GeneratorException;

  49.     /**
  50.      * Generate anything that is dependent on the global scope, or not
  51.      * directly connected to a single program.
  52.      *
  53.      * @param registry The global program registry.
  54.      * @param inputFiles List of files that are generated for.
  55.      * @throws IOException If writing files failed.
  56.      * @throws GeneratorException If bad generation.
  57.      */
  58.     public void generateGlobal(GlobalRegistry registry,
  59.                                Collection<Path> inputFiles) throws IOException, GeneratorException {}
  60. }