workaround for overload resolution for methods from Object when project has multiple...
authorAnna Kozlova <anna.kozlova@jetbrains.com>
Wed, 21 Jan 2015 11:14:13 +0000 (12:14 +0100)
committerAnna Kozlova <anna.kozlova@jetbrains.com>
Wed, 21 Jan 2015 11:14:13 +0000 (12:14 +0100)
java/java-psi-impl/src/com/intellij/psi/scope/conflictResolvers/JavaMethodsConflictResolver.java
java/java-tests/testData/codeInsight/generation/surroundWith/java/CommentAsFirstRunnableSurroundStatement_after.java
java/java-tests/testData/codeInsight/multipleJdks/java7/p/GetClass.java [new file with mode: 0644]
java/java-tests/testData/codeInsight/multipleJdks/java8/p/GetClass.java [new file with mode: 0644]
java/java-tests/testData/codeInsight/multipleJdks/libs/GetClass.jar [new file with mode: 0644]
java/java-tests/testSrc/com/intellij/codeInsight/ClsGenericsHighlightingTest.java
java/java-tests/testSrc/com/intellij/codeInsight/MultipleJdksHighlightingTest.java [new file with mode: 0644]

index 9127c8bcaa0a92407c3278e7e7c0d23fbd22b05e..099678b627b29f85b86c217a1c87d3a75c91445f 100644 (file)
@@ -615,12 +615,12 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{
           return Specifics.SECOND;
         }
       }
+      else if (MethodSignatureUtil.areErasedParametersEqual(method1.getSignature(PsiSubstitutor.EMPTY), method2.getSignature(PsiSubstitutor.EMPTY)) &&
+               MethodSignatureUtil.isSubsignature(method2.getSignature(info2.getSubstitutor(false)), method1.getSignature(info1.getSubstitutor(false)))) {
+        return Specifics.FIRST;
+      }
       else if (class1.isInheritor(class2, true) || class2.isInterface()) {
-        if (MethodSignatureUtil.areErasedParametersEqual(method1.getSignature(PsiSubstitutor.EMPTY), method2.getSignature(PsiSubstitutor.EMPTY)) && 
-            MethodSignatureUtil.isSubsignature(method2.getSignature(info2.getSubstitutor(false)), method1.getSignature(info1.getSubstitutor(false)))) {
-          return Specifics.FIRST;
-        }
-        else if (method1.hasModifierProperty(PsiModifier.STATIC) && method2.hasModifierProperty(PsiModifier.STATIC) && boxingHappened[0] == 0) {
+        if (method1.hasModifierProperty(PsiModifier.STATIC) && method2.hasModifierProperty(PsiModifier.STATIC) && boxingHappened[0] == 0) {
           return Specifics.FIRST;
         }
       }
index 30ae98a335fc9eda5c612134390bb09dcd8fd38f..3d5b4b8f12c463db97970d5b80bcb0344826e23a 100644 (file)
@@ -1,6 +1,7 @@
 class Test {
     void foo() {
         <caret>Runnable runnable = new Runnable() {
+            @Override
             public void run() {
                 // This is comment"
                 int i = 1;
diff --git a/java/java-tests/testData/codeInsight/multipleJdks/java7/p/GetClass.java b/java/java-tests/testData/codeInsight/multipleJdks/java7/p/GetClass.java
new file mode 100644 (file)
index 0000000..7b1ddba
--- /dev/null
@@ -0,0 +1,6 @@
+package p;
+abstract class B extends A implements p.P {
+  {
+    final Class<? extends B> aClass = getClass();
+  }
+}
diff --git a/java/java-tests/testData/codeInsight/multipleJdks/java8/p/GetClass.java b/java/java-tests/testData/codeInsight/multipleJdks/java8/p/GetClass.java
new file mode 100644 (file)
index 0000000..b413b7f
--- /dev/null
@@ -0,0 +1,6 @@
+package p;
+public abstract class A implements p.P {
+  {
+    final Class aClass = getClass();
+  }
+}
\ No newline at end of file
diff --git a/java/java-tests/testData/codeInsight/multipleJdks/libs/GetClass.jar b/java/java-tests/testData/codeInsight/multipleJdks/libs/GetClass.jar
new file mode 100644 (file)
index 0000000..95fbb92
Binary files /dev/null and b/java/java-tests/testData/codeInsight/multipleJdks/libs/GetClass.jar differ
index 839d933437fc3fd24b89ef0a42e6c79853468f57..d0acde8a4803ba068c4061a84c12b4c8372438b9 100644 (file)
@@ -77,23 +77,27 @@ public abstract class ClsGenericsHighlightingTest extends UsefulTestCase {
     ModuleRootModificationUtil.updateModel(myModule, new Consumer<ModifiableRootModel>() {
       @Override
       public void consume(ModifiableRootModel model) {
-        LibraryTable libraryTable = model.getModuleLibraryTable();
-        Library library = libraryTable.createLibrary("test");
-
-        Library.ModifiableModel libraryModel = library.getModifiableModel();
-        for (String annotationsDir : libraryPath) {
-          String path = myFixture.getTestDataPath() + "/libs/" + annotationsDir;
-          VirtualFile libJarLocal = LocalFileSystem.getInstance().findFileByPath(path);
-          assertNotNull(libJarLocal);
-          VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(libJarLocal);
-          assertNotNull(jarRoot);
-          libraryModel.addRoot(jarRoot, OrderRootType.CLASSES);
-        }
-        libraryModel.commit();
+        commitLibraryModel(model, myFixture.getTestDataPath(), libraryPath);
 
         String contentUrl = VfsUtilCore.pathToUrl(myFixture.getTempDirPath());
         model.addContentEntry(contentUrl).addSourceFolder(contentUrl, false);
       }
     });
   }
+
+  protected static void commitLibraryModel(ModifiableRootModel model, String testDataPath, @NotNull String... libraryPath) {
+    LibraryTable libraryTable = model.getModuleLibraryTable();
+    Library library = libraryTable.createLibrary("test");
+
+    Library.ModifiableModel libraryModel = library.getModifiableModel();
+    for (String annotationsDir : libraryPath) {
+      String path = testDataPath + "/libs/" + annotationsDir;
+      VirtualFile libJarLocal = LocalFileSystem.getInstance().findFileByPath(path);
+      assertNotNull(libJarLocal);
+      VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(libJarLocal);
+      assertNotNull(jarRoot);
+      libraryModel.addRoot(jarRoot, OrderRootType.CLASSES);
+    }
+    libraryModel.commit();
+  }
 }
diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/MultipleJdksHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/MultipleJdksHighlightingTest.java
new file mode 100644 (file)
index 0000000..9d3ec59
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * Copyright 2000-2015 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.codeInsight;
+
+import com.intellij.openapi.application.ex.PathManagerEx;
+import com.intellij.openapi.module.Module;
+import com.intellij.openapi.roots.ModifiableRootModel;
+import com.intellij.openapi.roots.ModuleRootModificationUtil;
+import com.intellij.openapi.vfs.VfsUtilCore;
+import com.intellij.testFramework.IdeaTestCase;
+import com.intellij.testFramework.IdeaTestUtil;
+import com.intellij.testFramework.UsefulTestCase;
+import com.intellij.testFramework.builders.JavaModuleFixtureBuilder;
+import com.intellij.testFramework.fixtures.*;
+import com.intellij.util.Consumer;
+
+public class MultipleJdksHighlightingTest extends UsefulTestCase {
+
+  private CodeInsightTestFixture myFixture;
+  private Module myJava7Module;
+  private Module myJava8Module;
+
+  @SuppressWarnings("JUnitTestCaseWithNonTrivialConstructors")
+  public MultipleJdksHighlightingTest() {
+    IdeaTestCase.initPlatformPrefix();
+  }
+
+  @Override
+  protected void tearDown() throws Exception {
+    super.tearDown();
+    myFixture.tearDown();
+    myFixture = null;
+    myJava7Module = null;
+    myJava8Module = null;
+  }
+  
+  @Override
+  public void setUp() throws Exception {
+    super.setUp();
+    TestFixtureBuilder<IdeaProjectTestFixture> projectBuilder = IdeaTestFixtureFactory.getFixtureFactory().createFixtureBuilder(getName());
+    myFixture = JavaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(projectBuilder.getFixture());
+    myFixture.setTestDataPath(PathManagerEx.getTestDataPath() + "/codeInsight/multipleJdks");
+    final JavaModuleFixtureBuilder[] builders = new JavaModuleFixtureBuilder[2];
+    builders[0] = projectBuilder.addModule(JavaModuleFixtureBuilder.class);
+    builders[1] = projectBuilder.addModule(JavaModuleFixtureBuilder.class);
+    myFixture.setUp();
+    myJava7Module = builders[0].getFixture().getModule();
+    myJava8Module = builders[1].getFixture().getModule();
+    ModuleRootModificationUtil.updateModel(myJava7Module, new Consumer<ModifiableRootModel>() {
+      @Override
+      public void consume(ModifiableRootModel model) {
+        model.addModuleOrderEntry(myJava8Module);
+        model.setSdk(IdeaTestUtil.getMockJdk17());
+        String contentUrl = VfsUtilCore.pathToUrl(myFixture.getTempDirPath()) + "/java7";
+        model.addContentEntry(contentUrl).addSourceFolder(contentUrl, false);
+      }
+    });
+
+    ModuleRootModificationUtil.updateModel(myJava8Module, new Consumer<ModifiableRootModel>() {
+      @Override
+      public void consume(ModifiableRootModel model) {
+        model.setSdk(IdeaTestUtil.getMockJdk18());
+        String contentUrl = VfsUtilCore.pathToUrl(myFixture.getTempDirPath()) + "/java8";
+        model.addContentEntry(contentUrl).addSourceFolder(contentUrl, false);
+      }
+    });
+  }
+
+  public void testGetClass() throws Exception {
+    doTest();
+  }
+
+  protected void doTest() {
+    final String name = getTestName(false);
+    for (Module module : new Module[] {myJava7Module, myJava8Module}) {
+      ModuleRootModificationUtil.updateModel(module, new Consumer<ModifiableRootModel>() {
+        @Override
+        public void consume(ModifiableRootModel model) {
+          ClsGenericsHighlightingTest.commitLibraryModel(model, myFixture.getTestDataPath(), name + ".jar");
+        }
+      });
+    }
+
+    myFixture.configureByFiles("java7/p/" + name + ".java", "java8/p/" + name + ".java");
+    myFixture.checkHighlighting();
+  }
+}