Java Code Examples for org.eclipse.xtext.formatting2.debug.TextRegionsToString

The following examples show how to use org.eclipse.xtext.formatting2.debug.TextRegionsToString. 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-core   Source File: FormatterTestHelper.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 4
@Override
public String toString() {
	List<String> result = Lists.newArrayList();
	for (IEmfResourceChange c : changes) {
		String title = getTitle(c);
		if (c instanceof ITextDocumentChange) {
			ITextDocumentChange change = (ITextDocumentChange) c;
			TextRegionsToString textRegionsToString = new TextRegionsToString();
			textRegionsToString.setIgnoreCarriageReturnInQuotes(true);
			textRegionsToString.addAllReplacements(change.getReplacements());
			textRegionsToString.setTitle(title);
			result.add(textRegionsToString.toString());
		} else {
			String box = box(title, c.toString());
			result.add(box);
		}
	}
	return Joiner.on("\n").join(result);
}
 
Example 5
Source Project: xtext-extras   Source File: FormatterTester.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected void assertReplacementsAreInRegion(List<ITextReplacement> rep, Collection<ITextRegion> regions,
		String doc) {
	Set<ITextReplacement> invalid = Sets.newHashSet();
	ALLOWED: for (ITextRegion allowed : regions)
		for (ITextReplacement r : rep) {
			if (allowed.contains(r))
				continue ALLOWED;
			invalid.add(r);
		}
	if (!invalid.isEmpty()) {
		String visualized = new TextRegionsToString().addAllReplacements(invalid).toString();
		fail("One or more TextReplacements are outside of the allowed region. Region: " + regions, visualized);
	}
}
 
Example 6
Source Project: xtext-eclipse   Source File: FormatterTester.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected void assertReplacementsAreInRegion(List<ITextReplacement> rep, Collection<ITextRegion> regions,
		String doc) {
	Set<ITextReplacement> invalid = Sets.newHashSet();
	ALLOWED: for (ITextRegion allowed : regions)
		for (ITextReplacement r : rep) {
			if (allowed.contains(r))
				continue ALLOWED;
			invalid.add(r);
		}
	if (!invalid.isEmpty()) {
		String visualized = new TextRegionsToString().addAllReplacements(invalid).toString();
		fail("One or more TextReplacements are outside of the allowed region. Region: " + regions, visualized);
	}
}
 
Example 7
Source Project: xtext-core   Source File: FormatterTestHelper.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected void assertReplacementsAreInRegion(List<ITextReplacement> rep, Collection<ITextRegion> regions,
		String doc) {
	Set<ITextReplacement> invalid = Sets.newHashSet();
	ALLOWED: for (ITextRegion allowed : regions)
		for (ITextReplacement r : rep) {
			if (allowed.contains(r))
				continue ALLOWED;
			invalid.add(r);
		}
	if (!invalid.isEmpty()) {
		String visualized = new TextRegionsToString().addAllReplacements(invalid).toString();
		fail("One or more TextReplacements are outside of the allowed region. Region: " + regions, visualized);
	}
}
 
Example 8
Source Project: xtext-core   Source File: TextReplacementList.java    License: Eclipse Public License 2.0 4 votes vote down vote up
@Override
public String toString() {
	return new TextRegionsToString().setTitle(getClass().getSimpleName()).addAllReplacements(this).toString();
}