Search in sources :

Example 1 with CodeGenerator

use of org.opendaylight.mdsal.binding.model.api.CodeGenerator in project mdsal by opendaylight.

the class JavaFileGenerator method generateFiles.

@VisibleForTesting
static Table<GeneratedFileType, GeneratedFilePath, GeneratedFile> generateFiles(final List<GeneratedType> types, final boolean ignoreDuplicateFiles) {
    final Table<GeneratedFileType, GeneratedFilePath, GeneratedFile> result = HashBasedTable.create();
    for (Type type : types) {
        for (CodeGenerator generator : GENERATORS) {
            if (!generator.isAcceptable(type)) {
                continue;
            }
            final GeneratedFileLifecycle kind = type instanceof GeneratedTransferObject && ((GeneratedTransferObject) type).isUnionTypeBuilder() ? GeneratedFileLifecycle.PERSISTENT : GeneratedFileLifecycle.TRANSIENT;
            final GeneratedFilePath file = GeneratedFilePath.ofFilePath(type.getPackageName().replace('.', File.separatorChar) + File.separator + generator.getUnitName(type) + ".java");
            if (result.contains(GeneratedFileType.SOURCE, file)) {
                if (ignoreDuplicateFiles) {
                    LOG.warn("Naming conflict for type '{}': file with same name already exists and will not be " + "generated.", type.getFullyQualifiedName());
                    continue;
                }
                throw new IllegalStateException("Duplicate " + kind + " file '" + file.getPath() + "' for " + type.getFullyQualifiedName());
            }
            result.put(GeneratedFileType.SOURCE, file, new CodeGeneratorGeneratedFile(kind, generator, type));
        }
    }
    return result;
}
Also used : GeneratedFilePath(org.opendaylight.yangtools.plugin.generator.api.GeneratedFilePath) GeneratedFileType(org.opendaylight.yangtools.plugin.generator.api.GeneratedFileType) Type(org.opendaylight.mdsal.binding.model.api.Type) GeneratedType(org.opendaylight.mdsal.binding.model.api.GeneratedType) GeneratedFileType(org.opendaylight.yangtools.plugin.generator.api.GeneratedFileType) GeneratedTransferObject(org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject) GeneratedFileLifecycle(org.opendaylight.yangtools.plugin.generator.api.GeneratedFileLifecycle) CodeGenerator(org.opendaylight.mdsal.binding.model.api.CodeGenerator) GeneratedFile(org.opendaylight.yangtools.plugin.generator.api.GeneratedFile) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 CodeGenerator (org.opendaylight.mdsal.binding.model.api.CodeGenerator)1 GeneratedTransferObject (org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject)1 GeneratedType (org.opendaylight.mdsal.binding.model.api.GeneratedType)1 Type (org.opendaylight.mdsal.binding.model.api.Type)1 GeneratedFile (org.opendaylight.yangtools.plugin.generator.api.GeneratedFile)1 GeneratedFileLifecycle (org.opendaylight.yangtools.plugin.generator.api.GeneratedFileLifecycle)1 GeneratedFilePath (org.opendaylight.yangtools.plugin.generator.api.GeneratedFilePath)1 GeneratedFileType (org.opendaylight.yangtools.plugin.generator.api.GeneratedFileType)1