本文整理汇总了Java中org.eclipse.jface.text.ITextViewer.getDocument方法的典型用法代码示例。如果您正苦于以下问题:Java ITextViewer.getDocument方法的具体用法?Java ITextViewer.getDocument怎么用?Java ITextViewer.getDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jface.text.ITextViewer
的用法示例。
在下文中一共展示了ITextViewer.getDocument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: computeCompletionProposals
import org.eclipse.jface.text.ITextViewer; //导入方法依赖的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: provideSyncCodeLenses
import org.eclipse.jface.text.ITextViewer; //导入方法依赖的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]);
}
示例3: extractPrefix
import org.eclipse.jface.text.ITextViewer; //导入方法依赖的package包/类
@Override
protected String extractPrefix(ITextViewer viewer, int offset) {
int i = offset;
IDocument document = viewer.getDocument();
if (i > document.getLength()) {
return ""; //$NON-NLS-1$
}
try {
while (i > 0) {
char ch = document.getChar(i - 1);
if (!PgDiffUtils.isValidIdChar(ch)) {
break;
}
i--;
}
if (i > 0) {
int j = i;
if (document.getChar(j - 1) == '<') {
i--;
}
}
return document.get(i, offset - i);
} catch (BadLocationException e) {
return ""; //$NON-NLS-1$
}
}
示例4: getHoverRegion
import org.eclipse.jface.text.ITextViewer; //导入方法依赖的package包/类
@Override
public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
IDocument document = textViewer.getDocument();
/* Vérifie qu'on est dans une String de KSP */
boolean isSqlString = DocumentUtils.isContentType(document, offset, KspRegionType.STRING);
if (!isSqlString) {
return null;
}
/* Extrait le mot courant. */
ITextSelection selection = new TextSelection(document, offset, 0);
ITextSelection currentWordSelection = DocumentUtils.findCurrentWord(document, selection, WordSelectionType.SNAKE_CASE);
if (currentWordSelection == null) {
return null;
}
String currentWord = currentWordSelection.getText();
if (currentWord == null) {
return null;
}
/* Renvoie la région du mot. */
return new Region(currentWordSelection.getOffset(), currentWordSelection.getLength());
}
示例5: apply
import org.eclipse.jface.text.ITextViewer; //导入方法依赖的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;
}
示例6: computeCompletionProposals
import org.eclipse.jface.text.ITextViewer; //导入方法依赖的package包/类
@Override
public ComparableCompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
List<ComparableCompletionProposal> results = new ArrayList<ComparableCompletionProposal>();
IDocument document = viewer.getDocument();
if (viewer.getSelectedRange().y == 0) {
try {
int position = getCurrentWordStart(document, offset);
String start = document.get(position, offset - position);
results.addAll(AsciidocVariablesProposals.getValidCompletionProposals(document, offset, start));
if (isCurrentLineStart(document, offset)) {
results.addAll(AsciidocBlocksAndHeadersProposals.getValidCompletionProposals(document, offset));
}
results.addAll(AsciidocAnchorsProposals.getValidCompletionProposals(document, offset, start));
results.addAll(AsciidocMacrosCompletionProposals.getValidCompletionProposals(document, offset, start));
} catch (BadLocationException e) {
e.printStackTrace();
}
} else {
}
Collections.sort(results);
return results.toArray(new ComparableCompletionProposal[0]);
}
示例7: computeCompletionProposals
import org.eclipse.jface.text.ITextViewer; //导入方法依赖的package包/类
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
try {
List<ICompletionProposal> completionProposals = new ArrayList<ICompletionProposal>();
IDocument document = viewer.getDocument();
String prefix = lastWord(document, offset);
String indent = lastIndent(document, offset);
// EiffelModel model = EiffelModel.getModel(document, null);
// model.getContentProposals(prefix, indent, offset, completionProposals);
return completionProposals.toArray(new ICompletionProposal[completionProposals.size()]);
} catch (Exception e) {
return NO_COMPLETIONS;
}
}
示例8: getHoverInfo
import org.eclipse.jface.text.ITextViewer; //导入方法依赖的package包/类
public String getHoverInfo( ITextViewer textViewer, IRegion hoverRegion){
int offset = hoverRegion.getOffset();
if (hoverRegion != null) {
try {
if (hoverRegion.getLength() > -1) {
IDocument doc = textViewer.getDocument();
// String key = textViewer.getDocument().get(offset, hoverRegion.getLength());
// ITypedRegion region = doc.getPartition(offset);
ITypedRegion partitionType = textViewer.getDocument().getPartition(offset);
IRegion reg2 = doc.getLineInformationOfOffset(offset);
String lineText = doc.get(reg2.getOffset(), reg2.getLength());
// if(BaseUtils.isEmpty(key)){
// key = BaseUtils.getKeyFromLine(lineText);
// return HAssistInfoMap.getInfo(key);
// }
String key = DocumentUtils.getKeyFromLine(lineText);
return LazyObjects.getInfoMap("Headers").getInfo(key);
}
} catch (BadLocationException x) {
}
}
return "JavaEditorMessages.getString(MyTextHover.emptySelection)";
}
示例9: computeCompletionProposals
import org.eclipse.jface.text.ITextViewer; //导入方法依赖的package包/类
public ICompletionProposal[] computeCompletionProposals( ITextViewer textViewer, int documentOffset){
IDocument document = textViewer.getDocument();
int currOffset = documentOffset - 1;
try {
String currWord = "";
char currChar;
while (currOffset > 0 && !Character.isWhitespace(currChar = document.getChar(currOffset))) {
currWord = currChar + currWord;
currOffset--;
}
List suggestions = wordTracker.suggest(currWord);
ICompletionProposal[] proposals = null;
if (suggestions.size() > 0) {
proposals = buildProposals(suggestions, currWord, documentOffset - currWord.length());
lastError = null;
}
return proposals;
} catch (BadLocationException e) {
e.printStackTrace();
lastError = e.getMessage();
return null;
}
}
示例10: extractPrefix
import org.eclipse.jface.text.ITextViewer; //导入方法依赖的package包/类
/**
* Heuristically extracts the prefix used for determining template relevance
* from the viewer's document. The default implementation returns the String from
* offset backwards that forms a java identifier.
*
* @param viewer the viewer
* @param offset offset into document
* @return the prefix to consider
* @see #getRelevance(Template, String)
*/
protected String extractPrefix(ITextViewer viewer, int offset) {
int i= offset;
IDocument document= viewer.getDocument();
if (i > document.getLength())
return ""; //$NON-NLS-1$
try {
while (i > 0) {
char ch= document.getChar(i - 1);
if (!Character.isJavaIdentifierPart(ch))
break;
i--;
}
return document.get(i, offset - i);
} catch (BadLocationException e) {
return ""; //$NON-NLS-1$
}
}
示例11: computeCompletionProposals
import org.eclipse.jface.text.ITextViewer; //导入方法依赖的package包/类
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
if (viewer instanceof XtextSourceViewer) {
IXtextDocument document = (IXtextDocument) viewer.getDocument();
return document.priorityReadOnly(createCompletionProposalComputer(viewer, offset));
}
return new ICompletionProposal[0];
}
示例12: detectHyperlinks
import org.eclipse.jface.text.ITextViewer; //导入方法依赖的package包/类
/**
* Method copied from super class with only a minor change: call to "readOnly" changed to "tryReadOnly".
*/
@Override
public IHyperlink[] detectHyperlinks(final ITextViewer textViewer, final IRegion region,
final boolean canShowMultipleHyperlinks) {
final IDocument xtextDocument = textViewer.getDocument();
if (!(xtextDocument instanceof N4JSDocument)) {
return super.detectHyperlinks(textViewer, region, canShowMultipleHyperlinks);
}
final IHyperlinkHelper helper = getHelper();
return ((N4JSDocument) xtextDocument).tryReadOnly(new IUnitOfWork<IHyperlink[], XtextResource>() {
@Override
public IHyperlink[] exec(XtextResource resource) throws Exception {
if (resource == null) {
return null;
}
if (helper instanceof ISourceViewerAware && textViewer instanceof ISourceViewer) {
((ISourceViewerAware) helper).setSourceViewer((ISourceViewer) textViewer);
}
return helper.createHyperlinksByOffset(resource, region.getOffset(), canShowMultipleHyperlinks);
}
}, null);
}
示例13: getHoverInfo
import org.eclipse.jface.text.ITextViewer; //导入方法依赖的package包/类
@Override
public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
BashEditorPreferences preferences = BashEditorPreferences.getInstance();
boolean tooltipsEnabled = preferences.getBooleanPreference(P_TOOLTIPS_ENABLED);
if (!tooltipsEnabled){
return null;
}
IDocument document = textViewer.getDocument();
if (document == null) {
return "";
}
String text = document.get();
if (text == null) {
return "";
}
int offset = hoverRegion.getOffset();
String word = SimpleStringUtils.nextWordUntilWhitespace(text, offset);
if (word.isEmpty()) {
return "";
}
for (DocumentKeyWord keyword : DocumentKeyWords.getAll()) {
if (word.equals(keyword.getText())) {
return buildHoverInfo(keyword);
}
}
return "";
}
示例14: resolveSyncCodeLens
import org.eclipse.jface.text.ITextViewer; //导入方法依赖的package包/类
@Override
public ICodeLens resolveSyncCodeLens(ICodeLensContext context, ICodeLens codeLens, IProgressMonitor monitor) {
ITextViewer textViewer = context.getViewer();
IDocument document = textViewer.getDocument();
String className = ((ClassCodeLens) codeLens).getClassName();
int refCount = 0;
int lineCount = document.getNumberOfLines();
for (int i = 0; i < lineCount; i++) {
String line = getLineText(document, i, false);
refCount += line.contains("new " + className) ? 1 : 0;
}
((ClassCodeLens) codeLens).setCommand(new Command(refCount + " references", ""));
return codeLens;
}
示例15: resolveSyncCodeLens
import org.eclipse.jface.text.ITextViewer; //导入方法依赖的package包/类
@Override
public ICodeLens resolveSyncCodeLens(ICodeLensContext context, ICodeLens codeLens, IProgressMonitor monitor) {
ITextViewer textViewer = context.getViewer();
IDocument document = textViewer.getDocument();
String className = ((ClassCodeLens) codeLens).getClassName();
int refCount = 0;
int lineCount = document.getNumberOfLines();
for (int i = 0; i < lineCount; i++) {
String line = getLineText(document, i, false);
refCount += line.contains("implements " + className) ? 1 : 0;
}
((ClassCodeLens) codeLens).setCommand(new Command(refCount + " implementation", ""));
return codeLens;
}