mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
new inference: address anonymous classes (IDEA-121063)
This commit is contained in:
+8
-5
@@ -179,8 +179,8 @@ public class InferenceSession {
|
||||
return parameterType;
|
||||
}
|
||||
}
|
||||
if (arg instanceof PsiMethodCallExpression) {
|
||||
final PsiMethod method = ((PsiMethodCallExpression)arg).resolveMethod();
|
||||
if (arg instanceof PsiCallExpression) {
|
||||
final PsiMethod method = ((PsiCallExpression)arg).resolveMethod();
|
||||
if (method != null) {
|
||||
final PsiType returnType = method.getReturnType();
|
||||
if (returnType != null && returnType.getArrayDimensions() == parameterType.getArrayDimensions()) {
|
||||
@@ -492,7 +492,10 @@ public class InferenceSession {
|
||||
private PsiType getTargetType(final PsiExpression context) {
|
||||
final PsiElement parent = PsiUtil.skipParenthesizedExprUp(context.getParent());
|
||||
if (parent instanceof PsiExpressionList) {
|
||||
final PsiElement gParent = parent.getParent();
|
||||
PsiElement gParent = parent.getParent();
|
||||
if (gParent instanceof PsiAnonymousClass) {
|
||||
gParent = gParent.getParent();
|
||||
}
|
||||
if (gParent instanceof PsiCallExpression) {
|
||||
final PsiExpressionList argumentList = ((PsiCallExpression)gParent).getArgumentList();
|
||||
if (argumentList != null) {
|
||||
@@ -561,8 +564,8 @@ public class InferenceSession {
|
||||
}
|
||||
final int i = ArrayUtilRt.find(args, arg);
|
||||
if (i < 0) return null;
|
||||
final PsiCallExpression callExpression = (PsiCallExpression)argumentList.getParent();
|
||||
if (callExpression.getTypeArguments().length > 0) {
|
||||
final PsiCallExpression callExpression = PsiTreeUtil.getParentOfType(argumentList, PsiCallExpression.class);
|
||||
if (callExpression != null && callExpression.getTypeArguments().length > 0) {
|
||||
return getParameterType(parameters, args, i, ((MethodCandidateInfo)result).typeArgumentsSubstitutor());
|
||||
}
|
||||
final PsiType parameterType = getParameterType(parameters, args, i, pair != null ? pair.second : PsiSubstitutor.EMPTY);
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import java.util.function.Function;
|
||||
|
||||
class TypeDetectionTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Table<String>(Function.identity()) {{}};
|
||||
new Table<String>(Function.identity());
|
||||
new Table<String>(x -> x) {{}};
|
||||
|
||||
}
|
||||
|
||||
public static class Table<T> {
|
||||
public Table(Function<T, T> f) {
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
@@ -144,6 +144,10 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testTargetTypeByAnonymousClass() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() throws Exception {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user