use of org.eclipse.jface.text.TextSelection in project xtext-eclipse by eclipse.
the class MarkOccurrencesTest method testMarkOccurrencesCrossFile.
@Test
public void testMarkOccurrencesCrossFile() throws Exception {
String model1 = "Zonk { Bar(Foo) {} Baz(Foo Bar) {} }";
String model2 = "Foo {}";
IFile modelFile1 = IResourcesSetupUtil.createFile("test/src/Test1.outlinetestlanguage", model1);
IResourcesSetupUtil.createFile("test/src/Test2.outlinetestlanguage", model2);
IResourcesSetupUtil.waitForBuild();
XtextEditor editor = openEditor(modelFile1);
ISelectionProvider selectionProvider = editor.getSelectionProvider();
selectionProvider.setSelection(new TextSelection(model1.indexOf("Foo"), 1));
IAnnotationModel annotationModel = editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
ExpectationBuilder listener = new ExpectationBuilder().added(OCCURRENCE_ANNOTATION_TYPE, model1.indexOf("Foo", 3), 3).added(OCCURRENCE_ANNOTATION_TYPE, model1.lastIndexOf("Foo"), 3);
listener.start();
annotationModel.addAnnotationModelListener(listener);
setMarkOccurrences(true);
listener.verify(TIMEOUT);
}
use of org.eclipse.jface.text.TextSelection in project xtext-eclipse by eclipse.
the class ExpressionUtilTest method assertExpressionSelected.
protected void assertExpressionSelected(final String modelWithSelectionMarkup, final String expectedSelection) {
final String cleanedModel = modelWithSelectionMarkup.replaceAll("\\$", "");
final XExpression expression = this.parse(cleanedModel);
final int selectionOffset = modelWithSelectionMarkup.indexOf("$");
int _lastIndexOf = modelWithSelectionMarkup.lastIndexOf("$");
int _minus = (_lastIndexOf - selectionOffset);
final int selectionLength = (_minus - 1);
Resource _eResource = expression.eResource();
TextSelection _textSelection = new TextSelection(selectionOffset, selectionLength);
final XExpression selectedExpression = this.util.findSelectedExpression(((XtextResource) _eResource), _textSelection);
final ITextRegion selectedRegion = this.locationInFileProvider.getFullTextRegion(selectedExpression);
int _offset = selectedRegion.getOffset();
int _offset_1 = selectedRegion.getOffset();
int _length = selectedRegion.getLength();
int _plus = (_offset_1 + _length);
Assert.assertEquals(expectedSelection, cleanedModel.substring(_offset, _plus));
}
use of org.eclipse.jface.text.TextSelection in project xtext-eclipse by eclipse.
the class ExpressionUtilTest method assertSiblingExpressionsSelected.
protected void assertSiblingExpressionsSelected(final String modelWithSelectionMarkup, final String expectedSelection) {
final String cleanedModel = modelWithSelectionMarkup.replaceAll("\\$", "");
final XExpression expression = this.parse(cleanedModel);
final int selectionOffset = modelWithSelectionMarkup.indexOf("$");
int _lastIndexOf = modelWithSelectionMarkup.lastIndexOf("$");
int _minus = (_lastIndexOf - selectionOffset);
final int selectionLength = (_minus - 1);
Resource _eResource = expression.eResource();
TextSelection _textSelection = new TextSelection(selectionOffset, selectionLength);
final List<XExpression> selectedExpressions = this.util.findSelectedSiblingExpressions(((XtextResource) _eResource), _textSelection);
final Function1<XExpression, ITextRegion> _function = (XExpression it) -> {
return this.locationInFileProvider.getFullTextRegion(it);
};
final Function2<ITextRegion, ITextRegion, ITextRegion> _function_1 = (ITextRegion a, ITextRegion b) -> {
return a.merge(b);
};
final ITextRegion selectedRegion = IterableExtensions.<ITextRegion>reduce(ListExtensions.<XExpression, ITextRegion>map(selectedExpressions, _function), _function_1);
int _offset = selectedRegion.getOffset();
int _offset_1 = selectedRegion.getOffset();
int _length = selectedRegion.getLength();
int _plus = (_offset_1 + _length);
Assert.assertEquals(expectedSelection, cleanedModel.substring(_offset, _plus));
}
use of org.eclipse.jface.text.TextSelection in project xtext-eclipse by eclipse.
the class NewFeatureNameUtilTest method assertDefaultName.
protected void assertDefaultName(final String modelWithSelectionMarkup, final String expectedName) {
final String cleanedModel = modelWithSelectionMarkup.replaceAll("\\$", "");
final XExpression expression = this.parse(cleanedModel);
final int selectionOffset = modelWithSelectionMarkup.indexOf("$");
int _lastIndexOf = modelWithSelectionMarkup.lastIndexOf("$");
int _minus = (_lastIndexOf - selectionOffset);
final int selectionLength = (_minus - 1);
Resource _eResource = expression.eResource();
TextSelection _textSelection = new TextSelection(selectionOffset, selectionLength);
final XExpression selectedExpression = this.util.findSelectedExpression(((XtextResource) _eResource), _textSelection);
final XExpression successor = this.util.findSuccessorExpressionForVariableDeclaration(selectedExpression);
final NewFeatureNameUtil nameUtil = this.nameUtilProvider.get();
nameUtil.setFeatureScopeContext(successor);
final String defaultName = nameUtil.getDefaultName(selectedExpression);
Assert.assertEquals(expectedName, defaultName);
}
use of org.eclipse.jface.text.TextSelection in project xtext-eclipse by eclipse.
the class XtextGrammarRefactoringIntegrationTest method doRefactoring.
private XtextEditor doRefactoring(XtextEditor editor) throws Exception {
final TextSelection selection = new TextSelection(grammar.indexOf(CLASSIFIERNAME), CLASSIFIERNAME.length());
editor.getSelectionProvider().setSelection(selection);
waitForDisplay();
IRenameElementContext context = new IRenameElementContext.Impl(greetingParserRuleUri, XtextPackage.Literals.PARSER_RULE, editor, selection, grammarUri);
renameRefactoringController.startRefactoring(context);
waitForDisplay();
pressKeys(editor, REFACTOREDCLASSIFIERNAME + "\n");
waitForDisplay();
return editor;
}
Aggregations