use of org.eclipse.xtext.resource.XtextResource in project xtext-xtend by eclipse.
the class ImportOrganizerTest method assertIsOrganizedTo.
protected void assertIsOrganizedTo(final CharSequence model, final CharSequence expected, final boolean validate) {
try {
Assert.assertFalse(expected.toString().contains("$"));
final XtendFile xtendFile = this.file(model.toString(), validate);
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());
};
final List<ReplaceRegion> sortedChanges = IterableExtensions.<ReplaceRegion, Integer>sortBy(changes, _function);
ReplaceRegion lastChange = null;
for (final ReplaceRegion it : sortedChanges) {
{
if (((lastChange != null) && (lastChange.getEndOffset() > it.getOffset()))) {
Assert.fail(((("Overlapping text edits: " + lastChange) + " and ") + it));
}
lastChange = it;
}
}
List<ReplaceRegion> _reverse = ListExtensions.<ReplaceRegion>reverse(sortedChanges);
for (final ReplaceRegion it_1 : _reverse) {
int _offset = it_1.getOffset();
int _offset_1 = it_1.getOffset();
int _length = it_1.getLength();
int _plus = (_offset_1 + _length);
builder.replace(_offset, _plus, it_1.getText());
}
Assert.assertEquals(expected.toString(), builder.toString());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.resource.XtextResource in project xtext-xtend by eclipse.
the class InsertionOffsetTest method checkFieldInsertionOffset.
protected void checkFieldInsertionOffset(final CharSequence model) {
try {
final String modelAsString = model.toString();
final int caretOffset = modelAsString.replace("$", "").indexOf("|");
final int expectedOffset = modelAsString.replace("|", "").indexOf("$");
XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(this.parseHelper.parse(modelAsString.replace("|", "").replace("$", "")).getXtendTypes());
final XtendClass xtendClass = ((XtendClass) _head);
Resource _eResource = xtendClass.eResource();
final XtextResource xtextResource = ((XtextResource) _eResource);
final EObject caretElement = this._eObjectAtOffsetHelper.resolveContainedElementAt(xtextResource, caretOffset);
Assert.assertEquals(expectedOffset, this._insertionOffsets.getNewFieldInsertOffset(caretElement, xtendClass));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.resource.XtextResource in project xtext-xtend by eclipse.
the class InsertionOffsetTest method checkMethodInsertionOffset.
protected void checkMethodInsertionOffset(final CharSequence model) {
try {
final String modelAsString = model.toString();
final int caretOffset = modelAsString.replace("$", "").indexOf("|");
final int expectedOffset = modelAsString.replace("|", "").indexOf("$");
XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(this.parseHelper.parse(modelAsString.replace("|", "").replace("$", "")).getXtendTypes());
final XtendClass xtendClass = ((XtendClass) _head);
Resource _eResource = xtendClass.eResource();
final XtextResource xtextResource = ((XtextResource) _eResource);
final EObject caretElement = this._eObjectAtOffsetHelper.resolveContainedElementAt(xtextResource, caretOffset);
Assert.assertEquals(expectedOffset, this._insertionOffsets.getNewMethodInsertOffset(caretElement, xtendClass));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.resource.XtextResource in project xtext-xtend by eclipse.
the class HyperlinkingTest method testReturnTypeLabel.
@Test
public void testReturnTypeLabel() throws Exception {
String modelAsString = "class Baz {def Baz meth(Baz baz, String str) { var vv='' x = baz j = str vv=j x.meth(baz,str) } var x = new Baz var j = '' }";
XtextResource resource = (XtextResource) testHelper.xtendFile("Baz", modelAsString).eResource();
int indexOf_x_FieldRef = modelAsString.indexOf("x");
IHyperlink[] hyperlinks = hyperlinkHelper.createHyperlinksByOffset(resource, indexOf_x_FieldRef, true);
assertEquals(2, hyperlinks.length);
assertEquals("Open Declaration - x : Baz", hyperlinks[0].getHyperlinkText());
assertEquals("Open Field Type - Baz", hyperlinks[1].getHyperlinkText());
int indexOf_Baz_ParamRef = modelAsString.indexOf("baz", indexOf_x_FieldRef);
hyperlinks = hyperlinkHelper.createHyperlinksByOffset(resource, indexOf_Baz_ParamRef, true);
assertEquals(2, hyperlinks.length);
assertEquals("Open Declaration - Baz baz", hyperlinks[0].getHyperlinkText());
assertEquals("Open Parameter Type - Baz", hyperlinks[1].getHyperlinkText());
int indexOf_j_FieldRef = modelAsString.indexOf("j", indexOf_Baz_ParamRef);
hyperlinks = hyperlinkHelper.createHyperlinksByOffset(resource, indexOf_j_FieldRef, true);
assertEquals(2, hyperlinks.length);
assertEquals("Open Declaration - j : String", hyperlinks[0].getHyperlinkText());
assertEquals("Open Field Type - String", hyperlinks[1].getHyperlinkText());
assertEquals("String", ((JdtHyperlink) hyperlinks[1]).getJavaElement().getElementName());
int indexOf_vv_VarRef = modelAsString.indexOf("vv", indexOf_j_FieldRef);
hyperlinks = hyperlinkHelper.createHyperlinksByOffset(resource, indexOf_vv_VarRef, true);
assertEquals(2, hyperlinks.length);
assertEquals("Open Declaration - String vv", hyperlinks[0].getHyperlinkText());
assertEquals("Open Variable Type - String", hyperlinks[1].getHyperlinkText());
int indexOf_meth_MethodeCall = modelAsString.indexOf("meth", indexOf_vv_VarRef);
hyperlinks = hyperlinkHelper.createHyperlinksByOffset(resource, indexOf_meth_MethodeCall, true);
assertEquals(2, hyperlinks.length);
assertEquals("Open Declaration - meth(Baz, String) : Baz", hyperlinks[0].getHyperlinkText());
assertEquals("Open Return Type - Baz", hyperlinks[1].getHyperlinkText());
}
use of org.eclipse.xtext.resource.XtextResource in project xtext-xtend by eclipse.
the class HyperlinkingTest method testOpenInferredTypeOnReference.
@Test
public void testOpenInferredTypeOnReference() throws Exception {
String modelAsString = "class Baz { def void foo() { var myVar='' println(myVar) } }";
XtextResource resource = (XtextResource) testHelper.xtendFile("Baz", modelAsString).eResource();
int indexOf_x_FieldRef = modelAsString.indexOf("myVar)");
IHyperlink[] hyperlinks = hyperlinkHelper.createHyperlinksByOffset(resource, indexOf_x_FieldRef, true);
assertEquals(2, hyperlinks.length);
assertEquals("Open Declaration - String myVar", hyperlinks[0].getHyperlinkText());
assertEquals("Open Variable Type - String", hyperlinks[1].getHyperlinkText());
}
Aggregations