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


Java ISourceReference.getSourceRange方法代码示例

本文整理汇总了Java中org.eclipse.jdt.core.ISourceReference.getSourceRange方法的典型用法代码示例。如果您正苦于以下问题:Java ISourceReference.getSourceRange方法的具体用法?Java ISourceReference.getSourceRange怎么用?Java ISourceReference.getSourceRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jdt.core.ISourceReference的用法示例。


在下文中一共展示了ISourceReference.getSourceRange方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isInside

import org.eclipse.jdt.core.ISourceReference; //导入方法依赖的package包/类
/**
 * Tests if a position is inside the source range of an element.
 * @param pos Position to be tested.
 * @param sourceElement Source element (must be a IJavaElement)
 * @return boolean Return <code>true</code> if position is located inside the source element.
 * @throws CoreException Exception thrown if element range could not be accessed.
 *
 * @since 2.1
 */
protected boolean isInside(int pos, ISourceReference sourceElement) throws CoreException {
	if (fCachedRange == null) {
		fCachedRange= sourceElement.getSourceRange();
	}
	ISourceRange range= fCachedRange;
	if (range != null) {
		int rangeOffset= range.getOffset();
		return (rangeOffset <= pos && rangeOffset + range.getLength() > pos);
	}
	return false;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:21,代码来源:ProblemsLabelDecorator.java

示例2: getOffset

import org.eclipse.jdt.core.ISourceReference; //导入方法依赖的package包/类
/**
 * Returns the offset of the given Java element.
 *
 * @param element	Java element
 * @return Offset of the given Java element
 */
private int getOffset(IJavaElement element) {
	if (element instanceof ISourceReference) {
		ISourceReference sr= (ISourceReference) element;
		try {
			ISourceRange srcRange= sr.getSourceRange();
			if (srcRange != null)
				return srcRange.getOffset();
		} catch (JavaModelException e) {
		}
	}
	return -1;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:19,代码来源:CompilationUnitEditor.java

示例3: getLength

import org.eclipse.jdt.core.ISourceReference; //导入方法依赖的package包/类
/**
 * Returns the length of the given Java element.
 *
 * @param element	Java element
 * @return Length of the given Java element
 */
private int getLength(IJavaElement element) {
	if (element instanceof ISourceReference) {
		ISourceReference sr= (ISourceReference) element;
		try {
			ISourceRange srcRange= sr.getSourceRange();
			if (srcRange != null)
				return srcRange.getLength();
		} catch (JavaModelException e) {
		}
	}
	return -1;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:19,代码来源:CompilationUnitEditor.java

示例4: update

import org.eclipse.jdt.core.ISourceReference; //导入方法依赖的package包/类
public void update() {
	boolean enabled= false;
	ISourceReference ref= getSourceReference();
	if (ref != null) {
		ISourceRange range;
		try {
			range= ref.getSourceRange();
			enabled= range != null && range.getLength() > 0;
		} catch (JavaModelException e) {
			// enabled= false;
		}
	}
	setEnabled(enabled);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:15,代码来源:GoToNextPreviousMemberAction.java

示例5: getExtendedSource

import org.eclipse.jdt.core.ISourceReference; //导入方法依赖的package包/类
private String getExtendedSource(ISourceReference ref) throws JavaModelException {

		// get parent
		if (ref instanceof IJavaElement) {
			IJavaElement parent= ((IJavaElement) ref).getParent();
			if (parent instanceof ISourceReference) {
				ISourceReference sr= (ISourceReference) parent;
				String parentContent= sr.getSource();
				if (parentContent != null) {
					ISourceRange parentRange= sr.getSourceRange();
					ISourceRange childRange= ref.getSourceRange();

					int start= childRange.getOffset() - parentRange.getOffset();
					int end= start + childRange.getLength();

					// search backwards for beginning of line
					while (start > 0) {
						char c= parentContent.charAt(start-1);
						if (c == '\n' || c == '\r')
							break;
						start--;
					}

					return parentContent.substring(start, end);
				}
			}
		}

		return ref.getSource();
	}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:31,代码来源:JavaCompareAction.java

示例6: run

import org.eclipse.jdt.core.ISourceReference; //导入方法依赖的package包/类
@Override
public void run() {

	final JavaSourceViewer viewer= (JavaSourceViewer) getSourceViewer();
	if (viewer.isEditable() && ElementValidator.check(getInputJavaElement(), getSite().getShell(), JavaEditorMessages.JavaEditor_FormatElementDialog_label, true)) {

		final Point selection= viewer.rememberSelection();
		try {
			viewer.setRedraw(false);

			boolean emptySelection= selection.y == 0;
			if (emptySelection) {
				final ITypedRegion partition= TextUtilities.getPartition(viewer.getDocument(), IJavaPartitions.JAVA_PARTITIONING, selection.x, true);
				String type= partition.getType();
				if (IJavaPartitions.JAVA_DOC.equals(type) || IJavaPartitions.JAVA_MULTI_LINE_COMMENT.equals(type) || IJavaPartitions.JAVA_SINGLE_LINE_COMMENT.equals(type)) {
					viewer.setSelectedRange(partition.getOffset(), partition.getLength());
					viewer.doOperation(ISourceViewer.FORMAT);
					return;
				}
			}
			final IJavaElement element= getElementAt(selection.x, true);
			if (element != null && element.exists()) {
				try {
					final int kind= element.getElementType();
					if (kind == IJavaElement.TYPE || kind == IJavaElement.METHOD || kind == IJavaElement.INITIALIZER) {

						final ISourceReference reference= (ISourceReference) element;
						final ISourceRange range= reference.getSourceRange();
						final ISourceRange nameRange= reference.getNameRange();
						final boolean seletionInNameRange= nameRange != null && selection.x >= nameRange.getOffset()
								&& selection.x + selection.y <= nameRange.getOffset() + nameRange.getLength();
						if (range != null && (emptySelection || seletionInNameRange))
							viewer.setSelectedRange(range.getOffset(), range.getLength());
					}
				} catch (JavaModelException exception) {
					// Should not happen
				}
			}
			viewer.doOperation(ISourceViewer.FORMAT);
		} catch (BadLocationException e) {
			// Cannot happen
		} finally {

			viewer.setRedraw(true);
			viewer.restoreSelection();
		}
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:49,代码来源:JavaEditor.java


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