Search in sources :

Example 11 with DomElement

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

the class DomElementAnnotationsManagerImpl method _getOrCreateProblemsHolder.

private DomElementsProblemsHolderImpl _getOrCreateProblemsHolder(final DomFileElement element) {
    DomElementsProblemsHolderImpl holder;
    final DomElement rootElement = element.getRootElement();
    final XmlTag rootTag = rootElement.getXmlTag();
    if (rootTag == null)
        return new DomElementsProblemsHolderImpl(element);
    holder = rootTag.getUserData(DOM_PROBLEM_HOLDER_KEY);
    if (isHolderOutdated(element.getFile()) || holder == null) {
        holder = new DomElementsProblemsHolderImpl(element);
        rootTag.putUserData(DOM_PROBLEM_HOLDER_KEY, holder);
        final CachedValue<Boolean> cachedValue = CachedValuesManager.getManager(myProject).createCachedValue(() -> new CachedValueProvider.Result<>(Boolean.FALSE, element, PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, this, ProjectRootManager.getInstance(myProject)), false);
        cachedValue.getValue();
        element.getFile().putUserData(CACHED_VALUE_KEY, cachedValue);
    }
    return holder;
}
Also used : DomElement(com.intellij.util.xml.DomElement) CachedValueProvider(com.intellij.psi.util.CachedValueProvider) XmlTag(com.intellij.psi.xml.XmlTag)

Example 12 with DomElement

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

the class IndexedElementInvocationHandler method createPathStableCopy.

@Override
public final DomElement createPathStableCopy() {
    final DomFixedChildDescription description = getChildDescription();
    final DomElement parentCopy = getParent().createStableCopy();
    return getManager().createStableValue((Factory<DomElement>) () -> parentCopy.isValid() ? description.getValues(parentCopy).get(myIndex) : null);
}
Also used : DomElement(com.intellij.util.xml.DomElement) DomFixedChildDescription(com.intellij.util.xml.reflect.DomFixedChildDescription)

Example 13 with DomElement

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

the class DomElementsProblemsHolderImpl method getProblemsMap.

@NotNull
private Map<Class<? extends DomElementsInspection>, List<DomElementProblemDescriptor>> getProblemsMap(final DomElement domElement) {
    final Map<Class<? extends DomElementsInspection>, List<DomElementProblemDescriptor>> map = myCachedChildrenErrors.get(domElement);
    if (map != null) {
        return map;
    }
    final Map<Class<? extends DomElementsInspection>, List<DomElementProblemDescriptor>> problems = new THashMap<>();
    if (domElement == myElement) {
        for (Map<Class<? extends DomElementsInspection>, List<DomElementProblemDescriptor>> listMap : myCachedErrors.values()) {
            mergeMaps(problems, listMap);
        }
    } else {
        mergeMaps(problems, myCachedErrors.get(domElement));
        if (DomUtil.hasXml(domElement)) {
            domElement.acceptChildren(new DomElementVisitor() {

                @Override
                public void visitDomElement(DomElement element) {
                    mergeMaps(problems, getProblemsMap(element));
                }
            });
        }
    }
    myCachedChildrenErrors.put(domElement, problems);
    return problems;
}
Also used : DomElement(com.intellij.util.xml.DomElement) THashMap(gnu.trove.THashMap) DomElementVisitor(com.intellij.util.xml.DomElementVisitor) SmartList(com.intellij.util.SmartList) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with DomElement

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

the class AttributeChildInvocationHandler method setValue.

@Override
protected void setValue(@Nullable final String value) {
    final XmlTag tag = ensureTagExists();
    final String attributeName = getXmlElementName();
    final String namespace = getXmlApiCompatibleNamespace(getParentHandler());
    final String oldValue = StringUtil.unescapeXml(tag.getAttributeValue(attributeName, namespace));
    final String newValue = XmlStringUtil.escapeString(value);
    if (Comparing.equal(oldValue, newValue, true))
        return;
    getManager().runChange(() -> {
        try {
            XmlAttribute attribute = tag.setAttribute(attributeName, namespace, newValue);
            setXmlElement(attribute);
            getManager().cacheHandler(DomManagerImpl.DOM_ATTRIBUTE_HANDLER_KEY, attribute, this);
        } catch (IncorrectOperationException e) {
            LOG.error(e);
        }
    });
    final DomElement proxy = getProxy();
    getManager().fireEvent(oldValue != null ? new DomEvent(proxy, false) : new DomEvent(proxy, true));
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) DomElement(com.intellij.util.xml.DomElement) IncorrectOperationException(com.intellij.util.IncorrectOperationException) XmlTag(com.intellij.psi.xml.XmlTag) DomEvent(com.intellij.util.xml.events.DomEvent)

Example 15 with DomElement

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

the class AbstractDomGenerateProvider method generate.

@Override
public T generate(final Project project, final Editor editor, final PsiFile file) {
    DomElement parentDomElement = getParentDomElement(project, editor, file);
    final T t = generate(parentDomElement, editor);
    runTemplate(editor, file, t, getPredefinedVars(parentDomElement, t, editor, file));
    return t;
}
Also used : DomElement(com.intellij.util.xml.DomElement)

Aggregations

DomElement (com.intellij.util.xml.DomElement)97 XmlTag (com.intellij.psi.xml.XmlTag)34 PsiElement (com.intellij.psi.PsiElement)19 Nullable (org.jetbrains.annotations.Nullable)19 NotNull (org.jetbrains.annotations.NotNull)15 Project (com.intellij.openapi.project.Project)11 PsiFile (com.intellij.psi.PsiFile)11 XmlFile (com.intellij.psi.xml.XmlFile)11 XmlAttribute (com.intellij.psi.xml.XmlAttribute)10 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)9 ArrayList (java.util.ArrayList)8 LayoutViewElement (org.jetbrains.android.dom.layout.LayoutViewElement)7 ResourceElement (org.jetbrains.android.dom.resources.ResourceElement)6 DomManager (com.intellij.util.xml.DomManager)5 Style (org.jetbrains.android.dom.resources.Style)5 AntDomTarget (com.intellij.lang.ant.dom.AntDomTarget)4 XmlElement (com.intellij.psi.xml.XmlElement)4 DomElementProblemDescriptor (com.intellij.util.xml.highlighting.DomElementProblemDescriptor)4 LookupElement (com.intellij.codeInsight.lookup.LookupElement)3 TextRange (com.intellij.openapi.util.TextRange)3