migrate from trove collections to java/fastutil

GitOrigin-RevId: fbbad777e5faa490f777c09f0189eddb3ffdecc9
This commit is contained in:
Vladimir Krivosheev
2020-06-04 12:09:17 +03:00
committed by intellij-monorepo-bot
parent 07ed7e4294
commit ae99e746bc
54 changed files with 585 additions and 731 deletions
@@ -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<Path> foundFiles = new THashSet<>();
final Set<Path> foundFiles = new ObjectOpenHashSet<>();
final List<Path> moduleFiles = new ArrayList<>();
for (Element moduleElement : JDOMUtil.getChildren(componentElement.getChild(MODULES_TAG), MODULE_TAG)) {
final String path = moduleElement.getAttributeValue(FILE_PATH_ATTRIBUTE);
@@ -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<Macro> = ContainerUtil.createLockFreeCopyOnWriteList()
private val storageLock = ReentrantReadWriteLock()
private val storages = Object2ObjectOpenHashMap<String, StateStorage>()
private val storages = HashMap<String, StateStorage>()
val compoundStreamProvider: CompoundStreamProvider = CompoundStreamProvider()
@@ -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;
@@ -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;
@@ -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;
@@ -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) {
@@ -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;
@@ -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;
@@ -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<String, KdbxGroup> = THashMap()
private val groups: MutableMap<String, KdbxGroup> = HashMap()
private val entries: MutableList<KdbxEntry> by lazy {
ContainerUtil.createLockFreeCopyOnWriteList(element.getChildren(KdbxDbElementNames.entry).map { KdbxEntry(it, database, this) })
}
@@ -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<String> {
val map = TIntObjectHashMap<String>()
private fun readAttributes(list: SecKeychainAttributeList): Int2ObjectMap<String> {
val map = Int2ObjectOpenHashMap<String>()
val attrList = SecKeychainAttribute(list.attr!!)
attrList.read()
@Suppress("UNCHECKED_CAST")
@@ -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<CredentialAttributes, Credentials>()
val credentialMap = HashMap<CredentialAttributes, Credentials>()
for (i in 0..9) {
val accountName = randomString()
val attributes = CredentialAttributes(randomString(), accountName)
@@ -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;
@@ -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<HttpConfigurab
public boolean KEEP_PROXY_PASSWORD;
public transient String LAST_ERROR;
private final Object2ObjectMap<CommonProxy.HostInfo, ProxyInfo> myGenericPasswords = new Object2ObjectOpenHashMap<>();
private final Set<CommonProxy.HostInfo> myGenericCancelled = new ObjectOpenHashSet<>();
private final Map<CommonProxy.HostInfo, ProxyInfo> myGenericPasswords = new HashMap<>();
private final Set<CommonProxy.HostInfo> myGenericCancelled = new HashSet<>();
public String PROXY_EXCEPTIONS;
public boolean USE_PAC_URL;
@@ -169,12 +168,7 @@ public class HttpConfigurable implements PersistentStateComponent<HttpConfigurab
private void correctPasswords(@NotNull HttpConfigurable to) {
synchronized (myLock) {
for (ObjectIterator<Object2ObjectMap.Entry<CommonProxy.HostInfo, ProxyInfo>> iterator = Object2ObjectMaps.fastIterator(to.myGenericPasswords); iterator.hasNext(); ) {
Object2ObjectMap.Entry<CommonProxy.HostInfo, ProxyInfo> entry = iterator.next();
if (!entry.getValue().isStore()) {
iterator.remove();
}
}
to.myGenericPasswords.values().removeIf(it -> !it.isStore());
}
}
@@ -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<List<String>> portToPath = new Int2ObjectOpenHashMap<>(2);
Map<Integer, List<String>> portToPath = new HashMap<>();
readPort(myConfigPath, portToPath);
readPort(mySystemPath, portToPath);
if (!portToPath.isEmpty()) {
args = JetBrainsProtocolHandler.checkForJetBrainsProtocolCommand(args);
for (Int2ObjectMap.Entry<List<String>> entry : Int2ObjectMaps.fastIterable(portToPath)) {
Map.Entry<ActivationStatus, CliResult> status = tryActivate(entry.getIntKey(), entry.getValue(), args);
for (Map.Entry<Integer, List<String>> entry : portToPath.entrySet()) {
Map.Entry<ActivationStatus, CliResult> 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<List<String>> portToPath) {
private static void readPort(@NotNull Path dir, @NotNull Map<Integer, List<String>> portToPath) {
try {
int port = Integer.parseInt(readOneLine(dir.resolve(PORT_FILE)));
List<String> 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) {
}
@@ -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<? extends CharSequence> namesToRemove) {
public void removeChildren(@NotNull IntSet idsToRemove, @NotNull List<? extends CharSequence> namesToRemove) {
boolean caseSensitive = getFileSystem().isCaseSensitive();
synchronized (myData) {
// remove from array by merging two sorted lists
@@ -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<String> 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<String> strategy;
final boolean isFsCaseSensitive;
final BlockingQueue<NewVirtualFile> filesToBecomeDirty = new LinkedBlockingQueue<>();
RefreshContext(@NotNull NewVirtualFileSystem fs, @NotNull PersistentFS persistence, @NotNull TObjectHashingStrategy<String> 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<VirtualFile>, List<String>> result = ReadAction.compute(() -> pair(dir.getCachedChildren(), dir.getSuspiciousNames()));
Pair<List<VirtualFile>, List<String>> result = ReadAction.compute(() -> new Pair<>(dir.getCachedChildren(), dir.getSuspiciousNames()));
List<VirtualFile> cached = result.getFirst();
List<String> wanted = result.getSecond();
@@ -269,8 +263,8 @@ class LocalFileSystemRefreshWorker {
private static class SequentialRefreshContext extends RefreshContext {
private final Queue<Runnable> myRefreshRequests = new Queue<>(100);
SequentialRefreshContext(@NotNull NewVirtualFileSystem fs, @NotNull PersistentFS persistentFS, @NotNull TObjectHashingStrategy<String> 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<String> 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<Path> {
private final class RefreshingFileVisitor extends SimpleFileVisitor<Path> {
private final VfsEventGenerationHelper myHelper = new VfsEventGenerationHelper();
private final Map<String, VirtualFile> myPersistentChildren;
private final Set<String> myChildrenWeAreInterested; // null - no limit
@@ -339,13 +333,15 @@ class LocalFileSystemRefreshWorker {
@NotNull Collection<? extends VirtualFile> 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);
}
}
}
@@ -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<? extends VFileEvent> events,
int startIndex,
@NotNull MostlySingularMultiMap<String, VFileEvent> filesInvolved,
@NotNull Set<? super String> middleDirsInvolved,
@NotNull Set<String> middleDirsInvolved,
@NotNull Set<? super String> deletedPaths,
@NotNull Set<? super String> createdPaths,
@NotNull Set<? super VFileEvent> 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<String, VFileEvent> files,
@NotNull Set<? super String> middleDirs) {
Iterable<VFileEvent> stored = files.get(path);
if (!canReconcileEvents(event, stored)) {
@NotNull Set<String> 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<? extends VFileEvent> 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<? super Runnable> outApplyEvents,
@NotNull List<? super VFileEvent> outValidatedEvents,
@NotNull MostlySingularMultiMap<String, VFileEvent> filesInvolved,
@NotNull Set<? super String> middleDirsInvolved) {
@NotNull Set<String> middleDirsInvolved) {
Set<VFileEvent> 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<Runnable> applyEvents = new ArrayList<>(cappedInitialSize);
MostlySingularMultiMap<String, VFileEvent> files = new MostlySingularMultiMap<String, VFileEvent>(){
@NotNull
@Override
protected Map<String, Object> createMap() {
return new THashMap<>(cappedInitialSize, FileUtil.PATH_HASHING_STRATEGY);
}
};
Set<String> middleDirs = new THashSet<>(cappedInitialSize, FileUtil.PATH_HASHING_STRATEGY);
MostlySingularMultiMap<String, VFileEvent> files = new MostlySingularMultiMap<>(CollectionFactory.createFilePathMap(cappedInitialSize));
Set<String> middleDirs = CollectionFactory.createFilePathSet(cappedInitialSize);
List<VFileEvent> 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<CharSequence> childrenNamesDeleted = new ArrayList<>(deleteEvents.size());
TIntHashSet childrenIdsDeleted = new TIntHashSet(deleteEvents.size());
IntSet childrenIdsDeleted = new IntOpenHashSet(deleteEvents.size());
List<ChildInfo> 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<? extends VFileCreateEvent> createEvents) {
@NotNull Collection<VFileCreateEvent> 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<? extends VFileCreateEvent> createEvents,
private static void saveScannedChildrenRecursively(@NotNull Collection<VFileCreateEvent> createEvents,
@NotNull NewVirtualFileSystem delegate,
@NotNull TObjectHashingStrategy<CharSequence> 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
@@ -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<CharSequence> names = ContainerUtil.map(events, e -> ((VFileCreateEvent)e).getChildName());
temp.removeChildren(new TIntHashSet(), names);
temp.removeChildren(IntSortedSets.EMPTY_SET, names);
}
private void eventsForDeleting(List<? super VFileEvent> events, VirtualDirectoryImpl temp) {
@@ -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<RemoteServersServiceViewContributor, Boolean> myContributors = ContainerUtil.createConcurrentWeakMap();
private final Map<RemoteServersServiceViewContributor, Boolean> myContributors = CollectionFactory.createConcurrentWeakMap();
private final Map<RemoteServer<?>, 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<ServerConnection<?>> myConnectionsToExpand = new SmartHashSet<>();
private final Set<ServerConnection<?>> myConnectionsToExpand = new HashSet<>();
@Override
public void onConnectionCreated(@NotNull ServerConnection<?> connection) {
@@ -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 <T, R> Collection<T>.mapSmart(transform: (T) -> R): List<R> {
inline fun <T, R> Collection<T>.mapSmartSet(transform: (T) -> R): Set<R> {
return when (val size = size) {
1 -> {
val result = SmartHashSet<R>()
result.add(transform(first()))
result
Collections.singleton(transform(first()))
}
0 -> emptySet()
else -> mapTo(THashSet(size), transform)
else -> mapTo(HashSet(size), transform)
}
}
@@ -88,6 +88,28 @@ public final class CollectionFactory {
}
}
public static @NotNull Set<String> createFilePathSet(int expectedSize) {
return createFilePathSet(expectedSize, SystemInfoRt.isFileSystemCaseSensitive);
}
public static @NotNull Set<String> createFilePathSet(int expectedSize, boolean isFileSystemCaseSensitive) {
if (isFileSystemCaseSensitive) {
return new HashSet<>(expectedSize);
}
else {
return new ObjectOpenCustomHashSet<>(expectedSize, CaseInsensitiveStringHashingStrategy.INSTANCE);
}
}
public static @NotNull Set<String> createFilePathSet(@NotNull Collection<String> paths, boolean isFileSystemCaseSensitive) {
if (isFileSystemCaseSensitive) {
return new HashSet<>(paths);
}
else {
return new ObjectOpenCustomHashSet<>(paths, CaseInsensitiveStringHashingStrategy.INSTANCE);
}
}
public static @NotNull <V> Map<String, V> createFilePathMap() {
if (SystemInfoRt.isFileSystemCaseSensitive) {
return new HashMap<>();
@@ -97,6 +119,19 @@ public final class CollectionFactory {
}
}
public static @NotNull <V> Map<String, V> createFilePathMap(int expectedSize) {
return createFilePathMap(expectedSize, SystemInfoRt.isFileSystemCaseSensitive);
}
public static @NotNull <V> Map<String, V> createFilePathMap(int expectedSize, boolean isFileSystemCaseSensitive) {
if (isFileSystemCaseSensitive) {
return new HashMap<>(expectedSize);
}
else {
return new Object2ObjectOpenCustomHashMap<>(expectedSize, CaseInsensitiveStringHashingStrategy.INSTANCE);
}
}
public static @NotNull <V> Map<File, V> createFileMap() {
return new Object2ObjectOpenCustomHashMap<>(FILE_HASH_STRATEGY);
}
@@ -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<K, V> extends MostlySingularMultiMap<K, V> {
@Override
protected @NotNull Map<K, Object> createMap() {
return new ConcurrentHashMap<>();
public final class ConcurrentMostlySingularMultiMap<K, V> extends MostlySingularMultiMap<K, V> {
public ConcurrentMostlySingularMultiMap() {
super(new ConcurrentHashMap<>());
}
@Override
@@ -22,17 +20,19 @@ public class ConcurrentMostlySingularMultiMap<K, V> 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<Object> newList = new ValueList<>(curList.size() + 1);
List<?> curList = (ValueList<?>)current;
List<Object> newList = new ValueList<>(curList.size() + 1);
newList.addAll(curList);
newList.add(value);
if (map.replace(key, curList, newList)) break;
}
else {
ValueList<Object> newList = new ValueList<>(2);
List<Object> newList = new ValueList<>(2);
newList.add(current);
newList.add(value);
if (map.replace(key, current, newList)) break;
@@ -63,7 +63,7 @@ public class ConcurrentMostlySingularMultiMap<K, V> extends MostlySingularMultiM
}
@Override
public void addAll(MostlySingularMultiMap<? extends K, ? extends V> other) {
public void addAll(@NotNull MostlySingularMultiMap<K, V> other) {
throw new AbstractMethodError("Not yet re-implemented for concurrency");
}
@@ -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<K, V> implements Serializable {
protected final Map<K, Object> myMap;
public MostlySingularMultiMap() {
myMap = createMap();
myMap = new Object2ObjectOpenHashMap<>();
}
@NotNull
protected Map<K, Object> createMap() {
return new THashMap<>();
public MostlySingularMultiMap(@NotNull Map<K, Object> map) {
myMap = map;
}
public void add(@NotNull K key, @NotNull V value) {
@@ -37,11 +37,10 @@ public class MostlySingularMultiMap<K, V> implements Serializable {
}
else if (current instanceof ValueList) {
//noinspection unchecked
ValueList<Object> curList = (ValueList<Object>) current;
curList.add(value);
((List<V>)current).add(value);
}
else {
ValueList<V> newList = new ValueList<>();
List<V> newList = new ValueList<>();
//noinspection unchecked
newList.add((V)current);
newList.add(value);
@@ -54,17 +53,14 @@ public class MostlySingularMultiMap<K, V> implements Serializable {
if (current == null) {
return false;
}
if (current instanceof ValueList) {
else if (current instanceof ValueList) {
//noinspection unchecked
ValueList<V> curList = (ValueList<V>) current;
return curList.remove(value);
return ((List<V>)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<K, V> implements Serializable {
return myMap.remove(key) != null;
}
@NotNull
public Set<K> keySet() {
public final @NotNull Set<K> keySet() {
return myMap.keySet();
}
public boolean isEmpty() {
public final boolean isEmpty() {
return myMap.isEmpty();
}
public boolean processForKey(@NotNull K key, @NotNull Processor<? super V> p) {
public final boolean processForKey(@NotNull K key, @NotNull Processor<? super V> p) {
return processValue(p, myMap.get(key));
}
@@ -89,64 +84,73 @@ public class MostlySingularMultiMap<K, V> implements Serializable {
if (v instanceof ValueList) {
//noinspection unchecked
for (V o : (ValueList<V>)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<? super V> 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<V>)current).size();
}
return 1;
}
@NotNull
public Iterable<V> get(@NotNull K name) {
final Object value = myMap.get(name);
return rawValueToCollection(value);
public final @NotNull Iterable<V> get(@NotNull K name) {
return rawValueToCollection(myMap.get(name));
}
@NotNull
protected List<V> rawValueToCollection(Object value) {
if (value == null) return Collections.emptyList();
if (value instanceof ValueList) {
protected final @NotNull List<V> rawValueToCollection(Object value) {
if (value == null) {
return Collections.emptyList();
}
else if (value instanceof ValueList) {
//noinspection unchecked
return (ValueList<V>)value;
}
//noinspection unchecked
return Collections.singletonList((V)value);
else {
//noinspection unchecked
return Collections.singletonList((V)value);
}
}
public void compact() {
((THashMap<K,Object>)myMap).compact();
if (myMap instanceof Object2ObjectOpenHashMap) {
((Object2ObjectOpenHashMap<K, Object>)myMap).trim();
}
else if (myMap instanceof Object2ObjectOpenCustomHashMap) {
((Object2ObjectOpenCustomHashMap<K, Object>)myMap).trim();
}
for (Object eachValue : myMap.values()) {
if (eachValue instanceof ValueList) {
//noinspection unchecked
@@ -156,7 +160,7 @@ public class MostlySingularMultiMap<K, V> 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<K, V> implements Serializable {
}
@NotNull
public static <K,V> MostlySingularMultiMap<K,V> emptyMap() {
public static <K, V> MostlySingularMultiMap<K, V> emptyMap() {
//noinspection unchecked
return (MostlySingularMultiMap<K, V>)EMPTY;
return (MostlySingularMultiMap<K, V>)EmptyMap.EMPTY;
}
@NotNull
public static <K, V> MostlySingularMultiMap<K, V> newMap() {
return new MostlySingularMultiMap<>();
}
private static final MostlySingularMultiMap<?,?> EMPTY = new EmptyMap();
public void addAll(MostlySingularMultiMap<? extends K, ? extends V> other) {
if (other instanceof EmptyMap) return;
public void addAll(@NotNull MostlySingularMultiMap<K, V> other) {
if (other.isEmpty()) {
return;
}
for (Map.Entry<? extends K, Object> entry : other.myMap.entrySet()) {
K key = entry.getKey();
@@ -199,7 +199,7 @@ public class MostlySingularMultiMap<K, V> implements Serializable {
}
else if (myValue instanceof ValueList) {
//noinspection unchecked
ValueList<V> myListValue = (ValueList<V>)myValue;
List<V> myListValue = (ValueList<V>)myValue;
if (otherValue instanceof ValueList) {
//noinspection unchecked
myListValue.addAll((ValueList<? extends V>)otherValue);
@@ -212,15 +212,15 @@ public class MostlySingularMultiMap<K, V> implements Serializable {
else {
if (otherValue instanceof ValueList) {
//noinspection unchecked
ValueList<V> otherListValue = (ValueList<V>)otherValue;
ValueList<V> newList = new ValueList<>(otherListValue.size() + 1);
List<V> otherListValue = (ValueList<V>)otherValue;
List<V> newList = new ValueList<>(otherListValue.size() + 1);
//noinspection unchecked
newList.add((V)myValue);
newList.addAll(otherListValue);
myMap.put(key, newList);
}
else {
ValueList<Object> newList = new ValueList<>();
List<Object> newList = new ValueList<>();
newList.add(myValue);
newList.add(otherValue);
myMap.put(key, newList);
@@ -230,7 +230,7 @@ public class MostlySingularMultiMap<K, V> implements Serializable {
}
// marker class to distinguish multi-values from single values in case client want to store collections as values.
protected static class ValueList<V> extends ArrayList<V> {
protected static final class ValueList<V> extends ArrayList<V> {
public ValueList() {
}
@@ -242,8 +242,23 @@ public class MostlySingularMultiMap<K, V> implements Serializable {
super(c);
}
}
private static class EmptyMap extends MostlySingularMultiMap<Object, Object> {
public static @NotNull Class<? extends List<?>> 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<Object, Object> {
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<K, V> 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<Object> 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<Object> get(@NotNull Object name) {
return ContainerUtil.emptyList();
}
}
}
@@ -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<Icon, Icon> ourIcon2DisabledIcon = ContainerUtil.createConcurrentWeakMap(200, 0.75f, Math.min(Runtime.getRuntime().availableProcessors(), 4), ContainerUtil.canonicalStrategy());
private static final ConcurrentMap<Icon, Icon> ourIcon2DisabledIcon = CollectionFactory.createConcurrentWeakMap(200, 0.75f, Math.min(Runtime.getRuntime().availableProcessors(), 4));
private static volatile boolean STRICT_GLOBAL;
@@ -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<GraphicsConfiguration, Pair<Insets, Long>> ourInsetsCache =
Patches.isJdkBugId8004103() ? ContainerUtil.createWeakMap() : null;
Patches.isJdkBugId8004103() ? CollectionFactory.createWeakMap() : null;
private static final int ourInsetsTimeout = 5000; // shouldn't be too long
private ScreenUtil() { }
@@ -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<String, Pair<Image, ImageLoader.Dimension2DDouble>> ourCache = ContainerUtil.createConcurrentSoftValueMap();
private static final ConcurrentMap<String, Image> ourLargeImageCache = ContainerUtil.createConcurrentWeakValueMap();
private static final ConcurrentMap<Image, ImageLoader.Dimension2DDouble> ourLargeImageDimensionMap = ContainerUtil.createConcurrentWeakMap();
private static final ConcurrentMap<Image, ImageLoader.Dimension2DDouble> ourLargeImageDimensionMap = CollectionFactory.createConcurrentWeakMap();
final @NotNull String path;
public final double scale; // initial scale factor
@@ -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<EnumMap<ScaleType, TDoubleObjectHashMap<Scale>>> cache =
private static final ThreadLocal<EnumMap<ScaleType, Double2ObjectOpenHashMap<Scale>>> cache =
ThreadLocal.withInitial(() -> new EnumMap<>(ScaleType.class));
@NotNull
public static Scale create(double value, @NotNull ScaleType type) {
EnumMap<ScaleType, TDoubleObjectHashMap<Scale>> enumMap = cache.get();
TDoubleObjectHashMap<Scale> map = enumMap.get(type);
EnumMap<ScaleType, Double2ObjectOpenHashMap<Scale>> enumMap = cache.get();
Double2ObjectOpenHashMap<Scale> 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;
@@ -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<GraphicsDevice, Boolean> devicesToRetinaSupportCacheMap = ContainerUtil.createWeakMap();
private static final Map<GraphicsDevice, Boolean> devicesToRetinaSupportCacheMap = CollectionFactory.createWeakMap();
@NotNull
// cannot be static because logging maybe not configured yet
@@ -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.*;
* </pre>
* 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<Insets> myDefaultColumnInsets = new TIntObjectHashMap<>();
@NotNull private final Int2ObjectOpenHashMap<Insets> myDefaultColumnInsets = new Int2ObjectOpenHashMap<>();
public GridBag() {
gridx = gridy = -1;
@@ -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]);
}
}
@@ -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<String>): Set<File> {
val result = THashSet(FileUtil.FILE_HASHING_STRATEGY)
val result = CollectionFactory.createFileSet()
for (path in classpath) {
result.add(File(path))
}
@@ -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<String> myMisses = new THashSet<>();
private final Set<String> myMisses = new HashSet<>();
public AntResourcesClassLoader(final List<URL> 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);
@@ -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<Boolean> ourIsBuildingClasspathForCustomTagLoading = ThreadLocal.withInitial(() -> Boolean.FALSE);
private static final Logger LOG = Logger.getInstance(CustomAntElementsRegistry.class);
private static final Key<CustomAntElementsRegistry> REGISTRY_KEY = Key.create("_custom_element_registry_");
private final Map<XmlName, ClassProvider> myCustomElements = new THashMap<>();
private final Map<AntDomNamedElement, String> myTypeDefErrors = new THashMap<>();
private final Map<XmlName, AntDomNamedElement> myDeclarations = new THashMap<>();
private final Map<String, ClassLoader> myNamedLoaders = new THashMap<>();
private final Map<XmlName, ClassProvider> myCustomElements = new HashMap<>();
private final Map<AntDomNamedElement, String> myTypeDefErrors = new HashMap<>();
private final Map<XmlName, AntDomNamedElement> myDeclarations = new HashMap<>();
private final Map<String, ClassLoader> myNamedLoaders = new HashMap<>();
private CustomAntElementsRegistry(final AntDomProject antProject) {
antProject.accept(new CustomTagDefinitionFinder(antProject));
@@ -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);
@@ -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<JavaSourceRootDescriptor, ModuleBuildTarget> 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<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder,
JpsAppEngineModuleExtension extension) throws IOException, ProjectBuildException {
final Set<File> roots = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
final Set<File> roots = CollectionFactory.createFileSet();
for (String path : extension.getFilesToEnhance()) {
roots.add(new File(FileUtil.toSystemDependentName(path)));
}
@@ -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<MethodSignature> getDuplicatedSignatures(@NotNull PsiClass clazz) {
return CachedValuesManager.getCachedValue(clazz, () -> {
PsiElementFactory factory = JavaPsiFacade.getInstance(clazz.getProject()).getElementFactory();
MostlySingularMultiMap<MethodSignature, PsiMethod> signatures = MostlySingularMultiMap.newMap();
MostlySingularMultiMap<MethodSignature, PsiMethod> signatures = new MostlySingularMultiMap<>();
for (PsiMethod method : clazz.getMethods()) {
MethodSignature signature = method.getSignature(factory.createRawSubstitutor(method));
signatures.add(signature, method);
@@ -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> 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<Locale, String> locales = new THashMap<>(splitRawLocales.length);
final Map<Locale, String> locales = new HashMap<>(splitRawLocales.length);
for (String rawLocale : splitRawLocales) {
final Pair<Locale, String> localeAndSuffix = PropertiesUtil.getLocaleAndTrimmedSuffix("_" + rawLocale + ".properties");
@@ -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<String, String>()
val data = HashMap<String, String>()
repository.processChildren("keymaps") {name, input ->
data.put(name, FileUtil.loadTextAndClose(input))
true
@@ -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;
@@ -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<TextMateElementType> tokenTypeMap;
public final class TextMateLexerDataStorage extends ShortBasedStorage {
private final Object2IntMap<TextMateElementType> tokenTypeMap;
private final List<TextMateElementType> tokenTypes;
public TextMateLexerDataStorage() {
this(new TObjectIntHashMap<>(), new SmartList<>());
this(new Object2IntOpenHashMap<>(), new ArrayList<>());
}
private TextMateLexerDataStorage(@NotNull TObjectIntHashMap<TextMateElementType> tokenTypeMap,
private TextMateLexerDataStorage(@NotNull Object2IntMap<TextMateElementType> tokenTypeMap,
@NotNull List<TextMateElementType> tokenTypes) {
super();
this.tokenTypeMap = tokenTypeMap;
@@ -25,7 +26,7 @@ public class TextMateLexerDataStorage extends ShortBasedStorage {
}
private TextMateLexerDataStorage(short @NotNull [] data,
@NotNull TObjectIntHashMap<TextMateElementType> tokenTypeMap,
@NotNull Object2IntMap<TextMateElementType> tokenTypeMap,
@NotNull List<TextMateElementType> 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);
@@ -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<PsiElement> myHistory = new ReferenceOpenHashSet<>();
private final Set<PsiElement> myHistory = ContainerUtil.newIdentityTroveSet();
private ResolveUtil() {
}
private ResolveUtil() {
@Nullable
public static Collection<XmlFile> getDependencies(XmlFile element) {
final CommonProcessors.CollectUniquesProcessor<XmlFile> processor = new CommonProcessors.CollectUniquesProcessor<XmlFile>() {
@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<XmlFile> getDependencies(XmlFile element) {
final CommonProcessors.CollectUniquesProcessor<XmlFile> processor = new CommonProcessors.CollectUniquesProcessor<XmlFile>() {
@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<PsiElement> 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<PsiElement> 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<PsiElement> process(final Matcher matcher, final boolean resolve) {
return new ResolveUtil()._process(matcher, resolve);
}
private List<PsiElement> _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<PsiElement> 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<XmlTag> {
@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<PsiElement> 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<PsiElement> 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<PsiElement> process(final Matcher matcher, final boolean resolve) {
return new ResolveUtil()._process(matcher, resolve);
}
private List<PsiElement> _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<PsiElement> 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<XmlTag> {
@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());
}
}
@@ -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<YamlMetaType> flattenedTypes = new SmartList<>();
Set<YamlMetaType> cerber = ContainerUtil.newIdentityTroveSet();
Set<YamlMetaType> 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);
}
@@ -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<String, Integer> {
public final class YAMLKeysIndex extends FileBasedIndexExtension<String, Integer> {
@NonNls
public static final ID<String, Integer> KEY = ID.create("yaml.keys.name");
@@ -35,7 +36,7 @@ public class YAMLKeysIndex extends FileBasedIndexExtension<String, Integer> {
@NotNull
@Override
public Map<String, Integer> map(@NotNull FileContent inputData) {
final Map<String, Integer> map = new THashMap<>();
Object2IntMap<String> map = new Object2IntOpenHashMap<>();
inputData.getPsiFile().accept(new YamlRecursivePsiElementVisitor() {
@Override
public void visitKeyValue(@NotNull YAMLKeyValue keyValue) {
@@ -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<YAMLKeyNavigationItem> {
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<String> applyPattern(@NotNull Collection<String> keys,
@NotNull String pattern,
ProgressIndicator progressIndicator) {
MultiMap<Integer, String> priority = MultiMap.create();
Int2ObjectMap<List<String>> 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<String> result = new ArrayList<>();
for (IntListIterator iterator = listToSort.iterator(); iterator.hasNext(); ) {
int index = iterator.nextInt();
List<String> found = priority.get(index);
List<String> toSort = new ArrayList<>(found);
toSort.sort(null);
result.addAll(toSort);
}
return result;
}
@@ -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<YAMLAlias, YAMLAnchor> resolveMap = new THashMap<>();
Map<YAMLAlias, YAMLAnchor> resolveMap = new HashMap<>();
Map<String, YAMLAnchor> defMap = new HashMap<>();
// store first definitions: need for completion
@@ -58,7 +56,7 @@ public class YAMLLocalResolveUtil {
}
}
});
Set<YAMLAnchor> firstDefs = new THashSet<>(firstDefMap.values());
Set<YAMLAnchor> firstDefs = new HashSet<>(firstDefMap.values());
YAMLAliasResolveResult result = new YAMLAliasResolveResult(resolveMap, firstDefs);
return CachedValueProvider.Result.create(result, file);
});
@@ -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<T extends DomElement> extends ResolvingConverter<T>{
public final class DomResolveConverter<T extends DomElement> extends ResolvingConverter<T>{
private static final Map<Class<? extends DomElement>, DomResolveConverter> ourCache =
ConcurrentFactoryMap.createMap(key -> new DomResolveConverter(key));
private final boolean myAttribute;
@@ -56,7 +42,7 @@ public class DomResolveConverter<T extends DomElement> extends ResolvingConverte
return CachedValuesManager.getManager(project).createCachedValue(new CachedValueProvider<Map<String, DomElement>>() {
@Override
public Result<Map<String, DomElement>> compute() {
final Map<String, DomElement> map = new THashMap<>();
final Map<String, DomElement> map = new HashMap<>();
visitDomElement(scope, map);
return new Result<>(map, PsiModificationTracker.MODIFICATION_COUNT);
}
@@ -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<E extends PsiElement> {
visitElement(pattern);
}
public void visitDefine(Define define) {
public void visitDefine(Define<?, ?> define) {
visitElement(define);
}
@@ -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<? super Define> myResult;
private final List<? super Define<?, ?>> myResult;
OverriddenDefineSearcher(Define define, XmlFile localFile, List<? super Define> result) {
OverriddenDefineSearcher(Define<?, ?> define, XmlFile localFile, List<? super Define<?, ?>> 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);
}
@@ -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) {
@@ -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<String> ourCharacterEntities = new TObjectIntHashMap<>();
public final class XmlTagUtil extends XmlTagUtilBase {
private static final Object2IntMap<String> ourCharacterEntities = new Object2IntOpenHashMap<>();
static {
ourCharacterEntities.put("lt", '<');
@@ -84,13 +82,11 @@ public class XmlTagUtil extends XmlTagUtilBase {
}
public static String[] getCharacterEntityNames() {
List<String> 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
@@ -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;
@@ -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<String, CachedValue<CanContainAttributeType>> myAnyAttributeCache =
ConcurrentFactoryMap.createMap(key -> CachedValuesManager.getManager(myTag.getProject()).createCachedValue(() -> {
THashSet<Object> dependencies = new THashSet<>();
CanContainAttributeType type = _canContainAttribute(key, myTag, null, new THashSet<>(), dependencies);
Set<Object> dependencies = new HashSet<>();
CanContainAttributeType type = _canContainAttribute(key, myTag, null, new HashSet<>(), dependencies);
if (dependencies.isEmpty()) {
dependencies.add(myTag.getContainingFile());
}
@@ -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<String> EMPTY_TAGS_MAP = new THashSet<>();
private static final Set<String> 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<String> OPTIONAL_END_TAGS_MAP = new THashSet<>();
private static final Set<String> 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<String> BLOCK_TAGS_MAP = new THashSet<>();
private static final Set<String> 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<String> INLINE_ELEMENTS_CONTAINER_MAP = new THashSet<>();
private static final Set<String> POSSIBLY_INLINE_TAGS_MAP = new THashSet<>();
private static final Set<String> 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<String> HTML5_TAGS_SET = new THashSet<>();
private static final Set<String> HTML5_TAGS_SET = new HashSet<>();
private static final Map<String, Set<String>> AUTO_CLOSE_BY_MAP = new THashMap<>();
static {
@@ -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<Section> 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;
}