Java Code Examples for org.eclipse.xtext.formatting2.FormatterRequest#setAllowIdentityEdits()
The following examples show how to use
org.eclipse.xtext.formatting2.FormatterRequest#setAllowIdentityEdits() .
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 |
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: ConvertJavaCode.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
private String formatXtendCode(IFile xtendFile, final String xtendCode) { try { XtextResource resource = (XtextResource) createResource(xtendFile, xtendCode); ITextRegionAccess regionAccess = regionAccessBuilder.get().forNodeModel(resource).create(); FormatterRequest request = new FormatterRequest(); request.setAllowIdentityEdits(false); request.setTextRegionAccess(regionAccess); request.setPreferences(TypedPreferenceValues.castOrWrap(cfgProvider.getPreferenceValues(resource))); List<ITextReplacement> replacements = formatter.format(request); String formatted = regionAccess.getRewriter().renderToString(replacements); return formatted; } catch (Exception e) { LOG.error("Formatting step canceled due to an exception.", e); return null; } }
Example 3
Source File: FormatterFacade.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
public String format(final String xtendCode) { try { final XtextResourceSet resourceSet = new XtextResourceSet(); Resource _createResource = this.resourceFactory.createResource(URI.createURI("synthetic://to-be-formatted.xtend")); final XtextResource resource = ((XtextResource) _createResource); EList<Resource> _resources = resourceSet.getResources(); _resources.add(resource); StringInputStream _stringInputStream = new StringInputStream(xtendCode); resource.load(_stringInputStream, CollectionLiterals.<Object, Object>emptyMap()); final ITextRegionAccess regionAccess = this.regionAccessBuilder.get().forNodeModel(resource).create(); FormatterRequest _formatterRequest = new FormatterRequest(); final Procedure1<FormatterRequest> _function = (FormatterRequest it) -> { it.setAllowIdentityEdits(false); it.setTextRegionAccess(regionAccess); it.setPreferences(TypedPreferenceValues.castOrWrap(this.cfgProvider.getPreferenceValues(resource))); }; FormatterRequest request = ObjectExtensions.<FormatterRequest>operator_doubleArrow(_formatterRequest, _function); List<ITextReplacement> replacements = this.formatter.format(request); return regionAccess.getRewriter().renderToString(replacements); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 4
Source File: FormattingService.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
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 5
Source File: ContentFormatter.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
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); }