org.eclipse.xtext.preferences.ITypedPreferenceValues Java Examples

The following examples show how to use org.eclipse.xtext.preferences.ITypedPreferenceValues. 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: 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 #3
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 #4
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 #5
Source File: FormatterTestRequest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public MapBasedPreferenceValues getOrCreateMapBasedPreferences() {
	ITypedPreferenceValues preferences = request.getPreferences();
	if (preferences instanceof MapBasedPreferenceValues)
		return (MapBasedPreferenceValues) preferences;
	LinkedHashMap<String, String> newMap = Maps.<String, String> newLinkedHashMap();
	MapBasedPreferenceValues result = new MapBasedPreferenceValues(preferences, newMap);
	request.setPreferences(result);
	return result;
}
 
Example #6
Source File: FormatterTestRequest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public MapBasedPreferenceValues getOrCreateMapBasedPreferences() {
	ITypedPreferenceValues preferences = request.getPreferences();
	if (preferences instanceof MapBasedPreferenceValues)
		return (MapBasedPreferenceValues) preferences;
	LinkedHashMap<String, String> newMap = Maps.<String, String> newLinkedHashMap();
	MapBasedPreferenceValues result = new MapBasedPreferenceValues(preferences, newMap);
	request.setPreferences(result);
	return result;
}
 
Example #7
Source File: FormatterRequest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @see #preferences
 */
public FormatterRequest setPreferences(ITypedPreferenceValues preferenceValues) {
	this.preferences = preferenceValues;
	return this;
}
 
Example #8
Source File: FormattableDocument.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public ITypedPreferenceValues getPreferences() {
	return getFormatter().getPreferences();
}
 
Example #9
Source File: AbstractFormatter2.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @return the preferences from the {@link FormatterRequest}
 */
public ITypedPreferenceValues getPreferences() {
	return request.getPreferences();
}