Search in sources :

Example 91 with HashSet

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);
                }
            }
        });
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IProperty(com.intellij.lang.properties.IProperty) HashSet(com.intellij.util.containers.HashSet)

Example 92 with HashSet

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;
}
Also used : Module(com.intellij.openapi.module.Module) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 93 with HashSet

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) RelativePoint(com.intellij.ui.awt.RelativePoint) HashSet(com.intellij.util.containers.HashSet) Nullable(org.jetbrains.annotations.Nullable)

Example 94 with HashSet

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);
}
Also used : AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) IOException(java.io.IOException) File(java.io.File) LocalProperties(com.android.tools.idea.gradle.util.LocalProperties) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) HashSet(com.intellij.util.containers.HashSet)

Example 95 with HashSet

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()]);
}
Also used : PsiField(com.intellij.psi.PsiField) UsageInfo(com.intellij.usageView.UsageInfo) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

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