Search in sources :

Example 81 with XmlElementDescriptor

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

the class ActionScriptImportHandler method _resolveTypeName.

// TODO _str should be JSReferenceExpression for caching!
@Nullable
private JSImportedElementResolveResult _resolveTypeName(@Nullable final String _name, @NotNull PsiElement context) {
    String name = _name;
    if (name == null)
        return null;
    JSResolveUtil.GenericSignature genericSignature = JSResolveUtil.extractGenericSignature(name);
    if (genericSignature != null) {
        name = genericSignature.elementType;
    }
    final Ref<JSImportedElementResolveResult> resultRef = new Ref<>();
    final String name1 = name;
    JSResolveUtil.walkOverStructure(context, context1 -> {
        JSImportedElementResolveResult resolved = null;
        if (context1 instanceof XmlBackedJSClassImpl) {
            XmlTag rootTag = ((XmlBackedJSClassImpl) context1).getParent();
            if (rootTag != null && name1.equals(rootTag.getLocalName())) {
                final XmlElementDescriptor descriptor = rootTag.getDescriptor();
                PsiElement element = descriptor != null ? descriptor.getDeclaration() : null;
                if (element instanceof XmlFile) {
                    element = XmlBackedJSClassFactory.getXmlBackedClass((XmlFile) element);
                }
                final String s = element instanceof JSClass ? ((JSClass) element).getQualifiedName() : rootTag.getLocalName();
                resolved = new JSImportedElementResolveResult(s);
            } else {
                resolved = resolveTypeNameUsingImports(name1, context1);
            }
        } else if (context1 instanceof JSQualifiedNamedElement) {
            if (context1 instanceof JSClass && name1.equals(context1.getName())) {
                resolved = new JSImportedElementResolveResult(((JSQualifiedNamedElement) context1).getQualifiedName());
            } else {
                resolved = resolveTypeNameUsingImports(name1, context1);
                if (resolved == null && context1.getParent() instanceof JSFile) {
                    final String qName = ((JSQualifiedNamedElement) context1).getQualifiedName();
                    final String packageName = qName == null ? "" : context1 instanceof JSPackageStatement ? qName + "." : qName.substring(0, qName.lastIndexOf('.') + 1);
                    if (packageName.length() != 0) {
                        final PsiElement byQName = JSClassResolver.findClassFromNamespace(packageName + name1, context1);
                        if (byQName instanceof JSQualifiedNamedElement) {
                            resolved = new JSImportedElementResolveResult(((JSQualifiedNamedElement) byQName).getQualifiedName());
                        }
                    }
                }
            }
        } else {
            resolved = resolveTypeNameUsingImports(name1, context1);
            PsiElement contextOfContext;
            if (resolved == null && context1 instanceof JSFile && (contextOfContext = context1.getContext()) != null) {
                XmlBackedJSClassImpl clazz = contextOfContext instanceof XmlElement ? (XmlBackedJSClassImpl) XmlBackedJSClassImpl.getContainingComponent((XmlElement) contextOfContext) : null;
                if (clazz != null) {
                    SinkResolveProcessor r = new SinkResolveProcessor(name1, new ResolveResultSink(null, name1));
                    r.setForceImportsForPlace(true);
                    boolean b = clazz.doImportFromScripts(r, clazz);
                    if (!b) {
                        PsiElement resultFromProcessor = r.getResult();
                        JSQualifiedNamedElement clazzFromComponent = resultFromProcessor instanceof JSQualifiedNamedElement ? (JSQualifiedNamedElement) resultFromProcessor : null;
                        if (clazzFromComponent != null) {
                            resolved = new JSImportedElementResolveResult(clazzFromComponent.getQualifiedName(), clazz, null);
                        }
                    }
                }
            }
        }
        if (resolved != null) {
            resultRef.set(resolved);
            return false;
        }
        if (context1 instanceof JSPackageStatement)
            return false;
        return true;
    });
    JSImportedElementResolveResult result = resultRef.get();
    if (genericSignature != null && result != null) {
        // TODO: more than one type parameter
        StringBuilder genericSignatureBuffer = new StringBuilder();
        genericSignatureBuffer.append(".<");
        genericSignatureBuffer.append(resolveTypeName(genericSignature.genericType, context).getQualifiedName());
        genericSignatureBuffer.append(">");
        result = result.appendSignature(genericSignatureBuffer.toString());
    }
    return result;
}
Also used : XmlBackedJSClassImpl(com.intellij.lang.javascript.flex.XmlBackedJSClassImpl) XmlFile(com.intellij.psi.xml.XmlFile) JSPackageStatement(com.intellij.lang.javascript.psi.ecmal4.JSPackageStatement) JSQualifiedNamedElement(com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement) Ref(com.intellij.openapi.util.Ref) XmlElement(com.intellij.psi.xml.XmlElement) JSFile(com.intellij.lang.javascript.psi.JSFile) 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 82 with XmlElementDescriptor

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

the class FxDefinitionBackedDescriptor method getClassBackedDescriptor.

@Nullable
private ClassBackedElementDescriptor getClassBackedDescriptor() {
    final XmlTag tag = PsiTreeUtil.getParentOfType(getDeclaration(), XmlTag.class);
    final XmlTag[] subTags = tag == null ? XmlTag.EMPTY : tag.getSubTags();
    if (subTags.length == 1) {
        final XmlElementDescriptor descriptor = subTags[0].getDescriptor();
        return descriptor instanceof ClassBackedElementDescriptor ? (ClassBackedElementDescriptor) descriptor : null;
    }
    return null;
}
Also used : XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 83 with XmlElementDescriptor

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

the class MxmlTagNameReference method fixSubTagsPrefixes.

private static void fixSubTagsPrefixes(final XmlTag tag, final String oldPrefix, final String newPrefix) {
    final XmlElementDescriptor descriptor = tag.getDescriptor();
    if (!(descriptor instanceof ClassBackedElementDescriptor)) {
        return;
    }
    for (final XmlTag subTag : tag.getSubTags()) {
        if (Comparing.strEqual(subTag.getNamespacePrefix(), oldPrefix) && subTag.getDescriptor() == null) {
            final String oldSubTagName = subTag.getName();
            subTag.setName(StringUtil.isEmpty(newPrefix) ? subTag.getLocalName() : (newPrefix + ":" + subTag.getLocalName()));
            final XmlElementDescriptor subTagDescriptor = descriptor.getElementDescriptor(subTag, tag);
            if (!(subTagDescriptor instanceof AnnotationBackedDescriptor)) {
                subTag.setName(oldSubTagName);
            }
        }
    }
}
Also used : XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) AnnotationBackedDescriptor(com.intellij.lang.javascript.flex.AnnotationBackedDescriptor) XmlTag(com.intellij.psi.xml.XmlTag)

Example 84 with XmlElementDescriptor

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

the class XmlTagValueProvider method getSubstituted.

@Override
public CharSequence getSubstituted() {
    CharSequence v = getDisplay(tag.getValue().getChildren());
    if (v == EMPTY) {
        return EMPTY;
    }
    XmlElementDescriptor descriptor = tag.getDescriptor();
    // may be ClassBackedElementDescriptor for fx:String: <TextArea><text><fx:String>sfsdsd</fx:String></text></TextArea>
    if (descriptor instanceof AnnotationBackedDescriptor && ((AnnotationBackedDescriptor) descriptor).isCollapseWhiteSpace()) {
        return CharMatcher.WHITESPACE.trimAndCollapseFrom(v, ' ');
    } else {
        return v;
    }
}
Also used : XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) AnnotationBackedDescriptor(com.intellij.lang.javascript.flex.AnnotationBackedDescriptor)

Example 85 with XmlElementDescriptor

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

the class MxmlWriter method write.

@Nullable
public Pair<ProjectComponentReferenceCounter, List<RangeMarker>> write(XmlFile psiFile) throws IOException {
    document = MxmlUtil.getDocumentAndWaitIfNotCommitted(psiFile);
    final AccessToken token = ReadAction.start();
    try {
        VirtualFile virtualFile = psiFile.getVirtualFile();
        LOG.assertTrue(virtualFile != null);
        problemsHolder.setCurrentFile(virtualFile);
        XmlTag tag = psiFile.getRootTag();
        XmlElementDescriptor untypedDescriptor = tag == null ? null : tag.getDescriptor();
        final ClassBackedElementDescriptor descriptor;
        if (untypedDescriptor instanceof ClassBackedElementDescriptor) {
            descriptor = (ClassBackedElementDescriptor) untypedDescriptor;
        } else {
            return null;
        }
        final Trinity<Integer, String, Condition<AnnotationBackedDescriptor>> effectiveClassInfo;
        try {
            PsiElement declaration = descriptor.getDeclaration();
            if (declaration == null) {
                return null;
            }
            effectiveClassInfo = MxmlUtil.computeEffectiveClass(tag, declaration, projectComponentReferenceCounter, true);
        } catch (InvalidPropertyException e) {
            problemsHolder.add(e);
            return null;
        }
        if (effectiveClassInfo.first == -1) {
            out.write(Amf3Types.OBJECT);
            writer.mxmlObjectHeader(effectiveClassInfo.second == null ? descriptor.getQualifiedName() : effectiveClassInfo.second);
        } else {
            writer.documentReference(effectiveClassInfo.first);
            out.allocateClearShort();
        }
        processElements(tag, null, false, -1, out.size() - 2, true, effectiveClassInfo.third);
        writer.endObject();
        if (stateWriter != null) {
            stateWriter.write();
            hasStates = false;
        } else {
            out.write(0);
        }
        injectedASWriter.write();
        writer.writeMessageHeader(projectComponentReferenceCounter);
        return Pair.create(projectComponentReferenceCounter, rangeMarkers);
    } finally {
        token.finish();
        problemsHolder.setCurrentFile(null);
        writer.resetAfterMessage();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Condition(com.intellij.openapi.util.Condition) ClassBackedElementDescriptor(com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor) AccessToken(com.intellij.openapi.application.AccessToken) InvalidPropertyException(com.intellij.flex.uiDesigner.InvalidPropertyException) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

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