Search in sources :

Example 1 with ContentProviderManager

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

the class JavaLanguageServerPlugin method start.

/*
	 * (non-Javadoc)
	 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
	 */
@Override
public void start(BundleContext bundleContext) throws BackingStoreException {
    try {
        Platform.getBundle(ResourcesPlugin.PI_RESOURCES).start(Bundle.START_TRANSIENT);
    } catch (BundleException e) {
        logException(e.getMessage(), e);
    }
    try {
        redirectStandardStreams();
    } catch (FileNotFoundException e) {
        logException(e.getMessage(), e);
    }
    JavaLanguageServerPlugin.context = bundleContext;
    JavaLanguageServerPlugin.pluginInstance = this;
    // Set the ID to use for preference lookups
    JavaManipulation.setPreferenceNodeId(PLUGIN_ID);
    preferenceManager = new PreferenceManager();
    initializeJDTOptions();
    projectsManager = new ProjectsManager(preferenceManager);
    try {
        ResourcesPlugin.getWorkspace().addSaveParticipant(PLUGIN_ID, projectsManager);
    } catch (CoreException e) {
        logException(e.getMessage(), e);
    }
    contentProviderManager = new ContentProviderManager(preferenceManager);
    logInfo(getClass() + " is started");
    configureProxy();
}
Also used : ContentProviderManager(org.eclipse.jdt.ls.core.internal.managers.ContentProviderManager) CoreException(org.eclipse.core.runtime.CoreException) FileNotFoundException(java.io.FileNotFoundException) BundleException(org.osgi.framework.BundleException) ProjectsManager(org.eclipse.jdt.ls.core.internal.managers.ProjectsManager) PreferenceManager(org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager)

Example 2 with ContentProviderManager

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

the class JDTUtils method findElementsAtSelection.

public static IJavaElement[] findElementsAtSelection(ITypeRoot unit, int line, int column, PreferenceManager preferenceManager, IProgressMonitor monitor) throws JavaModelException {
    if (unit == null) {
        return null;
    }
    int offset = JsonRpcHelpers.toOffset(unit.getBuffer(), line, column);
    if (offset > -1) {
        return unit.codeSelect(offset, 0);
    }
    if (unit instanceof IClassFile) {
        IClassFile classFile = (IClassFile) unit;
        ContentProviderManager contentProvider = JavaLanguageServerPlugin.getContentProviderManager();
        String contents = contentProvider.getSource(classFile, monitor);
        if (contents != null) {
            IDocument document = new Document(contents);
            try {
                offset = document.getLineOffset(line) + column;
                if (offset > -1) {
                    String name = parse(contents, offset);
                    if (name == null) {
                        return null;
                    }
                    SearchPattern pattern = SearchPattern.createPattern(name, IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_FULL_MATCH);
                    IJavaSearchScope scope = createSearchScope(unit.getJavaProject());
                    List<IJavaElement> elements = new ArrayList<>();
                    SearchRequestor requestor = new SearchRequestor() {

                        @Override
                        public void acceptSearchMatch(SearchMatch match) {
                            if (match.getElement() instanceof IJavaElement) {
                                elements.add((IJavaElement) match.getElement());
                            }
                        }
                    };
                    SearchEngine searchEngine = new SearchEngine();
                    searchEngine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, null);
                    return elements.toArray(new IJavaElement[0]);
                }
            } catch (BadLocationException | CoreException e) {
                JavaLanguageServerPlugin.logException(e.getMessage(), e);
            }
        }
    }
    return null;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) SearchMatch(org.eclipse.jdt.core.search.SearchMatch) IClassFile(org.eclipse.jdt.core.IClassFile) ContentProviderManager(org.eclipse.jdt.ls.core.internal.managers.ContentProviderManager) ArrayList(java.util.ArrayList) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) SearchRequestor(org.eclipse.jdt.core.search.SearchRequestor) SearchEngine(org.eclipse.jdt.core.search.SearchEngine) CoreException(org.eclipse.core.runtime.CoreException) IJavaSearchScope(org.eclipse.jdt.core.search.IJavaSearchScope) SearchPattern(org.eclipse.jdt.core.search.SearchPattern) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 3 with ContentProviderManager

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

the class JDTLanguageServer method classFileContents.

/* (non-Javadoc)
	 * @see org.eclipse.jdt.ls.core.internal.JavaProtocolExtensions#ClassFileContents(org.eclipse.lsp4j.TextDocumentIdentifier)
	 */
@Override
public CompletableFuture<String> classFileContents(TextDocumentIdentifier param) {
    logInfo(">> java/classFileContents");
    ContentProviderManager handler = JavaLanguageServerPlugin.getContentProviderManager();
    URI uri = JDTUtils.toURI(param.getUri());
    return computeAsync((monitor) -> handler.getContent(uri, monitor));
}
Also used : ContentProviderManager(org.eclipse.jdt.ls.core.internal.managers.ContentProviderManager) URI(java.net.URI)

Aggregations

ContentProviderManager (org.eclipse.jdt.ls.core.internal.managers.ContentProviderManager)3 CoreException (org.eclipse.core.runtime.CoreException)2 FileNotFoundException (java.io.FileNotFoundException)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 IClassFile (org.eclipse.jdt.core.IClassFile)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1 IJavaSearchScope (org.eclipse.jdt.core.search.IJavaSearchScope)1 SearchEngine (org.eclipse.jdt.core.search.SearchEngine)1 SearchMatch (org.eclipse.jdt.core.search.SearchMatch)1 SearchPattern (org.eclipse.jdt.core.search.SearchPattern)1 SearchRequestor (org.eclipse.jdt.core.search.SearchRequestor)1 ProjectsManager (org.eclipse.jdt.ls.core.internal.managers.ProjectsManager)1 PreferenceManager (org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 Document (org.eclipse.jface.text.Document)1 IDocument (org.eclipse.jface.text.IDocument)1 BundleException (org.osgi.framework.BundleException)1