Search in sources :

Example 41 with ISemanticRegion

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

the class RegionAccessDiffTest method testSingleSemanticToken.

@Test
public void testSingleSemanticToken() throws Exception {
    String model = "1 foo\n";
    ITextRegionAccess access = regionAccessTestHelper.toTextRegionAccess(model);
    ITextRegionAccess modifiedAccess = regionAccessTestHelper.modify(access, (ITextRegionDiffBuilder it) -> {
        ITextRegionExtensions ext = access.getExtensions();
        EObject root = access.regionForRootEObject().getSemanticElement();
        ISemanticRegion foo = ext.allRegionsFor(root).feature(RegionaccesstestlanguagePackage.Literals.SIMPLE__NAME);
        it.replace(foo, "baaar");
    });
    String expectation = "0 0   H\n" + "      B Simple'foo' Root\n" + "0 1    S \"1\"        Simple:'1'\n" + "1 1    H \" \"        Whitespace:TerminalRule'WS'\n" + "2 5 1  S \"baaar\"    Simple:name=ID\n" + "      E Simple'foo' Root\n" + "7 0   H\n" + "------------ diff 1 ------------\n" + "2 3 S \"foo\"      Simple:name=ID\n";
    regionAccessTestHelper.assertRegions(modifiedAccess, expectation);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) EObject(org.eclipse.emf.ecore.EObject) ITextRegionDiffBuilder(org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) ITextRegionExtensions(org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions) Test(org.junit.Test)

Example 42 with ISemanticRegion

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

the class RegionAccessDiffTest method testInsertBeforeComment.

@Test
public void testInsertBeforeComment() throws Exception {
    String model = "8\n" + "/**/\n" + "a b\n";
    ITextRegionAccess access = regionAccessTestHelper.toTextRegionAccess(model);
    ITextRegionAccess modifiedAccess = regionAccessTestHelper.modify(access, (ITextRegionDiffBuilder it) -> {
        ITextRegionExtensions ext = access.getExtensions();
        ValueList rootObj = (ValueList) access.regionForRootEObject().getSemanticElement();
        ISemanticRegion a = ext.regionFor(rootObj).keyword("8").getNextSemanticRegion();
        ISemanticRegion b = a.getNextSemanticRegion();
        it.replace(a.getPreviousHiddenRegion(), a.getPreviousHiddenRegion(), b.getPreviousHiddenRegion(), b.getNextHiddenRegion());
    });
    String expectation = " 0 0   H\n" + "       B ValueList'[a, b]' Root\n" + " 0 1    S \"8\"        Root:'8'\n" + " 1 1 1  H \"\\n" + "\"       Whitespace:TerminalRule'WS'\n" + " 2 1 1  S \"b\"        ValueList:name+=ID\n" + " 3   1  H \"/**/\"     Comment:TerminalRule'ML_COMMENT' Association:PREVIOUS\n" + "   5    \"\\n" + "\"       Whitespace:TerminalRule'WS'\n" + " 8 1    S \"a\"        ValueList:name+=ID\n" + " 9 1    H \" \"        Whitespace:TerminalRule'WS'\n" + "10 1    S \"b\"        ValueList:name+=ID\n" + "       E ValueList'[a, b]' Root\n" + "11 0   H\n" + "------------ diff 1 ------------\n" + " 1   H \"\\n" + "\"       Whitespace:TerminalRule'WS'\n" + "       \"/**/\"     Comment:TerminalRule'ML_COMMENT' Association:NEXT\n" + "   6   \"\\n" + "\"       Whitespace:TerminalRule'WS'\n";
    regionAccessTestHelper.assertRegions(modifiedAccess, expectation);
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) ValueList(org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.ValueList) ITextRegionDiffBuilder(org.eclipse.xtext.formatting2.regionaccess.ITextRegionDiffBuilder) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) ITextRegionExtensions(org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions) Test(org.junit.Test)

Example 43 with ISemanticRegion

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

the class SemanticRegionFinderTest method regionForKeyword.

@Test
public void regionForKeyword() throws Exception {
    Mixed mixed = parseAs("6 (foo)", Mixed.class);
    ISemanticRegionsFinder finder = toAccess(mixed).regionForEObject(mixed).getRegionFor();
    ISemanticRegion actual = finder.keyword(grammarAccess.getMixedAccess().getLeftParenthesisKeyword_0());
    List<ISemanticRegion> actuals = finder.keywords(grammarAccess.getMixedAccess().getLeftParenthesisKeyword_0());
    assertEquals("(", actual, actuals);
}
Also used : Mixed(org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Mixed) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) ISemanticRegionsFinder(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegionsFinder) Test(org.junit.Test)

Example 44 with ISemanticRegion

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

the class SemanticRegionFinderTest method regionForAssignment.

@Test
public void regionForAssignment() throws Exception {
    Mixed mixed = parseAs("6 (foo)", Mixed.class);
    ISemanticRegionsFinder finder = toAccess(mixed).regionForEObject(mixed).getRegionFor();
    ISemanticRegion actual = finder.assignment(grammarAccess.getMixedAccess().getNameAssignment_2_2_0());
    List<ISemanticRegion> actuals = finder.assignments(grammarAccess.getMixedAccess().getNameAssignment_2_2_0());
    assertEquals("foo", actual, actuals);
}
Also used : Mixed(org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Mixed) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) ISemanticRegionsFinder(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegionsFinder) Test(org.junit.Test)

Example 45 with ISemanticRegion

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

the class SemanticRegionFinderTest method regionForRuleCallToAssignedTerminal.

@Test
public void regionForRuleCallToAssignedTerminal() throws Exception {
    Mixed mixed = parseAs("6 (foo)", Mixed.class);
    ISemanticRegionsFinder finder = toAccess(mixed).regionForEObject(mixed).getRegionFor();
    ISemanticRegion actual = finder.ruleCallTo(grammarAccess.getIDRule());
    ISemanticRegion actuals = finder.ruleCallTo(grammarAccess.getIDRule());
    Assert.assertEquals("foo", actual, actuals);
}
Also used : Mixed(org.eclipse.xtext.formatting2.regionaccess.internal.regionaccesstestlanguage.Mixed) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) ISemanticRegionsFinder(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegionsFinder) Test(org.junit.Test)

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