@NotNull @Override public PsiClassType createTypeByFQClassName(@NotNull final String qName, @NotNull final GlobalSearchScope resolveScope) { if (CommonClassNames.JAVA_LANG_OBJECT.equals(qName)) { PsiClassType cachedObjectType = myCachedObjectType.get(resolveScope); if (cachedObjectType != null) { return cachedObjectType; } PsiClass aClass = JavaPsiFacade.getInstance(myManager.getProject()).findClass(CommonClassNames.JAVA_LANG_OBJECT, resolveScope); if (aClass != null) { cachedObjectType = new PsiImmediateClassType(aClass, PsiSubstitutor.EMPTY); cachedObjectType = ConcurrencyUtil.cacheOrGet(myCachedObjectType, resolveScope, cachedObjectType); return cachedObjectType; } } return new PsiClassReferenceType(createReferenceElementByFQClassName(qName, resolveScope), null); }
@Override public PsiClass findClass(@NotNull final String qualifiedName, @NotNull GlobalSearchScope scope) { ProgressIndicatorProvider.checkCanceled(); // We hope this method is being called often enough to cancel daemon processes smoothly Map<String, PsiClass> map = myClassCache.get(scope); if (map == null) { map = ContainerUtil.createConcurrentWeakValueMap(); map = ConcurrencyUtil.cacheOrGet(myClassCache, scope, map); } PsiClass result = map.get(qualifiedName); if (result == null) { result = doFindClass(qualifiedName, scope); if (result != null) { map.put(qualifiedName, result); } } return result; }
@Override public PsiPackage findPackage(@NotNull String qualifiedName) { PsiPackage aPackage = myPackageCache.get(qualifiedName); if (aPackage != null) { return aPackage; } for (PsiElementFinder finder : filteredFinders()) { aPackage = finder.findPackage(qualifiedName); if (aPackage != null) { return ConcurrencyUtil.cacheOrGet(myPackageCache, qualifiedName, aPackage); } } return null; }
@NotNull static HighlightingSession getOrCreateHighlightingSession(@NotNull PsiFile psiFile, @Nullable Editor editor, @NotNull DaemonProgressIndicator progressIndicator, @Nullable EditorColorsScheme editorColorsScheme) { HighlightingSession session = getHighlightingSession(psiFile, progressIndicator); if (session == null) { session = new HighlightingSessionImpl(psiFile, editor, progressIndicator, editorColorsScheme); ConcurrentMap<PsiFile, HighlightingSession> map = progressIndicator.getUserData(HIGHLIGHTING_SESSION); if (map == null) { map = progressIndicator.putUserDataIfAbsent(HIGHLIGHTING_SESSION, ContainerUtil.<PsiFile, HighlightingSession>newConcurrentMap()); } session = ConcurrencyUtil.cacheOrGet(map, psiFile, session); } return session; }
@NotNull public static AttributesFlyweight create(Color foreground, Color background, @JdkConstants.FontStyle int fontType, Color effectColor, EffectType effectType, Color errorStripeColor) { FlyweightKey key = ourKey.get(); if (key == null) { ourKey.set(key = new FlyweightKey()); } key.foreground = foreground; key.background = background; key.fontType = fontType; key.effectColor = effectColor; key.effectType = effectType; key.errorStripeColor = errorStripeColor; AttributesFlyweight flyweight = entries.get(key); if (flyweight != null) { return flyweight; } AttributesFlyweight newValue = new AttributesFlyweight(foreground, background, fontType, effectColor, effectType, errorStripeColor); return ConcurrencyUtil.cacheOrGet(entries, key.clone(), newValue); }
@Override @NotNull @SuppressWarnings({"unchecked"}) public <L> L syncPublisher(@NotNull final Topic<L> topic) { checkNotDisposed(); L publisher = (L)mySyncPublishers.get(topic); if (publisher == null) { final Class<L> listenerClass = topic.getListenerClass(); InvocationHandler handler = new InvocationHandler() { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { sendMessage(new Message(topic, method, args)); return NA; } }; publisher = (L)Proxy.newProxyInstance(listenerClass.getClassLoader(), new Class[]{listenerClass}, handler); publisher = (L)ConcurrencyUtil.cacheOrGet(mySyncPublishers, topic, publisher); } return publisher; }
@Override @NotNull @SuppressWarnings({"unchecked"}) public <L> L asyncPublisher(@NotNull final Topic<L> topic) { checkNotDisposed(); L publisher = (L)myAsyncPublishers.get(topic); if (publisher == null) { final Class<L> listenerClass = topic.getListenerClass(); InvocationHandler handler = new InvocationHandler() { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { postMessage(new Message(topic, method, args)); return NA; } }; publisher = (L)Proxy.newProxyInstance(listenerClass.getClassLoader(), new Class[]{listenerClass}, handler); publisher = (L)ConcurrencyUtil.cacheOrGet(myAsyncPublishers, topic, publisher); } return publisher; }
@Nullable private PsiDirectory findDirectoryImpl(@NotNull VirtualFile vFile) { PsiDirectory psiDir = myVFileToPsiDirMap.get(vFile); if (psiDir != null) return psiDir; if (Registry.is("ide.hide.excluded.files")) { if (myFileIndex.isExcludedFile(vFile)) return null; } else { if (myFileIndex.isUnderIgnored(vFile)) return null; } VirtualFile parent = vFile.getParent(); if (parent != null) { //? findDirectoryImpl(parent);// need to cache parent directory - used for firing events } psiDir = PsiDirectoryFactory.getInstance(myManager.getProject()).createDirectory(vFile); return ConcurrencyUtil.cacheOrGet(myVFileToPsiDirMap, vFile, psiDir); }
@NotNull private InspectionTreeNode getToolParentNode(@NotNull String groupName, HighlightDisplayLevel errorLevel, boolean groupedBySeverity) { if (groupName.isEmpty()) { return getRelativeRootNode(groupedBySeverity, errorLevel); } ConcurrentMap<String, InspectionGroupNode> map = myGroups.get(errorLevel); if (map == null) { map = ConcurrencyUtil.cacheOrGet(myGroups, errorLevel, ContainerUtil.<String, InspectionGroupNode>newConcurrentMap()); } InspectionGroupNode group; if (groupedBySeverity) { group = map.get(groupName); } else { group = null; for (Map<String, InspectionGroupNode> groupMap : myGroups.values()) { if ((group = groupMap.get(groupName)) != null) break; } } if (group == null) { group = ConcurrencyUtil.cacheOrGet(map, groupName, new InspectionGroupNode(groupName)); addChildNodeInEDT(getRelativeRootNode(groupedBySeverity, errorLevel), group); } return group; }
@NotNull private InspectionTreeNode getRelativeRootNode(boolean isGroupedBySeverity, HighlightDisplayLevel level) { if (isGroupedBySeverity) { InspectionSeverityGroupNode severityGroupNode = mySeverityGroupNodes.get(level); if (severityGroupNode == null) { InspectionSeverityGroupNode newNode = new InspectionSeverityGroupNode(myProject, level); severityGroupNode = ConcurrencyUtil.cacheOrGet(mySeverityGroupNodes, level, newNode); if (severityGroupNode == newNode) { InspectionTreeNode root = myTree.getRoot(); addChildNodeInEDT(root, severityGroupNode); } } return severityGroupNode; } return myTree.getRoot(); }
public ApplicationLevelNumberConnectionsGuardImpl() { myDelay = DELAY; mySet = new HashSet<CachingSvnRepositoryPool>(); myService = Executors.newSingleThreadScheduledExecutor(ConcurrencyUtil.newNamedThreadFactory("SVN connection")); myLock = new Object(); myDisposed = false; myRecheck = new Runnable() { @Override public void run() { HashSet<CachingSvnRepositoryPool> pools = new HashSet<CachingSvnRepositoryPool>(); synchronized (myLock) { pools.addAll(mySet); } for (CachingSvnRepositoryPool pool : pools) { pool.check(); } } }; myCurrentlyActiveConnections = 0; myCurrentlyOpenedConnections = 0; }
@Nullable public <T extends GroovyPsiElement> PsiType getType(@NotNull T element, @NotNull Function<T, PsiType> calculator) { PsiType type = myCalculatedTypes.get(element); if (type == null) { RecursionGuard.StackStamp stamp = ourGuard.markStack(); type = calculator.fun(element); if (type == null) { type = UNKNOWN_TYPE; } if (stamp.mayCacheNow()) { type = ConcurrencyUtil.cacheOrGet(myCalculatedTypes, element, type); } else { final PsiType alreadyInferred = myCalculatedTypes.get(element); if (alreadyInferred != null) { type = alreadyInferred; } } } if (!type.isValid()) { error(element, type); } return UNKNOWN_TYPE == type ? null : type; }
@NotNull private XDebugProcessStarter createDebugProcessStarter(@NotNull final TheRXProcessHandler processHandler, @NotNull final ExecutionConsole executionConsole, @NotNull final TheRDebugger debugger, @NotNull final TheROutputReceiver outputReceiver, @NotNull final TheRResolvingSession resolvingSession) { return new XDebugProcessStarter() { @NotNull @Override public XDebugProcess start(@NotNull final XDebugSession session) throws ExecutionException { return new TheRDebugProcess( session, processHandler, executionConsole, debugger, outputReceiver, resolvingSession, ConcurrencyUtil.newSingleThreadExecutor(EXECUTOR_NAME) ); } }; }
@Override public PsiPackage findPackage(@NotNull String qualifiedName) { SoftReference<ConcurrentMap<String, PsiPackage>> ref = myPackageCache; ConcurrentMap<String, PsiPackage> cache = ref == null ? null : ref.get(); if (cache == null) { myPackageCache = new SoftReference<ConcurrentMap<String, PsiPackage>>(cache = new ConcurrentHashMap<String, PsiPackage>()); } PsiPackage aPackage = cache.get(qualifiedName); if (aPackage != null) { return aPackage; } for (PsiElementFinder finder : filteredFinders()) { aPackage = finder.findPackage(qualifiedName); if (aPackage != null) { return ConcurrencyUtil.cacheOrGet(cache, qualifiedName, aPackage); } } return null; }
@NotNull public static AttributesFlyweight create(Color foreground, Color background, @JdkConstants.FontStyle int fontType, Color effectColor, EffectType effectType, Color errorStripeColor) { FlyweightKey key = ourKey.get(); if (key == null) { ourKey.set(key = new FlyweightKey()); } key.foreground = foreground; key.background = background; key.fontType = fontType; key.effectColor = effectColor; key.effectType = effectType; key.errorStripeColor = errorStripeColor; AttributesFlyweight flyweight = entries.get(key); if (flyweight != null) { return flyweight; } return ConcurrencyUtil.cacheOrGet(entries, key.clone(), new AttributesFlyweight(foreground, background, fontType, effectColor, effectType, errorStripeColor)); }
@Override protected PsiFile getPsiInner(@NotNull final Language target) { PsiFile file = myRoots.get(target); if (file == null) { if (isPhysical()) { VirtualFile virtualFile = getVirtualFile(); if (isIgnored()) return null; VirtualFile parent = virtualFile.getParent(); if (parent != null) { getManager().findDirectory(parent); } } file = createFile(target); if (file == null) return null; if (myOriginal != null) { final PsiFile originalFile = myOriginal.getPsi(target); if (originalFile != null) { ((PsiFileImpl)file).setOriginalFile(originalFile); } } file = ConcurrencyUtil.cacheOrGet(myRoots, target, file); } return file; }
@Nullable public <T extends GroovyPsiElement> PsiType getType(@NotNull T element, @NotNull Function<T, PsiType> calculator) { PsiType type = myCalculatedTypes.get(element); if (type == null) { RecursionGuard.StackStamp stamp = ourGuard.markStack(); type = calculator.fun(element); if (type == null) { type = UNKNOWN_TYPE; } if (stamp.mayCacheNow()) { type = ConcurrencyUtil.cacheOrGet(myCalculatedTypes, element, type); } else { final PsiType alreadyInferred = myCalculatedTypes.get(element); if (alreadyInferred != null) { type = alreadyInferred; } } } if (!type.isValid()) { LOG.error("Type is invalid: " + type + "; element: " + element + " of class " + element.getClass()); } return UNKNOWN_TYPE == type ? null : type; }
@Nonnull public static AttributesFlyweight create(Color foreground, Color background, @JdkConstants.FontStyle int fontType, Color effectColor, EffectType effectType, Color errorStripeColor) { FlyweightKey key = ourKey.get(); if (key == null) { ourKey.set(key = new FlyweightKey()); } key.foreground = foreground; key.background = background; key.fontType = fontType; key.effectColor = effectColor; key.effectType = effectType; key.errorStripeColor = errorStripeColor; AttributesFlyweight flyweight = entries.get(key); if (flyweight != null) { return flyweight; } AttributesFlyweight newValue = new AttributesFlyweight(foreground, background, fontType, effectColor, effectType, errorStripeColor); return ConcurrencyUtil.cacheOrGet(entries, key.clone(), newValue); }
@Override @Nonnull @SuppressWarnings("unchecked") public <L> L syncPublisher(@Nonnull final Topic<L> topic) { checkNotDisposed(); L publisher = (L)mySyncPublishers.get(topic); if (publisher == null) { final Class<L> listenerClass = topic.getListenerClass(); InvocationHandler handler = new InvocationHandler() { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { sendMessage(new Message(topic, method, args)); return NA; } }; publisher = (L)Proxy.newProxyInstance(listenerClass.getClassLoader(), new Class[]{listenerClass}, handler); publisher = (L)ConcurrencyUtil.cacheOrGet(mySyncPublishers, topic, publisher); } return publisher; }
@Override @Nonnull @SuppressWarnings("unchecked") public <L> L asyncPublisher(@Nonnull final Topic<L> topic) { checkNotDisposed(); L publisher = (L)myAsyncPublishers.get(topic); if (publisher == null) { final Class<L> listenerClass = topic.getListenerClass(); InvocationHandler handler = new InvocationHandler() { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { postMessage(new Message(topic, method, args)); return NA; } }; publisher = (L)Proxy.newProxyInstance(listenerClass.getClassLoader(), new Class[]{listenerClass}, handler); publisher = (L)ConcurrencyUtil.cacheOrGet(myAsyncPublishers, topic, publisher); } return publisher; }
private void registerNamedReferenceProvider(@Nonnull String[] names, final PsiNamePatternCondition<?> nameCondition, @Nonnull Class scopeClass, final boolean caseSensitive, @Nonnull PsiReferenceProvider provider, final double priority, @Nonnull ElementPattern pattern) { NamedObjectProviderBinding<PsiReferenceProvider> providerBinding = myNamedBindingsMap.get(scopeClass); if (providerBinding == null) { providerBinding = ConcurrencyUtil.cacheOrGet(myNamedBindingsMap, scopeClass, new NamedObjectProviderBinding<PsiReferenceProvider>() { @Override protected String getName(final PsiElement position) { return nameCondition.getPropertyValue(position); } }); } providerBinding.registerProvider(names, pattern, caseSensitive, provider, priority); }
public void registerProvider(@NonNls @Nonnull String[] names, @Nonnull ElementPattern filter, boolean caseSensitive, @Nonnull Provider provider, final double priority) { final ConcurrentMap<String, List<ProviderInfo<Provider, ElementPattern>>> map = caseSensitive ? myNamesToProvidersMap : myNamesToProvidersMapInsensitive; for (final String attributeName : names) { List<ProviderInfo<Provider, ElementPattern>> psiReferenceProviders = map.get(attributeName); if (psiReferenceProviders == null) { String key = caseSensitive ? attributeName : attributeName.toLowerCase(); psiReferenceProviders = ConcurrencyUtil.cacheOrGet(map, key, ContainerUtil.<ProviderInfo<Provider,ElementPattern>>createLockFreeCopyOnWriteList()); } psiReferenceProviders.add(new ProviderInfo<Provider,ElementPattern>(provider, filter, priority)); } }
private Object cache(@NotNull PsiElement element, @Nullable Object value) { value = ConcurrencyUtil.cacheOrGet(map(), element, value == null ? NO_VALUE : value); if (value == NO_VALUE) { value = null; } return value; }
@Override public RefModule getRefModule(Module module) { if (module == null) { return null; } RefModule refModule = myModules.get(module); if (refModule == null) { refModule = ConcurrencyUtil.cacheOrGet(myModules, module, new RefModuleImpl(module, this)); } return refModule; }
/** * @see #findSingle(Object) */ @NotNull public List<T> forKey(@NotNull KeyT key) { final String stringKey = keyToString(key); boolean rebuild = myPoint == null && Extensions.getRootArea().hasExtensionPoint(myEpName); List<T> cached = rebuild ? null : myCache.get(stringKey); if (cached != null) return cached; cached = buildExtensions(stringKey, key); cached = ConcurrencyUtil.cacheOrGet(myCache, stringKey, cached); return cached; }
protected Language(@Nullable Language baseLanguage, @NotNull @NonNls final String ID, @NotNull @NonNls final String... mimeTypes) { myBaseLanguage = baseLanguage; myID = ID; myMimeTypes = mimeTypes; Class<? extends Language> langClass = getClass(); Language prev = ourRegisteredLanguages.put(langClass, this); if (prev != null) { LOG.error("Language of '" + langClass + "' is already registered: " + prev); return; } prev = ourRegisteredIDs.put(ID, this); if (prev != null) { LOG.error("Language with ID '" + ID + "' is already registered: " + prev.getClass()); } for (String mimeType : mimeTypes) { if (StringUtil.isEmpty(mimeType)) { continue; } List<Language> languagesByMimeType = ourRegisteredMimeTypes.get(mimeType); if (languagesByMimeType == null) { languagesByMimeType = ConcurrencyUtil.cacheOrGet(ourRegisteredMimeTypes, mimeType, ContainerUtil.<Language>createConcurrentList()); } languagesByMimeType.add(this); } if (baseLanguage != null) { baseLanguage.myDialects.add(this); } }
@NotNull private GlobalSearchScope getScopeForLibraryUsedIn(@NotNull Module[] modulesLibraryIsUsedIn) { GlobalSearchScope scope = myLibraryScopes.get(modulesLibraryIsUsedIn); if (scope != null) { return scope; } GlobalSearchScope newScope = modulesLibraryIsUsedIn.length == 0 ? myLibrariesOnlyScope : new LibraryRuntimeClasspathScope(myProject, modulesLibraryIsUsedIn); return ConcurrencyUtil.cacheOrGet(myLibraryScopes, modulesLibraryIsUsedIn, newScope); }
static void registerDisposable(@NotNull Disposable parentDisposable, @NotNull VirtualFilePointerImpl pointer) { DelegatingDisposable result = ourInstances.get(parentDisposable); if (result == null) { DelegatingDisposable newDisposable = new DelegatingDisposable(parentDisposable); result = ConcurrencyUtil.cacheOrGet(ourInstances, parentDisposable, newDisposable); if (result == newDisposable) { Disposer.register(parentDisposable, result); } } synchronized (result) { result.myCounts.put(pointer, result.myCounts.get(pointer) + 1); } }
@Nullable public static Icon findIcon(URL url, boolean useCache) { if (url == null) { return null; } CachedImageIcon icon = ourIconsCache.get(url); if (icon == null) { icon = new CachedImageIcon(url); if (useCache) { icon = ConcurrencyUtil.cacheOrGet(ourIconsCache, url, icon); } } return icon; }
void notifyOnSubscription(final MessageBusConnectionImpl connection, final Topic topic) { checkNotDisposed(); List<MessageBusConnectionImpl> topicSubscribers = mySubscribers.get(topic); if (topicSubscribers == null) { topicSubscribers = ContainerUtil.createLockFreeCopyOnWriteList(); topicSubscribers = ConcurrencyUtil.cacheOrGet(mySubscribers, topic, topicSubscribers); } topicSubscribers.add(connection); getRootBus().clearSubscriberCache(); }
private void appendResult(@NotNull PsiFile file, @NotNull InspectionResult result) { List<InspectionResult> resultList = this.result.get(file); if (resultList == null) { resultList = ConcurrencyUtil.cacheOrGet(this.result, file, new ArrayList<InspectionResult>()); } synchronized (resultList) { resultList.add(result); } }
private SemCacheChunk getOrCreateChunk(final PsiElement element) { SemCacheChunk chunk = obtainChunk(element); if (chunk == null) { chunk = ConcurrencyUtil.cacheOrGet(myCache, element, new SemCacheChunk()); } return chunk; }
@Override public void setUp() throws Exception { super.setUp(); // This should happen on some other thread - it will become the AWT event queue thread. Future<IdeaTestApplication> application = Executors.newSingleThreadExecutor(ConcurrencyUtil.newNamedThreadFactory("async validator test")). submit(new Callable<IdeaTestApplication>() { @Override public IdeaTestApplication call() throws Exception { return IdeaTestApplication.getInstance(); } }); application.get(100, TimeUnit.SECONDS); // Wait for the application instantiation }
@Override protected void callRunnable(Runnable runnable) { myFuture = Executors.newSingleThreadExecutor(ConcurrencyUtil.newNamedThreadFactory("CVS request")).submit(runnable); final long tOut = (myTimeout < 20000) ? 20000 : myTimeout; while (true) { mySemaphore.waitFor(tOut); if (myFuture.isDone() || myFuture.isCancelled()) break; if (! commandStopper.isAlive()) break; commandStopper.resetAlive(); } }
public boolean isCompileStatic(@NotNull PsiMember member) { Boolean aBoolean = myCompileStatic.get(member); if (aBoolean == null) { aBoolean = ConcurrencyUtil.cacheOrGet(myCompileStatic, member, isCompileStaticInner(member)); } return aBoolean; }
public TerminalSessionEditor(Project project, @NotNull TerminalSessionVirtualFileImpl terminalFile) { myProject = project; myFile = terminalFile; final TabbedSettingsProvider settings = myFile.getSettingsProvider(); myFile.getTerminal().setNextProvider(new TerminalActionProviderBase() { @Override public List<TerminalAction> getActions() { return Lists.newArrayList( new TerminalAction("Close Session", settings.getCloseSessionKeyStrokes(), new Predicate<KeyEvent>() { @Override public boolean apply(KeyEvent input) { handleCloseSession(); return true; } }).withMnemonicKey(KeyEvent.VK_S) ); } }); myWaitFor = new TtyConnectorWaitFor(myFile.getTerminal().getTtyConnector(), Executors.newSingleThreadExecutor( ConcurrencyUtil.newNamedThreadFactory("Terminal session"))); myWaitFor .setTerminationCallback(new Predicate<Integer>() { @Override public boolean apply(Integer integer) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { FileEditorManagerEx.getInstanceEx(myProject).closeFile(myFile); } }); return true; } }); }
@Override protected RunContentDescriptor doExecute(@NotNull final RunProfileState state, @NotNull final ExecutionEnvironment environment) throws ExecutionException { FileDocumentManager.getInstance().saveAllDocuments(); final Project project = environment.getProject(); return new TheRRunProcess( project, environment, getExecutionResult(state, environment), ConcurrencyUtil.newSingleThreadExecutor(EXECUTOR_NAME) ).getRunContentDescriptor(); }