Search in sources :

Example 11 with LayoutViewElement

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

the class StructureViewTest method testLayoutStructure.

public void testLayoutStructure() throws Exception {
    VirtualFile file = copyFileToProject("layout/structure_view_test.xml", "/res/layout/layout.xml");
    PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(file);
    assertInstanceOf(psiFile, XmlFile.class);
    DomFileElement<LayoutViewElement> element = DomManager.getDomManager(getProject()).getFileElement(((XmlFile) psiFile), LayoutViewElement.class);
    assertNotNull(element);
    final StructureViewModel model = new LayoutStructureViewBuilder(element).createStructureViewModel(null);
    String expected = "LinearLayout\n" + "  TextView\n" + "  TextView (@+id/login)\n" + "  TextView (@+id/password)\n" + "  LinearLayout\n" + "    Include @layout/some_other_layout\n" + "    TextView\n";
    assertEquals(expected, model.getRoot().toString());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LayoutViewElement(org.jetbrains.android.dom.layout.LayoutViewElement) XmlFile(com.intellij.psi.xml.XmlFile) StructureViewModel(com.intellij.ide.structureView.StructureViewModel) PsiFile(com.intellij.psi.PsiFile) LayoutStructureViewBuilder(org.jetbrains.android.dom.structure.layout.LayoutStructureViewBuilder)

Example 12 with LayoutViewElement

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

the class StructureViewTest method testLayoutStructureOrder1.

public void testLayoutStructureOrder1() throws Exception {
    VirtualFile file = copyFileToProject("layout/structure_view_test_order_1.xml", "/res/layout/layout.xml");
    PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(file);
    assertInstanceOf(psiFile, XmlFile.class);
    DomFileElement<LayoutViewElement> element = DomManager.getDomManager(getProject()).getFileElement(((XmlFile) psiFile), LayoutViewElement.class);
    assertNotNull(element);
    final StructureViewModel model = new LayoutStructureViewBuilder(element).createStructureViewModel(null);
    String expected = "LinearLayout\n" + "  Fragment\n" + "  Include\n";
    assertEquals(expected, model.getRoot().toString());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LayoutViewElement(org.jetbrains.android.dom.layout.LayoutViewElement) XmlFile(com.intellij.psi.xml.XmlFile) StructureViewModel(com.intellij.ide.structureView.StructureViewModel) PsiFile(com.intellij.psi.PsiFile) LayoutStructureViewBuilder(org.jetbrains.android.dom.structure.layout.LayoutStructureViewBuilder)

Aggregations

LayoutViewElement (org.jetbrains.android.dom.layout.LayoutViewElement)12 DomElement (com.intellij.util.xml.DomElement)7 PsiFile (com.intellij.psi.PsiFile)6 XmlTag (com.intellij.psi.xml.XmlTag)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 XmlAttribute (com.intellij.psi.xml.XmlAttribute)4 XmlFile (com.intellij.psi.xml.XmlFile)4 Nullable (org.jetbrains.annotations.Nullable)4 StructureViewModel (com.intellij.ide.structureView.StructureViewModel)3 DomManager (com.intellij.util.xml.DomManager)3 LayoutStructureViewBuilder (org.jetbrains.android.dom.structure.layout.LayoutStructureViewBuilder)3 Project (com.intellij.openapi.project.Project)2 Pair (com.intellij.openapi.util.Pair)2 PsiElement (com.intellij.psi.PsiElement)2 UsageInfo (com.intellij.usageView.UsageInfo)2 HashSet (com.intellij.util.containers.HashSet)2 ResourceValue (org.jetbrains.android.dom.resources.ResourceValue)2 Style (org.jetbrains.android.dom.resources.Style)2 XmlResourceElement (org.jetbrains.android.dom.xml.XmlResourceElement)2 Result (com.intellij.openapi.application.Result)1