public ITextSegment getRegion() { final SeparatorEntry<T, R> prev = this.getLeadingSeparator(); final SeparatorEntry<T, R> trail = this.getTrailingSeparator(); int _xifexpression = (int) 0; if ((prev != null)) { _xifexpression = prev.getSeparator().getEndOffset(); } else { _xifexpression = this.list.getRoot().getOffset(); } final int offset = _xifexpression; int _xifexpression_1 = (int) 0; if ((trail != null)) { _xifexpression_1 = trail.getSeparator().getOffset(); } else { _xifexpression_1 = this.list.getRoot().getEndOffset(); } final int endOffset = _xifexpression_1; ITextRegionAccess _textRegionAccess = this.list.getRoot().getTextRegionAccess(); return new TextSegment(_textRegionAccess, offset, (endOffset - offset)); }
protected void assertAllWhitespaceIsFormatted(ITextRegionAccess access, List<ITextReplacement> replacements) { List<ITextSegment> expected = Lists.newArrayList(); IHiddenRegion current = access.regionForRootEObject().getPreviousHiddenRegion(); while (current != null) { expected.addAll(current.getMergedSpaces()); current = current.getNextHiddenRegion(); } List<ITextSegment> missing = TextRegions.difference(expected, replacements); if (!missing.isEmpty()) { TextRegionsToString toString = new TextRegionsToString().setTextRegionAccess(access); for (ITextSegment region : missing) toString.add(region, region.getClass().getSimpleName()); String msg = "The following regions are not formatted:\n" + toString; System.err.println(msg); Assert.fail(msg); } }
@Override public String toString() { List<ITextSegment> list = toTokenAndGapList(); if (list.isEmpty()) return "(empty)"; ITextRegionAccess access = list.get(0).getTextRegionAccess(); DiffColumn diff = new DiffColumn(access); TextRegionListToString result = new TextRegionListToString(); if (!hideColumnExplanation) { if (diff.isDiff()) { result.add("Columns: 1:offset 2:length 3:diff 4:kind 5: text 6:grammarElement", false); } else { result.add("Columns: 1:offset 2:length 3:kind 4: text 5:grammarElement", false); } result.add("Kind: H=IHiddenRegion S=ISemanticRegion B/E=IEObjectRegion", false); result.add("", false); } appendRegions(result, list, diff, false); diff.appendDiffs(result, this); return result.toString(); }
@Override public String toString() { ITextRegionAccess access = getTextRegionAccess(); ITextSegment frame = getFrame(); if (access == null || frame == null) return "(null)"; ITextRegionRewriter rewriter = access.getRewriter(); StringBuilder builder = new StringBuilder(); List<ITextReplacement> replacements = Lists.newArrayList(); for (int i = 0; i < this.items.size(); i++) { Item item = this.items.get(i); ITextSegment region = item.getRegion(); String regionStr = "offset=" + region.getOffset() + " length=" + region.getLength(); String open = i < BRACKETS_OPEN.length ? BRACKETS_OPEN[i] : "[" + i + "["; String close = i < BRACKETS_CLOSE.length ? BRACKETS_CLOSE[i] : "]" + i + "]"; builder.append(open + close + ": " + item.getTitle() + " at " + regionStr + "\n"); replacements.add(rewriter.createReplacement(region.getOffset(), 0, open)); replacements.add(rewriter.createReplacement(region.getEndOffset(), 0, close)); } String vizualized = rewriter.renderToString(frame, replacements); builder.append(box("document snippet", vizualized)); return builder.toString(); }
@Override public List<IHiddenRegionPart> merge(ITextRegionAccess b, IHiddenRegion first, IHiddenRegion last, boolean del) { List<IHiddenRegionPart> parts1 = first.getParts(); List<IHiddenRegionPart> parts2 = last.getParts(); boolean firstInFile1 = first.getPreviousSemanticRegion() == null; boolean firstInFile2 = last.getPreviousSemanticRegion() == null; int index1 = firstInFile1 ? getIndexFirstInFile(parts1) : getIndex(parts1); int index2 = firstInFile2 ? getIndexFirstInFile(parts2) : getIndex(parts2); List<IHiddenRegionPart> result = Lists.newArrayList(); if (del && !first.isMultiline()) { result.addAll(parts1); } else { for (int i = 0; i < index1; i++) { result.add(parts1.get(i)); } } if (del && !last.isMultiline()) { result.addAll(parts2); } else { for (int i = index2; i < parts2.size(); i++) { result.add(parts2.get(i)); } } return result; }
@Override public ILineRegion getNextLine() { ITextRegionAccess access = getTextRegionAccess(); int start = getEndOffset() + 1; String text = access.regionForDocument().getText(); while (true) { if (start >= text.length()) return null; char c = text.charAt(start); if (c == '\n' || c == '\r') start++; else break; } int end = text.indexOf('\n', start); if (end > 0) { if (text.charAt(end - 1) == '\r') end = end - 1; } else end = text.length(); return new LineRegion(access, start, end - start); }
@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); }
protected List<ITextReplacement> format2(final XtextResource resource, final ITextRegion selection, final ITypedPreferenceValues preferences) { final FormatterRequest request = this.formatterRequestProvider.get(); request.setAllowIdentityEdits(false); request.setFormatUndefinedHiddenRegionsOnly(false); if ((selection != null)) { request.setRegions(Collections.<ITextRegion>unmodifiableList(CollectionLiterals.<ITextRegion>newArrayList(selection))); } if ((preferences != null)) { request.setPreferences(preferences); } final ITextRegionAccess regionAccess = this.regionBuilder.forNodeModel(resource).create(); request.setTextRegionAccess(regionAccess); final IFormatter2 formatter2 = this.formatter2Provider.get(); final List<ITextReplacement> replacements = formatter2.format(request); return replacements; }
@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; }
protected boolean isInRequestedRange(EObject obj) { Collection<ITextRegion> regions = request.getRegions(); if (regions.isEmpty()) return true; ITextRegionAccess access = request.getTextRegionAccess(); IEObjectRegion objRegion = access.regionForEObject(obj); if (objRegion == null) return false; IHiddenRegion previousHidden = objRegion.getPreviousHiddenRegion(); IHiddenRegion nextHidden = objRegion.getNextHiddenRegion(); int objOffset = previousHidden != null ? previousHidden.getOffset() : 0; int objEnd = nextHidden != null ? nextHidden.getEndOffset() : access.regionForRootEObject().getEndOffset(); for (ITextRegion region : regions) { int regionOffset = region.getOffset(); int regionEnd = regionOffset + region.getLength(); if (regionOffset <= objEnd && regionEnd >= objOffset) return true; } return false; }
private void operator_tripleEquals(final CharSequence file, final CharSequence expectation) { try { final String exp = expectation.toString(); final Root obj = this.parseHelper.parse(file); this.validationTestHelper.assertNoErrors(obj); final ITextRegionAccess access1 = this.createFromNodeModel(obj); final ITextRegionAccess access2 = this.serializer.serializeToRegions(obj); this.assertToStringDoesNotCrash(access1); this.assertToStringDoesNotCrash(access2); this.assertLinesAreConsistent(access1); this.assertLinesAreConsistent(access2); TextRegionAccessToString _cfg = this.cfg(new TextRegionAccessToString().withRegionAccess(access1)); final String tra1 = (_cfg + "\n"); TextRegionAccessToString _cfg_1 = this.cfg(new TextRegionAccessToString().withRegionAccess(access2)); final String tra2 = (_cfg_1 + "\n"); Assert.assertEquals(Strings.toPlatformLineSeparator(exp), Strings.toPlatformLineSeparator(tra1)); Assert.assertEquals(Strings.toPlatformLineSeparator(exp), Strings.toPlatformLineSeparator(tra2)); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
private void assertToStringDoesNotCrash(final ITextRegionAccess access) { IHiddenRegion _previousHiddenRegion = access.regionForRootEObject().getPreviousHiddenRegion(); ISequentialRegion current = ((ISequentialRegion) _previousHiddenRegion); while ((current != null)) { { Assert.assertNotNull(current.toString()); boolean _matched = false; if (current instanceof IHiddenRegion) { _matched=true; current = ((IHiddenRegion)current).getNextSemanticRegion(); } if (!_matched) { if (current instanceof ISemanticRegion) { _matched=true; Assert.assertNotNull(((ISemanticRegion)current).getEObjectRegion().toString()); current = ((ISemanticRegion)current).getNextHiddenRegion(); } } } } }
protected IAstRegion findRegion(IEObjectRegion owner, FeatureChange change) { EStructuralFeature feature = change.getFeature(); if (feature instanceof EReference && ((EReference) feature).isContainment()) { ITextRegionAccess access = owner.getTextRegionAccess(); EObject oldValue = change.getReferenceValue(); if (oldValue != null) { return access.regionForEObject(oldValue); } EObject value = (EObject) owner.getSemanticElement().eGet(feature); if (value != null) { return access.regionForEObject(value); } return null; } else { return owner.getRegionFor().feature(feature); } }
private ITextSegment getRegionForLines(ITextRegionAccess regions, int offset, int lines) { ILineRegion firstLine = regions.regionForLineAtOffset(offset); ILineRegion lastLine = firstLine; for (int i = 1; i < lines; i++) { ILineRegion next = lastLine.getNextLine(); if (next != null) { lastLine = next; } else { break; } } int firstLineOffset = firstLine.getOffset(); ITextSegment region = regions.regionForOffset(firstLineOffset, (lastLine.getEndOffset() - firstLineOffset) + 1); return region; }
@Override protected TextEdit createTextEdit(List<ITextReplacement> replacements) { if (replacements.isEmpty()) { return new ReplaceEdit(0, 0, ""); } ITextRegionAccess regionAccess = replacements.get(0).getTextRegionAccess(); String newDocument = regionAccess.getRewriter().renderToString(replacements); return new ReplaceEdit(0, regionAccess.regionForDocument().getLength(), newDocument); }
public ITextRegionAccess serializeToRegions(EObject obj) { checkNotNull(obj, "obj must not be null."); ISerializationContext context = getIContext(obj); TextRegionAccessBuilder builder = textRegionBuilderProvider.get(); ISerializationDiagnostic.Acceptor errors = ISerializationDiagnostic.EXCEPTION_THROWING_ACCEPTOR; serialize(context, obj, builder.forSequence(context, obj), errors); ITextRegionAccess regionAccess = builder.create(); return regionAccess; }
protected void serialize(EObject obj, Appendable appendable, SaveOptions options) throws IOException { ITextRegionAccess regionAccess = serializeToRegions(obj); FormatterRequest request = formatterRequestProvider.get(); request.setFormatUndefinedHiddenRegionsOnly(!options.isFormatting()); request.setTextRegionAccess(regionAccess); IFormatter2 formatter2 = formatter2Provider.get(); List<ITextReplacement> replacements = formatter2.format(request); regionAccess.getRewriter().renderToAppendable(replacements, appendable); }
public ITextSegment getFrame() { if (this.frame != null) return this.frame; ITextRegionAccess access = getTextRegionAccess(); if (access != null) { ITextSegment impactRegion = TextRegions.merge(this.items); List<ILineRegion> expandToLines = TextRegions.expandToLines(impactRegion, getLeadingLines(), getTrailingLines()); return TextRegions.merge(expandToLines); } return null; }
public ITextRegionAccess getTextRegionAccess() { if (this.textRegionAccess != null) return this.textRegionAccess; for (ITextReplacement item : this.items) return item.getTextRegionAccess(); return null; }
@Override public String toString() { try { ITextRegionAccess access = getTextRegionAccess(); ITextSegment frame = getFrame(); if (access == null || frame == null) return box(title, "(no changes)"); StringBuilder builder = new StringBuilder(); String vizualized = access.getRewriter().renderToString(frame, items); builder.append(box(title, vizualized)); return builder.toString(); } catch (Exception e) { return box("error", e.getMessage() + "\n" + Throwables.getStackTraceAsString(e)); } }
public DiffColumn(ITextRegionAccess access) { if (access instanceof ITextRegionAccessDiff) { this.diffs = Maps.newHashMap(); this.access = (ITextRegionAccessDiff) access; int width = 0; int i = 1; for (ITextSegmentDiff diff : this.access.getRegionDifferences()) { ISequentialRegion current = (ISequentialRegion) diff.getModifiedFirstRegion(); ISequentialRegion last = (ISequentialRegion) diff.getModifiedLastRegion(); String text = i + " "; if (width < text.length()) { width = text.length(); } while (current != null) { diffs.put(current, text); if (current.equals(last)) { break; } current = current.getNextSequentialRegion(); } i++; } this.empty = Strings.repeat(" ", width); } else { this.access = null; this.empty = ""; } }
public ITextSegment getFrame() { if (this.frame != null) return this.frame; ITextRegionAccess access = getTextRegionAccess(); if (access != null) { List<ITextSegment> segments = Lists.newArrayList(); for (Item item : items) segments.add(item.getRegion()); ITextSegment impactRegion = merge(segments); List<ILineRegion> expandToLines = expandToLines(impactRegion, getLeadingLines(), getTrailingLines()); return merge(expandToLines); } return null; }
public ITextRegionAccess getTextRegionAccess() { if (this.textRegionAccess != null) return this.textRegionAccess; for (Item item : this.items) return item.region.getTextRegionAccess(); return null; }
/** * Sets the {@link #textRegionAccess}. If the region has syntax errors and no explicit {@link ExceptionAcceptor} is * configured yet, the {@link ExceptionAcceptor#IGNORING ignoring acceptor} will be configured. */ public FormatterRequest setTextRegionAccess(ITextRegionAccess tokens) { if (tokens.hasSyntaxError() && this.exceptionHandler == null) this.exceptionHandler = ExceptionAcceptor.IGNORING; this.textRegionAccess = tokens; return this; }
@Override public void replace(IHiddenRegion originalFirst, IHiddenRegion originalLast, ITextRegionAccess acc) { checkOriginal(originalFirst); checkOriginal(originalLast); IEObjectRegion substituteRoot = acc.regionForRootEObject(); IHiddenRegion substituteFirst = substituteRoot.getPreviousHiddenRegion(); IHiddenRegion substituteLast = substituteRoot.getNextHiddenRegion(); replace(originalFirst, originalLast, substituteFirst, substituteLast); }
protected Map<EObject, AbstractEObjectRegion> getEObjectToTokensMap(ITextRegionAccess regionAccess) { this.eObjToTokens = Maps.newHashMap(); this.firstHidden = createHiddenRegion(regionAccess); this.lastHidden = this.firstHidden; NodeModelBasedRegionAccess access = (NodeModelBasedRegionAccess) regionAccess; ICompositeNode rootNode = resource.getParseResult().getRootNode(); process(rootNode, access); return ImmutableMap.<EObject, AbstractEObjectRegion>copyOf(this.eObjToTokens); }
public TextReplacement(ITextRegionAccess access, int offset, int length, String text) { super(); Preconditions.checkArgument(offset >= 0, "offset must be >= 0"); Preconditions.checkArgument(length >= 0, "length must be >= 0"); this.access = access; this.offset = offset; this.length = length; this.replacement = text; }
protected IHiddenRegion copyAndAppend(IHiddenRegion region1, IHiddenRegion region2) { StringHiddenRegion region = appendHiddenRegion(region1.isUndefined() || region2.isUndefined()); ITextRegionAccess original = access.getOriginalTextRegionAccess(); List<IHiddenRegionPart> merged = hiddenRegionMerger.merge(original, region1, region2, false); copyHiddenRegionParts(region, merged); return region; }
public SequentialRegionDiff copySurroundingHidden(IHiddenRegion originalFirst, IHiddenRegion originalLast, boolean delete) { boolean firstHidden = originalFirst instanceof IHiddenRegion; boolean lastHidden = originalLast instanceof IHiddenRegion; if (firstHidden && lastHidden) { IHiddenRegion hiddenFirst = (IHiddenRegion) originalFirst; IHiddenRegion hiddenLast = (IHiddenRegion) originalLast; StringHiddenRegion merged = appendHiddenRegion(hiddenFirst.isUndefined() || hiddenLast.isUndefined()); ITextRegionAccess original = access.getOriginalTextRegionAccess(); List<IHiddenRegionPart> parts = hiddenRegionMerger.merge(original, hiddenFirst, hiddenLast, delete); copyHiddenRegionParts(merged, parts); return new SequentialRegionDiff(originalFirst, originalLast, merged, merged); } IHiddenRegion inserted = null; if (originalFirst == null) { if (!lastHidden) { inserted = appendHiddenRegion(true); } } else if (originalLast == null) { if (!firstHidden) { inserted = appendHiddenRegion(true); } } else if (!firstHidden && !lastHidden) { inserted = appendHiddenRegion(true); } return new SequentialRegionDiff(originalFirst, originalLast, inserted, inserted); }
@Override public String getText() { ITextRegionAccess access = getTextRegionAccess(); if (access != null) return ((AbstractRegionAccess) access).textForOffset(getOffset(), getLength()); return null; }
@Override public boolean isWrapSincePrevious() { ITextRegionAccess access = getDocument().getRequest().getTextRegionAccess(); ITextSegment region = getRegion(0); ITextSegment previousRegion = getRegion(1); if (previousRegion != null) { int offset = previousRegion.getEndOffset(); String between = access.textForOffset(offset, region.getOffset() - offset); if (between.contains("\n")) { return true; } } return false; }
@Test public void testMandatoryValueChange() { final IChangeSerializer.IModification<MandatoryValue> _function = (MandatoryValue it) -> { it.setName("bar"); }; ITextRegionAccess _recordDiff = this.<MandatoryValue>recordDiff(MandatoryValue.class, "#2 foo", _function); StringConcatenation _builder = new StringConcatenation(); _builder.append("0 0 H"); _builder.newLine(); _builder.append(" "); _builder.append("B MandatoryValue\'bar\' Model"); _builder.newLine(); _builder.append("0 2 S \"#2\" Model:\'#2\'"); _builder.newLine(); _builder.append("2 1 H \" \" Whitespace:TerminalRule\'WS\'"); _builder.newLine(); _builder.append("3 3 1 S \"bar\" MandatoryValue:name=ID"); _builder.newLine(); _builder.append(" "); _builder.append("E MandatoryValue\'bar\' Model"); _builder.newLine(); _builder.append("6 0 H"); _builder.newLine(); _builder.append("------------ diff 1 ------------"); _builder.newLine(); _builder.append("3 3 S \"foo\" MandatoryValue:name=ID"); _builder.newLine(); this._changeSerializerTestHelper.operator_tripleEquals(_recordDiff, _builder); }
@Test public void testOptionalValueInsert() { final IChangeSerializer.IModification<OptionalValue> _function = (OptionalValue it) -> { it.setName("foo"); }; ITextRegionAccess _recordDiff = this.<OptionalValue>recordDiff(OptionalValue.class, "#3", _function); StringConcatenation _builder = new StringConcatenation(); _builder.append("0 0 1 H"); _builder.newLine(); _builder.append(" "); _builder.append("B OptionalValue\'foo\' Model"); _builder.newLine(); _builder.append("0 2 1 S \"#3\" Model:\'#3\'"); _builder.newLine(); _builder.append("2 0 1 H"); _builder.newLine(); _builder.append("2 3 1 S \"foo\" OptionalValue:name=ID"); _builder.newLine(); _builder.append(" "); _builder.append("E OptionalValue\'foo\' Model"); _builder.newLine(); _builder.append("5 0 1 H"); _builder.newLine(); _builder.append("------------ diff 1 ------------"); _builder.newLine(); _builder.append("0 0 H"); _builder.newLine(); _builder.append("0 2 S \"#3\" Model:\'#3\'"); _builder.newLine(); _builder.append("2 0 H"); _builder.newLine(); this._changeSerializerTestHelper.operator_tripleEquals(_recordDiff, _builder); }
@Test public void testOptionalValueChange() { final IChangeSerializer.IModification<OptionalValue> _function = (OptionalValue it) -> { it.setName("baz"); }; ITextRegionAccess _recordDiff = this.<OptionalValue>recordDiff(OptionalValue.class, "#3 foo", _function); StringConcatenation _builder = new StringConcatenation(); _builder.append("0 0 H"); _builder.newLine(); _builder.append(" "); _builder.append("B OptionalValue\'baz\' Model"); _builder.newLine(); _builder.append("0 2 S \"#3\" Model:\'#3\'"); _builder.newLine(); _builder.append("2 1 H \" \" Whitespace:TerminalRule\'WS\'"); _builder.newLine(); _builder.append("3 3 1 S \"baz\" OptionalValue:name=ID"); _builder.newLine(); _builder.append(" "); _builder.append("E OptionalValue\'baz\' Model"); _builder.newLine(); _builder.append("6 0 H"); _builder.newLine(); _builder.append("------------ diff 1 ------------"); _builder.newLine(); _builder.append("3 3 S \"foo\" OptionalValue:name=ID"); _builder.newLine(); this._changeSerializerTestHelper.operator_tripleEquals(_recordDiff, _builder); }
@Test public void testOptionalValueRemove() { final IChangeSerializer.IModification<OptionalValue> _function = (OptionalValue it) -> { it.setName(null); }; ITextRegionAccess _recordDiff = this.<OptionalValue>recordDiff(OptionalValue.class, "#3 foo", _function); StringConcatenation _builder = new StringConcatenation(); _builder.append("0 0 H"); _builder.newLine(); _builder.append(" "); _builder.append("B OptionalValue Model"); _builder.newLine(); _builder.append("0 2 S \"#3\" Model:\'#3\'"); _builder.newLine(); _builder.append(" "); _builder.append("E OptionalValue Model"); _builder.newLine(); _builder.append("2 1 1 H \" \" Whitespace:TerminalRule\'WS\'"); _builder.newLine(); _builder.append("------------ diff 1 ------------"); _builder.newLine(); _builder.append("2 1 H \" \" Whitespace:TerminalRule\'WS\'"); _builder.newLine(); _builder.append("3 3 S \"foo\" OptionalValue:name=ID"); _builder.newLine(); _builder.append("6 0 H"); _builder.newLine(); this._changeSerializerTestHelper.operator_tripleEquals(_recordDiff, _builder); }
@Test public void testOptionalChildRemove() { final IChangeSerializer.IModification<OptionalChild> _function = (OptionalChild it) -> { it.setChild(null); }; ITextRegionAccess _recordDiff = this.<OptionalChild>recordDiff(OptionalChild.class, "#5 foo", _function); StringConcatenation _builder = new StringConcatenation(); _builder.append("0 0 H"); _builder.newLine(); _builder.append(" "); _builder.append("B OptionalChild Model"); _builder.newLine(); _builder.append("0 2 S \"#5\" Model:\'#5\'"); _builder.newLine(); _builder.append(" "); _builder.append("E OptionalChild Model"); _builder.newLine(); _builder.append("2 1 1 H \" \" Whitespace:TerminalRule\'WS\'"); _builder.newLine(); _builder.append("------------ diff 1 ------------"); _builder.newLine(); _builder.append("2 1 H \" \" Whitespace:TerminalRule\'WS\'"); _builder.newLine(); _builder.append("3 3 S \"foo\" MandatoryValue:name=ID"); _builder.newLine(); _builder.append("6 0 H"); _builder.newLine(); this._changeSerializerTestHelper.operator_tripleEquals(_recordDiff, _builder); }
@Test public void testOptionalChildRemoveListAllOne() { final IChangeSerializer.IModification<OptionalChildList> _function = (OptionalChildList it) -> { EcoreUtil.remove(it.getChildren().get(0)); }; ITextRegionAccess _recordDiff = this.<OptionalChildList>recordDiff(OptionalChildList.class, "#13 x1", _function); StringConcatenation _builder = new StringConcatenation(); _builder.append("0 0 H"); _builder.newLine(); _builder.append(" "); _builder.append("B OptionalChildList Model"); _builder.newLine(); _builder.append("0 3 S \"#13\" Model:\'#13\'"); _builder.newLine(); _builder.append(" "); _builder.append("E OptionalChildList Model"); _builder.newLine(); _builder.append("3 1 1 H \" \" Whitespace:TerminalRule\'WS\'"); _builder.newLine(); _builder.append("------------ diff 1 ------------"); _builder.newLine(); _builder.append("3 1 H \" \" Whitespace:TerminalRule\'WS\'"); _builder.newLine(); _builder.append("4 2 S \"x1\" MandatoryValue:name=ID"); _builder.newLine(); _builder.append("6 0 H"); _builder.newLine(); this._changeSerializerTestHelper.operator_tripleEquals(_recordDiff, _builder); }
@Test public void testOptionalChildRemoveListAllTwo() { final IChangeSerializer.IModification<OptionalChildList> _function = (OptionalChildList it) -> { EcoreUtil.remove(it.getChildren().get(1)); EcoreUtil.remove(it.getChildren().get(0)); }; ITextRegionAccess _recordDiff = this.<OptionalChildList>recordDiff(OptionalChildList.class, "#13 a b", _function); StringConcatenation _builder = new StringConcatenation(); _builder.append("0 0 H"); _builder.newLine(); _builder.append(" "); _builder.append("B OptionalChildList Model"); _builder.newLine(); _builder.append("0 3 S \"#13\" Model:\'#13\'"); _builder.newLine(); _builder.append(" "); _builder.append("E OptionalChildList Model"); _builder.newLine(); _builder.append("3 1 1 H \" \" Whitespace:TerminalRule\'WS\'"); _builder.newLine(); _builder.append("------------ diff 1 ------------"); _builder.newLine(); _builder.append("3 1 H \" \" Whitespace:TerminalRule\'WS\'"); _builder.newLine(); _builder.append("4 1 S \"a\" MandatoryValue:name=ID"); _builder.newLine(); _builder.append("5 1 H \" \" Whitespace:TerminalRule\'WS\'"); _builder.newLine(); _builder.append("6 1 S \"b\" MandatoryValue:name=ID"); _builder.newLine(); _builder.append("7 0 H"); _builder.newLine(); this._changeSerializerTestHelper.operator_tripleEquals(_recordDiff, _builder); }
private <T extends EObject> ITextRegionAccess recordDiff(final Class<T> modelType, final CharSequence modelText, final IChangeSerializer.IModification<T> modification) { final InMemoryURIHandler fs = new InMemoryURIHandler(); String _string = modelText.toString(); Pair<String, String> _mappedTo = Pair.<String, String>of("inmemory:/file1.pstl", _string); this._changeSerializerTestHelper.operator_add(fs, _mappedTo); final ResourceSet rs = this._changeSerializerTestHelper.createResourceSet(fs); final T model = this._changeSerializerTestHelper.<T>contents(rs, "inmemory:/file1.pstl", modelType); final ChangeSerializer serializer = this.serializerProvider.get(); serializer.<T>addModification(model, modification); return this._changeSerializerTestHelper.endRecordChangesToTextRegions(serializer); }