本文整理匯總了Java中org.eclipse.jface.text.ITextSelection.getStartLine方法的典型用法代碼示例。如果您正苦於以下問題:Java ITextSelection.getStartLine方法的具體用法?Java ITextSelection.getStartLine怎麽用?Java ITextSelection.getStartLine使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jface.text.ITextSelection
的用法示例。
在下文中一共展示了ITextSelection.getStartLine方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: toggleLineBreakpoints
import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
@Override
public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
ITextEditor textEditor = getEditor(part);
if (textEditor != null) {
IResource resource = textEditor.getEditorInput().getAdapter(IResource.class);
ITextSelection textSelection = (ITextSelection) selection;
int lineNumber = textSelection.getStartLine();
IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager()
.getBreakpoints(DSPPlugin.ID_DSP_DEBUG_MODEL);
for (int i = 0; i < breakpoints.length; i++) {
IBreakpoint breakpoint = breakpoints[i];
if (breakpoint instanceof ILineBreakpoint && resource.equals(breakpoint.getMarker().getResource())) {
if (((ILineBreakpoint) breakpoint).getLineNumber() == (lineNumber + 1)) {
// remove
breakpoint.delete();
return;
}
}
}
// create line breakpoint (doc line numbers start at 0)
DSPLineBreakpoint lineBreakpoint = new DSPLineBreakpoint(resource, lineNumber + 1);
DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(lineBreakpoint);
}
}
示例2: addBookmarkProperties
import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
private void addBookmarkProperties(Map<String, String> properties, ITextEditor textEditor,
ITextSelection textSelection) {
int lineNumber = textSelection.getStartLine();
addLineNumber(properties, lineNumber);
addLineContent(properties, textEditor, lineNumber);
addWorkspacePath(properties, textEditor);
putIfAbsent(properties, PROPERTY_NAME, () -> {
String lineContent = properties.get(PROP_LINE_CONTENT);
if (lineContent != null) {
return textEditor.getEditorInput().getName() + " : " + lineContent;
} else {
return textEditor.getEditorInput().getName();
}
});
IPath filePath = getFilePath(textEditor);
if (filePath != null) {
addFilePath(properties, filePath);
}
}
示例3: toggleLineBreakpoints
import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection)
throws CoreException {
ITextEditor textEditor = getEditor(part);
if (textEditor != null) {
IResource resource = (IResource) textEditor.getEditorInput().getAdapter(IResource.class);
ITextSelection textSelection = (ITextSelection) selection;
int lineNumber = textSelection.getStartLine();
IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(
getDebugModelId());
for (int i = 0; i < breakpoints.length; i++) {
IBreakpoint breakpoint = breakpoints[i];
if (resource.equals(breakpoint.getMarker().getResource())) {
if (((ILineBreakpoint) breakpoint).getLineNumber() == lineNumber + 1) {
// remove
breakpoint.delete();
return;
}
}
}
// Line numbers start with 0 in V8, with 1 in Eclipse.
ChromiumLineBreakpoint lineBreakpoint = new ChromiumLineBreakpoint(resource, lineNumber + 1,
getDebugModelId());
DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(lineBreakpoint);
}
}
示例4: addBookmarkProperties
import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
@Override
public void addBookmarkProperties(Map<String, String> bookmarkProperties, IWorkbenchPart part, ISelection selection,
IProgressMonitor monitor) {
ITextEditor editor = getTextEditor(part);
if (editor == null) {
return;
}
if (editor != part) {
selection = getSelection(editor);
}
if (!(selection instanceof ITextSelection)) {
return;
}
ITextSelection textSelection = (ITextSelection) selection;
int lineNumber = textSelection.getStartLine();
int offset = getOffset(editor, textSelection);
IJavaElement editorJavaElement = JavaUI.getEditorInputJavaElement(editor.getEditorInput());
if (editorJavaElement == null) {
return;
}
IJavaElement containingJavaElement = getContainingJavaElement(editorJavaElement, offset);
if (!(containingJavaElement instanceof IMember)) {
return;
}
IMember member = (IMember) containingJavaElement;
super.addMemberBookmarkProperties(bookmarkProperties, member);
addLineNumberInsideMemberProperty(bookmarkProperties, member, lineNumber);
addJavadocComment(bookmarkProperties, member, lineNumber);
addLineContent(bookmarkProperties, editor, lineNumber);
}
示例5: run
import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
public void run()
{
ITextEditor editor = getTextEditor();
ISelection selection = editor.getSelectionProvider().getSelection();
if (selection instanceof ITextSelection)
{
ITextSelection textSelection = (ITextSelection) selection;
if (textSelection.getLength() != 0)
{
IAnnotationModel model = getAnnotationModel(editor);
if (model != null)
{
int start = textSelection.getStartLine();
int end = textSelection.getEndLine();
try
{
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
int offset = document.getLineOffset(start);
int endOffset = document.getLineOffset(end + 1);
Position position = new Position(offset, endOffset - offset);
model.addAnnotation(new ProjectionAnnotation(), position);
} catch (BadLocationException x)
{
// ignore
}
}
}
}
}
示例6: getInstructionFromSelection
import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
private Z80Instruction getInstructionFromSelection(ITextSelection sel) {
IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (part instanceof XtextEditor) {
final XtextEditor editor = (XtextEditor) part;
IDocumentProvider prov = editor.getDocumentProvider();
final IDocument doc = prov.getDocument(editor.getEditorInput());
if (sel instanceof TextSelection) {
ITextSelection textSel = (ITextSelection) sel;
int line = textSel.getStartLine();
int off = textSel.getOffset();
int len = textSel.getLength();
if (len == 0) {
try {
off = doc.getLineOffset(line);
len = doc.getLineLength(line);
loadHtmlOpcodeInfo(off, len, editor);
} catch (BadLocationException e) {
throw new RuntimeException("Invalid line number: " + line, e);
}
} else if (editor instanceof XtextEditor) {
loadCycleInfo(off, len, editor, doc);
}
}
}
return null;
}
示例7: containedByVisibleRegion
import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
/**
* Checks if <code>selection</code> is contained by the visible region of <code>viewer</code>.
* As a special case, a selection is considered contained even if it extends over the visible
* region, but the extension stays on a partially contained line and contains only white space.
*
* @param selection the selection to be checked
* @param viewer the viewer displaying a visible region of <code>selection</code>'s document.
* @return <code>true</code>, if <code>selection</code> is contained, <code>false</code> otherwise.
*/
private boolean containedByVisibleRegion(ITextSelection selection, ITextViewer viewer) {
int min= selection.getOffset();
int max= min + selection.getLength();
IDocument document= viewer.getDocument();
IRegion visible;
if (viewer instanceof ITextViewerExtension5)
visible= ((ITextViewerExtension5) viewer).getModelCoverage();
else
visible= viewer.getVisibleRegion();
int visOffset= visible.getOffset();
try {
if (visOffset > min) {
if (document.getLineOfOffset(visOffset) != selection.getStartLine())
return false;
if (!isWhitespace(document.get(min, visOffset - min))) {
return false;
}
}
int visEnd= visOffset + visible.getLength();
if (visEnd < max) {
if (document.getLineOfOffset(visEnd) != selection.getEndLine())
return false;
if (!isWhitespace(document.get(visEnd, max - visEnd))) {
return false;
}
}
return true;
} catch (BadLocationException e) {
}
return false;
}
示例8: getSkippedLine
import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
/**
* Computes the region of the skipped line given the text block to be moved. If
* <code>fUpwards</code> is <code>true</code>, the line above <code>selection</code>
* is selected, otherwise the line below.
*
* @param document the document <code>selection</code> refers to
* @param selection the selection on <code>document</code> that will be moved.
* @return the region comprising the line that <code>selection</code> will be moved over, without its terminating delimiter.
*/
private ITextSelection getSkippedLine(IDocument document, ITextSelection selection) {
int skippedLineN= (fUpwards ? selection.getStartLine() - 1 : selection.getEndLine() + 1);
if (skippedLineN > document.getNumberOfLines() || (!fCopy && (skippedLineN < 0 || skippedLineN == document.getNumberOfLines())))
return null;
try {
if (fCopy && skippedLineN == -1)
skippedLineN= 0;
IRegion line= document.getLineInformation(skippedLineN);
return new TextSelection(document, line.getOffset(), line.getLength());
} catch (BadLocationException e) {
// only happens on concurrent modifications
return null;
}
}
示例9: run
import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
@Override
public void run() {
ITextViewer viewer= getTextViewer();
if (viewer == null)
return;
if (!canModifyViewer())
return;
IDocument document= viewer.getDocument();
if (document == null)
return;
ITextSelection selection= getSelection(viewer);
if (selection == null)
return;
int startLine= selection.getStartLine();
int endLine= selection.getEndLine();
try {
int caretOffset= joinLines(document, startLine, endLine);
if (caretOffset > -1) {
StyledText widget= viewer.getTextWidget();
widget.setRedraw(false);
adjustHighlightRange(viewer, caretOffset, 0);
viewer.revealRange(caretOffset, 0);
viewer.setSelectedRange(caretOffset, 0);
widget.setRedraw(true);
}
} catch (BadLocationException e) {
// should not happen
}
}
示例10: toggleLineBreakpoints
import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
@Override
public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection)
throws CoreException {
System.out.println("MontoToggleBreakpointsTarget.toggleLineBreakpoints()");
if (part != null && part instanceof UniversalEditor) {
UniversalEditor universalEditor = (UniversalEditor) part;
if (universalEditor.getParseController() instanceof MontoParseController) {
MontoParseController montoParseController =
(MontoParseController) universalEditor.getParseController();
IResource resource =
(IResource) universalEditor.getEditorInput().getAdapter(IResource.class);
ITextSelection textSelection = (ITextSelection) selection;
int lineNumber = textSelection.getStartLine();
// delete old breakpoints in lineNumber
IBreakpoint[] oldBreakpoints =
DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(Activator.PLUGIN_ID);
boolean deletedBreakPoints = false;
for (IBreakpoint oldBreakpoint : oldBreakpoints) {
if (resource.equals(oldBreakpoint.getMarker().getResource())
&& ((ILineBreakpoint) oldBreakpoint).getLineNumber() == (lineNumber + 1)) {
deletedBreakPoints = true;
oldBreakpoint.delete();
}
}
if (!deletedBreakPoints) {
// create new one
DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(
new MontoLineBreakpoint(resource, lineNumber + 1, montoParseController.getSource()));
}
}
}
}
示例11: execute
import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
/**
* The method called when the user executes the Goto Matching Paren command.
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
TLAEditor tlaEditor = EditorUtil.getTLAEditorWithFocus();
document = tlaEditor.publicGetSourceViewer().getDocument();
try {
ITextSelection selection = (ITextSelection) tlaEditor
.getSelectionProvider().getSelection();
Region selectedRegion = new Region(selection.getOffset(),
selection.getLength());
int selectedParenIdx = getSelectedParen(selectedRegion);
int lineNumber = selection.getStartLine();
// Note: if the selection covers multiple lines, then
// selectParenIdx should have thrown an exception.
if (lineNumber < 0) {
throw new ParenErrorException("Toolbox bug: bad selected line computed", null, null);
}
setLineRegions(lineNumber);
setRegionInfo();
if (selectedParenIdx < PCOUNT) {
findMatchingRightParen(selectedParenIdx);
}
else {
findMatchingLeftParen(selectedParenIdx);
}
tlaEditor.selectAndReveal(currLoc, 0);
} catch (ParenErrorException e) {
/*
* Report the error.
*/
IResource resource = ResourceHelper
.getResourceByModuleName(tlaEditor.getModuleName());
ErrorMessageEraser listener = new ErrorMessageEraser(tlaEditor,
resource);
tlaEditor.getViewer().getTextWidget().addCaretListener(listener);
tlaEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(e.message);
Region[] regions = e.regions;
if (regions[0] != null) {
try {
// The following code was largely copied from the The
// ShowUsesHandler class.
Spec spec = ToolboxHandle.getCurrentSpec();
spec.setMarkersToShow(null);
IMarker[] markersToShow = new IMarker[2];
for (int i = 0; i < 2; i++) {
IMarker marker = resource
.createMarker(PAREN_ERROR_MARKER_TYPE);
Map<String, Integer> markerAttributes = new HashMap<String, Integer>(
2);
markerAttributes.put(IMarker.CHAR_START, new Integer(
regions[i].getOffset()));
markerAttributes.put(
IMarker.CHAR_END,
new Integer(regions[i].getOffset()
+ regions[i].getLength()));
marker.setAttributes(markerAttributes);
markersToShow[i] = marker;
}
spec.setMarkersToShow(markersToShow);
} catch (CoreException exc) {
System.out
.println("GotoMatchingParenHandler.execute threw CoreException");
}
}
}
return null;
}
示例12: convertRegion
import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
private static IRegion convertRegion(int offset, int length, String text,
String originalDelimiter) {
try {
Document document = new Document(text);
String delimiter = document.getLineDelimiter(0);
// If the document's line delimiter is the same as that used to originally
// calculate this offset/length, then just return the original region.
if (delimiter == null || delimiter.equals(originalDelimiter)) {
return new Region(offset, length);
}
// If we're running a platform other than the one this offset/length was
// calculated on, we'll need to adjust the values. We start by creating
// a text selection containing the original region and the text with the
// original line endings.
String originalText = text.replaceAll(delimiter, originalDelimiter);
ITextSelection originalSelection = new TextSelection(new Document(
originalText), offset, length);
int delimiterLengthCorrection = originalDelimiter.length()
- delimiter.length();
// Adjust the offset by the delimiter length difference for each line
// that came before it.
int newOffset = originalSelection.getOffset()
- (delimiterLengthCorrection * originalSelection.getStartLine());
// Adjust the length by the delimiter length difference for each line
// between the start and the end of the original region
// TODO: account for case where the selection ends with a line break;
// currently this will not update the length since the selection starts
// and ends on the same line.
int regionLineBreaks = originalSelection.getEndLine()
- originalSelection.getStartLine();
int newLength = originalSelection.getLength()
- (delimiterLengthCorrection * regionLineBreaks);
return new Region(newOffset, newLength);
} catch (BadLocationException e) {
return null;
}
}