mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
java 8: anonymous class fields could be available later in next lambdas (IDEA-123731)
This commit is contained in:
@@ -544,7 +544,8 @@ public class PsiImplUtil {
|
||||
PsiClass aClass = member.getContainingClass();
|
||||
if (aClass instanceof PsiAnonymousClass) {
|
||||
//member from anonymous class can be called from outside the class
|
||||
PsiElement methodCallExpr = PsiTreeUtil.getParentOfType(aClass, PsiMethodCallExpression.class);
|
||||
PsiElement methodCallExpr = PsiUtil.isLanguageLevel8OrHigher(aClass) ? PsiTreeUtil.getParentOfType(aClass, PsiMember.class)
|
||||
: PsiTreeUtil.getParentOfType(aClass, PsiMethodCallExpression.class);
|
||||
return new LocalSearchScope(methodCallExpr != null ? methodCallExpr : aClass);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
class Test{
|
||||
|
||||
public static void main(String[] args) {
|
||||
Map<String, Collection<Integer>> myMap = null;
|
||||
|
||||
myMap.entrySet().stream()
|
||||
.flatMap(entry -> entry.getValue().stream()
|
||||
.map(val -> new Object() {
|
||||
String key = entry.getKey();
|
||||
Integer va<caret>lue = val;
|
||||
}))
|
||||
.forEachOrdered(o -> {
|
||||
final String key = o.key;
|
||||
final Integer value = o.value;
|
||||
System.out.println("key: " + key + " value: " + value);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -16,12 +16,13 @@
|
||||
package com.intellij.codeInsight.daemon.lambda;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFunctionalExpression;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.searches.FunctionalExpressionSearch;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -39,8 +40,27 @@ public class FindFunctionalInterfaceTest extends LightCodeInsightFixtureTestCase
|
||||
assertEquals("() -> {}", next.getText());
|
||||
}
|
||||
|
||||
public void testFieldFromAnonymousClassScope() throws Exception {
|
||||
myFixture.configureByFile(getTestName(false) + ".java");
|
||||
final PsiElement elementAtCaret = myFixture.getElementAtCaret();
|
||||
assertNotNull(elementAtCaret);
|
||||
final PsiField field = PsiTreeUtil.getParentOfType(elementAtCaret, PsiField.class, false);
|
||||
assertNotNull(field);
|
||||
final PsiClass aClass = field.getContainingClass();
|
||||
assertTrue(aClass instanceof PsiAnonymousClass);
|
||||
final Collection<PsiReference> references = ReferencesSearch.search(field).findAll();
|
||||
assertFalse(references.isEmpty());
|
||||
assertEquals(1, references.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return JavaTestUtil.getRelativeJavaTestDataPath() + "/codeInsight/daemonCodeAnalyzer/lambda/findUsages/";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_8;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user