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

项目:intellij-ce-playground    文件:JpsModuleTest.java   
public void testAddSourceRoot() {
  final JpsModule module = myProject.addModule("m", JpsJavaModuleType.INSTANCE);
  JavaSourceRootProperties properties = JpsJavaExtensionService.getInstance().createSourceRootProperties("com.xxx");
  final JpsModuleSourceRoot sourceRoot = module.addSourceRoot("file://url", JavaSourceRootType.SOURCE, properties);

  assertSameElements(myDispatcher.retrieveAdded(JpsModule.class), module);
  assertSameElements(myDispatcher.retrieveAdded(JpsModuleSourceRoot.class), sourceRoot);

  final JpsModuleSourceRoot root = assertOneElement(module.getSourceRoots());
  assertEquals("file://url", root.getUrl());
  assertSameElements(ContainerUtilRt.newArrayList(module.getSourceRoots(JavaSourceRootType.SOURCE)), root);
  assertEmpty(ContainerUtil.newArrayList(module.getSourceRoots(JavaSourceRootType.TEST_SOURCE)));
  JpsTypedModuleSourceRoot<JavaSourceRootProperties> typedRoot = root.asTyped(JavaSourceRootType.SOURCE);
  assertNotNull(typedRoot);
  assertEquals("com.xxx", typedRoot.getProperties().getPackagePrefix());
}
项目:intellij-ce-playground    文件:JavaInheritanceWeigher.java   
@NotNull
@Override
public Set<String> fun(ProximityLocation location) {
  final HashSet<String> result = new HashSet<String>();
  PsiClass contextClass = PsiTreeUtil.getContextOfType(location.getPosition(), PsiClass.class, false);
  Processor<PsiClass> processor = new Processor<PsiClass>() {
    @Override
    public boolean process(PsiClass psiClass) {
      ContainerUtilRt.addIfNotNull(result, psiClass.getQualifiedName());
      return true;
    }
  };
  while (contextClass != null) {
    InheritanceUtil.processSupers(contextClass, true, processor);
    contextClass = contextClass.getContainingClass();
  }
  return result;
}
项目:intellij-ce-playground    文件:ConfigurationsTest.java   
public void testModulesSelector() throws ConfigurationException {
  if (PlatformTestUtil.COVERAGE_ENABLED_BUILD) return;

  Module module1 = getModule1();
  Module module2 = getModule2();
  JUnitConfigurable editor = new JUnitConfigurable(myProject);
  try {
    JUnitConfiguration configuration = createConfiguration(findTestA(module2));
    editor.getComponent(); // To get all the watchers installed.
    Configurable configurable = new RunConfigurationConfigurableAdapter(editor, configuration);
    JComboBox comboBox = editor.getModulesComponent();
    configurable.reset();
    assertFalse(configurable.isModified());
    assertEquals(module2.getName(), ((Module)comboBox.getSelectedItem()).getName());
    assertEquals(ModuleManager.getInstance(myProject).getModules().length + 1, comboBox.getModel().getSize()); //no module
    comboBox.setSelectedItem(module1);
    assertTrue(configurable.isModified());
    configurable.apply();
    assertFalse(configurable.isModified());
    assertEquals(Collections.singleton(module1), ContainerUtilRt.newHashSet(configuration.getModules()));
  }
  finally {
    Disposer.dispose(editor);
  }
}
项目:intellij-ce-playground    文件:ProjectDataManager.java   
public ProjectDataManager() {
  myServices = new NotNullLazyValue<Map<Key<?>, List<ProjectDataService<?, ?>>>>() {
    @NotNull
    @Override
    protected Map<Key<?>, List<ProjectDataService<?, ?>>> compute() {
      Map<Key<?>, List<ProjectDataService<?, ?>>> result = ContainerUtilRt.newHashMap();
      for (ProjectDataService<?, ?> service : ProjectDataService.EP_NAME.getExtensions()) {
        List<ProjectDataService<?, ?>> services = result.get(service.getTargetDataKey());
        if (services == null) {
          result.put(service.getTargetDataKey(), services = ContainerUtilRt.newArrayList());
        }
        services.add(service);
      }

      for (List<ProjectDataService<?, ?>> services : result.values()) {
        ExternalSystemApiUtil.orderAwareSort(services);
      }
      return result;
    }
  };
}
项目:intellij-ce-playground    文件:ModuleDataService.java   
@NotNull
private static Collection<DataNode<ModuleData>> filterExistingModules(@NotNull Collection<DataNode<ModuleData>> modules,
                                                                      @NotNull IdeModifiableModelsProvider modelsProvider)
{
  Collection<DataNode<ModuleData>> result = ContainerUtilRt.newArrayList();
  for (DataNode<ModuleData> node : modules) {
    ModuleData moduleData = node.getData();
    Module module = modelsProvider.findIdeModule(moduleData);
    if (module == null) {
      result.add(node);
    }
    else {
      setModuleOptions(module, node);
    }
  }
  return result;
}
项目:intellij-ce-playground    文件:ExternalSystemBeforeRunTaskProvider.java   
@Override
public boolean canExecuteTask(RunConfiguration configuration, ExternalSystemBeforeRunTask beforeRunTask) {
  final ExternalSystemTaskExecutionSettings executionSettings = beforeRunTask.getTaskExecutionSettings();

  final List<ExternalTaskPojo> tasks = ContainerUtilRt.newArrayList();
  for (String taskName : executionSettings.getTaskNames()) {
    tasks.add(new ExternalTaskPojo(taskName, executionSettings.getExternalProjectPath(), null));
  }
  if (tasks.isEmpty()) return true;

  final Pair<ProgramRunner, ExecutionEnvironment> pair =
    ExternalSystemUtil.createRunner(executionSettings, DefaultRunExecutor.EXECUTOR_ID, myProject, mySystemId);

  if (pair == null) return false;

  final ProgramRunner runner = pair.first;
  final ExecutionEnvironment environment = pair.second;

  return runner.canRun(DefaultRunExecutor.EXECUTOR_ID, environment.getRunProfile());
}
项目:intellij-ce-playground    文件:ExternalSystemFacadeManager.java   
private static <V> void onProjectRename(@NotNull Map<IntegrationKey, V> data,
                                        @NotNull String oldName,
                                        @NotNull String newName)
{
  Set<IntegrationKey> keys = ContainerUtilRt.newHashSet(data.keySet());
  for (IntegrationKey key : keys) {
    if (!key.getIdeProjectName().equals(oldName)) {
      continue;
    }
    IntegrationKey newKey = new IntegrationKey(newName,
                                               key.getIdeProjectLocationHash(),
                                               key.getExternalSystemId(),
                                               key.getExternalProjectConfigPath());
    V value = data.get(key);
    data.put(newKey, value);
    data.remove(key);
    if (value instanceof Consumer) {
      //noinspection unchecked
      ((Consumer)value).consume(newKey);
    }
  }
}
项目:intellij-ce-playground    文件:ExternalSystemFacadeManager.java   
public boolean isTaskActive(@NotNull ExternalSystemTaskId id) {
  Map<IntegrationKey, Pair<RemoteExternalSystemFacade, ExternalSystemExecutionSettings>> copy
    = ContainerUtilRt.newHashMap(myRemoteFacades);
  for (Map.Entry<IntegrationKey, Pair<RemoteExternalSystemFacade, ExternalSystemExecutionSettings>> entry : copy.entrySet()) {
    try {
      if (entry.getValue().first.isTaskInProgress(id)) {
        return true;
      }
    }
    catch (RemoteException e) {
      myLock.lock();
      try {
        myRemoteFacades.remove(entry.getKey());
        myFacadeWrappers.remove(entry.getKey());
      }
      finally {
        myLock.unlock();
      }
    }
  }
  return false;
}
项目:intellij-ce-playground    文件:ExternalSystemExecuteTaskTask.java   
@SuppressWarnings("unchecked")
@Override
protected void doExecute() throws Exception {
  final ExternalSystemFacadeManager manager = ServiceManager.getService(ExternalSystemFacadeManager.class);
  ExternalSystemExecutionSettings settings = ExternalSystemApiUtil.getExecutionSettings(getIdeProject(),
                                                                                        getExternalProjectPath(),
                                                                                        getExternalSystemId());
  RemoteExternalSystemFacade facade = manager.getFacade(getIdeProject(), getExternalProjectPath(), getExternalSystemId());
  RemoteExternalSystemTaskManager taskManager = facade.getTaskManager();
  List<String> taskNames = ContainerUtilRt.map2List(myTasksToExecute, MAPPER);

  final List<String> vmOptions = parseCmdParameters(myVmOptions);
  final List<String> scriptParametersList = parseCmdParameters(myScriptParameters);

  taskManager.executeTasks(getId(), taskNames, getExternalProjectPath(), settings, vmOptions, scriptParametersList, myDebuggerSetup);
}
项目:intellij-ce-playground    文件:ExternalSystemTasksTree.java   
/**
 * Schedules 'collapse/expand' state restoring for the given path. We can't do that immediately from the tree model listener
 * as there is a possible case that other listeners have not been notified about the model state change, hence, attempt to define
 * 'collapse/expand' state may bring us to the inconsistent state.
 *
 * @param path  target path
 */
private void scheduleCollapseStateAppliance(@NotNull TreePath path) {
  myPathsToProcessCollapseState.add(path);
  myCollapseStateAlarm.cancelAllRequests();
  myCollapseStateAlarm.addRequest(new Runnable() {
    @Override
    public void run() {
      // We assume that the paths collection is modified only from the EDT, so, ConcurrentModificationException doesn't have
      // a chance.
      // Another thing is that we sort the paths in order to process the longest first. That is related to the JTree specifics
      // that it automatically expands parent paths on child path expansion.
      List<TreePath> paths = ContainerUtilRt.newArrayList(myPathsToProcessCollapseState);
      myPathsToProcessCollapseState.clear();
      Collections.sort(paths, PATH_COMPARATOR);
      for (TreePath treePath : paths) {
        applyCollapseState(treePath);
      }
      final TreePath rootPath = new TreePath(getModel().getRoot());
      if (isCollapsed(rootPath)) {
        expandPath(rootPath);
      }
    }
  }, COLLAPSE_STATE_PROCESSING_DELAY_MILLIS);
}
项目:intellij-ce-playground    文件:ExternalSystemTestUtil.java   
public static void assertMapsEqual(@NotNull Map<?, ?> expected, @NotNull Map<?, ?> actual) {
  Map<?, ?> local = ContainerUtilRt.newHashMap(expected);
  for (Map.Entry<?, ?> entry : actual.entrySet()) {
    Object expectedValue = local.remove(entry.getKey());
    if (expectedValue == null) {
      Assert.fail(String.format("Expected to find '%s' -> '%s' mapping but it doesn't exist", entry.getKey(), entry.getValue()));
    }
    if (!expectedValue.equals(entry.getValue())) {
      Assert.fail(
        String.format("Expected to find '%s' value for the key '%s' but got '%s'", expectedValue, entry.getKey(), entry.getValue())
      );
    }
  }
  if (!local.isEmpty()) {
    Assert.fail("No mappings found for the following keys: " + local.keySet());
  }
}
项目:intellij-ce-playground    文件:StandardArrangementEntryMatcherTest.java   
@Test
public void atomCondition() {
  ArrangementAtomMatchCondition condition = new ArrangementAtomMatchCondition(FIELD);

  StdArrangementEntryMatcher matcher = new StdArrangementEntryMatcher(condition);
  assertEquals(condition, matcher.getCondition());

  final TypeAwareArrangementEntry fieldEntry = myMockery.mock(TypeAwareArrangementEntry.class, "field");
  final TypeAwareArrangementEntry classEntry = myMockery.mock(TypeAwareArrangementEntry.class, "class");
  final ModifierAwareArrangementEntry publicEntry = myMockery.mock(ModifierAwareArrangementEntry.class, "public");
  myMockery.checking(new Expectations() {{
    allowing(fieldEntry).getTypes(); will(returnValue(ContainerUtilRt.newHashSet(FIELD)));
    allowing(classEntry).getTypes(); will(returnValue(ContainerUtilRt.newHashSet(CLASS)));
    allowing(publicEntry).getModifiers(); will(returnValue(ContainerUtilRt.newHashSet(PUBLIC)));
  }});

  assertTrue(matcher.isMatched(fieldEntry));
  assertFalse(matcher.isMatched(classEntry));
  assertFalse(matcher.isMatched(publicEntry));
}
项目:intellij-ce-playground    文件:StdArrangementEntryMatcher.java   
@Nullable
@Override
public Collection<ArrangementEntryMatcher> buildMatchers() {
  List<ArrangementEntryMatcher> result = ContainerUtilRt.newArrayList(myMatchers);
  Collection<ArrangementAtomMatchCondition> entryTokens = context.get(StdArrangementTokenType.ENTRY_TYPE);
  if (entryTokens!= null) {
    result.add(new ByTypeArrangementEntryMatcher(entryTokens));
  }
  Collection<ArrangementAtomMatchCondition> modifierTokens = context.get(StdArrangementTokenType.MODIFIER);
  if (modifierTokens != null) {
    result.add(new ByModifierArrangementEntryMatcher(modifierTokens));
  }
  if (myNamePattern != null) {
    result.add(new ByNameArrangementEntryMatcher(myNamePattern));
  }
  if (myNamespacePattern != null) {
    result.add(new ByNamespaceArrangementEntryMatcher(myNamespacePattern));
  }
  if (myText != null) {
    result.add(new ByTextArrangementEntryMatcher(myText));
  }
  return result;
}
项目:intellij-ce-playground    文件:VcsUtil.java   
@NotNull
public static Collection<VcsDirectoryMapping> findRoots(@NotNull VirtualFile rootDir, @NotNull Project project)
  throws IllegalArgumentException {
  if (!rootDir.isDirectory()) {
    throw new IllegalArgumentException(
      "Can't find VCS at the target file system path. Reason: expected to find a directory there but it's not. The path: "
      + rootDir.getParent()
    );
  }
  Collection<VcsRoot> roots = ServiceManager.getService(project, VcsRootDetector.class).detect(rootDir);
  Collection<VcsDirectoryMapping> result = ContainerUtilRt.newArrayList();
  for (VcsRoot vcsRoot : roots) {
    VirtualFile vFile = vcsRoot.getPath();
    AbstractVcs rootVcs = vcsRoot.getVcs();
    if (rootVcs != null && vFile != null) {
      result.add(new VcsDirectoryMapping(vFile.getPath(), rootVcs.getName()));
    }
  }
  return result;
}
项目:intellij-ce-playground    文件:ArrangementMatchingRuleEditor.java   
@Nullable
private Pair<ArrangementMatchCondition, ArrangementSettingsToken> buildCondition() {
  List<ArrangementMatchCondition> conditions = ContainerUtilRt.newArrayList();
  ArrangementSettingsToken orderType = null;
  for (ArrangementUiComponent component : myComponents.values()) {
    if (!component.isEnabled() || !component.isSelected()) {
      continue;
    }
    ArrangementSettingsToken token = component.getToken();
    if (token != null && StdArrangementTokenType.ORDER.is(token)) {
      orderType = token;
    }
    else {
      conditions.add(component.getMatchCondition());
    }
  }
  if (!conditions.isEmpty()) {
    if (orderType == null) {
      orderType = StdArrangementTokens.Order.KEEP;
    }
    return Pair.create(ArrangementUtil.combine(conditions.toArray(new ArrangementMatchCondition[conditions.size()])), orderType);
  }
  else {
    return null;
  }
}
项目:intellij-ce-playground    文件:ArrangementSettingsPanel.java   
@Override
protected void resetImpl(CodeStyleSettings settings) {
  StdArrangementSettings s = getSettings(settings);
  if (s == null) {
    myGroupingRulesPanel.setRules(null);
    myMatchingRulesPanel.setSections(null);
  }
  else {
    List<ArrangementGroupingRule> groupings = s.getGroupings();
    myGroupingRulesPanel.setRules(ContainerUtilRt.newArrayList(groupings));
    myMatchingRulesPanel.setSections(copy(s.getSections()));
    if (s instanceof StdArrangementExtendableSettings) {
      myMatchingRulesPanel.setRulesAliases(((StdArrangementExtendableSettings)s).getRuleAliases());
    }

    if (myForceArrangementPanel != null) {
      myForceArrangementPanel.setSelectedMode(settings.getCommonSettings(myLanguage).FORCE_REARRANGE_MODE);
    }
  }
}
项目:intellij-ce-playground    文件:GradleManager.java   
@Override
public void enhanceRemoteProcessing(@NotNull SimpleJavaParameters parameters) throws ExecutionException {
  final Set<String> additionalEntries = ContainerUtilRt.newHashSet();
  for (GradleProjectResolverExtension extension : RESOLVER_EXTENSIONS.getValue()) {
    ContainerUtilRt.addIfNotNull(additionalEntries, PathUtil.getJarPathForClass(extension.getClass()));
    for (Class aClass : extension.getExtraProjectModelClasses()) {
      ContainerUtilRt.addIfNotNull(additionalEntries, PathUtil.getJarPathForClass(aClass));
    }
    extension.enhanceRemoteProcessing(parameters);
  }

  final PathsList classPath = parameters.getClassPath();
  for (String entry : additionalEntries) {
    classPath.add(entry);
  }

  parameters.getVMParametersList().addProperty(
    ExternalSystemConstants.EXTERNAL_SYSTEM_ID_KEY, GradleConstants.SYSTEM_ID.getId());
}
项目:intellij-ce-playground    文件:GradleManager.java   
private static void patchAvailableTasks(@NotNull Map<String, String> adjustedPaths, @NotNull GradleLocalSettings localSettings) {
  Map<String, Collection<ExternalTaskPojo>> adjustedAvailableTasks = ContainerUtilRt.newHashMap();
  for (Map.Entry<String, Collection<ExternalTaskPojo>> entry : localSettings.getAvailableTasks().entrySet()) {
    String newPath = adjustedPaths.get(entry.getKey());
    if (newPath == null) {
      adjustedAvailableTasks.put(entry.getKey(), entry.getValue());
    }
    else {
      for (ExternalTaskPojo task : entry.getValue()) {
        String newTaskPath = adjustedPaths.get(task.getLinkedExternalProjectPath());
        if (newTaskPath != null) {
          task.setLinkedExternalProjectPath(newTaskPath);
        }
      }
      adjustedAvailableTasks.put(newPath, entry.getValue());
    }
  }
  localSettings.setAvailableTasks(adjustedAvailableTasks);
}
项目:intellij-ce-playground    文件:GradleLibraryNamesMixer.java   
/**
 * Tries to ensure that given libraries have distinct names, i.e. traverses all of them and tries to generate
 * unique name for those with equal names.
 * 
 * @param libraries  libraries to process
 */
@SuppressWarnings("MethodMayBeStatic")
public void mixNames(@NotNull Collection<DataNode<LibraryData>> libraries) {
  if (libraries.isEmpty()) {
    return;
  }
  Map<String, Wrapped> names = ContainerUtilRt.newHashMap();
  List<Wrapped> data = ContainerUtilRt.newArrayList();
  for (DataNode<LibraryData> library : libraries) {
    Wrapped wrapped = new Wrapped(library.getData());
    data.add(wrapped);
  }
  boolean mixed = false;
  while (!mixed) {
    mixed = doMixNames(data, names);
  }
}
项目:intellij-ce-playground    文件:GrAnnotationNameValuePairImpl.java   
private static GroovyResolveResult[] multiResolveFromAlias(@NotNull GrAnnotation alias, @NotNull String name, @NotNull PsiAnnotation annotationCollector) {
  List<GroovyResolveResult> result = ContainerUtilRt.newArrayList();

  List<GrAnnotation> annotations = ContainerUtilRt.newArrayList();
  GrAnnotationCollector.collectAnnotations(annotations, alias, annotationCollector);

  for (GrAnnotation annotation : annotations) {
    final PsiElement clazz = annotation.getClassReference().resolve();
    if (clazz instanceof PsiClass && ((PsiClass)clazz).isAnnotationType()) {
      if (GroovyCommonClassNames.GROOVY_TRANSFORM_ANNOTATION_COLLECTOR.equals(((PsiClass)clazz).getQualifiedName())) continue;
      for (PsiMethod method : ((PsiClass)clazz).findMethodsByName(name, false)) {
        result.add(new GroovyResolveResultImpl(method, true));
      }
    }
  }

  return result.toArray(new GroovyResolveResult[result.size()]);
}
项目:tools-idea    文件:JpsModuleTest.java   
public void testAddSourceRoot() {
  final JpsModule module = myProject.addModule("m", JpsJavaModuleType.INSTANCE);
  JpsSimpleElement<JavaSourceRootProperties> properties = JpsElementFactory.getInstance().createSimpleElement(
    new JavaSourceRootProperties("com.xxx"));
  final JpsModuleSourceRoot sourceRoot = module.addSourceRoot("file://url", JavaSourceRootType.SOURCE, properties);

  assertSameElements(myDispatcher.retrieveAdded(JpsModule.class), module);
  assertSameElements(myDispatcher.retrieveAdded(JpsModuleSourceRoot.class), sourceRoot);

  final JpsModuleSourceRoot root = assertOneElement(module.getSourceRoots());
  assertEquals("file://url", root.getUrl());
  assertSameElements(ContainerUtilRt.newArrayList(module.getSourceRoots(JavaSourceRootType.SOURCE)), root);
  assertEmpty(ContainerUtil.newArrayList(module.getSourceRoots(JavaSourceRootType.TEST_SOURCE)));
  JpsTypedModuleSourceRoot<JpsSimpleElement<JavaSourceRootProperties>> typedRoot = root.asTyped(JavaSourceRootType.SOURCE);
  assertNotNull(typedRoot);
  assertEquals("com.xxx", typedRoot.getProperties().getData().getPackagePrefix());
}
项目:tools-idea    文件:JavaInheritanceWeigher.java   
@NotNull
@Override
public Set<String> fun(ProximityLocation location) {
  final HashSet<String> result = new HashSet<String>();
  PsiClass contextClass = PsiTreeUtil.getContextOfType(location.getPosition(), PsiClass.class, false);
  Processor<PsiClass> processor = new Processor<PsiClass>() {
    @Override
    public boolean process(PsiClass psiClass) {
      ContainerUtilRt.addIfNotNull(result, psiClass.getQualifiedName());
      return true;
    }
  };
  while (contextClass != null) {
    InheritanceUtil.processSupers(contextClass, true, processor);
    contextClass = contextClass.getContainingClass();
  }
  return result;
}
项目:tools-idea    文件:ContentRootData.java   
/**
 * Ask to remember that directory at the given path contains sources of the given type.
 *
 * @param type  target sources type
 * @param path  target source directory path
 * @throws IllegalArgumentException   if given path points to the directory that is not located
 *                                    under the {@link #getRootPath() content root}
 */
public void storePath(@NotNull ExternalSystemSourceType type, @NotNull String path) throws IllegalArgumentException {
  if (FileUtil.isAncestor(new File(getRootPath()), new File(path), false)) {
    Collection<String> paths = myData.get(type);
    if (paths == null) {
      myData.put(type, paths = ContainerUtilRt.newHashSet());
    }
    paths.add(ExternalSystemApiUtil.toCanonicalPath(path));
    return;
  }
  if (!ExternalSystemSourceType.EXCLUDED.equals(type)) { // There are external systems which mark output directory as 'excluded' path.
    // We don't need to bother if it's outside a module content root then.
    throw new IllegalArgumentException(String.format(
      "Can't register given path of type '%s' because it's out of content root.%nContent root: '%s'%nGiven path: '%s'",
      type, getRootPath(), new File(path).getAbsolutePath()
    ));
  }
}
项目:tools-idea    文件:ProjectDataManager.java   
@SuppressWarnings("unchecked")
public <T> void importData(@NotNull Key<T> key, @NotNull Collection<DataNode<T>> nodes, @NotNull Project project, boolean synchronous) {
  ensureTheDataIsReadyToUse(nodes);
  List<ProjectDataService<?, ?>> services = myServices.getValue().get(key);
  if (services == null) {
    LOG.warn(String.format(
      "Can't import data nodes '%s'. Reason: no service is registered for key %s. Available services for %s",
      nodes, key, myServices.getValue().keySet()
    ));
  }
  else {
    for (ProjectDataService<?, ?> service : services) {
      ((ProjectDataService<T, ?>)service).importData(nodes, project, synchronous);
    }
  }

  Collection<DataNode<?>> children = ContainerUtilRt.newArrayList();
  for (DataNode<T> node : nodes) {
    children.addAll(node.getChildren());
  }
  importData(children, project, synchronous);
}
项目:tools-idea    文件:ModuleDataService.java   
@NotNull
private Collection<DataNode<ModuleData>> filterExistingModules(@NotNull Collection<DataNode<ModuleData>> modules,
                                                               @NotNull Project project)
{
  Collection<DataNode<ModuleData>> result = ContainerUtilRt.newArrayList();
  for (DataNode<ModuleData> node : modules) {
    ModuleData moduleData = node.getData();
    Module module = myProjectStructureHelper.findIdeModule(moduleData, project);
    if (module == null) {
      result.add(node);
    }
    else {
      module.setOption(ExternalSystemConstants.EXTERNAL_SYSTEM_ID_KEY, moduleData.getOwner().toString());
      module.setOption(ExternalSystemConstants.LINKED_PROJECT_PATH_KEY, moduleData.getLinkedExternalProjectPath());
    }
  }
  return result;
}
项目:tools-idea    文件:ExternalSystemFacadeManager.java   
private static <V> void onProjectRename(@NotNull Map<IntegrationKey, V> data,
                                        @NotNull String oldName,
                                        @NotNull String newName)
{
  Set<IntegrationKey> keys = ContainerUtilRt.newHashSet(data.keySet());
  for (IntegrationKey key : keys) {
    if (!key.getIdeProjectName().equals(oldName)) {
      continue;
    }
    IntegrationKey newKey = new IntegrationKey(newName,
                                               key.getIdeProjectLocationHash(),
                                               key.getExternalSystemId(),
                                               key.getExternalProjectConfigPath());
    V value = data.get(key);
    data.put(newKey, value);
    data.remove(key);
    if (value instanceof Consumer) {
      //noinspection unchecked
      ((Consumer)value).consume(newKey);
    }
  }
}
项目:tools-idea    文件:ExternalSystemFacadeManager.java   
public boolean isTaskActive(@NotNull ExternalSystemTaskId id) {
  Map<IntegrationKey, Pair<RemoteExternalSystemFacade, ExternalSystemExecutionSettings>> copy
    = ContainerUtilRt.newHashMap(myRemoteFacades);
  for (Map.Entry<IntegrationKey, Pair<RemoteExternalSystemFacade, ExternalSystemExecutionSettings>> entry : copy.entrySet()) {
    try {
      if (entry.getValue().first.isTaskInProgress(id)) {
        return true;
      }
    }
    catch (RemoteException e) {
      myLock.lock();
      try {
        myRemoteFacades.remove(entry.getKey());
        myFacadeWrappers.remove(entry.getKey());
      }
      finally {
        myLock.unlock();
      }
    }
  }
  return false;
}
项目:tools-idea    文件:ExternalSystemExecuteTaskTask.java   
@SuppressWarnings("unchecked")
@Override
protected void doExecute() throws Exception {
  final ExternalSystemFacadeManager manager = ServiceManager.getService(ExternalSystemFacadeManager.class);
  ExternalSystemSettingsManager settingsManager = ServiceManager.getService(ExternalSystemSettingsManager.class);
  ExternalSystemExecutionSettings settings = settingsManager.getExecutionSettings(getIdeProject(),
                                                                                  getExternalProjectPath(),
                                                                                  getExternalSystemId());
  RemoteExternalSystemFacade facade = manager.getFacade(getIdeProject(), getExternalProjectPath(), getExternalSystemId());
  RemoteExternalSystemTaskManager taskManager = facade.getTaskManager();
  List<String> taskNames = ContainerUtilRt.map2List(myTasksToExecute, MAPPER);

  setState(ExternalSystemTaskState.IN_PROGRESS);
  try {
    taskManager.executeTasks(getId(), taskNames, getExternalProjectPath(), settings, myVmOptions);
  }
  finally {
    setState(ExternalSystemTaskState.FINISHED);
  }
}
项目:tools-idea    文件:AbstractExternalSystemConfigurable.java   
@Override
public void apply() throws ConfigurationException {
  SystemSettings systemSettings = getSettings();
  L publisher = systemSettings.getPublisher();
  publisher.onBulkChangeStart();
  try {
    List<ProjectSettings> projectSettings = ContainerUtilRt.newArrayList();
    for (ExternalSystemSettingsControl<ProjectSettings> control : myProjectSettingsControls) {
      ProjectSettings s = newProjectSettings();
      control.apply(s);
      projectSettings.add(s);
    }
    systemSettings.setLinkedProjectsSettings(projectSettings);
    if (mySystemSettingsControl != null) {
      mySystemSettingsControl.apply(systemSettings);
    }
  }
  finally {
    publisher.onBulkChangeEnd();
  }
}
项目:tools-idea    文件:ExternalSystemTasksTree.java   
/**
 * Schedules 'collapse/expand' state restoring for the given path. We can't do that immediately from the tree model listener
 * as there is a possible case that other listeners have not been notified about the model state change, hence, attempt to define
 * 'collapse/expand' state may bring us to the inconsistent state.
 *
 * @param path  target path
 */
private void scheduleCollapseStateAppliance(@NotNull TreePath path) {
  myPathsToProcessCollapseState.add(path);
  myCollapseStateAlarm.cancelAllRequests();
  myCollapseStateAlarm.addRequest(new Runnable() {
    @Override
    public void run() {
      // We assume that the paths collection is modified only from the EDT, so, ConcurrentModificationException doesn't have
      // a chance.
      // Another thing is that we sort the paths in order to process the longest first. That is related to the JTree specifics
      // that it automatically expands parent paths on child path expansion.
      List<TreePath> paths = ContainerUtilRt.newArrayList(myPathsToProcessCollapseState);
      myPathsToProcessCollapseState.clear();
      Collections.sort(paths, PATH_COMPARATOR);
      for (TreePath treePath : paths) {
        applyCollapseState(treePath);
      }
      final TreePath rootPath = new TreePath(getModel().getRoot());
      if (isCollapsed(rootPath)) {
        expandPath(rootPath);
      }
    }
  }, COLLAPSE_STATE_PROCESSING_DELAY_MILLIS);
}
项目:tools-idea    文件:StandardArrangementEntryMatcherTest.java   
@Test
public void atomCondition() {
  ArrangementAtomMatchCondition condition = new ArrangementAtomMatchCondition(FIELD);

  StdArrangementEntryMatcher matcher = new StdArrangementEntryMatcher(condition);
  assertEquals(condition, matcher.getCondition());

  final TypeAwareArrangementEntry fieldEntry = myMockery.mock(TypeAwareArrangementEntry.class, "field");
  final TypeAwareArrangementEntry classEntry = myMockery.mock(TypeAwareArrangementEntry.class, "class");
  final ModifierAwareArrangementEntry publicEntry = myMockery.mock(ModifierAwareArrangementEntry.class, "public");
  myMockery.checking(new Expectations() {{
    allowing(fieldEntry).getTypes(); will(returnValue(ContainerUtilRt.newHashSet(FIELD)));
    allowing(classEntry).getTypes(); will(returnValue(ContainerUtilRt.newHashSet(CLASS)));
    allowing(publicEntry).getModifiers(); will(returnValue(ContainerUtilRt.newHashSet(PUBLIC)));
  }});

  assertTrue(matcher.isMatched(fieldEntry));
  assertFalse(matcher.isMatched(classEntry));
  assertFalse(matcher.isMatched(publicEntry));
}
项目:tools-idea    文件:VcsUtil.java   
@NotNull
public static Collection<VcsDirectoryMapping> findRoots(@NotNull VirtualFile rootDir, @NotNull Project project)
  throws IllegalArgumentException
{
  if (!rootDir.isDirectory()) {
    throw new IllegalArgumentException(
      "Can't find VCS at the target file system path. Reason: expected to find a directory there but it's not. The path: "
      + rootDir.getParent()
    );
  }
  Collection<VcsDirectoryMapping> result = ContainerUtilRt.newArrayList();
  for (VcsRootFinder finder : VcsRootFinder.EP_NAME.getExtensions(project)) {
    result.addAll(finder.findRoots(rootDir));
  }
  return result;
}
项目:tools-idea    文件:ArrangementMatchingRuleEditor.java   
@Nullable
private Pair<ArrangementMatchCondition, ArrangementSettingsToken> buildCondition() {
  List<ArrangementMatchCondition> conditions = ContainerUtilRt.newArrayList();
  ArrangementSettingsToken orderType = null;
  for (ArrangementUiComponent component : myComponents.values()) {
    if (!component.isEnabled() || !component.isSelected()) {
      continue;
    }
    ArrangementSettingsToken token = component.getToken();
    if (token != null && StdArrangementTokens.Order.is(token)) {
      orderType = token;
    }
    else {
      conditions.add(component.getMatchCondition());
    }
  }
  if (orderType != null && !conditions.isEmpty()) {
    return Pair.create(ArrangementUtil.combine(conditions.toArray(new ArrangementMatchCondition[conditions.size()])), orderType);
  }
  else {
    return null;
  }
}
项目:tools-idea    文件:ArrangementSettingsPanel.java   
@Override
protected void resetImpl(CodeStyleSettings settings) {
  StdArrangementSettings s = getSettings(settings);
  if (s == null) {
    myGroupingRulesPanel.setRules(null);
    myMatchingRulesPanel.setRules(null);
  }
  else {
    List<ArrangementGroupingRule> groupings = s.getGroupings();
    myGroupingRulesPanel.setVisible(!groupings.isEmpty());
    if (!groupings.isEmpty()) {
      myGroupingRulesPanel.setRules(ContainerUtilRt.newArrayList(groupings));
    }
    myMatchingRulesPanel.setRules(copy(s.getRules()));
  }
}
项目:tools-idea    文件:GradleManager.java   
private static void patchAvailableTasks(@NotNull Map<String, String> adjustedPaths, @NotNull GradleLocalSettings localSettings) {
  Map<String, Collection<ExternalTaskPojo>> adjustedAvailableTasks = ContainerUtilRt.newHashMap();
  for (Map.Entry<String, Collection<ExternalTaskPojo>> entry : localSettings.getAvailableTasks().entrySet()) {
    String newPath = adjustedPaths.get(entry.getKey());
    if (newPath == null) {
      adjustedAvailableTasks.put(entry.getKey(), entry.getValue());
    }
    else {
      for (ExternalTaskPojo task : entry.getValue()) {
        String newTaskPath = adjustedPaths.get(task.getLinkedExternalProjectPath());
        if (newTaskPath != null) {
          task.setLinkedExternalProjectPath(newTaskPath);
        }
      }
      adjustedAvailableTasks.put(newPath, entry.getValue());
    }
  }
  localSettings.setAvailableTasks(adjustedAvailableTasks);
}
项目:tools-idea    文件:GradleLibraryNamesMixer.java   
/**
 * Tries to ensure that given libraries have distinct names, i.e. traverses all of them and tries to generate
 * unique name for those with equal names.
 * 
 * @param libraries  libraries to process
 */
@SuppressWarnings("MethodMayBeStatic")
public void mixNames(@NotNull Collection<DataNode<LibraryData>> libraries) {
  if (libraries.isEmpty()) {
    return;
  }
  Map<String, Wrapped> names = ContainerUtilRt.newHashMap();
  List<Wrapped> data = ContainerUtilRt.newArrayList();
  for (DataNode<LibraryData> library : libraries) {
    Wrapped wrapped = new Wrapped(library.getData());
    data.add(wrapped);
  }
  boolean mixed = false;
  while (!mixed) {
    mixed = doMixNames(data, names);
  }
}
项目:tools-idea    文件:GrAnnotationNameValuePairImpl.java   
private static GroovyResolveResult[] multiResolveFromAlias(@NotNull GrAnnotation alias, @NotNull String name, @NotNull GrAnnotation annotationCollector) {
  List<GroovyResolveResult> result = ContainerUtilRt.newArrayList();

  List<GrAnnotation> annotations = ContainerUtilRt.newArrayList();
  GrAnnotationCollector.collectAnnotations(annotations, alias, annotationCollector);

  for (GrAnnotation annotation : annotations) {
    final PsiElement clazz = annotation.getClassReference().resolve();
    if (clazz instanceof PsiClass && ((PsiClass)clazz).isAnnotationType()) {
      if (GroovyCommonClassNames.GROOVY_TRANSFORM_ANNOTATION_COLLECTOR.equals(((PsiClass)clazz).getQualifiedName())) continue;
      for (PsiMethod method : ((PsiClass)clazz).findMethodsByName(name, false)) {
        result.add(new GroovyResolveResultImpl(method, true));
      }
    }
  }

  return result.toArray(new GroovyResolveResult[result.size()]);
}
项目:consulo    文件:ProjectDataManager.java   
@SuppressWarnings("unchecked")
public <T> void importData(@Nonnull Key<T> key, @Nonnull Collection<DataNode<T>> nodes, @Nonnull Project project, boolean synchronous) {
  ensureTheDataIsReadyToUse(nodes);
  List<ProjectDataService<?, ?>> services = myServices.getValue().get(key);
  if (services == null) {
    LOG.warn(String.format(
      "Can't import data nodes '%s'. Reason: no service is registered for key %s. Available services for %s",
      nodes, key, myServices.getValue().keySet()
    ));
  }
  else {
    for (ProjectDataService<?, ?> service : services) {
      ((ProjectDataService<T, ?>)service).importData(nodes, project, synchronous);
    }
  }

  Collection<DataNode<?>> children = ContainerUtilRt.newArrayList();
  for (DataNode<T> node : nodes) {
    children.addAll(node.getChildren());
  }
  importData(children, project, synchronous);
}
项目:consulo    文件:ModuleDataService.java   
@Nonnull
@RequiredDispatchThread
private Collection<DataNode<ModuleData>> filterExistingModules(@Nonnull Collection<DataNode<ModuleData>> modules, @Nonnull Project project) {
  Collection<DataNode<ModuleData>> result = ContainerUtilRt.newArrayList();
  for (DataNode<ModuleData> node : modules) {
    ModuleData moduleData = node.getData();
    Module module = ProjectStructureHelper.findIdeModule(moduleData, project);
    if (module == null) {
      result.add(node);
    }
    else {
      setModuleOptions(module, null, node);
    }
  }
  return result;
}
项目:consulo    文件:ExternalSystemFacadeManager.java   
private static <V> void onProjectRename(@Nonnull Map<IntegrationKey, V> data,
                                        @Nonnull String oldName,
                                        @Nonnull String newName)
{
  Set<IntegrationKey> keys = ContainerUtilRt.newHashSet(data.keySet());
  for (IntegrationKey key : keys) {
    if (!key.getIdeProjectName().equals(oldName)) {
      continue;
    }
    IntegrationKey newKey = new IntegrationKey(newName,
                                               key.getIdeProjectLocationHash(),
                                               key.getExternalSystemId(),
                                               key.getExternalProjectConfigPath());
    V value = data.get(key);
    data.put(newKey, value);
    data.remove(key);
    if (value instanceof Consumer) {
      //noinspection unchecked
      ((Consumer)value).consume(newKey);
    }
  }
}