use of com.intellij.util.containers.HashSet in project android by JetBrains.
the class AndroidPropertyFilesUpdater method updateDependenciesInPropertyFile.
private static void updateDependenciesInPropertyFile(@NotNull final PropertiesFile projectProperties, @Nullable final Pair<Properties, VirtualFile> localProperties, @NotNull final VirtualFile[] dependencies, @NotNull List<Runnable> changes) {
final VirtualFile vFile = projectProperties.getVirtualFile();
if (vFile == null) {
return;
}
final Set<VirtualFile> localDependencies = localProperties != null ? ImportDependenciesUtil.getLibDirs(localProperties) : Collections.<VirtualFile>emptySet();
final VirtualFile baseDir = vFile.getParent();
final String baseDirPath = baseDir.getPath();
final List<String> newDepValues = new ArrayList<String>();
for (VirtualFile dependency : dependencies) {
if (!localDependencies.contains(dependency)) {
final String relPath = FileUtil.getRelativePath(baseDirPath, dependency.getPath(), '/');
final String value = relPath != null ? relPath : dependency.getPath();
newDepValues.add(value);
}
}
final Set<String> oldDepValues = new HashSet<String>();
for (IProperty property : projectProperties.getProperties()) {
final String name = property.getName();
if (name != null && name.startsWith(AndroidUtils.ANDROID_LIBRARY_REFERENCE_PROPERTY_PREFIX)) {
oldDepValues.add(property.getValue());
}
}
if (!new HashSet<String>(newDepValues).equals(oldDepValues)) {
changes.add(new Runnable() {
@Override
public void run() {
for (IProperty property : projectProperties.getProperties()) {
final String name = property.getName();
if (name != null && name.startsWith(AndroidUtils.ANDROID_LIBRARY_REFERENCE_PROPERTY_PREFIX)) {
property.getPsiElement().delete();
}
}
for (int i = 0; i < newDepValues.size(); i++) {
final String value = newDepValues.get(i);
projectProperties.addProperty(AndroidUtils.ANDROID_LIBRARY_REFERENCE_PROPERTY_PREFIX + Integer.toString(i + 1), value);
}
}
});
}
}
use of com.intellij.util.containers.HashSet in project android by JetBrains.
the class AndroidUtils method getSetWithBackwardDependencies.
@NotNull
public static Set<Module> getSetWithBackwardDependencies(@NotNull Collection<Module> modules) {
if (modules.isEmpty())
return Collections.emptySet();
Module next = modules.iterator().next();
Graph<Module> graph = ModuleManager.getInstance(next.getProject()).moduleGraph();
final Set<Module> set = new HashSet<>();
for (Module module : modules) {
GraphAlgorithms.getInstance().collectOutsRecursively(graph, module, set);
}
return set;
}
use of com.intellij.util.containers.HashSet in project android by JetBrains.
the class AndroidUtils method computePackageName.
@Nullable
public static String computePackageName(@NotNull Module module, VirtualFile file) {
final Set<VirtualFile> sourceRoots = new HashSet<>();
Collections.addAll(sourceRoots, ModuleRootManager.getInstance(module).getSourceRoots());
final VirtualFile projectDir = module.getProject().getBaseDir();
final List<String> packages = new ArrayList<>();
file = file.getParent();
while (file != null && !Comparing.equal(projectDir, file) && !sourceRoots.contains(file)) {
packages.add(file.getName());
file = file.getParent();
}
if (file != null && sourceRoots.contains(file)) {
final StringBuilder packageName = new StringBuilder();
for (int i = packages.size() - 1; i >= 0; i--) {
packageName.append(packages.get(i));
if (i > 0)
packageName.append('.');
}
return packageName.toString();
}
return null;
}
use of com.intellij.util.containers.HashSet in project android by JetBrains.
the class AndroidRunSdkToolAction method doAction.
public void doAction(@NotNull Project project) {
if (IdeInfo.getInstance().isAndroidStudio()) {
File androidHome = IdeSdks.getInstance().getAndroidSdkPath();
if (androidHome != null) {
doRunTool(project, androidHome.getPath());
return;
}
}
// Gradle project.
try {
LocalProperties localProperties = new LocalProperties(project);
File androidSdkPath = localProperties.getAndroidSdkPath();
if (androidSdkPath != null) {
doRunTool(project, androidSdkPath.getPath());
return;
}
} catch (IOException ignored) {
LOG.info(String.format("Unable to read local.properties file from project '%1$s'", project.getName()), ignored);
}
List<AndroidFacet> facets = ProjectFacetManager.getInstance(project).getFacets(AndroidFacet.ID);
assert facets.size() > 0;
Set<String> sdkSet = new HashSet<>();
for (AndroidFacet facet : facets) {
AndroidSdkData sdkData = facet.getConfiguration().getAndroidSdk();
if (sdkData != null) {
sdkSet.add(sdkData.getLocation().getPath());
}
}
if (sdkSet.size() == 0) {
Messages.showErrorDialog(project, AndroidBundle.message("specify.platform.error"), CommonBundle.getErrorTitle());
return;
}
String sdkPath = sdkSet.iterator().next();
if (sdkSet.size() > 1) {
String[] sdks = ArrayUtil.toStringArray(sdkSet);
int index = Messages.showChooseDialog(project, AndroidBundle.message("android.choose.sdk.label"), AndroidBundle.message("android.choose.sdk.title"), Messages.getQuestionIcon(), sdks, sdkPath);
if (index < 0) {
return;
}
sdkPath = sdks[index];
}
doRunTool(project, sdkPath);
}
use of com.intellij.util.containers.HashSet in project android by JetBrains.
the class AndroidInlineLayoutProcessor method findUsages.
@NotNull
@Override
protected UsageInfo[] findUsages() {
if (myUsageElement != null) {
return new UsageInfo[] { new UsageInfo(myUsageElement) };
}
final Set<UsageInfo> usages = new HashSet<UsageInfo>();
AndroidInlineUtil.addReferences(myLayoutFile, usages);
for (PsiField field : AndroidResourceUtil.findResourceFieldsForFileResource(myLayoutFile, false)) {
AndroidInlineUtil.addReferences(field, usages);
}
return usages.toArray(new UsageInfo[usages.size()]);
}
Aggregations