Search in sources :

Example 11 with PsiMetaData

use of com.intellij.psi.meta.PsiMetaData in project intellij-plugins by JetBrains.

the class MxmlReferenceContributor method createReferenceProviderForTagOrAttributeExpectingJSClass.

private static PsiReferenceProvider createReferenceProviderForTagOrAttributeExpectingJSClass(final Function<PsiReference, LocalQuickFix[]> quickFixProvider) {
    return new PsiReferenceProvider() {

        @NotNull
        public PsiReference[] getReferencesByElement(@NotNull final PsiElement element, @NotNull final ProcessingContext context) {
            final PsiMetaData descriptor;
            final String name;
            if (element instanceof XmlTag) {
                descriptor = ((XmlTag) element).getDescriptor();
                name = ((XmlTag) element).getLocalName();
            } else if (element instanceof XmlAttributeValue) {
                final XmlAttribute xmlAttribute = PsiTreeUtil.getParentOfType(element, XmlAttribute.class);
                descriptor = xmlAttribute == null ? null : xmlAttribute.getDescriptor();
                name = xmlAttribute == null ? "" : xmlAttribute.getName();
            } else {
                assert false : element;
                return PsiReference.EMPTY_ARRAY;
            }
            if (!(descriptor instanceof AnnotationBackedDescriptor))
                return PsiReference.EMPTY_ARRAY;
            final String type = ((AnnotationBackedDescriptor) descriptor).getType();
            if (!FlexReferenceContributor.isClassReferenceType(type))
                return PsiReference.EMPTY_ARRAY;
            final Pair<String, TextRange> trimmedValueAndRange = getTrimmedValueAndRange((XmlElement) element);
            if (trimmedValueAndRange.second.getStartOffset() == 0)
                return PsiReference.EMPTY_ARRAY;
            if (trimmedValueAndRange.first.indexOf('{') != -1 || trimmedValueAndRange.first.indexOf('@') != -1)
                return PsiReference.EMPTY_ARRAY;
            final JSReferenceSet jsReferenceSet = new JSReferenceSet(element, trimmedValueAndRange.first, trimmedValueAndRange.second.getStartOffset(), false, true) {

                @Override
                protected JSTextReference createTextReference(String s, int offset, boolean methodRef) {
                    return new MyJSTextReference(this, s, offset, methodRef, quickFixProvider);
                }
            };
            if (SKIN_CLASS_ATTR_NAME.equals(name)) {
                jsReferenceSet.setBaseClassFqns(Collections.singletonList(UI_COMPONENT_FQN));
            }
            return jsReferenceSet.getReferences();
        }
    };
}
Also used : TextRange(com.intellij.openapi.util.TextRange) NotNull(org.jetbrains.annotations.NotNull) AnnotationBackedDescriptor(com.intellij.lang.javascript.flex.AnnotationBackedDescriptor) JSReferenceSet(com.intellij.lang.javascript.psi.impl.JSReferenceSet) PsiMetaData(com.intellij.psi.meta.PsiMetaData)

Example 12 with PsiMetaData

use of com.intellij.psi.meta.PsiMetaData in project intellij-plugins by JetBrains.

the class PropertyProcessor method writeClassFactory.

private void writeClassFactory(XmlElementValueProvider valueProvider) throws InvalidPropertyException {
    if (valueProvider instanceof XmlTagValueProvider) {
        XmlTag tag = ((XmlTagValueProvider) valueProvider).getTag();
        XmlTag[] subTags = tag.getSubTags();
        if (subTags.length > 0) {
            processFxComponent(subTags[0], true);
            return;
        }
    }
    String className = valueProvider.getTrimmed();
    if (writeFxComponentReferenceIfProcessed(className) || writeReferenceIfReferenced(className)) {
        return;
    }
    final JSClass jsClass = valueProvider.getJsClass();
    if (jsClass == null) {
        throw new InvalidPropertyException(valueProvider.getElement(), "unresolved.class", valueProvider.getTrimmed());
    }
    final Trinity<Integer, String, Condition<AnnotationBackedDescriptor>> effectiveClassInfo;
    final PsiElement parent = jsClass.getNavigationElement().getParent();
    if (parent instanceof XmlTag && MxmlUtil.isComponentLanguageTag((XmlTag) parent)) {
        // if referenced by inner class name, but inner fx component is not yet processed
        if (parent.getContainingFile().equals(valueProvider.getElement().getContainingFile())) {
            processFxComponent((XmlTag) parent, false);
            return;
        } else {
            effectiveClassInfo = new Trinity<>(-1, "mx.core.UIComponent", null);
        }
    } else {
        effectiveClassInfo = MxmlUtil.computeEffectiveClass(valueProvider.getElement(), jsClass, mxmlWriter.projectComponentReferenceCounter, false);
    }
    if (effectiveClassInfo.first == -1) {
        if (effectiveClassInfo.second != null) {
            if (effectiveClassInfo.second.equals("mx.core.UIComponent")) {
                PsiMetaData psiMetaData = valueProvider.getPsiMetaData();
                if (psiMetaData != null && psiMetaData.getName().equals("itemRenderer") && MxmlUtil.isPropertyOfSparkDataGroup((AnnotationBackedDescriptor) psiMetaData)) {
                    className = MxmlUtil.UNKNOWN_ITEM_RENDERER_CLASS_NAME;
                } else {
                    className = MxmlUtil.UNKNOWN_COMPONENT_CLASS_NAME;
                }
            } else {
                className = effectiveClassInfo.second;
            }
        }
        writeNonProjectUnreferencedClassFactory(className);
    } else {
        writer.documentFactoryReference(effectiveClassInfo.first);
    }
}
Also used : Condition(com.intellij.openapi.util.Condition) AnnotationBackedDescriptor(com.intellij.lang.javascript.flex.AnnotationBackedDescriptor) PsiMetaData(com.intellij.psi.meta.PsiMetaData) InvalidPropertyException(com.intellij.flex.uiDesigner.InvalidPropertyException) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement)

Example 13 with PsiMetaData

use of com.intellij.psi.meta.PsiMetaData in project intellij-community by JetBrains.

the class DescriptiveNameUtil method getDescriptiveName.

@NotNull
public static String getDescriptiveName(@NotNull PsiElement psiElement) {
    LOG.assertTrue(psiElement.isValid());
    if (psiElement instanceof PsiMetaOwner) {
        final PsiMetaOwner psiMetaOwner = (PsiMetaOwner) psiElement;
        final PsiMetaData metaData = psiMetaOwner.getMetaData();
        if (metaData != null)
            return getMetaDataName(metaData);
    }
    if (psiElement instanceof PsiFile) {
        return ((PsiFile) psiElement).getName();
    }
    final Language lang = psiElement.getLanguage();
    final FindUsagesProvider provider = LanguageFindUsages.INSTANCE.forLanguage(lang);
    assert provider != null : lang;
    return provider.getDescriptiveName(psiElement);
}
Also used : Language(com.intellij.lang.Language) PsiMetaData(com.intellij.psi.meta.PsiMetaData) PsiFile(com.intellij.psi.PsiFile) PsiMetaOwner(com.intellij.psi.meta.PsiMetaOwner) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with PsiMetaData

use of com.intellij.psi.meta.PsiMetaData in project intellij-community by JetBrains.

the class CompletionData method objectToLookupItem.

public static LookupElement objectToLookupItem(@NotNull final Object object) {
    if (object instanceof LookupElement)
        return (LookupElement) object;
    String s = null;
    TailType tailType = TailType.NONE;
    if (object instanceof PsiElement) {
        s = PsiUtilCore.getName((PsiElement) object);
    } else if (object instanceof PsiMetaData) {
        s = ((PsiMetaData) object).getName();
    } else if (object instanceof String) {
        s = (String) object;
    } else if (object instanceof Template) {
        s = ((Template) object).getKey();
    } else if (object instanceof PresentableLookupValue) {
        s = ((PresentableLookupValue) object).getPresentation();
    }
    if (s == null) {
        throw new AssertionError("Null string for object: " + object + " of class " + object.getClass());
    }
    LookupItem item = new LookupItem(object, s);
    if (object instanceof LookupValueWithUIHint && ((LookupValueWithUIHint) object).isBold()) {
        item.setBold();
    }
    item.setAttribute(LookupItem.TAIL_TYPE_ATTR, tailType);
    return item;
}
Also used : PsiMetaData(com.intellij.psi.meta.PsiMetaData) LookupValueWithUIHint(com.intellij.codeInsight.lookup.LookupValueWithUIHint) LookupItem(com.intellij.codeInsight.lookup.LookupItem) LookupElement(com.intellij.codeInsight.lookup.LookupElement) PresentableLookupValue(com.intellij.codeInsight.lookup.PresentableLookupValue) TailType(com.intellij.codeInsight.TailType) Template(com.intellij.codeInsight.template.Template)

Example 15 with PsiMetaData

use of com.intellij.psi.meta.PsiMetaData in project intellij-community by JetBrains.

the class AbstractQualifiedReference method bindToElement.

@Override
public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
    CheckUtil.checkWritable(this);
    if (isReferenceTo(element))
        return this;
    if (element instanceof PsiMethod) {
        final PsiMethod method = (PsiMethod) element;
        final String methodName = method.getName();
        if (isDirectlyVisible(method))
            return replaceReference(methodName);
        final AbstractQualifiedReference result = replaceReference(method.getContainingClass().getQualifiedName() + "." + methodName);
        final AbstractQualifiedReference qualifier = result.getQualifier();
        assert qualifier != null;
        qualifier.shortenReferences();
        return result;
    }
    if (element instanceof PsiClass) {
        return replaceReference(((PsiClass) element).getQualifiedName()).shortenReferences();
    }
    if (element instanceof PsiPackage) {
        return replaceReference(((PsiPackage) element).getQualifiedName());
    }
    if (element instanceof PsiMetaOwner) {
        final PsiMetaData metaData = ((PsiMetaOwner) element).getMetaData();
        if (metaData != null) {
            final String name = metaData.getName(this);
            if (name != null) {
                return replaceReference(name);
            }
        }
    }
    return this;
}
Also used : PsiMetaData(com.intellij.psi.meta.PsiMetaData) PsiMetaOwner(com.intellij.psi.meta.PsiMetaOwner)

Aggregations

PsiMetaData (com.intellij.psi.meta.PsiMetaData)24 PsiMetaOwner (com.intellij.psi.meta.PsiMetaOwner)10 XmlDocument (com.intellij.psi.xml.XmlDocument)5 NotNull (org.jetbrains.annotations.NotNull)5 PsiElement (com.intellij.psi.PsiElement)4 XmlFile (com.intellij.psi.xml.XmlFile)3 XmlTag (com.intellij.psi.xml.XmlTag)3 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)3 Nullable (org.jetbrains.annotations.Nullable)3 TailType (com.intellij.codeInsight.TailType)2 Template (com.intellij.codeInsight.template.Template)2 AnnotationBackedDescriptor (com.intellij.lang.javascript.flex.AnnotationBackedDescriptor)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PsiFile (com.intellij.psi.PsiFile)2 PsiNamedElement (com.intellij.psi.PsiNamedElement)2 IncorrectOperationException (com.intellij.util.IncorrectOperationException)2 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)2 XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)2 XmlNSDescriptorImpl (com.intellij.xml.impl.schema.XmlNSDescriptorImpl)2 JavaMethodCallElement (com.intellij.codeInsight.completion.JavaMethodCallElement)1