Search in sources :

Example 1 with JSDocReferenceSet

use of com.intellij.lang.javascript.psi.jsdoc.impl.JSDocReferenceSet in project intellij-plugins by JetBrains.

the class FlexDocumentationProvider method getDocumentationElementForLinkStatic.

@Nullable
private static PsiElement getDocumentationElementForLinkStatic(final PsiManager psiManager, String link, final PsiElement context) {
    final int delimiterIndex = link.lastIndexOf(':');
    final JavaScriptIndex index = JavaScriptIndex.getInstance(psiManager.getProject());
    String attributeType = null;
    String attributeName = null;
    for (Map.Entry<String, String> e : DOCUMENTED_ATTRIBUTES.entrySet()) {
        final String pattern = "." + e.getValue();
        if (link.contains(pattern)) {
            attributeType = e.getKey();
            attributeName = StringUtil.substringAfter(link, pattern);
            link = link.substring(0, link.indexOf(pattern));
            break;
        }
    }
    if (delimiterIndex != -1 && attributeType == null) {
        return resolveDocumentLink(psiManager, link, delimiterIndex);
    } else if (attributeType != null) {
        PsiElement clazz = ActionScriptClassResolver.findClassByQName(link, index, context != null ? ModuleUtilCore.findModuleForPsiElement(context) : null);
        if (!(clazz instanceof JSClass)) {
            return null;
        }
        return findNamedAttribute((JSClass) clazz, attributeType, attributeName);
    } else {
        PsiElement clazz = ActionScriptClassResolver.findClassByQName(link, index, context != null ? ModuleUtilCore.findModuleForPsiElement(context) : null);
        if (clazz == null && link.contains(".")) {
            String qname = link.substring(0, link.lastIndexOf('.'));
            clazz = ActionScriptClassResolver.findClassByQName(qname, index, context != null ? ModuleUtilCore.findModuleForPsiElement(context) : null);
            if (clazz instanceof JSClass) {
                JSClass jsClass = (JSClass) clazz;
                String member = link.substring(link.lastIndexOf('.') + 1);
                if (member.endsWith("()")) {
                    member = member.substring(0, member.length() - 2);
                    PsiElement result = findMethod(jsClass, member);
                    if (result == null) {
                        // user might refer to a property
                        result = findProperty(jsClass, member);
                    }
                    return result;
                } else {
                    PsiElement result = jsClass.findFieldByName(member);
                    if (result == null) {
                        result = findProperty(jsClass, member);
                    }
                    if (result == null) {
                        // user might forget brackets
                        result = findMethod(jsClass, member);
                    }
                    return result;
                }
            }
        }
        if (clazz instanceof JSVariable) {
            return clazz;
        }
        if (link.endsWith("()")) {
            link = link.substring(0, link.length() - 2);
            clazz = ActionScriptClassResolver.findClassByQName(link, index, context != null ? ModuleUtilCore.findModuleForPsiElement(context) : null);
            if (clazz instanceof JSFunction) {
                return clazz;
            }
        }
        if (clazz == null && context != null) {
            final PsiReference[] references = new JSDocReferenceSet(context, link, 0, false).getReferences();
            if (references.length > 0) {
                final PsiElement resolve = references[references.length - 1].resolve();
                if (resolve != null)
                    return resolve;
            }
        }
        return clazz;
    }
}
Also used : JavaScriptIndex(com.intellij.lang.javascript.index.JavaScriptIndex) JSDocReferenceSet(com.intellij.lang.javascript.psi.jsdoc.impl.JSDocReferenceSet) THashMap(gnu.trove.THashMap) Map(java.util.Map) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

JavaScriptIndex (com.intellij.lang.javascript.index.JavaScriptIndex)1 JSDocReferenceSet (com.intellij.lang.javascript.psi.jsdoc.impl.JSDocReferenceSet)1 THashMap (gnu.trove.THashMap)1 Map (java.util.Map)1 Nullable (org.jetbrains.annotations.Nullable)1