Search in sources :

Example 1 with JSDocTag

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

the class AngularJSDocumentationProvider method getUrlFor.

@Override
public List<String> getUrlFor(PsiElement element, PsiElement originalElement) {
    if (element instanceof JSImplicitElement)
        element = element.getParent();
    if (element instanceof JSDocComment) {
        JSDocTag ngdocTag = null;
        JSDocTag nameTag = null;
        for (JSDocTag tag : ((JSDocComment) element).getTags()) {
            if ("ngdoc".equals(tag.getName()))
                ngdocTag = tag;
            else if ("name".equals(tag.getName()))
                nameTag = tag;
        }
        if (ngdocTag != null && nameTag != null) {
            final JSDocTagValue nameValue = nameTag.getValue();
            String name = nameValue != null ? nameValue.getText() : null;
            if (name != null)
                name = name.substring(name.indexOf(':') + 1);
            if (name != null && AngularIndexUtil.resolve(element.getProject(), AngularDirectivesDocIndex.KEY, DirectiveUtil.getAttributeName(name)) != null) {
                final String directiveName = DirectiveUtil.attributeToDirective(null, name);
                return Collections.singletonList("http://docs.angularjs.org/api/ng/directive/" + directiveName);
            }
        }
    }
    return null;
}
Also used : JSDocComment(com.intellij.lang.javascript.psi.jsdoc.JSDocComment) JSDocTagValue(com.intellij.lang.javascript.psi.jsdoc.JSDocTagValue) JSDocTag(com.intellij.lang.javascript.psi.jsdoc.JSDocTag) JSImplicitElement(com.intellij.lang.javascript.psi.stubs.JSImplicitElement)

Example 2 with JSDocTag

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

the class AngularJSIndexingHandler method processJSDocComment.

@Override
public JSElementIndexingData processJSDocComment(@NotNull final JSDocComment comment, @Nullable JSElementIndexingData outData) {
    JSDocTag ngdocTag = null;
    JSDocTag nameTag = null;
    for (JSDocTag tag : comment.getTags()) {
        if ("ngdoc".equals(tag.getName()))
            ngdocTag = tag;
        else if ("name".equals(tag.getName()))
            nameTag = tag;
    }
    if (ngdocTag != null && nameTag != null) {
        final JSDocTagValue nameValue = nameTag.getValue();
        String name = nameValue != null ? nameValue.getText() : null;
        if (name != null)
            name = name.substring(name.indexOf(':') + 1);
        String ngdocValue = null;
        PsiElement nextSibling = ngdocTag.getNextSibling();
        if (nextSibling instanceof PsiWhiteSpace)
            nextSibling = nextSibling.getNextSibling();
        if (nextSibling != null && nextSibling.getNode().getElementType() == JSDocTokenTypes.DOC_COMMENT_DATA) {
            ngdocValue = nextSibling.getText();
        }
        if (ngdocValue != null && name != null) {
            final String[] commentLines = StringUtil.splitByLines(comment.getText());
            final boolean directive = ngdocValue.contains(DIRECTIVE);
            final boolean component = ngdocValue.contains(COMPONENT);
            if (directive || component) {
                final String restrictions = calculateRestrictions(commentLines, directive ? DEFAULT_RESTRICTIONS : "E");
                if (outData == null)
                    outData = new JSElementIndexingDataImpl();
                addImplicitElements(comment, directive ? DIRECTIVE : COMPONENT, AngularDirectivesDocIndex.KEY, name, restrictions, outData);
            } else if (ngdocValue.contains(FILTER)) {
                if (outData == null)
                    outData = new JSElementIndexingDataImpl();
                addImplicitElements(comment, FILTER, AngularFilterIndex.KEY, name, null, outData);
            }
        }
    }
    return outData;
}
Also used : JSDocTagValue(com.intellij.lang.javascript.psi.jsdoc.JSDocTagValue) JSElementIndexingDataImpl(com.intellij.lang.javascript.psi.stubs.impl.JSElementIndexingDataImpl) JSDocTag(com.intellij.lang.javascript.psi.jsdoc.JSDocTag) PsiElement(com.intellij.psi.PsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace)

Aggregations

JSDocTag (com.intellij.lang.javascript.psi.jsdoc.JSDocTag)2 JSDocTagValue (com.intellij.lang.javascript.psi.jsdoc.JSDocTagValue)2 JSDocComment (com.intellij.lang.javascript.psi.jsdoc.JSDocComment)1 JSImplicitElement (com.intellij.lang.javascript.psi.stubs.JSImplicitElement)1 JSElementIndexingDataImpl (com.intellij.lang.javascript.psi.stubs.impl.JSElementIndexingDataImpl)1 PsiElement (com.intellij.psi.PsiElement)1 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)1