Search in sources :

Example 1 with JSDocInfo

use of com.google.javascript.rhino.JSDocInfo in project ow by vtst.

the class JSElementInfo method writeFunctionParameterInfo.

// **************************************************************************
// Function parameters
private void writeFunctionParameterInfo(Node functionNode, String parameterName) {
    JSDocInfo docInfo = functionNode.getJSDocInfo();
    if (docInfo != null) {
        String description = docInfo.getDescriptionForParameter(parameterName);
        if (description != null) {
            buf.append(description);
            buf.append("<p>");
        }
        openSectionAndItem(messages.getString("jsdoc_type"));
        buf.append("<em>");
        buf.append(getParameterNodeJSDocType(node));
        buf.append("</em>");
        closeSectionAndItem();
    }
}
Also used : JSDocInfo(com.google.javascript.rhino.JSDocInfo)

Example 2 with JSDocInfo

use of com.google.javascript.rhino.JSDocInfo in project ow by vtst.

the class JSElementInfo method writeFunctionInfo.

/**
   * @param fnNode A node for a function for which to generate a type annotation
   */
private void writeFunctionInfo(Node fnNode) {
    if (fnNode == null)
        return;
    Preconditions.checkState(fnNode.getType() == Token.FUNCTION);
    JSDocInfo fnDocInfo = NodeUtil.getFunctionJSDocInfo(fnNode);
    JSType type = fnNode.getJSType();
    if (type == null || type.isUnknownType()) {
        return;
    }
    FunctionType funType = type.toMaybeFunctionType();
    //     NAME param2
    if (fnNode != null) {
        openSection(messages.getString("jsdoc_parameters"));
        Node paramNode = NodeUtil.getFunctionParameters(fnNode).getFirstChild();
        // Param types
        for (Node n : funType.getParameters()) {
            // Bail out if the paramNode is not there.
            if (paramNode == null) {
                break;
            }
            openItem();
            writeParameter(paramNode, n, fnDocInfo.getDescriptionForParameter(paramNode.getString()));
            closeItem();
            paramNode = paramNode.getNext();
        }
        closeSection();
    }
    // Return type
    JSType retType = funType.getReturnType();
    if (retType != null && !retType.isUnknownType() && !retType.isEmptyType()) {
        openSectionAndItem(messages.getString("jsdoc_return"));
        writeType(retType);
        writeTypeDescription(fnDocInfo.getReturnDescription());
        closeSectionAndItem();
    }
    // Constructor/interface
    if (funType.isConstructor() || funType.isInterface()) {
        FunctionType superConstructor = funType.getSuperClassConstructor();
        if (superConstructor != null) {
            ObjectType superInstance = funType.getSuperClassConstructor().getInstanceType();
            if (!superInstance.toString().equals("Object")) {
                openSectionAndItem(messages.getString("jsdoc_extends"));
                buf.append(superInstance.toString());
                closeSectionAndItem();
            }
        }
        if (funType.isInterface()) {
            for (ObjectType interfaceType : funType.getExtendedInterfaces()) {
                openSectionAndItem(messages.getString("jsdoc_extends"));
                buf.append(interfaceType.toString());
                closeSectionAndItem();
            }
        }
        // Avoid duplicates, add implemented type to a set first
        Set<String> interfaces = Sets.newTreeSet();
        for (ObjectType interfaze : funType.getImplementedInterfaces()) {
            interfaces.add(interfaze.toString());
        }
        if (!interfaces.isEmpty()) {
            openSectionAndItem(messages.getString("jsdoc_implements"));
            boolean first = true;
            for (String interfaze : interfaces) {
                if (first)
                    first = false;
                else
                    buf.append("<p>");
                buf.append(interfaze.toString());
            }
            closeSectionAndItem();
        }
    }
}
Also used : ObjectType(com.google.javascript.rhino.jstype.ObjectType) JSType(com.google.javascript.rhino.jstype.JSType) FunctionType(com.google.javascript.rhino.jstype.FunctionType) Node(com.google.javascript.rhino.Node) JSDocInfo(com.google.javascript.rhino.JSDocInfo)

Aggregations

JSDocInfo (com.google.javascript.rhino.JSDocInfo)2 Node (com.google.javascript.rhino.Node)1 FunctionType (com.google.javascript.rhino.jstype.FunctionType)1 JSType (com.google.javascript.rhino.jstype.JSType)1 ObjectType (com.google.javascript.rhino.jstype.ObjectType)1