Search in sources :

Example 1 with SaveOptions

use of org.eclipse.xtext.resource.SaveOptions in project xtext-core by eclipse.

the class GrammarAccessExtensions method grammarFragmentToString.

/**
 * @noreference
 */
public static String grammarFragmentToString(final ISerializer serializer, final EObject object, final String prefix) {
    String s = null;
    try {
        final SaveOptions options = SaveOptions.newBuilder().format().getOptions();
        s = serializer.serialize(object, options);
    } catch (final Throwable _t) {
        if (_t instanceof Exception) {
            final Exception e = (Exception) _t;
            s = e.toString();
        } else {
            throw Exceptions.sneakyThrow(_t);
        }
    }
    String _replace = s.trim().replaceAll("(\\r?\\n)", ("$1" + prefix)).replace("\\u", "\\\\u");
    String _plus = (prefix + _replace);
    s = _plus;
    return s;
}
Also used : SaveOptions(org.eclipse.xtext.resource.SaveOptions)

Example 2 with SaveOptions

use of org.eclipse.xtext.resource.SaveOptions in project xtext-core by eclipse.

the class XtextFormatterTest method _testXtextXtext.

public void _testXtextXtext() {
    Serializer serializer = get(Serializer.class);
    IGrammarAccess grammar = get(IGrammarAccess.class);
    SaveOptions opt = SaveOptions.newBuilder().format().getOptions();
    System.out.println(serializer.serialize(grammar.getGrammar(), opt));
}
Also used : IGrammarAccess(org.eclipse.xtext.IGrammarAccess) SaveOptions(org.eclipse.xtext.resource.SaveOptions) Serializer(org.eclipse.xtext.parsetree.reconstr.Serializer)

Aggregations

SaveOptions (org.eclipse.xtext.resource.SaveOptions)2 IGrammarAccess (org.eclipse.xtext.IGrammarAccess)1 Serializer (org.eclipse.xtext.parsetree.reconstr.Serializer)1