本文整理汇总了Java中org.eclipse.jface.text.IDocument类的典型用法代码示例。如果您正苦于以下问题:Java IDocument类的具体用法?Java IDocument怎么用?Java IDocument使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IDocument类属于org.eclipse.jface.text包,在下文中一共展示了IDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: computeCompletionProposals
import org.eclipse.jface.text.IDocument; //导入依赖的package包/类
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
IDocument document = viewer.getDocument();
if (document == null) {
return null;
}
String source = document.get();
Set<String> words = simpleWordCompletion.calculate(source, offset);
ICompletionProposal[] result = new ICompletionProposal[words.size()];
int i = 0;
for (String word : words) {
result[i++] = new SimpleWordProposal(document, offset, word);
}
return result;
}
开发者ID:de-jcup,项目名称:eclipse-batch-editor,代码行数:19,代码来源:BatchEditorSimpleWordContentAssistProcessor.java
示例2: apply
import org.eclipse.jface.text.IDocument; //导入依赖的package包/类
@Override
public void apply(IDocument document) {
// the proposal shall enter always a space after applyment...
String proposal = word;
if (isAddingSpaceAtEnd()) {
proposal += " ";
}
int zeroOffset = offset - textBefore.length();
try {
document.replace(zeroOffset, textBefore.length(), proposal);
nextSelection = zeroOffset + proposal.length();
} catch (BadLocationException e) {
BatchEditorUtil.logError("Not able to replace by proposal:" + word +", zero offset:"+zeroOffset+", textBefore:"+textBefore, e);
}
}
开发者ID:de-jcup,项目名称:eclipse-batch-editor,代码行数:17,代码来源:BatchEditorSimpleWordContentAssistProcessor.java
示例3: getPartitionsInfoByType
import org.eclipse.jface.text.IDocument; //导入依赖的package包/类
public static HashMap<String, IRegion> getPartitionsInfoByType(IDocument document,
String partitionType) {
HashMap<String, IRegion> lines = new HashMap<String, IRegion>();
final Scanner scanner = new Scanner(document.get());
int lineNumber = 0;
try {
while (scanner.hasNextLine()) {
final String line = scanner.nextLine();
final int offset = document.getLineOffset(lineNumber);
if (document.getPartition(offset).getType().equals(partitionType)) {
lines.put(line, document.getLineInformation(lineNumber));
}
lineNumber++;
}
} catch (BadLocationException e) {
e.printStackTrace();
} finally {
if (scanner != null)
scanner.close();
}
return lines;
}
示例4: apply
import org.eclipse.jface.text.IDocument; //导入依赖的package包/类
@Override
public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) {
initIfNeeded();
IDocument document = viewer.getDocument();
if (fTextViewer == null) {
fTextViewer = viewer;
}
// don't eat if not in preferences, XOR with modifier key 1 (Ctrl)
// but: if there is a selection, replace it!
Point selection = viewer.getSelectedRange();
fToggleEating = (stateMask & SWT.MOD1) != 0;
int newLength = selection.x + selection.y - getReplacementOffset();
if ((insertCompletion() ^ fToggleEating) && newLength >= 0) {
setReplacementLength(newLength);
}
apply(document, trigger, offset);
fToggleEating = false;
}
示例5: getDocument
import org.eclipse.jface.text.IDocument; //导入依赖的package包/类
@Override
public IDocument getDocument(Object element) {
IDocument document = super.getDocument(element);
if (document == null) {
return null;
}
IDocumentPartitioner formerPartitioner = document.getDocumentPartitioner();
if (formerPartitioner instanceof BatchPartitioner) {
return document;
}
/* installation necessary */
IDocumentPartitioner partitioner = BatchPartionerFactory.create();
partitioner.connect(document);
document.setDocumentPartitioner(partitioner);
return document;
}
示例6: moveTo
import org.eclipse.jface.text.IDocument; //导入依赖的package包/类
public void moveTo(String handlerName) {
IEditorPart editor = PlatformUI
.getWorkbench()
.getActiveWorkbenchWindow()
.getActivePage()
.getActiveEditor();
if (editor instanceof JscriptTransactionEditor) {
JscriptTransactionEditor myEditor = (JscriptTransactionEditor) editor;
MyJScriptEditor jsEditor = myEditor.getEditor();
IDocumentProvider provider = jsEditor.getDocumentProvider();
IDocument document = provider.getDocument(editor.getEditorInput());
String content = document.get();
int index = content.indexOf(handlerName);
jsEditor.selectAndReveal(index, handlerName.length());
}
}
示例7: getLineByOffset
import org.eclipse.jface.text.IDocument; //导入依赖的package包/类
public static String getLineByOffset(IDocument document, int offset) {
final Scanner scanner = new Scanner(document.get());
int lineNumber = 0;
try {
while (scanner.hasNextLine()) {
final String line = scanner.nextLine();
if (lineNumber == document.getLineOfOffset(offset)) {
return line;
}
lineNumber++;
}
} catch (BadLocationException e) {
e.printStackTrace();
} finally {
if (scanner != null)
scanner.close();
}
return "";
}
示例8: validate
import org.eclipse.jface.text.IDocument; //导入依赖的package包/类
@Override
public boolean validate(IDocument document, int offset, DocumentEvent event) {
try {
String content = document.get(fReplacementPosition.getOffset(), offset - fReplacementPosition.getOffset());
if (fReplacementString.startsWith(content)) {
return true;
} else if (fReplacementString.length() > 0) {
char c = fReplacementString.charAt(0);
if ((c == '"' || c == '\'') && fReplacementString.startsWith(c + content)) {
return true;
}
}
} catch (BadLocationException e) {
// ignore concurrently modified document
}
return false;
}
示例9: getOffsetAdjustment
import org.eclipse.jface.text.IDocument; //导入依赖的package包/类
protected int getOffsetAdjustment(IDocument document, int offset, int length) {
if (length == 0 || Math.abs(length) > 1)
return 0;
try {
if (length < 0) {
if (isOpeningBracket(document.getChar(offset))) {
return 1;
}
} else {
if (isClosingBracket(document.getChar(offset - 1))) {
return -1;
}
}
} catch (BadLocationException e) {
// do nothing
}
return 0;
}
示例10: apply
import org.eclipse.jface.text.IDocument; //导入依赖的package包/类
@Override
public void apply(IDocument document) {
// the proposal shall enter always a space after applyment...
String proposal = word;
if (isAddingSpaceAtEnd()) {
proposal += " ";
}
int zeroOffset = offset - textBefore.length();
try {
document.replace(zeroOffset, textBefore.length(), proposal);
nextSelection = zeroOffset + proposal.length();
} catch (BadLocationException e) {
BashEditorUtil.logError("Not able to replace by proposal:" + word +", zero offset:"+zeroOffset+", textBefore:"+textBefore, e);
}
}
示例11: getDocument
import org.eclipse.jface.text.IDocument; //导入依赖的package包/类
@Override
public IDocument getDocument(Object element) {
IDocument document = super.getDocument(element);
if (document == null) {
return null;
}
IDocumentPartitioner formerPartitioner = document.getDocumentPartitioner();
if (formerPartitioner instanceof BashPartitioner) {
return document;
}
/* installation necessary */
IDocumentPartitioner partitioner = BashPartionerFactory.create();
partitioner.connect(document);
document.setDocumentPartitioner(partitioner);
return document;
}
示例12: paint
import org.eclipse.jface.text.IDocument; //导入依赖的package包/类
@Override
public void paint(int reason) {
IDocument document = textViewer.getDocument();
if (document == null) {
deactivate(false);
return;
}
if (!fIsActive) {
StyledText styledText = textViewer.getTextWidget();
fIsActive = true;
styledText.addPaintListener(this);
redrawAll();
} else if (reason == CONFIGURATION || reason == INTERNAL) {
redrawAll();
}
}
示例13: provideSyncCodeLenses
import org.eclipse.jface.text.IDocument; //导入依赖的package包/类
@Override
public ICodeLens[] provideSyncCodeLenses(ICodeLensContext context, IProgressMonitor monitor) {
ITextViewer textViewer = context.getViewer();
IDocument document = textViewer.getDocument();
List<ICodeLens> lenses = new ArrayList<>();
int lineCount = document.getNumberOfLines();
for (int i = 0; i < lineCount; i++) {
String line = getLineText(document, i, false);
int index = line.indexOf("class ");
if (index != -1) {
String className = line.substring(index + "class ".length(), line.length());
index = className.indexOf(" ");
if (index != -1) {
className = className.substring(0, index);
}
if (className.length() > 0) {
lenses.add(new ClassCodeLens(className, i + 1));
}
}
}
return lenses.toArray(new ICodeLens[0]);
}
示例14: save
import org.eclipse.jface.text.IDocument; //导入依赖的package包/类
/**
* Save the AST int he Compilation Unit
*
* @param testInterface
* @param rewrite
* @throws CoreException
*/
public static void save(CompilationUnit unit, ASTRewrite rewrite) throws CoreException {
ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
IPath path = unit.getJavaElement().getPath();
try {
bufferManager.connect(path, null);
ITextFileBuffer textFileBuffer = bufferManager.getTextFileBuffer(path);
IDocument document = textFileBuffer.getDocument();
TextEdit edit = rewrite.rewriteAST(document, null);
edit.apply(document);
textFileBuffer.commit(null /* ProgressMonitor */, true /* Overwrite */);
} catch (Exception e) {
ResourceManager.logException(e);
} finally {
// disconnect the path
bufferManager.disconnect(path, null);
}
}
示例15: getLineInformationOfRegion
import org.eclipse.jface.text.IDocument; //导入依赖的package包/类
/**
* Similar to {@link IDocument#getLineInformationOfOffset(int)}, but the client can provide a text region instead of
* only an offset. If the given region spans multiple lines, all affected lines will be returned, i.e. entire line
* containing beginning of region, all lines contained in the region, and entire line containing the end of the
* region.
*/
public static IRegion getLineInformationOfRegion(IDocument doc, int offset, int length,
boolean includeLineDelimiterOfLastLine) throws BadLocationException {
// get the line containing the beginning of the given text region
final int firstLineNo = doc.getLineOfOffset(offset);
// get the line containing the end of the given text region
// (may be the same line if removal does not span multiple lines)
final int lastLineNo = doc.getLineOfOffset(offset + length);
// compute result
final int startOffset = doc.getLineOffset(firstLineNo);
final int endOffset = doc.getLineOffset(lastLineNo) + (includeLineDelimiterOfLastLine ?
doc.getLineLength(lastLineNo) // includes line delimiters!
: doc.getLineInformation(lastLineNo).getLength()); // does *not* include line delimiters!
return new Region(
startOffset,
endOffset - startOffset);
}