Search in sources :

Example 21 with XmlFile

use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.

the class DomHighlightingLiteTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    myInspectionProfile = new MockInspectionProfile();
    myAnnotationsManager = new DomElementAnnotationsManagerImpl(getProject()) {

        @Override
        protected InspectionProfile getInspectionProfile(final DomFileElement fileElement) {
            return myInspectionProfile;
        }
    };
    final XmlFile file = createXmlFile("<a/>");
    final MockDomElement rootElement = new MockDomElement() {

        @Override
        @Nullable
        public XmlElement getXmlElement() {
            return getXmlTag();
        }

        @Override
        public XmlTag getXmlTag() {
            return file.getRootTag();
        }

        @NotNull
        @Override
        public Type getDomElementType() {
            return DomElement.class;
        }
    };
    myElement = new MockDomFileElement() {

        @Override
        @Nullable
        public XmlElement getXmlElement() {
            return file;
        }

        @Override
        @NotNull
        public XmlFile getFile() {
            return file;
        }

        @Override
        public DomElement getParent() {
            return null;
        }

        @Override
        @NotNull
        public DomElement getRootElement() {
            return rootElement;
        }

        @NotNull
        @Override
        public Class getRootElementClass() {
            return DomElement.class;
        }

        @Override
        public boolean isValid() {
            return true;
        }
    };
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) MockInspectionProfile(com.intellij.mock.MockInspectionProfile) InspectionProfile(com.intellij.codeInspection.InspectionProfile) NotNull(org.jetbrains.annotations.NotNull) MockInspectionProfile(com.intellij.mock.MockInspectionProfile) XmlElement(com.intellij.psi.xml.XmlElement) Nullable(org.jetbrains.annotations.Nullable)

Example 22 with XmlFile

use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.

the class DomIncludesTest method testNavigationToIncluded.

public void testNavigationToIncluded() throws Throwable {
    final MyElement rootElement = createDomFile("a.xml", "<root xmlns:xi=\"http://www.w3.org/2001/XInclude\">" + "<xi:include href=\"b.xml\" xpointer=\"xpointer(/xxx/*)\"/>" + "<child ref=\"b\"/>" + "</root>");
    final XmlFile includedFile = (XmlFile) createFile("b.xml", "<xxx><child xxx=\"b\"/></xxx>");
    final List<Child> children = rootElement.getChildren();
    final MyElement domTarget = children.get(0);
    final GenericAttributeValue<Child> ref = children.get(1).getRef();
    final MyElement value = ref.getValue();
    assertEquals(domTarget, value);
    myFixture.configureFromTempProjectFile("a.xml");
    final int offset = ref.getXmlAttributeValue().getTextRange().getStartOffset() + 1;
    myFixture.getEditor().getCaretModel().moveToOffset(offset);
    final PsiElement target = GotoDeclarationAction.findTargetElement(getProject(), myFixture.getEditor(), offset);
    PsiElement element = ((DomTarget) ((PomTargetPsiElement) target).getTarget()).getNavigationElement();
    //    assertSame(PomService.convertToPsi(DomTarget.getTarget(domTarget)), target);
    assertSame(includedFile.getDocument().getRootTag().getSubTags()[0].getAttributes()[0].getValueElement(), element);
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement) PsiElement(com.intellij.psi.PsiElement)

Example 23 with XmlFile

use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.

the class DomAnnotationsTest method createElement.

@Override
protected <T extends DomElement> T createElement(final String xml, final Class<T> aClass) {
    final String name = "a.xml";
    final XmlFile file = (XmlFile) PsiFileFactory.getInstance(getProject()).createFileFromText(name, StdFileTypes.XML, xml, 0, true);
    final XmlTag tag = file.getDocument().getRootTag();
    final String rootTagName = tag != null ? tag.getName() : "root";
    final T element = getDomManager().getFileElement(file, aClass, rootTagName).getRootElement();
    assertNotNull(element);
    assertSame(tag, element.getXmlTag());
    return element;
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) XmlTag(com.intellij.psi.xml.XmlTag)

Example 24 with XmlFile

use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.

the class DomConcurrencyStressTest method testInternalDomLocksReadConsistency.

public void testInternalDomLocksReadConsistency() throws Throwable {
    getDomManager().registerFileDescription(new DomFileDescription(MyElement.class, "a"), getTestRootDisposable());
    registerExtender(MyElement.class, MyExtender.class);
    final XmlFile file = createXmlFile("<a attr=\"1\" attr2=\"2\">" + "<foo-child><foo-child/><custom-foo/></foo-child>" + "<bar-child><foo-child/></bar-child>" + "<foo-element>" + "  <foo-child/>" + "  <foo-child><foo-child attr=\"\"/></foo-child>" + "  <custom-foo/>" + "  <custom-bar/>" + "</foo-element>" + "<custom-bar/>" + "<custom-bar>" + "  <foo-child/>" + "  <foo-element/>" + "  <foo-element/>" + "  <custom-bar/>" + "</custom-bar>" + "<custom-bar attr=\"\">" + "  <foo-child/>" + "  <some-child/>" + "  <custom-bar/>" + "</custom-bar>" + "<child/>" + "<child/>" + "<bool/>" + "</a>");
    System.out.println("ITERATIONS =" + ITERATIONS);
    runThreads(42, new Runnable() {

        @Override
        public void run() {
            for (int i = 0; i < ITERATIONS; i++) {
                ApplicationManager.getApplication().runReadAction(new Runnable() {

                    @Override
                    public void run() {
                        final DomFileElementImpl<DomElement> element = getDomManager().getFileElement(file);
                        assertNotNull(element);
                        element.getRootElement().accept(new DomElementVisitor() {

                            @Override
                            public void visitDomElement(final DomElement element) {
                                if (DomUtil.hasXml(element)) {
                                    element.acceptChildren(this);
                                }
                            }
                        });
                    }
                });
                SemService.getSemService(getProject()).clearCache();
            }
        }
    });
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile)

Example 25 with XmlFile

use of com.intellij.psi.xml.XmlFile in project intellij-community by JetBrains.

the class DomFileDescriptionTest method testDependantFileDescriptionCauseStackOverflow.

public void testDependantFileDescriptionCauseStackOverflow() throws Throwable {
    final XmlFile interestingFile = (XmlFile) createFile("a.xml", "<b>42</b>");
    getDomManager().registerFileDescription(new MockDomFileDescription<>(MyElement.class, "b", (XmlFile) null), myDisposable);
    for (int i = 0; i < 239; i++) {
        getDomManager().registerFileDescription(new MockDomFileDescription<AbstractElement>(AbstractElement.class, "b", (XmlFile) null) {

            @Override
            @NotNull
            public Set getDependencyItems(final XmlFile file) {
                getDomManager().isDomFile(interestingFile);
                return super.getDependencyItems(file);
            }
        }, myDisposable);
    }
    getDomManager().isDomFile(interestingFile);
}
Also used : Set(java.util.Set) XmlFile(com.intellij.psi.xml.XmlFile) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

XmlFile (com.intellij.psi.xml.XmlFile)409 XmlTag (com.intellij.psi.xml.XmlTag)155 PsiFile (com.intellij.psi.PsiFile)121 VirtualFile (com.intellij.openapi.vfs.VirtualFile)102 Nullable (org.jetbrains.annotations.Nullable)74 Project (com.intellij.openapi.project.Project)69 NotNull (org.jetbrains.annotations.NotNull)66 PsiElement (com.intellij.psi.PsiElement)64 XmlAttribute (com.intellij.psi.xml.XmlAttribute)39 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)34 Module (com.intellij.openapi.module.Module)34 XmlDocument (com.intellij.psi.xml.XmlDocument)32 Result (com.intellij.openapi.application.Result)28 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)23 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)22 XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)21 ArrayList (java.util.ArrayList)20 Document (com.intellij.openapi.editor.Document)19 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)18 Editor (com.intellij.openapi.editor.Editor)15