下面列出了com.intellij.psi.search.LocalSearchScope#com.intellij.util.containers.HashSet 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void resetSelection(@NotNull String[] selectedSerials) {
MyDeviceTableModel model = (MyDeviceTableModel)myDeviceTable.getModel();
Set<String> selectedSerialsSet = new HashSet<String>();
Collections.addAll(selectedSerialsSet, selectedSerials);
IDevice[] myDevices = model.myDevices;
ListSelectionModel selectionModel = myDeviceTable.getSelectionModel();
boolean cleared = false;
for (int i = 0, n = myDevices.length; i < n; i++) {
String serialNumber = myDevices[i].getSerialNumber();
if (selectedSerialsSet.contains(serialNumber)) {
if (!cleared) {
selectionModel.clearSelection();
cleared = true;
}
selectionModel.addSelectionInterval(i, i);
}
}
}
@Override
public Set<String> read(@NotNull DataInput in) throws IOException {
final int size = in.readInt();
if (size < 0) {
// Something is very wrong (corrupt index); trigger an index rebuild.
throw new IOException("Corrupt Index: Size " + size);
}
final Set<String> result = new HashSet<>(size);
for (int i = 0; i < size; i++) {
final String s = in.readUTF();
result.add(s);
}
return result;
}
@Override
public Set<String> read(@NotNull DataInput in) throws IOException {
final int size = in.readInt();
if (size < 0) {
// Something is very wrong (corrupt index); trigger an index rebuild.
throw new IOException("Corrupt Index: Size " + size);
}
final Set<String> result = new HashSet<>(size);
for (int i = 0; i < size; i++) {
final String s = in.readUTF();
result.add(s);
}
return result;
}
private Set<String> getReferencedFilesJson(final PsiFile file, final VirtualFile specDirectory) {
final Set<String> result = new HashSet<>();
file.accept(
new JsonRecursiveElementVisitor() {
@Override
public void visitProperty(@NotNull JsonProperty property) {
if (ApiConstants.REF_KEY.equals(property.getName()) && property.getValue() != null) {
final String refValue = StringUtils.removeAllQuotes(property.getValue().getText());
if (SwaggerFilesUtils.isFileReference(refValue)) {
getReferencedFileIndexValue(property.getValue(), refValue, specDirectory)
.ifPresent(result::add);
}
}
super.visitProperty(property);
}
});
return result;
}
private Set<String> getReferencedFilesYaml(final PsiFile file, final VirtualFile specDirectory) {
final Set<String> result = new HashSet<>();
file.accept(
new YamlRecursivePsiElementVisitor() {
@Override
public void visitKeyValue(@NotNull YAMLKeyValue yamlKeyValue) {
if (ApiConstants.REF_KEY.equals(yamlKeyValue.getKeyText())
&& yamlKeyValue.getValue() != null) {
final String refValue = StringUtils.removeAllQuotes(yamlKeyValue.getValueText());
if (SwaggerFilesUtils.isFileReference(refValue)) {
getReferencedFileIndexValue(yamlKeyValue.getValue(), refValue, specDirectory)
.ifPresent(result::add);
}
}
super.visitKeyValue(yamlKeyValue);
}
});
return result;
}
private void resetSelection(@NotNull String[] selectedSerials) {
MyDeviceTableModel model = (MyDeviceTableModel)myDeviceTable.getModel();
Set<String> selectedSerialsSet = new HashSet<String>();
Collections.addAll(selectedSerialsSet, selectedSerials);
IDevice[] myDevices = model.myDevices;
ListSelectionModel selectionModel = myDeviceTable.getSelectionModel();
boolean cleared = false;
for (int i = 0, n = myDevices.length; i < n; i++) {
String serialNumber = myDevices[i].getSerialNumber();
if (selectedSerialsSet.contains(serialNumber)) {
if (!cleared) {
selectionModel.clearSelection();
cleared = true;
}
selectionModel.addSelectionInterval(i, i);
}
}
}
@NotNull
@Override
public DataIndexer<String, Set<String>, FileContent> getIndexer() {
return inputData -> {
Map<String, Set<String>> map = new THashMap<>();
map.putIfAbsent("all", new java.util.HashSet<>());
FileType fileType = inputData.getFileType();
if (fileType == SmartyFileType.INSTANCE && inputData.getPsiFile() instanceof SmartyFile) {
for (String name : ConfigUtil.getConfigsInFile((SmartyFile) inputData.getPsiFile())) {
map.get("all").add(name);
}
} else {
PsiFile psiFile = inputData.getPsiFile();
if(!Symfony2ProjectComponent.isEnabled(psiFile.getProject())) {
return Collections.emptyMap();
}
psiFile.accept(new MyPsiRecursiveElementWalkingVisitor(map));
}
return map;
};
}
protected void loadModuleSymbols(final Map<String, List<LookupElement>> m) {
cacheLoaders.add(new Function<HaskellCompletionCacheLoader.Cache, Void>() {
@Override
public Void fun(HaskellCompletionCacheLoader.Cache cache) {
Map<String, Set<LookupElementWrapper>> syms = cache.moduleSymbols();
for (Map.Entry<String, List<LookupElement>> kvp : m.entrySet()) {
Set<LookupElementWrapper> v = syms.get(kvp.getKey());
if (v == null) {
v = new HashSet<LookupElementWrapper>(kvp.getValue().size());
syms.put(kvp.getKey(), v);
}
for (LookupElement e : kvp.getValue()) {
v.add(new LookupElementWrapper(e));
}
}
return null;
}
});
}
private void assertVisitedPaths(String... expected) {
VirtualFile vDir = myFileSystem.findFileByIoFile(myTempDir);
assertNotNull(vDir);
Set<String> expectedSet = new HashSet<String>(expected.length + 1, 1);
ContainerUtil.addAll(expectedSet, FileUtil.toSystemIndependentName(myTempDir.getPath()));
ContainerUtil.addAll(expectedSet, ContainerUtil.map(expected, new Function<String, String>() {
@Override
public String fun(String path) {
return FileUtil.toSystemIndependentName(path);
}
}));
final Set<String> actualSet = new HashSet<String>();
VfsUtilCore.visitChildrenRecursively(vDir, new VirtualFileVisitor() {
@Override
public boolean visitFile(@Nonnull VirtualFile file) {
actualSet.add(file.getPath());
return true;
}
});
assertEquals(expectedSet, actualSet);
}
protected void checkApply(Set<MyNode> rootNodes, String prefix, String title) throws ConfigurationException {
for (MyNode rootNode : rootNodes) {
final Set<String> names = new HashSet<String>();
for (int i = 0; i < rootNode.getChildCount(); i++) {
final MyNode node = (MyNode)rootNode.getChildAt(i);
final NamedConfigurable scopeConfigurable = node.getConfigurable();
final String name = scopeConfigurable.getDisplayName();
if (name.trim().length() == 0) {
selectNodeInTree(node);
throw new ConfigurationException("Name should contain non-space characters");
}
if (names.contains(name)) {
final NamedConfigurable selectedConfigurable = getSelectedConfigurable();
if (selectedConfigurable == null || !Comparing.strEqual(selectedConfigurable.getDisplayName(), name)) {
selectNodeInTree(node);
}
throw new ConfigurationException(CommonBundle.message("smth.already.exist.error.message", prefix, name), title);
}
names.add(name);
}
}
}
public ModuleRootCompileScope(Project project, final Module[] modules, boolean includeDependentModules) {
myProject = project;
myScopeModules = new HashSet<Module>();
for (Module module : modules) {
if (module == null) {
continue; // prevent NPE
}
if (includeDependentModules) {
buildScopeModulesSet(module);
}
else {
myScopeModules.add(module);
}
}
myModules = ModuleManager.getInstance(myProject).getModules();
}
@Override
public void assignModule(@Nonnull VirtualFile root, @Nonnull Module module, final boolean isTestSource, @Nullable Compiler compiler) {
try {
myRootToModuleMap.put(root, module);
Set<VirtualFile> set = myModuleToRootsMap.get(module);
if (set == null) {
set = new HashSet<VirtualFile>();
myModuleToRootsMap.put(module, set);
}
set.add(root);
if (isTestSource) {
myGeneratedTestRoots.add(root);
}
if (compiler instanceof SourceGeneratingCompiler) {
myOutputRootToSourceGeneratorMap.put(root, new Pair<SourceGeneratingCompiler, Module>((SourceGeneratingCompiler)compiler, module));
}
}
finally {
myModuleToRootsCache.remove(module);
}
}
@Nullable
private Set<Integer> getMatchingHeads(@Nonnull VcsLogRefs refs,
@Nonnull Collection<VirtualFile> roots,
@Nonnull VcsLogFilterCollection filters) {
VcsLogBranchFilter branchFilter = filters.getBranchFilter();
VcsLogRootFilter rootFilter = filters.getRootFilter();
VcsLogStructureFilter structureFilter = filters.getStructureFilter();
if (branchFilter == null && rootFilter == null && structureFilter == null) return null;
Set<Integer> filteredByBranch = null;
if (branchFilter != null) {
filteredByBranch = getMatchingHeads(refs, branchFilter);
}
Set<Integer> filteredByFile = getMatchingHeads(refs, roots);
if (filteredByBranch == null) return filteredByFile;
if (filteredByFile == null) return filteredByBranch;
return new HashSet<>(ContainerUtil.intersection(filteredByBranch, filteredByFile));
}
@Nonnull
@Override
public Set<WatchRequest> replaceWatchedRoots(@Nonnull Collection<WatchRequest> watchRequests,
@Nullable Collection<String> recursiveRoots,
@Nullable Collection<String> flatRoots) {
recursiveRoots = ObjectUtil.notNull(recursiveRoots, Collections.emptyList());
flatRoots = ObjectUtil.notNull(flatRoots, Collections.emptyList());
Set<WatchRequest> result = new HashSet<>();
synchronized (myLock) {
boolean update = doAddRootsToWatch(recursiveRoots, flatRoots, result) |
doRemoveWatchedRoots(watchRequests);
if (update) {
myNormalizedTree = null;
setUpFileWatcher();
}
}
return result;
}
public void setChanges(@Nonnull ArrayList<Change> changes) {
if (myChanges != null) {
HashSet<Change> newChanges = new HashSet<Change>(changes);
LOG.assertTrue(newChanges.size() == changes.size());
for (Iterator<Change> iterator = myChanges.iterator(); iterator.hasNext();) {
Change oldChange = iterator.next();
if (!newChanges.contains(oldChange)) {
iterator.remove();
oldChange.onRemovedFromList();
}
}
}
for (Change change : changes) {
LOG.assertTrue(change.isValid());
}
myChanges = new ArrayList<Change>(changes);
myAppliedChanges = new ArrayList<Change>();
}
@Override
public void loadState(final Element element) {
List<Element> groups = element.getChildren(GROUP_TAG);
for (Element groupElement : groups) {
String groupName = groupElement.getAttributeValue(GROUP_NAME_ATTR);
List<Element> projectsList = groupElement.getChildren(PROJECT_TAG);
for (Element projectElement : projectsList) {
String projectId = projectElement.getAttributeValue(PROJECT_ID_ATTR);
String frameworks = projectElement.getAttributeValue(VALUES_ATTR);
if (!StringUtil.isEmptyOrSpaces(projectId) && !StringUtil.isEmptyOrSpaces(frameworks)) {
Set<UsageDescriptor> frameworkDescriptors = new HashSet<UsageDescriptor>();
for (String key : StringUtil.split(frameworks, TOKENIZER)) {
final UsageDescriptor descriptor = getUsageDescriptor(key);
if (descriptor != null) frameworkDescriptors.add(descriptor);
}
getApplicationData(groupName).put(projectId, frameworkDescriptors);
}
}
}
}
@Override
public void persistPatch(@Nonnull Map<String, Set<PatchedUsage>> patchedDescriptorMap) {
for (Map.Entry<String, Set<PatchedUsage>> entry : patchedDescriptorMap.entrySet()) {
final String groupDescriptor = entry.getKey();
for (PatchedUsage patchedUsage : entry.getValue()) {
UsageDescriptor usageDescriptor = StatisticsUploadAssistant.findDescriptor(mySentDescriptors, Pair.create(groupDescriptor, patchedUsage.getKey()));
if (usageDescriptor != null) {
usageDescriptor.setValue(usageDescriptor.getValue() + patchedUsage.getDelta());
}
else {
if (!mySentDescriptors.containsKey(groupDescriptor)) {
mySentDescriptors.put(groupDescriptor, new HashSet<>());
}
mySentDescriptors.get(groupDescriptor).add(new UsageDescriptor(patchedUsage.getKey(), patchedUsage.getValue()));
}
}
}
setSentTime(System.currentTimeMillis());
}
@Override
protected boolean isActionEnabled(final Project project, final AnActionEvent event) {
final List<Pair<EditorComposite, EditorWindow>> filesToClose = getFilesToClose(event);
if (filesToClose.isEmpty()) return false;
Set<EditorWindow> checked = new HashSet<>();
for (Pair<EditorComposite, EditorWindow> pair : filesToClose) {
final EditorWindow window = pair.second;
if (!checked.contains(window)) {
checked.add(window);
if (hasPinned(window)) {
return true;
}
}
}
return false;
}
public void clearCurrent(Set<String> paths) {
final HashSet<String> converted = new HashSet<>();
for (String path : paths) {
converted.add(FilePathsHelper.convertPath(path));
}
synchronized (myLock) {
final Set<CurrentKey> toRemove = new HashSet<>();
myCurrentRevisionsCache.iterateKeys(new Consumer<CurrentKey>() {
@Override
public void consume(CurrentKey currentKey) {
if (converted.contains(FilePathsHelper.convertPath(currentKey.getPath().getPath()))) {
toRemove.add(currentKey);
}
}
});
for (CurrentKey key : toRemove) {
myCurrentRevisionsCache.remove(key);
}
}
}
private List<Module> getNotAddedModules() {
final ModifiableRootModel rootModel = myClasspathPanel.getRootModel();
Set<Module> addedModules = new HashSet<Module>(Arrays.asList(rootModel.getModuleDependencies(true)));
addedModules.add(rootModel.getModule());
final Module[] modules = myClasspathPanel.getModuleConfigurationState().getModulesProvider().getModules();
final List<Module> elements = new ArrayList<Module>();
for (final Module module : modules) {
if (!addedModules.contains(module)) {
elements.add(module);
}
}
ContainerUtil.sort(elements, new Comparator<Module>() {
@Override
public int compare(Module o1, Module o2) {
return StringUtil.compare(o1.getName(), o2.getName(), false);
}
});
return elements;
}
private static void excludeProblem(final String externalName, final Map<String, Set<OfflineProblemDescriptor>> content) {
for (Iterator<String> iter = content.keySet().iterator(); iter.hasNext();) {
final String packageName = iter.next();
final Set<OfflineProblemDescriptor> excluded = new HashSet<OfflineProblemDescriptor>(content.get(packageName));
for (Iterator<OfflineProblemDescriptor> it = excluded.iterator(); it.hasNext();) {
final OfflineProblemDescriptor ex = it.next();
if (Comparing.strEqual(ex.getFQName(), externalName)) {
it.remove();
}
}
if (excluded.isEmpty()) {
iter.remove();
} else {
content.put(packageName, excluded);
}
}
}
@Override
public void updateContent() {
myContents = new com.intellij.util.containers.HashMap<String, Set<RefEntity>>();
myModulesProblems = new HashSet<RefModule>();
final Set<RefEntity> elements = getProblemElements().keySet();
for (RefEntity element : elements) {
if (getContext().getUIOptions().FILTER_RESOLVED_ITEMS && getIgnoredElements().containsKey(element)) continue;
if (element instanceof RefModule) {
myModulesProblems.add((RefModule)element);
}
else {
String groupName = element instanceof RefElement ? element.getRefManager().getGroupName((RefElement)element) : null;
Set<RefEntity> content = myContents.get(groupName);
if (content == null) {
content = new HashSet<RefEntity>();
myContents.put(groupName, content);
}
content.add(element);
}
}
}
@Override
public Map<String, Set<RefEntity>> getOldContent() {
if (myOldProblemElements == null) return null;
final com.intellij.util.containers.HashMap<String, Set<RefEntity>>
oldContents = new com.intellij.util.containers.HashMap<String, Set<RefEntity>>();
final Set<RefEntity> elements = myOldProblemElements.keySet();
for (RefEntity element : elements) {
String groupName = element instanceof RefElement ? element.getRefManager().getGroupName((RefElement)element) : element.getName();
final Set<RefEntity> collection = myContents.get(groupName);
if (collection != null) {
final Set<RefEntity> currentElements = new HashSet<RefEntity>(collection);
if (RefUtil.contains(element, currentElements)) continue;
}
Set<RefEntity> oldContent = oldContents.get(groupName);
if (oldContent == null) {
oldContent = new HashSet<RefEntity>();
oldContents.put(groupName, oldContent);
}
oldContent.add(element);
}
return oldContents;
}
@Override
@Nonnull
public FileStatus getProblemStatus(@Nonnull final CommonProblemDescriptor descriptor) {
final GlobalInspectionContextImpl context = getContext();
if (!isDisposed() && context.getUIOptions().SHOW_DIFF_WITH_PREVIOUS_RUN){
if (myOldProblemElements != null){
final Set<CommonProblemDescriptor> allAvailable = new HashSet<CommonProblemDescriptor>();
for (CommonProblemDescriptor[] descriptors : myOldProblemElements.values()) {
if (descriptors != null) {
ContainerUtil.addAll(allAvailable, descriptors);
}
}
final boolean old = containsDescriptor(descriptor, allAvailable);
final boolean current = containsDescriptor(descriptor, getProblemToElements().keySet());
return calcStatus(old, current);
}
}
return FileStatus.NOT_CHANGED;
}
private Set<VirtualFile> getNotExcludedRoots() {
Set<VirtualFile> roots = new LinkedHashSet<VirtualFile>();
String[] excludedRootUrls = getLibraryEditor().getExcludedRootUrls();
Set<VirtualFile> excludedRoots = new HashSet<VirtualFile>();
for (String url : excludedRootUrls) {
ContainerUtil.addIfNotNull(excludedRoots, VirtualFileManager.getInstance().findFileByUrl(url));
}
for (OrderRootType type : OrderRootType.getAllTypes()) {
VirtualFile[] files = getLibraryEditor().getFiles(type);
for (VirtualFile file : files) {
if (!VfsUtilCore.isUnder(file, excludedRoots)) {
roots.add(PathUtil.getLocalFile(file));
}
}
}
return roots;
}
@Nonnull
@Override
public final Set<UsageDescriptor> getProjectUsages(@Nonnull final Project project) {
final Set<String> runConfigurationTypes = new HashSet<String>();
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
@Override
public void run() {
if (project.isDisposed()) return;
final RunManager runManager = RunManager.getInstance(project);
for (RunConfiguration runConfiguration : runManager.getAllConfigurationsList()) {
if (runConfiguration != null && isApplicable(runManager, runConfiguration)) {
final ConfigurationFactory configurationFactory = runConfiguration.getFactory();
final ConfigurationType configurationType = configurationFactory.getType();
final StringBuilder keyBuilder = new StringBuilder();
keyBuilder.append(configurationType.getId());
if (configurationType.getConfigurationFactories().length > 1) {
keyBuilder.append(".").append(configurationFactory.getName());
}
runConfigurationTypes.add(keyBuilder.toString());
}
}
}
});
return ContainerUtil.map2Set(runConfigurationTypes, runConfigurationType -> new UsageDescriptor(runConfigurationType, 1));
}
@RequiredReadAction
private Collection<FoldingDescriptor> getCustomFoldingDescriptors() {
Set<FoldingDescriptor> foldingDescriptors = new HashSet<FoldingDescriptor>();
final Document document = myEditor.getDocument();
PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myProject);
PsiFile file = documentManager != null ? documentManager.getPsiFile(document) : null;
if (file != null) {
final FileViewProvider viewProvider = file.getViewProvider();
for (final Language language : viewProvider.getLanguages()) {
final PsiFile psi = viewProvider.getPsi(language);
final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(language);
if (psi != null) {
for (FoldingDescriptor descriptor : LanguageFolding.buildFoldingDescriptors(foldingBuilder, psi, document, false)) {
CustomFoldingBuilder customFoldingBuilder = getCustomFoldingBuilder(foldingBuilder, descriptor);
if (customFoldingBuilder != null) {
if (customFoldingBuilder.isCustomRegionStart(descriptor.getElement())) {
foldingDescriptors.add(descriptor);
}
}
}
}
}
}
return foldingDescriptors;
}
@Nonnull
@RequiredReadAction
private static Collection<FoldingDescriptor> getCustomFoldingDescriptors(@Nonnull Editor editor, @Nonnull Project project) {
Set<FoldingDescriptor> foldingDescriptors = new HashSet<>();
final Document document = editor.getDocument();
PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
PsiFile file = documentManager != null ? documentManager.getPsiFile(document) : null;
if (file != null) {
final FileViewProvider viewProvider = file.getViewProvider();
for (final Language language : viewProvider.getLanguages()) {
final PsiFile psi = viewProvider.getPsi(language);
final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(language);
if (psi != null) {
for (FoldingDescriptor descriptor : LanguageFolding.buildFoldingDescriptors(foldingBuilder, psi, document, false)) {
CustomFoldingBuilder customFoldingBuilder = getCustomFoldingBuilder(foldingBuilder, descriptor);
if (customFoldingBuilder != null) {
if (customFoldingBuilder.isCustomRegionStart(descriptor.getElement())) {
foldingDescriptors.add(descriptor);
}
}
}
}
}
}
return foldingDescriptors;
}
@Nullable
public static PackageDependenciesNode[] findNodeForPsiElement(PackageDependenciesNode parent, PsiElement element){
final Set<PackageDependenciesNode> result = new HashSet<PackageDependenciesNode>();
for (int i = 0; i < parent.getChildCount(); i++){
final TreeNode treeNode = parent.getChildAt(i);
if (treeNode instanceof PackageDependenciesNode){
final PackageDependenciesNode node = (PackageDependenciesNode)treeNode;
if (element instanceof PsiDirectory && node.getPsiElement() == element){
return new PackageDependenciesNode[] {node};
}
if (element instanceof PsiFile) {
PsiFile psiFile = null;
if (node instanceof BasePsiNode) {
psiFile = ((BasePsiNode)node).getContainingFile();
}
else if (node instanceof FileNode) { //non java files
psiFile = ((PsiFile)node.getPsiElement());
}
if (psiFile != null && Comparing.equal(psiFile.getVirtualFile(), ((PsiFile)element).getVirtualFile())) {
result.add(node);
}
}
}
}
return result.isEmpty() ? null : result.toArray(new PackageDependenciesNode[result.size()]);
}
@Override
protected void checkApply(Set<MyNode> rootNodes, String prefix, String title) throws ConfigurationException {
super.checkApply(rootNodes, prefix, title);
final Set<String> predefinedScopes = new HashSet<String>();
for (CustomScopesProvider scopesProvider : myProject.getExtensions(CustomScopesProvider.CUSTOM_SCOPES_PROVIDER)) {
for (NamedScope namedScope : scopesProvider.getCustomScopes()) {
predefinedScopes.add(namedScope.getName());
}
}
for (MyNode rootNode : rootNodes) {
for (int i = 0; i < rootNode.getChildCount(); i++) {
final MyNode node = (MyNode)rootNode.getChildAt(i);
final NamedConfigurable scopeConfigurable = node.getConfigurable();
final String name = scopeConfigurable.getDisplayName();
if (predefinedScopes.contains(name)) {
selectNodeInTree(node);
throw new ConfigurationException("Scope name equals to predefined one", ProjectBundle.message("rename.scope.title"));
}
}
}
}