Search in sources :

Example 1 with LayoutDomFileDescription

use of org.jetbrains.android.dom.layout.LayoutDomFileDescription in project android by JetBrains.

the class AndroidXmlFormattingModelBuilder method getContextSpecificSettings.

@Nullable
private static ContextSpecificSettingsProviders.Provider getContextSpecificSettings(PsiElement context) {
    final PsiFile file = context.getContainingFile();
    if (!(file instanceof XmlFile) || AndroidFacet.getInstance(file) == null) {
        return null;
    }
    final DomFileDescription<?> description = DomManager.getDomManager(context.getProject()).getDomFileDescription((XmlFile) file);
    if (description instanceof LayoutDomFileDescription) {
        return ContextSpecificSettingsProviders.LAYOUT;
    } else if (description instanceof ManifestDomFileDescription) {
        return ContextSpecificSettingsProviders.MANIFEST;
    } else if (description instanceof ResourcesDomFileDescription || description instanceof DrawableStateListDomFileDescription || description instanceof ColorDomFileDescription) {
        return ContextSpecificSettingsProviders.VALUE_RESOURCE_FILE;
    } else if (description instanceof AndroidResourceDomFileDescription) {
        return ContextSpecificSettingsProviders.OTHER;
    }
    return null;
}
Also used : ManifestDomFileDescription(org.jetbrains.android.dom.manifest.ManifestDomFileDescription) LayoutDomFileDescription(org.jetbrains.android.dom.layout.LayoutDomFileDescription) XmlFile(com.intellij.psi.xml.XmlFile) AndroidResourceDomFileDescription(org.jetbrains.android.dom.AndroidResourceDomFileDescription) PsiFile(com.intellij.psi.PsiFile) ColorDomFileDescription(org.jetbrains.android.dom.color.ColorDomFileDescription) ResourcesDomFileDescription(org.jetbrains.android.dom.resources.ResourcesDomFileDescription) DrawableStateListDomFileDescription(org.jetbrains.android.dom.drawable.fileDescriptions.DrawableStateListDomFileDescription) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with LayoutDomFileDescription

use of org.jetbrains.android.dom.layout.LayoutDomFileDescription in project android by JetBrains.

the class AndroidMissingOnClickHandlerInspection method checkFile.

@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
    if (!(file instanceof XmlFile)) {
        return ProblemDescriptor.EMPTY_ARRAY;
    }
    final AndroidFacet facet = AndroidFacet.getInstance(file);
    if (facet == null) {
        return ProblemDescriptor.EMPTY_ARRAY;
    }
    final DomFileDescription<?> description = DomManager.getDomManager(file.getProject()).getDomFileDescription((XmlFile) file);
    if (!(description instanceof LayoutDomFileDescription) && !(description instanceof MenuDomFileDescription)) {
        return ProblemDescriptor.EMPTY_ARRAY;
    }
    final Collection<PsiClass> activities = findRelatedActivities((XmlFile) file, facet, description);
    final MyVisitor visitor = new MyVisitor(manager, isOnTheFly, activities);
    file.accept(visitor);
    return visitor.myResult.toArray(new ProblemDescriptor[visitor.myResult.size()]);
}
Also used : LayoutDomFileDescription(org.jetbrains.android.dom.layout.LayoutDomFileDescription) XmlFile(com.intellij.psi.xml.XmlFile) MenuDomFileDescription(org.jetbrains.android.dom.menu.MenuDomFileDescription) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 3 with LayoutDomFileDescription

use of org.jetbrains.android.dom.layout.LayoutDomFileDescription in project android by JetBrains.

the class RtlSupportProcessor method performRefactoringForLayoutFile.

private void performRefactoringForLayoutFile(@NotNull final RtlRefactoringUsageInfo usageInfo) {
    final PsiElement element = usageInfo.getElement();
    assert element != null;
    final XmlAttribute attribute = (XmlAttribute) element;
    final int minSdk = usageInfo.getAndroidManifestMinSdkVersion();
    if (!usageInfo.isCreateV17()) {
        updateAttributeForElement(attribute, minSdk);
    } else {
        // We need first to create the v17 layout file, so first get our initial layout file
        final PsiFile psiFile = element.getContainingFile();
        final VirtualFile layoutFile = psiFile.getVirtualFile();
        assert layoutFile != null;
        final VirtualFile layoutDir = layoutFile.getParent();
        assert layoutDir != null;
        final VirtualFile layoutV17Dir = getLayoutV17(layoutDir, true);
        assert layoutV17Dir != null;
        final String layoutFileName = layoutFile.getName();
        // Create the v17 file if needed (should be done only once)
        if (layoutV17Dir.findChild(layoutFileName) == null) {
            ApplicationManager.getApplication().runWriteAction(new Runnable() {

                @Override
                public void run() {
                    try {
                        layoutFile.copy(this, layoutV17Dir, layoutFileName);
                    } catch (IOException e) {
                        LOG.error("Cannot copy layout file " + quote(layoutFileName) + " from " + quote(layoutDir.getName()) + " directory to " + quote(layoutV17Dir.getName()) + " directory");
                    }
                }
            });
        }
        final VirtualFile layoutV17File = layoutV17Dir.findChild(layoutFileName);
        assert layoutV17File != null;
        final XmlFile xmlV17File = (XmlFile) PsiManager.getInstance(myProject).findFile(layoutV17File);
        assert xmlV17File != null;
        LOG.info("Processing refactoring for attribute: " + attribute.getName() + " into file: " + layoutV17File.getPath());
        if (DomManager.getDomManager(myProject).getDomFileDescription((XmlFile) xmlV17File) instanceof LayoutDomFileDescription) {
            xmlV17File.accept(new XmlRecursiveElementVisitor() {

                @Override
                public void visitXmlTag(XmlTag tag) {
                    super.visitXmlTag(tag);
                    final XmlAttribute attribute = tag.getAttribute(((XmlAttribute) element).getName());
                    if (attribute == null) {
                        return;
                    }
                    updateAttributeForElement(attribute, minSdk);
                }
            });
        }
        layoutV17File.refresh(true, /* asynchronous */
        false);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LayoutDomFileDescription(org.jetbrains.android.dom.layout.LayoutDomFileDescription) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlFile(com.intellij.psi.xml.XmlFile) IOException(java.io.IOException) XmlTag(com.intellij.psi.xml.XmlTag)

Example 4 with LayoutDomFileDescription

use of org.jetbrains.android.dom.layout.LayoutDomFileDescription in project android by JetBrains.

the class AndroidMissingOnClickHandlerInspection method findRelatedActivities.

@NotNull
private static Collection<PsiClass> findRelatedActivities(@NotNull XmlFile file, @NotNull AndroidFacet facet, @NotNull DomFileDescription<?> description) {
    if (description instanceof LayoutDomFileDescription) {
        final Computable<List<GotoRelatedItem>> computable = AndroidGotoRelatedProvider.getLazyItemsForXmlFile(file, facet);
        if (computable == null) {
            return Collections.emptyList();
        }
        final List<GotoRelatedItem> items = computable.compute();
        if (items.isEmpty()) {
            return Collections.emptyList();
        }
        final PsiClass activityClass = findActivityClass(facet.getModule());
        if (activityClass == null) {
            return Collections.emptyList();
        }
        final List<PsiClass> result = new ArrayList<PsiClass>();
        for (GotoRelatedItem item : items) {
            final PsiElement element = item.getElement();
            if (element instanceof PsiClass) {
                final PsiClass aClass = (PsiClass) element;
                if (aClass.isInheritor(activityClass, true)) {
                    result.add(aClass);
                }
            }
        }
        return result;
    } else {
        return findRelatedActivitiesForMenu(file, facet);
    }
}
Also used : LayoutDomFileDescription(org.jetbrains.android.dom.layout.LayoutDomFileDescription) GotoRelatedItem(com.intellij.navigation.GotoRelatedItem) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

LayoutDomFileDescription (org.jetbrains.android.dom.layout.LayoutDomFileDescription)4 XmlFile (com.intellij.psi.xml.XmlFile)3 GotoRelatedItem (com.intellij.navigation.GotoRelatedItem)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 XmlAttribute (com.intellij.psi.xml.XmlAttribute)1 XmlTag (com.intellij.psi.xml.XmlTag)1 IOException (java.io.IOException)1 AndroidResourceDomFileDescription (org.jetbrains.android.dom.AndroidResourceDomFileDescription)1 ColorDomFileDescription (org.jetbrains.android.dom.color.ColorDomFileDescription)1 DrawableStateListDomFileDescription (org.jetbrains.android.dom.drawable.fileDescriptions.DrawableStateListDomFileDescription)1 ManifestDomFileDescription (org.jetbrains.android.dom.manifest.ManifestDomFileDescription)1 MenuDomFileDescription (org.jetbrains.android.dom.menu.MenuDomFileDescription)1 ResourcesDomFileDescription (org.jetbrains.android.dom.resources.ResourcesDomFileDescription)1 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1