Java Code Examples for org.eclipse.xtext.formatting2.IHiddenRegionFormatter#setNewLines()

The following examples show how to use org.eclipse.xtext.formatting2.IHiddenRegionFormatter#setNewLines() . 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: NewLineOrPreserveKey.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void apply(IHiddenRegionFormatter formatter) {
	ITypedPreferenceValues preferences = formatter.getRequest().getPreferences();
	Boolean newLine = preferences.getPreference(this);
	Boolean preserve = preferences.getPreference(XbaseFormatterPreferenceKeys.preserveNewLines);
	int min = 0;
	if (newLine.booleanValue()) {
		min = 1;
	}
	int max = 0;
	if (preserve.booleanValue() || newLine.booleanValue()) {
		max = 1;
	}
	formatter.setNewLines(min, min, max);
	formatter.setSpace(" ");
}
 
Example 2
Source File: NewLineKey.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void apply(IHiddenRegionFormatter formatter) {
	Boolean newLine = formatter.getRequest().getPreferences().getPreference(this);
	if (newLine.booleanValue()) {
		formatter.setNewLines(1);
	} else {
		formatter.oneSpace();
	}
}
 
Example 3
Source File: BlankLineKey.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void apply(IHiddenRegionFormatter formatter) {
	ITypedPreferenceValues preferences = formatter.getRequest().getPreferences();
	Integer blankline = preferences.getPreference(this);
	Integer preserve = preferences.getPreference(XbaseFormatterPreferenceKeys.preserveBlankLines);
	int min = blankline.intValue() + 1;
	int max = Math.max(preserve.intValue() + 1, min);
	formatter.setNewLines(min, min, max);
}
 
Example 4
Source File: NoJdtTestLanguageFormatter.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected void _format(final Greeting greeting, @Extension final IFormattableDocument document) {
  final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
    it.setNewLines(1, 1, 2);
  };
  document.<Greeting>append(greeting, _function);
}