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. Two most common kinds are captured in {@link #RESOURCE}, {@link #SOURCE}, but others may be
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");
44 private static final ImmutableMap<String, GeneratedFileType> WELL_KNOWN = ImmutableMap.of(
45 RESOURCE.name(), RESOURCE, SOURCE.name(), SOURCE);
47 private final String name;
49 private GeneratedFileType(final String name) {
50 this.name = requireNonNull(name);
53 public static GeneratedFileType of(final String name) {
54 checkArgument(!name.isEmpty());
55 final @Nullable GeneratedFileType wellKnown = WELL_KNOWN.get(name);
56 return wellKnown != null ? wellKnown : new GeneratedFileType(name);
59 public String name() {
64 public int hashCode() {
65 return name.hashCode();
69 public boolean equals(final @Nullable Object obj) {
70 return this == obj || obj instanceof GeneratedFileType && name.equals(((GeneratedFileType) obj).name);
74 public String toString() {
75 return MoreObjects.toStringHelper(this).add("name", name).toString();