Java 类com.intellij.util.containers.ConcurrentHashSet 实例源码

项目:tools-idea    文件:MockComponentManager.java   
public MockComponentManager(@Nullable PicoContainer parent, @NotNull Disposable parentDisposable) {
  myPicoContainer = new IdeaPicoContainer(parent) {
    private Set<Object> myDisposableComponents = new ConcurrentHashSet<Object>();

    @Override
    @Nullable
    public Object getComponentInstance(final Object componentKey) {
      final Object o = super.getComponentInstance(componentKey);
      if (o instanceof Disposable && o != MockComponentManager.this) {
        if (myDisposableComponents.add(o))
          Disposer.register(MockComponentManager.this, (Disposable)o);
      }
      return o;
    }
  };
  myPicoContainer.registerComponentInstance(this);
  Disposer.register(parentDisposable, this);
}
项目:tools-idea    文件:SliceLeafAnalyzer.java   
public static Map<SliceNode, Collection<PsiElement>> createMap() {
  return new FactoryMap<SliceNode, Collection<PsiElement>>() {
    @Override
    protected Map<SliceNode, Collection<PsiElement>> createMap() {
      return new ConcurrentHashMap<SliceNode, Collection<PsiElement>>(ContainerUtil.<SliceNode>identityStrategy());
    }

    @Override
    protected Collection<PsiElement> create(SliceNode key) {
      return new ConcurrentHashSet<PsiElement>(SliceLeafAnalyzer.LEAF_ELEMENT_EQUALITY);
    }
  };
}
项目:tools-idea    文件:ExternalSystemProgressNotificationManagerImpl.java   
@Override
public boolean addNotificationListener(@NotNull ExternalSystemTaskId taskId, @NotNull ExternalSystemTaskNotificationListener listener) {
  Set<ExternalSystemTaskId> ids = null;
  while (ids == null) {
    if (myListeners.containsKey(listener)) {
      ids = myListeners.get(listener);
    }
    else {
      ids = myListeners.putIfAbsent(listener, new ConcurrentHashSet<ExternalSystemTaskId>());
    }
  }
  return ids.add(taskId);
}
项目:tools-idea    文件:VirtualFileTrackerImpl.java   
private static Set<VirtualFileListener> getSet(final String fileUrl, final Map<String, Set<VirtualFileListener>> map) {
  Set<VirtualFileListener> listeners = map.get(fileUrl);

  if (listeners == null) {
    listeners = new ConcurrentHashSet<VirtualFileListener>();
    map.put(fileUrl, listeners);
  }
  return listeners;
}
项目:tools-idea    文件:FormattingProgressTask.java   
private Collection<Runnable> getCallbacks(@NotNull EventType eventType) {
  Collection<Runnable> result = myCallbacks.get(eventType);
  if (result == null) {
    Collection<Runnable> candidate = myCallbacks.putIfAbsent(eventType, result = new ConcurrentHashSet<Runnable>());
    if (candidate != null) {
      result = candidate;
    }
  }
  return result;
}
项目:consulo    文件:ExternalSystemProgressNotificationManagerImpl.java   
@Override
public boolean addNotificationListener(@Nonnull ExternalSystemTaskId taskId, @Nonnull ExternalSystemTaskNotificationListener listener) {
  Set<ExternalSystemTaskId> ids = null;
  while (ids == null) {
    if (myListeners.containsKey(listener)) {
      ids = myListeners.get(listener);
    }
    else {
      ids = myListeners.putIfAbsent(listener, new ConcurrentHashSet<ExternalSystemTaskId>());
    }
  }
  return ids.add(taskId);
}
项目:consulo    文件:VirtualFileTrackerImpl.java   
private static Set<VirtualFileListener> getSet(final String fileUrl, final Map<String, Set<VirtualFileListener>> map) {
  Set<VirtualFileListener> listeners = map.get(fileUrl);

  if (listeners == null) {
    listeners = new ConcurrentHashSet<VirtualFileListener>();
    map.put(fileUrl, listeners);
  }
  return listeners;
}
项目:consulo    文件:FormattingProgressTask.java   
private Collection<Runnable> getCallbacks(@Nonnull EventType eventType) {
  Collection<Runnable> result = myCallbacks.get(eventType);
  if (result == null) {
    Collection<Runnable> candidate = myCallbacks.putIfAbsent(eventType, result = new ConcurrentHashSet<Runnable>());
    if (candidate != null) {
      result = candidate;
    }
  }
  return result;
}
项目:consulo-java    文件:SliceLeafAnalyzer.java   
public static Map<SliceNode, Collection<PsiElement>> createMap() {
  return new FactoryMap<SliceNode, Collection<PsiElement>>() {
    @Override
    protected Map<SliceNode, Collection<PsiElement>> createMap() {
      return new ConcurrentHashMap<SliceNode, Collection<PsiElement>>(ContainerUtil.<SliceNode>identityStrategy());
    }

    @Override
    protected Collection<PsiElement> create(SliceNode key) {
      return new ConcurrentHashSet<PsiElement>(SliceLeafAnalyzer.LEAF_ELEMENT_EQUALITY);
    }
  };
}
项目:tools-idea    文件:IncProjectBuilder.java   
private static CompileContext createContextWrapper(final CompileContext delegate) {
  final ClassLoader loader = delegate.getClass().getClassLoader();
  final UserDataHolderBase localDataHolder = new UserDataHolderBase();
  final Set<Object> deletedKeysSet = new ConcurrentHashSet<Object>();
  final Class<UserDataHolder> dataHolderInterface = UserDataHolder.class;
  final Class<MessageHandler> messageHandlerInterface = MessageHandler.class;
  return (CompileContext)Proxy.newProxyInstance(loader, new Class[]{CompileContext.class}, new InvocationHandler() {
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
      final Class<?> declaringClass = method.getDeclaringClass();
      if (dataHolderInterface.equals(declaringClass)) {
        final Object firstArgument = args[0];
        if (!(firstArgument instanceof GlobalContextKey)) {
          final boolean isWriteOperation = args.length == 2 /*&& void.class.equals(method.getReturnType())*/;
          if (isWriteOperation) {
            if (args[1] == null) {
              deletedKeysSet.add(firstArgument);
            }
            else {
              deletedKeysSet.remove(firstArgument);
            }
          }
          else {
            if (deletedKeysSet.contains(firstArgument)) {
              return null;
            }
          }
          final Object result = method.invoke(localDataHolder, args);
          if (isWriteOperation || result != null) {
            return result;
          }
        }
      }
      else if (messageHandlerInterface.equals(declaringClass)) {
        final BuildMessage msg = (BuildMessage)args[0];
        if (msg.getKind() == BuildMessage.Kind.ERROR) {
          Utils.ERRORS_DETECTED_KEY.set(localDataHolder, Boolean.TRUE);
        }
      }
      try {
        return method.invoke(delegate, args);
      }
      catch (InvocationTargetException e) {
        final Throwable targetEx = e.getTargetException();
        if (targetEx instanceof ProjectBuildException) {
          throw targetEx;
        }
        throw e;
      }
    }
  });
}
项目:tools-idea    文件:JarFileSystemImpl.java   
public JarFileSystemImpl(MessageBus bus) {
  boolean noCopy = SystemProperties.getBooleanProperty("idea.jars.nocopy", !SystemInfo.isWindows);
  myNoCopyJarPaths = noCopy ? null : new ConcurrentHashSet<String>(FileUtil.PATH_HASHING_STRATEGY);

  bus.connect().subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener.Adapter() {
    @Override
    public void after(@NotNull final List<? extends VFileEvent> events) {
      final List<VirtualFile> rootsToRefresh = new ArrayList<VirtualFile>();

      for (VFileEvent event : events) {
        if (event.getFileSystem() instanceof LocalFileSystem) {
          String path = event.getPath();

          String[] jarPaths;
          synchronized (LOCK) {
            jarPaths = jarPathsCache;
            if (jarPaths == null) {
              jarPathsCache = jarPaths = ArrayUtil.toStringArray(myHandlers.keySet());
            }
          }

          for (String jarPath : jarPaths) {
            final String jarFile = jarPath.substring(0, jarPath.length() - JAR_SEPARATOR.length());
            if (FileUtil.startsWith(jarFile, path)) {
              VirtualFile jarRootToRefresh = markDirty(jarPath);
              if (jarRootToRefresh != null) {
                rootsToRefresh.add(jarRootToRefresh);
              }
            }
          }
        }
      }

      if (!rootsToRefresh.isEmpty()) {
        final Application app = ApplicationManager.getApplication();
        Runnable runnable = new Runnable() {
          @Override
          public void run() {
            if (app.isDisposed()) return;
            for (VirtualFile root : rootsToRefresh) {
              if (root.isValid()) {
                ((NewVirtualFile)root).markDirtyRecursively();
              }
            }
            RefreshQueue.getInstance().refresh(false, true, null, rootsToRefresh);
          }
        };
        if (app.isUnitTestMode()) {
          runnable.run();
        }
        else {
          app.invokeLater(runnable, ModalityState.NON_MODAL);
        }
      }
    }
  });
}
项目:tools-idea    文件:GroovyConstructorUsagesSearcher.java   
static void processConstructorUsages(final PsiMethod constructor, final SearchScope searchScope, final Processor<PsiReference> consumer, final SearchRequestCollector collector, final boolean searchGppCalls, final boolean includeOverloads) {
  if (!constructor.isConstructor()) return;

  final PsiClass clazz = constructor.getContainingClass();
  if (clazz == null) return;

  SearchScope onlyGroovy = GroovyScopeUtil.restrictScopeToGroovyFiles(searchScope, GroovyScopeUtil.getEffectiveScope(constructor));
  Set<PsiClass> processed = collector.getSearchSession().getUserData(LITERALLY_CONSTRUCTED_CLASSES);
  if (processed == null) {
    collector.getSearchSession().putUserData(LITERALLY_CONSTRUCTED_CLASSES, processed = new ConcurrentHashSet<PsiClass>());
  }
  if (!processed.add(clazz)) return;

  if (clazz.isEnum() && clazz instanceof GroovyPsiElement) {
    for (PsiField field : clazz.getFields()) {
      if (field instanceof GrEnumConstant) {
        final PsiReference ref = field.getReference();
        if (ref != null && ref.isReferenceTo(constructor)) {
          if (!consumer.process(ref)) return;
        }
      }
    }
  }

  final LiteralConstructorSearcher literalProcessor = new LiteralConstructorSearcher(constructor, consumer, includeOverloads);

  final Processor<GrNewExpression> newExpressionProcessor = new Processor<GrNewExpression>() {
    @Override
    public boolean process(GrNewExpression grNewExpression) {
      final PsiMethod resolvedConstructor = grNewExpression.resolveMethod();
      if (includeOverloads || constructor.getManager().areElementsEquivalent(resolvedConstructor, constructor)) {
        return consumer.process(grNewExpression.getReferenceElement());
      }
      return true;
    }
  };

  processGroovyClassUsages(clazz, searchScope, collector, searchGppCalls, newExpressionProcessor, literalProcessor);

  //this()
  if (clazz instanceof GrTypeDefinition) {
    if (!processConstructors(constructor, consumer, clazz, true)) {
      return;
    }
  }
  //super()
  DirectClassInheritorsSearch.search(clazz, onlyGroovy).forEach(new ReadActionProcessor<PsiClass>() {
    @Override
    public boolean processInReadAction(PsiClass inheritor) {
      if (inheritor instanceof GrTypeDefinition) {
        if (!processConstructors(constructor, consumer, inheritor, false)) return false;
      }
      return true;
    }
  });
}