find functional interface on arrow/dbl column (IDEA-122033)

This commit is contained in:
Anna Kozlova
2014-11-25 19:23:28 +01:00
parent bf2f3f84ee
commit 58be40453f
2 changed files with 53 additions and 0 deletions
@@ -99,6 +99,15 @@ public class TargetElementUtil extends TargetElementUtilBase {
if (ref instanceof PsiJavaReference) {
refElement = ((PsiJavaReference)ref).advancedResolve(true).getElement();
}
else if (ref == null) {
final PsiElement element = file.findElementAt(offset);
if (element != null) {
final PsiElement parent = element.getParent();
if (parent instanceof PsiFunctionalExpression) {
refElement = PsiUtil.resolveClassInType(((PsiFunctionalExpression)parent).getFunctionalInterfaceType());
}
}
}
}
if (refElement != null) {
@@ -0,0 +1,44 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.navigation;
import com.intellij.codeInsight.TargetElementUtilBase;
import com.intellij.psi.CommonClassNames;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase;
public class ShowImplementationHandlerTest extends JavaCodeInsightFixtureTestCase {
public void testMultipleImplsFromAbstractCall() throws Throwable {
PsiFile file = myFixture.addFileToProject("Foo.java", "public abstract class Hello {" +
" {" +
" Runnable r = () <caret>-> {};\n" +
" }\n" +
"}\n" +
"\n");
myFixture.configureFromExistingVirtualFile(file.getVirtualFile());
final PsiElement element =
TargetElementUtilBase.findTargetElement(myFixture.getEditor(), TargetElementUtilBase.getInstance().getAllAccepted());
assertTrue(element instanceof PsiClass);
final String qualifiedName = ((PsiClass)element).getQualifiedName();
assertEquals(CommonClassNames.JAVA_LANG_RUNNABLE, qualifiedName);
}
}