Search in sources :

Example 86 with HashSet

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

the class ResourceManager method getIds.

@NotNull
public Collection<String> getIds(boolean declarationsOnly) {
    if (myProject.isDisposed()) {
        return Collections.emptyList();
    }
    final GlobalSearchScope scope = GlobalSearchScope.allScope(myProject);
    final FileBasedIndex index = FileBasedIndex.getInstance();
    final Map<VirtualFile, Set<String>> file2idEntries = new HashMap<VirtualFile, Set<String>>();
    index.processValues(AndroidIdIndex.INDEX_ID, AndroidIdIndex.MARKER, null, new FileBasedIndex.ValueProcessor<Set<String>>() {

        @Override
        public boolean process(@NotNull VirtualFile file, Set<String> value) {
            file2idEntries.put(file, value);
            return true;
        }
    }, scope);
    final Set<String> result = new HashSet<String>();
    for (VirtualFile resSubdir : getResourceSubdirsToSearchIds()) {
        for (VirtualFile resFile : resSubdir.getChildren()) {
            final Set<String> idEntries = file2idEntries.get(resFile);
            if (idEntries != null) {
                for (String idEntry : idEntries) {
                    if (idEntry.startsWith("+")) {
                        idEntry = idEntry.substring(1);
                    } else if (declarationsOnly) {
                        continue;
                    }
                    if (isResourcePublic(ResourceType.ID.getName(), idEntry)) {
                        result.add(idEntry);
                    }
                }
            }
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HashSet(com.intellij.util.containers.HashSet) ImmutableSet(com.google.common.collect.ImmutableSet) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) HashMap(com.intellij.util.containers.HashMap) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 87 with HashSet

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

the class AnalysisContentsDelegate method performAnalysis.

/**
   * This method is responsible for resetting the results panel, messaging the main window to perform the analysis, and
   * collecting/displaying the results.
   */
public void performAnalysis() {
    myCanRunAnalysis = false;
    UsageTracker.getInstance().log(AndroidStudioEvent.newBuilder().setCategory(EventCategory.PROFILING).setKind(EventKind.PROFILING_ANALYSIS_RUN));
    final DefaultTreeModel model = (DefaultTreeModel) myResultsTree.getModel();
    final DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
    root.removeAllChildren();
    myCategoryNodes.clear();
    Set<AnalysisReport.Listener> singletonListener = Collections.<AnalysisReport.Listener>singleton(new AnalysisReport.Listener() {

        @Override
        public void onResultsAdded(@NonNull final List<AnalysisResultEntry<?>> entries) {
            UIUtil.invokeLaterIfNeeded(new Runnable() {

                @Override
                public void run() {
                    boolean rootChanged = false;
                    Set<DefaultMutableTreeNode> changedCategories = new HashSet<DefaultMutableTreeNode>();
                    for (AnalysisResultEntry<?> entry : entries) {
                        String category = entry.getCategory();
                        DefaultMutableTreeNode categoryNode;
                        if (!myCategoryNodes.containsKey(category)) {
                            categoryNode = new DefaultMutableTreeNode(new String(category));
                            myCategoryNodes.put(category, categoryNode);
                            root.add(categoryNode);
                            rootChanged = true;
                        } else {
                            categoryNode = myCategoryNodes.get(category);
                        }
                        DefaultMutableTreeNode node = myCapturePanel.getContentsDelegate().getNodeForEntry(categoryNode.getChildCount(), entry);
                        if (node != null) {
                            changedCategories.add(categoryNode);
                            categoryNode.add(node);
                        }
                    }
                    if (rootChanged) {
                        model.nodeStructureChanged(root);
                    } else {
                        for (DefaultMutableTreeNode categoryNode : changedCategories) {
                            model.nodeStructureChanged(categoryNode);
                        }
                    }
                }
            });
        }

        @Override
        public void onAnalysisComplete() {
        }

        @Override
        public void onAnalysisCancelled() {
        }
    });
    myCapturePanel.performAnalysis(myEnabledTasks, singletonListener);
}
Also used : ItemListener(java.awt.event.ItemListener) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) AnalysisReport(com.android.tools.perflib.analyzer.AnalysisReport) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) AnalysisResultEntry(com.android.tools.perflib.analyzer.AnalysisResultEntry) HashSet(com.intellij.util.containers.HashSet)

Example 88 with HashSet

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

the class AndroidCompletionContributor method addDesignTimeAttributes.

/**
   * For every regular layout element attribute, add it with "tools:" prefix
   * (or whatever user uses for tools namespace)
   * <p/>
   * <a href="https://developer.android.com/studio/write/tool-attributes.html#design-time_view_attributes">Designtime attributes docs</a>
   */
private static void addDesignTimeAttributes(@NotNull final String namespacePrefix, @NotNull final PsiElement psiElement, @NotNull final AndroidFacet facet, @NotNull final XmlAttribute attribute, @NotNull final CompletionResultSet resultSet) {
    final XmlTag tag = attribute.getParent();
    final DomElement element = DomManager.getDomManager(tag.getProject()).getDomElement(tag);
    final Set<XmlName> registeredAttributes = new HashSet<>();
    if (element instanceof LayoutElement) {
        AttributeProcessingUtil.processLayoutAttributes(facet, tag, (LayoutElement) element, registeredAttributes, (xmlName, attrDef, parentStyleableName) -> {
            if (SdkConstants.ANDROID_URI.equals(xmlName.getNamespaceKey())) {
                final String localName = xmlName.getLocalName();
                // Lookup string is something that would be inserted when attribute is completed, so we want to use
                // local name as an argument of .create(), otherwise we'll end up with getting completions like
                // "tools:tools:src". However, we want to show "tools:" prefix in the completion list, and for that
                // .withPresentableText is used
                final LookupElementBuilder lookupElement = LookupElementBuilder.create(psiElement, localName).withInsertHandler(XmlAttributeInsertHandler.INSTANCE).withPresentableText(namespacePrefix + ":" + localName);
                resultSet.addElement(lookupElement);
            }
            return null;
        });
    }
}
Also used : LayoutElement(org.jetbrains.android.dom.layout.LayoutElement) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) HashSet(com.intellij.util.containers.HashSet)

Example 89 with HashSet

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

the class GradleBuildModel method appliedPlugins.

@NotNull
public List<GradleNotNullValue<String>> appliedPlugins() {
    ApplyDslElement applyDslElement = myGradleDslFile.getPropertyElement(APPLY_BLOCK_NAME, ApplyDslElement.class);
    if (applyDslElement == null) {
        return ImmutableList.of();
    }
    List<GradleNotNullValue<String>> listProperty = applyDslElement.getListProperty(PLUGIN, String.class);
    if (listProperty == null) {
        return ImmutableList.of();
    }
    List<GradleNotNullValue<String>> plugins = new ArrayList<>();
    Set<String> pluginValues = new HashSet<>();
    for (GradleNotNullValue<String> plugin : listProperty) {
        if (pluginValues.add(plugin.value())) {
            // Avoid duplicate plugin entries.
            plugins.add(plugin);
        }
    }
    for (GradleDslExpressionMap toBeAppliedPlugin : myToBeAppliedPlugins) {
        GradleNullableValue<String> plugin = toBeAppliedPlugin.getLiteralProperty(PLUGIN, String.class);
        assert plugin instanceof GradleNotNullValue;
        if (pluginValues.add(plugin.value())) {
            // Avoid duplicate plugin entries.
            plugins.add((GradleNotNullValue<String>) plugin);
        }
    }
    return plugins;
}
Also used : GradleDslExpressionMap(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpressionMap) ApplyDslElement(com.android.tools.idea.gradle.dsl.parser.apply.ApplyDslElement) ArrayList(java.util.ArrayList) GradleNotNullValue(com.android.tools.idea.gradle.dsl.model.values.GradleNotNullValue) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 90 with HashSet

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

the class EditLogFilterDialog method parseExistingMessagesIfNecessary.

private void parseExistingMessagesIfNecessary() {
    if (myExistingMessagesParsed) {
        return;
    }
    myExistingMessagesParsed = true;
    final StringBuffer document = myView.getLogConsole().getOriginalDocument();
    if (document == null) {
        return;
    }
    final Set<String> pidSet = new HashSet<>();
    final String[] lines = StringUtil.splitByLines(document.toString());
    for (String line : lines) {
        LogCatMessage message = AndroidLogcatFormatter.parseMessage(line);
        pidSet.add(Integer.toString(message.getPid()));
    }
    myUsedPids = Lists.newArrayList(pidSet);
}
Also used : LogCatMessage(com.android.ddmlib.logcat.LogCatMessage) 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