Search in sources :

Example 1 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("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);
}
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) Test(org.junit.Test)

Example 2 with TextSelection

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

Example 3 with TextSelection

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

Example 4 with TextSelection

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);
}
Also used : NewFeatureNameUtil(org.eclipse.xtext.xbase.ui.refactoring.NewFeatureNameUtil) TextSelection(org.eclipse.jface.text.TextSelection) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XExpression(org.eclipse.xtext.xbase.XExpression) XtextResource(org.eclipse.xtext.resource.XtextResource)

Example 5 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)

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 XtextResource (org.eclipse.xtext.resource.XtextResource)9 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