Search in sources :

Example 1 with BuildType

use of com.android.builder.model.BuildType in project android by JetBrains.

the class MoveToDebugManifestQuickFix method apply.

@Override
public void apply(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull AndroidQuickfixContexts.Context context) {
    final XmlAttribute attribute = PsiTreeUtil.getParentOfType(startElement, XmlAttribute.class);
    if (attribute != null) {
        XmlTag parent = attribute.getParent();
        if (parent != null && parent.getName().equals(TAG_USES_PERMISSION)) {
            Module module = getModule(parent);
            assert MOCK_LOCATION_PERMISSION.equals(parent.getAttributeValue(ATTR_NAME, ANDROID_URI));
            parent.delete();
            if (module != null) {
                AndroidFacet facet = AndroidFacet.getInstance(module);
                if (facet != null) {
                    VirtualFile mainManifest = facet.getMainIdeaSourceProvider().getManifestFile();
                    // TODO: b/22928250
                    AndroidModuleModel androidModel = AndroidModuleModel.get(facet);
                    if (androidModel != null && mainManifest != null && mainManifest.getParent() != null && mainManifest.getParent().getParent() != null) {
                        final VirtualFile src = mainManifest.getParent().getParent();
                        for (BuildTypeContainer container : androidModel.getAndroidProject().getBuildTypes()) {
                            BuildType buildType = container.getBuildType();
                            if (buildType.isDebuggable()) {
                                addManifest(module, src, buildType.getName());
                                return;
                            }
                        }
                        Messages.showErrorDialog(module.getProject(), "Did not find a debug build type", "Move Permission");
                    }
                }
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlAttribute(com.intellij.psi.xml.XmlAttribute) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) BuildType(com.android.builder.model.BuildType) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) XmlTag(com.intellij.psi.xml.XmlTag) BuildTypeContainer(com.android.builder.model.BuildTypeContainer)

Aggregations

BuildType (com.android.builder.model.BuildType)1 BuildTypeContainer (com.android.builder.model.BuildTypeContainer)1 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)1 Module (com.intellij.openapi.module.Module)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 XmlAttribute (com.intellij.psi.xml.XmlAttribute)1 XmlTag (com.intellij.psi.xml.XmlTag)1 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)1