Search in sources :

Example 91 with ITextRegionAccess

use of org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess in project elk by eclipse.

the class GraphvizDotSerializer method serialize.

@Override
protected void serialize(EObject obj, Appendable appendable, SaveOptions options) throws IOException {
    ITextRegionAccess regionAccess = serializeToRegions(obj);
    FormatterRequest request = formatterRequestProvider.get();
    MapBasedPreferenceValues preferences = new MapBasedPreferenceValues(Maps.<String, String>newLinkedHashMap());
    preferences.put(FormatterPreferenceKeys.maxLineWidth, MAX_LINE_LENGTH);
    request.setPreferences(preferences);
    request.setFormatUndefinedHiddenRegionsOnly(!options.isFormatting());
    request.setTextRegionAccess(regionAccess);
    IFormatter2 formatter2 = formatter2Provider.get();
    List<ITextReplacement> replacements = formatter2.format(request);
    regionAccess.getRewriter().renderToAppendable(replacements, appendable);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) IFormatter2(org.eclipse.xtext.formatting2.IFormatter2) ITextReplacement(org.eclipse.xtext.formatting2.regionaccess.ITextReplacement) MapBasedPreferenceValues(org.eclipse.xtext.preferences.MapBasedPreferenceValues) FormatterRequest(org.eclipse.xtext.formatting2.FormatterRequest)

Aggregations

ITextRegionAccess (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess)75 Test (org.junit.Test)39 ISemanticRegion (org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)17 ITextRegionDiffBuilder (org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder)17 ITextSegment (org.eclipse.xtext.formatting2.regionaccess.ITextSegment)17 OptionalChildList (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.OptionalChildList)12 TextRegionAccessToString (org.eclipse.xtext.formatting2.debug.TextRegionAccessToString)11 ITextReplacement (org.eclipse.xtext.formatting2.regionaccess.ITextReplacement)11 MandatoryValue (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.MandatoryValue)11 ILineRegion (org.eclipse.xtext.formatting2.regionaccess.ILineRegion)9 EObject (org.eclipse.emf.ecore.EObject)8 FormatterRequest (org.eclipse.xtext.formatting2.FormatterRequest)8 IHiddenRegion (org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion)8 IEObjectRegion (org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion)7 XtextResource (org.eclipse.xtext.resource.XtextResource)7 ITextRegionExtensions (org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions)6 IFormatter2 (org.eclipse.xtext.formatting2.IFormatter2)5 TextRegionsToString (org.eclipse.xtext.formatting2.debug.TextRegionsToString)4 String (java.lang.String)3 IComment (org.eclipse.xtext.formatting2.regionaccess.IComment)3