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

An exception occur when peek implementation #1007

Merged
merged 1 commit into from
Apr 23, 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 @@ -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());
}

}