Java Code Examples for org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess

The following examples show how to use org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: xtext-extras   Source File: FormatterTester.java    License: Eclipse Public License 2.0 6 votes vote down vote up
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);
	}
}
 
Example 2
Source Project: xtext-eclipse   Source File: FormatterTester.java    License: Eclipse Public License 2.0 6 votes vote down vote up
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);
	}
}
 
Example 3
Source Project: xtext-xtend   Source File: ConvertJavaCode.java    License: Eclipse Public License 2.0 6 votes vote down vote up
private String formatXtendCode(IFile xtendFile, final String xtendCode) {
	try {
		XtextResource resource = (XtextResource) createResource(xtendFile, xtendCode);
		ITextRegionAccess regionAccess = regionAccessBuilder.get().forNodeModel(resource).create();
		FormatterRequest request = new FormatterRequest();
		request.setAllowIdentityEdits(false);
		request.setTextRegionAccess(regionAccess);
		request.setPreferences(TypedPreferenceValues.castOrWrap(cfgProvider.getPreferenceValues(resource)));
		List<ITextReplacement> replacements = formatter.format(request);
		String formatted = regionAccess.getRewriter().renderToString(replacements);
		return formatted;
	} catch (Exception e) {
		LOG.error("Formatting step canceled due to an exception.", e);
		return null;
	}
}
 
Example 4
Source Project: xtext-xtend   Source File: FormatterSmokeSuite.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void processFile(String data) throws Exception {
	byte[] hash = ((MessageDigest) messageDigest.clone()).digest(data.getBytes("UTF-8"));
	if (seen.add(new BigInteger(hash))) {
		XtextResourceSet resourceSet = resourceSetProvider.get();
		resourceSet.setClasspathURIContext(classLoader);
		XtendFile file = parseHelper.parse(data, resourceSet);
		if (file != null) {
			try {
				XtextResource resource = (XtextResource) file.eResource();
				ITextRegionAccess regions = regionBuilder.get().forNodeModel(resource).create();
				FormatterRequest request = new FormatterRequest().setTextRegionAccess(regions);
				request.setExceptionHandler(ExceptionAcceptor.IGNORING);
				formatter.format(request);
			} catch (Exception e) {
				e.printStackTrace();
				ComparisonFailure error = new ComparisonFailure(e.getMessage(), data, "");
				error.setStackTrace(e.getStackTrace());
				throw error;
			}
		}
	}
}
 
Example 5
Source Project: xtext-core   Source File: PartialSerializer.java    License: Eclipse Public License 2.0 6 votes vote down vote up
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);
		}
		for (IAstRegion astRegion : owner.getAstRegions()) {
			if (astRegion instanceof IEObjectRegion) {
				if (feature.equals(astRegion.getContainingFeature())) {
					return  astRegion;
				}
			}
		}
		return null;
	} else {
		return owner.getRegionFor().feature(feature);
	}
}
 
Example 6
Source Project: xtext-xtend   Source File: RichStringFormatter.java    License: Eclipse Public License 2.0 6 votes vote down vote up
protected void setNewLines(final IFormattableDocument doc, final int offset, final int length, final int indentationIncrease, final int indentationDecrease, final int newLines) {
  IHiddenRegionFormatting _createHiddenRegionFormatting = doc.getFormatter().createHiddenRegionFormatting();
  final Procedure1<IHiddenRegionFormatting> _function = (IHiddenRegionFormatting it) -> {
    it.setIndentationIncrease(Integer.valueOf(indentationIncrease));
    it.setIndentationDecrease(Integer.valueOf(indentationDecrease));
    it.setNewLinesMin(Integer.valueOf(newLines));
    it.setNewLinesDefault(Integer.valueOf(newLines));
    it.setNewLinesMax(Integer.valueOf(newLines));
  };
  final IHiddenRegionFormatting fmt = ObjectExtensions.<IHiddenRegionFormatting>operator_doubleArrow(_createHiddenRegionFormatting, _function);
  AbstractFormatter2 _formatter = doc.getFormatter();
  ITextRegionAccess _textRegionAccess = this._iTextRegionExtensions.getTextRegionAccess();
  TextSegment _textSegment = new TextSegment(_textRegionAccess, offset, length);
  final ITextReplacer replacer = _formatter.createWhitespaceReplacer(_textSegment, fmt);
  doc.addReplacer(replacer);
}
 
Example 7
@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();
}
 
Example 8
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();
        }
      }
    }
  }
}
 
Example 9
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);
  }
}
 
Example 10
Source Project: xtext-core   Source File: FormattingService.java    License: Eclipse Public License 2.0 6 votes vote down vote up
protected List<ITextReplacement> format2(XtextResource resource, ITextRegion selection,
		ITypedPreferenceValues preferences) {
	FormatterRequest request = formatterRequestProvider.get();
	request.setAllowIdentityEdits(false);
	request.setFormatUndefinedHiddenRegionsOnly(false);
	if (selection != null) {
		request.setRegions(Collections.singletonList(selection));
	}
	if (preferences != null) {
		request.setPreferences(preferences);
	}
	ITextRegionAccess regionAccess = regionBuilder.forNodeModel(resource).create();
	request.setTextRegionAccess(regionAccess);
	IFormatter2 formatter2 = formatter2Provider.get();
	List<ITextReplacement> replacements = formatter2.format(request);
	return replacements;
}
 
Example 11
Source Project: xtext-core   Source File: LineRegion.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@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);
}
 
Example 12
Source Project: xtext-core   Source File: LineRegion.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@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);
}
 
Example 13
Source Project: xtext-core   Source File: ReferenceUpdater.java    License: Eclipse Public License 2.0 6 votes vote down vote up
protected ISemanticRegion getRegion(ITextRegionAccess access, IReferenceSnapshot ref) {
	XtextResource resource = access.getResource();
	URI objectUri = ref.getSourceEObjectUri();
	if (!resource.getURI().equals(objectUri.trimFragment())) {
		return null;
	}
	EObject object = resource.getEObject(objectUri.fragment());
	if (object == null) {
		return null;
	}
	ISemanticRegionsFinder finder = access.getExtensions().regionFor(object);
	int index = ref.getIndexInList();
	if (index < 0) {
		return finder.feature(ref.getEReference());
	} else {
		List<ISemanticRegion> list = finder.features(ref.getEReference());
		if (list != null && index < list.size()) {
			return list.get(index);
		}
	}
	return null;
}
 
Example 14
Source Project: xtext-core   Source File: TextReplacerContext.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@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;
}
 
Example 15
Source Project: xtext-core   Source File: AbstractFormatter2.java    License: Eclipse Public License 2.0 6 votes vote down vote up
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;
}
 
Example 16
Source Project: n4js   Source File: FormatterXpectMethod.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private ITextSegment findRegion(int lines, XpectInvocation inv, TargetSyntaxSupport syntax, ITextRegionAccess reg) {
	XtextResource resource = ((XtextTargetSyntaxSupport) syntax).getResource();

	IStatementRelatedRegion region2 = inv.getExtendedRegion();
	int end = region2.getOffset() + region2.getLength();
	ILeafNode node = NodeModelUtils.findLeafNodeAtOffset(resource.getParseResult().getRootNode(), end);

	int offset = node.getTotalEndOffset();
	ITextSegment region = getRegionForLines(reg, offset, lines);
	return region;
}
 
Example 17
Source Project: n4js   Source File: FormatterXpectMethod.java    License: Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example 18
Source Project: n4js   Source File: FixedContentFormatter.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@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);
}
 
Example 19
Source Project: xtext-core   Source File: RegionAccessDiffTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testSingleSemanticToken() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("1 foo");
  _builder.newLine();
  final ITextRegionAccess access = this._regionAccessTestHelper.toTextRegionAccess(_builder);
  final Procedure1<ITextRegionDiffBuilder> _function = (ITextRegionDiffBuilder it) -> {
    @Extension
    final ITextRegionExtensions ext = access.getExtensions();
    final EObject root = access.regionForRootEObject().getSemanticElement();
    final ISemanticRegion foo = ext.allRegionsFor(root).feature(RegionaccesstestlanguagePackage.Literals.SIMPLE__NAME);
    it.replace(foo, "baaar");
  };
  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 Simple\'foo\' Root");
  _builder_1.newLine();
  _builder_1.append("0 1    S \"1\"        Simple:\'1\'");
  _builder_1.newLine();
  _builder_1.append("1 1    H \" \"        Whitespace:TerminalRule\'WS\'");
  _builder_1.newLine();
  _builder_1.append("2 5 1  S \"baaar\"    Simple:name=ID");
  _builder_1.newLine();
  _builder_1.append("      ");
  _builder_1.append("E Simple\'foo\' Root");
  _builder_1.newLine();
  _builder_1.append("7 0   H");
  _builder_1.newLine();
  _builder_1.append("------------ diff 1 ------------");
  _builder_1.newLine();
  _builder_1.append("2 3 S \"foo\"      Simple:name=ID");
  _builder_1.newLine();
  this._regionAccessTestHelper.operator_tripleEquals(_modify, _builder_1);
}
 
Example 20
Source Project: xtext-eclipse   Source File: ContentFormatter.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected void initRequest(IXtextDocument document, IRegion region, XtextResource resource, FormatterRequest request) {
	ITextRegion textRegion = new TextRegion(region.getOffset(), region.getLength());
	request.setAllowIdentityEdits(false);
	request.setFormatUndefinedHiddenRegionsOnly(false);
	request.setRegions(singletonList(textRegion));
	ITextRegionAccess tokenAccess = regionBuilder.forNodeModel(resource).create();
	IPreferenceValues preferenceValues = preferencesProvider.getPreferenceValues(resource);
	request.setPreferences(TypedPreferenceValues.castOrWrap(preferenceValues));
	request.setTextRegionAccess(tokenAccess);
	if (tokenAccess.hasSyntaxError())
		request.setExceptionHandler(ExceptionAcceptor.IGNORING);
	else
		request.setExceptionHandler(ExceptionAcceptor.LOGGING);
}
 
Example 21
Source Project: xtext-core   Source File: Serializer.java    License: Eclipse Public License 2.0 5 votes vote down vote up
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;
}
 
Example 22
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;
}
 
Example 23
Source Project: xtext-core   Source File: PartialSerializerTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
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);
}
 
Example 24
@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));
	}
}
 
Example 25
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 = toSequential(diff.getModifiedFirstRegion());
			ISequentialRegion last = toSequential(diff.getModifiedLastRegion());
			String text = i + " ";
			if (width < text.length()) {
				width = text.length();
			}
			while (current != null) {
				diffs.put(current, text);
				if (current.getOffset() >= last.getOffset()) {
					break;
				}
				current = current.getNextSequentialRegion();
			}
			i++;
		}
		this.empty = Strings.repeat(" ", width);
	} else {
		this.access = null;
		this.empty = "";
	}
}
 
Example 26
Source Project: xtext-core   Source File: ReferenceUpdater.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected void updateExternalReferences(IReferenceUpdaterContext context, RelatedResource relatedResource) {
	ITextRegionAccess document = context.getModifyableDocument().getOriginalTextRegionAccess();
	for (IReferenceSnapshot ref : relatedResource.outgoingReferences) {
		ISemanticRegion region = getRegion(document, ref);
		if (region != null) {
			IUpdatableReference updatable = createUpdatableReference(region);
			if (updatable != null && needsUpdating(context, updatable)) {
				context.updateReference(updatable);
			}
		}
	}
}
 
Example 27
Source Project: xtext-core   Source File: RegionAccessDiffTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testInsertReplaceReplace() throws Exception {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("8 a");
  _builder.newLine();
  final ITextRegionAccess access = this._regionAccessTestHelper.toTextRegionAccess(_builder);
  final Procedure1<ITextRegionDiffBuilder> _function = (ITextRegionDiffBuilder it) -> {
    @Extension
    final ITextRegionExtensions ext = access.getExtensions();
    EObject _semanticElement = access.regionForRootEObject().getSemanticElement();
    final ValueList rootObj = ((ValueList) _semanticElement);
    final ISemanticRegion a = ext.regionFor(rootObj).keyword("8").getNextSemanticRegion();
    it.replace(a, "b");
    it.replace(a, "c");
  };
  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]\' 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("2 1 1  S \"c\"        ValueList:name+=ID");
  _builder_1.newLine();
  _builder_1.append("      ");
  _builder_1.append("E ValueList\'[a]\' Root");
  _builder_1.newLine();
  _builder_1.append("3 0   H");
  _builder_1.newLine();
  _builder_1.append("------------ diff 1 ------------");
  _builder_1.newLine();
  _builder_1.append("2 1 S \"a\"        ValueList:name+=ID");
  _builder_1.newLine();
  this._regionAccessTestHelper.operator_tripleEquals(_modify, _builder_1);
}
 
Example 28
Source Project: xtext-core   Source File: FormatterRequest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 29
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);
}
 
Example 30
Source Project: xtext-core   Source File: PartialSerializerTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@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);
}