Search in sources :

Example 1 with IDecompiler

use of org.eclipse.jdt.ls.core.internal.IDecompiler in project eclipse.jdt.ls by eclipse.

the class ContentProviderManager method getContent.

private String getContent(Object source, String cacheKey, Class<? extends IContentProvider> providerType, IProgressMonitor monitor) {
    URI uri = source instanceof URI ? (URI) source : null;
    List<ContentProviderDescriptor> matches = findMatchingProviders(uri);
    if (monitor.isCanceled()) {
        return EMPTY_CONTENT;
    }
    int previousPriority = -1;
    for (ContentProviderDescriptor match : matches) {
        IContentProvider contentProvider = match.getContentProvider();
        if (!providerType.isInstance(contentProvider)) {
            JavaLanguageServerPlugin.logError("Unable to load " + providerType.getSimpleName() + " class for " + match.id);
            continue;
        }
        if (monitor.isCanceled()) {
            return EMPTY_CONTENT;
        }
        if (previousPriority == match.priority) {
            requestPreferredProvider(match.priority, matches);
        }
        try {
            contentProvider.setPreferences(preferenceManager.getPreferences());
            String content = null;
            if (uri != null) {
                content = contentProvider.getContent(uri, monitor);
            } else if (source instanceof IClassFile) {
                content = ((IDecompiler) contentProvider).getSource((IClassFile) source, monitor);
            }
            if (monitor.isCanceled()) {
                return EMPTY_CONTENT;
            } else if (content != null) {
                return content;
            }
        } catch (Exception e) {
            JavaLanguageServerPlugin.logException("Error getting content via " + match.id, e);
        }
        previousPriority = match.priority;
    }
    return EMPTY_CONTENT;
}
Also used : IClassFile(org.eclipse.jdt.core.IClassFile) IContentProvider(org.eclipse.jdt.ls.core.internal.IContentProvider) IDecompiler(org.eclipse.jdt.ls.core.internal.IDecompiler) URI(java.net.URI) CoreException(org.eclipse.core.runtime.CoreException)

Aggregations

URI (java.net.URI)1 CoreException (org.eclipse.core.runtime.CoreException)1 IClassFile (org.eclipse.jdt.core.IClassFile)1 IContentProvider (org.eclipse.jdt.ls.core.internal.IContentProvider)1 IDecompiler (org.eclipse.jdt.ls.core.internal.IDecompiler)1