org.eclipse.xtext.formatting2.AbstractFormatter2 Java Examples

The following examples show how to use org.eclipse.xtext.formatting2.AbstractFormatter2. 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: RichStringFormatter.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected void setNewLines(final IFormattableDocument doc, final int offset, final int length, final int indentationIncrease, final int indentationDecrease, final int newLines) {
  IHiddenRegionFormatting _createHiddenRegionFormatting = doc.getFormatter().createHiddenRegionFormatting();
  final Procedure1<IHiddenRegionFormatting> _function = (IHiddenRegionFormatting it) -> {
    it.setIndentationIncrease(Integer.valueOf(indentationIncrease));
    it.setIndentationDecrease(Integer.valueOf(indentationDecrease));
    it.setNewLinesMin(Integer.valueOf(newLines));
    it.setNewLinesDefault(Integer.valueOf(newLines));
    it.setNewLinesMax(Integer.valueOf(newLines));
  };
  final IHiddenRegionFormatting fmt = ObjectExtensions.<IHiddenRegionFormatting>operator_doubleArrow(_createHiddenRegionFormatting, _function);
  AbstractFormatter2 _formatter = doc.getFormatter();
  ITextRegionAccess _textRegionAccess = this._iTextRegionExtensions.getTextRegionAccess();
  TextSegment _textSegment = new TextSegment(_textRegionAccess, offset, length);
  final ITextReplacer replacer = _formatter.createWhitespaceReplacer(_textSegment, fmt);
  doc.addReplacer(replacer);
}
 
Example #2
Source File: HiddenRegionReplacer.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public ITextReplacerContext createReplacements(ITextReplacerContext context) {
	AbstractFormatter2 formatter = context.getFormatter();
	List<IHiddenRegionPart> hiddens = region.getParts();
	if (hiddens.isEmpty()) {
		return formatter.createWhitespaceReplacer(region, formatting).createReplacements(context);
	} else if ((hiddens.size() == 1 && hiddens.get(0) instanceof IWhitespace)) {
		return formatter.createWhitespaceReplacer(hiddens.get(0), formatting).createReplacements(context);
	} else {
		List<ITextReplacer> replacers = createReplacers(formatter);
		applyHiddenRegionFormatting(replacers);
		ITextReplacerContext current = context;
		current.setNextReplacerIsChild();
		for (ITextReplacer replacer : replacers)
			current = replacer.createReplacements(current.withReplacer(replacer));
		return current;
	}
}
 
Example #3
Source File: FormattableDocument.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public IHiddenRegion set(IHiddenRegion hiddenRegion, Procedure1<? super IHiddenRegionFormatter> init) {
	if (hiddenRegion != null) {
		AbstractFormatter2 formatter = getFormatter();
		IHiddenRegionFormatting formatting = formatter.createHiddenRegionFormatting();
		init.apply(formatter.createHiddenRegionFormatter(formatting));
		ITextReplacer replacer = formatter.createHiddenRegionReplacer(hiddenRegion, formatting);
		addReplacer(replacer);
	}
	return hiddenRegion;
}
 
Example #4
Source File: Formatter2Fragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected TypeReference getStubSuperClass() {
  final Grammar superGrammar = GrammarUtil2.getNonTerminalsSuperGrammar(this.getLanguage().getGrammar());
  if ((superGrammar != null)) {
    return this.getFormatter2Stub(superGrammar);
  } else {
    return TypeReference.typeRef(AbstractFormatter2.class);
  }
}
 
Example #5
Source File: FormatterStubGenerator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public String getStubSuperClassName() {
  final Grammar superGrammar = IInheriting.Util.getNonTerminalsSuperGrammar(this.grammar);
  if ((superGrammar != null)) {
    return this.service.createGenerator(superGrammar).getStubQualifiedName();
  } else {
    return AbstractFormatter2.class.getName();
  }
}
 
Example #6
Source File: FormattableDocument.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Pair<IHiddenRegion, IHiddenRegion> set(IHiddenRegion first, IHiddenRegion second,
		Procedure1<? super IHiddenRegionFormatter> init) {
	if (first != null && second != null) {
		AbstractFormatter2 formatter = getFormatter();
		IHiddenRegionFormatting f1 = formatter.createHiddenRegionFormatting();
		IHiddenRegionFormatting f2 = formatter.createHiddenRegionFormatting();
		init.apply(formatter.createHiddenRegionFormatter(f1, f2));
		ITextReplacer replacer1 = formatter.createHiddenRegionReplacer(first, f1);
		ITextReplacer replacer2 = formatter.createHiddenRegionReplacer(second, f2);
		addReplacer(replacer1);
		addReplacer(replacer2);
	}
	return Pair.of(first, second);
}
 
Example #7
Source File: RichStringFormatter.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void setSpace(final IFormattableDocument doc, final int offset, final int length, final String space) {
  IHiddenRegionFormatting _createHiddenRegionFormatting = doc.getFormatter().createHiddenRegionFormatting();
  final Procedure1<IHiddenRegionFormatting> _function = (IHiddenRegionFormatting it) -> {
    it.setSpace(space);
  };
  final IHiddenRegionFormatting fmt = ObjectExtensions.<IHiddenRegionFormatting>operator_doubleArrow(_createHiddenRegionFormatting, _function);
  AbstractFormatter2 _formatter = doc.getFormatter();
  ITextRegionAccess _textRegionAccess = this._iTextRegionExtensions.getTextRegionAccess();
  TextSegment _textSegment = new TextSegment(_textRegionAccess, offset, length);
  final ITextReplacer replacer = _formatter.createWhitespaceReplacer(_textSegment, fmt);
  doc.addReplacer(replacer);
}
 
Example #8
Source File: SubDocument.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public AbstractFormatter2 getFormatter() {
	return parent.getFormatter();
}
 
Example #9
Source File: TextReplacerMerger.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public TextReplacerMerger(AbstractFormatter2 formatter) {
	super();
	this.formatter = formatter;
	this.merger = formatter.createHiddenRegionFormattingMerger();
}
 
Example #10
Source File: HiddenRegionFormattingMerger.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public HiddenRegionFormattingMerger(AbstractFormatter2 formatter) {
	super();
	this.formatter = formatter;
}
 
Example #11
Source File: HiddenRegionFormatting.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public HiddenRegionFormatting(AbstractFormatter2 formatter) {
	super();
	this.formatter = formatter;
}
 
Example #12
Source File: HiddenRegionFormatting.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public AbstractFormatter2 getFormatter() {
	return formatter;
}
 
Example #13
Source File: RootDocument.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public RootDocument(AbstractFormatter2 formatter) {
	super();
	this.formatter = formatter;
}
 
Example #14
Source File: RootDocument.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public AbstractFormatter2 getFormatter() {
	return formatter;
}
 
Example #15
Source File: TextReplacerContext.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public AbstractFormatter2 getFormatter() {
	return document.getFormatter();
}
 
Example #16
Source File: TextReplacerContext.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public String getIndentationString(int indentationLevel) {
	AbstractFormatter2 formatter = document.getFormatter();
	return Strings.repeat(formatter.getPreference(FormatterPreferenceKeys.indentation), indentationLevel);
}
 
Example #17
Source File: BugMultilineCommentIndentation.java    From sarl with Apache License 2.0 4 votes vote down vote up
@Override
public AbstractFormatter2 getFormatter() {
	return this.context.getFormatter();
}