Search in sources :

Example 1 with ITextRegionDiffBuilder

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

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

the class RegionAccessCommentsTest method testDeleteFirstRegion1.

@Test
public void testDeleteFirstRegion1() throws Exception {
    String model = "/*h*/\n" + "\n" + "/*8*/\n" + "8 //8\n" + "/*a*/\n" + "a\n";
    ITextRegionAccess access = regionAccessTestHelper.toTextRegionAccess(model);
    ITextRegionAccess modifiedAccess = regionAccessTestHelper.modify(access, (ITextRegionDiffBuilder it) -> {
        ISemanticRegion foo = access.regionForRootEObject().getAllRegionsFor().keyword("8");
        it.remove(foo);
    });
    String expectation = " 0    1 H \"/*h*/\"    Comment:TerminalRule'ML_COMMENT' Association:CONTAINER\n" + "        \"\\n" + "\\n" + "\"     Whitespace:TerminalRule'WS'\n" + "        \"/*a*/\"    Comment:TerminalRule'ML_COMMENT' Association:NEXT\n" + "   13   \"\\n" + "\"       Whitespace:TerminalRule'WS'\n" + "        B ValueList'[a]' Root\n" + "13  1    S \"a\"        ValueList:name+=ID\n" + "        E ValueList'[a]' Root\n" + "14  0   H\n" + "------------ diff 1 ------------\n" + " 0    H \"/*h*/\"    Comment:TerminalRule'ML_COMMENT' Association:CONTAINER\n" + "        \"\\n" + "\\n" + "\"     Whitespace:TerminalRule'WS'\n" + "        \"/*8*/\"    Comment:TerminalRule'ML_COMMENT' Association:NEXT\n" + "   13   \"\\n" + "\"       Whitespace:TerminalRule'WS'\n" + "13  1 S \"8\"        Root:'8'\n" + "14    H \" \"        Whitespace:TerminalRule'WS'\n" + "        \"//8\\n" + "\"    Comment:TerminalRule'SL_COMMENT' Association:PREVIOUS\n" + "        \"/*a*/\"    Comment:TerminalRule'ML_COMMENT' Association:NEXT\n" + "   11   \"\\n" + "\"       Whitespace:TerminalRule'WS'\n";
    regionAccessTestHelper.assertRegions(modifiedAccess, expectation);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) ITextRegionDiffBuilder(org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) Test(org.junit.Test)

Example 3 with ITextRegionDiffBuilder

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

the class RegionAccessCommentsTest method testDeleteFirstRegion2.

@Test
public void testDeleteFirstRegion2() throws Exception {
    String model = "/*h*/\n" + "\n" + "/*81*/\n" + "/*82*/\n" + "8 //8\n" + "/*a*/\n" + "a\n";
    ITextRegionAccess access = regionAccessTestHelper.toTextRegionAccess(model);
    ITextRegionAccess modifiedAccess = regionAccessTestHelper.modify(access, (ITextRegionDiffBuilder it) -> {
        ISemanticRegion foo = access.regionForRootEObject().getAllRegionsFor().keyword("8");
        it.remove(foo);
    });
    String expectation = " 0    1 H \"/*h*/\"    Comment:TerminalRule'ML_COMMENT' Association:CONTAINER\n" + "        \"\\n" + "\\n" + "\"     Whitespace:TerminalRule'WS'\n" + "        \"/*a*/\"    Comment:TerminalRule'ML_COMMENT' Association:NEXT\n" + "   13   \"\\n" + "\"       Whitespace:TerminalRule'WS'\n" + "        B ValueList'[a]' Root\n" + "13  1    S \"a\"        ValueList:name+=ID\n" + "        E ValueList'[a]' Root\n" + "14  0   H\n" + "------------ diff 1 ------------\n" + " 0    H \"/*h*/\"    Comment:TerminalRule'ML_COMMENT' Association:CONTAINER\n" + "        \"\\n" + "\\n" + "\"     Whitespace:TerminalRule'WS'\n" + "        \"/*81*/\"   Comment:TerminalRule'ML_COMMENT' Association:NEXT\n" + "        \"\\n" + "\"       Whitespace:TerminalRule'WS'\n" + "        \"/*82*/\"   Comment:TerminalRule'ML_COMMENT' Association:NEXT\n" + "   21   \"\\n" + "\"       Whitespace:TerminalRule'WS'\n" + "21  1 S \"8\"        Root:'8'\n" + "22    H \" \"        Whitespace:TerminalRule'WS'\n" + "        \"//8\\n" + "\"    Comment:TerminalRule'SL_COMMENT' Association:PREVIOUS\n" + "        \"/*a*/\"    Comment:TerminalRule'ML_COMMENT' Association:NEXT\n" + "   11   \"\\n" + "\"       Whitespace:TerminalRule'WS'\n";
    regionAccessTestHelper.assertRegions(modifiedAccess, expectation);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) ITextRegionDiffBuilder(org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) Test(org.junit.Test)

Example 4 with ITextRegionDiffBuilder

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

the class RegionAccessCommentsTest method testDeleteMiddleRegion.

@Test
public void testDeleteMiddleRegion() throws Exception {
    String model = "8\n" + "a /*a*/ //a\n" + "/*b1*/\n" + "/*b2*/\n" + "b\n";
    ITextRegionAccess access = regionAccessTestHelper.toTextRegionAccess(model);
    ITextRegionAccess modifiedAccess = regionAccessTestHelper.modify(access, (ITextRegionDiffBuilder it) -> {
        ISemanticRegion foo = Iterables.getFirst(access.regionForRootEObject().getAllRegionsFor().features(RegionaccesstestlanguagePackage.Literals.VALUE_LIST__NAME), null);
        it.remove(foo);
    });
    String expectation = " 0  0   H\n" + "        B ValueList'[a, b]' Root\n" + " 0  1    S \"8\"        Root:'8'\n" + " 1    1  H \"\\n" + "\"       Whitespace:TerminalRule'WS'\n" + "         \"/*b1*/\"   Comment:TerminalRule'ML_COMMENT' Association:NEXT\n" + "         \"\\n" + "\"       Whitespace:TerminalRule'WS'\n" + "         \"/*b2*/\"   Comment:TerminalRule'ML_COMMENT' Association:NEXT\n" + "   15    \"\\n" + "\"       Whitespace:TerminalRule'WS'\n" + "16  1    S \"b\"        ValueList:name+=ID\n" + "        E ValueList'[a, b]' Root\n" + "17  0   H\n" + "------------ diff 1 ------------\n" + " 1  1 H \"\\n" + "\"       Whitespace:TerminalRule'WS'\n" + " 2  1 S \"a\"        ValueList:name+=ID\n" + " 3    H \" \"        Whitespace:TerminalRule'WS'\n" + "        \"/*a*/\"    Comment:TerminalRule'ML_COMMENT' Association:PREVIOUS\n" + "        \" \"        Whitespace:TerminalRule'WS'\n" + "        \"//a\\n" + "\"    Comment:TerminalRule'SL_COMMENT' Association:PREVIOUS\n" + "        \"/*b1*/\"   Comment:TerminalRule'ML_COMMENT' Association:NEXT\n" + "        \"\\n" + "\"       Whitespace:TerminalRule'WS'\n" + "        \"/*b2*/\"   Comment:TerminalRule'ML_COMMENT' Association:NEXT\n" + "   25   \"\\n" + "\"       Whitespace:TerminalRule'WS'\n";
    regionAccessTestHelper.assertRegions(modifiedAccess, expectation);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) ITextRegionDiffBuilder(org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) Test(org.junit.Test)

Example 5 with ITextRegionDiffBuilder

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

the class RegionAccessCommentsTest method testDeleteFirstRegion3.

@Test
public void testDeleteFirstRegion3() throws Exception {
    String model = "/*h*/\n" + "/*81*/\n" + "\n" + "/*82*/\n" + "8 //8\n" + "/*a*/\n" + "a\n";
    ITextRegionAccess access = regionAccessTestHelper.toTextRegionAccess(model);
    ITextRegionAccess modifiedAccess = regionAccessTestHelper.modify(access, (ITextRegionDiffBuilder it) -> {
        ISemanticRegion foo = access.regionForRootEObject().getAllRegionsFor().keyword("8");
        it.remove(foo);
    });
    String expectation = " 0    1 H \"/*h*/\"    Comment:TerminalRule'ML_COMMENT' Association:CONTAINER\n" + "        \"\\n" + "\"       Whitespace:TerminalRule'WS'\n" + "        \"/*81*/\"   Comment:TerminalRule'ML_COMMENT' Association:CONTAINER\n" + "        \"\\n" + "\\n" + "\"     Whitespace:TerminalRule'WS'\n" + "        \"/*a*/\"    Comment:TerminalRule'ML_COMMENT' Association:NEXT\n" + "   20   \"\\n" + "\"       Whitespace:TerminalRule'WS'\n" + "        B ValueList'[a]' Root\n" + "20  1    S \"a\"        ValueList:name+=ID\n" + "        E ValueList'[a]' Root\n" + "21  0   H\n" + "------------ diff 1 ------------\n" + " 0    H \"/*h*/\"    Comment:TerminalRule'ML_COMMENT' Association:CONTAINER\n" + "        \"\\n" + "\"       Whitespace:TerminalRule'WS'\n" + "        \"/*81*/\"   Comment:TerminalRule'ML_COMMENT' Association:CONTAINER\n" + "        \"\\n" + "\\n" + "\"     Whitespace:TerminalRule'WS'\n" + "        \"/*82*/\"   Comment:TerminalRule'ML_COMMENT' Association:NEXT\n" + "   21   \"\\n" + "\"       Whitespace:TerminalRule'WS'\n" + "21  1 S \"8\"        Root:'8'\n" + "22    H \" \"        Whitespace:TerminalRule'WS'\n" + "        \"//8\\n" + "\"    Comment:TerminalRule'SL_COMMENT' Association:PREVIOUS\n" + "        \"/*a*/\"    Comment:TerminalRule'ML_COMMENT' Association:NEXT\n" + "   11   \"\\n" + "\"       Whitespace:TerminalRule'WS'\n";
    regionAccessTestHelper.assertRegions(modifiedAccess, expectation);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) ITextRegionDiffBuilder(org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) Test(org.junit.Test)

Aggregations

ITextRegionAccess (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess)17 ITextRegionDiffBuilder (org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder)17 Test (org.junit.Test)16 ISemanticRegion (org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)15 ITextRegionExtensions (org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions)6 IEObjectRegion (org.eclipse.xtext.formatting2.regionaccess.IEObjectRegion)3 StringBasedTextRegionAccessDiffBuilder (org.eclipse.xtext.formatting2.regionaccess.internal.StringBasedTextRegionAccessDiffBuilder)3 ValueList (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.ValueList)3 EObject (org.eclipse.emf.ecore.EObject)2 Delegate (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Delegate)2 PrefixedUnassigned (org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.PrefixedUnassigned)2 IUpdatableReference (org.eclipse.xtext.ide.serializer.hooks.IUpdatableReference)2 QualifiedName (org.eclipse.xtext.naming.QualifiedName)2 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)2 IScope (org.eclipse.xtext.scoping.IScope)2 ChangeDescription (org.eclipse.emf.ecore.change.ChangeDescription)1 ChangeRecorder (org.eclipse.emf.ecore.change.util.ChangeRecorder)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 ITextRegionAccessDiff (org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccessDiff)1 ITextReplacement (org.eclipse.xtext.formatting2.regionaccess.ITextReplacement)1