Skip to content

Commit

Permalink
Fix exception occuring when peeking at implementation (eclipse-jdtls#…
Browse files Browse the repository at this point in the history
…1007)

Signed-off-by: Snjezana Peco <[email protected]>
  • Loading branch information
snjeza authored Apr 23, 2019
1 parent 4ba96a3 commit c7967e7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.ITypeRoot;
import org.eclipse.jdt.core.JavaModelException;
Expand Down Expand Up @@ -50,7 +51,7 @@ public List<? extends Location> findImplementations(TextDocumentPositionParams p
if (typeRoot != null) {
elementToSearch = JDTUtils.findElementAtSelection(typeRoot, param.getPosition().getLine(), param.getPosition().getCharacter(), this.preferenceManager, monitor);
}
if (elementToSearch == null) {
if (!(elementToSearch instanceof IType || elementToSearch instanceof IMethod)) {
return Collections.emptyList();
}
int offset = getOffset(param, typeRoot);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.sample;
public class Foo4 {

public static <T extends Number> T get() {
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,17 @@ private List<? extends Location> getRunnableImplementations() {
return implementations;
}

@Test
public void testInvalidElement() {
URI uri = project.getFile("src/org/sample/Foo4.java").getRawLocationURI();
String fileURI = ResourceUtils.fixURI(uri);

TextDocumentPositionParams param = new TextDocumentPositionParams();
param.setPosition(new Position(3, 34)); //Position over T
param.setTextDocument(new TextDocumentIdentifier(fileURI));
List<? extends Location> implementations = handler.findImplementations(param, monitor);
assertNotNull("findImplementations should not return null", implementations);
assertEquals(implementations.toString(), 0, implementations.size());
}

}

0 comments on commit c7967e7

Please sign in to comment.