本文整理汇总了Java中org.eclipse.jface.text.IDocument.getLineInformationOfOffset方法的典型用法代码示例。如果您正苦于以下问题:Java IDocument.getLineInformationOfOffset方法的具体用法?Java IDocument.getLineInformationOfOffset怎么用?Java IDocument.getLineInformationOfOffset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jface.text.IDocument
的用法示例。
在下文中一共展示了IDocument.getLineInformationOfOffset方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: computeCompletionProposals
import org.eclipse.jface.text.IDocument; //导入方法依赖的package包/类
@Override
public ICompletionProposal[] computeCompletionProposals(final ITextViewer viewer,
final int offset) {
final List<ICompletionProposal> proposals = new ArrayList<>();
final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
try {
allFiles.clear();
allEcoreFiles.clear();
findAllEMFFiles(root);
findAllXMIFiles(root);
} catch (final Exception e) {
e.printStackTrace();
return null;
}
final IDocument document = viewer.getDocument();
try {
IRegion lineInfo = document.getLineInformationOfOffset(offset);
String line = document.get(lineInfo.getOffset(), lineInfo.getLength());
int activationIndex = line.indexOf(activationChar);
if (activationIndex != -1) {
String prefix = line.substring(line.indexOf("@") + 1);
String type = document.getPartition(offset - 1).getType();
int replacementOffset = offset - prefix.length();
addProposals(proposals, prefix, replacementOffset, type);
}
} catch (BadLocationException e1) {
e1.printStackTrace();
}
final ICompletionProposal[] result = new ICompletionProposal[proposals.size()];
proposals.toArray(result);
return result;
}
示例2: getLine
import org.eclipse.jface.text.IDocument; //导入方法依赖的package包/类
/**
* Returns the line containing the given offset without any line delimiters. The offset need not point to the
* beginning of the line.
*/
public static String getLine(IDocument doc, int offset) throws BadLocationException {
final IRegion reg = doc.getLineInformationOfOffset(offset);
return doc.get(reg.getOffset(), reg.getLength());
}