use of org.activityinfo.i18n.tools.parser.DefaultUpdatingVisitor in project activityinfo by bedatadriven.
the class Pull method updateJavaSource.
/**
* Updates the @DefaultMessage/@DefaultStringValue annotations and javadoc in the Messages or Constants
* interface Java source file.
*/
private void updateJavaSource(ResourceClass resourceClass, TranslationSet translations) throws IOException {
CompilationUnit compilationUnit;
try {
compilationUnit = resourceClass.parseJavaSource();
} catch (Exception e) {
throw new IOException("Failed to parse " + resourceClass.getJavaSourcePath(), e);
}
TranslationSet validated = validateMessages(resourceClass, compilationUnit, translations);
DefaultUpdatingVisitor visitor = new DefaultUpdatingVisitor();
visitor.visit(compilationUnit, validated);
if (visitor.isDirty()) {
try {
Files.write(compilationUnit.toString(), resourceClass.getJavaSourceFile(), Charsets.UTF_8);
} catch (IOException e) {
throw new IOException("Failed to write updated source file to " + resourceClass.getJavaSourcePath(), e);
}
System.out.println("Updated default translations in " + resourceClass.getJavaSourcePath());
} else {
System.out.println(resourceClass.getClassName() + " is up to date.");
}
}
Aggregations