Search in sources :

Example 11 with DomManager

use of com.intellij.util.xml.DomManager in project intellij-community by JetBrains.

the class AntSupport method getAntDomProject.

//
// Managing ant files dependencies via the <import> task.
//
@Nullable
public static AntDomProject getAntDomProject(PsiFile psiFile) {
    if (psiFile instanceof XmlFile) {
        final DomManager domManager = DomManager.getDomManager(psiFile.getProject());
        final DomFileElement<AntDomProject> fileElement = domManager.getFileElement((XmlFile) psiFile, AntDomProject.class);
        return fileElement != null ? fileElement.getRootElement() : null;
    }
    return null;
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) DomManager(com.intellij.util.xml.DomManager) AntDomProject(com.intellij.lang.ant.dom.AntDomProject) Nullable(org.jetbrains.annotations.Nullable)

Example 12 with DomManager

use of com.intellij.util.xml.DomManager in project intellij-community by JetBrains.

the class AntSupport method getAntDomProjectForceAntFile.

@Nullable
public static AntDomProject getAntDomProjectForceAntFile(PsiFile psiFile) {
    if (psiFile instanceof XmlFile) {
        final DomManager domManager = DomManager.getDomManager(psiFile.getProject());
        DomFileElement<AntDomProject> fileElement = domManager.getFileElement((XmlFile) psiFile, AntDomProject.class);
        if (fileElement == null) {
            ForcedAntFileAttribute.forceAntFile(psiFile.getVirtualFile(), true);
            fileElement = domManager.getFileElement((XmlFile) psiFile, AntDomProject.class);
        }
        return fileElement != null ? fileElement.getRootElement() : null;
    }
    return null;
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) DomManager(com.intellij.util.xml.DomManager) AntDomProject(com.intellij.lang.ant.dom.AntDomProject) Nullable(org.jetbrains.annotations.Nullable)

Example 13 with DomManager

use of com.intellij.util.xml.DomManager in project intellij-community by JetBrains.

the class MavenGroovyPomScriptMemberContributor method processDynamicElements.

@Override
public void processDynamicElements(@NotNull PsiType qualifierType, PsiClass aClass, @NotNull PsiScopeProcessor processor, @NotNull PsiElement place, @NotNull ResolveState state) {
    PsiElement pomElement = aClass.getContainingFile().getContext();
    if (pomElement == null)
        return;
    PsiFile pomFile = pomElement.getContainingFile();
    if (!(pomFile instanceof XmlFile))
        return;
    DomManager domManager = DomManager.getDomManager(pomElement.getProject());
    if (!(domManager.getDomFileDescription((XmlFile) pomFile) instanceof MavenDomProjectModelDescription)) {
        return;
    }
    DynamicMemberUtils.process(processor, false, place, CLASS_SOURCE);
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) DomManager(com.intellij.util.xml.DomManager) MavenDomProjectModelDescription(org.jetbrains.idea.maven.dom.MavenDomProjectModelDescription)

Example 14 with DomManager

use of com.intellij.util.xml.DomManager in project intellij-community by JetBrains.

the class MockDomElementsEditor method createMockElement.

private <T extends DomElement> T createMockElement(final Class<T> aClass, final Module module) {
    final Project project = module.getProject();
    ApplicationManager.getApplication().invokeLater(() -> {
        if (myFileEditor.isInitialised()) {
            myContents.reset();
        }
    });
    final DomManager domManager = DomManager.getDomManager(project);
    final T mockElement = domManager.createMockElement(aClass, module, true);
    if (myFileEditor != null) {
        myFileEditor.addWatchedElement(mockElement);
    }
    return mockElement;
}
Also used : Project(com.intellij.openapi.project.Project) DomManager(com.intellij.util.xml.DomManager)

Example 15 with DomManager

use of com.intellij.util.xml.DomManager in project intellij-community by JetBrains.

the class MockDomElementsEditor method initFileEditor.

protected final DomFileEditor initFileEditor(final Project project, final VirtualFile virtualFile, final String name, final Factory<? extends BasicDomElementComponent> component) {
    myFileEditor = new DomFileEditor<BasicDomElementComponent>(project, virtualFile, name, component) {

        @Override
        public JComponent getPreferredFocusedComponent() {
            return null;
        }

        @Override
        @NotNull
        protected JComponent createCustomComponent() {
            final JComponent customComponent = super.createCustomComponent();
            myContents = getDomComponent();
            return customComponent;
        }

        @Override
        public void reset() {
            for (final Map.Entry<EditedElementDescription<? extends DomElement>, DomElement> entry : myDomElements.entrySet()) {
                final DomElement newValue = entry.getKey().find();
                final DomElement oldValue = entry.getValue();
                if (newValue != null && !newValue.equals(oldValue) || newValue == null && !oldValue.getManager().isMockElement(oldValue)) {
                    ((StableElement) oldValue).revalidate();
                }
            }
            super.reset();
        }

        @Override
        public void commit() {
            super.commit();
            final List<EditedElementDescription> descriptions = new ArrayList<>();
            final Set<PsiFile> changedFiles = new HashSet<>();
            for (final Map.Entry<EditedElementDescription<? extends DomElement>, DomElement> entry : myDomElements.entrySet()) {
                final EditedElementDescription description = entry.getKey();
                final DomElement editedElement = entry.getValue();
                if (description.find() == null && editedElement.getXmlTag() != null) {
                    descriptions.add(description);
                    final XmlFile xmlFile = description.getEditedFile();
                    if (xmlFile != null) {
                        changedFiles.add(xmlFile);
                    }
                }
            }
            new WriteCommandAction(project, PsiUtilCore.toPsiFileArray(changedFiles)) {

                @Override
                protected void run(@NotNull Result result) throws Throwable {
                    for (EditedElementDescription description : descriptions) {
                        final DomElement editedElement = myDomElements.get(description);
                        DomElement element = description.addElement();
                        element.copyFrom(editedElement);
                        description.initialize(element);
                        removeWatchedElement(editedElement);
                        ((StableElement) editedElement).invalidate();
                    }
                }
            }.execute();
        }
    };
    final DomManager domManager = DomManager.getDomManager(project);
    for (final DomElement element : myDomElements.values()) {
        if (domManager.isMockElement(element)) {
            myFileEditor.addWatchedElement(element);
        }
    }
    return myFileEditor;
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) XmlFile(com.intellij.psi.xml.XmlFile) DomManager(com.intellij.util.xml.DomManager) NotNull(org.jetbrains.annotations.NotNull) Result(com.intellij.openapi.application.Result) StableElement(com.intellij.util.xml.StableElement) DomElement(com.intellij.util.xml.DomElement)

Aggregations

DomManager (com.intellij.util.xml.DomManager)15 XmlFile (com.intellij.psi.xml.XmlFile)9 Nullable (org.jetbrains.annotations.Nullable)7 DomElement (com.intellij.util.xml.DomElement)5 Project (com.intellij.openapi.project.Project)3 XmlTag (com.intellij.psi.xml.XmlTag)3 LayoutViewElement (org.jetbrains.android.dom.layout.LayoutViewElement)3 AntDomProject (com.intellij.lang.ant.dom.AntDomProject)2 AppEngineStandardWebApp (com.google.cloud.tools.intellij.appengine.descriptor.dom.AppEngineStandardWebApp)1 AntDomAntlib (com.intellij.lang.ant.dom.AntDomAntlib)1 Result (com.intellij.openapi.application.Result)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 PsiFile (com.intellij.psi.PsiFile)1 XmlAttribute (com.intellij.psi.xml.XmlAttribute)1 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)1 GenericAttributeValue (com.intellij.util.xml.GenericAttributeValue)1 StableElement (com.intellij.util.xml.StableElement)1 Data (org.jetbrains.android.dom.layout.Data)1 Import (org.jetbrains.android.dom.layout.Import)1 Layout (org.jetbrains.android.dom.layout.Layout)1