当前位置: 首页>>代码示例>>Java>>正文


Java ITextSelection.getStartLine方法代码示例

本文整理汇总了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);
	}
}
 
开发者ID:tracymiranda,项目名称:dsp4e,代码行数:25,代码来源:DSPBreakpointAdapter.java

示例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);
	}
}
 
开发者ID:cchabanois,项目名称:mesfavoris,代码行数:20,代码来源:TextEditorBookmarkPropertiesProvider.java

示例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);
  }
}
 
开发者ID:jbosstools,项目名称:chromedevtools,代码行数:27,代码来源:LineBreakpointAdapter.java

示例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);
}
 
开发者ID:cchabanois,项目名称:mesfavoris,代码行数:32,代码来源:JavaEditorBookmarkPropertiesProvider.java

示例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
                }
            }
        }
    }
}
 
开发者ID:tlaplus,项目名称:tlaplus,代码行数:32,代码来源:DefineFoldingRegionAction.java

示例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;
}
 
开发者ID:yuv422,项目名称:z80editor,代码行数:31,代码来源:Z80InstructionHelpView.java

示例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;
}
 
开发者ID:cplutte,项目名称:bts,代码行数:43,代码来源:TextViewerMoveLinesAction.java

示例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;
	}
}
 
开发者ID:cplutte,项目名称:bts,代码行数:24,代码来源:TextViewerMoveLinesAction.java

示例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
	}

}
 
开发者ID:cplutte,项目名称:bts,代码行数:37,代码来源:TextViewerJoinLinesAction.java

示例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()));
      }
    }
  }
}
 
开发者ID:monto-editor,项目名称:monto-eclipse,代码行数:36,代码来源:MontoToggleBreakpointsTarget.java

示例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;
}
 
开发者ID:tlaplus,项目名称:tlaplus,代码行数:77,代码来源:GotoMatchingParenHandler.java

示例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;
  }
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:45,代码来源:RegionConverter.java


注:本文中的org.eclipse.jface.text.ITextSelection.getStartLine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。