Search in sources :

Example 91 with DomElement

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

the class AllowedMethodsConverter method getActionElement.

/**
   * Gets the enclosing <code>action</code>-element for the current context.
   *
   * @param context Current context.
   * @return Action-element.
   */
@NotNull
private static Action getActionElement(final ConvertContext context) {
    final DomElement domElement = context.getInvocationElement();
    final Action action = domElement.getParentOfType(Action.class, false);
    assert action != null : "not triggered within <action> for " + domElement.getXmlElement();
    return action;
}
Also used : DomElement(com.intellij.util.xml.DomElement) NotNull(org.jetbrains.annotations.NotNull)

Example 92 with DomElement

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

the class ExceptionMappingResultResolveConverter method getVariants.

@NotNull
public Collection<? extends HasResultType> getVariants(final ConvertContext context) {
    final DomElement invocationElement = context.getInvocationElement();
    final Action action = invocationElement.getParentOfType(Action.class, true);
    if (action == null) {
        return Collections.emptySet();
    }
    final List<HasResultType> variants = new ArrayList<>();
    // Action-local first
    variants.addAll(action.getResults());
    final StrutsPackage strutsPackage = action.getStrutsPackage();
    final GlobalResults globalResults = strutsPackage.getGlobalResults();
    variants.addAll(globalResults.getResults());
    return variants;
}
Also used : DomElement(com.intellij.util.xml.DomElement) HasResultType(com.intellij.struts2.dom.struts.HasResultType) GlobalResults(com.intellij.struts2.dom.struts.strutspackage.GlobalResults) ArrayList(java.util.ArrayList) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage) NotNull(org.jetbrains.annotations.NotNull)

Example 93 with DomElement

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

the class StrutsResultContributor method getNamespace.

/**
   * Gets the current namespace for the given element.
   *
   * @param psiElement Current element.
   * @return {@code null} on XML errors or if {@link #matchesResultType(String)} returns {@code false}.
   */
@Nullable
protected final String getNamespace(@NotNull final PsiElement psiElement) {
    final DomElement resultElement = DomUtil.getDomElement(psiElement);
    if (resultElement == null) {
        // XML syntax error
        return null;
    }
    assert resultElement instanceof HasResultType : "not instance of HasResultType: " + resultElement + ", text: " + psiElement.getText();
    final ResultType effectiveResultType = ((HasResultType) resultElement).getEffectiveResultType();
    if (effectiveResultType == null) {
        return null;
    }
    final String resultType = effectiveResultType.getName().getStringValue();
    if (resultType == null || !matchesResultType(resultType)) {
        return null;
    }
    final StrutsPackage strutsPackage = resultElement.getParentOfType(StrutsPackage.class, true);
    if (strutsPackage == null) {
        // XML syntax error
        return null;
    }
    return strutsPackage.searchNamespace();
}
Also used : DomElement(com.intellij.util.xml.DomElement) HasResultType(com.intellij.struts2.dom.struts.HasResultType) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage) HasResultType(com.intellij.struts2.dom.struts.HasResultType) ResultType(com.intellij.struts2.dom.struts.strutspackage.ResultType) Nullable(org.jetbrains.annotations.Nullable)

Example 94 with DomElement

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

the class ParamNameConverterImpl method createReferences.

@NotNull
public PsiReference[] createReferences(final GenericDomValue<List<BeanProperty>> listGenericDomValue, final PsiElement psiElement, final ConvertContext convertContext) {
    final DomElement paramsElement = findEnclosingTag(convertContext);
    if (paramsElement == null) {
        return PsiReference.EMPTY_ARRAY;
    }
    for (ParamNameCustomConverter customConverter : Extensions.getExtensions(EP_NAME)) {
        final PsiReference[] customReferences = customConverter.getCustomReferences((XmlAttributeValue) psiElement, paramsElement);
        if (customReferences.length > 0) {
            return customReferences;
        }
    }
    final PsiClass rootPsiClass = findBeanPropertyClass(paramsElement);
    return new BeanPropertyPathReferenceSet(psiElement, rootPsiClass, false).getPsiReferences();
}
Also used : DomElement(com.intellij.util.xml.DomElement) PsiClass(com.intellij.psi.PsiClass) PsiReference(com.intellij.psi.PsiReference) BeanPropertyPathReferenceSet(com.intellij.struts2.reference.common.BeanPropertyPathReferenceSet) NotNull(org.jetbrains.annotations.NotNull)

Example 95 with DomElement

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

the class DomElementListCellRenderer method getElementText.

public String getElementText(final XmlTag element) {
    final DomElement domElement = getDomElement(element);
    if (domElement == null) {
        return element.getName();
    }
    final String elementName = domElement.getPresentation().getElementName();
    return elementName == null ? unknownElementText : elementName;
}
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