Define a feature-parent
[yangtools.git] / plugin / plugin-generator-api / src / main / java / org / opendaylight / yangtools / plugin / generator / api / FileGenerator.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.plugin.generator.api;
9
10 import com.google.common.collect.Table;
11 import java.util.Set;
12 import org.eclipse.jdt.annotation.NonNullByDefault;
13 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
14 import org.opendaylight.yangtools.yang.model.api.Module;
15 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
16
17 /**
18  * Interface implemented by plugins which can generate files from a {@link EffectiveModelContext}.
19  *
20  * @author Robert Varga
21  */
22 @NonNullByDefault
23 public interface FileGenerator {
24     /**
25      * Indicate import resolution mode this code generator requires. Default implementation indicates
26      * {@link ImportResolutionMode#REVISION_EXACT_OR_LATEST}.
27      *
28      * @implNote
29      *     Default implementation returns {@link ImportResolutionMode#REVISION_EXACT_OR_LATEST}.
30      *
31      * @return Required import resolution mode.
32      */
33     default ImportResolutionMode importResolutionMode() {
34         return ImportResolutionMode.REVISION_EXACT_OR_LATEST;
35     }
36
37     /**
38      * Generate files from a {@link SchemaContext}, being aware the that specific modules are local to the current
39      * project being processed.
40      *
41      * <p>
42      * Implementations of this interface must not interact with project directory directly, but rather supply the files
43      * generated as a set of {@link GeneratedFile}s. The caller of this method will use these to integrate with build
44      * management to ensure proper dependency tracking is performed.
45      *
46      * @param context SchemaContext to examine
47      * @param localModules Modules local to the project
48      * @param moduleResourcePathResolver Module-to-resource path resolver
49      * @return The set of generated files.
50      * @throws FileGeneratorException if anything bad happens
51      */
52     Table<GeneratedFileType, GeneratedFilePath, GeneratedFile> generateFiles(EffectiveModelContext context,
53             Set<Module> localModules, ModuleResourceResolver moduleResourcePathResolver) throws FileGeneratorException;
54
55     /**
56      * {@link EffectiveModelContext} can be assembled in multiple ways, we hold known modes here.
57      */
58     enum ImportResolutionMode {
59         /**
60          * Standard, RFC6020 and RFC7950 compliant mode. Imports are satisfied by exact revision match (if specified),
61          * or by latest available revision.
62          */
63         REVISION_EXACT_OR_LATEST;
64     }
65 }