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;
}
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);
}
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;
});
}
}
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;
}
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);
}
Aggregations