Search in sources :

Example 1 with DomManager

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

the class MockDomElementsEditor method addEditedElement.

protected final <T extends DomElement> T addEditedElement(final Class<T> aClass, final EditedElementDescription<T> description) {
    final DomManager domManager = DomManager.getDomManager(myModule.getProject());
    final T t = domManager.createStableValue(() -> {
        T t1 = description.find();
        if (t1 == null) {
            return createMockElement(aClass);
        }
        return t1;
    });
    myDomElements.put(description, t);
    return t;
}
Also used : DomManager(com.intellij.util.xml.DomManager)

Example 2 with DomManager

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

the class AndroidUtils method loadDomElementWithReadPermission.

/** This method should be called under a read action. */
@Nullable
public static <T extends DomElement> T loadDomElementWithReadPermission(@NotNull Project project, @NotNull XmlFile xmlFile, @NotNull Class<T> aClass) {
    getApplication().assertReadAccessAllowed();
    DomManager domManager = DomManager.getDomManager(project);
    DomFileElement<T> element = domManager.getFileElement(xmlFile, aClass);
    if (element == null)
        return null;
    return element.getRootElement();
}
Also used : DomManager(com.intellij.util.xml.DomManager) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with DomManager

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

the class AppEngineFacet method getRootElement.

//todo[nik] copied from JamCommonUtil
@Nullable
private static <T> T getRootElement(final PsiFile file, final Class<T> domClass, final Module module) {
    if (!(file instanceof XmlFile))
        return null;
    final DomManager domManager = DomManager.getDomManager(file.getProject());
    final DomFileElement<DomElement> element = domManager.getFileElement((XmlFile) file, DomElement.class);
    if (element == null)
        return null;
    final DomElement root = element.getRootElement();
    if (!ReflectionUtil.isAssignable(domClass, root.getClass()))
        return null;
    return (T) root;
}
Also used : DomElement(com.intellij.util.xml.DomElement) XmlFile(com.intellij.psi.xml.XmlFile) DomManager(com.intellij.util.xml.DomManager) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with DomManager

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

the class AndroidExtractAsIncludeAction method isEnabledForPsiRange.

@Override
protected boolean isEnabledForPsiRange(@NotNull PsiElement from, @Nullable PsiElement to) {
    final DomManager domManager = DomManager.getDomManager(from.getProject());
    PsiElement e = from;
    boolean containsViewElement = false;
    while (e != null) {
        if (e instanceof XmlTag) {
            final DomElement domElement = domManager.getDomElement((XmlTag) e);
            if (!isSuitableDomElement(domElement)) {
                return false;
            }
            if (domElement instanceof LayoutViewElement) {
                containsViewElement = true;
            }
        }
        if (e == to) {
            break;
        }
        e = e.getNextSibling();
    }
    return containsViewElement;
}
Also used : DomElement(com.intellij.util.xml.DomElement) LayoutViewElement(org.jetbrains.android.dom.layout.LayoutViewElement) DomManager(com.intellij.util.xml.DomManager) XmlTag(com.intellij.psi.xml.XmlTag)

Example 5 with DomManager

use of com.intellij.util.xml.DomManager in project google-cloud-intellij by GoogleCloudPlatform.

the class AppEngineStandardFacet method getAppEngineStandardWebXml.

@Nullable
public AppEngineStandardWebApp getAppEngineStandardWebXml() {
    XmlFile appengineWebXmlFile = AppEngineAssetProvider.getInstance().loadAppEngineStandardWebXml(getModule().getProject(), ImmutableList.of(getModule()));
    final DomManager domManager = DomManager.getDomManager(getModule().getProject());
    DomFileElement<AppEngineStandardWebApp> appEngineWebXmlDom = domManager.getFileElement(appengineWebXmlFile, AppEngineStandardWebApp.class);
    if (appEngineWebXmlDom == null) {
        return null;
    }
    return appEngineWebXmlDom.getRootElement();
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) DomManager(com.intellij.util.xml.DomManager) AppEngineStandardWebApp(com.google.cloud.tools.intellij.appengine.descriptor.dom.AppEngineStandardWebApp) Nullable(org.jetbrains.annotations.Nullable)

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