Search in sources :

Example 81 with HashSet

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

the class AndroidCompileUtil method createGenModulesAndSourceRoots.

public static boolean createGenModulesAndSourceRoots(@NotNull AndroidFacet facet, @NotNull ModifiableRootModel model) {
    if (facet.requiresAndroidModel() || !facet.getProperties().ENABLE_SOURCES_AUTOGENERATION) {
        return false;
    }
    final GlobalSearchScope moduleScope = facet.getModule().getModuleScope();
    final Ref<Boolean> modelChangedFlag = Ref.create(false);
    if (facet.isLibraryProject()) {
        removeGenModule(model, modelChangedFlag);
    }
    final Set<String> genRootsToCreate = new HashSet<String>();
    final Set<String> genRootsToInit = new HashSet<String>();
    final String buildConfigGenRootPath = AndroidRootUtil.getBuildconfigGenSourceRootPath(facet);
    if (buildConfigGenRootPath != null) {
        genRootsToCreate.add(buildConfigGenRootPath);
    }
    final String renderscriptGenRootPath = AndroidRootUtil.getRenderscriptGenSourceRootPath(facet);
    if (renderscriptGenRootPath != null) {
        final boolean createIfNotExist = FileTypeIndex.getFiles(AndroidRenderscriptFileType.INSTANCE, moduleScope).size() > 0;
        (createIfNotExist ? genRootsToCreate : genRootsToInit).add(renderscriptGenRootPath);
    }
    final String aptGenRootPath = AndroidRootUtil.getAptGenSourceRootPath(facet);
    if (aptGenRootPath != null) {
        genRootsToCreate.add(aptGenRootPath);
    }
    final String aidlGenRootPath = AndroidRootUtil.getAidlGenSourceRootPath(facet);
    if (aidlGenRootPath != null) {
        final boolean createIfNotExist = FileTypeIndex.getFiles(AidlFileType.INSTANCE, moduleScope).size() > 0;
        (createIfNotExist ? genRootsToCreate : genRootsToInit).add(aidlGenRootPath);
    }
    genRootsToInit.addAll(genRootsToCreate);
    for (String genRootPath : genRootsToInit) {
        initializeGenSourceRoot(model, genRootPath, genRootsToCreate.contains(genRootPath), true, modelChangedFlag);
    }
    return modelChangedFlag.get();
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) HashSet(com.intellij.util.containers.HashSet)

Example 82 with HashSet

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

the class AndroidAutogenerator method runAidl.

private static void runAidl(@NotNull final AndroidFacet facet, @NotNull final CompileContext context) {
    final Module module = facet.getModule();
    final ModuleCompileScope moduleCompileScope = new ModuleCompileScope(module, false);
    final VirtualFile[] files = moduleCompileScope.getFiles(AidlFileType.INSTANCE, true);
    final List<IdlAutogenerationItem> items = new ArrayList<IdlAutogenerationItem>();
    for (final VirtualFile file : files) {
        final IdlAutogenerationItem item = ApplicationManager.getApplication().runReadAction(new Computable<IdlAutogenerationItem>() {

            @Nullable
            @Override
            public IdlAutogenerationItem compute() {
                if (module.isDisposed() || module.getProject().isDisposed()) {
                    return null;
                }
                final IAndroidTarget target = facet.getConfiguration().getAndroidTarget();
                if (target == null) {
                    context.addMessage(CompilerMessageCategory.ERROR, AndroidBundle.message("android.compilation.error.specify.platform", module.getName()), null, -1, -1);
                    return null;
                }
                final String packageName = AndroidUtils.computePackageName(module, file);
                if (packageName == null) {
                    context.addMessage(CompilerMessageCategory.ERROR, "Cannot compute package for file", file.getUrl(), -1, -1);
                    return null;
                }
                final String sourceRootPath = AndroidRootUtil.getAidlGenSourceRootPath(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 VirtualFile[] sourceRoots = getSourceRootsForModuleAndDependencies(module, false);
                final String[] sourceRootOsPaths = AndroidCompileUtil.toOsPaths(sourceRoots);
                final String outFileOsPath = FileUtil.toSystemDependentName(sourceRootPath + '/' + packageName.replace('.', '/') + '/' + file.getNameWithoutExtension() + ".java");
                return new IdlAutogenerationItem(file, target, outFileOsPath, sourceRootOsPaths, sourceRootPath, packageName);
            }
        });
        if (item != null) {
            items.add(item);
        }
    }
    final Set<VirtualFile> filesToCheck = new HashSet<VirtualFile>();
    for (IdlAutogenerationItem item : items) {
        if (new File(FileUtil.toSystemDependentName(item.myFile.getPath())).exists()) {
            filesToCheck.add(item.myFile);
        }
    }
    if (!ensureFilesWritable(module.getProject(), filesToCheck)) {
        return;
    }
    facet.clearAutogeneratedFiles(AndroidAutogeneratorMode.AIDL);
    for (IdlAutogenerationItem item : items) {
        final VirtualFile file = item.myFile;
        final String fileOsPath = FileUtil.toSystemDependentName(file.getPath());
        try {
            final Map<CompilerMessageCategory, List<String>> messages = AndroidCompileUtil.toCompilerMessageCategoryKeys(AndroidIdl.execute(item.myTarget, fileOsPath, item.myOutFileOsPath, item.mySourceRootOsPaths));
            ApplicationManager.getApplication().runReadAction(new Runnable() {

                @Override
                public void run() {
                    if (module.getProject().isDisposed())
                        return;
                    for (CompilerMessageCategory category : messages.keySet()) {
                        List<String> messageList = messages.get(category);
                        for (String message : messageList) {
                            context.addMessage(category, message, file.getUrl(), -1, -1);
                        }
                    }
                }
            });
            removeDuplicateClasses(module, item.myPackage, new File(item.myOutFileOsPath), item.myOutDirOsPath);
            final VirtualFile genDir = LocalFileSystem.getInstance().findFileByPath(item.myOutDirOsPath);
            if (genDir != null) {
                genDir.refresh(false, true);
            }
            final VirtualFile outFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(item.myOutFileOsPath);
            if (outFile != null && outFile.exists()) {
                patchAndMarkGeneratedFile(facet, AndroidAutogeneratorMode.AIDL, outFile);
            }
        } 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, e.getMessage(), file.getUrl(), -1, -1);
                }
            });
        }
    }
}
Also used : CompilerMessageCategory(com.intellij.openapi.compiler.CompilerMessageCategory) IAndroidTarget(com.android.sdklib.IAndroidTarget) IOException(java.io.IOException) ModuleCompileScope(com.intellij.compiler.impl.ModuleCompileScope) Module(com.intellij.openapi.module.Module) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable) HashSet(com.intellij.util.containers.HashSet)

Example 83 with HashSet

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

the class AndroidAutogenerator method run.

public static void run(@NotNull AndroidAutogeneratorMode mode, @NotNull AndroidFacet facet, @NotNull CompileContext context, boolean force) {
    if (!toRun(mode, facet, force)) {
        return;
    }
    final Set<String> obsoleteFiles = new HashSet<String>(facet.getAutogeneratedFiles(mode));
    switch(mode) {
        case AAPT:
            runAapt(facet, context, force);
            break;
        case AIDL:
            runAidl(facet, context);
            break;
        case RENDERSCRIPT:
            runRenderscript(facet, context);
            break;
        case BUILDCONFIG:
            runBuildConfigGenerator(facet, context);
            break;
        default:
            LOG.error("Unknown mode" + mode);
    }
    obsoleteFiles.removeAll(facet.getAutogeneratedFiles(mode));
    for (String path : obsoleteFiles) {
        final File file = new File(path);
        if (file.isFile()) {
            FileUtil.delete(file);
            CompilerUtil.refreshIOFile(file);
        }
    }
}
Also used : File(java.io.File) HashSet(com.intellij.util.containers.HashSet)

Example 84 with HashSet

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

the class ResourceManager method getValueResourceEntries.

@NotNull
public Collection<ResourceEntry> getValueResourceEntries(@NotNull final ResourceType resourceType) {
    final FileBasedIndex index = FileBasedIndex.getInstance();
    final ResourceEntry typeMarkerEntry = AndroidValueResourcesIndex.createTypeMarkerKey(resourceType.getName());
    final GlobalSearchScope scope = GlobalSearchScope.allScope(myProject);
    final Map<VirtualFile, Set<ResourceEntry>> file2resourceSet = new HashMap<VirtualFile, Set<ResourceEntry>>();
    index.processValues(AndroidValueResourcesIndex.INDEX_ID, typeMarkerEntry, null, new FileBasedIndex.ValueProcessor<ImmutableSet<AndroidValueResourcesIndex.MyResourceInfo>>() {

        @Override
        public boolean process(@NotNull VirtualFile file, ImmutableSet<AndroidValueResourcesIndex.MyResourceInfo> infos) {
            for (AndroidValueResourcesIndex.MyResourceInfo info : infos) {
                Set<ResourceEntry> resourcesInFile = file2resourceSet.get(file);
                if (resourcesInFile == null) {
                    resourcesInFile = new HashSet<ResourceEntry>();
                    file2resourceSet.put(file, resourcesInFile);
                }
                resourcesInFile.add(info.getResourceEntry());
            }
            return true;
        }
    }, scope);
    final List<ResourceEntry> result = new ArrayList<ResourceEntry>();
    for (VirtualFile file : getAllValueResourceFiles()) {
        final Set<ResourceEntry> entries = file2resourceSet.get(file);
        if (entries != null) {
            for (ResourceEntry entry : entries) {
                if (isResourcePublic(entry.getType(), entry.getName())) {
                    result.add(entry);
                }
            }
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HashSet(com.intellij.util.containers.HashSet) ImmutableSet(com.google.common.collect.ImmutableSet) HashMap(com.intellij.util.containers.HashMap) ImmutableSet(com.google.common.collect.ImmutableSet) ResourceEntry(org.jetbrains.android.util.ResourceEntry) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) AndroidValueResourcesIndex(org.jetbrains.android.AndroidValueResourcesIndex) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 85 with HashSet

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

the class ResourceManager method getResourceNames.

@NotNull
public Collection<String> getResourceNames(@NotNull ResourceType resourceType, boolean publicOnly) {
    final Set<String> result = new HashSet<String>();
    result.addAll(getValueResourceNames(resourceType));
    List<ResourceFolderType> folders = FolderTypeRelationship.getRelatedFolders(resourceType);
    if (!folders.isEmpty()) {
        for (ResourceFolderType folderType : folders) {
            if (folderType != ResourceFolderType.VALUES) {
                result.addAll(getFileResourcesNames(folderType.getName()));
            }
        }
    }
    if (resourceType == ResourceType.ID) {
        result.addAll(getIds(true));
    }
    return result;
}
Also used : ResourceFolderType(com.android.resources.ResourceFolderType) 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