Search in sources :

Example 1 with ISemanticRegionsFinder

use of org.eclipse.xtext.formatting2.regionaccess.ISemanticRegionsFinder 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 2 with ISemanticRegionsFinder

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

the class ReferenceUpdater method getRegion.

protected ISemanticRegion getRegion(ITextRegionAccess access, IReferenceSnapshot ref) {
    XtextResource resource = access.getResource();
    URI objectUri = ref.getSourceEObjectUri();
    if (!resource.getURI().equals(objectUri.trimFragment())) {
        return null;
    }
    EObject object = resource.getEObject(objectUri.fragment());
    if (object == null) {
        return null;
    }
    ISemanticRegionsFinder finder = access.getExtensions().regionFor(object);
    int index = ref.getIndexInList();
    if (index < 0) {
        return finder.feature(ref.getEReference());
    } else {
        List<ISemanticRegion> list = finder.features(ref.getEReference());
        if (list != null && index < list.size()) {
            return list.get(index);
        }
    }
    return null;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) XtextResource(org.eclipse.xtext.resource.XtextResource) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) URI(org.eclipse.emf.common.util.URI) ISemanticRegionsFinder(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegionsFinder)

Example 3 with ISemanticRegionsFinder

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

the class SemanticRegionFinderTest method regionForRuleCallCrossReference.

@Test
public void regionForRuleCallCrossReference() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("6 (ref foo) action (foo) end");
    final AssignedAction mixed = this.<AssignedAction>parseAs(_builder, AssignedAction.class);
    final ISemanticRegionsFinder finder = this.toAccess(mixed).regionForEObject(mixed.getChild()).getRegionFor();
    final ISemanticRegion actual = finder.ruleCall(this._regionAccessTestLanguageGrammarAccess.getMixedAccess().getRefMixedIDTerminalRuleCall_2_2_3_1_0_1());
    final List<ISemanticRegion> actuals = finder.ruleCalls(this._regionAccessTestLanguageGrammarAccess.getMixedAccess().getRefMixedIDTerminalRuleCall_2_2_3_1_0_1());
    this.assertEquals("foo", actual, actuals);
}
Also used : AssignedAction(org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.AssignedAction) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) ISemanticRegionsFinder(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegionsFinder) Test(org.junit.Test)

Example 4 with ISemanticRegionsFinder

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

the class SemanticRegionFinderTest method regionForRuleCallAssignedTerminal.

@Test
public void regionForRuleCallAssignedTerminal() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("6 (foo)");
    final Mixed mixed = this.<Mixed>parseAs(_builder, Mixed.class);
    final ISemanticRegionsFinder finder = this.toAccess(mixed).regionForEObject(mixed).getRegionFor();
    final ISemanticRegion actual = finder.ruleCall(this._regionAccessTestLanguageGrammarAccess.getMixedAccess().getNameIDTerminalRuleCall_2_2_0_0());
    final ISemanticRegion actuals = finder.ruleCall(this._regionAccessTestLanguageGrammarAccess.getMixedAccess().getNameIDTerminalRuleCall_2_2_0_0());
    Assert.assertEquals("foo", actual, actuals);
}
Also used : Mixed(org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Mixed) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) ISemanticRegionsFinder(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegionsFinder) Test(org.junit.Test)

Example 5 with ISemanticRegionsFinder

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

the class SemanticRegionFinderTest method regionForRuleCallAssignedDataType.

@Test
public void regionForRuleCallAssignedDataType() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("6 (datatype foo)");
    final Mixed mixed = this.<Mixed>parseAs(_builder, Mixed.class);
    final ISemanticRegionsFinder finder = this.toAccess(mixed).regionForEObject(mixed).getRegionFor();
    final ISemanticRegion actual = finder.ruleCall(this._regionAccessTestLanguageGrammarAccess.getMixedAccess().getDatatypeDatatypeParserRuleCall_2_2_2_0());
    final ISemanticRegion actuals = finder.ruleCall(this._regionAccessTestLanguageGrammarAccess.getMixedAccess().getDatatypeDatatypeParserRuleCall_2_2_2_0());
    Assert.assertEquals("datatype foo", actual, actuals);
}
Also used : Mixed(org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Mixed) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) ISemanticRegionsFinder(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegionsFinder) Test(org.junit.Test)

Aggregations

ISemanticRegionsFinder (org.eclipse.xtext.formatting2.regionaccess.ISemanticRegionsFinder)22 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)20 Test (org.junit.Test)20 ISemanticRegion (org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)17 Mixed (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Mixed)14 AssignedAction (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.AssignedAction)4 Expression (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Expression)2 RegionAccessTestLanguageGrammarAccess (org.eclipse.xtext.formatting2.regionaccess.internal.services.RegionAccessTestLanguageGrammarAccess)2 Extension (org.eclipse.xtext.xbase.lib.Extension)2 URI (org.eclipse.emf.common.util.URI)1 EObject (org.eclipse.emf.ecore.EObject)1 IEObjectRegion (org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1