From 3e9370f4516ccc053bdaf33741a1ac628696da1d Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Mon, 14 Nov 2016 15:31:58 +0100 Subject: [PATCH] substitute base class according to resolve place EA-90836 - assert: InferenceSession.collectApplicabilityConstraints --- .../graphInference/InferenceSession.java | 13 +++++++---- ...MethodReferencePointingToDifferentJdk.java | 8 +++++++ ...MethodReferencePointingToDifferentJdk.java | 23 +++++++++++++++++++ .../MultipleJdksHighlightingTest.java | 12 +++++++++- 4 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/multipleJdks/java3/p/MethodReferencePointingToDifferentJdk.java create mode 100644 java/java-tests/testData/codeInsight/multipleJdks/java8/p/MethodReferencePointingToDifferentJdk.java diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java index 25406c5c3e6d..71499ba32b30 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java @@ -1614,7 +1614,7 @@ public class InferenceSession { } if (methodContainingClass != null) { - psiSubstitutor = TypeConversionUtil.getClassSubstitutor(methodContainingClass, containingClass, psiSubstitutor); + psiSubstitutor = JavaClassSupers.getInstance().getSuperClassSubstitutor(methodContainingClass, containingClass, reference.getResolveScope(), psiSubstitutor); LOG.assertTrue(psiSubstitutor != null, "derived: " + containingClass + "; super: " + methodContainingClass + "; reference: " + reference.getText() + @@ -1631,7 +1631,7 @@ public class InferenceSession { final PsiType pType = signature.getParameterTypes()[0]; // 15.13.1 If the ReferenceType is a raw type, and there exists a parameterization of this type, T, that is a supertype of P1, - // the type to search is the result of capture conversion (5.1.10) applied to T; + // the type to search is the result of capture conversion (5.1.10) applied to T; // otherwise, the type to search is the same as the type of the first search. Again, the type arguments, if any, are given by the method reference. if (PsiUtil.isRawSubstitutor(containingClass, psiSubstitutor)) { PsiType normalizedPType = PsiUtil.captureToplevelWildcards(pType, myContext); @@ -1646,7 +1646,7 @@ public class InferenceSession { mySiteSubstitutor = mySiteSubstitutor.putAll(receiverSubstitutor); if (methodContainingClass != null) { - final PsiSubstitutor superSubstitutor = TypeConversionUtil.getClassSubstitutor(methodContainingClass, containingClass, receiverSubstitutor); + final PsiSubstitutor superSubstitutor = JavaClassSupers.getInstance().getSuperClassSubstitutor(methodContainingClass, containingClass, reference.getResolveScope(), receiverSubstitutor); LOG.assertTrue(superSubstitutor != null, "mContainingClass: " + methodContainingClass.getName() + "; containingClass: " + containingClass.getName()); mySiteSubstitutor = mySiteSubstitutor.putAll(superSubstitutor); } @@ -1660,8 +1660,11 @@ public class InferenceSession { addConstraint(new TypeCompatibilityConstraint(substituteWithInferenceVariables(qType), pType)); if (methodContainingClass != null) { - psiSubstitutor = TypeConversionUtil.getClassSubstitutor(methodContainingClass, containingClass, psiSubstitutor); - LOG.assertTrue(psiSubstitutor != null, "derived: " + containingClass + "; super: " + methodContainingClass); + psiSubstitutor = JavaClassSupers.getInstance().getSuperClassSubstitutor(methodContainingClass, containingClass, reference.getResolveScope(), psiSubstitutor); + LOG.assertTrue(psiSubstitutor != null, "derived: " + containingClass + + "; super: " + methodContainingClass + + "; reference: " + reference.getText() + + "; containingFile: " + reference.getContainingFile().getName()); } for (int i = 0; i < signature.getParameterTypes().length - 1; i++) { diff --git a/java/java-tests/testData/codeInsight/multipleJdks/java3/p/MethodReferencePointingToDifferentJdk.java b/java/java-tests/testData/codeInsight/multipleJdks/java3/p/MethodReferencePointingToDifferentJdk.java new file mode 100644 index 000000000000..8de5b9a1f059 --- /dev/null +++ b/java/java-tests/testData/codeInsight/multipleJdks/java3/p/MethodReferencePointingToDifferentJdk.java @@ -0,0 +1,8 @@ +package p; + +import java.io.FileReader; +import java.io.IOException; + +public class PersistentMap extends FileReader { + public void close() throws IOException {} +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/multipleJdks/java8/p/MethodReferencePointingToDifferentJdk.java b/java/java-tests/testData/codeInsight/multipleJdks/java8/p/MethodReferencePointingToDifferentJdk.java new file mode 100644 index 000000000000..2adae27db380 --- /dev/null +++ b/java/java-tests/testData/codeInsight/multipleJdks/java8/p/MethodReferencePointingToDifferentJdk.java @@ -0,0 +1,23 @@ +package p; +import java.io.*; + +class Subst { + PersistentMap messages; + + { + register(() -> catchAndWarn(messages::close)); + } + + static void register(Runnable r) {} + + private static void catchAndWarn(ThrowableRunnable runnable) { + try { + runnable.run(); + } + catch (IOException e) {} + } + + interface ThrowableRunnable { + void run() throws IOException; + } +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/MultipleJdksHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/MultipleJdksHighlightingTest.java index 0fa886c71d14..131f6a37f4dc 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/MultipleJdksHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/MultipleJdksHighlightingTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -217,6 +217,16 @@ public class MultipleJdksHighlightingTest extends UsefulTestCase { myFixture.checkHighlighting(); } + public void testMethodReferencePointingToDifferentJdk() throws Exception { + ModuleRootModificationUtil.addDependency(myJava8Module, myJava3Module); + final String testName = getTestName(false); + myFixture.copyFileToProject("java3/p/" + testName + ".java"); + myFixture.copyFileToProject("java8/p/" + testName + ".java"); + + myFixture.configureByFiles("java8/p/" + testName + ".java", "java3/p/" + testName + ".java"); + myFixture.checkHighlighting(); + } + public void testInheritorsOfJdkClassOnlyInModulesWithThatJdk() { ModuleRootModificationUtil.addDependency(myJava8Module, myJava7Module);