Search in sources :

Example 16 with ISemanticRegion

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

the class SemanticRegionFinderTest method regionForKeywordString.

@Test
public void regionForKeywordString() throws Exception {
    Mixed mixed = parseAs("6 (foo)", Mixed.class);
    ISemanticRegionsFinder finder = toAccess(mixed).regionForEObject(mixed).getRegionFor();
    ISemanticRegion actual = finder.keyword("(");
    List<ISemanticRegion> actuals = finder.keywords("(");
    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 17 with ISemanticRegion

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

the class SemanticRegionFinderTest method regionForRuleCallUnassignedDataType.

@Test
public void regionForRuleCallUnassignedDataType() throws Exception {
    Mixed mixed = parseAs("6 (unassigned datatype foo)", Mixed.class);
    ISemanticRegionsFinder finder = toAccess(mixed).regionForEObject(mixed).getRegionFor();
    ISemanticRegion actual = finder.ruleCall(grammarAccess.getMixedAccess().getDatatypeParserRuleCall_1_1_1());
    List<ISemanticRegion> actuals = finder.ruleCalls(grammarAccess.getMixedAccess().getDatatypeParserRuleCall_1_1_1());
    assertEquals("datatype 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 18 with ISemanticRegion

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

the class SemanticRegionFinderTest method regionForRuleCallCrossReference.

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

Example 19 with ISemanticRegion

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

the class SemanticRegionFinderTest method regionForRuleCallToAssignedDataType.

@Test
public void regionForRuleCallToAssignedDataType() throws Exception {
    Mixed mixed = parseAs("6 (datatype foo)", Mixed.class);
    ISemanticRegionsFinder finder = toAccess(mixed).regionForEObject(mixed).getRegionFor();
    ISemanticRegion actual = finder.ruleCallTo(grammarAccess.getDatatypeRule());
    ISemanticRegion actuals = finder.ruleCallTo(grammarAccess.getDatatypeRule());
    Assert.assertEquals("datatype 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 20 with ISemanticRegion

use of org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion 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)

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