use of org.eclipse.xtext.xbase.compiler.output.TreeAppendable in project xtext-xtend by eclipse.
the class UnicodeAwarePostProcessorTest method testUTF8_tree.
@Test
public void testUTF8_tree() {
TreeAppendable treeAppendable = new TreeAppendable(null, null, this, this, EcoreFactory.eINSTANCE.createEObject(), " ", "\n");
treeAppendable.append("\u03b1\u03c1\u03b5\u03c4\u03b7");
CharSequence result = postProcessor.postProcess(URI.createFileURI("com/acme/MyFile.java"), treeAppendable, Charsets.UTF_8);
assertSame(treeAppendable, result);
assertEquals("\u03b1\u03c1\u03b5\u03c4\u03b7", result.toString());
}
use of org.eclipse.xtext.xbase.compiler.output.TreeAppendable in project xtext-xtend by eclipse.
the class UnicodeAwarePostProcessor method postProcess.
@Override
public CharSequence postProcess(URI fileURI, CharSequence content, /* @Nullable */
Charset targetCharset) {
if (targetCharset != null && "java".equalsIgnoreCase(fileURI.fileExtension())) {
final String lineSeparator = getWhitespaceInformationProvider().getLineSeparatorInformation(fileURI).getLineSeparator();
final CharsetEncoder encoder = targetCharset.newEncoder();
if (content instanceof TreeAppendable) {
return ((TreeAppendable) content).acceptVisitor(new TreeAppendable.Visitor() {
@Override
protected /* @NonNull */
String visit(/* @NonNull */
String string) {
return replaceLineSeparatorsAndEscapeChars(string, lineSeparator, encoder);
}
});
} else {
String result = replaceLineSeparatorsAndEscapeChars(content, lineSeparator, encoder);
return result;
}
} else {
return postProcess(fileURI, content);
}
}
use of org.eclipse.xtext.xbase.compiler.output.TreeAppendable in project xtext-xtend by eclipse.
the class UnicodeAwarePostProcessorTest method testISO_8859_1_tree.
@Test
public void testISO_8859_1_tree() {
TreeAppendable treeAppendable = new TreeAppendable(null, null, this, this, EcoreFactory.eINSTANCE.createEObject(), " ", "\n");
treeAppendable.append("\u03b1\u03c1\u03b5\u03c4\u03b7");
CharSequence result = postProcessor.postProcess(URI.createFileURI("com/acme/MyFile.java"), treeAppendable, Charsets.ISO_8859_1);
assertSame(treeAppendable, result);
assertEquals("\\u03b1\\u03c1\\u03b5\\u03c4\\u03b7", result.toString());
}
Aggregations