本文整理汇总了Java中org.eclipse.jdt.core.IMember.getTypeRoot方法的典型用法代码示例。如果您正苦于以下问题:Java IMember.getTypeRoot方法的具体用法?Java IMember.getTypeRoot怎么用?Java IMember.getTypeRoot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.IMember
的用法示例。
在下文中一共展示了IMember.getTypeRoot方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getLineNumber
import org.eclipse.jdt.core.IMember; //导入方法依赖的package包/类
public static Integer getLineNumber(IMember member) throws JavaModelException {
ITypeRoot typeRoot = member.getTypeRoot();
IBuffer buffer = typeRoot.getBuffer();
if (buffer == null) {
return null;
}
Document document = new Document(buffer.getContents());
int offset = 0;
if (SourceRange.isAvailable(member.getNameRange())) {
offset = member.getNameRange().getOffset();
} else if (SourceRange.isAvailable(member.getSourceRange())) {
offset = member.getSourceRange().getOffset();
}
try {
return document.getLineOfOffset(offset);
} catch (BadLocationException e) {
return null;
}
}
示例2: getLineNumber
import org.eclipse.jdt.core.IMember; //导入方法依赖的package包/类
private LinePosition getLineNumber(IMember member, Bookmark bookmark, IProgressMonitor monitor) {
Integer estimatedLineNumber = getEstimatedLineNumber(member, bookmark);
Integer lineNumber = estimatedLineNumber;
Integer lineOffset = null;
String lineContent = bookmark.getPropertyValue(TextEditorBookmarkProperties.PROP_LINE_CONTENT);
try {
ITypeRoot typeRoot = member.getTypeRoot();
if (typeRoot.getBuffer() == null) {
return null;
}
Document document = new Document(typeRoot.getBuffer().getContents());
if (lineContent != null) {
DocumentFuzzySearcher searcher = new DocumentFuzzySearcher(document);
int foundLineNumber = searcher.findLineNumber(getRegion(member.getSourceRange()),
estimatedLineNumber == null ? -1 : estimatedLineNumber, lineContent, monitor);
lineNumber = foundLineNumber == -1 ? estimatedLineNumber : foundLineNumber;
}
if (lineNumber == null) {
return null;
}
lineOffset = getLineOffset(document, lineNumber);
if (lineOffset == null) {
return null;
}
return new LinePosition(lineNumber, lineOffset);
} catch (JavaModelException e) {
return null;
}
}