use of org.eclipse.jface.text.TextSelection in project xtext-eclipse by eclipse.
the class ExpressionUtilTest method assertExpressionSelected.
protected void assertExpressionSelected(String modelWithSelectionMarkup, String expectedSelection) throws Exception {
String cleanedModel = modelWithSelectionMarkup.replaceAll("\\$", "");
XExpression expression = parse(cleanedModel);
int selectionOffset = modelWithSelectionMarkup.indexOf("$");
int selectionLength = modelWithSelectionMarkup.lastIndexOf("$") - selectionOffset - 1;
XExpression selectedExpression = util.findSelectedExpression((XtextResource) expression.eResource(), new TextSelection(selectionOffset, selectionLength));
ITextRegion selectedRegion = locationInFileProvider.getFullTextRegion(selectedExpression);
assertEquals(expectedSelection, cleanedModel.substring(selectedRegion.getOffset(), selectedRegion.getOffset() + selectedRegion.getLength()));
}
use of org.eclipse.jface.text.TextSelection in project xtext-eclipse by eclipse.
the class ExpressionUtilTest method assertSiblingExpressionsSelected.
protected void assertSiblingExpressionsSelected(String modelWithSelectionMarkup, String expectedSelection) throws Exception {
String cleanedModel = modelWithSelectionMarkup.replaceAll("\\$", "");
XExpression expression = parse(cleanedModel);
int selectionOffset = modelWithSelectionMarkup.indexOf("$");
int selectionLength = modelWithSelectionMarkup.lastIndexOf("$") - selectionOffset - 1;
List<XExpression> selectedExpressions = util.findSelectedSiblingExpressions((XtextResource) expression.eResource(), new TextSelection(selectionOffset, selectionLength));
List<ITextRegion> regions = ListExtensions.map(selectedExpressions, it -> locationInFileProvider.getFullTextRegion(it));
ITextRegion selectedRegion = IterableExtensions.reduce(regions, (a, b) -> a.merge(b));
assertEquals(expectedSelection, cleanedModel.substring(selectedRegion.getOffset(), selectedRegion.getOffset() + selectedRegion.getLength()));
}
use of org.eclipse.jface.text.TextSelection in project xtext-eclipse by eclipse.
the class ExpressionUtil method trimSelection.
protected ITextSelection trimSelection(XtextResource resource, ITextSelection selection) {
IParseResult parseResult = resource.getParseResult();
if (parseResult != null) {
String model = parseResult.getRootNode().getText();
String selectedText = model.substring(selection.getOffset(), selection.getOffset() + selection.getLength());
String trimmedSelection = selectedText.trim();
return new TextSelection(selection.getOffset() + selectedText.indexOf(trimmedSelection), trimmedSelection.length());
}
return null;
}
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;
}
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("MarkOccurrencesTest/src/Test1.outlinetestlanguage", model1);
IResourcesSetupUtil.createFile("MarkOccurrencesTest/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(editor, annotationModel).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);
}
Aggregations