Java Code Examples for org.eclipse.xtext.formatting2.FormatterRequest#setFormatUndefinedHiddenRegionsOnly()

The following examples show how to use org.eclipse.xtext.formatting2.FormatterRequest#setFormatUndefinedHiddenRegionsOnly() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FormattingService.java    From xtext-web with Eclipse Public License 2.0 6 votes vote down vote up
protected String format2(XtextResource resource, ITextRegion selection, ITypedPreferenceValues preferences) {
	FormatterRequest request = formatterRequestProvider.get();
	request.setAllowIdentityEdits(false);
	request.setFormatUndefinedHiddenRegionsOnly(false);
	if (selection != null) {
		request.setRegions(Lists.newArrayList(selection));
	}
	if (preferences != null) {
		request.setPreferences(preferences);
	}
	ITextRegionAccess regionAccess = regionBuilder.forNodeModel(resource).create();
	request.setTextRegionAccess(regionAccess);
	IFormatter2 formatter2 = formatter2Provider.get();
	List<ITextReplacement> replacements = formatter2.format(request);
	if (selection != null) {
		return regionAccess.getRewriter().renderToString(
				new TextSegment(regionAccess, selection.getOffset(), selection.getLength()), replacements);
	} else {
		return regionAccess.getRewriter().renderToString(replacements);
	}
}
 
Example 2
Source File: FormattingService.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected List<ITextReplacement> format2(XtextResource resource, ITextRegion selection,
		ITypedPreferenceValues preferences) {
	FormatterRequest request = formatterRequestProvider.get();
	request.setAllowIdentityEdits(false);
	request.setFormatUndefinedHiddenRegionsOnly(false);
	if (selection != null) {
		request.setRegions(Collections.singletonList(selection));
	}
	if (preferences != null) {
		request.setPreferences(preferences);
	}
	ITextRegionAccess regionAccess = regionBuilder.forNodeModel(resource).create();
	request.setTextRegionAccess(regionAccess);
	IFormatter2 formatter2 = formatter2Provider.get();
	List<ITextReplacement> replacements = formatter2.format(request);
	return replacements;
}
 
Example 3
Source File: ContentFormatter.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void initRequest(IXtextDocument document, IRegion region, XtextResource resource, FormatterRequest request) {
	ITextRegion textRegion = new TextRegion(region.getOffset(), region.getLength());
	request.setAllowIdentityEdits(false);
	request.setFormatUndefinedHiddenRegionsOnly(false);
	request.setRegions(singletonList(textRegion));
	ITextRegionAccess tokenAccess = regionBuilder.forNodeModel(resource).create();
	IPreferenceValues preferenceValues = preferencesProvider.getPreferenceValues(resource);
	request.setPreferences(TypedPreferenceValues.castOrWrap(preferenceValues));
	request.setTextRegionAccess(tokenAccess);
	if (tokenAccess.hasSyntaxError())
		request.setExceptionHandler(ExceptionAcceptor.IGNORING);
	else
		request.setExceptionHandler(ExceptionAcceptor.LOGGING);
}
 
Example 4
Source File: Serializer.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected void serialize(EObject obj, Appendable appendable, SaveOptions options) throws IOException {
	ITextRegionAccess regionAccess = serializeToRegions(obj);
	FormatterRequest request = formatterRequestProvider.get();
	request.setFormatUndefinedHiddenRegionsOnly(!options.isFormatting());
	request.setTextRegionAccess(regionAccess);
	IFormatter2 formatter2 = formatter2Provider.get();
	List<ITextReplacement> replacements = formatter2.format(request);
	regionAccess.getRewriter().renderToAppendable(replacements, appendable);
}