Search in sources :

Example 1 with EclipseFileObject

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);
}
Also used : EclipseFileObject(org.eclipse.jdt.internal.compiler.tool.EclipseFileObject) OutputStreamWriter(java.io.OutputStreamWriter) JavaSnippetDocument(org.knime.base.node.jsnippet.guarded.JavaSnippetDocument) GuardedDocument(org.knime.base.node.jsnippet.guarded.GuardedDocument) Document(javax.swing.text.Document) File(java.io.File) BundleFile(org.eclipse.osgi.storage.bundlefile.BundleFile) BufferedWriter(java.io.BufferedWriter) StringWriter(java.io.StringWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) BadLocationException(javax.swing.text.BadLocationException) BufferedWriter(java.io.BufferedWriter)

Aggregations

BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 OutputStreamWriter (java.io.OutputStreamWriter)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 BadLocationException (javax.swing.text.BadLocationException)1 Document (javax.swing.text.Document)1 EclipseFileObject (org.eclipse.jdt.internal.compiler.tool.EclipseFileObject)1 BundleFile (org.eclipse.osgi.storage.bundlefile.BundleFile)1 GuardedDocument (org.knime.base.node.jsnippet.guarded.GuardedDocument)1 JavaSnippetDocument (org.knime.base.node.jsnippet.guarded.JavaSnippetDocument)1