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


Java IRegion.getLength方法代碼示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: getCurrentLine

import org.eclipse.jface.text.IRegion; //導入方法依賴的package包/類
public String getCurrentLine(IDocument document, int offset) {
	
	final String docContent = document.get();		
	String line = "";
	IRegion currentRegion = null;
	int posOffset = offset;
	try {
		currentRegion = document.getLineInformationOfOffset(offset);
		
		posOffset = currentRegion.getOffset() + currentRegion.getLength();
		
		line = docContent.substring(currentRegion.getOffset(), posOffset);
	}
	catch (BadLocationException ble) {
		Activator.getDefault().log("could not get current line", ble);
	}
	
	return line; 
}
 
開發者ID:SAP,項目名稱:hybris-commerce-eclipse-plugin,代碼行數:20,代碼來源:ImpexCommandContentAssistProcessor.java

示例6: insertMultiLiner

import org.eclipse.jface.text.IRegion; //導入方法依賴的package包/類
private void insertMultiLiner(BracketInsertion data, ISelectionProvider selectionProvider, int offset,
		IDocument document) throws BadLocationException {
	IRegion region = document.getLineInformationOfOffset(offset);
	if (region == null) {
		return;
	}
	int length = region.getLength();

	String textBeforeColumn = document.get(offset - length, length-1); //-1 to get not he bracket itself
	String relevantColumnsBefore = TextUtil.trimRightWhitespaces(textBeforeColumn);
	InsertionData result = support.prepareInsertionString(
			data.createMultiLineTemplate(SourceCodeInsertionSupport.CURSOR_VARIABLE), relevantColumnsBefore);

	document.replace(offset - 1, 1, result.getSourceCode());
	selectionProvider.setSelection(new TextSelection(offset + result.getCursorOffset() - 1, 0));

}
 
開發者ID:de-jcup,項目名稱:egradle,代碼行數:18,代碼來源:GroovyBracketInsertionCompleter.java

示例7: 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,代碼來源:DwprofileToggleCommentHandler.java

示例8: 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

示例9: 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:convertigo,項目名稱:convertigo-eclipse,代碼行數:23,代碼來源:NonRuleBasedDamagerRepairer.java

示例10: getDamageRegion

import org.eclipse.jface.text.IRegion; //導入方法依賴的package包/類
/**
 * @see IPresentationDamager#getDamageRegion(ITypedRegion, DocumentEvent, boolean)
 */
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:convertigo,項目名稱:convertigo-eclipse,代碼行數:40,代碼來源:NonRuleBasedDamagerRepairer.java

示例11: detectHyperlinks

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

	/* Vérifie qu'on est dans une String de KSP */
	boolean isSqlString = DocumentUtils.isContentType(document, region.getOffset(), KspRegionType.STRING);
	if (!isSqlString) {
		return null; // NOSONAR
	}

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

	/* Extrait un nom de DTO : Calcul le nom en PascalCase */
	String javaName = StringUtils.toPascalCase(currentWord);

	/* Cherche le fichier Java du DTO. */
	DtoFile dtoFile = DtoManager.getInstance().findDtoFile(javaName);

	/* Fichier Java trouvé : on ajoute un lien vers le fichier Java. */
	if (dtoFile != null) {
		IRegion targetRegion = new Region(currentWordSelection.getOffset(), currentWordSelection.getLength());
		return new IHyperlink[] { new JavaImplementationHyperLink(targetRegion, dtoFile) };
	}

	return null; // NOSONAR
}
 
開發者ID:sebez,項目名稱:vertigo-chroma-kspplugin,代碼行數:36,代碼來源:SqlTableHyperLinkDetector.java

示例12: 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.NOT_SPACE);
	if (currentWordSelection == null) {
		return null; // NOSONAR
	}
	String currentWord = currentWordSelection.getText();
	if (currentWord == null) {
		return null; // NOSONAR
	}

	/* Vérifie que c'est un chemin relatif valide. */
	String absolutePath = getAbsolutePath(currentWord);
	if (absolutePath == null) {
		return null; // NOSONAR
	}

	/* Vérifie que le fichier existe. */
	IFile file = (IFile) ResourcesPlugin.getWorkspace().getRoot().findMember(absolutePath);
	if (file == null) {
		return null; // NOSONAR
	}

	/* Renvoin un lien vers le fichier dont on a trouvé le chemin. */
	IRegion targetRegion = new Region(currentWordSelection.getOffset(), currentWordSelection.getLength());
	return new IHyperlink[] { new FileHyperLink(targetRegion, file) };
}
 
開發者ID:sebez,項目名稱:vertigo-chroma-kspplugin,代碼行數:33,代碼來源:FilePathHyperLinkDetector.java

示例13: 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

示例14: 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.CANONICAL_JAVA_NAME);
	if (currentWordSelection == null) {
		return null; // NOSONAR
	}
	String currentWord = currentWordSelection.getText();
	if (currentWord == null) {
		return null; // NOSONAR
	}

	/* Vérifie qu'on est dans une région entière KspString */
	if (!DocumentUtils.isExactKspString(document, currentWordSelection)) {
		return null; // NOSONAR
	}

	/* Extrait un chemin de définition de DTO. */
	DtoDefinitionPath definitionPath = KspStringUtils.getKasper3DefinitionPath(currentWord);
	if (definitionPath == null) {
		return null; // NOSONAR
	}

	/* Cherche le fichier Java du DTO. */
	DtoFile dtoFile = DtoManager.getInstance().findDtoFile(definitionPath);
	if (dtoFile == null) {
		return null; // NOSONAR
	}

	/* Fichier Java trouvé : on ajoute un lien vers le fichier Java. */
	IRegion targetRegion = new Region(currentWordSelection.getOffset(), currentWordSelection.getLength());
	return new IHyperlink[] { new JavaImplementationHyperLink(targetRegion, dtoFile) };
}
 
開發者ID:sebez,項目名稱:vertigo-chroma-kspplugin,代碼行數:37,代碼來源:DtoDefinitionPathHyperLinkDetector.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.CANONICAL_JAVA_NAME);
	if (currentWordSelection == null) {
		return null; // NOSONAR
	}
	String currentWord = currentWordSelection.getText();
	if (currentWord == null) {
		return null; // NOSONAR
	}

	/* Vérifie qu'on est dans une région entière KspString */
	if (!DocumentUtils.isExactKspString(document, currentWordSelection)) {
		return null; // NOSONAR
	}

	/* Charge le type Java. */
	IType javaType = findJavaType(currentWord);
	if (javaType == null) {
		return null; // NOSONAR
	}

	/* Renvoie un lien pour ouvrir le type Java. */
	IRegion targetRegion = new Region(currentWordSelection.getOffset(), currentWordSelection.getLength());
	return new IHyperlink[] { new JavaTypeHyperLink(targetRegion, javaType) };
}
 
開發者ID:sebez,項目名稱:vertigo-chroma-kspplugin,代碼行數:31,代碼來源:CanonicalJavaNameHyperLinkDetector.java


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