Search in sources :

Example 1 with Preferences

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

the class CodeLensHandlerTest method testEnableImplementationsCodeLensSymbols.

@Test
public void testEnableImplementationsCodeLensSymbols() throws Exception {
    Preferences implementationsCodeLenses = Preferences.createFrom(Collections.singletonMap(Preferences.IMPLEMENTATIONS_CODE_LENS_ENABLED_KEY, "true"));
    Mockito.reset(preferenceManager);
    when(preferenceManager.getPreferences()).thenReturn(implementationsCodeLenses);
    handler = new CodeLensHandler(preferenceManager);
    String payload = createCodeLensSymbolsRequest("src/java/IFoo.java");
    CodeLensParams codeLensParams = getParams(payload);
    String uri = codeLensParams.getTextDocument().getUri();
    assertFalse(uri.isEmpty());
    // when
    List<CodeLens> result = handler.getCodeLensSymbols(uri, monitor);
    // then
    assertEquals(2, result.size());
    CodeLens lens = result.get(1);
    @SuppressWarnings("unchecked") List<Object> data = (List<Object>) lens.getData();
    String type = (String) data.get(2);
    assertEquals(type, "implementations");
}
Also used : CodeLens(org.eclipse.lsp4j.CodeLens) CodeLensParams(org.eclipse.lsp4j.CodeLensParams) List(java.util.List) Preferences(org.eclipse.jdt.ls.core.internal.preferences.Preferences) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest) Test(org.junit.Test)

Example 2 with Preferences

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

the class SaveActionHandlerTest method setup.

@Override
@Before
public void setup() throws Exception {
    importProjects("eclipse/hello");
    project = WorkspaceHelper.getProject("hello");
    preferenceManager = mock(PreferenceManager.class);
    Preferences preferences = mock(Preferences.class);
    when(preferences.isJavaSaveActionsOrganizeImportsEnabled()).thenReturn(Boolean.TRUE);
    when(preferenceManager.getPreferences()).thenReturn(preferences);
    monitor = mock(IProgressMonitor.class);
    when(monitor.isCanceled()).thenReturn(false);
    handler = new SaveActionHandler(preferenceManager);
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Preferences(org.eclipse.jdt.ls.core.internal.preferences.Preferences) PreferenceManager(org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager) Before(org.junit.Before)

Example 3 with Preferences

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

the class AbstractProjectsManagerBasedTest method initProjectManager.

@Before
public void initProjectManager() throws CoreException {
    clientRequests.clear();
    logListener = new SimpleLogListener();
    Platform.addLogListener(logListener);
    preferences = new Preferences();
    if (preferenceManager != null) {
        when(preferenceManager.getPreferences()).thenReturn(preferences);
        ClientPreferences clientPreferences = mock(ClientPreferences.class);
        when(clientPreferences.isProgressReportSupported()).thenReturn(true);
        when(preferenceManager.getClientPreferences()).thenReturn(clientPreferences);
    }
    projectsManager = new ProjectsManager(preferenceManager);
    ProgressReporterManager progressManager = new ProgressReporterManager(this.client, preferenceManager);
    // disable throttling to ensure we capture all events
    progressManager.setReportThrottle(0);
    Job.getJobManager().setProgressProvider(progressManager);
    monitor = progressManager.getDefaultMonitor();
    WorkingCopyOwner.setPrimaryBufferProvider(new WorkingCopyOwner() {

        @Override
        public IBuffer createBuffer(ICompilationUnit workingCopy) {
            ICompilationUnit original = workingCopy.getPrimary();
            IResource resource = original.getResource();
            if (resource instanceof IFile) {
                return new DocumentAdapter(workingCopy, (IFile) resource);
            }
            return DocumentAdapter.Null;
        }
    });
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) SimpleLogListener(org.eclipse.jdt.ls.core.internal.SimpleLogListener) ClientPreferences(org.eclipse.jdt.ls.core.internal.preferences.ClientPreferences) IFile(org.eclipse.core.resources.IFile) WorkingCopyOwner(org.eclipse.jdt.core.WorkingCopyOwner) ProgressReporterManager(org.eclipse.jdt.ls.core.internal.handlers.ProgressReporterManager) DocumentAdapter(org.eclipse.jdt.ls.core.internal.DocumentAdapter) ClientPreferences(org.eclipse.jdt.ls.core.internal.preferences.ClientPreferences) Preferences(org.eclipse.jdt.ls.core.internal.preferences.Preferences) IBuffer(org.eclipse.jdt.core.IBuffer) IResource(org.eclipse.core.resources.IResource) Before(org.junit.Before)

Example 4 with Preferences

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

the class HoverHandlerTest method setup.

@Before
public void setup() throws Exception {
    importProjects("eclipse/hello");
    project = WorkspaceHelper.getProject("hello");
    IJavaProject javaProject = JavaCore.create(project);
    sourceFolder = javaProject.getPackageFragmentRoot(javaProject.getProject().getFolder("src"));
    preferenceManager = mock(PreferenceManager.class);
    when(preferenceManager.getPreferences()).thenReturn(new Preferences());
    handler = new HoverHandler(preferenceManager);
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) Preferences(org.eclipse.jdt.ls.core.internal.preferences.Preferences) PreferenceManager(org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager) Before(org.junit.Before)

Example 5 with Preferences

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

the class InitHandlerTest method testJavaImportExclusions.

@Test
public void testJavaImportExclusions() throws Exception {
    Map<String, Object> initializationOptions = createInitializationOptions();
    @SuppressWarnings("unchecked") Preferences prefs = Preferences.createFrom((Map<String, Object>) (initializationOptions.get(InitHandler.SETTINGS_KEY)));
    assertEquals(TEST_EXCLUSIONS, prefs.getJavaImportExclusions().get(0));
}
Also used : ClientPreferences(org.eclipse.jdt.ls.core.internal.preferences.ClientPreferences) Preferences(org.eclipse.jdt.ls.core.internal.preferences.Preferences) AbstractProjectsManagerBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest) Test(org.junit.Test)

Aggregations

Preferences (org.eclipse.jdt.ls.core.internal.preferences.Preferences)17 Before (org.junit.Before)8 PreferenceManager (org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager)7 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)5 Test (org.junit.Test)5 CodeLens (org.eclipse.lsp4j.CodeLens)4 CodeLensParams (org.eclipse.lsp4j.CodeLensParams)4 IJavaProject (org.eclipse.jdt.core.IJavaProject)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 CoreException (org.eclipse.core.runtime.CoreException)2 ClientPreferences (org.eclipse.jdt.ls.core.internal.preferences.ClientPreferences)2 URI (java.net.URI)1 List (java.util.List)1 IFile (org.eclipse.core.resources.IFile)1 IResource (org.eclipse.core.resources.IResource)1 IPath (org.eclipse.core.runtime.IPath)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 IBuffer (org.eclipse.jdt.core.IBuffer)1