Search in sources :

Example 26 with Manifest

use of org.jetbrains.android.dom.manifest.Manifest in project android by JetBrains.

the class AndroidApplicationPackageRenameProcessor method renameElement.

@Override
public void renameElement(PsiElement element, String newName, UsageInfo[] usages, @Nullable RefactoringElementListener listener) throws IncorrectOperationException {
    if (element instanceof PsiPackage) {
        final Map<GenericAttributeValue, String> newAttrValues = new HashMap<GenericAttributeValue, String>();
        final Project project = element.getProject();
        final String oldPackageQName = ((PsiPackage) element).getQualifiedName();
        final String newPackageQName = PsiUtilCore.getQualifiedNameAfterRename(oldPackageQName, newName);
        for (Module module : ModuleManager.getInstance(project).getModules()) {
            final AndroidFacet facet = AndroidFacet.getInstance(module);
            final Manifest manifest = facet != null ? facet.getManifest() : null;
            if (manifest != null) {
                final XmlElement manifestElement = manifest.getXmlElement();
                final PsiFile manifestPsiFile = manifestElement != null ? manifestElement.getContainingFile() : null;
                if (manifestPsiFile instanceof XmlFile) {
                    final String basePackage = manifest.getPackage().getValue();
                    if (basePackage == null) {
                        continue;
                    }
                    processAllAttributesToUpdate((XmlFile) manifestPsiFile, basePackage, oldPackageQName, newPackageQName, new Processor<Pair<GenericAttributeValue, String>>() {

                        @Override
                        public boolean process(Pair<GenericAttributeValue, String> pair) {
                            newAttrValues.put(pair.getFirst(), pair.getSecond());
                            return true;
                        }
                    });
                }
            }
        }
        new RenamePsiPackageProcessor().renameElement(element, newName, usages, listener);
        for (Map.Entry<GenericAttributeValue, String> e : newAttrValues.entrySet()) {
            //noinspection unchecked
            e.getKey().setStringValue(e.getValue());
        }
        return;
    }
    final PsiFile file = element.getContainingFile();
    if (!(file instanceof XmlFile)) {
        return;
    }
    final Map<GenericAttributeValue, PsiClass> attr2class = buildAttr2ClassMap((XmlFile) file);
    new RenameXmlAttributeProcessor().renameElement(element, newName, usages, listener);
    for (Map.Entry<GenericAttributeValue, PsiClass> e : attr2class.entrySet()) {
        //noinspection unchecked
        e.getKey().setValue(e.getValue());
    }
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) HashMap(com.intellij.util.containers.HashMap) RenamePsiPackageProcessor(com.intellij.refactoring.rename.RenamePsiPackageProcessor) Manifest(org.jetbrains.android.dom.manifest.Manifest) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Project(com.intellij.openapi.project.Project) RenameXmlAttributeProcessor(com.intellij.refactoring.rename.RenameXmlAttributeProcessor) XmlElement(com.intellij.psi.xml.XmlElement) Module(com.intellij.openapi.module.Module) HashMap(com.intellij.util.containers.HashMap) Map(java.util.Map) GenericAttributeValue(com.intellij.util.xml.GenericAttributeValue) Pair(com.intellij.openapi.util.Pair)

Example 27 with Manifest

use of org.jetbrains.android.dom.manifest.Manifest in project android by JetBrains.

the class AbstractRegisterComponentAction method invoke.

@Override
public final void invoke(@NotNull Project project, @Nullable Editor editor, @Nullable PsiFile file) throws IncorrectOperationException {
    final PsiClass psiClass = editor == null ? null : extractClass(editor, file);
    if (psiClass == null) {
        return;
    }
    final AndroidFacet facet = AndroidFacet.getInstance(file);
    final Manifest manifest = facet == null ? null : facet.getManifest();
    if (manifest == null) {
        return;
    }
    final XmlElement element = manifest.getXmlElement();
    final PsiFile manifestFile = element == null ? null : element.getContainingFile();
    if (manifestFile == null) {
        return;
    }
    new WriteCommandAction.Simple(project, file, manifestFile) {

        @Override
        protected void run() throws Throwable {
            invoke(psiClass, manifest);
        }
    }.execute();
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) XmlElement(com.intellij.psi.xml.XmlElement) Manifest(org.jetbrains.android.dom.manifest.Manifest) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 28 with Manifest

use of org.jetbrains.android.dom.manifest.Manifest in project android by JetBrains.

the class AndroidActivityAliasCompletionContributor method doCollectActivityAliases.

private static void doCollectActivityAliases(@NotNull AndroidFacet facet, @NotNull Set<String> result) {
    final Manifest manifest = facet.getManifest();
    if (manifest == null) {
        return;
    }
    final String aPackage = manifest.getPackage().getStringValue();
    final Application application = manifest.getApplication();
    if (application == null) {
        return;
    }
    for (ActivityAlias activityAlias : application.getActivityAliases()) {
        String alias = activityAlias.getName().getStringValue();
        if (alias != null && alias.length() > 0) {
            if (!alias.startsWith(".")) {
                if (alias.indexOf('.') > 0) {
                    result.add(alias);
                }
                alias = "." + alias;
            }
            if (aPackage != null && aPackage.length() > 0 && StringUtil.commonPrefixLength(aPackage, alias) == 0) {
                result.add(aPackage + alias);
            }
        }
    }
}
Also used : ActivityAlias(org.jetbrains.android.dom.manifest.ActivityAlias) Manifest(org.jetbrains.android.dom.manifest.Manifest) Application(org.jetbrains.android.dom.manifest.Application)

Example 29 with Manifest

use of org.jetbrains.android.dom.manifest.Manifest in project android by JetBrains.

the class AndroidDataSourcePropertiesDialog method loadDatabases.

private void loadDatabases(@NotNull IDevice device) {
    myDatabaseMap.clear();
    final FileListingService service = device.getFileListingService();
    if (service == null)
        return;
    final Set<String> packages = new HashSet<String>();
    for (AndroidFacet facet : ProjectFacetManager.getInstance(myProject).getFacets(AndroidFacet.ID)) {
        final Manifest manifest = facet.getManifest();
        if (manifest != null) {
            final String aPackage = manifest.getPackage().getStringValue();
            if (aPackage != null && aPackage.length() > 0) {
                packages.add(aPackage);
            }
        }
    }
    if (packages.isEmpty())
        return;
    final long startTime = System.currentTimeMillis();
    boolean tooLong = false;
    for (String aPackage : packages) {
        myDatabaseMap.put(aPackage, tooLong ? Collections.<String>emptyList() : loadDatabases(device, aPackage));
        if (System.currentTimeMillis() - startTime > 4000) {
            tooLong = true;
        }
    }
}
Also used : FileListingService(com.android.ddmlib.FileListingService) Manifest(org.jetbrains.android.dom.manifest.Manifest) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) HashSet(com.intellij.util.containers.HashSet)

Aggregations

Manifest (org.jetbrains.android.dom.manifest.Manifest)29 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)14 Module (com.intellij.openapi.module.Module)10 Nullable (org.jetbrains.annotations.Nullable)7 XmlElement (com.intellij.psi.xml.XmlElement)6 HashSet (com.intellij.util.containers.HashSet)5 NotNull (org.jetbrains.annotations.NotNull)5 Project (com.intellij.openapi.project.Project)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 File (java.io.File)4 MergedManifest (com.android.tools.idea.model.MergedManifest)3 IOException (java.io.IOException)3 AndroidManifest (com.android.xml.AndroidManifest)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)2 Pair (com.intellij.openapi.util.Pair)2 PsiFile (com.intellij.psi.PsiFile)2 HashMap (com.intellij.util.containers.HashMap)2 GenericAttributeValue (com.intellij.util.xml.GenericAttributeValue)2 Application (org.jetbrains.android.dom.manifest.Application)2 ManifestElementWithRequiredName (org.jetbrains.android.dom.manifest.ManifestElementWithRequiredName)2