private static ISerializer getSerializer(final String delimiter) { ISerializer result = xtextSerializerByLineDelimiter.get(delimiter); if (result != null) { return result; } final ILineSeparatorInformation lineSeparatorInformation = new ILineSeparatorInformation() { @Override public String getLineSeparator() { return delimiter; } }; Injector injector = Guice.createInjector(new LineSeparatorModule(lineSeparatorInformation)); result = injector.getInstance(ISerializer.class); xtextSerializerByLineDelimiter.put(delimiter, result); return result; }
@Override public void setUp() throws Exception { super.setUp(); with(new XtextStandaloneSetup() { @Override public Injector createInjector() { return Guice.createInjector(new org.eclipse.xtext.XtextRuntimeModule() { @SuppressWarnings("unused") public Class<? extends ILineSeparatorInformation> bindILineSeparatorInformation() { return FormatterTestLineSeparatorInformation.class; } }); } }); get(FormatterTestLineSeparatorInformation.class).setLineSeparator("\n"); }
@Override public Injector createInjector() { return Guice.createInjector(new XcoreStandaloneRuntimeModule() { @SuppressWarnings("unused") public Class<? extends ILineSeparatorInformation> bindILineSeparatorInformation() { return UnixLineSeparator.class; } @SuppressWarnings("unused") public Class<? extends XcoreResourceSetInitializer> bindXcoreResourceSetInitializer() { return CreateResourceGuardedResourceSetInitializer.class; } }); }
/** * @since 2.7 */ protected void prettyPrint(String absoluteGrammarFileName, Charset encoding) { try { String content = readFileIntoString(absoluteGrammarFileName, encoding); final ILineSeparatorInformation lineSeparatorInformation = new ILineSeparatorInformation() { @Override public String getLineSeparator() { return DebugAntlrGeneratorFragment.this.getLineDelimiter(); } }; Injector injector = new SimpleAntlrStandaloneSetup() { @Override public Injector createInjector() { return Guice.createInjector(new SimpleAntlrRuntimeModule() { @Override public void configure(Binder binder) { super.configure(binder); binder.bind(ILineSeparatorInformation.class).toInstance(lineSeparatorInformation); } }); } }.createInjectorAndDoEMFRegistration(); XtextResource resource = injector.getInstance(XtextResource.class); resource.setURI(URI.createFileURI(absoluteGrammarFileName)); resource.load(new StringInputStream(content, encoding.name()), Collections.singletonMap(XtextResource.OPTION_ENCODING, encoding.name())); if (!resource.getErrors().isEmpty()) { String errors = Joiner.on(getLineDelimiter()).join(resource.getErrors()); throw new GeneratorWarning("Non fatal problem: Debug grammar could not be formatted due to:" + getLineDelimiter() + errors); } ByteArrayOutputStream outputStream = new ByteArrayOutputStream(content.length()); resource.save(outputStream, SaveOptions.newBuilder().format().getOptions().toOptionsMap()); String toBeWritten = new NewlineNormalizer(getLineDelimiter()).normalizeLineDelimiters( new String(outputStream.toByteArray(), encoding.name())); writeStringIntoFile(absoluteGrammarFileName, toBeWritten, encoding); } catch(IOException e) { throw new GeneratorWarning(e.getMessage()); } }
private ISerializer getSerializer() { final String delimiter = this.codeConfig.getLineDelimiter(); ISerializer result = this.xtextSerializerByLineDelimiter.get(delimiter); if ((result != null)) { return result; } final ILineSeparatorInformation _function = () -> { return delimiter; }; GrammarAccessExtensions.LineSeparatorModule _lineSeparatorModule = new GrammarAccessExtensions.LineSeparatorModule(_function); final Injector injector = Guice.createInjector(_lineSeparatorModule); result = injector.<ISerializer>getInstance(ISerializer.class); this.xtextSerializerByLineDelimiter.put(delimiter, result); return result; }
public ILineSeparatorInformation getLineSeparatorInformation(URI uri) { final String lineSeparator = getLineSeparatorPreference(uri); return new ILineSeparatorInformation() { public String getLineSeparator() { return lineSeparator; } }; }
protected LineSeparatorModule(ILineSeparatorInformation lineSeparatorInformation) { this.lineSeparatorInformation = lineSeparatorInformation; }
public ILineSeparatorInformation bindILineSeparatorInformation() { return lineSeparatorInformation; }
public FormattingConfig2(IGrammarAccess grammarAccess, IHiddenTokenHelper hiddenTokenHelper, IIndentationInformation indentInfo, ILineSeparatorInformation lineSeparatorInfo) { super(grammarAccess, hiddenTokenHelper, indentInfo); this.lineSeparatorInfo = lineSeparatorInfo; }
public ILineSeparatorInformation getLineSeparatorInfo() { return lineSeparatorInfo; }
/** * @since 2.3 */ protected ILineSeparatorInformation getLineSeparatorInfo() { return whitespaceInformationProvider.getLineSeparatorInformation(contextResourceURI); }
public ILineSeparatorInformation bindILineSeparatorInformation() { return this.lineSeparatorInformation; }
public LineSeparatorModule(final ILineSeparatorInformation lineSeparatorInformation) { super(); this.lineSeparatorInformation = lineSeparatorInformation; }
public void configureLineSeparatorInformation(final Binder binder) { final ILineSeparatorInformation _function = () -> { return this.code.getLineDelimiter(); }; binder.<ILineSeparatorInformation>bind(ILineSeparatorInformation.class).toInstance(_function); }
public Class<? extends ILineSeparatorInformation> bindILineSeparatorInformation() { return FormatterTestLineSeparatorInformation.class; }
/** * Instantiates a new AcfFormattingConfig. * * @param grammarAccess * the grammar access * @param hiddenTokenHelper * the hidden token helper * @param indentInfo * the indent info * @param lineSeparatorInfo * the line separator info */ public ExtendedFormattingConfig(final IGrammarAccess grammarAccess, final IHiddenTokenHelper hiddenTokenHelper, final IIndentationInformation indentInfo, final ILineSeparatorInformation lineSeparatorInfo) { super(grammarAccess, hiddenTokenHelper, indentInfo, lineSeparatorInfo); }