private static void removeFromMap(
      LookupElement key,
      MultiMap<LookupElement, LookupElement> mainMap,
      MultiMap<LookupElement, LookupElement> inverseMap) {
    Collection<LookupElement> removed = mainMap.remove(key);
    if (removed == null) return;

    for (LookupElement reference : ContainerUtil.newArrayList(removed)) {
      inverseMap.remove(reference, key);
    }
  }
Ejemplo n.º 2
0
  private void handleStepOutOfLoop(
      @NotNull final Instruction prevInstruction,
      @NotNull Instruction nextInstruction,
      @NotNull final int[] loopNumber,
      @NotNull MultiMap<BranchingInstruction, DfaMemoryState> processedStates,
      @NotNull MultiMap<BranchingInstruction, DfaMemoryState> incomingStates,
      @NotNull List<DfaInstructionState> inFlightStates,
      @NotNull DfaInstructionState[] afterStates,
      @NotNull StateQueue queue) {
    if (loopNumber[prevInstruction.getIndex()] == 0
        || inSameLoop(prevInstruction, nextInstruction, loopNumber)) {
      return;
    }
    // stepped out of loop. destroy all memory states from the loop, we don't need them anymore

    // but do not touch yet states being handled right now
    for (DfaInstructionState state : inFlightStates) {
      Instruction instruction = state.getInstruction();
      if (inSameLoop(prevInstruction, instruction, loopNumber)) {
        return;
      }
    }
    for (DfaInstructionState state : afterStates) {
      Instruction instruction = state.getInstruction();
      if (inSameLoop(prevInstruction, instruction, loopNumber)) {
        return;
      }
    }
    // and still in queue
    if (!queue.processAll(
        new Processor<DfaInstructionState>() {
          @Override
          public boolean process(DfaInstructionState state) {
            Instruction instruction = state.getInstruction();
            return !inSameLoop(prevInstruction, instruction, loopNumber);
          }
        })) return;

    // now remove obsolete memory states
    final Set<BranchingInstruction> mayRemoveStatesFor = new THashSet<BranchingInstruction>();
    for (Instruction instruction : myInstructions) {
      if (inSameLoop(prevInstruction, instruction, loopNumber)
          && instruction instanceof BranchingInstruction) {
        mayRemoveStatesFor.add((BranchingInstruction) instruction);
      }
    }

    for (Instruction instruction : mayRemoveStatesFor) {
      processedStates.remove((BranchingInstruction) instruction);
      incomingStates.remove((BranchingInstruction) instruction);
    }
  }
  private void fillAddedFiles(
      Project project,
      SvnVcs vcs,
      List<VirtualFile> addedVFiles,
      Map<VirtualFile, File> copyFromMap,
      Set<VirtualFile> recursiveItems) {
    final Collection<AddedFileInfo> addedFileInfos = myAddedFiles.remove(project);
    final ChangeListManager changeListManager = ChangeListManager.getInstance(project);

    for (AddedFileInfo addedFileInfo : addedFileInfos) {
      final File ioFile = new File(getIOFile(addedFileInfo.myDir), addedFileInfo.myName);
      VirtualFile addedFile = addedFileInfo.myDir.findChild(addedFileInfo.myName);
      if (addedFile == null) {
        addedFile = myLfs.refreshAndFindFileByIoFile(ioFile);
      }
      if (addedFile != null) {
        final SVNStatus fileStatus = getFileStatus(vcs, ioFile);
        if (fileStatus == null || !SvnVcs.svnStatusIs(fileStatus, SVNStatusType.STATUS_IGNORED)) {
          boolean isIgnored = changeListManager.isIgnoredFile(addedFile);
          if (!isIgnored) {
            addedVFiles.add(addedFile);
            copyFromMap.put(addedFile, addedFileInfo.myCopyFrom);
            if (addedFileInfo.myRecursive) {
              recursiveItems.add(addedFile);
            }
          }
        }
      }
    }
  }
 public void minus(Pair<String, AbstractVcs> pair) {
   final VirtualFile root = getRootForPath(pair.getFirst());
   if (root == null) return;
   synchronized (myLock) {
     final VcsRoot key = new VcsRoot(pair.getSecond(), root);
     if (myQueries.containsKey(key)) {
       myQueries.remove(key, pair.getFirst());
     }
     myChanged.remove(pair.getFirst());
   }
 }
  @Override
  public void removeElement(@NotNull LookupElement element, @NotNull ProcessingContext context) {
    for (String s : CompletionUtil.iterateLookupStrings(element)) {
      myElements.remove(s, element);
      if (myElements.get(s).isEmpty()) {
        mySortedStrings.remove(s);
      }
    }

    removeFromMap(element, myToLift, myReversedToLift);
    removeFromMap(element, myReversedToLift, myToLift);

    super.removeElement(element, context);
  }
  private static void ensureInit() {
    if (ourClassSpecifiedContributors != null) return;

    MultiMap<String, NonCodeMembersContributor> contributorMap =
        new MultiMap<String, NonCodeMembersContributor>();

    for (final NonCodeMembersContributor contributor : EP_NAME.getExtensions()) {
      contributorMap.putValue(contributor.getParentClassName(), contributor);
    }

    Collection<NonCodeMembersContributor> allTypeContributors = contributorMap.remove(null);
    ourAllTypeContributors =
        allTypeContributors.toArray(new NonCodeMembersContributor[allTypeContributors.size()]);
    ourClassSpecifiedContributors = contributorMap;
  }
  @Override
  public void removeFoldRegion(@NotNull final FoldRegion region) {
    assertIsDispatchThreadForEditor();

    if (!myIsBatchFoldingProcessing) {
      LOG.error("Fold regions must be added or removed inside batchFoldProcessing() only.");
    }

    region.setExpanded(true);
    final FoldingGroup group = region.getGroup();
    if (group != null) {
      myGroups.remove(group, region);
    }

    myFoldTree.removeRegion(region);
    myFoldRegionsProcessed = true;
    region.dispose();
  }
 private void fillDeletedFiles(
     Project project,
     List<Pair<FilePath, WorkingCopyFormat>> deletedFiles,
     Collection<FilePath> deleteAnyway)
     throws SVNException {
   final SvnVcs vcs = SvnVcs.getInstance(project);
   final Collection<File> files = myDeletedFiles.remove(project);
   for (final File file : files) {
     final SVNStatus status =
         new RepeatSvnActionThroughBusy() {
           @Override
           protected void executeImpl() throws SVNException {
             myT = vcs.getFactory(file).createStatusClient().doStatus(file, false);
           }
         }.compute();
     boolean isAdded = SVNStatusType.STATUS_ADDED.equals(status.getNodeStatus());
     final FilePath filePath = VcsContextFactory.SERVICE.getInstance().createFilePathOn(file);
     if (isAdded) {
       deleteAnyway.add(filePath);
     } else {
       deletedFiles.add(Pair.create(filePath, vcs.getWorkingCopyFormat(file)));
     }
   }
 }
  public static MultiMap<String, GoImportSpec> filterUnusedImports(
      @NotNull PsiFile file, @NotNull MultiMap<String, GoImportSpec> importMap) {
    MultiMap<String, GoImportSpec> result = MultiMap.create();
    result.putAllValues(importMap);
    result.remove("_"); // imports for side effects are always used

    Collection<GoImportSpec> implicitImports = ContainerUtil.newArrayList(result.get("."));
    for (GoImportSpec importEntry : implicitImports) {
      GoImportSpec spec = getImportSpec(importEntry);
      if (spec != null && spec.isDot() && hasImportUsers(spec)) {
        result.remove(".", importEntry);
      }
    }

    file.accept(
        new GoRecursiveVisitor() {
          @Override
          public void visitTypeReferenceExpression(@NotNull GoTypeReferenceExpression o) {
            GoTypeReferenceExpression lastQualifier = o.getQualifier();
            if (lastQualifier != null) {
              GoTypeReferenceExpression previousQualifier;
              while ((previousQualifier = lastQualifier.getQualifier()) != null) {
                lastQualifier = previousQualifier;
              }
              markAsUsed(lastQualifier.getIdentifier(), lastQualifier.getReference());
            }
          }

          @Override
          public void visitReferenceExpression(@NotNull GoReferenceExpression o) {
            GoReferenceExpression lastQualifier = o.getQualifier();
            if (lastQualifier != null) {
              GoReferenceExpression previousQualifier;
              while ((previousQualifier = lastQualifier.getQualifier()) != null) {
                lastQualifier = previousQualifier;
              }
              markAsUsed(lastQualifier.getIdentifier(), lastQualifier.getReference());
            }
          }

          private void markAsUsed(@NotNull PsiElement qualifier, @NotNull PsiReference reference) {
            String qualifierText = qualifier.getText();
            if (!result.containsKey(qualifierText)) {
              // already marked
              return;
            }
            PsiElement resolve = reference.resolve();
            if (!(resolve instanceof PsiDirectory
                || resolve instanceof GoImportSpec
                || resolve instanceof PsiDirectoryContainer)) {
              return;
            }
            Collection<String> qualifiersToDelete = ContainerUtil.newHashSet();
            for (GoImportSpec spec : result.get(qualifierText)) {
              for (Map.Entry<String, Collection<GoImportSpec>> entry : result.entrySet()) {
                for (GoImportSpec importSpec : entry.getValue()) {
                  if (importSpec == spec) {
                    qualifiersToDelete.add(entry.getKey());
                  }
                }
              }
            }
            for (String qualifierToDelete : qualifiersToDelete) {
              result.remove(qualifierToDelete);
            }
          }
        });
    return result;
  }
Ejemplo n.º 10
0
  private List<TemplatesGroup> fillTemplatesMap(WizardContext context) {

    List<ModuleBuilder> builders = ModuleBuilder.getAllBuilders();
    if (context.isCreatingNewProject()) {
      builders.add(new EmptyModuleBuilder());
    }
    Map<String, TemplatesGroup> groupMap = new HashMap<String, TemplatesGroup>();
    for (ModuleBuilder builder : builders) {
      BuilderBasedTemplate template = new BuilderBasedTemplate(builder);
      if (builder.isTemplate()) {
        TemplatesGroup group = groupMap.get(builder.getGroupName());
        if (group == null) {
          group = new TemplatesGroup(builder);
        }
        myTemplatesMap.putValue(group, template);
      } else {
        TemplatesGroup group = new TemplatesGroup(builder);
        groupMap.put(group.getName(), group);
        myTemplatesMap.put(group, new ArrayList<ProjectTemplate>());
      }
    }

    MultiMap<TemplatesGroup, ProjectTemplate> map = CreateFromTemplateMode.getTemplatesMap(context);
    myTemplatesMap.putAllValues(map);

    for (ProjectCategory category : ProjectCategory.EXTENSION_POINT_NAME.getExtensions()) {
      TemplatesGroup group = new TemplatesGroup(category);
      myTemplatesMap.remove(group);
      myTemplatesMap.put(group, new ArrayList<ProjectTemplate>());
    }

    if (context.isCreatingNewProject()) {
      MultiMap<String, ProjectTemplate> localTemplates = loadLocalTemplates();
      for (TemplatesGroup group : myTemplatesMap.keySet()) {
        myTemplatesMap.putValues(group, localTemplates.get(group.getId()));
      }
    }

    // remove Static Web group in IDEA Community if no specific templates found (IDEA-120593)
    if (PlatformUtils.isIdeaCommunity()) {
      for (TemplatesGroup group : myTemplatesMap.keySet()) {
        if (WebModuleTypeBase.WEB_MODULE.equals(group.getId())
            && myTemplatesMap.get(group).isEmpty()) {
          myTemplatesMap.remove(group);
          break;
        }
      }
    }

    List<TemplatesGroup> groups = new ArrayList<TemplatesGroup>(myTemplatesMap.keySet());

    // sorting by module type popularity
    final MultiMap<ModuleType, TemplatesGroup> moduleTypes =
        new MultiMap<ModuleType, TemplatesGroup>();
    for (TemplatesGroup group : groups) {
      ModuleType type = getModuleType(group);
      moduleTypes.putValue(type, group);
    }
    Collections.sort(
        groups,
        new Comparator<TemplatesGroup>() {
          @Override
          public int compare(TemplatesGroup o1, TemplatesGroup o2) {
            int i = o2.getWeight() - o1.getWeight();
            if (i != 0) return i;
            int i1 =
                moduleTypes.get(getModuleType(o2)).size()
                    - moduleTypes.get(getModuleType(o1)).size();
            if (i1 != 0) return i1;
            return o1.compareTo(o2);
          }
        });

    Set<String> groupNames =
        ContainerUtil.map2Set(
            groups,
            new Function<TemplatesGroup, String>() {
              @Override
              public String fun(TemplatesGroup group) {
                return group.getParentGroup();
              }
            });

    // move subgroups
    MultiMap<String, TemplatesGroup> subGroups = new MultiMap<String, TemplatesGroup>();
    for (ListIterator<TemplatesGroup> iterator = groups.listIterator(); iterator.hasNext(); ) {
      TemplatesGroup group = iterator.next();
      String parentGroup = group.getParentGroup();
      if (parentGroup != null
          && groupNames.contains(parentGroup)
          && !group.getName().equals(parentGroup)
          && groupMap.containsKey(parentGroup)) {
        subGroups.putValue(parentGroup, group);
        iterator.remove();
      }
    }
    for (ListIterator<TemplatesGroup> iterator = groups.listIterator(); iterator.hasNext(); ) {
      TemplatesGroup group = iterator.next();
      for (TemplatesGroup subGroup : subGroups.get(group.getName())) {
        iterator.add(subGroup);
      }
    }
    return groups;
  }
  public static MultiMap<String, GoImportSpec> filterUnusedImports(
      @NotNull PsiFile file, @NotNull final MultiMap<String, GoImportSpec> importMap) {
    final MultiMap<String, GoImportSpec> result = MultiMap.create();
    result.putAllValues(importMap);
    result.remove("_"); // imports for side effects are always used

    Collection<GoImportSpec> implicitImports = ContainerUtil.newArrayList(result.get("."));
    for (GoImportSpec importEntry : implicitImports) {
      GoImportSpec spec = getImportSpec(importEntry);
      if (spec != null && spec.isDot()) {
        List<? extends PsiElement> list = spec.getUserData(GoReference.IMPORT_USERS);
        if (list != null) {
          for (PsiElement e : list) {
            if (e.isValid()) {
              result.remove(".", importEntry);
            }
          }
        }
      }
    }

    file.accept(
        new GoRecursiveVisitor() {
          @Override
          public void visitTypeReferenceExpression(@NotNull GoTypeReferenceExpression o) {
            GoTypeReferenceExpression lastQualifier = o.getQualifier();
            if (lastQualifier != null) {
              GoTypeReferenceExpression previousQualifier;
              while ((previousQualifier = lastQualifier.getQualifier()) != null) {
                lastQualifier = previousQualifier;
              }
              markAsUsed(lastQualifier.getIdentifier());
            }
          }

          @Override
          public void visitReferenceExpression(@NotNull GoReferenceExpression o) {
            GoReferenceExpression lastQualifier = o.getQualifier();
            if (lastQualifier != null) {
              GoReferenceExpression previousQualifier;
              while ((previousQualifier = lastQualifier.getQualifier()) != null) {
                lastQualifier = previousQualifier;
              }
              markAsUsed(lastQualifier.getIdentifier());
            }
          }

          private void markAsUsed(@NotNull PsiElement qualifier) {
            Collection<String> qualifiersToDelete = ContainerUtil.newHashSet();
            for (GoImportSpec spec : result.get(qualifier.getText())) {
              for (Map.Entry<String, Collection<GoImportSpec>> entry : result.entrySet()) {
                for (GoImportSpec importSpec : entry.getValue()) {
                  if (importSpec == spec) {
                    qualifiersToDelete.add(entry.getKey());
                  }
                }
              }
            }
            for (String qualifierToDelete : qualifiersToDelete) {
              result.remove(qualifierToDelete);
            }
          }
        });
    return result;
  }
Ejemplo n.º 12
0
 /** @deprecated use {@link #remove(Object, Object)} instead */
 public void removeValue(K key, V value) {
   remove(key, value);
 }
Ejemplo n.º 13
0
 public void removeFeature(Feature feature) {
   myFeatureToNodes.remove(feature);
   myModelRefToFeatures.removeValue(feature.getModelReference(), feature);
 }
 /**
  * Remove specified certificate and corresponding organization, if after removal it contains no
  * certificates.
  */
 public void removeCertificate(@NotNull X509Certificate certificate) {
   CertificateWrapper wrapper = new CertificateWrapper(certificate);
   myCertificates.remove(wrapper.getSubjectField(ORGANIZATION), wrapper);
   queueUpdateFrom(RootDescriptor.ROOT, true);
 }