当前位置: 首页>>代码示例>>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;未经允许,请勿转载。