Java 类com.intellij.util.ConcurrencyUtil 实例源码

项目:intellij-ce-playground    文件:PsiElementFactoryImpl.java   
@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);
}
项目:intellij-ce-playground    文件:JavaPsiFacadeImpl.java   
@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;
}
项目:intellij-ce-playground    文件:JavaPsiFacadeImpl.java   
@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;
}
项目:intellij-ce-playground    文件:HighlightingSessionImpl.java   
@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;
}
项目:intellij-ce-playground    文件:AttributesFlyweight.java   
@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);
}
项目:intellij-ce-playground    文件:MessageBusImpl.java   
@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;
}
项目:intellij-ce-playground    文件:MessageBusImpl.java   
@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;
}
项目:intellij-ce-playground    文件:FileManagerImpl.java   
@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);
}
项目:intellij-ce-playground    文件:InspectionResultsView.java   
@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;
}
项目:intellij-ce-playground    文件:InspectionResultsView.java   
@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();
}
项目:intellij-ce-playground    文件:ApplicationLevelNumberConnectionsGuardImpl.java   
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;
}
项目:intellij-ce-playground    文件:GroovyPsiManager.java   
@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;
}
项目:TheRPlugin    文件:TheRDebugRunner.java   
@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)
      );
    }
  };
}
项目:tools-idea    文件:JavaPsiFacadeImpl.java   
@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;
}
项目:tools-idea    文件:AttributesFlyweight.java   
@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));
}
项目:tools-idea    文件:MessageBusImpl.java   
@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;
}
项目:tools-idea    文件:MessageBusImpl.java   
@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;
}
项目:tools-idea    文件:MultiplePsiFilesPerDocumentFileViewProvider.java   
@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;
}
项目:tools-idea    文件:GroovyPsiManager.java   
@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;
}
项目:consulo    文件:AttributesFlyweight.java   
@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);
}
项目:consulo    文件:MessageBusImpl.java   
@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;
}
项目:consulo    文件:MessageBusImpl.java   
@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;
}
项目:consulo    文件:PsiReferenceRegistrarImpl.java   
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);
}
项目:consulo    文件:NamedObjectProviderBinding.java   
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));
  }
}
项目:intellij-ce-playground    文件:JavaConstantExpressionEvaluator.java   
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;
}
项目:intellij-ce-playground    文件:RefManagerImpl.java   
@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;
}
项目:intellij-ce-playground    文件:KeyedExtensionCollector.java   
/**
 * @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;
}
项目:intellij-ce-playground    文件:Language.java   
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);
  }
}
项目:intellij-ce-playground    文件:LibraryScopeCache.java   
@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);
}
项目:intellij-ce-playground    文件:VirtualFilePointerManagerImpl.java   
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);
  }
}
项目:intellij-ce-playground    文件:IconLoader.java   
@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;
}
项目:intellij-ce-playground    文件:MessageBusImpl.java   
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();
}
项目:intellij-ce-playground    文件:LocalInspectionsPass.java   
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);
  }
}
项目:intellij-ce-playground    文件:SemServiceImpl.java   
private SemCacheChunk getOrCreateChunk(final PsiElement element) {
  SemCacheChunk chunk = obtainChunk(element);
  if (chunk == null) {
    chunk = ConcurrencyUtil.cacheOrGet(myCache, element, new SemCacheChunk());
  }
  return chunk;
}
项目:intellij-ce-playground    文件:AsyncValidatorTest.java   
@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
}
项目:intellij-ce-playground    文件:RequestProcessor.java   
@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();
  }
}
项目:intellij-ce-playground    文件:GroovyPsiManager.java   
public boolean isCompileStatic(@NotNull PsiMember member) {
  Boolean aBoolean = myCompileStatic.get(member);
  if (aBoolean == null) {
    aBoolean = ConcurrencyUtil.cacheOrGet(myCompileStatic, member, isCompileStaticInner(member));
  }
  return aBoolean;
}
项目:intellij-ce-playground    文件:TerminalSessionEditor.java   
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;
      }
    });
}
项目:TheRPlugin    文件:TheRRunRunner.java   
@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();
}
项目:tools-idea    文件:JavaConstantExpressionEvaluator.java   
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;
}