Search in sources :

Example 11 with HashSet

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

the class GroovyFoldingBuilder method appendDescriptors.

private void appendDescriptors(PsiElement element, List<FoldingDescriptor> descriptors, Set<PsiElement> usedComments) {
    ASTNode node = element.getNode();
    if (node == null)
        return;
    IElementType type = node.getElementType();
    if (TokenSets.BLOCK_SET.contains(type) && !isSingleHighLevelClassBody(element) || type == GroovyElementTypes.CLOSABLE_BLOCK) {
        if (isMultiline(element)) {
            collapseBlock(descriptors, element);
        }
    }
    // comments
    if ((type.equals(GroovyTokenTypes.mML_COMMENT) || type.equals(GroovyDocElementTypes.GROOVY_DOC_COMMENT)) && isMultiline(element) && isWellEndedComment(element)) {
        descriptors.add(new FoldingDescriptor(node, node.getTextRange()));
    }
    if (type.equals(GroovyTokenTypes.mSL_COMMENT) && !usedComments.contains(element)) {
        boolean containsCustomRegionMarker = isCustomRegionElement(element);
        usedComments.add(element);
        PsiElement end = null;
        for (PsiElement current = element.getNextSibling(); current != null; current = current.getNextSibling()) {
            if (PsiImplUtil.isWhiteSpaceOrNls(current))
                continue;
            IElementType elementType = current.getNode().getElementType();
            if (elementType == GroovyTokenTypes.mSL_COMMENT) {
                end = current;
                usedComments.add(current);
                containsCustomRegionMarker |= isCustomRegionElement(current);
                continue;
            }
            break;
        }
        if (end != null && !containsCustomRegionMarker) {
            final TextRange range = new TextRange(element.getTextRange().getStartOffset(), end.getTextRange().getEndOffset());
            descriptors.add(new FoldingDescriptor(element, range));
        }
    }
    //multiline strings
    addFoldingForStrings(descriptors, node);
    Set<PsiElement> newUsedComments = new HashSet<>();
    for (PsiElement child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
        appendDescriptors(child, descriptors, newUsedComments);
    }
    if (element instanceof GroovyFile) {
        processImports(descriptors, ((GroovyFile) element).getImportStatements());
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) FoldingDescriptor(com.intellij.lang.folding.FoldingDescriptor) NamedFoldingDescriptor(com.intellij.lang.folding.NamedFoldingDescriptor) ASTNode(com.intellij.lang.ASTNode) TextRange(com.intellij.openapi.util.TextRange) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile) HashSet(com.intellij.util.containers.hash.HashSet)

Example 12 with HashSet

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

the class AndroidPrecompileTask method checkArtifacts.

private static boolean checkArtifacts(@NotNull CompileContext context) {
    final Project project = context.getProject();
    final CompileScope scope = context.getCompileScope();
    final Set<Artifact> artifacts = ApplicationManager.getApplication().runReadAction(new Computable<Set<Artifact>>() {

        @Override
        public Set<Artifact> compute() {
            return ArtifactCompileScope.getArtifactsToBuild(project, scope, false);
        }
    });
    if (artifacts == null) {
        return true;
    }
    final Set<Artifact> debugArtifacts = new HashSet<>();
    final Set<Artifact> releaseArtifacts = new HashSet<>();
    final Map<AndroidFacet, List<Artifact>> facet2artifacts = new HashMap<>();
    for (final Artifact artifact : artifacts) {
        final ArtifactProperties<?> properties = artifact.getProperties(AndroidArtifactPropertiesProvider.getInstance());
        if (properties instanceof AndroidApplicationArtifactProperties) {
            final AndroidArtifactSigningMode mode = ((AndroidApplicationArtifactProperties) properties).getSigningMode();
            if (mode == AndroidArtifactSigningMode.DEBUG || mode == AndroidArtifactSigningMode.DEBUG_WITH_CUSTOM_CERTIFICATE) {
                debugArtifacts.add(artifact);
            } else {
                releaseArtifacts.add(artifact);
            }
        }
        final AndroidFacet facet = ApplicationManager.getApplication().runReadAction(new Computable<AndroidFacet>() {

            @Nullable
            @Override
            public AndroidFacet compute() {
                return AndroidArtifactUtil.getPackagedFacet(project, artifact);
            }
        });
        if (facet != null) {
            List<Artifact> list = facet2artifacts.get(facet);
            if (list == null) {
                list = new ArrayList<>();
                facet2artifacts.put(facet, list);
            }
            list.add(artifact);
        }
    }
    boolean success = true;
    if (debugArtifacts.size() > 0 && releaseArtifacts.size() > 0) {
        final String message = "Cannot build debug and release Android artifacts in the same session\n" + "Debug artifacts: " + toString(debugArtifacts) + "\n" + "Release artifacts: " + toString(releaseArtifacts);
        context.addMessage(CompilerMessageCategory.ERROR, message, null, -1, -1);
        success = false;
    }
    if (releaseArtifacts.size() > 0 && CompileStepBeforeRun.getRunConfiguration(context) != null) {
        final String message = "Cannot build release Android artifacts in the 'make before run' session\n" + "Release artifacts: " + toString(releaseArtifacts);
        context.addMessage(CompilerMessageCategory.ERROR, message, null, -1, -1);
        success = false;
    }
    for (Map.Entry<AndroidFacet, List<Artifact>> entry : facet2artifacts.entrySet()) {
        final List<Artifact> list = entry.getValue();
        final String moduleName = entry.getKey().getModule().getName();
        if (list.size() > 1) {
            final Artifact firstArtifact = list.get(0);
            final Object[] firstArtifactProGuardOptions = getProGuardOptions(firstArtifact);
            for (int i = 1; i < list.size(); i++) {
                final Artifact artifact = list.get(i);
                if (!Arrays.equals(getProGuardOptions(artifact), firstArtifactProGuardOptions)) {
                    context.addMessage(CompilerMessageCategory.ERROR, "Artifacts related to the same module '" + moduleName + "' have different ProGuard options: " + firstArtifact.getName() + ", " + artifact.getName(), null, -1, -1);
                    success = false;
                    break;
                }
            }
        }
    }
    return success;
}
Also used : HashSet(com.intellij.util.containers.hash.HashSet) HashMap(com.intellij.util.containers.HashMap) AndroidApplicationArtifactProperties(org.jetbrains.android.compiler.artifact.AndroidApplicationArtifactProperties) HashSet(com.intellij.util.containers.hash.HashSet) Artifact(com.intellij.packaging.artifacts.Artifact) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Project(com.intellij.openapi.project.Project) ArtifactCompileScope(com.intellij.packaging.impl.compiler.ArtifactCompileScope) AndroidArtifactSigningMode(org.jetbrains.android.compiler.artifact.AndroidArtifactSigningMode) HashMap(com.intellij.util.containers.HashMap) Nullable(org.jetbrains.annotations.Nullable)

Example 13 with HashSet

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

the class AndroidPrecompileTask method unexcludeAllSourceRoots.

private static void unexcludeAllSourceRoots(AndroidFacet facet, ExcludesConfiguration configuration) {
    final VirtualFile[] sourceRoots = ModuleRootManager.getInstance(facet.getModule()).getSourceRoots();
    final Set<VirtualFile> sourceRootSet = new HashSet<>();
    sourceRootSet.addAll(Arrays.asList(sourceRoots));
    final String aidlGenSourceRootPath = AndroidRootUtil.getAidlGenSourceRootPath(facet);
    if (aidlGenSourceRootPath != null) {
        final VirtualFile aidlGenSourceRoot = LocalFileSystem.getInstance().findFileByPath(aidlGenSourceRootPath);
        if (aidlGenSourceRoot != null) {
            sourceRootSet.remove(aidlGenSourceRoot);
        }
    }
    final String aptGenSourceRootPath = AndroidRootUtil.getAptGenSourceRootPath(facet);
    if (aptGenSourceRootPath != null) {
        final VirtualFile aptGenSourceRoot = LocalFileSystem.getInstance().findFileByPath(aptGenSourceRootPath);
        if (aptGenSourceRoot != null) {
            sourceRootSet.remove(aptGenSourceRoot);
        }
    }
    final VirtualFile rsGenRoot = AndroidRootUtil.getRenderscriptGenDir(facet);
    if (rsGenRoot != null) {
        sourceRootSet.remove(rsGenRoot);
    }
    final VirtualFile buildconfigGenDir = AndroidRootUtil.getBuildconfigGenDir(facet);
    if (buildconfigGenDir != null) {
        sourceRootSet.remove(buildconfigGenDir);
    }
    final ExcludeEntryDescription[] descriptions = configuration.getExcludeEntryDescriptions();
    configuration.removeAllExcludeEntryDescriptions();
    for (ExcludeEntryDescription description : descriptions) {
        final VirtualFile file = description.getVirtualFile();
        if (file == null || !sourceRootSet.contains(file)) {
            configuration.addExcludeEntryDescription(description);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ExcludeEntryDescription(com.intellij.openapi.compiler.options.ExcludeEntryDescription) HashSet(com.intellij.util.containers.hash.HashSet)

Example 14 with HashSet

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

the class AndroidPrecompileTask method prepareForCompilation.

private static boolean prepareForCompilation(CompileContext context) {
    final Project project = context.getProject();
    if (!checkArtifacts(context)) {
        return false;
    }
    checkAndroidDependencies(context);
    ExcludesConfiguration configuration = CompilerConfiguration.getInstance(project).getExcludedEntriesConfiguration();
    Set<ExcludeEntryDescription> addedEntries = new HashSet<>();
    for (Module module : ModuleManager.getInstance(project).getModules()) {
        final AndroidFacet facet = AndroidFacet.getInstance(module);
        if (facet == null) {
            continue;
        }
        if (context.isRebuild()) {
            clearResCache(facet, context);
        }
        final AndroidPlatform platform = facet.getConfiguration().getAndroidPlatform();
        final int platformToolsRevision = platform != null ? platform.getSdkData().getPlatformToolsRevision() : -1;
        LOG.debug("Platform-tools revision for module " + module.getName() + " is " + platformToolsRevision);
        if (!facet.isAppProject()) {
            if (platformToolsRevision >= 0 && platformToolsRevision <= 7) {
                LOG.debug("Excluded sources of module " + module.getName());
                excludeAllSourceRoots(module, configuration, addedEntries);
            } else {
                // todo: support this by project converter to use on compile-server
                unexcludeAllSourceRoots(facet, configuration);
            }
        }
    }
    if (addedEntries.size() > 0) {
        LOG.debug("Files excluded by Android: " + addedEntries.size());
        project.getMessageBus().connect().subscribe(CompilerTopics.COMPILATION_STATUS, new MyCompilationStatusListener(project, addedEntries));
    }
    return true;
}
Also used : Project(com.intellij.openapi.project.Project) ExcludesConfiguration(com.intellij.openapi.compiler.options.ExcludesConfiguration) ExcludeEntryDescription(com.intellij.openapi.compiler.options.ExcludeEntryDescription) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) HashSet(com.intellij.util.containers.hash.HashSet)

Example 15 with HashSet

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

the class LibraryJarUsagesCollector method getProjectUsages.

@NotNull
@Override
public Set<UsageDescriptor> getProjectUsages(@NotNull final Project project) throws CollectUsagesException {
    final LibraryJarDescriptor[] descriptors = LibraryJarStatisticsService.getInstance().getTechnologyDescriptors();
    final Set<UsageDescriptor> result = new HashSet<>(descriptors.length);
    ApplicationManager.getApplication().runReadAction(() -> {
        for (LibraryJarDescriptor descriptor : descriptors) {
            String className = descriptor.myClass;
            if (className == null)
                continue;
            PsiClass[] psiClasses = JavaPsiFacade.getInstance(project).findClasses(className, ProjectScope.getLibrariesScope(project));
            for (PsiClass psiClass : psiClasses) {
                if (psiClass == null)
                    continue;
                VirtualFile jarFile = JarFileSystem.getInstance().getLocalVirtualFileFor(psiClass.getContainingFile().getVirtualFile());
                if (jarFile == null)
                    continue;
                String version = getVersionByJarManifest(jarFile);
                if (version == null) {
                    version = getVersionByJarFileName(jarFile.getName());
                }
                if (version == null || !StringUtil.containsChar(version, '.')) {
                    continue;
                }
                result.add(new UsageDescriptor(descriptor.myName + "_" + version, 1));
            }
        }
    });
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiClass(com.intellij.psi.PsiClass) UsageDescriptor(com.intellij.internal.statistic.beans.UsageDescriptor) HashSet(com.intellij.util.containers.hash.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

HashSet (com.intellij.util.containers.hash.HashSet)27 Project (com.intellij.openapi.project.Project)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)9 NotNull (org.jetbrains.annotations.NotNull)6 Nullable (org.jetbrains.annotations.Nullable)5 PsiElement (com.intellij.psi.PsiElement)4 XmlFile (com.intellij.psi.xml.XmlFile)4 Set (java.util.Set)4 Ref (com.intellij.openapi.util.Ref)3 ContainerUtil (com.intellij.util.containers.ContainerUtil)3 UsageDescriptor (com.intellij.internal.statistic.beans.UsageDescriptor)2 ExcludeEntryDescription (com.intellij.openapi.compiler.options.ExcludeEntryDescription)2 Module (com.intellij.openapi.module.Module)2 StringUtil (com.intellij.openapi.util.text.StringUtil)2 PsiClass (com.intellij.psi.PsiClass)2 PsiFile (com.intellij.psi.PsiFile)2 XmlTag (com.intellij.psi.xml.XmlTag)2 Function (com.intellij.util.Function)2 Processor (com.intellij.util.Processor)2 SmartList (com.intellij.util.SmartList)2