diff --git a/idea/src/org/jetbrains/kotlin/idea/versions/KotlinRuntimeLibraryUtil.java b/idea/src/org/jetbrains/kotlin/idea/versions/KotlinRuntimeLibraryUtil.java index 20ef703423e..563ce004d96 100644 --- a/idea/src/org/jetbrains/kotlin/idea/versions/KotlinRuntimeLibraryUtil.java +++ b/idea/src/org/jetbrains/kotlin/idea/versions/KotlinRuntimeLibraryUtil.java @@ -36,6 +36,7 @@ import com.intellij.psi.search.ProjectScope; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.indexing.FileBasedIndex; import com.intellij.util.indexing.ID; +import com.intellij.util.indexing.ScalarIndexExtension; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.idea.JetPluginUtil; @@ -62,33 +63,15 @@ public class KotlinRuntimeLibraryUtil { @NotNull public static Collection getLibraryRootsWithAbiIncompatibleKotlinClasses(@NotNull Project project) { - ID id = KotlinAbiVersionIndex.INSTANCE.getName(); - Collection abiVersions = FileBasedIndex.getInstance().getAllKeys(id, project); - Set badAbiVersions = Sets.newHashSet(Collections2.filter(abiVersions, new Predicate() { - @Override - public boolean apply(Integer abiVersion) { - return !AbiVersionUtil.isAbiVersionCompatible(abiVersion); - } - })); - Set badRoots = Sets.newHashSet(); - ProjectFileIndex fileIndex = ProjectFileIndex.SERVICE.getInstance(project); - - for (Integer version : badAbiVersions) { - Collection indexedFiles = FileBasedIndex.getInstance().getContainingFiles( - id, version, ProjectScope.getLibrariesScope(project)); - - for (VirtualFile indexedFile : indexedFiles) { - VirtualFile libraryRoot = fileIndex.getClassRootForFile(indexedFile); - assert libraryRoot != null : "Only library roots were requested, " + - "and only class files should be indexed with KotlinAbiVersionIndex key. " + - "File: " + indexedFile.getPath(); - badRoots.add(getLocalFile(libraryRoot)); - } - } - - return badRoots; + return getLibraryRootsWithAbiIncompatibleVersion(project, KotlinAbiVersionIndex.INSTANCE$); } + @NotNull + public static Collection getLibraryRootsWithAbiIncompatibleForKotlinJs(@NotNull Project project) { + return getLibraryRootsWithAbiIncompatibleVersion(project, KotlinJavaScriptAbiVersionIndex.INSTANCE$); + } + + public static void addJdkAnnotations(@NotNull Sdk sdk) { addAnnotations(sdk, PathUtil.getKotlinPathsForIdeaPlugin().getJdkAnnotationsPath()); } @@ -300,4 +283,36 @@ public class KotlinRuntimeLibraryUtil { throw new AssertionError(e); } } + + @NotNull + private static Collection getLibraryRootsWithAbiIncompatibleVersion( + @NotNull Project project, + @NotNull ScalarIndexExtension index + ) { + ID id = index.getName(); + Collection abiVersions = FileBasedIndex.getInstance().getAllKeys(id, project); + Set badAbiVersions = Sets.newHashSet(Collections2.filter(abiVersions, new Predicate() { + @Override + public boolean apply(Integer abiVersion) { + return !AbiVersionUtil.isAbiVersionCompatible(abiVersion); + } + })); + Set badRoots = Sets.newHashSet(); + ProjectFileIndex fileIndex = ProjectFileIndex.SERVICE.getInstance(project); + + for (Integer version : badAbiVersions) { + Collection indexedFiles = FileBasedIndex.getInstance().getContainingFiles( + id, version, ProjectScope.getLibrariesScope(project)); + + for (VirtualFile indexedFile : indexedFiles) { + VirtualFile libraryRoot = fileIndex.getClassRootForFile(indexedFile); + assert libraryRoot != null : "Only library roots were requested, " + + "and only class files should be indexed with KotlinAbiVersionIndex key. " + + "File: " + indexedFile.getPath(); + badRoots.add(getLocalFile(libraryRoot)); + } + } + + return badRoots; + } } diff --git a/idea/src/org/jetbrains/kotlin/idea/versions/KotlinUpdatePluginComponent.kt b/idea/src/org/jetbrains/kotlin/idea/versions/KotlinUpdatePluginComponent.kt index a6ee3c6fe65..d242863f4c5 100644 --- a/idea/src/org/jetbrains/kotlin/idea/versions/KotlinUpdatePluginComponent.kt +++ b/idea/src/org/jetbrains/kotlin/idea/versions/KotlinUpdatePluginComponent.kt @@ -61,7 +61,8 @@ class KotlinUpdatePluginComponent : ApplicationComponent { // Force update indices for files under config directory val fileBasedIndex = FileBasedIndex.getInstance() - fileBasedIndex.requestRebuild(KotlinAbiVersionIndex.INSTANCE.getName()) + fileBasedIndex.requestRebuild(KotlinAbiVersionIndex.getName()) + fileBasedIndex.requestRebuild(KotlinJavaScriptAbiVersionIndex.getName()) fileBasedIndex.requestRebuild(KotlinClassFileIndex.KEY) fileBasedIndex.requestRebuild(KotlinJavaScriptMetaFileIndex.KEY) diff --git a/idea/src/org/jetbrains/kotlin/idea/versions/UnsupportedAbiVersionNotificationPanelProvider.java b/idea/src/org/jetbrains/kotlin/idea/versions/UnsupportedAbiVersionNotificationPanelProvider.java index a4fd55a0dca..018bc27744c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/versions/UnsupportedAbiVersionNotificationPanelProvider.java +++ b/idea/src/org/jetbrains/kotlin/idea/versions/UnsupportedAbiVersionNotificationPanelProvider.java @@ -51,6 +51,7 @@ import org.jetbrains.kotlin.idea.JetFileType; import org.jetbrains.kotlin.idea.configuration.ConfigureKotlinInProjectUtils; import org.jetbrains.kotlin.idea.configuration.KotlinJavaModuleConfigurator; import org.jetbrains.kotlin.idea.configuration.KotlinProjectConfigurator; +import org.jetbrains.kotlin.idea.framework.JSLibraryStdPresentationProvider; import org.jetbrains.kotlin.idea.framework.JavaRuntimePresentationProvider; import javax.swing.*; @@ -85,7 +86,7 @@ public class UnsupportedAbiVersionNotificationPanelProvider extends EditorNotifi @Nullable public static EditorNotificationPanel checkAndCreate(@NotNull Project project) { - Collection badRoots = KotlinRuntimeLibraryUtil.getLibraryRootsWithAbiIncompatibleKotlinClasses(project); + Collection badRoots = collectBadRoots(project); if (!badRoots.isEmpty()) { return new UnsupportedAbiVersionNotificationPanelProvider(project).doCreate(badRoots); } @@ -101,8 +102,9 @@ public class UnsupportedAbiVersionNotificationPanelProvider extends EditorNotifi @Override public boolean apply(@Nullable Library library) { assert library != null : "library should be non null"; - VirtualFile runtimeJar = JavaRuntimePresentationProvider.getRuntimeJar(library); - return badRoots.contains(KotlinRuntimeLibraryUtil.getLocalJar(runtimeJar)); + VirtualFile runtimeJar = KotlinRuntimeLibraryUtil.getLocalJar(JavaRuntimePresentationProvider.getRuntimeJar(library)); + VirtualFile jsLibJar = KotlinRuntimeLibraryUtil.getLocalJar(JSLibraryStdPresentationProvider.getJsStdLibJar(library)); + return badRoots.contains(runtimeJar) || badRoots.contains(jsLibJar); } }); @@ -161,8 +163,7 @@ public class UnsupportedAbiVersionNotificationPanelProvider extends EditorNotifi DumbService.getInstance(project).tryRunReadActionInSmartMode(new Computable() { @Override public Object compute() { - Collection badRoots = - KotlinRuntimeLibraryUtil.getLibraryRootsWithAbiIncompatibleKotlinClasses(project); + Collection badRoots = collectBadRoots(project); assert !badRoots.isEmpty() : "This action should only be called when bad roots are present"; LibraryRootsPopupModel listPopupModel = new LibraryRootsPopupModel("Unsupported format", project, badRoots); @@ -272,4 +273,10 @@ public class UnsupportedAbiVersionNotificationPanelProvider extends EditorNotifi }); } + @NotNull + private static Collection collectBadRoots(@NotNull Project project) { + Collection badRoots = KotlinRuntimeLibraryUtil.getLibraryRootsWithAbiIncompatibleKotlinClasses(project); + badRoots.addAll(KotlinRuntimeLibraryUtil.getLibraryRootsWithAbiIncompatibleForKotlinJs(project)); + return badRoots; + } }