當前位置: 首頁>>代碼示例>>Java>>正文


Java IRegion.getOffset方法代碼示例

本文整理匯總了Java中org.eclipse.jface.text.IRegion.getOffset方法的典型用法代碼示例。如果您正苦於以下問題:Java IRegion.getOffset方法的具體用法?Java IRegion.getOffset怎麽用?Java IRegion.getOffset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jface.text.IRegion的用法示例。


在下文中一共展示了IRegion.getOffset方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: insertLineAbove

import org.eclipse.jface.text.IRegion; //導入方法依賴的package包/類
/**
 * Insert the given string as a new line above the line at the given offset. The given string need not contain any
 * line delimiters and the offset need not point to the beginning of a line. If 'sameIndentation' is set to
 * <code>true</code>, the new line will be indented as the line at the given offset (i.e. same leading white space).
 */
public static IChange insertLineAbove(IXtextDocument doc, int offset, String txt, boolean sameIndentation)
		throws BadLocationException {
	final String NL = lineDelimiter(doc, offset);
	final IRegion currLineReg = doc.getLineInformationOfOffset(offset);
	String indent = "";
	if (sameIndentation) {
		final String currLine = doc.get(currLineReg.getOffset(), currLineReg.getLength());
		int idx = 0;
		while (idx < currLine.length() && Character.isWhitespace(currLine.charAt(idx))) {
			idx++;
		}
		indent = currLine.substring(0, idx);
	}
	return new Replacement(getURI(doc), currLineReg.getOffset(), 0, indent + txt + NL);
}
 
開發者ID:eclipse,項目名稱:n4js,代碼行數:21,代碼來源:ChangeProvider.java

示例2: removeText

import org.eclipse.jface.text.IRegion; //導入方法依賴的package包/類
/**
 * Removes text of the given length at the given offset. If 'removeEntireLineIfEmpty' is set to <code>true</code>,
 * the line containing the given text region will be deleted entirely iff the change would leave the line empty
 * (i.e. contains only white space) <em>after</em> the removal of the text region.
 */
public static IChange removeText(IXtextDocument doc, int offset, int length, boolean removeEntireLineIfEmpty)
		throws BadLocationException {
	if (!removeEntireLineIfEmpty) {
		// simple
		return new Replacement(getURI(doc), offset, length, "");
	} else {
		// get entire line containing the region to be removed
		// OR in case the region spans multiple lines: get *all* lines affected by the removal
		final IRegion linesRegion = DocumentUtilN4.getLineInformationOfRegion(doc, offset, length, true);
		final String lines = doc.get(linesRegion.getOffset(), linesRegion.getLength());
		// simulate the removal
		final int offsetRelative = offset - linesRegion.getOffset();
		final String lineAfterRemoval = removeSubstring(lines, offsetRelative, length);
		final boolean isEmptyAfterRemoval = lineAfterRemoval.trim().isEmpty();
		if (isEmptyAfterRemoval) {
			// remove entire line (or in case the removal spans multiple lines: remove all affected lines entirely)
			return new Replacement(getURI(doc),
					linesRegion.getOffset(), linesRegion.getLength(), "");
		} else {
			// just remove the given text region
			return new Replacement(getURI(doc), offset, length, "");
		}
	}
}
 
開發者ID:eclipse,項目名稱:n4js,代碼行數:30,代碼來源:ChangeProvider.java

示例3: endOfLineOf

import org.eclipse.jface.text.IRegion; //導入方法依賴的package包/類
/**
 * Returns the end offset of the line that contains the specified offset or
 * if the offset is inside a line delimiter, the end offset of the next
 * line.
 *
 * @param offset
 *            the offset whose line end offset must be computed
 * @return the line end offset for the given offset
 * @exception BadLocationException
 *                if offset is invalid in the current document
 */
protected int endOfLineOf(int offset) throws BadLocationException {

	IRegion info = fDocument.getLineInformationOfOffset(offset);
	if (offset <= info.getOffset() + info.getLength()){
		return info.getOffset() + info.getLength();
	}

	int line = fDocument.getLineOfOffset(offset);
	try {
		info = fDocument.getLineInformation(line + 1);
		return info.getOffset() + info.getLength();
	} catch (BadLocationException x) {
		return fDocument.getLength();
	}
}
 
開發者ID:de-jcup,項目名稱:eclipse-batch-editor,代碼行數:27,代碼來源:PresentationSupport.java

示例4: getDamageRegion

import org.eclipse.jface.text.IRegion; //導入方法依賴的package包/類
@Override
public IRegion getDamageRegion(ITypedRegion partition, DocumentEvent event, boolean documentPartitioningChanged) {
	if (!documentPartitioningChanged) {
		try {

			IRegion info = fDocument.getLineInformationOfOffset(event.getOffset());
			int start = Math.max(partition.getOffset(), info.getOffset());

			int end = event.getOffset() + (event.getText() == null ? event.getLength() : event.getText().length());

			if (info.getOffset() <= end && end <= info.getOffset() + info.getLength()) {
				// optimize the case of the same line
				end = info.getOffset() + info.getLength();
			} else{
				end = endOfLineOf(end);
			}

			end = Math.min(partition.getOffset() + partition.getLength(), end);
			return new Region(start, end - start);

		} catch (BadLocationException x) {
		}
	}

	return partition;
}
 
開發者ID:de-jcup,項目名稱:eclipse-batch-editor,代碼行數:27,代碼來源:PresentationSupport.java

示例5: validateInsertFinalNewline

import org.eclipse.jface.text.IRegion; //導入方法依賴的package包/類
/**
 * Validate 'insert_final_newline' if needed and update the given set of marker.
 *
 * @param document
 *            the document to validate
 * @param remainingMarkers
 *            set of markers to update.
 * @throws BadLocationException
 */
private void validateInsertFinalNewline(IDocument document, Set<IMarker> remainingMarkers)
		throws BadLocationException {
	boolean insertFinalNewline = preferenceStore.getBoolean(EDITOR_INSERT_FINAL_NEWLINE);
	if (!insertFinalNewline) {
		return;
	}
	// Check if there are an empty line at the end of the document.
	if (document.getLength() == 0) {
		return;
	}
	int line = document.getNumberOfLines() - 1;
	IRegion region = document.getLineInformation(line);
	if (region.getLength() > 0) {
		int end = region.getOffset() + region.getLength();
		int start = end - 1;
		addOrUpdateMarker(start, end, insertFinalNewlineType, document, remainingMarkers);
	}
}
 
開發者ID:angelozerr,項目名稱:ec4e,代碼行數:28,代碼來源:ValidateAppliedOptionsStrategy.java

示例6: detectHyperlinks

import org.eclipse.jface.text.IRegion; //導入方法依賴的package包/類
@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region,
        boolean canShowMultipleHyperlinks) {
    SQLEditor editor = getAdapter(SQLEditor.class);
    PgDbParser parser = editor.getParser();

    int offset = region.getOffset();
    List<PgObjLocation> refs = parser.getObjsForEditor(editor.getEditorInput());
    for (PgObjLocation obj : refs) {
        if (offset > obj.getOffset()
                && offset < (obj.getOffset() + obj.getObjLength())) {
            IHyperlink[] links =  parser.getDefinitionsForObj(obj)
                    .map(def -> new SQLEditorHyperLink(
                            new Region(def.getOffset(), def.getObjLength()),
                            new Region(obj.getOffset(), obj.getObjLength()),
                            obj.getObjName(), def.getFilePath(), def.getLineNumber()))
                    .toArray(IHyperlink[]::new);
            if (links.length != 0) {
                return links;
            }
        }
    }
    return null;
}
 
開發者ID:pgcodekeeper,項目名稱:pgcodekeeper,代碼行數:25,代碼來源:SQLEditorHyperLinkDetector.java

示例7: setCommentFields

import org.eclipse.jface.text.IRegion; //導入方法依賴的package包/類
/**
 * Sets beginCommentOffset, endCommentOffset, indent, and margin
 * 
 * @throws org.eclipse.jface.text.BadLocationException
 */
private void setCommentFields()
		throws org.eclipse.jface.text.BadLocationException {
	// Following code modified by LL on 13 Apr 2011 so that it
	// finds the correct beginning and end of the comment if
	// if the cursor is at right after the "(" or right before
	// the ")" that bracket the comment.
	int searchOffset = offset;
	if ((offset > 0) && text.charAt(offset - 1) == '(') {
		searchOffset++;
	}
	beginCommentOffset = text.lastIndexOf("(*", searchOffset);
	searchOffset = offset;
	if (text.charAt(offset) == ')') {
		searchOffset--;
	}
	endCommentOffset = text.indexOf("*)", searchOffset) + 2;

	IRegion beginCommentLineInfo = doc
			.getLineInformationOfOffset(beginCommentOffset);
	indent = beginCommentOffset - beginCommentLineInfo.getOffset();

	margin = Math.max(RightMargin, indent + 4);
}
 
開發者ID:tlaplus,項目名稱:tlaplus,代碼行數:29,代碼來源:BoxedCommentHandler.java

示例8: getFirstCompleteLineOfRegion

import org.eclipse.jface.text.IRegion; //導入方法依賴的package包/類
private int getFirstCompleteLineOfRegion(IRegion region, IDocument document) {
	try {
		final int startLine = document.getLineOfOffset(region.getOffset());
		int offset = document.getLineOffset(startLine);
		if (offset >= region.getOffset()) {
			return startLine;
		}
		final int nextLine = startLine + 1;
		if (nextLine == document.getNumberOfLines()) {
			return -1;
		}
		offset = document.getLineOffset(nextLine);
		return (offset > region.getOffset() + region.getLength() ? -1 : nextLine);
	} catch (BadLocationException x) {
		// should not happen
	}
	return -1;
}
 
開發者ID:DarwinSPL,項目名稱:DarwinSPL,代碼行數:19,代碼來源:HyconstraintsToggleCommentHandler.java

示例9: getRegionWithPreviousLine

import org.eclipse.jface.text.IRegion; //導入方法依賴的package包/類
/**
 * Returns a new region that ends at the end of the input region and begins
 * at the first character of the line before the line containing the offset
 * of the input region. If the input region's offset is on the first
 * line of the document, this method does nothing.
 * 
 * @param document
 * @param region
 * @return
 * @throws BadLocationException
 */
public static IRegion getRegionWithPreviousLine(IDocument document, IRegion region) throws BadLocationException
{
    // the first line of the region
    int currentFirstLine = document.getLineOfOffset(region.getOffset());
    if (currentFirstLine > 0)
    {
        int newOffset = document.getLineOffset(currentFirstLine - 1);
        return new Region(newOffset, region.getLength() + (region.getOffset() - newOffset));
    } else
    {
        // no previous line so do nothing
        return region;
    }

}
 
開發者ID:tlaplus,項目名稱:tlaplus,代碼行數:27,代碼來源:DocumentHelper.java

示例10: detectHyperlinks

import org.eclipse.jface.text.IRegion; //導入方法依賴的package包/類
@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region,
    boolean canShowMultipleHyperlinks) {

  int offset = region.getOffset();
  int length = region.getLength();
  if (offset == 0 && length == 0)
    return null;

  if (MarkerActivator.getEditor() == null || MarkerActivator.getEditor().getEditorInput() == null)
    return null;

  IFile file = (IFile) MarkerActivator.getEditor().getEditorInput().getAdapter(IFile.class);

  List<IMarker> markedList = MarkerFactory.findMarkers(file);
  for (IMarker iMarker : markedList) {
    // look for keyword
    // detect region containing keyword
    IRegion targetRegion = new Region(MarkUtilities.getStart(iMarker),
        MarkUtilities.getLength(iMarker));
    if ((targetRegion.getOffset() <= offset)
        && ((targetRegion.getOffset() + targetRegion.getLength()) > offset)) {
      // create link
      return new IHyperlink[] {new MarkerMappingActionHyperlink(targetRegion)};
    }
  }
  return null;
}
 
開發者ID:ModelWriter,項目名稱:Tarski,代碼行數:29,代碼來源:MarkerMappingActionHyperlinkDetector.java

示例11: getHoverInfo

import org.eclipse.jface.text.IRegion; //導入方法依賴的package包/類
@Override
public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
	BashEditorPreferences preferences = BashEditorPreferences.getInstance();
	boolean tooltipsEnabled = preferences.getBooleanPreference(P_TOOLTIPS_ENABLED);
	if (!tooltipsEnabled){
		return null;
	}
	IDocument document = textViewer.getDocument();
	if (document == null) {
		return "";
	}
	String text = document.get();
	if (text == null) {
		return "";
	}
	int offset = hoverRegion.getOffset();
	String word = SimpleStringUtils.nextWordUntilWhitespace(text, offset);
	if (word.isEmpty()) {
		return "";
	}

	for (DocumentKeyWord keyword : DocumentKeyWords.getAll()) {
		if (word.equals(keyword.getText())) {
			return buildHoverInfo(keyword);
		}
	}

	return "";
}
 
開發者ID:de-jcup,項目名稱:eclipse-bash-editor,代碼行數:30,代碼來源:BashTextHover.java

示例12: getAllSnippetsAnnotations

import org.eclipse.jface.text.IRegion; //導入方法依賴的package包/類
private Map<ProjectionAnnotation, Position> getAllSnippetsAnnotations() {
	Map<ProjectionAnnotation, Position> annotations = new HashMap<ProjectionAnnotation, Position>();
	IDocument document = getDocument();
	int curOffset = 0;
	FindReplaceDocumentAdapter frda = new FindReplaceDocumentAdapter(document);
	try {
		IRegion startRegion = frda.find(curOffset, "SNIPPET_START", true, false, false, false); //$NON-NLS-1$
		while (startRegion != null && startRegion.getOffset() >= curOffset) {
			int startLine = document.getLineOfOffset(startRegion.getOffset());
			int startOffset = document.getLineOffset(startLine);
			curOffset = startOffset + document.getLineLength(startLine);
			IRegion endRegion = frda.find(startRegion.getOffset(), "SNIPPET_END", true, false, false, false); //$NON-NLS-1$
			if (endRegion != null) {
				int endLine = document.getLineOfOffset(endRegion.getOffset());
				int endOffset = document.getLineOffset(endLine);
				endOffset += document.getLineLength(endLine);
				curOffset = endOffset;
				String text = document.get(startOffset, endOffset - startOffset);
				ProjectionAnnotation annotation = new ProjectionAnnotation(true);
				annotation.setText(text);
				annotation.setRangeIndication(true);
				annotations.put(annotation, new Position(startOffset, endOffset - startOffset));
			}
			if (curOffset < document.getLength()) {
				startRegion = frda.find(curOffset, "SNIPPET_START", true, false, false, false); //$NON-NLS-1$
			}
		}

	} catch (BadLocationException e) {

	}
	return annotations;
}
 
開發者ID:capitalone,項目名稱:Hydrograph,代碼行數:34,代碼來源:SourceViewer.java

示例13: addNewAnnotation

import org.eclipse.jface.text.IRegion; //導入方法依賴的package包/類
private void addNewAnnotation(final String errored, final int line,
    final IRegion lineInformationOfOffset) {
  final int offset = lineInformationOfOffset.getOffset();
  final int length = lineInformationOfOffset.getLength();
  final String message = errored + " cannot be resolved as a relation";

  final Annotation annotation = new Annotation(this.MME_REASON_ANNOT_TYPE, true, message);
  this.annotationModel.connect(this.document);
  this.annotationModel.addAnnotation(annotation, new Position(offset, length));
  this.annotationModel.disconnect(this.document);
}
 
開發者ID:ModelWriter,項目名稱:Tarski,代碼行數:12,代碼來源:ReasonReconcilingStrategy.java

示例14: getMethodOffset

import org.eclipse.jface.text.IRegion; //導入方法依賴的package包/類
/**
 * This method returns the offset of the method passed to it.
 * @param document The document user is interacting with.
 * @param method The method whose offset is required.
 * @return The offset of the method.
 */
private Integer getMethodOffset(IDocument document, VFMethod method) {

	FindReplaceDocumentAdapter findReplaceDocumentAdapter = new FindReplaceDocumentAdapter(document);
	try {
		IRegion region = findReplaceDocumentAdapter.find(0, FindReplaceDocumentAdapter.escapeForRegExPattern(method.getSootMethod().getDeclaration()), true,
				true, false, true);
		return region.getOffset();
	} catch (BadLocationException e) {
		e.printStackTrace();
	}
	return 0;
}
 
開發者ID:VisuFlow,項目名稱:visuflow-plugin,代碼行數:19,代碼來源:NavigationHandler.java

示例15: detectHyperlinks

import org.eclipse.jface.text.IRegion; //導入方法依賴的package包/類
@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
	IDocument document = textViewer.getDocument();

	/* Extrait le mot courant. */
	ITextSelection selection = new TextSelection(document, region.getOffset(), region.getLength());
	ITextSelection currentWordSelection = DocumentUtils.findCurrentWord(document, selection, WordSelectionType.CONSTANT_CASE);
	if (currentWordSelection == null) {
		return null; // NOSONAR
	}
	String currentWord = currentWordSelection.getText();
	if (currentWord == null) {
		return null; // NOSONAR
	}

	IRegion targetRegion = new Region(currentWordSelection.getOffset(), currentWordSelection.getLength());
	FileRegion fileRegion = new FileRegion(UiUtils.getCurrentEditorFile(), targetRegion.getOffset(), targetRegion.getLength());

	/* Cherche un nom de DTO. */
	IHyperlink[] hyperlinks = detectDtDefinitionName(currentWord, targetRegion, fileRegion);
	if (hyperlinks != null) {
		return hyperlinks;
	}

	/* Cherche un nom de Task. */
	hyperlinks = detectTaskName(currentWord, targetRegion);
	if (hyperlinks != null) {
		return hyperlinks;
	}

	/* Cherche une déclaration KSP autre. */
	return detectKspName(currentWord, targetRegion, fileRegion);
}
 
開發者ID:sebez,項目名稱:vertigo-chroma-kspplugin,代碼行數:34,代碼來源:KspNameHyperLinkDetector.java


注:本文中的org.eclipse.jface.text.IRegion.getOffset方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。