use of org.eclipse.xtext.util.ReplaceRegion in project xtext-xtend by eclipse.
the class AbstractSmokeTest method testSkipNodesInBetween.
@Test
public void testSkipNodesInBetween() throws Exception {
for (String string : smokeTestModels) {
LazyLinkingResource resource = createResource(string);
ICompositeNode rootNode = resource.getParseResult().getRootNode();
ReplaceRegion replaceRegion = null;
for (INode node : rootNode.getAsTreeIterable()) {
int offset = node.getTotalOffset();
int length = node.getTotalLength();
if (replaceRegion == null || replaceRegion.getOffset() != offset || replaceRegion.getLength() != length) {
replaceRegion = new ReplaceRegion(offset, length, "");
StringBuilder builder = new StringBuilder(string);
replaceRegion.applyTo(builder);
doParseAndCheckForSmoke(builder.toString());
}
}
}
}
use of org.eclipse.xtext.util.ReplaceRegion in project xtext-xtend by eclipse.
the class AbstractRewritableImportSectionTest method assertEquals.
protected void assertEquals(final RewritableImportSection section, final CharSequence sectionAsString) {
final StringBuilder builder = new StringBuilder(this.model);
final List<ReplaceRegion> changes = section.rewrite();
final Function1<ReplaceRegion, Integer> _function = (ReplaceRegion it) -> {
return Integer.valueOf(it.getOffset());
};
List<ReplaceRegion> _reverse = ListExtensions.<ReplaceRegion>reverse(IterableExtensions.<ReplaceRegion, Integer>sortBy(changes, _function));
for (final ReplaceRegion it : _reverse) {
int _offset = it.getOffset();
int _offset_1 = it.getOffset();
int _length = it.getLength();
int _plus = (_offset_1 + _length);
builder.replace(_offset, _plus, it.getText());
}
Assert.assertEquals(this.processLinebreaks(this.getExpectedModel(sectionAsString.toString())), this.processLinebreaks(builder));
}
use of org.eclipse.xtext.util.ReplaceRegion in project xtext-xtend by eclipse.
the class OrganizeImportsTest method assertIsOrganizedTo.
protected void assertIsOrganizedTo(final CharSequence model, final String fileName, final CharSequence expected) {
try {
Assert.assertFalse(expected.toString().contains("$"));
final XtendFile xtendFile = this._workbenchTestHelper.xtendFile(fileName, model.toString());
Resource _eResource = xtendFile.eResource();
final List<ReplaceRegion> changes = this.importOrganizer.getOrganizedImportChanges(((XtextResource) _eResource));
final StringBuilder builder = new StringBuilder(model);
final Function1<ReplaceRegion, Integer> _function = (ReplaceRegion it) -> {
return Integer.valueOf(it.getOffset());
};
List<ReplaceRegion> _reverse = ListExtensions.<ReplaceRegion>reverse(IterableExtensions.<ReplaceRegion, Integer>sortBy(changes, _function));
for (final ReplaceRegion it : _reverse) {
int _offset = it.getOffset();
int _offset_1 = it.getOffset();
int _length = it.getLength();
int _plus = (_offset_1 + _length);
builder.replace(_offset, _plus, it.getText());
}
Assert.assertEquals(expected.toString(), builder.toString());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.util.ReplaceRegion in project xtext-xtend by eclipse.
the class OrganizeImportsTest method assertIsOrganizedWithErrorsTo.
protected void assertIsOrganizedWithErrorsTo(final CharSequence model, final CharSequence expected) {
try {
Assert.assertFalse(expected.toString().contains("$"));
final XtendFile xtendFile = this.xtendFileWithError(model.toString());
Resource _eResource = xtendFile.eResource();
final List<ReplaceRegion> changes = this.importOrganizer.getOrganizedImportChanges(((XtextResource) _eResource));
final StringBuilder builder = new StringBuilder(model);
final Function1<ReplaceRegion, Integer> _function = (ReplaceRegion it) -> {
return Integer.valueOf(it.getOffset());
};
List<ReplaceRegion> _reverse = ListExtensions.<ReplaceRegion>reverse(IterableExtensions.<ReplaceRegion, Integer>sortBy(changes, _function));
for (final ReplaceRegion it : _reverse) {
int _offset = it.getOffset();
int _offset_1 = it.getOffset();
int _length = it.getLength();
int _plus = (_offset_1 + _length);
builder.replace(_offset, _plus, it.getText());
}
Assert.assertEquals(expected.toString(), builder.toString());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.util.ReplaceRegion in project xtext-xtend by eclipse.
the class XtendValidator method checkJavaDocRefs.
@Check
public void checkJavaDocRefs(XtendMember member) {
if (isIgnored(IssueCodes.JAVA_DOC_LINKING_DIAGNOSTIC))
return;
List<INode> documentationNodes = ((IEObjectDocumentationProviderExtension) documentationProvider).getDocumentationNodes(member);
for (INode node : documentationNodes) {
for (ReplaceRegion region : javaDocTypeReferenceProvider.computeTypeRefRegions(node)) {
String typeRefString = region.getText();
if (typeRefString != null && typeRefString.length() > 0) {
IScope scope = scopeProvider.getScope(member, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE);
IEObjectDescription candidate = scope.getSingleElement(qualifiedNameConverter.toQualifiedName(typeRefString));
if (candidate == null) {
Severity severity = getIssueSeverities(getContext(), getCurrentObject()).getSeverity(IssueCodes.JAVA_DOC_LINKING_DIAGNOSTIC);
if (severity != null)
getChain().add(createDiagnostic(severity, "javaDoc: " + typeRefString + " cannot be resolved to a type", member, region.getOffset(), region.getLength(), IssueCodes.JAVA_DOC_LINKING_DIAGNOSTIC));
}
}
}
}
}
Aggregations