Search in sources :

Example 1 with JSDocInfoBuilder

use of com.google.javascript.rhino.JSDocInfoBuilder in project closure-compiler by google.

the class NodeUtil method createConstantJsDoc.

static JSDocInfo createConstantJsDoc() {
    JSDocInfoBuilder builder = new JSDocInfoBuilder(false);
    builder.recordConstancy();
    return builder.build();
}
Also used : JSDocInfoBuilder(com.google.javascript.rhino.JSDocInfoBuilder)

Example 2 with JSDocInfoBuilder

use of com.google.javascript.rhino.JSDocInfoBuilder in project closure-compiler by google.

the class PolymerClassRewriter method appendPropertiesToBlock.

/**
 * Appends all properties in the ClassDefinition to the prototype of the custom element.
 */
private void appendPropertiesToBlock(final PolymerClassDefinition cls, Node block, String basePath) {
    for (MemberDefinition prop : cls.props) {
        Node propertyNode = IR.exprResult(NodeUtil.newQName(compiler, basePath + prop.name.getString()));
        // If a property string is quoted, make sure the added prototype properties are also quoted
        if (prop.name.isQuotedString()) {
            continue;
        }
        propertyNode.useSourceInfoIfMissingFromForTree(prop.name);
        JSDocInfoBuilder info = JSDocInfoBuilder.maybeCopyFrom(prop.info);
        JSTypeExpression propType = PolymerPassStaticUtils.getTypeFromProperty(prop, compiler);
        if (propType == null) {
            return;
        }
        info.recordType(propType);
        propertyNode.getFirstChild().setJSDocInfo(info.build());
        block.addChildToBack(propertyNode);
    }
}
Also used : Node(com.google.javascript.rhino.Node) JSTypeExpression(com.google.javascript.rhino.JSTypeExpression) JSDocInfoBuilder(com.google.javascript.rhino.JSDocInfoBuilder) MemberDefinition(com.google.javascript.jscomp.PolymerPass.MemberDefinition)

Example 3 with JSDocInfoBuilder

use of com.google.javascript.rhino.JSDocInfoBuilder in project closure-compiler by google.

the class PolymerClassRewriter method makeReadOnlySetter.

/**
 * Adds the generated setter for a readonly property.
 * @see https://www.polymer-project.org/0.8/docs/devguide/properties.html#read-only
 */
private Node makeReadOnlySetter(String propName, String qualifiedPath) {
    String setterName = "_set" + propName.substring(0, 1).toUpperCase() + propName.substring(1);
    Node fnNode = IR.function(IR.name(""), IR.paramList(IR.name(propName)), IR.block());
    compiler.reportChangeToChangeScope(fnNode);
    Node exprResNode = IR.exprResult(IR.assign(NodeUtil.newQName(compiler, qualifiedPath + setterName), fnNode));
    JSDocInfoBuilder info = new JSDocInfoBuilder(true);
    // This is overriding a generated function which was added to the interface in
    // {@code addInterfaceExterns}.
    info.recordOverride();
    exprResNode.getFirstChild().setJSDocInfo(info.build());
    return exprResNode;
}
Also used : Node(com.google.javascript.rhino.Node) JSDocInfoBuilder(com.google.javascript.rhino.JSDocInfoBuilder)

Example 4 with JSDocInfoBuilder

use of com.google.javascript.rhino.JSDocInfoBuilder in project closure-compiler by google.

the class JsdocUtil method getConstJSDoc.

private static JSDocInfo getConstJSDoc(JSDocInfo oldJSDoc, JSTypeExpression newType) {
    JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(oldJSDoc);
    builder.recordType(newType);
    builder.recordConstancy();
    return builder.build();
}
Also used : JSDocInfoBuilder(com.google.javascript.rhino.JSDocInfoBuilder)

Example 5 with JSDocInfoBuilder

use of com.google.javascript.rhino.JSDocInfoBuilder in project closure-compiler by google.

the class JsdocUtil method mergeJsdocs.

static JSDocInfo mergeJsdocs(@Nullable JSDocInfo classicJsdoc, @Nullable JSDocInfo inlineJsdoc) {
    if (inlineJsdoc == null || !inlineJsdoc.hasType()) {
        return classicJsdoc;
    }
    JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(classicJsdoc);
    builder.recordType(inlineJsdoc.getType());
    return builder.build();
}
Also used : JSDocInfoBuilder(com.google.javascript.rhino.JSDocInfoBuilder)

Aggregations

JSDocInfoBuilder (com.google.javascript.rhino.JSDocInfoBuilder)40 Node (com.google.javascript.rhino.Node)27 JSTypeExpression (com.google.javascript.rhino.JSTypeExpression)18 TypeDeclarationNode (com.google.javascript.rhino.Node.TypeDeclarationNode)10 JSDocInfo (com.google.javascript.rhino.JSDocInfo)8 MemberDefinition (com.google.javascript.jscomp.PolymerPass.MemberDefinition)4 Visibility (com.google.javascript.rhino.JSDocInfo.Visibility)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 ClassDeclarationMetadata (com.google.javascript.jscomp.Es6RewriteClass.ClassDeclarationMetadata)1 FeatureSet (com.google.javascript.jscomp.parsing.parser.FeatureSet)1 TypeI (com.google.javascript.rhino.TypeI)1 TypeIRegistry (com.google.javascript.rhino.TypeIRegistry)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1