* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.mdsal.binding.generator.util;
+import com.google.common.io.Files;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+import java.io.BufferedWriter;
import java.io.File;
-import java.io.FileWriter;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import javassist.CtClass;
import javassist.CtField;
import javassist.CtMethod;
* written to a file under a specified directory.
*
* @author Thomas Pantelis
+ *
+ * @deprecated Code generation is a concert separate from type mapping and is an implementation detail.
*/
+@Deprecated
public class DefaultSourceCodeGenerator implements SourceCodeGenerator {
private static final Logger LOG = LoggerFactory.getLogger(DefaultSourceCodeGenerator.class);
builder.append(";\n");
} catch (NotFoundException e) {
- LOG.error("Error building field source for " + field.getName(), e);
+ LOG.error("Error building field source for {}", field.getName(), e);
}
}
builder.append(" )\n").append(code).append("\n\n");
} catch (NotFoundException e) {
- LOG.error("Error building method source for " + method.getName(), e);
+ LOG.error("Error building method source for {}", method.getName(), e);
}
}
@Override
+ @SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE")
public void outputGeneratedSource(final CtClass ctClass) {
String name = ctClass.getName();
}
}
- classBuilder.append(" {\n").append(builder.toString())
- .append("\n}");
+ classBuilder.append(" {\n").append(builder).append("\n}");
} catch (NotFoundException e) {
- LOG.error("Error building class source for " + name, e);
+ LOG.error("Error building class source for {}", name, e);
return;
}
File dir = new File(generatedSourceDir);
- dir.mkdir();
- try (FileWriter writer = new FileWriter(new File(dir, name + ".java"))) {
- writer.append(classBuilder.toString());
+ if (!dir.mkdir()) {
+ LOG.warn("Failed to create directory {}, attempting to continue", generatedSourceDir);
+ }
+
+ try (BufferedWriter writer = Files.newWriter(new File(dir, name + ".java"), StandardCharsets.UTF_8)) {
+ writer.append(classBuilder);
writer.flush();
} catch (IOException e) {
- LOG.error("Error writing class source for " + name, e);
+ LOG.error("Error writing class source for {}", name, e);
}
}
}