Search in sources :

Example 46 with HashSet

use of com.intellij.util.containers.HashSet in project android by JetBrains.

the class ResourceManager method getValueResourceNames.

@NotNull
public Collection<String> getValueResourceNames(@NotNull final ResourceType resourceType) {
    final Set<String> result = new HashSet<String>();
    final boolean attr = ResourceType.ATTR == resourceType;
    for (ResourceEntry entry : getValueResourceEntries(resourceType)) {
        final String name = entry.getName();
        if (!attr || !name.startsWith("android:")) {
            result.add(name);
        }
    }
    return result;
}
Also used : ResourceEntry(org.jetbrains.android.util.ResourceEntry) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 47 with HashSet

use of com.intellij.util.containers.HashSet in project android by JetBrains.

the class AndroidFindStyleApplicationsProcessor method collectFilesToProcess.

public Collection<PsiFile> collectFilesToProcess() {
    final Project project = myModule.getProject();
    final List<VirtualFile> resDirs = new ArrayList<VirtualFile>();
    if (mySearchOnlyInCurrentModule) {
        collectResDir(myModule, myStyleNameAttrValue, myStyleName, resDirs);
    } else {
        for (Module m : getAllModulesToScan(myModule)) {
            collectResDir(m, myStyleNameAttrValue, myStyleName, resDirs);
        }
    }
    final List<VirtualFile> subdirs = AndroidResourceUtil.getResourceSubdirs(ResourceFolderType.LAYOUT, resDirs.toArray(new VirtualFile[resDirs.size()]));
    List<VirtualFile> filesToProcess = new ArrayList<VirtualFile>();
    for (VirtualFile subdir : subdirs) {
        for (VirtualFile child : subdir.getChildren()) {
            if (child.getFileType() == XmlFileType.INSTANCE && (myFileToScan == null || myFileToScan.equals(child))) {
                filesToProcess.add(child);
            }
        }
    }
    if (filesToProcess.size() == 0) {
        return Collections.emptyList();
    }
    final Set<PsiFile> psiFilesToProcess = new HashSet<PsiFile>();
    for (VirtualFile file : filesToProcess) {
        final PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
        if (psiFile != null) {
            psiFilesToProcess.add(psiFile);
        }
    }
    final CacheManager cacheManager = CacheManager.SERVICE.getInstance(project);
    final GlobalSearchScope projectScope = GlobalSearchScope.projectScope(project);
    for (Map.Entry<AndroidAttributeInfo, String> entry : myAttrMap.entrySet()) {
        filterFilesToScan(cacheManager, entry.getKey().getName(), psiFilesToProcess, projectScope);
        filterFilesToScan(cacheManager, entry.getValue(), psiFilesToProcess, projectScope);
    }
    return psiFilesToProcess;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) CacheManager(com.intellij.psi.impl.cache.CacheManager) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) HashMap(com.intellij.util.containers.HashMap) HashSet(com.intellij.util.containers.HashSet)

Example 48 with HashSet

use of com.intellij.util.containers.HashSet in project android by JetBrains.

the class AndroidInlineAllStyleUsagesProcessor method findUsages.

@NotNull
@Override
protected UsageInfo[] findUsages() {
    final Set<UsageInfo> usages = new HashSet<UsageInfo>();
    AndroidInlineUtil.addReferences(myStyleElement, usages);
    for (PsiField field : AndroidResourceUtil.findResourceFieldsForValueResource(myStyleTag, false)) {
        AndroidInlineUtil.addReferences(field, usages);
    }
    return usages.toArray(new UsageInfo[usages.size()]);
}
Also used : PsiField(com.intellij.psi.PsiField) UsageInfo(com.intellij.usageView.UsageInfo) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 49 with HashSet

use of com.intellij.util.containers.HashSet in project android by JetBrains.

the class ResourceManager method findIdDeclarations.

// searches only declarations such as "@+id/..."
@NotNull
public List<XmlAttributeValue> findIdDeclarations(@NotNull final String id) {
    if (!isResourcePublic(ResourceType.ID.getName(), id)) {
        return Collections.emptyList();
    }
    final List<XmlAttributeValue> declarations = new ArrayList<XmlAttributeValue>();
    final Collection<VirtualFile> files = FileBasedIndex.getInstance().getContainingFiles(AndroidIdIndex.INDEX_ID, "+" + id, GlobalSearchScope.allScope(myProject));
    final Set<VirtualFile> fileSet = new HashSet<VirtualFile>(files);
    final PsiManager psiManager = PsiManager.getInstance(myProject);
    for (VirtualFile subdir : getResourceSubdirsToSearchIds()) {
        for (VirtualFile file : subdir.getChildren()) {
            if (fileSet.contains(file)) {
                final PsiFile psiFile = psiManager.findFile(file);
                if (psiFile instanceof XmlFile) {
                    psiFile.accept(new XmlRecursiveElementVisitor() {

                        @Override
                        public void visitXmlAttributeValue(XmlAttributeValue attributeValue) {
                            if (AndroidResourceUtil.isIdDeclaration(attributeValue)) {
                                final String idInAttr = AndroidResourceUtil.getResourceNameByReferenceText(attributeValue.getValue());
                                if (id.equals(idInAttr)) {
                                    declarations.add(attributeValue);
                                }
                            }
                        }
                    });
                }
            }
        }
    }
    return declarations;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlFile(com.intellij.psi.xml.XmlFile) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 50 with HashSet

use of com.intellij.util.containers.HashSet in project intellij-community by JetBrains.

the class GitRootConverter method convertRoots.

@NotNull
public List<VirtualFile> convertRoots(@NotNull List<VirtualFile> result) {
    // TODO this should be faster, because it is called rather often. gitRootOrNull could be a bottle-neck.
    ArrayList<VirtualFile> roots = new ArrayList<>();
    HashSet<VirtualFile> listed = new HashSet<>();
    for (VirtualFile f : result) {
        VirtualFile r = GitUtil.gitRootOrNull(f);
        if (r != null && listed.add(r)) {
            roots.add(r);
        }
    }
    return roots;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

HashSet (com.intellij.util.containers.HashSet)162 NotNull (org.jetbrains.annotations.NotNull)50 VirtualFile (com.intellij.openapi.vfs.VirtualFile)31 File (java.io.File)22 PsiElement (com.intellij.psi.PsiElement)20 Module (com.intellij.openapi.module.Module)19 ArrayList (java.util.ArrayList)18 Project (com.intellij.openapi.project.Project)17 THashSet (gnu.trove.THashSet)15 Nullable (org.jetbrains.annotations.Nullable)14 HashMap (com.intellij.util.containers.HashMap)13 IOException (java.io.IOException)13 PsiFile (com.intellij.psi.PsiFile)12 UsageInfo (com.intellij.usageView.UsageInfo)12 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)11 MultiMap (com.intellij.util.containers.MultiMap)11 Pair (com.intellij.openapi.util.Pair)7 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)7 ConflictsDialog (com.intellij.refactoring.ui.ConflictsDialog)6 Document (com.intellij.openapi.editor.Document)5