Search in sources :

Example 41 with HashSet

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

the class AndroidActivityAliasCompletionContributor method collectActivityAliases.

@NotNull
private static Set<String> collectActivityAliases(@NotNull AndroidFacet facet) {
    final Set<String> result = new HashSet<String>();
    doCollectActivityAliases(facet, result);
    for (AndroidFacet depFacet : AndroidUtils.getAllAndroidDependencies(facet.getModule(), true)) {
        doCollectActivityAliases(depFacet, result);
    }
    return result;
}
Also used : AndroidFacet(org.jetbrains.android.facet.AndroidFacet) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 42 with HashSet

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

the class AndroidUtils method getDepLibsPackages.

@NotNull
public static Set<String> getDepLibsPackages(Module module) {
    final Set<String> result = new HashSet<>();
    final HashSet<Module> visited = new HashSet<>();
    if (visited.add(module)) {
        for (AndroidFacet depFacet : getAllAndroidDependencies(module, true)) {
            final Manifest manifest = depFacet.getManifest();
            if (manifest != null) {
                String aPackage = manifest.getPackage().getValue();
                if (aPackage != null) {
                    result.add(aPackage);
                }
            }
        }
    }
    return result;
}
Also used : Module(com.intellij.openapi.module.Module) Manifest(org.jetbrains.android.dom.manifest.Manifest) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 43 with HashSet

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

the class ThemeEditorStyle method removeAttribute.

/**
   * Deletes an attribute of that particular style from all the relevant xml files
   */
public void removeAttribute(@NotNull final String attribute) {
    if (!isProjectStyle()) {
        throw new UnsupportedOperationException("Non project styles can not be modified");
    }
    final Project project = myManager.getProject();
    Collection<PsiFile> toBeEdited = new HashSet<PsiFile>();
    final Collection<XmlTag> toBeRemoved = new HashSet<XmlTag>();
    for (ResourceItem resourceItem : getStyleResourceItems()) {
        final XmlTag sourceXml = LocalResourceRepository.getItemTag(project, resourceItem);
        assert sourceXml != null;
        final XmlTag tag = getValueTag(sourceXml, attribute);
        if (tag != null) {
            toBeEdited.add(tag.getContainingFile());
            toBeRemoved.add(tag);
        }
    }
    new WriteCommandAction.Simple(project, "Removing " + attribute, toBeEdited.toArray(new PsiFile[toBeEdited.size()])) {

        @Override
        protected void run() {
            // Makes the command global even if only one xml file is modified
            // That way, the Undo is always available from the theme editor
            CommandProcessor.getInstance().markCurrentCommandAsGlobal(project);
            for (XmlTag tag : toBeRemoved) {
                tag.delete();
            }
        }
    }.execute();
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) ResourceItem(com.android.ide.common.res2.ResourceItem) HashSet(com.intellij.util.containers.HashSet) XmlTag(com.intellij.psi.xml.XmlTag)

Example 44 with HashSet

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

the class AndroidAutogenerator method runAapt.

private static void runAapt(@NotNull final AndroidFacet facet, @NotNull final CompileContext context, boolean force) {
    final Module module = facet.getModule();
    final AptAutogenerationItem item = ApplicationManager.getApplication().runReadAction(new Computable<AptAutogenerationItem>() {

        @Nullable
        @Override
        public AptAutogenerationItem compute() {
            if (module.isDisposed() || module.getProject().isDisposed()) {
                return null;
            }
            final VirtualFile manifestFile = AndroidRootUtil.getManifestFileForCompiler(facet);
            if (manifestFile == null) {
                context.addMessage(CompilerMessageCategory.ERROR, AndroidBundle.message("android.compilation.error.manifest.not.found", module.getName()), null, -1, -1);
                return null;
            }
            final Manifest manifest = AndroidUtils.loadDomElement(module, manifestFile, Manifest.class);
            if (manifest == null) {
                context.addMessage(CompilerMessageCategory.ERROR, "Cannot parse file", manifestFile.getUrl(), -1, -1);
                return null;
            }
            String packageName = manifest.getPackage().getValue();
            if (packageName != null) {
                packageName = packageName.trim();
            }
            if (packageName == null || packageName.length() <= 0) {
                context.addMessage(CompilerMessageCategory.ERROR, AndroidBundle.message("package.not.found.error"), manifestFile.getUrl(), -1, -1);
                return null;
            }
            if (!AndroidUtils.isValidAndroidPackageName(packageName)) {
                context.addMessage(CompilerMessageCategory.ERROR, AndroidBundle.message("not.valid.package.name.error", packageName), manifestFile.getUrl(), -1, -1);
                return null;
            }
            final String sourceRootPath = AndroidRootUtil.getAptGenSourceRootPath(facet);
            if (sourceRootPath == null) {
                context.addMessage(CompilerMessageCategory.ERROR, AndroidBundle.message("android.compilation.error.apt.gen.not.specified", module.getName()), null, -1, -1);
                return null;
            }
            final Map<String, String> genFilePath2Package = new HashMap<String, String>();
            final String packageDir = packageName.replace('.', '/') + '/';
            genFilePath2Package.put(packageDir + AndroidCommonUtils.MANIFEST_JAVA_FILE_NAME, packageName);
            genFilePath2Package.put(packageDir + AndroidCommonUtils.R_JAVA_FILENAME, packageName);
            return new AptAutogenerationItem(packageName, sourceRootPath, genFilePath2Package);
        }
    });
    if (item == null) {
        return;
    }
    if (force) {
        final Set<VirtualFile> filesToCheck = new HashSet<VirtualFile>();
        for (String genFileRelPath : item.myGenFileRelPath2package.keySet()) {
            final String genFileFullPath = item.myOutputDirOsPath + '/' + genFileRelPath;
            if (new File(genFileFullPath).exists()) {
                final VirtualFile genFile = LocalFileSystem.getInstance().findFileByPath(genFileFullPath);
                if (genFile != null) {
                    filesToCheck.add(genFile);
                }
            }
        }
        if (!ensureFilesWritable(module.getProject(), filesToCheck)) {
            return;
        }
    }
    File tempOutDir = null;
    try {
        // Aapt generation can be very long, so we generate it in temp directory first
        tempOutDir = FileUtil.createTempDirectory("android_apt_autogeneration", "tmp");
        generateStubClasses(item.myPackage, tempOutDir, AndroidUtils.R_CLASS_NAME, AndroidUtils.MANIFEST_CLASS_NAME);
        for (String genFileRelPath : item.myGenFileRelPath2package.keySet()) {
            final File srcFile = new File(tempOutDir.getPath() + '/' + genFileRelPath);
            if (srcFile.isFile()) {
                final File dstFile = new File(item.myOutputDirOsPath + '/' + genFileRelPath);
                if (dstFile.exists()) {
                    if (!force) {
                        continue;
                    }
                    if (!FileUtil.delete(dstFile)) {
                        ApplicationManager.getApplication().runReadAction(new Runnable() {

                            @Override
                            public void run() {
                                if (module.isDisposed() || module.getProject().isDisposed()) {
                                    return;
                                }
                                context.addMessage(CompilerMessageCategory.ERROR, "Cannot delete " + FileUtil.toSystemDependentName(dstFile.getPath()), null, -1, -1);
                            }
                        });
                    }
                }
                FileUtil.rename(srcFile, dstFile);
            }
        }
        for (Map.Entry<String, String> entry : item.myGenFileRelPath2package.entrySet()) {
            final String path = item.myOutputDirOsPath + '/' + entry.getKey();
            final String aPackage = entry.getValue();
            final File file = new File(path);
            CompilerUtil.refreshIOFile(file);
            removeAllFilesWithSameName(module, file, item.myOutputDirOsPath);
            removeDuplicateClasses(module, aPackage, file, item.myOutputDirOsPath);
        }
        final VirtualFile genSourceRoot = LocalFileSystem.getInstance().findFileByPath(item.myOutputDirOsPath);
        if (genSourceRoot != null) {
            genSourceRoot.refresh(false, true);
        }
        facet.clearAutogeneratedFiles(AndroidAutogeneratorMode.AAPT);
        for (String relPath : item.myGenFileRelPath2package.keySet()) {
            final VirtualFile genFile = LocalFileSystem.getInstance().findFileByPath(item.myOutputDirOsPath + '/' + relPath);
            if (genFile != null && genFile.exists()) {
                facet.markFileAutogenerated(AndroidAutogeneratorMode.AAPT, genFile);
            }
        }
    } catch (final IOException e) {
        LOG.info(e);
        ApplicationManager.getApplication().runReadAction(new Runnable() {

            @Override
            public void run() {
                if (module.getProject().isDisposed())
                    return;
                context.addMessage(CompilerMessageCategory.ERROR, "I/O error: " + e.getMessage(), null, -1, -1);
            }
        });
    } finally {
        if (tempOutDir != null) {
            FileUtil.delete(tempOutDir);
        }
    }
}
Also used : IOException(java.io.IOException) Manifest(org.jetbrains.android.dom.manifest.Manifest) Module(com.intellij.openapi.module.Module) HashMap(com.intellij.util.containers.HashMap) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable) HashSet(com.intellij.util.containers.HashSet)

Example 45 with HashSet

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

the class AndroidCompileUtil method excludeAllBuildConfigsFromCompilation.

private static void excludeAllBuildConfigsFromCompilation(AndroidFacet facet, VirtualFile sourceRoot) {
    final Module module = facet.getModule();
    final Project project = module.getProject();
    final Set<String> packages = new HashSet<String>();
    final Manifest manifest = facet.getManifest();
    final String aPackage = manifest != null ? manifest.getPackage().getStringValue() : null;
    if (aPackage != null) {
        packages.add(aPackage);
    }
    packages.addAll(AndroidUtils.getDepLibsPackages(module));
    for (String p : packages) {
        excludeFromCompilation(project, sourceRoot, p);
    }
}
Also used : Project(com.intellij.openapi.project.Project) Module(com.intellij.openapi.module.Module) Manifest(org.jetbrains.android.dom.manifest.Manifest) HashSet(com.intellij.util.containers.HashSet)

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