org.eclipse.xtext.formatting.ILineSeparatorInformation Java Examples

The following examples show how to use org.eclipse.xtext.formatting.ILineSeparatorInformation. 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: XtextFormatterTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@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");
}
 
Example #2
Source File: GrammarAccessUtil.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
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;
}
 
Example #3
Source File: XbaseHoverDocumentationProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected void getDocumentationWithPrefix(EObject object) {
	String startTag = "/**";
	String endTag = "*/";
	ILineSeparatorInformation lineSeparatorInformation = whitespaceInformationProvider
			.getLineSeparatorInformation(EcoreUtil.getURI(object));
	String lineBreak = lineSeparatorInformation.getLineSeparator();
	String documentation = resolveDocumentation(object);
	if (documentation != null && documentation.length() > 0) {
		BufferedReader reader = new BufferedReader(new StringReader(documentation));
		StringBuilder builder = new StringBuilder(startTag + lineBreak);
		try {
			String line = "";
			while ((line = reader.readLine()) != null) {
				if (line.length() > 0)
					builder.append(line + lineBreak);
			}
			builder.append(endTag);
		} catch (IOException e) {

		}
		rawJavaDoc = builder.toString();
	}
}
 
Example #4
Source File: NewlineAwareXcoreStandaloneSetup.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@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;
		}

		/**
		 * Binds XcoreEcoreBuilder that aligns the MWE2 workflow trigger xcore generation with the incremental
		 * builder.
		 */
		@SuppressWarnings("unused")
		public Class<? extends XcoreEcoreBuilder> bindXcoreEcoreBuilder() {
			return NoDocumentationInferenceXcoreEcoreBuilder.class;
		}
	});
}
 
Example #5
Source File: DebugAntlrGeneratorFragment.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @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());
	}
}
 
Example #6
Source File: AbstractWebServerTest.java    From xtext-web with Eclipse Public License 2.0 5 votes vote down vote up
protected com.google.inject.Module getRuntimeModule() {

		return new StatemachineRuntimeModule() {
			@SuppressWarnings("unused")
			public Class<? extends ILineSeparatorInformation> bindILineSeparatorInformation() {
				return AbstractWebServerTest.TestLineSeparatorInformation.class;
			}
		};
	}
 
Example #7
Source File: PreferenceStoreWhitespaceInformationProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public ILineSeparatorInformation getLineSeparatorInformation(URI uri) {
	if (uri == null) {
		return lineSeparatorInformation;
	}
	final String lineSeparator = getLineSeparatorPreference(uri);
	return new ILineSeparatorInformation() {
		@Override
		public String getLineSeparator() {
			return lineSeparator;
		}
	};
}
 
Example #8
Source File: GrammarAccessExtensions.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
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;
}
 
Example #9
Source File: FormattingConfig2.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public FormattingConfig2(IGrammarAccess grammarAccess, IHiddenTokenHelper hiddenTokenHelper,
		IIndentationInformation indentInfo, ILineSeparatorInformation lineSeparatorInfo) {
	super(grammarAccess, hiddenTokenHelper, indentInfo);
	this.lineSeparatorInfo = lineSeparatorInfo;
}
 
Example #10
Source File: FormatterTestLanguageRuntimeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends ILineSeparatorInformation> bindILineSeparatorInformation() {
	return FormatterTestLineSeparatorInformation.class;
}
 
Example #11
Source File: GrammarAccessExtensions.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public LineSeparatorModule(final ILineSeparatorInformation lineSeparatorInformation) {
  super();
  this.lineSeparatorInformation = lineSeparatorInformation;
}
 
Example #12
Source File: GrammarAccessExtensions.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public ILineSeparatorInformation bindILineSeparatorInformation() {
  return this.lineSeparatorInformation;
}
 
Example #13
Source File: DefaultGeneratorModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public void configureLineSeparatorInformation(Binder binder) {
	binder.bind(ILineSeparatorInformation.class).toInstance(() -> code.getLineDelimiter());
}
 
Example #14
Source File: AbstractDeclarativeFormatter.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @since 2.3
 */
protected ILineSeparatorInformation getLineSeparatorInfo() {
	return whitespaceInformationProvider.getLineSeparatorInformation(contextResourceURI);
}
 
Example #15
Source File: FormattingConfig2.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public ILineSeparatorInformation getLineSeparatorInfo() {
	return lineSeparatorInfo;
}
 
Example #16
Source File: DotFormatter.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
protected ILineSeparatorInformation getLineSeparatorInfo() {
	return whitespaceInformationProvider
			.getLineSeparatorInformation(contextResourceURI);
}
 
Example #17
Source File: GrammarAccessUtil.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public ILineSeparatorInformation bindILineSeparatorInformation() {
	return lineSeparatorInformation;
}
 
Example #18
Source File: GrammarAccessUtil.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected LineSeparatorModule(ILineSeparatorInformation lineSeparatorInformation) {
	this.lineSeparatorInformation = lineSeparatorInformation;
}
 
Example #19
Source File: ExtendedFormattingConfig.java    From dsl-devkit with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * 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);
}