use of gnu.trove.THashSet in project intellij-community by JetBrains.
the class GroovyAnnotator method checkDuplicateModifiers.
private static void checkDuplicateModifiers(AnnotationHolder holder, @NotNull GrModifierList list, PsiMember member) {
final PsiElement[] modifiers = list.getModifiers();
Set<String> set = new THashSet<>(modifiers.length);
for (PsiElement modifier : modifiers) {
if (modifier instanceof GrAnnotation)
continue;
@GrModifier.GrModifierConstant String name = modifier.getText();
if (set.contains(name)) {
final Annotation annotation = holder.createErrorAnnotation(list, GroovyBundle.message("duplicate.modifier", name));
registerFix(annotation, new GrModifierFix(member, name, false, false, GrModifierFix.MODIFIER_LIST), list);
} else {
set.add(name);
}
}
}
use of gnu.trove.THashSet in project intellij-community by JetBrains.
the class GroovyNamesUtil method getMethodArgumentsNames.
public static String[] getMethodArgumentsNames(Project project, PsiType[] types) {
Set<String> uniqNames = new LinkedHashSet<>();
Set<String> nonUniqNames = new THashSet<>();
for (PsiType type : types) {
final SuggestedNameInfo nameInfo = JavaCodeStyleManager.getInstance(project).suggestVariableName(VariableKind.PARAMETER, null, null, type);
final String name = nameInfo.names[0];
if (uniqNames.contains(name)) {
int i = 2;
while (uniqNames.contains(name + i)) i++;
uniqNames.add(name + i);
nonUniqNames.add(name);
} else {
uniqNames.add(name);
}
}
final String[] result = new String[uniqNames.size()];
int i = 0;
for (String name : uniqNames) {
result[i] = nonUniqNames.contains(name) ? name + 1 : name;
i++;
}
return result;
}
use of gnu.trove.THashSet in project intellij-community by JetBrains.
the class PsiSearchHelperImpl method processVirtualFile.
private void processVirtualFile(@NotNull final VirtualFile vfile, @NotNull final ProgressIndicator progress, @NotNull final Processor<? super PsiFile> localProcessor, @NotNull final AtomicBoolean canceled) throws ApplicationUtil.CannotRunReadActionException {
final PsiFile file = ApplicationUtil.tryRunReadAction(() -> vfile.isValid() ? myManager.findFile(vfile) : null);
if (file != null && !(file instanceof PsiBinaryFile)) {
// load contents outside read action
if (FileDocumentManager.getInstance().getCachedDocument(vfile) == null) {
// cache bytes in vfs
try {
vfile.contentsToByteArray();
} catch (IOException ignored) {
}
}
ApplicationUtil.tryRunReadAction(() -> {
final Project project = myManager.getProject();
if (project.isDisposed())
throw new ProcessCanceledException();
if (DumbService.isDumb(project))
throw new ApplicationUtil.CannotRunReadActionException();
List<PsiFile> psiRoots = file.getViewProvider().getAllFiles();
Set<PsiFile> processed = new THashSet<>(psiRoots.size() * 2, (float) 0.5);
for (final PsiFile psiRoot : psiRoots) {
progress.checkCanceled();
assert psiRoot != null : "One of the roots of file " + file + " is null. All roots: " + psiRoots + "; ViewProvider: " + file.getViewProvider() + "; Virtual file: " + file.getViewProvider().getVirtualFile();
if (!processed.add(psiRoot))
continue;
if (!psiRoot.isValid()) {
continue;
}
if (!localProcessor.process(psiRoot)) {
canceled.set(true);
break;
}
}
});
}
}
use of gnu.trove.THashSet in project intellij-community by JetBrains.
the class AdditionalIndexableFileSet method collectFilesAndDirectories.
private THashSet<VirtualFile> collectFilesAndDirectories() {
THashSet<VirtualFile> files = new THashSet<>();
THashSet<VirtualFile> directories = new THashSet<>();
if (myExtensions == null) {
myExtensions = Extensions.getExtensions(IndexableSetContributor.EP_NAME);
}
for (IndexableSetContributor contributor : myExtensions) {
for (VirtualFile root : IndexableSetContributor.getRootsToIndex(contributor)) {
(root.isDirectory() ? directories : files).add(root);
}
if (myProject != null) {
Set<VirtualFile> projectRoots = IndexableSetContributor.getProjectRootsToIndex(contributor, myProject);
for (VirtualFile root : projectRoots) {
(root.isDirectory() ? directories : files).add(root);
}
}
}
cachedFiles = files;
cachedDirectories = directories;
return directories;
}
use of gnu.trove.THashSet in project intellij-community by JetBrains.
the class ModuleWithDependentsScope method buildDependents.
private static Set<Module> buildDependents(Module module) {
Set<Module> result = new THashSet<>();
result.add(module);
Set<Module> processedExporting = new THashSet<>();
ModuleIndex index = getModuleIndex(module.getProject());
Queue<Module> walkingQueue = new Queue<>(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;
}
Aggregations