Search in sources :

Example 56 with XmlElementDescriptor

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

the class CreateFlexSkinIntention method getHostComponentClass.

@Nullable
private JSClass getHostComponentClass() {
    final XmlTag tag = myElement instanceof XmlTag ? ((XmlTag) myElement).getParentTag() : myElement instanceof XmlAttributeValue ? (XmlTag) myElement.getParent().getParent() : null;
    final XmlElementDescriptor descriptor = tag == null ? null : tag.getDescriptor();
    if (descriptor instanceof ClassBackedElementDescriptor) {
        final PsiElement declaration = descriptor.getDeclaration();
        if (declaration instanceof JSClass) {
            return (JSClass) declaration;
        }
    }
    return null;
}
Also used : ClassBackedElementDescriptor(com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 57 with XmlElementDescriptor

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

the class AngularJSErrorFilter method shouldHighlightErrorElement.

@Override
public boolean shouldHighlightErrorElement(@NotNull PsiErrorElement error) {
    final Project project = error.getProject();
    final Language language = error.getLanguage();
    if ("CSS".equals(language.getID()) && PsiTreeUtil.getParentOfType(error, XmlAttribute.class) != null && AngularIndexUtil.hasAngularJS(project)) {
        final PsiFile file = error.getContainingFile();
        PsiErrorElement nextError = error;
        while (nextError != null) {
            if (hasAngularInjectionAt(project, file, nextError.getTextOffset()))
                return false;
            nextError = PsiTreeUtil.getNextSiblingOfType(nextError, PsiErrorElement.class);
        }
    }
    if (HTMLLanguage.INSTANCE.is(language) && error.getErrorDescription().endsWith("not closed")) {
        final PsiElement parent = error.getParent();
        final XmlElementDescriptor descriptor = parent instanceof XmlTag ? ((XmlTag) parent).getDescriptor() : null;
        return !(descriptor instanceof AngularJSTagDescriptor);
    }
    if (XMLLanguage.INSTANCE.is(language) && error.getErrorDescription().equals(XmlErrorMessages.message("xml.parsing.unexpected.tokens"))) {
        return !error.getParent().getLanguage().is(Angular2HTMLLanguage.INSTANCE);
    }
    return true;
}
Also used : Project(com.intellij.openapi.project.Project) PsiErrorElement(com.intellij.psi.PsiErrorElement) XmlAttribute(com.intellij.psi.xml.XmlAttribute) Language(com.intellij.lang.Language) Angular2HTMLLanguage(org.angularjs.html.Angular2HTMLLanguage) XMLLanguage(com.intellij.lang.xml.XMLLanguage) HTMLLanguage(com.intellij.lang.html.HTMLLanguage) PsiFile(com.intellij.psi.PsiFile) AngularJSTagDescriptor(org.angularjs.codeInsight.tags.AngularJSTagDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Example 58 with XmlElementDescriptor

use of com.intellij.xml.XmlElementDescriptor 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 59 with XmlElementDescriptor

use of com.intellij.xml.XmlElementDescriptor in project android by JetBrains.

the class AndroidDomElementDescriptorProvider method getDescriptor.

@Nullable
private static XmlElementDescriptor getDescriptor(DomElement domElement, XmlTag tag, @Nullable String baseClassName) {
    AndroidFacet facet = AndroidFacet.getInstance(domElement);
    if (facet == null)
        return null;
    final String name = domElement.getXmlTag().getName();
    final PsiClass aClass = baseClassName != null ? LayoutViewClassUtils.findClassByTagName(facet, name, baseClassName) : null;
    final Icon icon = getIconForTag(name, domElement);
    final DefinesXml definesXml = domElement.getAnnotation(DefinesXml.class);
    if (definesXml != null) {
        return new AndroidXmlTagDescriptor(aClass, new DomElementXmlDescriptor(domElement), baseClassName, icon);
    }
    final PsiElement parent = tag.getParent();
    if (parent instanceof XmlTag) {
        final XmlElementDescriptor parentDescriptor = ((XmlTag) parent).getDescriptor();
        if (parentDescriptor != null && parentDescriptor instanceof AndroidXmlTagDescriptor) {
            XmlElementDescriptor domDescriptor = parentDescriptor.getElementDescriptor(tag, (XmlTag) parent);
            if (domDescriptor != null) {
                return new AndroidXmlTagDescriptor(aClass, domDescriptor, baseClassName, icon);
            }
        }
    }
    return null;
}
Also used : DomElementXmlDescriptor(com.intellij.xml.impl.dom.DomElementXmlDescriptor) PsiClass(com.intellij.psi.PsiClass) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) DefinesXml(com.intellij.util.xml.DefinesXml) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 60 with XmlElementDescriptor

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

the class FlexSchemaHandler method getAvailableNamespaces.

@NotNull
@Override
public Set<String> getAvailableNamespaces(@NotNull XmlFile _file, @Nullable @NonNls final String tagName) {
    // tagName == null => tag name completion
    // tagName != null => guess namespace of unresolved tag
    PsiFile originalFile = _file.getOriginalFile();
    if (originalFile instanceof XmlFile)
        _file = (XmlFile) originalFile;
    final XmlFile file = _file;
    final Project project = file.getProject();
    final Module module = ProjectRootManager.getInstance(project).getFileIndex().getModuleForFile(file.getVirtualFile());
    final Collection<String> illegalNamespaces = getIllegalNamespaces(file);
    final Set<String> result = new THashSet<>();
    final Set<String> componentsThatHaveNotPackageBackedNamespace = new THashSet<>();
    for (final String namespace : CodeContextHolder.getInstance(project).getNamespaces(module)) {
        if (!CodeContext.isPackageBackedNamespace(namespace) && !illegalNamespaces.contains(namespace)) {
            // package backed namespaces will be added later from JSPackageIndex
            if (tagName == null) {
                result.add(namespace);
            } else {
                final XmlElementDescriptor descriptor = CodeContext.getContext(namespace, module).getElementDescriptor(tagName, (XmlTag) null);
                if (descriptor != null) {
                    result.add(namespace);
                    componentsThatHaveNotPackageBackedNamespace.add(descriptor.getQualifiedName());
                }
            }
        }
    }
    if (tagName == null && !illegalNamespaces.contains(JavaScriptSupportLoader.MXML_URI)) {
        result.add(JavaScriptSupportLoader.MXML_URI);
    }
    if (XmlBackedJSClassImpl.SCRIPT_TAG_NAME.equals(tagName) || "Style".equals(tagName))
        return result;
    if (DumbService.isDumb(project))
        return result;
    if (tagName == null) {
        FileBasedIndex.getInstance().processAllKeys(JSPackageIndex.INDEX_ID, packageName -> {
            result.add(StringUtil.isEmpty(packageName) ? "*" : packageName + ".*");
            return true;
        }, project);
    } else {
        final GlobalSearchScope scopeWithLibs = module != null ? GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module) : GlobalSearchScope.allScope(project);
        for (JSQualifiedNamedElement element : JSResolveUtil.findElementsByName(tagName, project, scopeWithLibs, false)) {
            if (element instanceof JSClass && CodeContext.hasDefaultConstructor((JSClass) element)) {
                final String packageName = StringUtil.getPackageName(element.getQualifiedName());
                if (!componentsThatHaveNotPackageBackedNamespace.contains(StringUtil.getQualifiedName(packageName, tagName))) {
                    result.add(StringUtil.isEmpty(packageName) ? "*" : packageName + ".*");
                }
            }
        }
    }
    final GlobalSearchScope scopeWithoutLibs = module != null ? GlobalSearchScope.moduleWithDependenciesScope(module) : GlobalSearchScope.allScope(project);
    // packages that contain *.mxml files and do not contain *.as are not retrieved from JSPackageIndex
    FlexResolveHelper.processAllMxmlAndFxgFiles(scopeWithoutLibs, project, new FlexResolveHelper.MxmlAndFxgFilesProcessor() {

        public void addDependency(final PsiDirectory directory) {
        }

        public boolean processFile(final VirtualFile file, final VirtualFile root) {
            if (tagName == null || tagName.equals(file.getNameWithoutExtension())) {
                final String packageName = VfsUtilCore.getRelativePath(file.getParent(), root, '.');
                if (packageName != null && (tagName == null || !componentsThatHaveNotPackageBackedNamespace.contains(StringUtil.getQualifiedName(packageName, tagName)))) {
                    result.add(StringUtil.isEmpty(packageName) ? "*" : packageName + ".*");
                }
            }
            return true;
        }
    }, tagName);
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlFile(com.intellij.psi.xml.XmlFile) FlexResolveHelper(com.intellij.javascript.flex.resolve.FlexResolveHelper) JSQualifiedNamedElement(com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement) THashSet(gnu.trove.THashSet) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiDirectory(com.intellij.psi.PsiDirectory) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) MxmlJSClass(com.intellij.javascript.flex.mxml.MxmlJSClass) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)159 XmlTag (com.intellij.psi.xml.XmlTag)88 XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)60 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)54 PsiElement (com.intellij.psi.PsiElement)23 XmlFile (com.intellij.psi.xml.XmlFile)23 Nullable (org.jetbrains.annotations.Nullable)23 AnyXmlElementDescriptor (com.intellij.xml.impl.schema.AnyXmlElementDescriptor)22 PsiFile (com.intellij.psi.PsiFile)11 ArrayList (java.util.ArrayList)11 XmlAttribute (com.intellij.psi.xml.XmlAttribute)10 NotNull (org.jetbrains.annotations.NotNull)10 ClassBackedElementDescriptor (com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor)7 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)7 Project (com.intellij.openapi.project.Project)7 HtmlTag (com.intellij.psi.html.HtmlTag)7 AnnotationBackedDescriptor (com.intellij.lang.javascript.flex.AnnotationBackedDescriptor)5 XmlDocument (com.intellij.psi.xml.XmlDocument)5 DElementPattern (org.kohsuke.rngom.digested.DElementPattern)5 InvalidPropertyException (com.intellij.flex.uiDesigner.InvalidPropertyException)4