gnu.trove.THashSet Java Examples

The following examples show how to use gnu.trove.THashSet. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DesktopEditorsSplitters.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
@Nonnull
public FileEditor[] getSelectedEditors() {
  Set<DesktopEditorWindow> windows = new THashSet<>(myWindows);
  final EditorWindow currentWindow = getCurrentWindow();
  if (currentWindow != null) {
    windows.add((DesktopEditorWindow)currentWindow);
  }
  List<FileEditor> editors = new ArrayList<>();
  for (final DesktopEditorWindow window : windows) {
    final DesktopEditorWithProviderComposite composite = window.getSelectedEditor();
    if (composite != null) {
      editors.add(composite.getSelectedEditor());
    }
  }
  return editors.toArray(new FileEditor[editors.size()]);
}
 
Example #2
Source File: DartVmServiceEvaluator.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private LibraryRef findMatchingLibrary(Isolate isolate, List<VirtualFile> libraryFiles) {
  if (libraryFiles != null && !libraryFiles.isEmpty()) {
    final Set<String> uris = new THashSet<>();

    for (VirtualFile libraryFile : libraryFiles) {
      uris.addAll(myDebugProcess.getUrisForFile(libraryFile));
    }

    for (LibraryRef library : isolate.getLibraries()) {
      if (uris.contains(library.getUri())) {
        return library;
      }
    }
  }
  return isolate.getRootLib();
}
 
Example #3
Source File: ModuleGroup.java    From consulo with Apache License 2.0 6 votes vote down vote up
public Collection<ModuleGroup> childGroups(ModifiableModuleModel model, Project project) {
  final Module[] allModules;
  if ( model != null ) {
    allModules = model.getModules();
  } else {
    allModules = ModuleManager.getInstance(project).getModules();
  }

  Set<ModuleGroup> result = new THashSet<ModuleGroup>();
  for (Module module : allModules) {
    String[] group;
    if ( model != null ) {
      group = model.getModuleGroupPath(module);
    } else {
      group = ModuleManager.getInstance(project).getModuleGroupPath(module);
    }
    if (group == null) continue;
    final String[] directChild = directChild(myGroupPath, group);
    if (directChild != null) {
      result.add(new ModuleGroup(directChild));
    }
  }

  return result;
}
 
Example #4
Source File: ScrapTest.java    From semafor-semantic-parser with GNU General Public License v3.0 6 votes vote down vote up
public static THashSet<String> getSpans()
{
	THashSet<String> spans = new THashSet<String>();
	try
	{
		String line = null;
		BufferedReader bReader = new BufferedReader(new FileReader("lrdata/matched_spans"));
		while((line=bReader.readLine())!=null)
		{
			String[] toks = line.trim().split("\t");
			char first = toks[0].charAt(0);
			if((first>='a'&&first<='z')||(first>='A'&&first<='Z')||(first>='0'&&first<='9'))
			{
				spans.add(toks[0].trim());
			}
		}
		bReader.close();
	}
	catch(Exception e)
	{
		e.printStackTrace();
	}
	return spans;
}
 
Example #5
Source File: ModuleWithDependentsScope.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static Set<Module> buildDependents(Module module) {
  Set<Module> result = new THashSet<Module>();
  result.add(module);

  Set<Module> processedExporting = new THashSet<Module>();

  ModuleIndex index = getModuleIndex(module.getProject());

  Queue<Module> walkingQueue = new Queue<Module>(10);
  walkingQueue.addLast(module);

  while (!walkingQueue.isEmpty()) {
    Module current = walkingQueue.pullFirst();
    processedExporting.add(current);
    result.addAll(index.plainUsages.get(current));
    for (Module dependent : index.exportingUsages.get(current)) {
      result.add(dependent);
      if (processedExporting.add(dependent)) {
        walkingQueue.addLast(dependent);
      }
    }
  }
  return result;
}
 
Example #6
Source File: LocalFileSystemRefreshWorker.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * @param fileOrDir
 * @param refreshContext
 * @param childrenToRefresh  null means all
 * @param existingPersistentChildren
 */
RefreshingFileVisitor(@Nonnull NewVirtualFile fileOrDir,
                      @Nonnull RefreshContext refreshContext,
                      @Nullable Collection<String> childrenToRefresh,
                      @Nonnull Collection<? extends VirtualFile> existingPersistentChildren) {
  myFileOrDir = fileOrDir;
  myRefreshContext = refreshContext;
  myPersistentChildren = new THashMap<>(existingPersistentChildren.size(), refreshContext.strategy);
  myChildrenWeAreInterested = childrenToRefresh == null ? null : new THashSet<>(childrenToRefresh, refreshContext.strategy);

  for (VirtualFile child : existingPersistentChildren) {
    String name = child.getName();
    myPersistentChildren.put(name, child);
    if (myChildrenWeAreInterested != null) myChildrenWeAreInterested.add(name);
  }
}
 
Example #7
Source File: PaperEvaluation.java    From semafor-semantic-parser with GNU General Public License v3.0 6 votes vote down vote up
public static void convertGoldJohanssonToFramesFile()
{
	String goldFile = malRootDir+"/testdata/semeval.fulltest.sentences.frame.elements";
	String outFile = malRootDir+"/testdata/file.frame.elements";
	ArrayList<String> inLines = ParsePreparation.readSentencesFromFile(goldFile);
	ArrayList<String> outLines = new ArrayList<String>();
	THashMap<String,THashSet<String>> frameMap = (THashMap<String,THashSet<String>>)SerializedObjects.readSerializedObject("lrdata/framenet.original.map");
	for(String inLine: inLines)
	{	
		String[] toks = inLine.split("\t");
		if(!frameMap.contains(toks[1]))
				continue;
		String outLine = "1\t"+toks[1]+"\t"+toks[2]+"\t"+toks[3]+"\t"+toks[4]+"\t"+toks[5];
		outLines.add(outLine);
	}
	ParsePreparation.writeSentencesToTempFile(outFile, outLines);
}
 
Example #8
Source File: PaperEvaluation.java    From semafor-semantic-parser with GNU General Public License v3.0 6 votes vote down vote up
public static void convertGoldTestToFramesFileOracleSpans()
{
	String goldFile = malRootDir+"/testdata/semeval.fulltest.sentences.frame.elements";
	String outFile = malRootDir+"/testdata/file.os.frame.elements";
	ArrayList<String> inLines = ParsePreparation.readSentencesFromFile(goldFile);
	ArrayList<String> outLines = new ArrayList<String>();
	THashMap<String,THashSet<String>> frameMap = (THashMap<String,THashSet<String>>)SerializedObjects.readSerializedObject("lrdata/framenet.original.map");
	for(String inLine: inLines)
	{
		String[] toks = inLine.split("\t");
		if(!frameMap.contains(toks[1]))
				continue;
		outLines.add(inLine);
	}
	ParsePreparation.writeSentencesToTempFile(outFile, outLines);
}
 
Example #9
Source File: LexicalUnitsFrameExtraction.java    From semafor-semantic-parser with GNU General Public License v3.0 6 votes vote down vote up
public static void printMap()
{
	String mapFile = "/mal2/dipanjan/experiments/FramenetParsing/framenet_1.3/ddData/framenet.original.map";
	THashMap<String,THashSet<String>> map = (THashMap<String,THashSet<String>>)SerializedObjects.readSerializedObject(mapFile);
	Set<String> set = map.keySet();
	for(String frame: set)
	{
		THashSet<String> val = map.get(frame);
		System.out.print(frame+": ");
		for(String unit: val)
		{
			System.out.print(unit+" ");
		}
		System.out.println();
	}
}
 
Example #10
Source File: CodeInsightUtilBase.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public boolean preparePsiElementsForWrite(@Nonnull Collection<? extends PsiElement> elements) {
  if (elements.isEmpty()) return true;
  Set<VirtualFile> files = new THashSet<VirtualFile>();
  Project project = null;
  for (PsiElement element : elements) {
    if (element == null) continue;
    PsiFile file = element.getContainingFile();
    if (file == null || !file.isPhysical()) continue;
    project = file.getProject();
    VirtualFile virtualFile = file.getVirtualFile();
    if (virtualFile == null) continue;
    files.add(virtualFile);
  }
  if (!files.isEmpty()) {
    VirtualFile[] virtualFiles = VfsUtilCore.toVirtualFileArray(files);
    ReadonlyStatusHandler.OperationStatus status = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(virtualFiles);
    return !status.hasReadonlyFiles();
  }
  return true;
}
 
Example #11
Source File: BaseDataManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
public <T> T getDataFromProvider(@Nonnull final DataProvider provider, @Nonnull Key<T> dataId, @Nullable Set<Key> alreadyComputedIds) {
  if (alreadyComputedIds != null && alreadyComputedIds.contains(dataId)) {
    return null;
  }
  try {
    T data = provider.getDataUnchecked(dataId);
    if (data != null) return validated(data, dataId, provider);

    GetDataRule<T> dataRule = getDataRule(dataId);
    if (dataRule != null) {
      final Set<Key> ids = alreadyComputedIds == null ? new THashSet<>() : alreadyComputedIds;
      ids.add(dataId);
      data = dataRule.getData(id -> getDataFromProvider(provider, id, ids));

      if (data != null) return validated(data, dataId, provider);
    }

    return null;
  }
  finally {
    if (alreadyComputedIds != null) alreadyComputedIds.remove(dataId);
  }
}
 
Example #12
Source File: FrameIdentificationDecoder.java    From semafor-semantic-parser with GNU General Public License v3.0 6 votes vote down vote up
private double getValueForFrame(String frame, int[] intTokNums, String[][] data)	
{
	THashSet<String> hiddenUnits = mFrameMap.get(frame);
	double result = 0.0;
	DependencyParse parse = DependencyParse.processFN(data, 0.0);
	for (String unit : hiddenUnits)
	{
		FeatureExtractor featex = new FeatureExtractor();
		IntCounter<String> valMap =  featex.extractFeatures(frame, intTokNums, unit, data, mWNR, "test", mWnRelationsCache,null,parse);
		Set<String> features = valMap.keySet();
		double featSum = 0.0;
		for (String feat : features)
		{
			double val = valMap.getT(feat);
			int ind = localA.get(feat);
			double paramVal = V[ind].exponentiate();
			double prod = val*paramVal;
			featSum+=prod;
		}
		double expVal = Math.exp(featSum);
		result+=expVal;
	}
	return result;
}
 
Example #13
Source File: FeatureExtractor.java    From semafor-semantic-parser with GNU General Public License v3.0 6 votes vote down vote up
public Set<String> getWNRelations(THashMap<String, THashSet<String>> wnCacheMap,String sWord, String tWord, WordNetRelations wnr)
{
	String pair = sWord.toLowerCase()+"\t"+tWord.toLowerCase();
	if(wnCacheMap==null)
	{
		return wnr.getRelations(sWord.toLowerCase(), tWord.toLowerCase());
	}
	else if(!wnCacheMap.contains(pair))
	{
		Set<String> relations = wnr.getRelations(sWord.toLowerCase(), tWord.toLowerCase());
		if(relations.contains(WordNetRelations.NO_RELATION))
			return relations;
		else
		{
			THashSet<String> nR = new THashSet<String>();
			for(String string:relations)
				nR.add(string);
			wnCacheMap.put(pair, nR);
			return relations;
		}
	}
	else
	{
		return wnCacheMap.get(pair);
	}
}
 
Example #14
Source File: ArchivesBuilder.java    From consulo with Apache License 2.0 6 votes vote down vote up
private <T> void addFileToArchive(@Nonnull T archiveObject,
                                  @Nonnull ArchivePackageWriter<T> writer,
                                  @Nonnull File file,
                                  @Nonnull String relativePath,
                                  @Nonnull THashSet<String> writtenPaths) throws IOException {
  if (!file.exists()) {
    return;
  }

  if (!FileUtil.isFilePathAcceptable(file, myFileFilter)) {
    return;
  }

  if (!writtenPaths.add(relativePath)) {
    return;
  }

  relativePath = addParentDirectories(archiveObject, writer, writtenPaths, relativePath);

  myContext.getProgressIndicator().setText2(relativePath);

  try (FileInputStream fileOutputStream = new FileInputStream(file)) {
    writer.addFile(archiveObject, fileOutputStream, relativePath, file.length(), file.lastModified());
  }
}
 
Example #15
Source File: Range.java    From semafor-semantic-parser with GNU General Public License v3.0 6 votes vote down vote up
public static Set<Integer> intersect(List<? extends Range> ranges) {
	Set<Integer> union = union(ranges);
	Set<Integer> result = new THashSet<Integer>();
	for (int i : union) {
		boolean included = true;
		for (Range range : ranges) {
			if (!range.contains(i)) {
				included = false;
				break;
			}
			if (included)
				result.add(i);
		}
	}
	return result;
}
 
Example #16
Source File: AbstractArtifactsBeforeRunTaskProvider.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
@Nonnull
@Override
public AsyncResult<Void> configureTask(RunConfiguration runConfiguration, T task) {
  final Artifact[] artifacts = ArtifactManager.getInstance(myProject).getArtifacts();
  Set<ArtifactPointer> pointers = new THashSet<>();
  for (Artifact artifact : artifacts) {
    pointers.add(ArtifactPointerManager.getInstance(myProject).create(artifact));
  }
  pointers.addAll(task.getArtifactPointers());
  ArtifactChooser chooser = new ArtifactChooser(new ArrayList<>(pointers));
  chooser.markElements(task.getArtifactPointers());
  chooser.setPreferredSize(new Dimension(400, 300));

  DialogBuilder builder = new DialogBuilder(myProject);
  builder.setTitle(CompilerBundle.message("build.artifacts.before.run.selector.title"));
  builder.setDimensionServiceKey("#BuildArtifactsBeforeRunChooser");
  builder.addOkAction();
  builder.addCancelAction();
  builder.setCenterPanel(chooser);
  builder.setPreferredFocusComponent(chooser);

  AsyncResult<Void> result = builder.showAsync();
  result.doWhenDone(() -> task.setArtifactPointers(chooser.getMarkedElements()));
  return result;
}
 
Example #17
Source File: HaxeSuggestIndexNameMacro.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
@Override
public Result calculateResult(@NotNull Expression[] params, ExpressionContext context) {
  final PsiElement at = context.getPsiElementAtStartOffset();
  final Set<HaxeComponentName> variables = HaxeMacroUtil.findVariables(at);
  final Set<String> names = new THashSet<String>(ContainerUtil.map(variables, new Function<HaxeComponentName, String>() {
    @Override
    public String fun(HaxeComponentName name) {
      return name.getName();
    }
  }));
  for (char i = 'i'; i < 'z'; ++i) {
    if (!names.contains(Character.toString(i))) {
      return new TextResult(Character.toString(i));
    }
  }
  return null;
}
 
Example #18
Source File: LexicalUnitsFrameExtraction.java    From semafor-semantic-parser with GNU General Public License v3.0 6 votes vote down vote up
/**
 * From flat-text files with sentences and frame occurrence information, 
 * creates a map from frame names to target words observed as evoking that frame 
 * and stores that map as a serialized object
 * @author dipanjan
 */
public static void writeMapOfFrames()
{
	String tokenizedFrameNetFile = "/mal2/dipanjan/experiments/FramenetParsing/framenet_1.3/ddData/framenet.original.sentences.all.tags";
	ArrayList<String> sentences = ParsePreparation.readSentencesFromFile(tokenizedFrameNetFile);
	String frameNetFrameFile = "/mal2/dipanjan/experiments/FramenetParsing/framenet_1.3/ddData/framenet.original.sentences.frames";
	ArrayList<String> frames = ParsePreparation.readSentencesFromFile(frameNetFrameFile);
	THashMap<String,THashSet<String>> map = new THashMap<String,THashSet<String>>();
	fillMap(map,frames,sentences);
			
	tokenizedFrameNetFile = "/mal2/dipanjan/experiments/FramenetParsing/framenet_1.3/ddData/semeval.fulltrain.sentences.all.tags";
	sentences = ParsePreparation.readSentencesFromFile(tokenizedFrameNetFile);
	frameNetFrameFile = "/mal2/dipanjan/experiments/FramenetParsing/framenet_1.3/ddData/semeval.fulltrain.sentences.frames";
	frames = ParsePreparation.readSentencesFromFile(frameNetFrameFile);
	fillMap(map,frames,sentences);		
	
	System.out.println(map.size());
	String mapFile = "/mal2/dipanjan/experiments/FramenetParsing/framenet_1.3/ddData/framenet.original.map";
	SerializedObjects.writeSerializedObject(map, mapFile);
}
 
Example #19
Source File: DesktopEditorMarkupModelImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public TooltipRenderer calcTooltipRenderer(@Nonnull final Collection<? extends RangeHighlighter> highlighters) {
  LineTooltipRenderer bigRenderer = null;
  //do not show same tooltip twice
  Set<String> tooltips = null;

  for (RangeHighlighter highlighter : highlighters) {
    final Object tooltipObject = highlighter.getErrorStripeTooltip();
    if (tooltipObject == null) continue;

    final String text = tooltipObject instanceof HighlightInfo ? ((HighlightInfo)tooltipObject).getToolTip() : tooltipObject.toString();
    if (text == null) continue;

    if (tooltips == null) {
      tooltips = new THashSet<>();
    }
    if (tooltips.add(text)) {
      if (bigRenderer == null) {
        bigRenderer = new LineTooltipRenderer(text, new Object[]{highlighters});
      }
      else {
        bigRenderer.addBelow(text);
      }
    }
  }

  return bigRenderer;
}
 
Example #20
Source File: VirtualFilePointerManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
synchronized Collection<VirtualFilePointer> dumpAllPointers() {
  Collection<VirtualFilePointer> result = new THashSet<>();
  for (Map<VirtualFilePointerListener, FilePointerPartNode> myPointers : myRoots.values()) {
    for (FilePointerPartNode node : myPointers.values()) {
      dumpPointersRecursivelyTo(node, result);
    }
  }
  return result;
}
 
Example #21
Source File: VcsDirtyScopeImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean belongsTo(final FilePath path, final Consumer<AbstractVcs> vcsConsumer) {
  if (myProject.isDisposed()) return false;
  final VcsRoot rootObject = myVcsManager.getVcsRootObjectFor(path);
  if (vcsConsumer != null && rootObject != null) {
    vcsConsumer.consume(rootObject.getVcs());
  }
  if (rootObject == null || rootObject.getVcs() != myVcs) {
    return false;
  }

  final VirtualFile vcsRoot = rootObject.getPath();
  if (vcsRoot != null) {
    for (VirtualFile contentRoot : myAffectedContentRoots) {
      // since we don't know exact dirty mechanics, maybe we have 3 nested mappings like:
      // /root -> vcs1, /root/child -> vcs2, /root/child/inner -> vcs1, and we have file /root/child/inner/file,
      // mapping is detected as vcs1 with root /root/child/inner, but we could possibly have in scope
      // "affected root" -> /root with scope = /root recursively
      if (VfsUtilCore.isAncestor(contentRoot, vcsRoot, false)) {
        THashSet<FilePath> dirsByRoot = myDirtyDirectoriesRecursively.get(contentRoot);
        if (dirsByRoot != null) {
          for (FilePath filePath : dirsByRoot) {
            if (path.isUnder(filePath, false)) return true;
          }
        }
      }
    }
  }

  if (!myDirtyFiles.isEmpty()) {
    FilePath parent = path.getParentPath();
    return isInDirtyFiles(path) || isInDirtyFiles(parent);
  }

  return false;
}
 
Example #22
Source File: VcsDirtyScopeImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private boolean isInDirtyFiles(final FilePath path) {
  final VcsRoot rootObject = myVcsManager.getVcsRootObjectFor(path);
  if (rootObject != null && myVcs.equals(rootObject.getVcs())) {
    final THashSet<FilePath> files = myDirtyFiles.get(rootObject.getPath());
    if (files != null && files.contains(path)) return true;
  }
  return false;
}
 
Example #23
Source File: PersistentFSImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void processEvents(@Nonnull List<? extends VFileEvent> events) {
  ApplicationManager.getApplication().assertWriteAccessAllowed();

  int startIndex = 0;
  int cappedInitialSize = Math.min(events.size(), INNER_ARRAYS_THRESHOLD);
  List<Runnable> applyEvents = new ArrayList<>(cappedInitialSize);
  MostlySingularMultiMap<String, VFileEvent> files = new MostlySingularMultiMap<String, VFileEvent>() {
    @Nonnull
    @Override
    protected Map<String, Object> createMap() {
      return new THashMap<>(cappedInitialSize, FileUtil.PATH_HASHING_STRATEGY);
    }
  };
  Set<String> middleDirs = new THashSet<>(cappedInitialSize, FileUtil.PATH_HASHING_STRATEGY);
  List<VFileEvent> validated = new ArrayList<>(cappedInitialSize);
  BulkFileListener publisher = getPublisher();
  while (startIndex != events.size()) {
    applyEvents.clear();
    files.clear();
    middleDirs.clear();
    validated.clear();
    startIndex = groupAndValidate(events, startIndex, applyEvents, validated, files, middleDirs);

    if (!validated.isEmpty()) {
      // do defensive copy to cope with ill-written listeners that save passed list for later processing
      List<VFileEvent> toSend = ContainerUtil.immutableList(validated.toArray(new VFileEvent[0]));
      publisher.before(toSend);

      applyEvents.forEach(Runnable::run);

      publisher.after(toSend);
    }
  }
}
 
Example #24
Source File: CSharpCompletionSorting.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
private ExpectedNameSorter(List<ExpectedTypeInfo> expectedTypeInfos)
{
	super("csharpByExpectedNameSorter");

	myExpectedNames = new THashSet<>();
	for(ExpectedTypeInfo expectedTypeInfo : expectedTypeInfos)
	{
		PsiElement typeProvider = expectedTypeInfo.getTypeProvider();
		if(typeProvider instanceof PsiNamedElement)
		{
			myExpectedNames.add(((PsiNamedElement) typeProvider).getName());
		}
	}
}
 
Example #25
Source File: MetadataNonPropertySuggestionNode.java    From intellij-spring-assistant with MIT License 5 votes vote down vote up
/**
 * @param originalName name that is not sanitised
 * @param parent       parent MetadataNonPropertySuggestionNode node
 * @param belongsTo    file/jar containing this property
 * @return newly constructed group node
 */
public static MetadataNonPropertySuggestionNode newInstance(String originalName,
    @Nullable MetadataNonPropertySuggestionNode parent, String belongsTo) {
  MetadataNonPropertySuggestionNodeBuilder builder =
      MetadataNonPropertySuggestionNode.builder().name(SuggestionNode.sanitise(originalName))
          .originalName(originalName).parent(parent);
  Set<String> belongsToSet = new THashSet<>();
  belongsToSet.add(belongsTo);
  builder.belongsTo(belongsToSet);
  return builder.build();
}
 
Example #26
Source File: VfsRootAccess.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static Collection<String> getAllRootUrls(@Nonnull Project project) {
  insideGettingRoots = true;
  final Set<String> roots = new THashSet<>();

  OrderEnumerator enumerator = ProjectRootManager.getInstance(project).orderEntries().using(new DefaultModulesProvider(project));
  ContainerUtil.addAll(roots, enumerator.classes().getUrls());
  ContainerUtil.addAll(roots, enumerator.sources().getUrls());

  insideGettingRoots = false;
  return roots;
}
 
Example #27
Source File: PsiSearchHelperImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param commonScope
 * @param data
 * @param keys
 * @return null means we did not find common container files
 */
@Nullable
private Set<VirtualFile> intersectionWithContainerNameFiles(@Nonnull GlobalSearchScope commonScope,
                                                            @Nonnull Collection<RequestWithProcessor> data,
                                                            @Nonnull Set<IdIndexEntry> keys) {
  String commonName = null;
  short searchContext = 0;
  boolean caseSensitive = true;
  for (RequestWithProcessor r : data) {
    String containerName = r.request.containerName;
    if (containerName != null) {
      if (commonName == null) {
        commonName = containerName;
        searchContext = r.request.searchContext;
        caseSensitive = r.request.caseSensitive;
      }
      else if (commonName.equals(containerName)) {
        searchContext |= r.request.searchContext;
        caseSensitive &= r.request.caseSensitive;
      }
      else {
        return null;
      }
    }
  }
  if (commonName == null) return null;

  List<IdIndexEntry> entries = getWordEntries(commonName, caseSensitive);
  if (entries.isEmpty()) return null;
  entries.addAll(keys); // should find words from both text and container names

  final short finalSearchContext = searchContext;
  Condition<Integer> contextMatches = context -> (context.intValue() & finalSearchContext) != 0;
  Set<VirtualFile> containerFiles = new THashSet<>();
  Processor<VirtualFile> processor = Processors.cancelableCollectProcessor(containerFiles);
  processFilesContainingAllKeys(myManager.getProject(), commonScope, contextMatches, entries, processor);

  return containerFiles;
}
 
Example #28
Source File: VcsLogJoiner.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void insertAllUseStack() {
  while (!newCommitsMap.isEmpty()) {
    commitsStack.push(newCommitsMap.values().iterator().next());
    while (!commitsStack.isEmpty()) {
      Commit currentCommit = commitsStack.peek();
      boolean allParentsWereAdded = true;
      for (CommitId parentHash : currentCommit.getParents()) {
        Commit parentCommit = newCommitsMap.get(parentHash);
        if (parentCommit != null) {
          commitsStack.push(parentCommit);
          allParentsWereAdded = false;
          break;
        }
      }

      if (!allParentsWereAdded) {
        continue;
      }

      int insertIndex;
      Set<CommitId> parents = new THashSet<>(currentCommit.getParents());
      for (insertIndex = 0; insertIndex < list.size(); insertIndex++) {
        Commit someCommit = list.get(insertIndex);
        if (parents.contains(someCommit.getId())) {
          break;
        }
        if (someCommit.getTimestamp() < currentCommit.getTimestamp()) {
          break;
        }
      }

      list.add(insertIndex, currentCommit);
      newCommitsMap.remove(currentCommit.getId());
      commitsStack.pop();
    }
  }
}
 
Example #29
Source File: FileIncludeManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static Collection<String> getPossibleIncludeNames(@Nonnull PsiFile context, @Nonnull String originalName) {
  Collection<String> names = new THashSet<>();
  names.add(originalName);
  for (FileIncludeProvider provider : FileIncludeProvider.EP_NAME.getExtensions()) {
    String newName = provider.getIncludeName(context, originalName);
    if (newName != originalName) {
      names.add(newName);
    }
  }
  return names;
}
 
Example #30
Source File: UndoableGroup.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public Collection<DocumentReference> getAffectedDocuments() {
  Set<DocumentReference> result = new THashSet<>();
  for (UndoableAction action : myActions) {
    DocumentReference[] refs = action.getAffectedDocuments();
    if (refs != null) Collections.addAll(result, refs);
  }
  return result;
}