diff --git a/java/execution/impl/src/com/intellij/execution/AlternativeSdkRootsProvider.kt b/java/execution/impl/src/com/intellij/execution/AlternativeSdkRootsProvider.kt index 790285a0f981..1dfb73336b9f 100644 --- a/java/execution/impl/src/com/intellij/execution/AlternativeSdkRootsProvider.kt +++ b/java/execution/impl/src/com/intellij/execution/AlternativeSdkRootsProvider.kt @@ -7,6 +7,7 @@ import com.intellij.openapi.project.Project import com.intellij.openapi.projectRoots.ProjectJdkTable import com.intellij.openapi.projectRoots.Sdk import com.intellij.openapi.roots.AdditionalLibraryRootsProvider +import com.intellij.openapi.roots.JavaSyntheticLibrary import com.intellij.openapi.roots.OrderRootType import com.intellij.openapi.roots.SyntheticLibrary import com.intellij.openapi.roots.ex.ProjectRootManagerEx @@ -14,7 +15,6 @@ import com.intellij.openapi.util.EmptyRunnable import com.intellij.openapi.util.registry.Registry import com.intellij.openapi.vfs.VirtualFile import com.intellij.ui.AppUIUtil -import java.util.* /** * @author egor @@ -28,20 +28,17 @@ class AlternativeSdkRootsProvider : AdditionalLibraryRootsProvider() { .mapNotNull { it.alternativeJrePath } .mapNotNull { ProjectJdkTable.getInstance().findJdk(it) } .distinct() - .map { SdkSyntheticLibrary(it) } + .map { createSdkLibrary(it) } .toList() } return emptyList() } - class SdkSyntheticLibrary(val sdk: Sdk) : SyntheticLibrary() { - override fun getSourceRoots(): Collection = sdk.rootProvider.getFiles(OrderRootType.SOURCES).toList() - - override fun getBinaryRoots(): Collection = sdk.rootProvider.getFiles(OrderRootType.CLASSES).toList() - - override fun equals(other: Any?) = other is SdkSyntheticLibrary && sourceRoots == other.sourceRoots && binaryRoots == other.binaryRoots - - override fun hashCode() = Objects.hash(sourceRoots, binaryRoots) + private fun createSdkLibrary(sdk: Sdk): JavaSyntheticLibrary { + return JavaSyntheticLibrary(sdk.rootProvider.getFiles(OrderRootType.SOURCES).toList(), + sdk.rootProvider.getFiles(OrderRootType.CLASSES).toList(), + emptySet(), + null) } companion object { diff --git a/java/java-tests/testSrc/com/intellij/java/openapi/roots/impl/DirectoryIndexTest.java b/java/java-tests/testSrc/com/intellij/java/openapi/roots/impl/DirectoryIndexTest.java index a1fd9d1340cf..ec59c1e882b6 100644 --- a/java/java-tests/testSrc/com/intellij/java/openapi/roots/impl/DirectoryIndexTest.java +++ b/java/java-tests/testSrc/com/intellij/java/openapi/roots/impl/DirectoryIndexTest.java @@ -171,9 +171,10 @@ public class DirectoryIndexTest extends DirectoryIndexTestCase { @Override public Collection getAdditionalProjectLibraries(@NotNull Project project) { return myProject == project ? Collections.singletonList( - SyntheticLibrary.newImmutableLibrary(ContainerUtil.newArrayList(myLibAdditionalClsDir, myLibAdditionalOutsideClsDir), - ContainerUtil.newArrayList(myLibAdditionalSrcDir, myLibAdditionalOutsideSrcDir), - ContainerUtil.newHashSet(myLibAdditionalExcludedDir, myLibAdditionalOutsideExcludedDir), null) + new JavaSyntheticLibrary(ContainerUtil.newArrayList(myLibAdditionalSrcDir, myLibAdditionalOutsideSrcDir), + ContainerUtil.newArrayList(myLibAdditionalClsDir, myLibAdditionalOutsideClsDir), + ContainerUtil.newHashSet(myLibAdditionalExcludedDir, myLibAdditionalOutsideExcludedDir), + null) ) : Collections.emptyList(); } }, getTestRootDisposable()); diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/ImmutableSyntheticLibrary.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/ImmutableSyntheticLibrary.java new file mode 100644 index 000000000000..7751f82b27d9 --- /dev/null +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/ImmutableSyntheticLibrary.java @@ -0,0 +1,74 @@ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.openapi.roots; + +import com.intellij.openapi.util.Condition; +import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Collection; +import java.util.Objects; +import java.util.Set; + +class ImmutableSyntheticLibrary extends SyntheticLibrary { + + private final Collection myBinaryRoots; + private final Collection mySourceRoots; + private final Set myExcludedRoots; + private final Condition myExcludeCondition; + + ImmutableSyntheticLibrary(@NotNull Collection sourceRoots, + @NotNull Collection binaryRoots, + @NotNull Set excludedRoots, + @Nullable Condition excludeCondition) { + mySourceRoots = sourceRoots; + myBinaryRoots = binaryRoots; + myExcludedRoots = excludedRoots; + myExcludeCondition = excludeCondition; + } + + @NotNull + @Override + public Collection getSourceRoots() { + return mySourceRoots; + } + + @NotNull + @Override + public Collection getBinaryRoots() { + return myBinaryRoots; + } + + @NotNull + @Override + public Set getExcludedRoots() { + return myExcludedRoots; + } + + @Nullable + @Override + public Condition getExcludeFileCondition() { + return myExcludeCondition; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ImmutableSyntheticLibrary library = (ImmutableSyntheticLibrary)o; + if (!mySourceRoots.equals(library.getSourceRoots())) return false; + if (!myBinaryRoots.equals(library.getBinaryRoots())) return false; + if (!myExcludedRoots.equals(library.getExcludedRoots())) return false; + if (!Objects.equals(myExcludeCondition, library.getExcludeFileCondition())) return false; + return true; + } + + @Override + public int hashCode() { + int result = mySourceRoots.hashCode(); + result = 31 * result + myBinaryRoots.hashCode(); + result = 31 * result + myExcludedRoots.hashCode(); + result = 31 * result + (myExcludeCondition != null ? myExcludeCondition.hashCode() : 0); + return result; + } +} diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/JavaSyntheticLibrary.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/JavaSyntheticLibrary.java new file mode 100644 index 000000000000..0949ed76b2e2 --- /dev/null +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/JavaSyntheticLibrary.java @@ -0,0 +1,20 @@ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.openapi.roots; + +import com.intellij.openapi.util.Condition; +import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Collection; +import java.util.Set; + +public class JavaSyntheticLibrary extends ImmutableSyntheticLibrary { + + public JavaSyntheticLibrary(@NotNull Collection sourceRoots, + @NotNull Collection binaryRoots, + @NotNull Set excludedRoots, + @Nullable Condition excludeCondition) { + super(sourceRoots, binaryRoots, excludedRoots, excludeCondition); + } +} diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/SyntheticLibrary.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/SyntheticLibrary.java index 83f357697907..dcc962b6f168 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/roots/SyntheticLibrary.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/SyntheticLibrary.java @@ -14,7 +14,6 @@ import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.Collections; -import java.util.Objects; import java.util.Set; import static com.intellij.util.containers.ContainerUtil.newTroveSet; @@ -113,60 +112,15 @@ public abstract class SyntheticLibrary { public static SyntheticLibrary newImmutableLibrary(@NotNull Collection sourceRoots, @NotNull Set excludedRoots, @Nullable Condition excludeCondition) { - return newImmutableLibrary(Collections.emptySet(), sourceRoots, excludedRoots, excludeCondition); + return newImmutableLibrary(sourceRoots, Collections.emptySet(), excludedRoots, excludeCondition); } @NotNull - public static SyntheticLibrary newImmutableLibrary(@NotNull Collection binaryRoots, - @NotNull Collection sourceRoots, + public static SyntheticLibrary newImmutableLibrary(@NotNull Collection sourceRoots, + @NotNull Collection binaryRoots, @NotNull Set excludedRoots, @Nullable Condition excludeCondition) { - return new SyntheticLibrary() { - @NotNull - @Override - public Collection getSourceRoots() { - return sourceRoots; - } - - @NotNull - @Override - public Collection getBinaryRoots() { - return binaryRoots; - } - - @NotNull - @Override - public Set getExcludedRoots() { - return excludedRoots; - } - - @Nullable - @Override - public Condition getExcludeFileCondition() { - return excludeCondition; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - SyntheticLibrary library = (SyntheticLibrary)o; - if (!sourceRoots.equals(library.getSourceRoots())) return false; - if (!binaryRoots.equals(library.getBinaryRoots())) return false; - if (!excludedRoots.equals(library.getExcludedRoots())) return false; - if (!Objects.equals(excludeCondition, library.getExcludeFileCondition())) return false; - return true; - } - - @Override - public int hashCode() { - int result = sourceRoots.hashCode(); - result = 31 * result + binaryRoots.hashCode(); - result = 31 * result + excludedRoots.hashCode(); - result = 31 * result + (excludeCondition != null ? excludeCondition.hashCode() : 0); - return result; - } - }; + return new ImmutableSyntheticLibrary(sourceRoots, binaryRoots, excludedRoots, excludeCondition); } @NotNull diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootIndex.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootIndex.java index 9c4256875c78..14895691778f 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootIndex.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/RootIndex.java @@ -200,7 +200,9 @@ public class RootIndex { info.libraryOrSdkSources.add(sourceRoot); info.classAndSourceRoots.add(sourceRoot); - info.packagePrefix.put(sourceRoot, ""); + if (descriptor instanceof JavaSyntheticLibrary) { + info.packagePrefix.put(sourceRoot, ""); + } info.sourceOfLibraries.putValue(sourceRoot, descriptor); } for (VirtualFile classRoot : descriptor.getBinaryRoots()) { @@ -208,7 +210,9 @@ public class RootIndex { info.libraryOrSdkClasses.add(classRoot); info.classAndSourceRoots.add(classRoot); - info.packagePrefix.put(classRoot, ""); + if (descriptor instanceof JavaSyntheticLibrary) { + info.packagePrefix.put(classRoot, ""); + } info.classOfLibraries.putValue(classRoot, descriptor); } for (VirtualFile file : descriptor.getExcludedRoots()) {