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


Java ITextViewer.getDocument方法代码示例

本文整理汇总了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]);
}
 
开发者ID:angelozerr,项目名称:codelens-eclipse,代码行数:23,代码来源:ClassReferencesCodeLensProvider.java

示例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$
    }
}
 
开发者ID:pgcodekeeper,项目名称:pgcodekeeper,代码行数:27,代码来源:SQLEditorTemplateAssistProcessor.java

示例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());
}
 
开发者ID:sebez,项目名称:vertigo-chroma-kspplugin,代码行数:26,代码来源:KspTextHover.java

示例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;
}
 
开发者ID:angelozerr,项目名称:ec4e,代码行数:19,代码来源:EditorConfigCompletionProposal.java

示例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]);
}
 
开发者ID:awltech,项目名称:eclipse-asciidoctools,代码行数:25,代码来源:AsciidocContentAssistProcessor.java

示例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;
		}
	}
 
开发者ID:Imhotup,项目名称:LibertyEiffel-Eclipse-Plugin,代码行数:18,代码来源:EiffelContentAssistantProcessor.java

示例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)";
}
 
开发者ID:nextinterfaces,项目名称:http4e,代码行数:26,代码来源:MyTextHover.java

示例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;
   }
}
 
开发者ID:nextinterfaces,项目名称:http4e,代码行数:26,代码来源:Ch5CompletionEditor.java

示例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$
	}
}
 
开发者ID:curiosag,项目名称:ftc,代码行数:30,代码来源:TweakedTemplateCompletionProcessor.java

示例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];
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:10,代码来源:JSDocContentAssistProcessor.java

示例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);
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:25,代码来源:N4JSHyperlinkDetector.java

示例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 "";
}
 
开发者ID:de-jcup,项目名称:eclipse-bash-editor,代码行数:30,代码来源:BashTextHover.java

示例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;
}
 
开发者ID:angelozerr,项目名称:codelens-eclipse,代码行数:15,代码来源:ClassReferencesCodeLensProvider.java

示例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;
}
 
开发者ID:angelozerr,项目名称:codelens-eclipse,代码行数:15,代码来源:ClassImplementationsCodeLensProvider.java


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