Search in sources :

Example 36 with TextSelection

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()));
}
Also used : TextSelection(org.eclipse.jface.text.TextSelection) ITextRegion(org.eclipse.xtext.util.ITextRegion) XExpression(org.eclipse.xtext.xbase.XExpression)

Example 37 with TextSelection

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()));
}
Also used : TextSelection(org.eclipse.jface.text.TextSelection) ITextRegion(org.eclipse.xtext.util.ITextRegion) XExpression(org.eclipse.xtext.xbase.XExpression)

Example 38 with TextSelection

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;
}
Also used : ITextSelection(org.eclipse.jface.text.ITextSelection) TextSelection(org.eclipse.jface.text.TextSelection) IParseResult(org.eclipse.xtext.parser.IParseResult)

Example 39 with TextSelection

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;
}
Also used : TextSelection(org.eclipse.jface.text.TextSelection) IRenameElementContext(org.eclipse.xtext.ui.refactoring.ui.IRenameElementContext)

Example 40 with TextSelection

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);
}
Also used : IFile(org.eclipse.core.resources.IFile) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) TextSelection(org.eclipse.jface.text.TextSelection) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) AbstractEditorTest(org.eclipse.xtext.ui.testing.AbstractEditorTest) RepeatedTest(org.eclipse.xtext.testing.RepeatedTest) Test(org.junit.Test)

Aggregations

TextSelection (org.eclipse.jface.text.TextSelection)109 IFile (org.eclipse.core.resources.IFile)35 ISelection (org.eclipse.jface.viewers.ISelection)26 ITextSelection (org.eclipse.jface.text.ITextSelection)24 Test (org.junit.Test)23 IDocument (org.eclipse.jface.text.IDocument)21 IEditorPart (org.eclipse.ui.IEditorPart)19 InputStream (java.io.InputStream)15 ByteArrayInputStream (java.io.ByteArrayInputStream)13 Path (org.eclipse.core.runtime.Path)13 BadLocationException (org.eclipse.jface.text.BadLocationException)11 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)11 IRegion (org.eclipse.jface.text.IRegion)10 IPreferencesService (org.eclipse.core.runtime.preferences.IPreferencesService)8 Module (org.eclipse.titan.designer.AST.Module)8 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)8 XExpression (org.eclipse.xtext.xbase.XExpression)8 TTCN3Editor (org.eclipse.titan.designer.editors.ttcn3editor.TTCN3Editor)7 XtextEditor (org.eclipse.xtext.ui.editor.XtextEditor)7 IResource (org.eclipse.core.resources.IResource)6