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.plugin.generator.api;
10 import static com.google.common.base.Preconditions.checkArgument;
11 import static java.util.Objects.requireNonNull;
13 import com.google.common.annotations.Beta;
14 import com.google.common.base.MoreObjects;
15 import com.google.common.collect.ImmutableMap;
16 import org.eclipse.jdt.annotation.NonNullByDefault;
17 import org.eclipse.jdt.annotation.Nullable;
20 * Type of generated file. Four most common kinds are captured in {@link #RESOURCE}, {@link #SOURCE},
21 * {@link #TEST_RESOURCE} and {@link #TEST_SOURCE}, but others may be externally defined.
24 * Users of {@link FileGenerator} are expected to provide sensible mapping of {@link GeneratedFileType} to their
25 * output structures. Notably they must handle pre-defined types, allow end users to specify mapping of custom types.
26 * They need to deal with runtime mismatches involving between FileGenerators and user's expectations, for example by
27 * issuing warnings when a mismatch is detected.
29 * @author Robert Varga
33 public final class GeneratedFileType {
35 * A generated resource file. This file should be part of artifact's resources.
37 public static final GeneratedFileType RESOURCE = new GeneratedFileType("resource");
40 * A generated source file. This file should be part of main compilation unit.
42 public static final GeneratedFileType SOURCE = new GeneratedFileType("source");
45 * A generated test resource file. This file should be part of test resources.
47 public static final GeneratedFileType TEST_RESOURCE = new GeneratedFileType("test-resource");
50 * A generated test source file. This file should be part of test sources.
52 public static final GeneratedFileType TEST_SOURCE = new GeneratedFileType("test-source");
54 private static final ImmutableMap<String, GeneratedFileType> WELL_KNOWN = ImmutableMap.of(
55 RESOURCE.name(), RESOURCE, TEST_RESOURCE.name(), TEST_RESOURCE,
56 SOURCE.name(), SOURCE, TEST_SOURCE.name(), TEST_SOURCE);
58 private final String name;
60 private GeneratedFileType(final String name) {
61 this.name = requireNonNull(name);
64 public static GeneratedFileType of(final String name) {
65 checkArgument(!name.isEmpty());
66 final @Nullable GeneratedFileType wellKnown = WELL_KNOWN.get(name);
67 return wellKnown != null ? wellKnown : new GeneratedFileType(name);
70 public String name() {
75 public int hashCode() {
76 return name.hashCode();
80 public boolean equals(final @Nullable Object obj) {
81 return this == obj || obj instanceof GeneratedFileType && name.equals(((GeneratedFileType) obj).name);
85 public String toString() {
86 return MoreObjects.toStringHelper(this).add("name", name).toString();