2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang2sources.plugin;
10 import com.google.common.base.MoreObjects;
11 import com.google.common.base.MoreObjects.ToStringHelper;
12 import org.apache.maven.project.MavenProject;
13 import org.eclipse.jdt.annotation.NonNullByDefault;
14 import org.opendaylight.yangtools.plugin.generator.api.FileGenerator.ImportResolutionMode;
15 import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
18 abstract class GeneratorTaskFactory extends ParserModeAware {
19 private final StatementParserMode parserMode;
21 GeneratorTaskFactory(final ImportResolutionMode importMode) {
23 case REVISION_EXACT_OR_LATEST:
24 parserMode = StatementParserMode.DEFAULT_MODE;
27 parserMode = StatementParserMode.SEMVER_MODE;
30 throw new LinkageError("Unhandled import mode " + importMode);
35 final StatementParserMode parserMode() {
39 final String generatorName() {
40 return generator().getClass().getName();
44 * Create a new {@link GeneratorTask} which will work in scope of specified {@link MavenProject} with the effective
45 * model held in specified {@link ContextHolder}.
47 * @param project current Maven Project
48 * @param context model generation context
50 abstract GeneratorTask<?> createTask(MavenProject project, ContextHolder context);
52 abstract Object generator();
54 ToStringHelper addToStringProperties(final ToStringHelper helper) {
55 return helper.add("generator", generatorName());
59 public final String toString() {
60 return addToStringProperties(MoreObjects.toStringHelper(this).omitNullValues()).toString();