use of org.eclipse.jdt.internal.compiler.tool.EclipseFileObject in project knime-core by knime.
the class JavaSnippet method getCompilationUnits.
@Override
public Iterable<? extends JavaFileObject> getCompilationUnits() throws IOException {
if (m_snippet == null || m_snippetFile == null || !m_snippetFile.exists()) {
m_snippetFile = new File(m_tempClassPathDir, "JSnippet.java");
// Note: this is a workaround for openWriter() not taking charset into account
m_snippet = new EclipseFileObject("JSnippet", m_snippetFile.toURI(), Kind.SOURCE, StandardCharsets.UTF_8);
m_dirty = true;
}
if (m_dirty) {
try (final Writer out = new BufferedWriter(new OutputStreamWriter(m_snippet.openOutputStream(), StandardCharsets.UTF_8))) {
try {
final Document doc = getDocument();
out.write(doc.getText(0, doc.getLength()));
m_dirty = false;
} catch (BadLocationException e) {
// this should never happen.
throw new IllegalStateException(e);
}
}
}
return Collections.singletonList(m_snippet);
}
Aggregations