use of org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess in project xtext-core by eclipse.
the class RegionAccessDiffTest method testMove.
@Test
public void testMove() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("8 a b c");
_builder.newLine();
final ITextRegionAccess access = this._regionAccessTestHelper.toTextRegionAccess(_builder);
final Procedure1<ITextRegionDiffBuilder> _function = (ITextRegionDiffBuilder it) -> {
final List<ISemanticRegion> regions = access.regionForRootEObject().getAllRegionsFor().features(RegionaccesstestlanguagePackage.Literals.VALUE_LIST__NAME);
final ISemanticRegion a = regions.get(0);
final ISemanticRegion b = regions.get(1);
it.move(b.getNextHiddenRegion(), a.getPreviousHiddenRegion(), a.getNextHiddenRegion());
};
ITextRegionAccess _modify = this._regionAccessTestHelper.modify(access, _function);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("0 0 H");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("B ValueList\'[a, b, c]\' Root");
_builder_1.newLine();
_builder_1.append("0 1 S \"8\" Root:\'8\'");
_builder_1.newLine();
_builder_1.append("1 1 H \" \" Whitespace:TerminalRule\'WS\'");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("2 \" \" Whitespace:TerminalRule\'WS\'");
_builder_1.newLine();
_builder_1.append("3 1 S \"b\" ValueList:name+=ID");
_builder_1.newLine();
_builder_1.append("4 1 2 H \" \" Whitespace:TerminalRule\'WS\'");
_builder_1.newLine();
_builder_1.append("5 1 2 S \"a\" ValueList:name+=ID");
_builder_1.newLine();
_builder_1.append("6 0 2 H");
_builder_1.newLine();
_builder_1.append("6 1 S \"c\" ValueList:name+=ID");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("E ValueList\'[a, b, c]\' Root");
_builder_1.newLine();
_builder_1.append("7 0 H");
_builder_1.newLine();
_builder_1.append("------------ diff 1 ------------");
_builder_1.newLine();
_builder_1.append("1 1 H \" \" Whitespace:TerminalRule\'WS\'");
_builder_1.newLine();
_builder_1.append("2 1 S \"a\" ValueList:name+=ID");
_builder_1.newLine();
_builder_1.append("3 1 H \" \" Whitespace:TerminalRule\'WS\'");
_builder_1.newLine();
_builder_1.append("------------ diff 2 ------------");
_builder_1.newLine();
_builder_1.append("5 1 H \" \" Whitespace:TerminalRule\'WS\'");
_builder_1.newLine();
_builder_1.append("6 1 S \"c\" ValueList:name+=ID");
_builder_1.newLine();
this._regionAccessTestHelper.operator_tripleEquals(_modify, _builder_1);
}
use of org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess in project xtext-core by eclipse.
the class RegionAccessTestHelper method toTextRegionAccess.
public ITextRegionAccess toTextRegionAccess(final CharSequence file) {
try {
final Root obj = this.parseHelper.parse(file.toString().replace("\r\n", "\n").trim());
this.validationTestHelper.assertNoErrors(obj);
Resource _eResource = obj.eResource();
return this.textRegionAccessBuilder.get().forNodeModel(((XtextResource) _eResource)).create();
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess in project xtext-core by eclipse.
the class TextReplacerContext method isWrapInRegion.
@Override
public boolean isWrapInRegion() {
ITextRegionAccess access = getDocument().getRequest().getTextRegionAccess();
ITextSegment region = getReplacer().getRegion();
int lastOffset = region.getOffset();
for (ITextReplacement rep : this.getLocalReplacements()) {
int endOffset = rep.getOffset();
String between = access.textForOffset(lastOffset, endOffset - lastOffset);
if (between.contains("\n") || rep.getReplacementText().contains("\n")) {
return true;
}
lastOffset = rep.getEndOffset();
}
String rest = access.textForOffset(lastOffset, region.getEndOffset() - lastOffset);
if (rest.contains("\n")) {
return true;
}
return false;
}
use of org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess in project xtext-core by eclipse.
the class LineRegion method getPreviousLine.
@Override
public ILineRegion getPreviousLine() {
ITextRegionAccess access = getTextRegionAccess();
int end = getOffset() - 1;
String text = access.regionForDocument().getText();
while (true) {
if (end < 0)
return null;
char c = text.charAt(end);
if (c == '\n' || c == '\r')
end--;
else
break;
}
int start = text.lastIndexOf('\n', end);
if (start < 0)
start = 0;
return new LineRegion(access, start, end - start);
}
use of org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess in project xtext-core by eclipse.
the class TextRegionAccessToString method toTokenAndGapList.
protected List<ITextSegment> toTokenAndGapList() {
final int range = this.hightlightOrigin ? 4 : (Integer.MAX_VALUE / 2);
ITextSegment first = null;
{
ITextSegment current = origin;
for (int i = 0; i < range && current != null; i++) {
first = current;
if (current instanceof ITextRegionAccess)
current = ((ITextRegionAccess) current).regionForRootEObject().getPreviousHiddenRegion();
else if (current instanceof ISequentialRegion)
current = ((ISequentialRegion) current).getPreviousHiddenRegion();
else if (current instanceof IHiddenRegionPart)
current = ((IHiddenRegionPart) current).getHiddenRegion();
else
throw new IllegalStateException("Unexpected Type: " + current.getClass());
}
}
if (first == null)
return Collections.emptyList();
List<ITextSegment> result = Lists.newArrayList();
{
ITextSegment current = first;
for (int i = 0; i <= (range * 2) && current != null; i++) {
result.add(current);
if (current instanceof ISemanticRegion)
current = ((ISemanticRegion) current).getNextHiddenRegion();
else if (current instanceof IHiddenRegion)
current = ((IHiddenRegion) current).getNextSemanticRegion();
else
throw new IllegalStateException("Unexpected Type: " + current.getClass());
}
}
return result;
}
Aggregations