Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NavigateToDefinitionHandler should not return null #1143

Merged
merged 1 commit into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package org.eclipse.jdt.ls.core.internal.handlers;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -45,7 +46,7 @@ public List<? extends Location> definition(TextDocumentPositionParams position,
location = computeDefinitionNavigation(unit, position.getPosition().getLine(),
position.getPosition().getCharacter(), monitor);
}
return location == null ? null : Arrays.asList(location);
return location == null ? Collections.emptyList : Arrays.asList(location);
}

private Location computeDefinitionNavigation(ITypeRoot unit, int line, int column, IProgressMonitor monitor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -52,7 +51,8 @@ public void setUp() throws Exception {
public void testGetEmptyDefinition() throws Exception {
List<? extends Location> definitions = handler.definition(
new TextDocumentPositionParams(new TextDocumentIdentifier("/foo/bar"), new Position(1, 1)), monitor);
assertNull(definitions);
assertNotNull(definitions);
assertEquals(0, definitions.size());
}

@Test
Expand All @@ -66,7 +66,8 @@ public void testNoClassContentSupport() throws Exception {
String uri = ClassFileUtil.getURI(project, "org.apache.commons.lang3.StringUtils");
when(preferenceManager.isClientSupportsClassFileContent()).thenReturn(false);
List<? extends Location> definitions = handler.definition(new TextDocumentPositionParams(new TextDocumentIdentifier(uri), new Position(20, 26)), monitor);
assertNull(definitions);
assertNotNull(definitions);
assertEquals(0, definitions.size());
}

@Test
Expand Down