org.eclipse.xtext.formatting2.IHiddenRegionFormatter Java Examples

The following examples show how to use org.eclipse.xtext.formatting2.IHiddenRegionFormatter. 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: XbaseFormatter.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void _format(final XCollectionLiteral literal, @Extension final IFormattableDocument document) {
  final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
    it.noSpace();
  };
  document.append(this.textRegionExtensions.regionFor(literal).keyword("#"), _function);
  ISemanticRegion _elvis = null;
  ISemanticRegion _keyword = this.textRegionExtensions.regionFor(literal).keyword("[");
  if (_keyword != null) {
    _elvis = _keyword;
  } else {
    ISemanticRegion _keyword_1 = this.textRegionExtensions.regionFor(literal).keyword("{");
    _elvis = _keyword_1;
  }
  final ISemanticRegion open = _elvis;
  ISemanticRegion _elvis_1 = null;
  ISemanticRegion _keyword_2 = this.textRegionExtensions.regionFor(literal).keyword("]");
  if (_keyword_2 != null) {
    _elvis_1 = _keyword_2;
  } else {
    ISemanticRegion _keyword_3 = this.textRegionExtensions.regionFor(literal).keyword("}");
    _elvis_1 = _keyword_3;
  }
  final ISemanticRegion close = _elvis_1;
  this.formatCommaSeparatedList(literal.getElements(), open, close, document);
}
 
Example #3
Source File: XbaseFormatter.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected void _format(final XFeatureCall expr, @Extension final IFormattableDocument format) {
  this.formatFeatureCallTypeParameters(expr, format);
  boolean _isExplicitOperationCall = expr.isExplicitOperationCall();
  if (_isExplicitOperationCall) {
    final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
      it.noSpace();
    };
    final ISemanticRegion open = format.prepend(this.textRegionExtensions.regionFor(expr).keyword(this.grammar.getXFeatureCallAccess().getExplicitOperationCallLeftParenthesisKeyword_3_0_0()), _function);
    final ISemanticRegion close = this.textRegionExtensions.regionFor(expr).keyword(this.grammar.getXFeatureCallAccess().getRightParenthesisKeyword_3_2());
    this.formatFeatureCallParams(expr.getFeatureCallArguments(), open, close, format);
  } else {
    EList<XExpression> _featureCallArguments = expr.getFeatureCallArguments();
    for (final XExpression arg : _featureCallArguments) {
      this.format(arg, format);
    }
  }
}
 
Example #4
Source File: FormattableDocument.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public ISemanticRegion prepend(ISemanticRegion token, Procedure1<? super IHiddenRegionFormatter> before) {
	if (token != null) {
		IHiddenRegion gap = token.getPreviousHiddenRegion();
		set(gap, before);
	}
	return token;
}
 
Example #5
Source File: XtendFormatter.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void _format(final XtendAnnotationType annotationType, @Extension final IFormattableDocument format) {
  this.formatAnnotations(annotationType, format, XbaseFormatterPreferenceKeys.newLineAfterClassAnnotations);
  this.formatModifiers(annotationType, format);
  final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
    it.oneSpace();
  };
  format.append(this.textRegionExtensions.regionFor(annotationType).keyword("annotation"), _function);
  this.formatBody(annotationType, format);
}
 
Example #6
Source File: XtendFormatter.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void _format(final XVariableDeclaration expr, @Extension final IFormattableDocument format) {
  final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
    it.oneSpace();
  };
  format.append(this.textRegionExtensions.regionFor(expr).keyword("extension"), _function);
  super._format(expr, format);
}
 
Example #7
Source File: XtendFormatter.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void _format(final JvmFormalParameter expr, @Extension final IFormattableDocument format) {
  final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
    it.oneSpace();
  };
  format.append(this.textRegionExtensions.regionFor(expr).keyword("extension"), _function);
  super._format(expr, format);
}
 
Example #8
Source File: XtendFormatter.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Always put existing modifiers into this fixed order
 */
protected void formatModifiers(final XtendMember member, @Extension final IFormattableDocument document) {
  final Consumer<ISemanticRegion> _function = (ISemanticRegion it) -> {
    final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_1) -> {
      it_1.oneSpace();
    };
    document.append(it, _function_1);
  };
  this.textRegionExtensions.regionFor(member).ruleCallsTo(this._xtendGrammarAccess.getCommonModifierRule(), this._xtendGrammarAccess.getMethodModifierRule(), this._xtendGrammarAccess.getFieldModifierRule()).forEach(_function);
}
 
Example #9
Source File: RichStringFormatter.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void _format(final XExpression expr, @Extension final IFormattableDocument doc) {
  final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
    it.noSpace();
  };
  doc.<XExpression>surround(expr, _function);
  this.formatIntoSingleLine(doc, expr);
}
 
Example #10
Source File: FormattableDocument.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public ISemanticRegion append(ISemanticRegion token, Procedure1<? super IHiddenRegionFormatter> after) {
	if (token != null) {
		IHiddenRegion gap = token.getNextHiddenRegion();
		set(gap, after);
	}
	return token;
}
 
Example #11
Source File: FormattableDocument.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public <T extends EObject> T append(T owner, Procedure1<? super IHiddenRegionFormatter> after) {
	if (owner != null) {
		IEObjectRegion region = getTextRegionAccess().regionForEObject(owner);
		if (region != null) {
			IHiddenRegion gap = region.getNextHiddenRegion();
			set(gap, after);
		}
	}
	return owner;
}
 
Example #12
Source File: FormattableDocument.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public <T extends EObject> T interior(T object, Procedure1<? super IHiddenRegionFormatter> init) {
	if (object != null) {
		IEObjectRegion objRegion = getTextRegionAccess().regionForEObject(object);
		if (objRegion != null) {
			IHiddenRegion previous = objRegion.getPreviousHiddenRegion();
			IHiddenRegion next = objRegion.getNextHiddenRegion();
			if (previous != null && next != null && previous != next) {
				interior(previous.getNextSemanticRegion(), next.getPreviousSemanticRegion(), init);
			}
		}
	}
	return object;
}
 
Example #13
Source File: FormattableDocument.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public <T1 extends ISemanticRegion, T2 extends ISemanticRegion> //
Pair<T1, T2> interior(T1 first, T2 second, Procedure1<? super IHiddenRegionFormatter> init) {
	if (first != null && second != null) {
		set(first.getNextHiddenRegion(), second.getPreviousHiddenRegion(), init);
	}
	return Pair.of(first, second);
}
 
Example #14
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 #15
Source File: FormattableDocument.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public <T extends EObject> T prepend(T owner, Procedure1<? super IHiddenRegionFormatter> before) {
	if (owner != null) {
		IEObjectRegion region = getTextRegionAccess().regionForEObject(owner);
		if (region != null) {
			IHiddenRegion gap = region.getPreviousHiddenRegion();
			set(gap, before);
		}
	}
	return owner;
}
 
Example #16
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 #17
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 #18
Source File: FormattableDocument.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public ISemanticRegion surround(ISemanticRegion token, Procedure1<? super IHiddenRegionFormatter> beforeAndAfter) {
	if (token != null) {
		IHiddenRegion previous = token.getPreviousHiddenRegion();
		IHiddenRegion next = token.getNextHiddenRegion();
		set(previous, next, beforeAndAfter);
	}
	return token;
}
 
Example #19
Source File: FormattableDocument.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public <T extends EObject> T surround(T owner, Procedure1<? super IHiddenRegionFormatter> beforeAndAfter) {
	if (owner != null && !owner.eIsProxy()) {
		IEObjectRegion region = getTextRegionAccess().regionForEObject(owner);
		if (region == null)
			return owner;
		IHiddenRegion previous = region.getPreviousHiddenRegion();
		IHiddenRegion next = region.getNextHiddenRegion();
		set(previous, next, beforeAndAfter);
	}
	return owner;
}
 
Example #20
Source File: XtendFormatter.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void formatAnnotations(final XtendAnnotationTarget target, @Extension final IFormattableDocument document, final Procedure1<? super IHiddenRegionFormatter> configKey) {
  boolean _isEmpty = target.getAnnotations().isEmpty();
  if (_isEmpty) {
    return;
  }
  EList<XAnnotation> _annotations = target.getAnnotations();
  for (final XAnnotation a : _annotations) {
    {
      document.<XAnnotation>format(a);
      document.<XAnnotation>append(a, configKey);
    }
  }
}
 
Example #21
Source File: DomainmodelFormatter.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void _format(final Property property, @Extension final IFormattableDocument document) {
  final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
    it.noSpace();
  };
  document.surround(this.textRegionExtensions.regionFor(property).keyword(":"), _function);
  document.<JvmTypeReference>format(property.getType());
}
 
Example #22
Source File: XtypeFormatter.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void _format(final JvmTypeParameter ref, @Extension final IFormattableDocument document) {
  EList<JvmTypeConstraint> _constraints = ref.getConstraints();
  for (final JvmTypeConstraint c : _constraints) {
    {
      final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
        it.oneSpace();
      };
      document.<JvmTypeConstraint>prepend(c, _function);
      document.<JvmTypeConstraint>format(c);
    }
  }
}
 
Example #23
Source File: XtypeFormatter.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void _format(final JvmWildcardTypeReference ref, @Extension final IFormattableDocument document) {
  boolean _isEmpty = ref.getConstraints().isEmpty();
  boolean _not = (!_isEmpty);
  if (_not) {
    final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
      it.oneSpace();
    };
    document.append(this.textRegionExtensions.regionFor(ref).keyword("?"), _function);
  }
  EList<JvmTypeConstraint> _constraints = ref.getConstraints();
  for (final JvmTypeConstraint c : _constraints) {
    document.<JvmTypeConstraint>format(c);
  }
}
 
Example #24
Source File: XbaseFormatter.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void _format(final XPostfixOperation expr, @Extension final IFormattableDocument doc) {
  final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
    it.noSpace();
  };
  doc.prepend(this.textRegionExtensions.regionFor(expr).feature(XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE), _function);
  doc.<XExpression>format(expr.getOperand());
}
 
Example #25
Source File: XbaseFormatter.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void _format(final XCastedExpression expr, @Extension final IFormattableDocument doc) {
  final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
    it.oneSpace();
  };
  doc.surround(this.textRegionExtensions.regionFor(expr).keyword("as"), _function);
  doc.<XExpression>format(expr.getTarget());
  doc.<JvmTypeReference>format(expr.getType());
}
 
Example #26
Source File: XbaseFormatter.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void _format(final XInstanceOfExpression expr, @Extension final IFormattableDocument doc) {
  final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
    it.oneSpace();
  };
  doc.surround(this.textRegionExtensions.regionFor(expr).keyword("instanceof"), _function);
  doc.<XExpression>format(expr.getExpression());
  doc.<JvmTypeReference>format(expr.getType());
}
 
Example #27
Source File: XbaseFormatter.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void _format(final JvmFormalParameter expr, @Extension final IFormattableDocument format) {
  JvmTypeReference _parameterType = expr.getParameterType();
  if (_parameterType!=null) {
    final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
      it.oneSpace();
    };
    format.<JvmTypeReference>append(_parameterType, _function);
  }
  format.<JvmTypeReference>format(expr.getParameterType());
}
 
Example #28
Source File: XbaseFormatter.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void _format(final XReturnExpression expr, @Extension final IFormattableDocument format) {
  final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
    it.oneSpace();
  };
  format.<XExpression>prepend(expr.getExpression(), _function);
  format.<XExpression>format(expr.getExpression());
}
 
Example #29
Source File: XbaseFormatter.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void _format(final XThrowExpression expr, @Extension final IFormattableDocument format) {
  final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
    it.oneSpace();
  };
  format.<XExpression>prepend(expr.getExpression(), _function);
  format.<XExpression>format(expr.getExpression());
}
 
Example #30
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);
}