use of com.intellij.util.containers.HashSet in project android by JetBrains.
the class AvdComboBox method doUpdateAvds.
private void doUpdateAvds() {
final Module module = getModule();
if (module == null || module.isDisposed()) {
return;
}
final AndroidFacet facet = AndroidFacet.getInstance(module);
final IdDisplay[] newAvds;
if (facet != null) {
final Set<String> filteringSet = new HashSet<String>();
if (myShowNotLaunchedOnly) {
final AndroidDebugBridge debugBridge = AndroidSdkUtils.getDebugBridge(facet.getModule().getProject());
if (debugBridge != null) {
for (IDevice device : debugBridge.getDevices()) {
final String avdName = device.getAvdName();
if (avdName != null && avdName.length() > 0) {
filteringSet.add(avdName);
}
}
}
}
final List<IdDisplay> newAvdList = new ArrayList<IdDisplay>();
if (myAddEmptyElement) {
newAvdList.add(IdDisplay.create("", ""));
}
for (AvdInfo avd : facet.getAllAvds()) {
String displayName = avd.getProperties().get(AvdManager.AVD_INI_DISPLAY_NAME);
final String avdName = displayName == null || displayName.isEmpty() ? avd.getName() : displayName;
if (!filteringSet.contains(avdName)) {
newAvdList.add(IdDisplay.create(avd.getName(), avdName));
}
}
newAvds = ArrayUtil.toObjectArray(newAvdList, IdDisplay.class);
} else {
newAvds = new IdDisplay[0];
}
if (!Arrays.equals(myOldAvds, newAvds)) {
myOldAvds = newAvds;
final Object selected = getComboBox().getSelectedItem();
getComboBox().setModel(new DefaultComboBoxModel(newAvds));
getComboBox().setSelectedItem(selected);
}
}
use of com.intellij.util.containers.HashSet in project android by JetBrains.
the class AndroidMissingOnClickHandlerInspection method findRelatedActivitiesForMenu.
@NotNull
private static Set<PsiClass> findRelatedActivitiesForMenu(@NotNull XmlFile file, @NotNull AndroidFacet facet) {
final String resType = ResourceType.MENU.getName();
final String resourceName = AndroidCommonUtils.getResourceName(resType, file.getName());
final PsiField[] fields = AndroidResourceUtil.findResourceFields(facet, resType, resourceName, true);
if (fields.length == 0) {
return Collections.emptySet();
}
final Module module = facet.getModule();
final GlobalSearchScope scope = module.getModuleScope(false);
final PsiClass activityClass = findActivityClass(module);
if (activityClass == null) {
return Collections.emptySet();
}
final Set<PsiClass> result = new HashSet<PsiClass>();
ReferencesSearch.search(fields[0], scope).forEach(new Processor<PsiReference>() {
@Override
public boolean process(PsiReference reference) {
final PsiElement element = reference.getElement();
if (element == null) {
return true;
}
final PsiClass aClass = PsiTreeUtil.getParentOfType(element, PsiClass.class);
if (aClass != null && !result.contains(aClass) && aClass.isInheritor(activityClass, true)) {
result.add(aClass);
}
return true;
}
});
return result;
}
use of com.intellij.util.containers.HashSet in project android by JetBrains.
the class AndroidProcessChooserDialog method collectAllProcessNames.
@NotNull
private static Set<String> collectAllProcessNames(Project project) {
final List<AndroidFacet> facets = ProjectFacetManager.getInstance(project).getFacets(AndroidFacet.ID);
final Set<String> result = new HashSet<String>();
for (AndroidFacet facet : facets) {
final String packageName = AndroidCompileUtil.getAaptManifestPackage(facet);
if (packageName != null) {
result.add(packageName.toLowerCase());
}
final Manifest manifest = facet.getManifest();
if (manifest != null) {
final XmlElement xmlElement = manifest.getXmlElement();
if (xmlElement != null) {
collectProcessNames(xmlElement, result);
}
}
final AndroidModel androidModel = facet.getAndroidModel();
if (androidModel != null) {
result.addAll(androidModel.getAllApplicationIds());
}
}
return result;
}
use of com.intellij.util.containers.HashSet in project android by JetBrains.
the class AndroidExtractStyleAction method doExtractStyle.
@Nullable
public static String doExtractStyle(@NotNull Module module, @NotNull final XmlTag viewTag, final boolean addStyleAttributeToTag, @Nullable MyTestConfig testConfig) {
final PsiFile file = viewTag.getContainingFile();
if (file == null) {
return null;
}
final String dialogTitle = AndroidBundle.message("android.extract.style.title");
final String fileName = AndroidResourceUtil.getDefaultResourceFileName(ResourceType.STYLE);
assert fileName != null;
final List<String> dirNames = Collections.singletonList(ResourceFolderType.VALUES.getName());
final List<XmlAttribute> extractableAttributes = getExtractableAttributes(viewTag);
final Project project = module.getProject();
if (extractableAttributes.size() == 0) {
AndroidUtils.reportError(project, "The tag doesn't contain any attributes that can be extracted", dialogTitle);
return null;
}
final LayoutViewElement viewElement = getLayoutViewElement(viewTag);
assert viewElement != null;
final ResourceValue parentStyleValue = viewElement.getStyle().getValue();
final String parentStyle;
boolean supportImplicitParent = false;
if (parentStyleValue != null) {
parentStyle = parentStyleValue.getResourceName();
if (ResourceType.STYLE != parentStyleValue.getType() || parentStyle == null || parentStyle.length() == 0) {
AndroidUtils.reportError(project, "Invalid parent style reference " + parentStyleValue.toString(), dialogTitle);
return null;
}
supportImplicitParent = parentStyleValue.getNamespace() == null;
} else {
parentStyle = null;
}
final String styleName;
final List<XmlAttribute> styledAttributes;
final VirtualFile chosenDirectory;
final boolean searchStyleApplications;
if (testConfig == null) {
final ExtractStyleDialog dialog = new ExtractStyleDialog(module, fileName, supportImplicitParent ? parentStyle : null, dirNames, extractableAttributes);
dialog.setTitle(dialogTitle);
if (!dialog.showAndGet()) {
return null;
}
searchStyleApplications = dialog.isToSearchStyleApplications();
chosenDirectory = dialog.getResourceDirectory();
if (chosenDirectory == null) {
AndroidUtils.reportError(project, AndroidBundle.message("check.resource.dir.error", module.getName()));
return null;
}
styledAttributes = dialog.getStyledAttributes();
styleName = dialog.getStyleName();
} else {
testConfig.validate(extractableAttributes);
chosenDirectory = testConfig.getResourceDirectory();
styleName = testConfig.getStyleName();
final Set<String> attrsToExtract = new HashSet<String>(Arrays.asList(testConfig.getAttributesToExtract()));
styledAttributes = new ArrayList<XmlAttribute>();
for (XmlAttribute attribute : extractableAttributes) {
if (attrsToExtract.contains(attribute.getName())) {
styledAttributes.add(attribute);
}
}
searchStyleApplications = false;
}
final boolean[] success = { false };
final Ref<Style> createdStyleRef = Ref.create();
final boolean finalSupportImplicitParent = supportImplicitParent;
new WriteCommandAction(project, "Extract Android Style '" + styleName + "'", file) {
@Override
protected void run(@NotNull final Result result) throws Throwable {
final List<XmlAttribute> attributesToDelete = new ArrayList<XmlAttribute>();
if (!AndroidResourceUtil.createValueResource(project, chosenDirectory, styleName, null, ResourceType.STYLE, fileName, dirNames, new Processor<ResourceElement>() {
@Override
public boolean process(ResourceElement element) {
assert element instanceof Style;
final Style style = (Style) element;
createdStyleRef.set(style);
for (XmlAttribute attribute : styledAttributes) {
if (SdkConstants.NS_RESOURCES.equals(attribute.getNamespace())) {
final StyleItem item = style.addItem();
item.getName().setStringValue("android:" + attribute.getLocalName());
item.setStringValue(attribute.getValue());
attributesToDelete.add(attribute);
}
}
if (parentStyleValue != null && (!finalSupportImplicitParent || !styleName.startsWith(parentStyle + "."))) {
final String aPackage = parentStyleValue.getNamespace();
style.getParentStyle().setStringValue((aPackage != null ? aPackage + ":" : "") + parentStyle);
}
return true;
}
})) {
return;
}
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
for (XmlAttribute attribute : attributesToDelete) {
attribute.delete();
}
if (addStyleAttributeToTag) {
final LayoutViewElement viewElement = getLayoutViewElement(viewTag);
assert viewElement != null;
viewElement.getStyle().setStringValue("@style/" + styleName);
}
}
});
success[0] = true;
}
@Override
protected UndoConfirmationPolicy getUndoConfirmationPolicy() {
return UndoConfirmationPolicy.REQUEST_CONFIRMATION;
}
}.execute();
if (!success[0]) {
return null;
}
final Style createdStyle = createdStyleRef.get();
final XmlTag createdStyleTag = createdStyle != null ? createdStyle.getXmlTag() : null;
if (createdStyleTag != null) {
final AndroidFindStyleApplicationsAction.MyStyleData createdStyleData = AndroidFindStyleApplicationsAction.getStyleData(createdStyleTag);
if (createdStyleData != null && searchStyleApplications) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
AndroidFindStyleApplicationsAction.doRefactoringForTag(createdStyleTag, createdStyleData, file, null);
}
});
}
}
return styleName;
}
use of com.intellij.util.containers.HashSet in project android by JetBrains.
the class AndroidFacetImporterBase method importExternalAarDependency.
private static void importExternalAarDependency(@NotNull MavenArtifact artifact, @NotNull MavenProject mavenProject, @NotNull MavenProjectsTree mavenTree, @NotNull MavenRootModelAdapter rootModelAdapter, @NotNull IdeModifiableModelsProvider modelsProvider, @NotNull Project project, @NotNull List<MavenProjectsProcessorTask> postTasks) {
final Library aarLibrary = rootModelAdapter.findLibrary(artifact);
if (aarLibrary == null) {
return;
}
final MavenId mavenId = artifact.getMavenId();
Map<MavenId, String> importedAarArtifacts = project.getUserData(IMPORTED_AAR_ARTIFACTS);
if (importedAarArtifacts == null) {
importedAarArtifacts = new HashMap<MavenId, String>();
project.putUserData(IMPORTED_AAR_ARTIFACTS, importedAarArtifacts);
postTasks.add(new MavenProjectsProcessorTask() {
@Override
public void perform(Project project, MavenEmbeddersManager embeddersManager, MavenConsole console, MavenProgressIndicator indicator) throws MavenProcessCanceledException {
project.putUserData(IMPORTED_AAR_ARTIFACTS, null);
}
});
}
final List<MavenProject> allProjects = mavenTree.getProjects();
String aarDirPath = importedAarArtifacts.get(mavenId);
if (aarDirPath == null) {
final String aarDirName = AndroidMavenUtil.getMavenIdStringForFileName(mavenId);
aarDirPath = findExtractedAarDirectory(allProjects, aarDirName);
if (aarDirPath == null) {
final String genDirPath = AndroidMavenUtil.computePathForGenExternalApklibsDir(mavenId, mavenProject, allProjects);
if (genDirPath == null) {
return;
}
aarDirPath = genDirPath + "/" + aarDirName;
}
importedAarArtifacts.put(mavenId, aarDirPath);
extractArtifact(artifact.getPath(), aarDirPath, project, mavenProject.getName());
}
final Library.ModifiableModel aarLibModel = modelsProvider.getModifiableLibraryModel(aarLibrary);
final String classesJarPath = aarDirPath + "/" + SdkConstants.FN_CLASSES_JAR;
final String classesJarUrl = VirtualFileManager.constructUrl(JarFileSystem.PROTOCOL, classesJarPath) + JarFileSystem.JAR_SEPARATOR;
final String resDirUrl = VfsUtilCore.pathToUrl(aarDirPath + "/" + SdkConstants.FD_RES);
final Set<String> urlsToAdd = new HashSet<String>(Arrays.asList(classesJarUrl, resDirUrl));
collectJarsInAarLibsFolder(aarDirPath, urlsToAdd);
for (String url : aarLibModel.getUrls(OrderRootType.CLASSES)) {
if (!urlsToAdd.remove(url)) {
aarLibModel.removeRoot(url, OrderRootType.CLASSES);
}
}
for (String url : urlsToAdd) {
aarLibModel.addRoot(url, OrderRootType.CLASSES);
}
}
Aggregations