Skip to content

Commit

Permalink
NavigateToDefinitionHandler should not return null
Browse files Browse the repository at this point in the history
Signed-off-by: Omar Tawfik <[email protected]>
  • Loading branch information
OmarTawfik authored and fbricon committed Aug 29, 2019
1 parent f4137eb commit ffd5d99
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
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

0 comments on commit ffd5d99

Please sign in to comment.