import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
-import java.util.Set;
import org.opendaylight.yangtools.sal.binding.model.api.CodeGenerator;
import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject;
/**
* Set of <code>Type</code> instances for which the JAVA code is generated.
*/
- private final Set<? extends Type> types;
+ private final Collection<? extends Type> types;
/**
* BuildContext used for instantiating files
* @param types
* set of types for which JAVA code should be generated
*/
- public GeneratorJavaFile(final BuildContext buildContext, final Set<? extends Type> types) {
+ public GeneratorJavaFile(final BuildContext buildContext, final Collection<? extends Type> types) {
this.buildContext = Preconditions.checkNotNull(buildContext);
this.types = Preconditions.checkNotNull(types);
generators.add(new InterfaceGenerator());
* @param types
* set of types for which JAVA code should be generated
*/
- public GeneratorJavaFile(final Set<? extends Type> types) {
+ public GeneratorJavaFile(final Collection<? extends Type> types) {
this(new DefaultBuildContext(), types);
}
throw new IllegalStateException("Generated code should not be empty!");
}
final File file = new File(packageDir, generator.getUnitName(type) + ".java");
+
+ if (file.exists()) {
+ LOG.warn(
+ "Naming conflict for type '{}': file with same name already exists and will not be generated.",
+ type.getFullyQualifiedName());
+ return null;
+ }
+
try (final OutputStream stream = buildContext.newFileOutputStream(file)) {
try (final Writer fw = new OutputStreamWriter(stream)) {
try (final BufferedWriter bw = new BufferedWriter(fw)) {
}
}
return file;
+
}
return null;
}
* @return <code>File</code> object which refers to the new directory for
* package <code>packageName</code>
*/
- private File packageToDirectory(final File parentDirectory, final String packageName) {
+ public static File packageToDirectory(final File parentDirectory, final String packageName) {
if (packageName == null) {
throw new IllegalArgumentException("Package Name cannot be NULL!");
}