Search in sources :

Example 26 with DomElement

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

the class ExtensionPointLocator method isRegisteredExtension.

public static boolean isRegisteredExtension(@NotNull PsiClass psiClass) {
    String name = psiClass.getQualifiedName();
    if (name == null)
        return false;
    Project project = psiClass.getProject();
    GlobalSearchScope scope = getCandidatesScope(project);
    return !PsiSearchHelper.SERVICE.getInstance(project).processUsagesInNonJavaFiles(name, new PsiNonJavaFileReferenceProcessor() {

        @Override
        public boolean process(PsiFile file, int startOffset, int endOffset) {
            PsiElement at = file.findElementAt(startOffset);
            String tokenText = at instanceof XmlToken ? at.getText() : null;
            if (!StringUtil.equals(name, tokenText))
                return true;
            XmlTag tag = PsiTreeUtil.getParentOfType(at, XmlTag.class);
            if (tag == null)
                return true;
            DomElement dom = DomUtil.getDomElement(tag);
            return !(dom instanceof Extension && ((Extension) dom).getExtensionPoint() != null);
        }
    }, scope);
}
Also used : Extension(org.jetbrains.idea.devkit.dom.Extension) Project(com.intellij.openapi.project.Project) DomElement(com.intellij.util.xml.DomElement) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiNonJavaFileReferenceProcessor(com.intellij.psi.search.PsiNonJavaFileReferenceProcessor) XmlToken(com.intellij.psi.xml.XmlToken) XmlTag(com.intellij.psi.xml.XmlTag)

Example 27 with DomElement

use of com.intellij.util.xml.DomElement 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 28 with DomElement

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

the class AndroidXmlTagDescriptor method getElementsDescriptors.

@Override
public XmlElementDescriptor[] getElementsDescriptors(XmlTag context) {
    final XmlElementDescriptor[] descriptors = myParentDescriptor.getElementsDescriptors(context);
    if (myBaseClassName == null || context == null) {
        return descriptors;
    }
    final AndroidFacet facet = AndroidFacet.getInstance(context);
    if (facet == null) {
        return descriptors;
    }
    final XmlElementDescriptor[] androidDescriptors = new XmlElementDescriptor[descriptors.length];
    final DomElement domElement = DomManager.getDomManager(context.getProject()).getDomElement(context);
    final PsiClass baseClass = JavaPsiFacade.getInstance(context.getProject()).findClass(myBaseClassName, facet.getModule().getModuleWithLibrariesScope());
    for (int i = 0; i < descriptors.length; i++) {
        final XmlElementDescriptor descriptor = descriptors[i];
        final String tagName = descriptor.getName();
        final PsiClass aClass = tagName != null && baseClass != null ? LayoutViewClassUtils.findClassByTagName(facet, tagName, baseClass) : null;
        final Icon icon = AndroidDomElementDescriptorProvider.getIconForTag(tagName, domElement);
        androidDescriptors[i] = new AndroidXmlTagDescriptor(aClass, descriptor, myBaseClassName, icon);
    }
    return androidDescriptors;
}
Also used : DomElement(com.intellij.util.xml.DomElement) PsiClass(com.intellij.psi.PsiClass) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 29 with DomElement

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

the class AndroidXmlSpellcheckingStrategy method isAttributeValueContext.

private static boolean isAttributeValueContext(@NotNull PsiElement element) {
    if (!(element instanceof XmlAttributeValue)) {
        return false;
    }
    PsiElement parent = element.getParent();
    parent = parent != null ? parent.getParent() : null;
    if (!(parent instanceof XmlTag)) {
        return false;
    }
    DomElement domElement = DomManager.getDomManager(element.getProject()).getDomElement((XmlTag) parent);
    if (domElement instanceof AndroidDomElement) {
        return inEnglish(element);
    }
    return false;
}
Also used : DomElement(com.intellij.util.xml.DomElement) AndroidDomElement(org.jetbrains.android.dom.AndroidDomElement) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) AndroidDomElement(org.jetbrains.android.dom.AndroidDomElement) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Example 30 with DomElement

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

the class AndroidFindUsagesHandlerFactory method correctResourceElement.

@Nullable
private static PsiElement correctResourceElement(PsiElement element) {
    if (element instanceof XmlElement && !(element instanceof XmlFile)) {
        XmlTag tag = element instanceof XmlTag ? (XmlTag) element : PsiTreeUtil.getParentOfType(element, XmlTag.class);
        DomElement domElement = DomManager.getDomManager(element.getProject()).getDomElement(tag);
        if (domElement instanceof ResourceElement) {
            return tag;
        }
        return null;
    }
    return element;
}
Also used : ResourceElement(org.jetbrains.android.dom.resources.ResourceElement) DomElement(com.intellij.util.xml.DomElement) Nullable(org.jetbrains.annotations.Nullable)

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