diff --git a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/JpsProjectLoader.java b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/JpsProjectLoader.java index 7a86bc3e9188..067ff55008ff 100644 --- a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/JpsProjectLoader.java +++ b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/JpsProjectLoader.java @@ -1,4 +1,4 @@ -// Copyright 2000-2019 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. +// Copyright 2000-2020 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 org.jetbrains.jps.model.serialization; import com.intellij.openapi.diagnostic.Logger; @@ -9,7 +9,7 @@ import com.intellij.openapi.util.io.FileUtilRt; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.concurrency.AppExecutorUtil; import com.intellij.util.containers.ContainerUtil; -import gnu.trove.THashSet; +import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import org.jdom.Element; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -45,7 +45,7 @@ import java.util.*; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; -public class JpsProjectLoader extends JpsLoaderBase { +public final class JpsProjectLoader extends JpsLoaderBase { public static final String MODULE_MANAGER_COMPONENT = "ProjectModuleManager"; public static final String MODULES_TAG = "modules"; public static final String MODULE_TAG = "module"; @@ -306,7 +306,7 @@ public class JpsProjectLoader extends JpsLoaderBase { } } - final Set foundFiles = new THashSet<>(); + final Set foundFiles = new ObjectOpenHashSet<>(); final List moduleFiles = new ArrayList<>(); for (Element moduleElement : JDOMUtil.getChildren(componentElement.getChild(MODULES_TAG), MODULE_TAG)) { final String path = moduleElement.getAttributeValue(FILE_PATH_ATTRIBUTE); diff --git a/platform/configuration-store-impl/src/StateStorageManagerImpl.kt b/platform/configuration-store-impl/src/StateStorageManagerImpl.kt index 4f82a392a348..9f627e6b455d 100644 --- a/platform/configuration-store-impl/src/StateStorageManagerImpl.kt +++ b/platform/configuration-store-impl/src/StateStorageManagerImpl.kt @@ -17,7 +17,6 @@ import com.intellij.util.SmartList import com.intellij.util.ThreeState import com.intellij.util.containers.ContainerUtil import com.intellij.util.io.systemIndependentPath -import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap import org.jdom.Element import org.jetbrains.annotations.TestOnly import java.io.IOException @@ -39,7 +38,7 @@ open class StateStorageManagerImpl(private val rootTagName: String, private val virtualFileTracker: StorageVirtualFileTracker? = createDefaultVirtualTracker(componentManager)) : StateStorageManager { private val macros: MutableList = ContainerUtil.createLockFreeCopyOnWriteList() private val storageLock = ReentrantReadWriteLock() - private val storages = Object2ObjectOpenHashMap() + private val storages = HashMap() val compoundStreamProvider: CompoundStreamProvider = CompoundStreamProvider() diff --git a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileContentChangeEvent.java b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileContentChangeEvent.java index 55b3840e3319..59d074a9afce 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileContentChangeEvent.java +++ b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileContentChangeEvent.java @@ -7,7 +7,7 @@ import com.intellij.util.LocalTimeCounter; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; -public class VFileContentChangeEvent extends VFileEvent { +public final class VFileContentChangeEvent extends VFileEvent { private final VirtualFile myFile; private final long myOldModificationStamp; private final long myNewModificationStamp; diff --git a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileCopyEvent.java b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileCopyEvent.java index 46841f0d5dde..acb75ac38c25 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileCopyEvent.java +++ b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileCopyEvent.java @@ -7,7 +7,7 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public class VFileCopyEvent extends VFileEvent { +public final class VFileCopyEvent extends VFileEvent { private final VirtualFile myFile; private final VirtualFile myNewParent; private final String myNewChildName; diff --git a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileCreateEvent.java b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileCreateEvent.java index 5ae34c6d4634..420a98bc8059 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileCreateEvent.java +++ b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileCreateEvent.java @@ -9,7 +9,7 @@ import com.intellij.openapi.vfs.VirtualFileSystem; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public class VFileCreateEvent extends VFileEvent { +public final class VFileCreateEvent extends VFileEvent { private final @NotNull VirtualFile myParent; private final boolean myDirectory; private final FileAttributes myAttributes; diff --git a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileDeleteEvent.java b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileDeleteEvent.java index c38ceb870cab..4f1af3429d8b 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileDeleteEvent.java +++ b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileDeleteEvent.java @@ -7,7 +7,7 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public class VFileDeleteEvent extends VFileEvent { +public final class VFileDeleteEvent extends VFileEvent { @NotNull private final VirtualFile myFile; public VFileDeleteEvent(@Nullable Object requestor, @NotNull VirtualFile file, boolean isFromRefresh) { diff --git a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileMoveEvent.java b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileMoveEvent.java index 6dd252ea1ebe..86867ff63bff 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileMoveEvent.java +++ b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFileMoveEvent.java @@ -7,7 +7,7 @@ import com.intellij.openapi.vfs.VirtualFileSystem; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; -public class VFileMoveEvent extends VFileEvent { +public final class VFileMoveEvent extends VFileEvent { private final VirtualFile myFile; private final VirtualFile myOldParent; private final VirtualFile myNewParent; diff --git a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFilePropertyChangeEvent.java b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFilePropertyChangeEvent.java index dcd311bb4c1f..2e1446d2512c 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFilePropertyChangeEvent.java +++ b/platform/core-api/src/com/intellij/openapi/vfs/newvfs/events/VFilePropertyChangeEvent.java @@ -12,7 +12,7 @@ import org.jetbrains.annotations.Nullable; import java.nio.charset.Charset; import java.util.Objects; -public class VFilePropertyChangeEvent extends VFileEvent { +public final class VFilePropertyChangeEvent extends VFileEvent { private final VirtualFile myFile; private final String myPropertyName; private final Object myOldValue; diff --git a/platform/credential-store/src/kdbx/KdbxGroup.kt b/platform/credential-store/src/kdbx/KdbxGroup.kt index a7bfe1aaaec9..3ba8f0b981e3 100644 --- a/platform/credential-store/src/kdbx/KdbxGroup.kt +++ b/platform/credential-store/src/kdbx/KdbxGroup.kt @@ -1,10 +1,9 @@ -// Copyright 2000-2019 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. +// Copyright 2000-2020 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.credentialStore.kdbx import com.intellij.credentialStore.LOG import com.intellij.util.containers.ContainerUtil import com.intellij.util.getOrCreate -import gnu.trove.THashMap import org.jdom.Element import java.time.Instant import java.time.LocalDateTime @@ -27,7 +26,7 @@ internal class KdbxGroup(internal val element: Element, private val database: Ke database.isDirty = true } - private val groups: MutableMap = THashMap() + private val groups: MutableMap = HashMap() private val entries: MutableList by lazy { ContainerUtil.createLockFreeCopyOnWriteList(element.getChildren(KdbxDbElementNames.entry).map { KdbxEntry(it, database, this) }) } diff --git a/platform/credential-store/src/macOsKeychainLibrary.kt b/platform/credential-store/src/macOsKeychainLibrary.kt index 5488d807710f..23de37e00730 100644 --- a/platform/credential-store/src/macOsKeychainLibrary.kt +++ b/platform/credential-store/src/macOsKeychainLibrary.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2019 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. +// Copyright 2000-2020 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.credentialStore import com.intellij.openapi.util.SystemInfo @@ -7,7 +7,8 @@ import com.intellij.util.text.nullize import com.sun.jna.* import com.sun.jna.ptr.IntByReference import com.sun.jna.ptr.PointerByReference -import gnu.trove.TIntObjectHashMap +import it.unimi.dsi.fastutil.ints.Int2ObjectMap +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap val isMacOsCredentialStoreSupported: Boolean get() = SystemInfo.isMacIntel64 && SystemInfo.isMacOSLeopard @@ -71,7 +72,7 @@ internal class KeyChainCredentialStore : CredentialStore { } else { val buf = CharArray(library.CFStringGetLength(translated).toInt()) - for (i in 0 until buf.size) { + for (i in buf.indices) { buf[i] = library.CFStringGetCharacterAtIndex(translated, i.toLong()) } library.CFRelease(translated) @@ -233,8 +234,8 @@ internal class SecKeychainAttribute : Structure, Structure.ByReference { internal constructor() : super() } -private fun readAttributes(list: SecKeychainAttributeList): TIntObjectHashMap { - val map = TIntObjectHashMap() +private fun readAttributes(list: SecKeychainAttributeList): Int2ObjectMap { + val map = Int2ObjectOpenHashMap() val attrList = SecKeychainAttribute(list.attr!!) attrList.read() @Suppress("UNCHECKED_CAST") diff --git a/platform/credential-store/test/keePass/KeePassCredentialStoreTest.kt b/platform/credential-store/test/keePass/KeePassCredentialStoreTest.kt index 73b06ccedeb7..977b55ab2900 100644 --- a/platform/credential-store/test/keePass/KeePassCredentialStoreTest.kt +++ b/platform/credential-store/test/keePass/KeePassCredentialStoreTest.kt @@ -1,11 +1,10 @@ -// Copyright 2000-2019 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. +// Copyright 2000-2020 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.credentialStore.keePass import com.intellij.credentialStore.* import com.intellij.credentialStore.kdbx.IncorrectMasterPasswordException import com.intellij.testFramework.TemporaryDirectory import com.intellij.util.io.delete -import gnu.trove.THashMap import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThatThrownBy import org.junit.Rule @@ -49,7 +48,7 @@ class KeePassCredentialStoreTest { var provider = createStore(baseDir) assertThat(baseDir).doesNotExist() - val credentialMap = THashMap() + val credentialMap = HashMap() for (i in 0..9) { val accountName = randomString() val attributes = CredentialAttributes(randomString(), accountName) diff --git a/platform/lvcs-impl/src/com/intellij/history/core/ChangeListStorage.java b/platform/lvcs-impl/src/com/intellij/history/core/ChangeListStorage.java index c589f23a25a9..2094995d4f66 100644 --- a/platform/lvcs-impl/src/com/intellij/history/core/ChangeListStorage.java +++ b/platform/lvcs-impl/src/com/intellij/history/core/ChangeListStorage.java @@ -1,19 +1,4 @@ -/* - * Copyright 2000-2010 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. - */ - +// Copyright 2000-2020 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.history.core; import com.intellij.history.core.changes.ChangeSet; diff --git a/platform/platform-api/src/com/intellij/util/net/HttpConfigurable.java b/platform/platform-api/src/com/intellij/util/net/HttpConfigurable.java index ecc5f5eb9875..db12b2bcbb0c 100644 --- a/platform/platform-api/src/com/intellij/util/net/HttpConfigurable.java +++ b/platform/platform-api/src/com/intellij/util/net/HttpConfigurable.java @@ -33,7 +33,6 @@ import com.intellij.util.proxy.PropertiesEncryptionSupport; import com.intellij.util.proxy.SharedProxyConfig; import com.intellij.util.xmlb.XmlSerializerUtil; import com.intellij.util.xmlb.annotations.Transient; -import it.unimi.dsi.fastutil.objects.*; import org.jdom.Element; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Contract; @@ -68,8 +67,8 @@ public class HttpConfigurable implements PersistentStateComponent myGenericPasswords = new Object2ObjectOpenHashMap<>(); - private final Set myGenericCancelled = new ObjectOpenHashSet<>(); + private final Map myGenericPasswords = new HashMap<>(); + private final Set myGenericCancelled = new HashSet<>(); public String PROXY_EXCEPTIONS; public boolean USE_PAC_URL; @@ -169,12 +168,7 @@ public class HttpConfigurable implements PersistentStateComponent> iterator = Object2ObjectMaps.fastIterator(to.myGenericPasswords); iterator.hasNext(); ) { - Object2ObjectMap.Entry entry = iterator.next(); - if (!entry.getValue().isStore()) { - iterator.remove(); - } - } + to.myGenericPasswords.values().removeIf(it -> !it.isStore()); } } diff --git a/platform/platform-impl/src/com/intellij/idea/SocketLock.java b/platform/platform-impl/src/com/intellij/idea/SocketLock.java index f71b4c33ce69..7ed16be793e7 100644 --- a/platform/platform-impl/src/com/intellij/idea/SocketLock.java +++ b/platform/platform-impl/src/com/intellij/idea/SocketLock.java @@ -19,9 +19,6 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufOutputStream; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import it.unimi.dsi.fastutil.ints.Int2ObjectMaps; -import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -152,13 +149,13 @@ public final class SocketLock { lockPortFiles(); - Int2ObjectOpenHashMap> portToPath = new Int2ObjectOpenHashMap<>(2); + Map> portToPath = new HashMap<>(); readPort(myConfigPath, portToPath); readPort(mySystemPath, portToPath); if (!portToPath.isEmpty()) { args = JetBrainsProtocolHandler.checkForJetBrainsProtocolCommand(args); - for (Int2ObjectMap.Entry> entry : Int2ObjectMaps.fastIterable(portToPath)) { - Map.Entry status = tryActivate(entry.getIntKey(), entry.getValue(), args); + for (Map.Entry> entry : portToPath.entrySet()) { + Map.Entry status = tryActivate(entry.getKey(), entry.getValue(), args); if (status.getKey() != ActivationStatus.NO_INSTANCE) { log("exit: lock(): " + status.getValue()); unlockPortFiles(); @@ -251,15 +248,9 @@ public final class SocketLock { } } - private static void readPort(@NotNull Path dir, @NotNull Int2ObjectOpenHashMap> portToPath) { + private static void readPort(@NotNull Path dir, @NotNull Map> portToPath) { try { - int port = Integer.parseInt(readOneLine(dir.resolve(PORT_FILE))); - List list = portToPath.get(port); - if (list == null) { - list = new ArrayList<>(); - portToPath.put(port, list); - } - list.add(dir.toString()); + portToPath.computeIfAbsent(Integer.parseInt(readOneLine(dir.resolve(PORT_FILE))), it -> new ArrayList<>()).add(dir.toString()); } catch (NoSuchFileException ignore) { } diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java index 9cfc29e6a1d3..fde44e8a7056 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java @@ -31,6 +31,7 @@ import com.intellij.util.text.CharSequenceHashingStrategy; import gnu.trove.THashSet; import gnu.trove.TIntArrayList; import gnu.trove.TIntHashSet; +import it.unimi.dsi.fastutil.ints.IntSet; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -601,7 +602,7 @@ public class VirtualDirectoryImpl extends VirtualFileSystemEntry { } // optimization: faster than forEach(this::removeChild) - public void removeChildren(@NotNull TIntHashSet idsToRemove, @NotNull List namesToRemove) { + public void removeChildren(@NotNull IntSet idsToRemove, @NotNull List namesToRemove) { boolean caseSensitive = getFileSystem().isCaseSensitive(); synchronized (myData) { // remove from array by merging two sorted lists diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/LocalFileSystemRefreshWorker.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/LocalFileSystemRefreshWorker.java index a84fba7fc432..104624d1b4a1 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/LocalFileSystemRefreshWorker.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/LocalFileSystemRefreshWorker.java @@ -16,12 +16,9 @@ import com.intellij.openapi.vfs.newvfs.NewVirtualFileSystem; import com.intellij.openapi.vfs.newvfs.events.VFileEvent; import com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl; import com.intellij.util.concurrency.AppExecutorUtil; +import com.intellij.util.containers.CollectionFactory; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.Queue; -import com.intellij.util.text.FilePathHashingStrategy; -import gnu.trove.THashMap; -import gnu.trove.THashSet; -import gnu.trove.TObjectHashingStrategy; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.TestOnly; @@ -34,10 +31,9 @@ import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; -import static com.intellij.openapi.util.Pair.pair; import static com.intellij.openapi.vfs.newvfs.persistent.VfsEventGenerationHelper.LOG; -class LocalFileSystemRefreshWorker { +final class LocalFileSystemRefreshWorker { private final boolean myIsRecursive; private final NewVirtualFile myRefreshRoot; private final VfsEventGenerationHelper myHelper = new VfsEventGenerationHelper(); @@ -74,21 +70,19 @@ class LocalFileSystemRefreshWorker { fs = PersistentFS.replaceWithNativeFS(fs); } - RefreshContext context = createRefreshContext(fs, PersistentFS.getInstance(), FilePathHashingStrategy.create(fs.isCaseSensitive())); + RefreshContext context = createRefreshContext(fs, PersistentFS.getInstance(), fs.isCaseSensitive()); context.submitRefreshRequest(() -> processFile(root, context)); context.waitForRefreshToFinish(); } - @NotNull - private RefreshContext createRefreshContext(@NotNull NewVirtualFileSystem fs, - @NotNull PersistentFS persistentFS, - @NotNull TObjectHashingStrategy strategy) { + private @NotNull RefreshContext createRefreshContext(@NotNull NewVirtualFileSystem fs, + @NotNull PersistentFS persistentFS, + boolean isFsCaseSensitive) { int parallelism = Registry.intValue("vfs.use.nio-based.local.refresh.worker.parallelism", Runtime.getRuntime().availableProcessors() - 1); - if (myIsRecursive && parallelism > 0 && !ApplicationManager.getApplication().isDispatchThread()) { - return new ConcurrentRefreshContext(fs, persistentFS, strategy, parallelism); + return new ConcurrentRefreshContext(fs, persistentFS, isFsCaseSensitive, parallelism); } - return new SequentialRefreshContext(fs, persistentFS, strategy); + return new SequentialRefreshContext(fs, persistentFS, isFsCaseSensitive); } private void processFile(@NotNull NewVirtualFile file, @NotNull RefreshContext refreshContext) { @@ -121,13 +115,13 @@ class LocalFileSystemRefreshWorker { private abstract static class RefreshContext { final NewVirtualFileSystem fs; final PersistentFS persistence; - final TObjectHashingStrategy strategy; + final boolean isFsCaseSensitive; final BlockingQueue filesToBecomeDirty = new LinkedBlockingQueue<>(); - RefreshContext(@NotNull NewVirtualFileSystem fs, @NotNull PersistentFS persistence, @NotNull TObjectHashingStrategy strategy) { + RefreshContext(@NotNull NewVirtualFileSystem fs, @NotNull PersistentFS persistence, boolean isFsCaseSensitive) { this.fs = fs; this.persistence = persistence; - this.strategy = strategy; + this.isFsCaseSensitive = isFsCaseSensitive; } abstract void submitRefreshRequest(@NotNull Runnable action); @@ -193,7 +187,7 @@ class LocalFileSystemRefreshWorker { return null; } VirtualFile[] children = dir.getChildren(); - return pair(getNames(children), Arrays.asList(children)); + return new Pair<>(getNames(children), Arrays.asList(children)); }); } @@ -209,7 +203,7 @@ class LocalFileSystemRefreshWorker { private void partialDirRefresh(@NotNull VirtualDirectoryImpl dir, @NotNull RefreshContext refreshContext) { while (true) { // obtaining directory snapshot - Pair, List> result = ReadAction.compute(() -> pair(dir.getCachedChildren(), dir.getSuspiciousNames())); + Pair, List> result = ReadAction.compute(() -> new Pair<>(dir.getCachedChildren(), dir.getSuspiciousNames())); List cached = result.getFirst(); List wanted = result.getSecond(); @@ -269,8 +263,8 @@ class LocalFileSystemRefreshWorker { private static class SequentialRefreshContext extends RefreshContext { private final Queue myRefreshRequests = new Queue<>(100); - SequentialRefreshContext(@NotNull NewVirtualFileSystem fs, @NotNull PersistentFS persistentFS, @NotNull TObjectHashingStrategy strategy) { - super(fs, persistentFS, strategy); + SequentialRefreshContext(@NotNull NewVirtualFileSystem fs, @NotNull PersistentFS persistentFS, boolean isFsCaseSensitive) { + super(fs, persistentFS, isFsCaseSensitive); } @Override @@ -286,16 +280,16 @@ class LocalFileSystemRefreshWorker { } } - private static class ConcurrentRefreshContext extends RefreshContext { + private static final class ConcurrentRefreshContext extends RefreshContext { private final ExecutorService service; private final AtomicInteger tasksScheduled = new AtomicInteger(); private final CountDownLatch refreshFinishedLatch = new CountDownLatch(1); ConcurrentRefreshContext(@NotNull NewVirtualFileSystem fs, @NotNull PersistentFS persistentFS, - @NotNull TObjectHashingStrategy strategy, + boolean isFsCaseSensitive, int parallelism) { - super(fs, persistentFS, strategy); + super(fs, persistentFS, isFsCaseSensitive); service = AppExecutorUtil.createBoundedApplicationPoolExecutor("Refresh Worker", parallelism); } @@ -325,7 +319,7 @@ class LocalFileSystemRefreshWorker { } } - private class RefreshingFileVisitor extends SimpleFileVisitor { + private final class RefreshingFileVisitor extends SimpleFileVisitor { private final VfsEventGenerationHelper myHelper = new VfsEventGenerationHelper(); private final Map myPersistentChildren; private final Set myChildrenWeAreInterested; // null - no limit @@ -339,13 +333,15 @@ class LocalFileSystemRefreshWorker { @NotNull Collection existingPersistentChildren) { myFileOrDir = fileOrDir; myRefreshContext = refreshContext; - myPersistentChildren = new THashMap<>(existingPersistentChildren.size(), refreshContext.strategy); - myChildrenWeAreInterested = childrenToRefresh == null ? null : new THashSet<>(childrenToRefresh, refreshContext.strategy); + myPersistentChildren = CollectionFactory.createFilePathMap(existingPersistentChildren.size(), refreshContext.isFsCaseSensitive); + myChildrenWeAreInterested = childrenToRefresh == null ? null : CollectionFactory.createFilePathSet(childrenToRefresh, refreshContext.isFsCaseSensitive); for (VirtualFile child : existingPersistentChildren) { String name = child.getName(); myPersistentChildren.put(name, child); - if (myChildrenWeAreInterested != null) myChildrenWeAreInterested.add(name); + if (myChildrenWeAreInterested != null) { + myChildrenWeAreInterested.add(name); + } } } diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java index 68fcbbafa11a..d6cffd979f5d 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java @@ -30,10 +30,10 @@ import com.intellij.util.*; import com.intellij.util.containers.*; import com.intellij.util.io.ReplicatorInputStream; import com.intellij.util.text.FilePathHashingStrategy; -import gnu.trove.THashMap; import gnu.trove.THashSet; -import gnu.trove.TIntHashSet; import gnu.trove.TObjectHashingStrategy; +import it.unimi.dsi.fastutil.ints.IntOpenHashSet; +import it.unimi.dsi.fastutil.ints.IntSet; import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -600,7 +600,7 @@ public final class PersistentFSImpl extends PersistentFS implements Disposable { } } - private static long reloadLengthFromDelegate(@NotNull VirtualFile file, @NotNull NewVirtualFileSystem delegate) { + private static long reloadLengthFromDelegate(@NotNull VirtualFile file, @NotNull FileSystemInterface delegate) { final long len = delegate.getLength(file); FSRecords.setLength(getFileId(file), len); return len; @@ -738,7 +738,7 @@ public final class PersistentFSImpl extends PersistentFS implements Disposable { private static int groupByPath(@NotNull List events, int startIndex, @NotNull MostlySingularMultiMap filesInvolved, - @NotNull Set middleDirsInvolved, + @NotNull Set middleDirsInvolved, @NotNull Set deletedPaths, @NotNull Set createdPaths, @NotNull Set eventsToRemove) { @@ -813,9 +813,15 @@ public final class PersistentFSImpl extends PersistentFS implements Disposable { private static boolean checkIfConflictingPaths(@NotNull VFileEvent event, @NotNull String path, @NotNull MostlySingularMultiMap files, - @NotNull Set middleDirs) { - Iterable stored = files.get(path); - if (!canReconcileEvents(event, stored)) { + @NotNull Set middleDirs) { + boolean canReconcileEvents = true; + for (VFileEvent t : files.get(path)) { + if (!(isContentChangeLikeHarmlessEvent(event) && isContentChangeLikeHarmlessEvent(t))) { + canReconcileEvents = false; + break; + } + } + if (!canReconcileEvents) { // conflicting event found for (non-strict) descendant, stop return true; } @@ -840,15 +846,6 @@ public final class PersistentFSImpl extends PersistentFS implements Disposable { return false; } - // true if {@code event} and events in {@code stored} can be applied in one batch. E.g. "content change" and {"writable property change", "content change"} - private static boolean canReconcileEvents(@NotNull VFileEvent event, @NotNull Iterable stored) { - return ContainerUtil.and(stored, e->canReconcile(event, e)); - } - - private static boolean canReconcile(@NotNull VFileEvent event1, @NotNull VFileEvent event2) { - return isContentChangeLikeHarmlessEvent(event1) && isContentChangeLikeHarmlessEvent(event2); - } - private static boolean isContentChangeLikeHarmlessEvent(@NotNull VFileEvent event1) { return event1 instanceof VFileContentChangeEvent || event1 instanceof VFilePropertyChangeEvent && (((VFilePropertyChangeEvent)event1).getPropertyName().equals(VirtualFile.PROP_WRITABLE) @@ -864,7 +861,7 @@ public final class PersistentFSImpl extends PersistentFS implements Disposable { @NotNull List outApplyEvents, @NotNull List outValidatedEvents, @NotNull MostlySingularMultiMap filesInvolved, - @NotNull Set middleDirsInvolved) { + @NotNull Set middleDirsInvolved) { Set toIgnore = new ReferenceOpenHashSet<>(); // VFileEvents override equals() int endIndex = groupByPath(events, startIndex, filesInvolved, middleDirsInvolved, CollectionFactory.createFilePathSet(), CollectionFactory.createFilePathSet(), toIgnore); @@ -975,14 +972,8 @@ public final class PersistentFSImpl extends PersistentFS implements Disposable { int startIndex = 0; int cappedInitialSize = Math.min(events.size(), INNER_ARRAYS_THRESHOLD); List applyEvents = new ArrayList<>(cappedInitialSize); - MostlySingularMultiMap files = new MostlySingularMultiMap(){ - @NotNull - @Override - protected Map createMap() { - return new THashMap<>(cappedInitialSize, FileUtil.PATH_HASHING_STRATEGY); - } - }; - Set middleDirs = new THashSet<>(cappedInitialSize, FileUtil.PATH_HASHING_STRATEGY); + MostlySingularMultiMap files = new MostlySingularMultiMap<>(CollectionFactory.createFilePathMap(cappedInitialSize)); + Set middleDirs = CollectionFactory.createFilePathSet(cappedInitialSize); List validated = new ArrayList<>(cappedInitialSize); BulkFileListener publisher = getPublisher(); while (startIndex != events.size()) { @@ -1022,7 +1013,7 @@ public final class PersistentFSImpl extends PersistentFS implements Disposable { int parentId = getFileId(parent); List childrenNamesDeleted = new ArrayList<>(deleteEvents.size()); - TIntHashSet childrenIdsDeleted = new TIntHashSet(deleteEvents.size()); + IntSet childrenIdsDeleted = new IntOpenHashSet(deleteEvents.size()); List deleted = new ArrayList<>(deleteEvents.size()); for (VFileDeleteEvent event : deleteEvents) { VirtualFile file = event.getFile(); @@ -1049,7 +1040,7 @@ public final class PersistentFSImpl extends PersistentFS implements Disposable { } private void applyCreateEventsInDirectory(@NotNull VirtualDirectoryImpl parent, - @NotNull Collection createEvents) { + @NotNull Collection createEvents) { int parentId = getFileId(parent); NewVirtualFile vf = findFileById(parentId); if (!(vf instanceof VirtualDirectoryImpl)) return; @@ -1074,7 +1065,7 @@ public final class PersistentFSImpl extends PersistentFS implements Disposable { saveScannedChildrenRecursively(createEvents, delegate, hashingStrategy); } - private static void saveScannedChildrenRecursively(@NotNull Collection createEvents, + private static void saveScannedChildrenRecursively(@NotNull Collection createEvents, @NotNull NewVirtualFileSystem delegate, @NotNull TObjectHashingStrategy hashingStrategy) { for (VFileCreateEvent createEvent : createEvents) { @@ -1494,19 +1485,19 @@ public final class PersistentFSImpl extends PersistentFS implements Disposable { final int newParentId = getFileId(newParent); final int oldParentId = getFileId(file.getParent()); - VirtualFileSystemEntry vfse = (VirtualFileSystemEntry)file; - NewVirtualFileSystem fileSystem = vfse.getFileSystem(); + VirtualFileSystemEntry virtualFileSystemEntry = (VirtualFileSystemEntry)file; + NewVirtualFileSystem fileSystem = virtualFileSystemEntry.getFileSystem(); removeIdFromChildren(oldParentId, fileId); FSRecords.setParent(fileId, newParentId); - ChildInfo newChild = new ChildInfoImpl(fileId, vfse.getNameId(), null, null, null); + ChildInfo newChild = new ChildInfoImpl(fileId, virtualFileSystemEntry.getNameId(), null, null, null); FSRecords.update(newParentId, children -> { // check that names are not duplicated ChildInfo duplicate = findExistingChildInfo(file.getName(), children.children, fileSystem); if (duplicate != null) return children; return children.insert(newChild); }); - vfse.setParent(newParent); + virtualFileSystemEntry.setParent(newParent); } @Override diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilPerformanceTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilPerformanceTest.java index 2fec3c30d9e5..807c099b7e8b 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilPerformanceTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilPerformanceTest.java @@ -1,4 +1,4 @@ -// Copyright 2000-2019 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. +// Copyright 2000-2020 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.vfs; import com.intellij.concurrency.JobLauncher; @@ -28,7 +28,7 @@ import com.intellij.util.ExceptionUtil; import com.intellij.util.ThrowableRunnable; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.UIUtil; -import gnu.trove.TIntHashSet; +import it.unimi.dsi.fastutil.ints.IntSortedSets; import org.junit.Rule; import org.junit.Test; @@ -331,7 +331,7 @@ public class VfsUtilPerformanceTest extends BareTestFixtureTestCase { }) .forEach(events::add); List names = ContainerUtil.map(events, e -> ((VFileCreateEvent)e).getChildName()); - temp.removeChildren(new TIntHashSet(), names); + temp.removeChildren(IntSortedSets.EMPTY_SET, names); } private void eventsForDeleting(List events, VirtualDirectoryImpl temp) { diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/RemoteServersDeploymentManager.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/RemoteServersDeploymentManager.java index de79804165d0..4c0d228322fe 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/RemoteServersDeploymentManager.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/ui/RemoteServersDeploymentManager.java @@ -1,4 +1,4 @@ -// Copyright 2000-2019 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. +// Copyright 2000-2020 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.remoteServer.impl.runtime.ui; import com.intellij.execution.services.ServiceEventListener; @@ -19,17 +19,17 @@ import com.intellij.remoteServer.impl.runtime.ui.tree.ServersTreeStructure.Remot import com.intellij.remoteServer.runtime.*; import com.intellij.remoteServer.runtime.ui.RemoteServersView; import com.intellij.util.Alarm; -import com.intellij.util.containers.ContainerUtil; -import com.intellij.util.containers.SmartHashSet; +import com.intellij.util.containers.CollectionFactory; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; import java.util.Set; -public class RemoteServersDeploymentManager { +public final class RemoteServersDeploymentManager { private static final int POLL_DEPLOYMENTS_DELAY = 2000; public static RemoteServersDeploymentManager getInstance(Project project) { @@ -38,7 +38,7 @@ public class RemoteServersDeploymentManager { private final Project myProject; private final ServersTreeNodeSelector myNodeSelector; - private final Map myContributors = ContainerUtil.createConcurrentWeakMap(); + private final Map myContributors = CollectionFactory.createConcurrentWeakMap(); private final Map, MessagePanel> myServerToContent = new HashMap<>(); public RemoteServersDeploymentManager(@NotNull Project project) { @@ -52,7 +52,7 @@ public class RemoteServersDeploymentManager { private void initListeners() { myProject.getMessageBus().connect().subscribe(ServerConnectionListener.TOPIC, new ServerConnectionListener() { - private final Set> myConnectionsToExpand = new SmartHashSet<>(); + private final Set> myConnectionsToExpand = new HashSet<>(); @Override public void onConnectionCreated(@NotNull ServerConnection connection) { diff --git a/platform/util-ex/src/com/intellij/util/containers/util.kt b/platform/util-ex/src/com/intellij/util/containers/util.kt index 36094feeb145..8d37a81923cc 100644 --- a/platform/util-ex/src/com/intellij/util/containers/util.kt +++ b/platform/util-ex/src/com/intellij/util/containers/util.kt @@ -1,10 +1,9 @@ -// Copyright 2000-2019 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. +// Copyright 2000-2020 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.util.containers import com.intellij.openapi.diagnostic.Logger import com.intellij.util.SmartList import com.intellij.util.lang.CompoundRuntimeException -import gnu.trove.THashSet import java.util.* import java.util.stream.Stream @@ -146,12 +145,10 @@ inline fun Collection.mapSmart(transform: (T) -> R): List { inline fun Collection.mapSmartSet(transform: (T) -> R): Set { return when (val size = size) { 1 -> { - val result = SmartHashSet() - result.add(transform(first())) - result + Collections.singleton(transform(first())) } 0 -> emptySet() - else -> mapTo(THashSet(size), transform) + else -> mapTo(HashSet(size), transform) } } diff --git a/platform/util/src/com/intellij/util/containers/CollectionFactory.java b/platform/util/src/com/intellij/util/containers/CollectionFactory.java index dbf93329d86f..619d81698b55 100644 --- a/platform/util/src/com/intellij/util/containers/CollectionFactory.java +++ b/platform/util/src/com/intellij/util/containers/CollectionFactory.java @@ -88,6 +88,28 @@ public final class CollectionFactory { } } + public static @NotNull Set createFilePathSet(int expectedSize) { + return createFilePathSet(expectedSize, SystemInfoRt.isFileSystemCaseSensitive); + } + + public static @NotNull Set createFilePathSet(int expectedSize, boolean isFileSystemCaseSensitive) { + if (isFileSystemCaseSensitive) { + return new HashSet<>(expectedSize); + } + else { + return new ObjectOpenCustomHashSet<>(expectedSize, CaseInsensitiveStringHashingStrategy.INSTANCE); + } + } + + public static @NotNull Set createFilePathSet(@NotNull Collection paths, boolean isFileSystemCaseSensitive) { + if (isFileSystemCaseSensitive) { + return new HashSet<>(paths); + } + else { + return new ObjectOpenCustomHashSet<>(paths, CaseInsensitiveStringHashingStrategy.INSTANCE); + } + } + public static @NotNull Map createFilePathMap() { if (SystemInfoRt.isFileSystemCaseSensitive) { return new HashMap<>(); @@ -97,6 +119,19 @@ public final class CollectionFactory { } } + public static @NotNull Map createFilePathMap(int expectedSize) { + return createFilePathMap(expectedSize, SystemInfoRt.isFileSystemCaseSensitive); + } + + public static @NotNull Map createFilePathMap(int expectedSize, boolean isFileSystemCaseSensitive) { + if (isFileSystemCaseSensitive) { + return new HashMap<>(expectedSize); + } + else { + return new Object2ObjectOpenCustomHashMap<>(expectedSize, CaseInsensitiveStringHashingStrategy.INSTANCE); + } + } + public static @NotNull Map createFileMap() { return new Object2ObjectOpenCustomHashMap<>(FILE_HASH_STRATEGY); } diff --git a/platform/util/src/com/intellij/util/containers/ConcurrentMostlySingularMultiMap.java b/platform/util/src/com/intellij/util/containers/ConcurrentMostlySingularMultiMap.java index 492075607adc..4f59da42f1be 100644 --- a/platform/util/src/com/intellij/util/containers/ConcurrentMostlySingularMultiMap.java +++ b/platform/util/src/com/intellij/util/containers/ConcurrentMostlySingularMultiMap.java @@ -6,14 +6,12 @@ import org.jetbrains.annotations.NotNull; import java.util.Collection; import java.util.List; -import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -public class ConcurrentMostlySingularMultiMap extends MostlySingularMultiMap { - @Override - protected @NotNull Map createMap() { - return new ConcurrentHashMap<>(); +public final class ConcurrentMostlySingularMultiMap extends MostlySingularMultiMap { + public ConcurrentMostlySingularMultiMap() { + super(new ConcurrentHashMap<>()); } @Override @@ -22,17 +20,19 @@ public class ConcurrentMostlySingularMultiMap extends MostlySingularMultiM while (true) { Object current = map.get(key); if (current == null) { - if (ConcurrencyUtil.cacheOrGet(map, key, value) == value) break; + if (ConcurrencyUtil.cacheOrGet(map, key, value) == value) { + break; + } } else if (current instanceof MostlySingularMultiMap.ValueList) { - ValueList curList = (ValueList)current; - ValueList newList = new ValueList<>(curList.size() + 1); + List curList = (ValueList)current; + List newList = new ValueList<>(curList.size() + 1); newList.addAll(curList); newList.add(value); if (map.replace(key, curList, newList)) break; } else { - ValueList newList = new ValueList<>(2); + List newList = new ValueList<>(2); newList.add(current); newList.add(value); if (map.replace(key, current, newList)) break; @@ -63,7 +63,7 @@ public class ConcurrentMostlySingularMultiMap extends MostlySingularMultiM } @Override - public void addAll(MostlySingularMultiMap other) { + public void addAll(@NotNull MostlySingularMultiMap other) { throw new AbstractMethodError("Not yet re-implemented for concurrency"); } diff --git a/platform/util/src/com/intellij/util/containers/MostlySingularMultiMap.java b/platform/util/src/com/intellij/util/containers/MostlySingularMultiMap.java index 7991e30b037d..957a0e7fc91a 100644 --- a/platform/util/src/com/intellij/util/containers/MostlySingularMultiMap.java +++ b/platform/util/src/com/intellij/util/containers/MostlySingularMultiMap.java @@ -1,4 +1,4 @@ -// Copyright 2000-2019 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. +// Copyright 2000-2020 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. /* * @author max @@ -8,7 +8,8 @@ package com.intellij.util.containers; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.IncorrectOperationException; import com.intellij.util.Processor; -import gnu.trove.THashMap; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenCustomHashMap; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import org.jetbrains.annotations.Debug; import org.jetbrains.annotations.NotNull; @@ -22,12 +23,11 @@ public class MostlySingularMultiMap implements Serializable { protected final Map myMap; public MostlySingularMultiMap() { - myMap = createMap(); + myMap = new Object2ObjectOpenHashMap<>(); } - @NotNull - protected Map createMap() { - return new THashMap<>(); + public MostlySingularMultiMap(@NotNull Map map) { + myMap = map; } public void add(@NotNull K key, @NotNull V value) { @@ -37,11 +37,10 @@ public class MostlySingularMultiMap implements Serializable { } else if (current instanceof ValueList) { //noinspection unchecked - ValueList curList = (ValueList) current; - curList.add(value); + ((List)current).add(value); } else { - ValueList newList = new ValueList<>(); + List newList = new ValueList<>(); //noinspection unchecked newList.add((V)current); newList.add(value); @@ -54,17 +53,14 @@ public class MostlySingularMultiMap implements Serializable { if (current == null) { return false; } - if (current instanceof ValueList) { + else if (current instanceof ValueList) { //noinspection unchecked - ValueList curList = (ValueList) current; - return curList.remove(value); + return ((List)current).remove(value); } - - if (value.equals(current)) { + else if (value.equals(current)) { myMap.remove(key); return true; } - return false; } @@ -72,16 +68,15 @@ public class MostlySingularMultiMap implements Serializable { return myMap.remove(key) != null; } - @NotNull - public Set keySet() { + public final @NotNull Set keySet() { return myMap.keySet(); } - public boolean isEmpty() { + public final boolean isEmpty() { return myMap.isEmpty(); } - public boolean processForKey(@NotNull K key, @NotNull Processor p) { + public final boolean processForKey(@NotNull K key, @NotNull Processor p) { return processValue(p, myMap.get(key)); } @@ -89,64 +84,73 @@ public class MostlySingularMultiMap implements Serializable { if (v instanceof ValueList) { //noinspection unchecked for (V o : (ValueList)v) { - if (!p.process(o)) return false; + if (!p.process(o)) { + return false; + } } + return true; } - else if (v != null) { + else { //noinspection unchecked - return p.process((V)v); + return v == null || p.process((V)v); } - - return true; } public boolean processAllValues(@NotNull Processor p) { for (Object v : myMap.values()) { - if (!processValue(p, v)) return false; + if (!processValue(p, v)) { + return false; + } } - return true; } - public int size() { + public final int size() { return myMap.size(); } - public boolean containsKey(@NotNull K key) { + public final boolean containsKey(@NotNull K key) { return myMap.containsKey(key); } - public int valuesForKey(@NotNull K key) { + public final int valuesForKey(@NotNull K key) { Object current = myMap.get(key); - if (current == null) return 0; - if (current instanceof ValueList) { + if (current == null) { + return 0; + } + else if (current instanceof ValueList) { //noinspection unchecked return ((ValueList)current).size(); } return 1; } - @NotNull - public Iterable get(@NotNull K name) { - final Object value = myMap.get(name); - return rawValueToCollection(value); + public final @NotNull Iterable get(@NotNull K name) { + return rawValueToCollection(myMap.get(name)); } - @NotNull - protected List rawValueToCollection(Object value) { - if (value == null) return Collections.emptyList(); - - if (value instanceof ValueList) { + protected final @NotNull List rawValueToCollection(Object value) { + if (value == null) { + return Collections.emptyList(); + } + else if (value instanceof ValueList) { //noinspection unchecked return (ValueList)value; } - - //noinspection unchecked - return Collections.singletonList((V)value); + else { + //noinspection unchecked + return Collections.singletonList((V)value); + } } public void compact() { - ((THashMap)myMap).compact(); + if (myMap instanceof Object2ObjectOpenHashMap) { + ((Object2ObjectOpenHashMap)myMap).trim(); + } + else if (myMap instanceof Object2ObjectOpenCustomHashMap) { + ((Object2ObjectOpenCustomHashMap)myMap).trim(); + } + for (Object eachValue : myMap.values()) { if (eachValue instanceof ValueList) { //noinspection unchecked @@ -156,7 +160,7 @@ public class MostlySingularMultiMap implements Serializable { } @Override - public String toString() { + public final String toString() { return "{" + StringUtil.join(myMap.entrySet(), entry -> { Object value = entry.getValue(); String s = (value instanceof ValueList ? value : Collections.singletonList(value)).toString(); @@ -169,19 +173,15 @@ public class MostlySingularMultiMap implements Serializable { } @NotNull - public static MostlySingularMultiMap emptyMap() { + public static MostlySingularMultiMap emptyMap() { //noinspection unchecked - return (MostlySingularMultiMap)EMPTY; + return (MostlySingularMultiMap)EmptyMap.EMPTY; } - @NotNull - public static MostlySingularMultiMap newMap() { - return new MostlySingularMultiMap<>(); - } - private static final MostlySingularMultiMap EMPTY = new EmptyMap(); - - public void addAll(MostlySingularMultiMap other) { - if (other instanceof EmptyMap) return; + public void addAll(@NotNull MostlySingularMultiMap other) { + if (other.isEmpty()) { + return; + } for (Map.Entry entry : other.myMap.entrySet()) { K key = entry.getKey(); @@ -199,7 +199,7 @@ public class MostlySingularMultiMap implements Serializable { } else if (myValue instanceof ValueList) { //noinspection unchecked - ValueList myListValue = (ValueList)myValue; + List myListValue = (ValueList)myValue; if (otherValue instanceof ValueList) { //noinspection unchecked myListValue.addAll((ValueList)otherValue); @@ -212,15 +212,15 @@ public class MostlySingularMultiMap implements Serializable { else { if (otherValue instanceof ValueList) { //noinspection unchecked - ValueList otherListValue = (ValueList)otherValue; - ValueList newList = new ValueList<>(otherListValue.size() + 1); + List otherListValue = (ValueList)otherValue; + List newList = new ValueList<>(otherListValue.size() + 1); //noinspection unchecked newList.add((V)myValue); newList.addAll(otherListValue); myMap.put(key, newList); } else { - ValueList newList = new ValueList<>(); + List newList = new ValueList<>(); newList.add(myValue); newList.add(otherValue); myMap.put(key, newList); @@ -230,7 +230,7 @@ public class MostlySingularMultiMap implements Serializable { } // marker class to distinguish multi-values from single values in case client want to store collections as values. - protected static class ValueList extends ArrayList { + protected static final class ValueList extends ArrayList { public ValueList() { } @@ -242,8 +242,23 @@ public class MostlySingularMultiMap implements Serializable { super(c); } } - - private static class EmptyMap extends MostlySingularMultiMap { + + public static @NotNull Class> getValueListClass() { + //noinspection unchecked,rawtypes + return (Class)MostlySingularMultiMap.ValueList.class; + } + + public static @NotNull List createValueList() { + return new MostlySingularMultiMap.ValueList<>(); + } + + private static final class EmptyMap extends MostlySingularMultiMap { + static final MostlySingularMultiMap EMPTY = new EmptyMap(); + + private EmptyMap() { + super(Collections.emptyMap()); + } + @Override public void add(@NotNull Object key, @NotNull Object value) { throw new IncorrectOperationException(); @@ -254,51 +269,9 @@ public class MostlySingularMultiMap implements Serializable { throw new IncorrectOperationException(); } - @Override - public boolean removeAllValues(@NotNull Object key) { - throw new IncorrectOperationException(); - } - @Override public void clear() { throw new IncorrectOperationException(); } - - @NotNull - @Override - public Set keySet() { - return Collections.emptySet(); - } - - @Override - public boolean isEmpty() { - return true; - } - - @Override - public boolean processForKey(@NotNull Object key, @NotNull Processor p) { - return true; - } - - @Override - public boolean processAllValues(@NotNull Processor p) { - return true; - } - - @Override - public int size() { - return 0; - } - - @Override - public int valuesForKey(@NotNull Object key) { - return 0; - } - - @NotNull - @Override - public Iterable get(@NotNull Object name) { - return ContainerUtil.emptyList(); - } } } diff --git a/platform/util/ui/src/com/intellij/openapi/util/IconLoader.java b/platform/util/ui/src/com/intellij/openapi/util/IconLoader.java index 04c256df5c73..55094a008547 100644 --- a/platform/util/ui/src/com/intellij/openapi/util/IconLoader.java +++ b/platform/util/ui/src/com/intellij/openapi/util/IconLoader.java @@ -15,6 +15,7 @@ import com.intellij.ui.scale.JBUIScale; import com.intellij.ui.scale.ScaleContext; import com.intellij.ui.scale.ScaleContextSupport; import com.intellij.util.*; +import com.intellij.util.containers.CollectionFactory; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.FixedHashMap; import com.intellij.util.ui.*; @@ -59,7 +60,7 @@ public final class IconLoader { /** * This cache contains mapping between icons and disabled icons. */ - private static final ConcurrentMap ourIcon2DisabledIcon = ContainerUtil.createConcurrentWeakMap(200, 0.75f, Math.min(Runtime.getRuntime().availableProcessors(), 4), ContainerUtil.canonicalStrategy()); + private static final ConcurrentMap ourIcon2DisabledIcon = CollectionFactory.createConcurrentWeakMap(200, 0.75f, Math.min(Runtime.getRuntime().availableProcessors(), 4)); private static volatile boolean STRICT_GLOBAL; diff --git a/platform/util/ui/src/com/intellij/ui/ScreenUtil.java b/platform/util/ui/src/com/intellij/ui/ScreenUtil.java index 7c58cf78f2a5..47beb4e109dd 100644 --- a/platform/util/ui/src/com/intellij/ui/ScreenUtil.java +++ b/platform/util/ui/src/com/intellij/ui/ScreenUtil.java @@ -3,7 +3,7 @@ package com.intellij.ui; import com.intellij.Patches; import com.intellij.openapi.util.Pair; -import com.intellij.util.containers.ContainerUtil; +import com.intellij.util.containers.CollectionFactory; import com.intellij.util.ui.JBInsets; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -17,7 +17,7 @@ public final class ScreenUtil { public static final String DISPOSE_TEMPORARY = "dispose.temporary"; @Nullable private static final Map> ourInsetsCache = - Patches.isJdkBugId8004103() ? ContainerUtil.createWeakMap() : null; + Patches.isJdkBugId8004103() ? CollectionFactory.createWeakMap() : null; private static final int ourInsetsTimeout = 5000; // shouldn't be too long private ScreenUtil() { } diff --git a/platform/util/ui/src/com/intellij/ui/icons/ImageDescriptor.java b/platform/util/ui/src/com/intellij/ui/icons/ImageDescriptor.java index bcf021233684..076ccf1a30a0 100644 --- a/platform/util/ui/src/com/intellij/ui/icons/ImageDescriptor.java +++ b/platform/util/ui/src/com/intellij/ui/icons/ImageDescriptor.java @@ -1,4 +1,4 @@ -// Copyright 2000-2019 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. +// Copyright 2000-2020 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.ui.icons; import com.intellij.diagnostic.StartUpMeasurer; @@ -10,6 +10,7 @@ import com.intellij.openapi.util.io.FileUtilRt; import com.intellij.openapi.util.text.StringUtilRt; import com.intellij.util.ImageLoader; import com.intellij.util.SVGLoader; +import com.intellij.util.containers.CollectionFactory; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -27,7 +28,7 @@ import java.util.concurrent.ConcurrentMap; public final class ImageDescriptor { private static final ConcurrentMap> ourCache = ContainerUtil.createConcurrentSoftValueMap(); private static final ConcurrentMap ourLargeImageCache = ContainerUtil.createConcurrentWeakValueMap(); - private static final ConcurrentMap ourLargeImageDimensionMap = ContainerUtil.createConcurrentWeakMap(); + private static final ConcurrentMap ourLargeImageDimensionMap = CollectionFactory.createConcurrentWeakMap(); final @NotNull String path; public final double scale; // initial scale factor diff --git a/platform/util/ui/src/com/intellij/ui/scale/Scale.java b/platform/util/ui/src/com/intellij/ui/scale/Scale.java index ca7781b11cd5..696e0434888c 100644 --- a/platform/util/ui/src/com/intellij/ui/scale/Scale.java +++ b/platform/util/ui/src/com/intellij/ui/scale/Scale.java @@ -1,7 +1,7 @@ -// Copyright 2000-2019 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. +// Copyright 2000-2020 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.ui.scale; -import gnu.trove.TDoubleObjectHashMap; +import it.unimi.dsi.fastutil.doubles.Double2ObjectOpenHashMap; import org.jetbrains.annotations.NotNull; import java.util.EnumMap; @@ -16,15 +16,15 @@ public final class Scale { final ScaleType type; // The cache radically reduces potentially thousands of equal Scale instances. - private static final ThreadLocal>> cache = + private static final ThreadLocal>> cache = ThreadLocal.withInitial(() -> new EnumMap<>(ScaleType.class)); @NotNull public static Scale create(double value, @NotNull ScaleType type) { - EnumMap> enumMap = cache.get(); - TDoubleObjectHashMap map = enumMap.get(type); + EnumMap> enumMap = cache.get(); + Double2ObjectOpenHashMap map = enumMap.get(type); if (map == null) { - enumMap.put(type, map = new TDoubleObjectHashMap<>()); + enumMap.put(type, map = new Double2ObjectOpenHashMap<>()); } Scale scale = map.get(value); if (scale != null) return scale; diff --git a/platform/util/ui/src/com/intellij/util/ui/DetectRetinaKit.java b/platform/util/ui/src/com/intellij/util/ui/DetectRetinaKit.java index ee46c394bfc8..e6730388a520 100644 --- a/platform/util/ui/src/com/intellij/util/ui/DetectRetinaKit.java +++ b/platform/util/ui/src/com/intellij/util/ui/DetectRetinaKit.java @@ -1,9 +1,9 @@ -// Copyright 2000-2019 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. +// Copyright 2000-2020 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.util.ui; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.SystemInfo; -import com.intellij.util.containers.ContainerUtil; +import com.intellij.util.containers.CollectionFactory; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -17,7 +17,7 @@ import java.util.Map; */ @ApiStatus.Internal public final class DetectRetinaKit { - private static final Map devicesToRetinaSupportCacheMap = ContainerUtil.createWeakMap(); + private static final Map devicesToRetinaSupportCacheMap = CollectionFactory.createWeakMap(); @NotNull // cannot be static because logging maybe not configured yet diff --git a/platform/util/ui/src/com/intellij/util/ui/GridBag.java b/platform/util/ui/src/com/intellij/util/ui/GridBag.java index d1f3692d595c..17042c3b5c12 100644 --- a/platform/util/ui/src/com/intellij/util/ui/GridBag.java +++ b/platform/util/ui/src/com/intellij/util/ui/GridBag.java @@ -1,9 +1,9 @@ -// Copyright 2000-2019 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. +// Copyright 2000-2020 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.util.ui; -import gnu.trove.TIntDoubleHashMap; -import gnu.trove.TIntIntHashMap; -import gnu.trove.TIntObjectHashMap; +import it.unimi.dsi.fastutil.ints.Int2DoubleOpenHashMap; +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -40,26 +40,25 @@ import java.awt.*; * * Note that every call of {@link #nextLine()} or {@link #next()} resets settings to the defaults for the corresponding column. */ -@SuppressWarnings("unused") -public class GridBag extends GridBagConstraints { +public final class GridBag extends GridBagConstraints { private int myDefaultAnchor = anchor; - @NotNull private final TIntIntHashMap myDefaultColumnAnchors = new TIntIntHashMap(); + @NotNull private final Int2IntOpenHashMap myDefaultColumnAnchors = new Int2IntOpenHashMap(); private int myDefaultFill = fill; - @NotNull private final TIntIntHashMap myDefaultColumnFills = new TIntIntHashMap(); + @NotNull private final Int2IntOpenHashMap myDefaultColumnFills = new Int2IntOpenHashMap(); private double myDefaultWeightX = weightx; - @NotNull private final TIntDoubleHashMap myDefaultColumnWeightsX = new TIntDoubleHashMap(); + @NotNull private final Int2DoubleOpenHashMap myDefaultColumnWeightsX = new Int2DoubleOpenHashMap(); private double myDefaultWeightY = weighty; - @NotNull private final TIntDoubleHashMap myDefaultColumnWeightsY = new TIntDoubleHashMap(); + @NotNull private final Int2DoubleOpenHashMap myDefaultColumnWeightsY = new Int2DoubleOpenHashMap(); private int myDefaultPaddingX = ipadx; - @NotNull private final TIntIntHashMap myDefaultColumnPaddingsX = new TIntIntHashMap(); + @NotNull private final Int2IntOpenHashMap myDefaultColumnPaddingsX = new Int2IntOpenHashMap(); private int myDefaultPaddingY = ipady; - @NotNull private final TIntIntHashMap myDefaultColumnPaddingsY = new TIntIntHashMap(); + @NotNull private final Int2IntOpenHashMap myDefaultColumnPaddingsY = new Int2IntOpenHashMap(); @Nullable private Insets myDefaultInsets = insets; - @NotNull private final TIntObjectHashMap myDefaultColumnInsets = new TIntObjectHashMap<>(); + @NotNull private final Int2ObjectOpenHashMap myDefaultColumnInsets = new Int2ObjectOpenHashMap<>(); public GridBag() { gridx = gridy = -1; diff --git a/platform/util/ui/src/com/intellij/util/ui/UIUtil.java b/platform/util/ui/src/com/intellij/util/ui/UIUtil.java index b38ae6cfb8ee..f0c2d97e9318 100644 --- a/platform/util/ui/src/com/intellij/util/ui/UIUtil.java +++ b/platform/util/ui/src/com/intellij/util/ui/UIUtil.java @@ -1919,7 +1919,7 @@ public final class UIUtil { } if (component != null && component.getParent() instanceof JLayeredPane) { // Handle LoadingDecorator Component[] components = ((JLayeredPane)component.getParent()).getComponentsInLayer(JLayeredPane.DEFAULT_LAYER); - if (components.length == 1 && ArrayUtil.indexOf(components, component) == -1) { + if (components.length == 1 && ArrayUtilRt.indexOf(components, component, 0, components.length) == -1) { component = getDeepestComponentAtForComponent(parent, x, y, components[0]); } } diff --git a/plugins/ant/jps-plugin/testSrc/org/jetbrains/jps/ant/JpsAntSerializationTest.kt b/plugins/ant/jps-plugin/testSrc/org/jetbrains/jps/ant/JpsAntSerializationTest.kt index c83d63accee3..104c8fd962ef 100644 --- a/plugins/ant/jps-plugin/testSrc/org/jetbrains/jps/ant/JpsAntSerializationTest.kt +++ b/plugins/ant/jps-plugin/testSrc/org/jetbrains/jps/ant/JpsAntSerializationTest.kt @@ -1,11 +1,11 @@ -// 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. +// Copyright 2000-2020 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 org.jetbrains.jps.ant import com.intellij.openapi.util.io.FileUtil import com.intellij.testFramework.UsefulTestCase import com.intellij.util.SystemProperties +import com.intellij.util.containers.CollectionFactory import com.intellij.util.io.directoryContent -import gnu.trove.THashSet import org.jetbrains.jps.ant.model.JpsAntExtensionService import org.jetbrains.jps.ant.model.impl.artifacts.JpsAntArtifactExtensionImpl import org.jetbrains.jps.model.artifact.JpsArtifactService @@ -110,7 +110,7 @@ class JpsAntSerializationTest : JpsSerializationTestCase() { const val OPTIONS_PATH = "plugins/ant/jps-plugin/testData/config/options" private fun toFiles(classpath: List): Set { - val result = THashSet(FileUtil.FILE_HASHING_STRATEGY) + val result = CollectionFactory.createFileSet() for (path in classpath) { result.add(File(path)) } diff --git a/plugins/ant/src/com/intellij/lang/ant/config/impl/AntResourcesClassLoader.java b/plugins/ant/src/com/intellij/lang/ant/config/impl/AntResourcesClassLoader.java index aaba3fa6ab6b..75899fc788b7 100644 --- a/plugins/ant/src/com/intellij/lang/ant/config/impl/AntResourcesClassLoader.java +++ b/plugins/ant/src/com/intellij/lang/ant/config/impl/AntResourcesClassLoader.java @@ -1,35 +1,21 @@ -/* - * Copyright 2000-2017 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. - */ +// Copyright 2000-2020 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.lang.ant.config.impl; import com.intellij.openapi.progress.ProgressManager; import com.intellij.util.lang.UrlClassLoader; -import gnu.trove.THashSet; import java.net.URL; +import java.util.HashSet; import java.util.List; import java.util.Set; /** * @author Eugene Zhuravlev */ -public class AntResourcesClassLoader extends UrlClassLoader { +public final class AntResourcesClassLoader extends UrlClassLoader { static { if (registerAsParallelCapable()) markParallelCapable(AntResourcesClassLoader.class); } - private final Set myMisses = new THashSet<>(); + private final Set myMisses = new HashSet<>(); public AntResourcesClassLoader(final List urls, final ClassLoader parentLoader, final boolean canLockJars, final boolean canUseCache) { super(build().urls(urls).parent(parentLoader).allowLock(canLockJars).useCache(canUseCache).noPreload()); @@ -51,7 +37,7 @@ public class AntResourcesClassLoader extends UrlClassLoader { } @Override - protected Class findClass(final String name) throws ClassNotFoundException { + protected Class findClass(String name) throws ClassNotFoundException { ProgressManager.checkCanceled(); try { return super.findClass(name); diff --git a/plugins/ant/src/com/intellij/lang/ant/dom/CustomAntElementsRegistry.java b/plugins/ant/src/com/intellij/lang/ant/dom/CustomAntElementsRegistry.java index 317231bc3e64..b1db0b44420b 100644 --- a/plugins/ant/src/com/intellij/lang/ant/dom/CustomAntElementsRegistry.java +++ b/plugins/ant/src/com/intellij/lang/ant/dom/CustomAntElementsRegistry.java @@ -1,18 +1,4 @@ -/* - * 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. - * 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. - */ +// Copyright 2000-2020 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.lang.ant.dom; import com.intellij.ide.highlighter.XmlFileType; @@ -38,7 +24,6 @@ import com.intellij.psi.xml.XmlFile; import com.intellij.psi.xml.XmlTag; import com.intellij.util.LocalTimeCounter; import com.intellij.util.xml.XmlName; -import gnu.trove.THashMap; import one.util.streamex.StreamEx; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -56,16 +41,15 @@ import java.util.*; * parsed from ant files * @author Eugene Zhuravlev */ -public class CustomAntElementsRegistry { - +public final class CustomAntElementsRegistry { public static final ThreadLocal ourIsBuildingClasspathForCustomTagLoading = ThreadLocal.withInitial(() -> Boolean.FALSE); private static final Logger LOG = Logger.getInstance(CustomAntElementsRegistry.class); private static final Key REGISTRY_KEY = Key.create("_custom_element_registry_"); - private final Map myCustomElements = new THashMap<>(); - private final Map myTypeDefErrors = new THashMap<>(); - private final Map myDeclarations = new THashMap<>(); - private final Map myNamedLoaders = new THashMap<>(); + private final Map myCustomElements = new HashMap<>(); + private final Map myTypeDefErrors = new HashMap<>(); + private final Map myDeclarations = new HashMap<>(); + private final Map myNamedLoaders = new HashMap<>(); private CustomAntElementsRegistry(final AntDomProject antProject) { antProject.accept(new CustomTagDefinitionFinder(antProject)); diff --git a/plugins/ant/src/com/intellij/lang/ant/segments/PushReader.java b/plugins/ant/src/com/intellij/lang/ant/segments/PushReader.java index 392c04099124..59d44e71ae22 100644 --- a/plugins/ant/src/com/intellij/lang/ant/segments/PushReader.java +++ b/plugins/ant/src/com/intellij/lang/ant/segments/PushReader.java @@ -1,24 +1,24 @@ // Copyright 2000-2020 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.lang.ant.segments; -import gnu.trove.TIntArrayList; +import it.unimi.dsi.fastutil.ints.IntArrayList; import org.jetbrains.annotations.NonNls; import java.io.IOException; import java.io.Reader; -public class PushReader { +public final class PushReader { private final Reader mySource; - private final TIntArrayList myReadAhead = new TIntArrayList(); + private final IntArrayList myReadAhead = new IntArrayList(); @NonNls - protected static final String INTERNAL_ERROR_UNEXPECTED_END_OF_PIPE = "Unexpected end of pipe"; + private static final String INTERNAL_ERROR_UNEXPECTED_END_OF_PIPE = "Unexpected end of pipe"; public PushReader(final Reader source) { mySource = source; } public int next() throws IOException { - return myReadAhead.isEmpty() ? mySource.read() : myReadAhead.remove(myReadAhead.size() - 1); + return myReadAhead.isEmpty() ? mySource.read() : myReadAhead.removeInt(myReadAhead.size() - 1); } public void pushBack(final char[] chars) { @@ -44,7 +44,7 @@ public class PushReader { final char[] chars = new char[charCount]; int offset = 0; for (; offset < chars.length && offset < myReadAhead.size(); offset++) - chars[offset] = (char)myReadAhead.remove(myReadAhead.size() - 1); + chars[offset] = (char)myReadAhead.removeInt(myReadAhead.size() - 1); while (offset < chars.length) { int bytesRead = mySource.read(chars, offset, chars.length - offset); diff --git a/plugins/google-app-engine/jps-plugin/src/org/jetbrains/jps/appengine/build/AppEngineEnhancerBuilder.java b/plugins/google-app-engine/jps-plugin/src/org/jetbrains/jps/appengine/build/AppEngineEnhancerBuilder.java index 6bb5cb9cc30b..3e0be24a3af3 100644 --- a/plugins/google-app-engine/jps-plugin/src/org/jetbrains/jps/appengine/build/AppEngineEnhancerBuilder.java +++ b/plugins/google-app-engine/jps-plugin/src/org/jetbrains/jps/appengine/build/AppEngineEnhancerBuilder.java @@ -1,25 +1,11 @@ -/* - * Copyright 2000-2013 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. - */ +// Copyright 2000-2020 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 org.jetbrains.jps.appengine.build; import com.intellij.appengine.rt.EnhancerRunner; import com.intellij.openapi.application.PathManager; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.util.containers.CollectionFactory; import com.intellij.util.execution.ParametersListUtil; -import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.jps.ModuleChunk; import org.jetbrains.jps.appengine.model.JpsAppEngineExtensionService; @@ -46,7 +32,7 @@ import java.io.IOException; import java.io.PrintWriter; import java.util.*; -public class AppEngineEnhancerBuilder extends ModuleLevelBuilder { +public final class AppEngineEnhancerBuilder extends ModuleLevelBuilder { public static final String NAME = "Google AppEngine Enhancer"; public AppEngineEnhancerBuilder() { @@ -59,7 +45,7 @@ public class AppEngineEnhancerBuilder extends ModuleLevelBuilder { DirtyFilesHolder dirtyFilesHolder, OutputConsumer outputConsumer) throws ProjectBuildException, IOException { - + boolean doneSomething = false; for (final JpsModule module : chunk.getModules()) { JpsAppEngineModuleExtension extension = JpsAppEngineExtensionService.getInstance().getExtension(module); @@ -80,7 +66,7 @@ public class AppEngineEnhancerBuilder extends ModuleLevelBuilder { private static boolean processModule(final CompileContext context, DirtyFilesHolder dirtyFilesHolder, JpsAppEngineModuleExtension extension) throws IOException, ProjectBuildException { - final Set roots = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY); + final Set roots = CollectionFactory.createFileSet(); for (String path : extension.getFilesToEnhance()) { roots.add(new File(FileUtil.toSystemDependentName(path))); } diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/util/GrClassImplUtil.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/util/GrClassImplUtil.java index 8a720620c788..2866b492fe1c 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/util/GrClassImplUtil.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/util/GrClassImplUtil.java @@ -1,4 +1,4 @@ -// Copyright 2000-2019 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. +// Copyright 2000-2020 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 org.jetbrains.plugins.groovy.lang.psi.util; import com.intellij.openapi.diagnostic.Logger; @@ -540,7 +540,7 @@ public class GrClassImplUtil { public static Set getDuplicatedSignatures(@NotNull PsiClass clazz) { return CachedValuesManager.getCachedValue(clazz, () -> { PsiElementFactory factory = JavaPsiFacade.getInstance(clazz.getProject()).getElementFactory(); - MostlySingularMultiMap signatures = MostlySingularMultiMap.newMap(); + MostlySingularMultiMap signatures = new MostlySingularMultiMap<>(); for (PsiMethod method : clazz.getMethods()) { MethodSignature signature = method.getSignature(factory.createRawSubstitutor(method)); signatures.add(signature, method); diff --git a/plugins/properties/src/com/intellij/lang/properties/create/CreateResourceBundleDialogComponent.java b/plugins/properties/src/com/intellij/lang/properties/create/CreateResourceBundleDialogComponent.java index b6c663620c2b..57a84d2a4351 100644 --- a/plugins/properties/src/com/intellij/lang/properties/create/CreateResourceBundleDialogComponent.java +++ b/plugins/properties/src/com/intellij/lang/properties/create/CreateResourceBundleDialogComponent.java @@ -29,7 +29,6 @@ import com.intellij.ui.components.JBList; import com.intellij.util.NotNullFunction; import com.intellij.util.PathUtil; import com.intellij.util.containers.ContainerUtil; -import gnu.trove.THashMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -42,7 +41,7 @@ import java.util.*; /** * @author Dmitry Batkovich */ -public class CreateResourceBundleDialogComponent { +public final class CreateResourceBundleDialogComponent { private final static Logger LOG = Logger.getInstance(CreateResourceBundleDialogComponent.class); private static final Comparator LOCALE_COMPARATOR = (l1, l2) -> { @@ -72,7 +71,7 @@ public class CreateResourceBundleDialogComponent { myProject = project; myDirectory = directory; myResourceBundle = resourceBundle; - myLocaleSuffixes = new THashMap<>(); + myLocaleSuffixes = new HashMap<>(); if (resourceBundle != null) { myResourceBundleNamePanel.setVisible(false); myUseXMLBasedPropertiesCheckBox.setVisible(false); @@ -264,7 +263,7 @@ public class CreateResourceBundleDialogComponent { return Collections.emptyMap(); } final String[] splitRawLocales = rawLocales.split(","); - final Map locales = new THashMap<>(splitRawLocales.length); + final Map locales = new HashMap<>(splitRawLocales.length); for (String rawLocale : splitRawLocales) { final Pair localeAndSuffix = PropertiesUtil.getLocaleAndTrimmedSuffix("_" + rawLocale + ".properties"); diff --git a/plugins/settings-repository/testSrc/BareGitTest.kt b/plugins/settings-repository/testSrc/BareGitTest.kt index 8c676015a4a3..4ca8711ba6b6 100644 --- a/plugins/settings-repository/testSrc/BareGitTest.kt +++ b/plugins/settings-repository/testSrc/BareGitTest.kt @@ -4,7 +4,6 @@ package org.jetbrains.settingsRepository.test import com.intellij.openapi.util.io.FileUtil import com.intellij.testFramework.TemporaryDirectory import com.intellij.util.SmartList -import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet import org.assertj.core.api.Assertions.assertThat import org.jetbrains.settingsRepository.git.cloneBare @@ -50,7 +49,7 @@ internal class BareGitTest { val repository = cloneBare(remoteRepository.workTree.absolutePath, tempDirManager.newPath()) - val data = Object2ObjectOpenHashMap() + val data = HashMap() repository.processChildren("keymaps") {name, input -> data.put(name, FileUtil.loadTextAndClose(input)) true diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/treeConflict/TreeConflictRefreshablePanel.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/treeConflict/TreeConflictRefreshablePanel.java index c8a17c157add..88d01534b700 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/treeConflict/TreeConflictRefreshablePanel.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/treeConflict/TreeConflictRefreshablePanel.java @@ -1,21 +1,11 @@ // Copyright 2000-2020 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 org.jetbrains.idea.svn.treeConflict; -import static com.intellij.openapi.application.ModalityState.defaultModalityState; -import static com.intellij.openapi.util.io.FileUtil.toSystemIndependentName; -import static com.intellij.vcsUtil.VcsUtil.getFilePathOnNonLocal; -import static org.jetbrains.idea.svn.history.SvnHistorySession.getCurrentCommittedRevision; - import com.intellij.openapi.CompositeDisposable; import com.intellij.openapi.Disposable; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.fileEditor.FileDocumentManager; -import com.intellij.openapi.progress.BackgroundTaskQueue; -import com.intellij.openapi.progress.EmptyProgressIndicator; -import com.intellij.openapi.progress.PerformInBackgroundOption; -import com.intellij.openapi.progress.ProgressIndicator; -import com.intellij.openapi.progress.ProgressManager; -import com.intellij.openapi.progress.Task; +import com.intellij.openapi.progress.*; import com.intellij.openapi.progress.impl.BackgroundableProcessIndicator; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.MessageType; @@ -26,12 +16,7 @@ import com.intellij.openapi.vcs.FilePath; import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vcs.changes.Change; import com.intellij.openapi.vcs.changes.ChangesUtil; -import com.intellij.openapi.vcs.history.FileHistoryPanelImpl; -import com.intellij.openapi.vcs.history.FileHistoryRefresherI; -import com.intellij.openapi.vcs.history.VcsAbstractHistorySession; -import com.intellij.openapi.vcs.history.VcsAppendableHistoryPartnerAdapter; -import com.intellij.openapi.vcs.history.VcsFileRevision; -import com.intellij.openapi.vcs.history.VcsRevisionNumber; +import com.intellij.openapi.vcs.history.*; import com.intellij.openapi.vcs.ui.VcsBalloonProblemNotifier; import com.intellij.ui.JBColor; import com.intellij.ui.components.JBLoadingPanel; @@ -40,20 +25,6 @@ import com.intellij.util.containers.Convertor; import com.intellij.util.ui.JBUI; import com.intellij.util.ui.VcsBackgroundTask; import gnu.trove.TLongArrayList; -import java.awt.BorderLayout; -import java.awt.FlowLayout; -import java.awt.Font; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.Collections; -import java.util.List; -import java.util.Objects; -import javax.swing.BorderFactory; -import javax.swing.JButton; -import javax.swing.JLabel; -import javax.swing.JPanel; import org.jetbrains.annotations.CalledInAwt; import org.jetbrains.annotations.CalledInBackground; import org.jetbrains.annotations.NotNull; @@ -68,8 +39,20 @@ import org.jetbrains.idea.svn.conflict.ConflictVersion; import org.jetbrains.idea.svn.conflict.TreeConflictDescription; import org.jetbrains.idea.svn.history.SvnHistoryProvider; -public class TreeConflictRefreshablePanel implements Disposable { +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import static com.intellij.openapi.application.ModalityState.defaultModalityState; +import static com.intellij.openapi.util.io.FileUtil.toSystemIndependentName; +import static com.intellij.vcsUtil.VcsUtil.getFilePathOnNonLocal; +import static org.jetbrains.idea.svn.history.SvnHistorySession.getCurrentCommittedRevision; + +public class TreeConflictRefreshablePanel implements Disposable { public static final String TITLE = "Resolve tree conflict"; private final ConflictedSvnChange myChange; private final SvnVcs myVcs; diff --git a/plugins/textmate/src/org/jetbrains/plugins/textmate/language/syntax/lexer/TextMateLexerDataStorage.java b/plugins/textmate/src/org/jetbrains/plugins/textmate/language/syntax/lexer/TextMateLexerDataStorage.java index 1da3289ba247..5f03b11958fc 100644 --- a/plugins/textmate/src/org/jetbrains/plugins/textmate/language/syntax/lexer/TextMateLexerDataStorage.java +++ b/plugins/textmate/src/org/jetbrains/plugins/textmate/language/syntax/lexer/TextMateLexerDataStorage.java @@ -3,21 +3,22 @@ package org.jetbrains.plugins.textmate.language.syntax.lexer; import com.intellij.openapi.editor.ex.util.DataStorage; import com.intellij.openapi.editor.ex.util.ShortBasedStorage; import com.intellij.psi.tree.IElementType; -import com.intellij.util.SmartList; -import gnu.trove.TObjectIntHashMap; +import it.unimi.dsi.fastutil.objects.Object2IntMap; +import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import org.jetbrains.annotations.NotNull; +import java.util.ArrayList; import java.util.List; -public class TextMateLexerDataStorage extends ShortBasedStorage { - private final TObjectIntHashMap tokenTypeMap; +public final class TextMateLexerDataStorage extends ShortBasedStorage { + private final Object2IntMap tokenTypeMap; private final List tokenTypes; public TextMateLexerDataStorage() { - this(new TObjectIntHashMap<>(), new SmartList<>()); + this(new Object2IntOpenHashMap<>(), new ArrayList<>()); } - private TextMateLexerDataStorage(@NotNull TObjectIntHashMap tokenTypeMap, + private TextMateLexerDataStorage(@NotNull Object2IntMap tokenTypeMap, @NotNull List tokenTypes) { super(); this.tokenTypeMap = tokenTypeMap; @@ -25,7 +26,7 @@ public class TextMateLexerDataStorage extends ShortBasedStorage { } private TextMateLexerDataStorage(short @NotNull [] data, - @NotNull TObjectIntHashMap tokenTypeMap, + @NotNull Object2IntMap tokenTypeMap, @NotNull List tokenTypes) { super(data); this.tokenTypeMap = tokenTypeMap; @@ -36,8 +37,8 @@ public class TextMateLexerDataStorage extends ShortBasedStorage { public int packData(IElementType tokenType, int state, boolean isRestartableState) { if (tokenType instanceof TextMateElementType) { synchronized (tokenTypeMap) { - if (tokenTypeMap.contains(tokenType)) { - return tokenTypeMap.get((TextMateElementType)tokenType) * (isRestartableState ? 1 : -1); + if (tokenTypeMap.containsKey(tokenType)) { + return tokenTypeMap.getInt(tokenType) * (isRestartableState ? 1 : -1); } int data = tokenTypes.size() + 1; tokenTypes.add((TextMateElementType)tokenType); diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/psi/impl/ResolveUtil.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/psi/impl/ResolveUtil.java index 17ae7d28a658..7aa55c55276d 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/psi/impl/ResolveUtil.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/psi/impl/ResolveUtil.java @@ -15,7 +15,7 @@ */ package org.intellij.lang.xpath.psi.impl; -import com.intellij.openapi.vfs.VfsUtil; +import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; import com.intellij.psi.util.PsiTreeUtil; @@ -26,208 +26,223 @@ import com.intellij.psi.xml.XmlFile; import com.intellij.psi.xml.XmlTag; import com.intellij.util.CommonProcessors; import com.intellij.util.Processor; -import com.intellij.util.containers.ContainerUtil; +import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet; import org.intellij.lang.xpath.xslt.impl.XsltIncludeIndex; import org.jetbrains.annotations.Nullable; import java.util.*; -public class ResolveUtil { +public final class ResolveUtil { + private final Set myHistory = new ReferenceOpenHashSet<>(); - private final Set myHistory = ContainerUtil.newIdentityTroveSet(); + private ResolveUtil() { + } - private ResolveUtil() { + @Nullable + public static Collection getDependencies(XmlFile element) { + final CommonProcessors.CollectUniquesProcessor processor = new CommonProcessors.CollectUniquesProcessor() { + @Override + public boolean process(XmlFile file) { + if (!getResults().contains(file)) { + XsltIncludeIndex.processForwardDependencies(file, this); + } + return super.process(file); + } + }; + XsltIncludeIndex.processForwardDependencies(element, processor); + return processor.getResults(); + } + + @Nullable + public static PsiFile resolveFile(String name, PsiFile baseFile) { + if (baseFile == null) return null; + + final VirtualFile virtualFile = VfsUtilCore.findRelativeFile(name, baseFile.getVirtualFile()); + if (virtualFile != null) { + final PsiFile file = baseFile.getManager().findFile(virtualFile); + if (file != baseFile && file instanceof XmlFile) { + return file; + } + } + return null; + } + + @Nullable + public static PsiFile resolveFile(XmlAttribute location, PsiFile baseFile) { + if (location == null) return null; + final XmlAttributeValue valueElement = location.getValueElement(); + if (valueElement == null) return null; + + // prefer direct relative path + final String value = valueElement.getValue(); + final PsiFile file = resolveFile(value, baseFile); + if (file != baseFile && file instanceof XmlFile) { + return file; } - @Nullable - public static Collection getDependencies(XmlFile element) { - final CommonProcessors.CollectUniquesProcessor processor = new CommonProcessors.CollectUniquesProcessor() { - @Override - public boolean process(XmlFile file) { - if (!getResults().contains(file)) { - XsltIncludeIndex.processForwardDependencies(file, this); + final PsiReference[] references = valueElement.getReferences(); + for (PsiReference reference : references) { + final PsiElement target = reference.resolve(); + if (target == null && reference instanceof PsiPolyVariantReference) { + final ResolveResult[] results = ((PsiPolyVariantReference)reference).multiResolve(false); + for (ResolveResult result : results) { + if (result.isValidResult()) { + // TODO: how to weigh/prioritize the results? + final PsiElement element = result.getElement(); + if (element != baseFile && element instanceof XmlFile) { + return (PsiFile)target; + } } - return super.process(file); } - }; - XsltIncludeIndex.processForwardDependencies(element, processor); - return processor.getResults(); + } + else if (target != baseFile && target instanceof XmlFile) { + return (PsiFile)target; + } } + return null; + } + + public interface Matcher { + @Nullable + XmlTag getRoot(); + + boolean isRecursive(); @Nullable - public static PsiFile resolveFile(String name, PsiFile baseFile) { - if (baseFile == null) return null; + Result match(XmlTag element); - final VirtualFile virtualFile = VfsUtil.findRelativeFile(name, baseFile.getVirtualFile()); - if (virtualFile != null) { - final PsiFile file = baseFile.getManager().findFile(virtualFile); - if (file != baseFile && file instanceof XmlFile) { - return file; + Matcher variantMatcher(); + + class Result { + final PsiElement result; + final Matcher chain; + + public Result(PsiElement element) { + result = element; + chain = null; + } + + public Result(Matcher matcher) { + chain = matcher; + result = null; + } + + public static Result create(PsiElement element) { return new Result(element); } + + public static Result create(Matcher matcher) { return new Result(matcher); } + } + } + + @Nullable + public static PsiElement resolve(final Matcher matcher) { + if (matcher == null) return null; + final List found = process(matcher, true); + return found.size() > 0 ? found.get(0) : null; + } + + public static PsiElement[] collect(final Matcher matcher) { + if (matcher == null) return PsiElement.EMPTY_ARRAY; + final List found = process(matcher, false); + return PsiUtilCore.toPsiElementArray(found); + } + + private static class Stop extends RuntimeException { + public static final Stop DONE = new Stop(); + + @Override + public Throwable fillInStackTrace() { + return this; + } + } + + private static List process(final Matcher matcher, final boolean resolve) { + return new ResolveUtil()._process(matcher, resolve); + } + + private List _process(final Matcher matcher, final boolean resolve) { + final XmlTag root = matcher.getRoot(); + if (root == null || myHistory.contains(root)) { + return Collections.emptyList(); + } + myHistory.add(root); + final List found = new ArrayList<>(); + + try { + if (matcher.isRecursive()) { + root.accept(new XmlRecursiveElementVisitor() { + @Override + public void visitXmlTag(XmlTag tag) { + final Matcher.Result match = matcher.match(tag); + if (match != null) { + if (match.chain != null) { + found.addAll(_process(match.chain, resolve)); + } + else { + assert match.result != null; + found.add(match.result); + if (resolve) throw Stop.DONE; + } } - } - return null; - } + super.visitXmlTag(tag); + } + }); + } + else { + root.acceptChildren(new XmlElementVisitor() { - @Nullable - public static PsiFile resolveFile(XmlAttribute location, PsiFile baseFile) { - if (location == null) return null; - final XmlAttributeValue valueElement = location.getValueElement(); - if (valueElement == null) return null; - - // prefer direct relative path - final String value = valueElement.getValue(); - final PsiFile file = resolveFile(value, baseFile); - if (file != baseFile && file instanceof XmlFile) { - return file; - } - - final PsiReference[] references = valueElement.getReferences(); - for (PsiReference reference : references) { - final PsiElement target = reference.resolve(); - if (target == null && reference instanceof PsiPolyVariantReference) { - final ResolveResult[] results = ((PsiPolyVariantReference)reference).multiResolve(false); - for (ResolveResult result : results) { - if (result.isValidResult()) { - // TODO: how to weigh/prioritize the results? - final PsiElement element = result.getElement(); - if (element != baseFile && element instanceof XmlFile) { - return (PsiFile)target; - } - } - } - } else if (target != baseFile && target instanceof XmlFile) { - return (PsiFile)target; + @Override + public void visitXmlTag(XmlTag tag) { + final Matcher.Result match = matcher.match(tag); + if (match != null) { + if (match.chain != null) { + found.addAll(_process(match.chain, resolve)); + } + else { + assert match.result != null; + found.add(match.result); + if (resolve) throw Stop.DONE; + } } + } + }); + } + } + catch (Stop e) { + /* processing stopped */ + } + return found; + } + + public interface XmlProcessor extends Processor { + @Override + boolean process(XmlTag tag); + } + + public interface ResolveProcessor extends XmlProcessor { + PsiElement getResult(); + } + + @Nullable + public static PsiElement treeWalkUp(final XmlProcessor processor, PsiElement elt) { + if (elt == null) return null; + + PsiElement cur = elt; + do { + if (cur instanceof XmlTag) { + final XmlTag tag = (XmlTag)cur; + if (!processor.process(tag)) { + if (processor instanceof ResolveProcessor) { + return ((ResolveProcessor)processor).getResult(); + } + return null; } - return null; + } + + if (cur instanceof PsiFile) break; + cur = PsiTreeUtil.getPrevSiblingOfType(cur, XmlTag.class); } + while (cur != null); - public interface Matcher { - @Nullable - XmlTag getRoot(); - - boolean isRecursive(); - - @Nullable - Result match(XmlTag element); - - Matcher variantMatcher(); - - class Result { - final PsiElement result; - final Matcher chain; - - public Result(PsiElement element) { result = element; chain = null; } - public Result(Matcher matcher) { chain = matcher; result = null; } - public static Result create(PsiElement element) { return new Result(element); } - public static Result create(Matcher matcher) { return new Result(matcher); } - } - } - - @Nullable - public static PsiElement resolve(final Matcher matcher) { - if (matcher == null) return null; - final List found = process(matcher, true); - return found.size() > 0 ? found.get(0) : null; - } - - public static PsiElement[] collect(final Matcher matcher) { - if (matcher == null) return PsiElement.EMPTY_ARRAY; - final List found = process(matcher, false); - return PsiUtilCore.toPsiElementArray(found); - } - - private static class Stop extends RuntimeException { - public static final Stop DONE = new Stop(); - @Override - public Throwable fillInStackTrace() { - return this; - } - } - - private static List process(final Matcher matcher, final boolean resolve) { - return new ResolveUtil()._process(matcher, resolve); - } - - private List _process(final Matcher matcher, final boolean resolve) { - final XmlTag root = matcher.getRoot(); - if (root == null || myHistory.contains(root)) { - return Collections.emptyList(); - } - myHistory.add(root); - final List found = new ArrayList<>(); - - try { - if (matcher.isRecursive()) { - root.accept(new XmlRecursiveElementVisitor(){ - @Override - public void visitXmlTag(XmlTag tag) { - final Matcher.Result match = matcher.match(tag); - if (match != null) { - if (match.chain != null) { - found.addAll(_process(match.chain, resolve)); - } else { - assert match.result != null; - found.add(match.result); - if (resolve) throw Stop.DONE; - } - } - super.visitXmlTag(tag); - } - }); - } else { - root.acceptChildren(new XmlElementVisitor() { - - @Override - public void visitXmlTag(XmlTag tag) { - final Matcher.Result match = matcher.match(tag); - if (match != null) { - if (match.chain != null) { - found.addAll(_process(match.chain, resolve)); - } else { - assert match.result != null; - found.add(match.result); - if (resolve) throw Stop.DONE; - } - } - } - }); - } - } catch (Stop e) { - /* processing stopped */ - } - return found; - } - - public interface XmlProcessor extends Processor { - @Override - boolean process(XmlTag tag); - } - - public interface ResolveProcessor extends XmlProcessor { - PsiElement getResult(); - } - - @Nullable - public static PsiElement treeWalkUp(final XmlProcessor processor, PsiElement elt) { - if (elt == null) return null; - - PsiElement cur = elt; - do { - if (cur instanceof XmlTag) { - final XmlTag tag = (XmlTag)cur; - if (!processor.process(tag)) { - if (processor instanceof ResolveProcessor) { - return ((ResolveProcessor)processor).getResult(); - } - return null; - } - } - - if (cur instanceof PsiFile) break; - cur = PsiTreeUtil.getPrevSiblingOfType(cur, XmlTag.class); - } while (cur != null); - - return treeWalkUp(processor, elt.getContext()); - } + return treeWalkUp(processor, elt.getContext()); + } } diff --git a/plugins/yaml/src/org/jetbrains/yaml/meta/model/YamlComposedTypeBase.java b/plugins/yaml/src/org/jetbrains/yaml/meta/model/YamlComposedTypeBase.java index 722bd0039cda..803aa72bc8ea 100644 --- a/plugins/yaml/src/org/jetbrains/yaml/meta/model/YamlComposedTypeBase.java +++ b/plugins/yaml/src/org/jetbrains/yaml/meta/model/YamlComposedTypeBase.java @@ -1,10 +1,11 @@ -// Copyright 2000-2019 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. +// Copyright 2000-2020 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 org.jetbrains.yaml.meta.model; import com.intellij.codeInspection.ProblemsHolder; import com.intellij.openapi.util.Pair; import com.intellij.util.SmartList; import com.intellij.util.containers.ContainerUtil; +import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.yaml.psi.YAMLMapping; @@ -22,12 +23,11 @@ public abstract class YamlComposedTypeBase extends YamlMetaType { throw new IllegalArgumentException("Nothing to compose"); } List flattenedTypes = new SmartList<>(); - Set cerber = ContainerUtil.newIdentityTroveSet(); + Set cerber = new ReferenceOpenHashSet<>(); for (YamlMetaType next : types) { - if (cerber.contains(next)) { + if (!cerber.add(next)) { continue; } - cerber.add(next); if (next instanceof YamlScalarType) { flattenedTypes.add(next); } diff --git a/plugins/yaml/src/org/jetbrains/yaml/navigation/YAMLKeysIndex.java b/plugins/yaml/src/org/jetbrains/yaml/navigation/YAMLKeysIndex.java index 9f68bde243a1..0a821607deb2 100644 --- a/plugins/yaml/src/org/jetbrains/yaml/navigation/YAMLKeysIndex.java +++ b/plugins/yaml/src/org/jetbrains/yaml/navigation/YAMLKeysIndex.java @@ -1,4 +1,4 @@ -// 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. +// Copyright 2000-2020 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 org.jetbrains.yaml.navigation; import com.intellij.psi.PsiElement; @@ -6,7 +6,8 @@ import com.intellij.util.indexing.*; import com.intellij.util.io.DataExternalizer; import com.intellij.util.io.EnumeratorStringDescriptor; import com.intellij.util.io.KeyDescriptor; -import gnu.trove.THashMap; +import it.unimi.dsi.fastutil.objects.Object2IntMap; +import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.yaml.YAMLUtil; @@ -19,7 +20,7 @@ import java.io.DataOutput; import java.io.IOException; import java.util.Map; -public class YAMLKeysIndex extends FileBasedIndexExtension { +public final class YAMLKeysIndex extends FileBasedIndexExtension { @NonNls public static final ID KEY = ID.create("yaml.keys.name"); @@ -35,7 +36,7 @@ public class YAMLKeysIndex extends FileBasedIndexExtension { @NotNull @Override public Map map(@NotNull FileContent inputData) { - final Map map = new THashMap<>(); + Object2IntMap map = new Object2IntOpenHashMap<>(); inputData.getPsiFile().accept(new YamlRecursivePsiElementVisitor() { @Override public void visitKeyValue(@NotNull YAMLKeyValue keyValue) { diff --git a/plugins/yaml/src/org/jetbrains/yaml/navigation/YAMLKeysSearchEverywhereContributor.java b/plugins/yaml/src/org/jetbrains/yaml/navigation/YAMLKeysSearchEverywhereContributor.java index 5cc443f2118b..9758e06b8750 100644 --- a/plugins/yaml/src/org/jetbrains/yaml/navigation/YAMLKeysSearchEverywhereContributor.java +++ b/plugins/yaml/src/org/jetbrains/yaml/navigation/YAMLKeysSearchEverywhereContributor.java @@ -1,4 +1,4 @@ -// 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. +// Copyright 2000-2020 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 org.jetbrains.yaml.navigation; import com.intellij.ide.actions.searcheverywhere.SearchEverywhereContributor; @@ -21,20 +21,24 @@ import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.search.ProjectScope; import com.intellij.util.CommonProcessors; import com.intellij.util.Processor; -import com.intellij.util.containers.MultiMap; +import com.intellij.util.SmartList; import com.intellij.util.indexing.FileBasedIndex; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.ints.IntArrayList; +import it.unimi.dsi.fastutil.ints.IntListIterator; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.yaml.YAMLBundle; import javax.swing.*; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; -import java.util.stream.Collectors; public class YAMLKeysSearchEverywhereContributor implements SearchEverywhereContributor { - final Project myProject; + private final Project myProject; public YAMLKeysSearchEverywhereContributor(Project project) { myProject = project; @@ -144,8 +148,7 @@ public class YAMLKeysSearchEverywhereContributor implements SearchEverywhereCont private static List applyPattern(@NotNull Collection keys, @NotNull String pattern, ProgressIndicator progressIndicator) { - MultiMap priority = MultiMap.create(); - + Int2ObjectMap> priority = new Int2ObjectOpenHashMap<>(); for (String key : keys) { progressIndicator.checkCanceled(); int start = key.indexOf(pattern); @@ -160,17 +163,21 @@ public class YAMLKeysSearchEverywhereContributor implements SearchEverywhereCont continue; } int dots = countDots(key, start); - priority.putValue(dots, key); + priority.computeIfAbsent(dots, __ -> new SmartList<>()).add(key); } progressIndicator.checkCanceled(); - return priority - .keySet() - .stream() - .sorted() - .map(idx -> priority.get(idx)) - .flatMap(found -> found.stream().sorted()) - .collect(Collectors.toList()); + IntArrayList listToSort = new IntArrayList(priority.keySet()); + listToSort.sort(null); + List result = new ArrayList<>(); + for (IntListIterator iterator = listToSort.iterator(); iterator.hasNext(); ) { + int index = iterator.nextInt(); + List found = priority.get(index); + List toSort = new ArrayList<>(found); + toSort.sort(null); + result.addAll(toSort); + } + return result; } diff --git a/plugins/yaml/src/org/jetbrains/yaml/resolve/YAMLLocalResolveUtil.java b/plugins/yaml/src/org/jetbrains/yaml/resolve/YAMLLocalResolveUtil.java index 11e8277a7762..7a4b3fc5ac71 100644 --- a/plugins/yaml/src/org/jetbrains/yaml/resolve/YAMLLocalResolveUtil.java +++ b/plugins/yaml/src/org/jetbrains/yaml/resolve/YAMLLocalResolveUtil.java @@ -1,11 +1,9 @@ -// 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. +// Copyright 2000-2020 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 org.jetbrains.yaml.resolve; import com.intellij.psi.PsiFile; import com.intellij.psi.util.CachedValueProvider; import com.intellij.psi.util.CachedValuesManager; -import gnu.trove.THashMap; -import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.yaml.psi.YAMLAlias; import org.jetbrains.yaml.psi.YAMLAnchor; @@ -13,7 +11,7 @@ import org.jetbrains.yaml.psi.YamlRecursivePsiElementVisitor; import java.util.*; -public class YAMLLocalResolveUtil { +public final class YAMLLocalResolveUtil { private YAMLLocalResolveUtil() {} /** @@ -37,7 +35,7 @@ public class YAMLLocalResolveUtil { @NotNull private static YAMLAliasResolveResult getResolveData(@NotNull PsiFile file) { return CachedValuesManager.getCachedValue(file, () -> { - Map resolveMap = new THashMap<>(); + Map resolveMap = new HashMap<>(); Map defMap = new HashMap<>(); // store first definitions: need for completion @@ -58,7 +56,7 @@ public class YAMLLocalResolveUtil { } } }); - Set firstDefs = new THashSet<>(firstDefMap.values()); + Set firstDefs = new HashSet<>(firstDefMap.values()); YAMLAliasResolveResult result = new YAMLAliasResolveResult(resolveMap, firstDefs); return CachedValueProvider.Result.create(result, file); }); diff --git a/xml/dom-openapi/src/com/intellij/util/xml/DomResolveConverter.java b/xml/dom-openapi/src/com/intellij/util/xml/DomResolveConverter.java index bb48ebee9c6c..effc8864148a 100644 --- a/xml/dom-openapi/src/com/intellij/util/xml/DomResolveConverter.java +++ b/xml/dom-openapi/src/com/intellij/util/xml/DomResolveConverter.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2014 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. - */ +// Copyright 2000-2020 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.util.xml; import com.intellij.codeInsight.CodeInsightBundle; @@ -28,11 +14,11 @@ import com.intellij.psi.util.PsiModificationTracker; import com.intellij.util.containers.ConcurrentFactoryMap; import com.intellij.util.containers.SoftFactoryMap; import com.intellij.util.xml.highlighting.ResolvingElementQuickFix; -import gnu.trove.THashMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Collection; +import java.util.HashMap; import java.util.Map; /** @@ -41,7 +27,7 @@ import java.util.Map; * * @author peter */ -public class DomResolveConverter extends ResolvingConverter{ +public final class DomResolveConverter extends ResolvingConverter{ private static final Map, DomResolveConverter> ourCache = ConcurrentFactoryMap.createMap(key -> new DomResolveConverter(key)); private final boolean myAttribute; @@ -56,7 +42,7 @@ public class DomResolveConverter extends ResolvingConverte return CachedValuesManager.getManager(project).createCachedValue(new CachedValueProvider>() { @Override public Result> compute() { - final Map map = new THashMap<>(); + final Map map = new HashMap<>(); visitDomElement(scope, map); return new Result<>(map, PsiModificationTracker.MODIFICATION_COUNT); } diff --git a/xml/relaxng/src/org/intellij/plugins/relaxNG/model/CommonElement.java b/xml/relaxng/src/org/intellij/plugins/relaxNG/model/CommonElement.java index 6ae76e41b2fe..772cc9c63024 100644 --- a/xml/relaxng/src/org/intellij/plugins/relaxNG/model/CommonElement.java +++ b/xml/relaxng/src/org/intellij/plugins/relaxNG/model/CommonElement.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.intellij.plugins.relaxNG.model; import com.intellij.psi.PsiElement; @@ -39,7 +38,7 @@ public interface CommonElement { visitElement(pattern); } - public void visitDefine(Define define) { + public void visitDefine(Define define) { visitElement(define); } diff --git a/xml/relaxng/src/org/intellij/plugins/relaxNG/model/annotation/OverriddenDefineSearcher.java b/xml/relaxng/src/org/intellij/plugins/relaxNG/model/annotation/OverriddenDefineSearcher.java index 77aee805aff2..1f234d6a80ba 100644 --- a/xml/relaxng/src/org/intellij/plugins/relaxNG/model/annotation/OverriddenDefineSearcher.java +++ b/xml/relaxng/src/org/intellij/plugins/relaxNG/model/annotation/OverriddenDefineSearcher.java @@ -1,33 +1,19 @@ -/* - * Copyright 2000-2014 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. - */ +// Copyright 2000-2020 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 org.intellij.plugins.relaxNG.model.annotation; import com.intellij.psi.xml.XmlFile; -import gnu.trove.TIntArrayList; +import it.unimi.dsi.fastutil.ints.IntArrayList; import org.intellij.plugins.relaxNG.model.*; import java.util.List; -class OverriddenDefineSearcher extends CommonElement.Visitor { - private final Define myDefine; - private final TIntArrayList myIncludes = new TIntArrayList(); +final class OverriddenDefineSearcher extends CommonElement.Visitor { + private final Define myDefine; + private final IntArrayList myIncludes = new IntArrayList(); private final XmlFile myLocalFile; - private final List myResult; + private final List> myResult; - OverriddenDefineSearcher(Define define, XmlFile localFile, List result) { + OverriddenDefineSearcher(Define define, XmlFile localFile, List> result) { myLocalFile = localFile; myResult = result; myDefine = define; @@ -38,8 +24,9 @@ class OverriddenDefineSearcher extends CommonElement.Visitor { myIncludes.add(inc.getInclude() == myLocalFile ? 1 : 0); try { inc.acceptChildren(this); - } finally { - myIncludes.remove(myIncludes.size() - 1); + } + finally { + myIncludes.removeInt(myIncludes.size() - 1); } } @@ -49,8 +36,8 @@ class OverriddenDefineSearcher extends CommonElement.Visitor { } @Override - public void visitDefine(Define d) { - if (myIncludes.size() > 0 && myIncludes.get(myIncludes.size() - 1) == 1) { + public void visitDefine(Define d) { + if (myIncludes.size() > 0 && myIncludes.getInt(myIncludes.size() - 1) == 1) { if (d.getName().equals(myDefine.getName())) { myResult.add(d); } diff --git a/xml/xml-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/XmlUnusedNamespaceInspection.java b/xml/xml-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/XmlUnusedNamespaceInspection.java index 982cd8e844c4..10bf677e8800 100644 --- a/xml/xml-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/XmlUnusedNamespaceInspection.java +++ b/xml/xml-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/XmlUnusedNamespaceInspection.java @@ -2,23 +2,12 @@ package com.intellij.codeInsight.daemon.impl.analysis; import com.intellij.codeInsight.daemon.ImplicitUsageProvider; -import com.intellij.codeInspection.LocalQuickFix; -import com.intellij.codeInspection.ProblemDescriptor; -import com.intellij.codeInspection.ProblemHighlightType; -import com.intellij.codeInspection.ProblemsHolder; -import com.intellij.codeInspection.XmlSuppressableInspectionTool; +import com.intellij.codeInspection.*; import com.intellij.openapi.editor.Document; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.psi.PsiDocumentManager; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiElementVisitor; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiReference; -import com.intellij.psi.SmartPointerManager; -import com.intellij.psi.SmartPsiElementPointer; -import com.intellij.psi.XmlElementVisitor; +import com.intellij.psi.*; import com.intellij.psi.impl.source.resolve.reference.impl.providers.URLReference; import com.intellij.psi.impl.source.xml.SchemaPrefix; import com.intellij.psi.xml.XmlAttribute; @@ -30,14 +19,15 @@ import com.intellij.xml.DefaultXmlExtension; import com.intellij.xml.analysis.XmlAnalysisBundle; import com.intellij.xml.util.XmlRefCountHolder; import com.intellij.xml.util.XmlUtil; -import java.util.Objects; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Objects; + /** * @author Dmitry Avdeev */ -public class XmlUnusedNamespaceInspection extends XmlSuppressableInspectionTool { +public final class XmlUnusedNamespaceInspection extends XmlSuppressableInspectionTool { @NotNull @Override public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) { @@ -321,8 +311,7 @@ public class XmlUnusedNamespaceInspection extends XmlSuppressableInspectionTool } } - public static class RemoveNamespaceLocationFix extends RemoveNamespaceDeclarationFix { - + public static final class RemoveNamespaceLocationFix extends RemoveNamespaceDeclarationFix { public static final String NAME = "Remove unused namespace location"; private RemoveNamespaceLocationFix(String namespace) { diff --git a/xml/xml-psi-api/src/com/intellij/xml/util/XmlTagUtil.java b/xml/xml-psi-api/src/com/intellij/xml/util/XmlTagUtil.java index 4e7069abbb8d..81518d27a1bf 100644 --- a/xml/xml-psi-api/src/com/intellij/xml/util/XmlTagUtil.java +++ b/xml/xml-psi-api/src/com/intellij/xml/util/XmlTagUtil.java @@ -1,4 +1,4 @@ -// Copyright 2000-2019 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. +// Copyright 2000-2020 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.xml.util; import com.intellij.lang.ASTNode; @@ -12,20 +12,18 @@ import com.intellij.psi.xml.XmlTagValue; import com.intellij.psi.xml.XmlToken; import com.intellij.psi.xml.XmlTokenType; import com.intellij.util.ArrayUtilRt; -import gnu.trove.TObjectIntHashMap; +import it.unimi.dsi.fastutil.objects.Object2IntMap; +import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; -import java.util.List; - /** * @author peter */ @SuppressWarnings({"HardCodedStringLiteral"}) -public class XmlTagUtil extends XmlTagUtilBase { - private static final TObjectIntHashMap ourCharacterEntities = new TObjectIntHashMap<>(); +public final class XmlTagUtil extends XmlTagUtilBase { + private static final Object2IntMap ourCharacterEntities = new Object2IntOpenHashMap<>(); static { ourCharacterEntities.put("lt", '<'); @@ -84,13 +82,11 @@ public class XmlTagUtil extends XmlTagUtilBase { } public static String[] getCharacterEntityNames() { - List list = new ArrayList<>(); - ourCharacterEntities.forEachKey(list::add); - return ArrayUtilRt.toStringArray(list); + return ArrayUtilRt.toStringArray(ourCharacterEntities.keySet()); } public static char getCharacterByEntityName(String entityName) { - return (char)ourCharacterEntities.get(entityName); + return (char)ourCharacterEntities.getInt(entityName); } @Nullable diff --git a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlTextImpl.java b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlTextImpl.java index 990ca2592f92..3bda596b1e52 100644 --- a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlTextImpl.java +++ b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlTextImpl.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2014 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. - */ +// Copyright 2000-2020 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.psi.impl.source.xml; import com.intellij.lang.ASTFactory; @@ -35,7 +21,8 @@ import com.intellij.psi.xml.*; import com.intellij.util.ArrayUtil; import com.intellij.util.IncorrectOperationException; import com.intellij.xml.util.XmlUtil; -import gnu.trove.TIntArrayList; +import it.unimi.dsi.fastutil.ints.IntArrayList; +import it.unimi.dsi.fastutil.ints.IntList; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -78,8 +65,8 @@ public class XmlTextImpl extends XmlElementImpl implements XmlText, PsiLanguageI if (displayText != null) return displayText; StringBuilder buffer = new StringBuilder(); ASTNode child = getFirstChildNode(); - final TIntArrayList gapsStarts = new TIntArrayList(); - final TIntArrayList gapsShifts = new TIntArrayList(); + final IntList gapsStarts = new IntArrayList(); + final IntList gapsShifts = new IntArrayList(); while (child != null) { final int start = buffer.length(); IElementType elementType = child.getElementType(); @@ -117,8 +104,8 @@ public class XmlTextImpl extends XmlElementImpl implements XmlText, PsiLanguageI int[] gapPhysicalStarts = ArrayUtil.newIntArray(gapsShifts.size()); int currentGapsSum = 0; for (int i = 0; i < gapDisplayStarts.length; i++) { - currentGapsSum += gapsShifts.get(i); - gapDisplayStarts[i] = gapsStarts.get(i); + currentGapsSum += gapsShifts.getInt(i); + gapDisplayStarts[i] = gapsStarts.getInt(i); gapPhysicalStarts[i] = gapDisplayStarts[i] + currentGapsSum; } myGapDisplayStarts = gapDisplayStarts; diff --git a/xml/xml-psi-impl/src/com/intellij/xml/impl/schema/ComplexTypeDescriptor.java b/xml/xml-psi-impl/src/com/intellij/xml/impl/schema/ComplexTypeDescriptor.java index e7ecbb04c7d0..79ee92ee2dae 100644 --- a/xml/xml-psi-impl/src/com/intellij/xml/impl/schema/ComplexTypeDescriptor.java +++ b/xml/xml-psi-impl/src/com/intellij/xml/impl/schema/ComplexTypeDescriptor.java @@ -10,12 +10,7 @@ import com.intellij.psi.meta.PsiMetaData; import com.intellij.psi.util.CachedValue; import com.intellij.psi.util.CachedValueProvider; import com.intellij.psi.util.CachedValuesManager; -import com.intellij.psi.xml.XmlAttribute; -import com.intellij.psi.xml.XmlAttributeValue; -import com.intellij.psi.xml.XmlDocument; -import com.intellij.psi.xml.XmlElement; -import com.intellij.psi.xml.XmlFile; -import com.intellij.psi.xml.XmlTag; +import com.intellij.psi.xml.*; import com.intellij.util.ArrayUtil; import com.intellij.util.containers.ConcurrentFactoryMap; import com.intellij.xml.XmlAttributeDescriptor; @@ -24,18 +19,12 @@ import com.intellij.xml.XmlElementsGroup; import com.intellij.xml.XmlNSDescriptor; import com.intellij.xml.util.XmlUtil; import gnu.trove.THashSet; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.*; + public class ComplexTypeDescriptor extends TypeDescriptor { protected final XmlNSDescriptorImpl myDocumentDescriptor; @@ -80,8 +69,8 @@ public class ComplexTypeDescriptor extends TypeDescriptor { private final Map> myAnyAttributeCache = ConcurrentFactoryMap.createMap(key -> CachedValuesManager.getManager(myTag.getProject()).createCachedValue(() -> { - THashSet dependencies = new THashSet<>(); - CanContainAttributeType type = _canContainAttribute(key, myTag, null, new THashSet<>(), dependencies); + Set dependencies = new HashSet<>(); + CanContainAttributeType type = _canContainAttribute(key, myTag, null, new HashSet<>(), dependencies); if (dependencies.isEmpty()) { dependencies.add(myTag.getContainingFile()); } diff --git a/xml/xml-psi-impl/src/com/intellij/xml/util/HtmlUtil.java b/xml/xml-psi-impl/src/com/intellij/xml/util/HtmlUtil.java index ec4ca3d7942d..b911c2e3ca4f 100644 --- a/xml/xml-psi-impl/src/com/intellij/xml/util/HtmlUtil.java +++ b/xml/xml-psi-impl/src/com/intellij/xml/util/HtmlUtil.java @@ -1,4 +1,4 @@ -// Copyright 2000-2019 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. +// Copyright 2000-2020 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.xml.util; import com.intellij.codeInspection.InspectionProfile; @@ -49,7 +49,7 @@ import java.util.*; /** * @author Maxim.Mossienko */ -public class HtmlUtil { +public final class HtmlUtil { private static final Logger LOG = Logger.getInstance(HtmlUtil.class); @NonNls private static final String JSFC = "jsfc"; @@ -79,7 +79,7 @@ public class HtmlUtil { private HtmlUtil() { } - private static final Set EMPTY_TAGS_MAP = new THashSet<>(); + private static final Set EMPTY_TAGS_MAP = new HashSet<>(); @NonNls private static final String[] OPTIONAL_END_TAGS = { //"html", "head", @@ -87,7 +87,7 @@ public class HtmlUtil { "p", "li", "dd", "dt", "thead", "tfoot", "tbody", "colgroup", "tr", "th", "td", "option", "embed", "noembed", "caption" }; - private static final Set OPTIONAL_END_TAGS_MAP = new THashSet<>(); + private static final Set OPTIONAL_END_TAGS_MAP = new HashSet<>(); @NonNls private static final String[] BLOCK_TAGS = {"p", "h1", "h2", "h3", "h4", "h5", "h6", "ul", "ol", "dir", "menu", "pre", "dl", "div", "center", "noscript", "noframes", "blockquote", "form", "isindex", "hr", "table", "fieldset", "address", @@ -104,19 +104,19 @@ public class HtmlUtil { "kbd", "label", "map", "object", "q", "s", "samp", "select", "small", "span", "strike", "strong", "sub", "sup", "textarea", "tt", "u", "var"}; - private static final Set BLOCK_TAGS_MAP = new THashSet<>(); + private static final Set BLOCK_TAGS_MAP = new HashSet<>(); @NonNls private static final String[] INLINE_ELEMENTS_CONTAINER = {"p", "h1", "h2", "h3", "h4", "h5", "h6", "pre"}; private static final Set INLINE_ELEMENTS_CONTAINER_MAP = new THashSet<>(); - private static final Set POSSIBLY_INLINE_TAGS_MAP = new THashSet<>(); + private static final Set POSSIBLY_INLINE_TAGS_MAP = new HashSet<>(); @NonNls private static final String[] HTML5_TAGS = { "article", "aside", "audio", "canvas", "command", "datalist", "details", "embed", "figcaption", "figure", "footer", "header", "keygen", "mark", "meter", "nav", "output", "progress", "rp", "rt", "ruby", "section", "source", "summary", "time", "video", "wbr", "main" }; - private static final Set HTML5_TAGS_SET = new THashSet<>(); + private static final Set HTML5_TAGS_SET = new HashSet<>(); private static final Map> AUTO_CLOSE_BY_MAP = new THashMap<>(); static { diff --git a/xml/xml-structure-view-impl/src/com/intellij/lang/html/structureView/Html5SectionsProcessor.java b/xml/xml-structure-view-impl/src/com/intellij/lang/html/structureView/Html5SectionsProcessor.java index 0cf7a0cfe847..1b218ecb4a8f 100644 --- a/xml/xml-structure-view-impl/src/com/intellij/lang/html/structureView/Html5SectionsProcessor.java +++ b/xml/xml-structure-view-impl/src/com/intellij/lang/html/structureView/Html5SectionsProcessor.java @@ -1,4 +1,4 @@ -// 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. +// Copyright 2000-2020 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.lang.html.structureView; import com.intellij.ide.structureView.StructureViewTreeElement; @@ -6,6 +6,7 @@ import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.xml.XmlTag; import com.intellij.util.ArrayUtil; +import com.intellij.util.ArrayUtilRt; import com.intellij.util.containers.SortedList; import com.intellij.util.containers.Stack; import org.jetbrains.annotations.NotNull; @@ -18,8 +19,7 @@ import java.util.LinkedList; // Algorithm described on https://www.w3.org/TR/html51/sections.html#creating-an-outline // One of the implementations: http://hoyois.github.com/html5outliner/ (https://github.com/hoyois/html5outliner) -class Html5SectionsProcessor { - +final class Html5SectionsProcessor { private static class SectionHolder { private final XmlTag myTag; private final LinkedList
myChildren = new LinkedList<>(); @@ -268,7 +268,7 @@ class Html5SectionsProcessor { int minIndex = HEADER_ELEMENTS.length; for (XmlTag subTag : header.getSubTags()) { - final int index = ArrayUtil.indexOf(HEADER_ELEMENTS, StringUtil.toLowerCase(subTag.getLocalName())); + int index = ArrayUtilRt.indexOf(HEADER_ELEMENTS, StringUtil.toLowerCase(subTag.getLocalName()), 0, HEADER_ELEMENTS.length); if (index < minIndex) { minIndex = index; if (minIndex == 0) break; @@ -283,7 +283,7 @@ class Html5SectionsProcessor { return minIndex + 1; } - final int index = ArrayUtil.indexOf(HEADER_ELEMENTS, StringUtil.toLowerCase(header.getLocalName())); + int index = ArrayUtilRt.indexOf(HEADER_ELEMENTS, StringUtil.toLowerCase(header.getLocalName()), 0, HEADER_ELEMENTS.length); if (index < 0) throw new IllegalArgumentException(header.getName()); return index + 1; }