Search in sources :

Example 6 with ISemanticRegion

use of org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion in project xtext-xtend by eclipse.

the class XtendFormatter method _format.

protected void _format(final XtendFunction func, @Extension final IFormattableDocument format) {
    this.formatAnnotations(func, format, XbaseFormatterPreferenceKeys.newLineAfterMethodAnnotations);
    this.formatModifiers(func, format);
    boolean _isEmpty = func.getTypeParameters().isEmpty();
    boolean _not = (!_isEmpty);
    if (_not) {
        final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
            it.noSpace();
        };
        format.append(this.textRegionExtensions.regionFor(func).keyword("<"), _function);
        EList<JvmTypeParameter> _typeParameters = func.getTypeParameters();
        for (final JvmTypeParameter arg : _typeParameters) {
            {
                format.<JvmTypeParameter>format(arg);
                final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
                    it.noSpace();
                };
                final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
                    it.oneSpace();
                };
                format.append(format.prepend(this.textRegionExtensions.immediatelyFollowing(arg).keyword(","), _function_1), _function_2);
            }
        }
        final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
            it.noSpace();
        };
        final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
            it.oneSpace();
        };
        format.append(format.prepend(this.textRegionExtensions.regionFor(func).keyword(">"), _function_1), _function_2);
    }
    final ISemanticRegion nameNode = this.textRegionExtensions.regionFor(func).feature(XtendPackage.Literals.XTEND_FUNCTION__NAME);
    ISemanticRegionFinder _immediatelyFollowing = null;
    if (nameNode != null) {
        _immediatelyFollowing = nameNode.immediatelyFollowing();
    }
    ISemanticRegion _keyword = null;
    if (_immediatelyFollowing != null) {
        _keyword = _immediatelyFollowing.keyword("(");
    }
    final ISemanticRegion open = _keyword;
    final ISemanticRegion close = this.textRegionExtensions.regionFor(func).keyword(")");
    final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it) -> {
        it.oneSpace();
    };
    format.<JvmTypeReference>append(func.getReturnType(), _function_3);
    final Procedure1<IHiddenRegionFormatter> _function_4 = (IHiddenRegionFormatter it) -> {
        it.noSpace();
    };
    format.prepend(open, _function_4);
    XExpression _expression = func.getExpression();
    boolean _tripleNotEquals = (_expression != null);
    if (_tripleNotEquals) {
        format.append(close, XbaseFormatterPreferenceKeys.bracesInNewLine);
    }
    this.formatCommaSeparatedList(func.getParameters(), open, close, format);
    format.<JvmTypeReference>format(func.getReturnType());
    format.<XExpression>format(func.getExpression());
}
Also used : IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) XExpression(org.eclipse.xtext.xbase.XExpression) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) ISemanticRegionFinder(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegionFinder)

Example 7 with ISemanticRegion

use of org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion in project xtext-xtend by eclipse.

the class XtendFormatter method formatBody.

protected ISemanticRegion formatBody(final XtendTypeDeclaration type, @Extension final IFormattableDocument format) {
    ISemanticRegion _xblockexpression = null;
    {
        final ISemanticRegion open = this.textRegionExtensions.regionFor(type).keyword("{");
        final ISemanticRegion close = this.textRegionExtensions.regionFor(type).keyword("}");
        final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
            it.indent();
        };
        format.<ISemanticRegion, ISemanticRegion>interior(open, close, _function);
        format.prepend(open, XbaseFormatterPreferenceKeys.bracesInNewLine);
        ISemanticRegion _xifexpression = null;
        boolean _isEmpty = type.getMembers().isEmpty();
        boolean _not = (!_isEmpty);
        if (_not) {
            format.append(open, XtendFormatterPreferenceKeys.blankLinesBeforeFirstMember);
            int _size = type.getMembers().size();
            int _minus = (_size - 1);
            IntegerRange _upTo = new IntegerRange(0, _minus);
            for (final Integer i : _upTo) {
                {
                    final XtendMember current = type.getMembers().get((i).intValue());
                    format.<XtendMember>format(current);
                    int _size_1 = type.getMembers().size();
                    int _minus_1 = (_size_1 - 1);
                    boolean _lessThan = ((i).intValue() < _minus_1);
                    if (_lessThan) {
                        final XtendMember next = type.getMembers().get(((i).intValue() + 1));
                        if (((current instanceof XtendField) && (next instanceof XtendField))) {
                            format.<XtendMember>append(current, XtendFormatterPreferenceKeys.blankLinesBetweenFields);
                        } else {
                            if (((current instanceof XtendFunction) && (next instanceof XtendFunction))) {
                                format.<XtendMember>append(current, XtendFormatterPreferenceKeys.blankLinesBetweenMethods);
                            } else {
                                format.<XtendMember>append(current, XtendFormatterPreferenceKeys.blankLinesBetweenFieldsAndMethods);
                            }
                        }
                    } else {
                        final XtendMember member = type.getMembers().get((i).intValue());
                        format.<XtendMember>append(member, XtendFormatterPreferenceKeys.blankLinesAfterLastMember);
                    }
                }
            }
        } else {
            final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
                it.newLine();
            };
            _xifexpression = format.append(open, _function_1);
        }
        _xblockexpression = _xifexpression;
    }
    return _xblockexpression;
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) IntegerRange(org.eclipse.xtext.xbase.lib.IntegerRange) IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) JvmTypeConstraint(org.eclipse.xtext.common.types.JvmTypeConstraint) XtendField(org.eclipse.xtend.core.xtend.XtendField)

Example 8 with ISemanticRegion

use of org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion in project xtext-xtend by eclipse.

the class RichStringToLineModel method announceNextLiteral.

@Override
public void announceNextLiteral(final RichStringLiteral object) {
    super.announceNextLiteral(object);
    if (((this.lastLiteralEndOffset > 0) && (this.contentStartOffset < 0))) {
        this.contentStartOffset = this.lastLiteralEndOffset;
    }
    IEObjectRegion _regionForEObject = this.nodeModelAccess.regionForEObject(object);
    ISemanticRegionsFinder _regionFor = null;
    if (_regionForEObject != null) {
        _regionFor = _regionForEObject.getRegionFor();
    }
    ISemanticRegion _feature = null;
    if (_regionFor != null) {
        _feature = _regionFor.feature(XbasePackage.Literals.XSTRING_LITERAL__VALUE);
    }
    final ISemanticRegion node = _feature;
    if ((node != null)) {
        int _offset = node.getOffset();
        int _literalPrefixLenght = this.literalPrefixLenght(node);
        int _plus = (_offset + _literalPrefixLenght);
        this.offset = _plus;
        int _endOffset = node.getEndOffset();
        int _literalPostfixLenght = this.literalPostfixLenght(node);
        int _minus = (_endOffset - _literalPostfixLenght);
        this.lastLiteralEndOffset = _minus;
    }
    this.content = true;
}
Also used : IEObjectRegion(org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) ISemanticRegionsFinder(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegionsFinder)

Example 9 with ISemanticRegion

use of org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion in project xtext-core by eclipse.

the class TestLanguageReferenceUpdater method updateReference.

@Override
public void updateReference(ITextRegionDiffBuilder rewriter, IUpdatableReference ref) {
    if (rewriter.isModified(ref.getReferenceRegion())) {
        return;
    }
    IScope scope = scopeProvider.getScope(ref.getSourceEObject(), ref.getEReference());
    ISemanticRegion region = ref.getReferenceRegion();
    QualifiedName oldName = nameConverter.toQualifiedName(region.getText());
    IEObjectDescription oldDesc = scope.getSingleElement(oldName);
    if (oldDesc != null && oldDesc.getEObjectOrProxy() == ref.getTargetEObject()) {
        return;
    }
    String newName = findValidName(ref, scope);
    if (newName != null) {
        if (oldName.getSegmentCount() > 1) {
            newName = oldName.skipLast(1).append(newName).toString();
        }
        rewriter.replace(region, newName);
    }
}
Also used : QualifiedName(org.eclipse.xtext.naming.QualifiedName) IScope(org.eclipse.xtext.scoping.IScope) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 10 with ISemanticRegion

use of org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion in project xtext-core by eclipse.

the class AbstractEObjectRegion method getAllSemanticRegions.

@Override
public Iterable<ISemanticRegion> getAllSemanticRegions() {
    ISemanticRegion first = previousHidden.getNextSemanticRegion();
    ISemanticRegion last = nextHidden.getPreviousSemanticRegion();
    return new SemanticRegionIterable(first, last);
}
Also used : ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)

Aggregations

ISemanticRegion (org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)59 Test (org.junit.Test)30 ISemanticRegionsFinder (org.eclipse.xtext.formatting2.regionaccess.ISemanticRegionsFinder)18 ITextRegionAccess (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess)15 IHiddenRegionFormatter (org.eclipse.xtext.formatting2.IHiddenRegionFormatter)14 ITextRegionDiffBuilder (org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder)13 Mixed (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Mixed)12 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)9 IHiddenRegion (org.eclipse.xtext.formatting2.regionaccess.IHiddenRegion)7 ITextRegionExtensions (org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions)7 EObject (org.eclipse.emf.ecore.EObject)4 IEObjectRegion (org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion)4 AssignedAction (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.AssignedAction)4 XExpression (org.eclipse.xtext.xbase.XExpression)4 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)3 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)3 ValueList (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.ValueList)3 LinkedList (java.util.LinkedList)2 EReference (org.eclipse.emf.ecore.EReference)2 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)2