use of org.eclipse.jface.text.TextSelection in project linuxtools by eclipse.
the class AbstractMassifTest method checkLine.
protected void checkLine(MassifHeapTreeNode node) {
IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
assertTrue(editor instanceof ITextEditor);
ITextEditor textEditor = (ITextEditor) editor;
ISelection selection = textEditor.getSelectionProvider().getSelection();
assertTrue(selection instanceof TextSelection);
TextSelection textSelection = (TextSelection) selection;
// zero-indexed
int line = textSelection.getStartLine() + 1;
assertEquals(node.getLine(), line);
}
use of org.eclipse.jface.text.TextSelection in project linuxtools by eclipse.
the class DoubleClickTest method testDoubleClickLaunchRemoved.
@Test
public void testDoubleClickLaunchRemoved() throws Exception {
ILaunchConfiguration config = createConfiguration(proj.getProject());
// $NON-NLS-1$
ILaunch launch = doLaunch(config, "testDoubleClickLine");
// Remove launch - tests #284919
DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
doDoubleClick();
IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
assertTrue("editor should be ITextEditor", editor instanceof ITextEditor);
ITextEditor textEditor = (ITextEditor) editor;
ISelection selection = textEditor.getSelectionProvider().getSelection();
assertTrue("selection must be TextSelection", selection instanceof TextSelection);
TextSelection textSelection = (TextSelection) selection;
// zero-indexed
int line = textSelection.getStartLine() + 1;
assertEquals(frame.getLine(), line);
}
use of org.eclipse.jface.text.TextSelection in project linuxtools by eclipse.
the class LinkedResourceDoubleClickTest method testLinkedDoubleClickLine.
@Test
public void testLinkedDoubleClickLine() throws Exception {
ILaunchConfiguration config = createConfiguration(proj.getProject());
// $NON-NLS-1$
doLaunch(config, "testLinkedDoubleClickLine");
doDoubleClick();
IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
assertTrue("editor must be text editor", editor instanceof ITextEditor);
ITextEditor textEditor = (ITextEditor) editor;
ISelection selection = textEditor.getSelectionProvider().getSelection();
assertTrue("selection must be text one", selection instanceof TextSelection);
TextSelection textSelection = (TextSelection) selection;
// zero-indexed
int line = textSelection.getStartLine() + 1;
assertEquals(frame.getLine(), line);
}
use of org.eclipse.jface.text.TextSelection in project linuxtools by eclipse.
the class STPEditor method jumpToLocation.
/**
* Jumps to the location in the IDocument.
* @param line The line you wish to jump to.
* @param character The character you wish to jump to.
*/
public void jumpToLocation(int line, int character) {
IDocument doc = getSourceViewer().getDocument();
try {
int offset = doc.getLineOffset(line - 1) + character;
this.getSelectionProvider().setSelection(new TextSelection(doc, offset, 0));
} catch (BadLocationException boe) {
// Pass
}
}
use of org.eclipse.jface.text.TextSelection in project linuxtools by eclipse.
the class CParserTest method canParseCurrentFunctionInCppFile.
/**
* Given an IEditorPart and current selection is inside a method,
* CParser should be able to figure that out.
*
* @throws Exception
*/
@Test
public void canParseCurrentFunctionInCppFile() throws Exception {
// make test project a C++ project
project.addCCNature();
final String expectedFunction = "main";
final String cppSourceCode = "#include \"circle.h\"\n" + "#include <math.h>\n" + "float circle::area() {\n" + "return this->radius * this-> radius * M_PI\n" + "}\n" + "int " + expectedFunction + "() {\n" + "int some_var = 0;\n" + "// " + OFFSET_MARKER + "\n" + "return 0;\n" + "}\n";
assertNull(project.getTestProject().findMember(new Path("/src/circle.cpp")));
// Add shape.h to project
InputStream newFileInputStream = new ByteArrayInputStream(cppSourceCode.getBytes());
IFile cppSourceFile = project.addFileToProject("/src", "circle.cpp", newFileInputStream);
assertNotNull(project.getTestProject().findMember(new Path("/src/circle.cpp")));
// Open a source file and get the IEditorPart
cppSourceEditorPart = openEditor(cppSourceFile);
// make sure editor content is correct
assertEquals(cppSourceCode, getContent(cppSourceEditorPart));
// make sure we have the proper editor type
assertTrue(cppSourceEditorPart instanceof AbstractTextEditor);
// Select the snippet we want
int selectionStart = cppSourceCode.indexOf(OFFSET_MARKER);
assertTrue(selectionStart >= 0);
int selectionLength = OFFSET_MARKER.length();
AbstractTextEditor cppEditor = (AbstractTextEditor) cppSourceEditorPart;
cppEditor.getSelectionProvider().setSelection(new TextSelection(selectionStart, selectionLength));
final String actualFunction = cParser.parseCurrentFunction(cppSourceEditorPart);
assertEquals(expectedFunction, actualFunction);
}
Aggregations