本文整理汇总了Java中org.eclipse.jface.text.ITextViewer类的典型用法代码示例。如果您正苦于以下问题:Java ITextViewer类的具体用法?Java ITextViewer怎么用?Java ITextViewer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ITextViewer类属于org.eclipse.jface.text包,在下文中一共展示了ITextViewer类的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: editorOpened
import org.eclipse.jface.text.ITextViewer; //导入依赖的package包/类
private void editorOpened(IEditorPart part) {
if (part instanceof ITextEditor) {
ITextViewer textViewer = (ITextViewer) part.getAdapter(ITextOperationTarget.class);
if (textViewer != null) {
ICodeLensController controller = codeLensControllers.get(part);
if (controller == null) {
ITextEditor textEditor = (ITextEditor) part;
controller = CodeLensControllerRegistry.getInstance().create(textEditor);
if (controller != null) {
controller.setProgressMonitor(new NullProgressMonitor());
codeLensControllers.put(textEditor, controller);
//controller.install();
}
}
}
}
}
示例4: 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$
}
}
示例5: detectHyperlinks
import org.eclipse.jface.text.ITextViewer; //导入依赖的package包/类
@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region,
boolean canShowMultipleHyperlinks) {
SQLEditor editor = getAdapter(SQLEditor.class);
PgDbParser parser = editor.getParser();
int offset = region.getOffset();
List<PgObjLocation> refs = parser.getObjsForEditor(editor.getEditorInput());
for (PgObjLocation obj : refs) {
if (offset > obj.getOffset()
&& offset < (obj.getOffset() + obj.getObjLength())) {
IHyperlink[] links = parser.getDefinitionsForObj(obj)
.map(def -> new SQLEditorHyperLink(
new Region(def.getOffset(), def.getObjLength()),
new Region(obj.getOffset(), obj.getObjLength()),
obj.getObjName(), def.getFilePath(), def.getLineNumber()))
.toArray(IHyperlink[]::new);
if (links.length != 0) {
return links;
}
}
}
return null;
}
示例6: getHoverRegion
import org.eclipse.jface.text.ITextViewer; //导入依赖的package包/类
@Override
public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
PgDbParser parser = editor.getParser();
List<PgObjLocation> refs = parser.getObjsForEditor(editor.getEditorInput());
for (PgObjLocation obj : refs) {
if (offset > obj.getOffset()
&& offset < (obj.getOffset() + obj.getObjLength())) {
Optional<PgObjLocation> loc = parser.getDefinitionsForObj(obj).findAny();
if (loc.isPresent()) {
SQLEditorMyRegion region = new SQLEditorMyRegion(obj.getOffset(), obj.getObjLength());
region.setComment(loc.get().getComment());
return region;
}
}
}
return new Region(offset, 0);
}
示例7: createContext
import org.eclipse.jface.text.ITextViewer; //导入依赖的package包/类
@Override
protected ContentAssistInvocationContext createContext(ITextViewer viewer, int offset)
{
ICompilationUnit compilationUnit = ((SourceViewer) viewer).getCompilatioUnit();
if (compilationUnit != null) {
CompletionProposalCollector completionProposalCollector = new CompletionProposalCollector(compilationUnit);
JavaContentAssistInvocationContext invocContext = new JavaContentAssistInvocationContext(viewer, offset,
new NullEditorPart());
completionProposalCollector.setInvocationContext(invocContext);
return invocContext;
} else {
return null;
}
}
示例8: 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());
}
示例9: getHoverInfo
import org.eclipse.jface.text.ITextViewer; //导入依赖的package包/类
@Override
public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
/* Extrait le mot de la région. */
String currentWord = getSelectedWord(textViewer, hoverRegion);
/* Extrait un nom de DTO : Calcul le nom en PascalCase */
String javaName = StringUtils.toPascalCase(currentWord);
/* Cherche le fichier Java du DTO. */
DtoFile dtoFile = DtoManager.getInstance().findDtoFile(javaName);
if (dtoFile == null) {
return null;
}
/* Renvoie le nom Java. Le texte complet sera généré par KspInformationPresenter. */
return javaName;
}
示例10: install
import org.eclipse.jface.text.ITextViewer; //导入依赖的package包/类
@Override
public void install(ITextViewer textViewer) {
if (fStrategies == null)
return;
for (int i = 0; i < fStrategies.length; i++) {
if (fStrategies[i] instanceof IReconciler) {
IReconciler extension = (IReconciler) fStrategies[i];
try {
extension.install(textViewer);
} catch (Exception e) {
}
}
}
}
示例11: 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;
}
示例12: hasProblem
import org.eclipse.jface.text.ITextViewer; //导入依赖的package包/类
/***
* Returns true if it exists a marker annotation in the given offset and false
* otherwise.
*
* @param textViewer
* @param offset
* @return true if it exists a marker annotation in the given offset and false
* otherwise.
*/
private static boolean hasProblem(ITextViewer textViewer, int offset) {
if (!(textViewer instanceof ISourceViewer)) {
return false;
}
IAnnotationModel annotationModel = ((ISourceViewer) textViewer).getAnnotationModel();
Iterator<Annotation> iter = (annotationModel instanceof IAnnotationModelExtension2)
? ((IAnnotationModelExtension2) annotationModel).getAnnotationIterator(offset, 1, true, true)
: annotationModel.getAnnotationIterator();
while (iter.hasNext()) {
Annotation ann = iter.next();
if (ann instanceof MarkerAnnotation) {
return true;
}
}
return false;
}
示例13: getTMPresentationReconciler
import org.eclipse.jface.text.ITextViewer; //导入依赖的package包/类
/**
* Returns the {@link TMPresentationReconciler} of the given text viewer and
* null otherwise.
*
* @param textViewer
* @return the {@link TMPresentationReconciler} of the given text viewer and
* null otherwise.
*/
public static TMPresentationReconciler getTMPresentationReconciler(ITextViewer textViewer) {
try {
Field field = SourceViewer.class.getDeclaredField("fPresentationReconciler");
if (field != null) {
field.setAccessible(true);
IPresentationReconciler presentationReconciler = (IPresentationReconciler) field.get(textViewer);
return presentationReconciler instanceof TMPresentationReconciler
? (TMPresentationReconciler) presentationReconciler
: null;
}
} catch (Exception e) {
}
return null;
}
示例14: getLanguageElementAt
import org.eclipse.jface.text.ITextViewer; //导入依赖的package包/类
/**
* Get language at given offset
*
* @param offset
* @param textViewer
* @return language element or <code>null</code>
*/
protected HoverDataRegion getLanguageElementAt(int offset, ITextViewer textViewer) {
IContentAssistant assist = gradleSourceViewerConfiguration.getContentAssistant(sourceViewer);
if (assist == null) {
return null;
}
IContentAssistProcessor processor = assist.getContentAssistProcessor(contentType);
if (!(processor instanceof GradleContentAssistProcessor)) {
return null;
}
GradleContentAssistProcessor gprocessor = (GradleContentAssistProcessor) processor;
String allText = textViewer.getDocument().get();
RelevantCodeCutter codeCutter = this.codeCutter;
Model model = gprocessor.getModel();
GradleFileType fileType = gradleSourceViewerConfiguration.getFileType();
GradleLanguageElementEstimater estimator = gprocessor.getEstimator();
HoverData data = hoverSupport.caclulateHoverData(allText, offset, codeCutter, model, fileType, estimator);
if (data == null) {
return null;
}
return new HoverDataRegion(data);
}
示例15: 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]);
}