本文整理匯總了Java中org.eclipse.jface.text.provisional.codelens.ICodeLens類的典型用法代碼示例。如果您正苦於以下問題:Java ICodeLens類的具體用法?Java ICodeLens怎麽用?Java ICodeLens使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ICodeLens類屬於org.eclipse.jface.text.provisional.codelens包,在下文中一共展示了ICodeLens類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: provideSyncCodeLenses
import org.eclipse.jface.text.provisional.codelens.ICodeLens; //導入依賴的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]);
}
示例2: resolveCodeLens
import org.eclipse.jface.text.provisional.codelens.ICodeLens; //導入依賴的package包/類
@Override
public CompletableFuture<ICodeLens> resolveCodeLens(ICodeLensContext context, ICodeLens codeLens,
IProgressMonitor monitor) {
ITextEditor textEditor = ((IEditorCodeLensContext) context).getTextEditor();
LSPDocumentInfo info = null;
Collection<LSPDocumentInfo> infos = LanguageServiceAccessor.getLSPDocumentInfosFor(
LSPEclipseUtils.getDocument((ITextEditor) textEditor),
capabilities -> capabilities.getCodeLensProvider() != null
&& capabilities.getCodeLensProvider().isResolveProvider());
if (!infos.isEmpty()) {
info = infos.iterator().next();
} else {
info = null;
}
if (info != null) {
LSPCodeLens lscl = ((LSPCodeLens) codeLens);
CodeLens unresolved = lscl.getCl();
return info.getLanguageClient().getTextDocumentService().resolveCodeLens(unresolved).thenApply(resolved -> {
lscl.update(resolved);
return lscl;
});
}
return null;
}
示例3: resolveSyncCodeLens
import org.eclipse.jface.text.provisional.codelens.ICodeLens; //導入依賴的package包/類
@Override
protected ICodeLens resolveSyncCodeLens(ICodeLensContext context, ICodeLens codeLens, IProgressMonitor monitor) {
ITextEditor textEditor = ((IEditorCodeLensContext) context).getTextEditor();
IFile file = EditorUtils.getFile(textEditor);
if (file == null) {
return null;
}
EditorConfigCodeLens cl = (EditorConfigCodeLens) codeLens;
CountSectionPatternVisitor visitor = new CountSectionPatternVisitor(cl.getSection());
try {
file.getParent().accept(visitor, IResource.NONE);
cl.update(visitor.getNbFiles() + " files match");
} catch (CoreException e) {
cl.update(e.getMessage());
}
return cl;
}
示例4: getText
import org.eclipse.jface.text.provisional.codelens.ICodeLens; //導入依賴的package包/類
public String getText(GC gc, int x) {
hoveredCodeLens = null;
hoveredCodeLensStartX = null;
hoveredCodeLensEndX = null;
if (resolvedSymbols == null || resolvedSymbols.size() < 1) {
return "no command";
} else {
StringBuilder text = new StringBuilder();
int i = 0;
boolean hasHover = hover != null;
for (ICodeLens codeLens : resolvedSymbols) {
if (i > 0) {
text.append(" | ");
}
Integer startX = null;
if (hasHover && hoveredCodeLens == null) {
startX = gc.textExtent(text.toString()).x + x;
}
text.append(codeLens.getCommand().getTitle());
if (hasHover && hoveredCodeLens == null) {
int endX = gc.textExtent(text.toString()).x + x;
if (hover.x < endX) {
hoveredCodeLensStartX = startX;
hoveredCodeLensEndX = endX;
hoveredCodeLens = codeLens;
}
}
i++;
}
return text.toString();
}
}
示例5: collectCodeLenses
import org.eclipse.jface.text.provisional.codelens.ICodeLens; //導入依賴的package包/類
private void collectCodeLenses(ITypeRoot unit, IJavaElement[] elements, List<ICodeLens> lenses,
IProgressMonitor monitor) throws JavaModelException {
for (IJavaElement element : elements) {
if (monitor.isCanceled()) {
return;
}
if (element.getElementType() == IJavaElement.TYPE) {
collectCodeLenses(unit, ((IType) element).getChildren(), lenses, monitor);
} else if (element.getElementType() != IJavaElement.METHOD || JDTUtils.isHiddenGeneratedElement(element)) {
continue;
}
// if (preferenceManager.getPreferences().isReferencesCodeLensEnabled()) {
ICodeLens lens = getCodeLens(REFERENCES_TYPE, element, unit);
lenses.add(lens);
// }
// if (preferenceManager.getPreferences().isImplementationsCodeLensEnabled() &&
// element instanceof IType) {
if (element instanceof IType) {
IType type = (IType) element;
if (type.isInterface() || Flags.isAbstract(type.getFlags())) {
lens = getCodeLens(IMPLEMENTATION_TYPE, element, unit);
lenses.add(lens);
}
}
}
}
示例6: getCodeLens
import org.eclipse.jface.text.provisional.codelens.ICodeLens; //導入依賴的package包/類
private ICodeLens getCodeLens(String type, IJavaElement element, ITypeRoot unit) throws JavaModelException {
ISourceRange r = ((ISourceReference) element).getNameRange();
final Range range = JDTUtils.toRange(unit, r.getOffset(), r.getLength());
ICodeLens lens = new JavaCodeLens(range, type);
// String uri = ResourceUtils.toClientUri(JDTUtils.getFileURI(unit));
// lens.setData(Arrays.asList(uri, range.getStart(), type));
return lens;
}
示例7: resolveSyncCodeLens
import org.eclipse.jface.text.provisional.codelens.ICodeLens; //導入依賴的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;
}
示例8: provideSyncCodeLenses
import org.eclipse.jface.text.provisional.codelens.ICodeLens; //導入依賴的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++) {
updateCodeLens(i, document, "class ", lenses);
updateCodeLens(i, document, "interface ", lenses);
}
return lenses.toArray(new ICodeLens[0]);
}
示例9: updateCodeLens
import org.eclipse.jface.text.provisional.codelens.ICodeLens; //導入依賴的package包/類
private void updateCodeLens(int lineIndex, IDocument document, String token, List<ICodeLens> lenses) {
String line = getLineText(document, lineIndex, false);
int index = line.indexOf(token);
if (index != -1) {
String className = line.substring(index + token.length(), line.length());
index = className.indexOf(" ");
if (index != -1) {
className = className.substring(0, index);
}
if (className.length() > 0) {
lenses.add(new ClassCodeLens(className, lineIndex + 1));
}
}
}
示例10: resolveSyncCodeLens
import org.eclipse.jface.text.provisional.codelens.ICodeLens; //導入依賴的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;
}
示例11: provideSyncCodeLenses
import org.eclipse.jface.text.provisional.codelens.ICodeLens; //導入依賴的package包/類
@Override
protected ICodeLens[] provideSyncCodeLenses(ICodeLensContext context, IProgressMonitor monitor) {
ITextEditor textEditor = ((IEditorCodeLensContext) context).getTextEditor();
IFile file = EditorUtils.getFile(textEditor);
if (file == null) {
return null;
}
IDocument document = context.getViewer().getDocument();
IDEEditorConfigManager editorConfigManager = IDEEditorConfigManager.getInstance();
final ErrorHandler errorHandler = ErrorHandler.IGNORING;
SectionsHandler handler = new SectionsHandler(editorConfigManager.getRegistry(), editorConfigManager.getVersion());
EditorConfigParser parser = EditorConfigParser.default_();
try {
parser.parse(Resources.ofString(file.getFullPath().toString(), document.get()), handler, errorHandler );
} catch (IOException e) {
/* Will not happen with Resources.ofString() */
throw new RuntimeException(e);
}
List<Section> sections = handler.getEditorConfig().getSections();
List<Location> sectionLocations = handler.getSectionLocations();
ICodeLens[] lenses = new ICodeLens[sections.size()];
for (int i = 0; i < lenses.length; i++) {
lenses[i] = new EditorConfigCodeLens(sections.get(i), sectionLocations.get(i), file);
}
return lenses;
}
示例12: provideCodeLenses
import org.eclipse.jface.text.provisional.codelens.ICodeLens; //導入依賴的package包/類
@Override
public CompletableFuture<ICodeLens[]> provideCodeLenses(ICodeLensContext context, IProgressMonitor monitor) {
ITextViewer textViewer = context.getViewer();
IResource resource = TypeScriptResourceUtil.getFile(textViewer.getDocument());
if (resource == null) {
return null;
}
if (TypeScriptResourceUtil.canConsumeTsserver(resource)) {
// the project of the resource has typescript nature, execute
// typescript
// navtree.
try {
IProject project = resource.getProject();
IIDETypeScriptProject tsProject = TypeScriptResourceUtil.getTypeScriptProject(project);
IDocument document = textViewer.getDocument();
IIDETypeScriptFile tsFile = tsProject.openFile(resource, document);
return tsProject.getClient().navtree(tsFile.getName(), tsFile).thenApply(tree -> {
List<Range> referenceableSpans = new ArrayList<>();
if (tree != null && tree.hasChildItems()) {
tree.getChildItems().forEach(item -> this.walkNavTree(tsFile, item, null, referenceableSpans));
}
return toCodeLenses(referenceableSpans, tsFile);
});
} catch (Exception e) {
TypeScriptUIPlugin.log("Error while TypeScript codelens", e);
}
}
return null;
}
示例13: resolveCodeLens
import org.eclipse.jface.text.provisional.codelens.ICodeLens; //導入依賴的package包/類
@Override
public CompletableFuture<ICodeLens> resolveCodeLens(ICodeLensContext context, ICodeLens cl, IProgressMonitor monitor) {
ImplementationsCodeLens codeLens = (ImplementationsCodeLens) cl;
// const codeLens = inputCodeLens as ReferencesCodeLens;
// const args: Proto.FileLocationRequestArgs = {
// file: codeLens.file,
// line: codeLens.range.start.line + 1,
// offset: codeLens.range.start.character + 1
// };
IIDETypeScriptFile tsFile = codeLens.getTsFile();
try {
int position = tsFile.getPosition(codeLens.getRange().startLineNumber, codeLens.getRange().startColumn);
return tsFile.implementation(position).thenApply(refs -> {
int refCount = refs.size();
if (refCount == 1) {
codeLens.setCommand(new Command("1 implementation", "implementation"));
} else {
codeLens.setCommand(
new Command(MessageFormat.format("{0} implementations", refCount), "implementation"));
}
return codeLens;
});
} catch (Exception e) {
codeLens.setCommand(new Command("Could not determine implementations", null));
}
return null;
}
示例14: updateCommands
import org.eclipse.jface.text.provisional.codelens.ICodeLens; //導入依賴的package包/類
public void updateCommands(List<ICodeLens> resolvedSymbols) {
this.resolvedSymbols = resolvedSymbols;
}
示例15: updateCommands
import org.eclipse.jface.text.provisional.codelens.ICodeLens; //導入依賴的package包/類
public void updateCommands(List<ICodeLens> resolvedSymbols) {
zone.updateCommands(resolvedSymbols);
}