use of org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess in project xtext-core by eclipse.
the class FormattingService method format2.
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;
}
use of org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess in project xtext-core by eclipse.
the class FormatterTestHelper method assertAllWhitespaceIsFormatted.
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);
}
}
use of org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess in project xtext-core by eclipse.
the class PartialSerializer method findRegion.
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);
}
}
use of org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess in project xtext-core by eclipse.
the class ReferenceUpdater method getRegion.
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;
}
use of org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess in project xtext-core by eclipse.
the class RegionDiffFormatter method createFormatterRequest.
protected FormatterRequest createFormatterRequest(ITextRegionAccess rewritten) {
FormatterRequest request = formatterRequest.get();
request.setTextRegionAccess(rewritten);
return request;
}
Aggregations