public JSTypeExpression copy() { return new JSTypeExpression(root.cloneTree(), sourceName); } }
/** * Constructs a new {@code JSTypeExpression}. * @param n A node. May be null. */ JSTypeExpression createJSTypeExpression(Node n) { return n == null ? null : new JSTypeExpression(n, getSourceName()); }
/** * Constructs a new {@code JSTypeExpression}. * @param n A node. May be null. */ JSTypeExpression createJSTypeExpression(Node n) { return n == null ? null : new JSTypeExpression(n, getSourceName()); }
public JSTypeExpression clone() { return new JSTypeExpression(root.cloneTree(), sourceName); } }
private static JSDocInfoBuilder makeBuilderWithType(@Nullable JSDocInfo oldJSDoc, Node typeAst) { JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(oldJSDoc); builder.recordType(new JSTypeExpression(typeAst, "<synthetic>")); return builder; }
private JSType evalNativeTypeExpr(Node ttlAst) { JSTypeExpression expr = new JSTypeExpression(getCallArgument(ttlAst, 0), VIRTUAL_FILE); return this.registry.evaluateTypeExpression(expr, this.typeEnv); }
private JSType evalNativeTypeExpr(Node ttlAst) { return new JSTypeExpression( getCallArgument(ttlAst, 0), "").evaluate(scope, typeRegistry); }
private static void setJsDocWithType(Node target, Node type) { JSDocInfoBuilder builder = new JSDocInfoBuilder(false); builder.recordType(new JSTypeExpression(type, "<ChromePass.java>")); target.setJSDocInfo(builder.build()); }
static JSType evaluateTypeString( AbstractCompiler compiler, String expression) throws InvalidRequirementSpec { Node typeNodes = JsDocInfoParser.parseTypeString(expression); if (typeNodes == null) { throw new InvalidRequirementSpec("bad type expression"); } JSTypeExpression typeExpr = new JSTypeExpression( typeNodes, "conformance"); return compiler.getTypeRegistry().evaluateTypeExpressionInGlobalScope(typeExpr); }
private JSDocInfo createUnknownTypeJsDocInfo() { JSDocInfoBuilder castToUnknownBuilder = new JSDocInfoBuilder(true); castToUnknownBuilder.recordType( new JSTypeExpression( JsDocInfoParser.parseTypeString("?"), "<ProcessClosurePrimitives.java>")); return castToUnknownBuilder.build(); }
static JSType evaluateTypeString( AbstractCompiler compiler, String expression) throws InvalidRequirementSpec { Node typeNodes = JsDocInfoParser.parseTypeString(expression); if (typeNodes == null) { throw new InvalidRequirementSpec("bad type expression"); } JSTypeExpression typeExpr = new JSTypeExpression( typeNodes, "conformance"); return typeExpr.evaluate(null, compiler.getTypeIRegistry()); }
/** * Make the given type expression into an optional type expression, * if possible. */ public static JSTypeExpression makeOptionalArg(JSTypeExpression expr) { if (expr.isOptionalArg() || expr.isVarArgs()) { return expr; } else { return new JSTypeExpression( new Node(Token.EQUALS, expr.root), expr.sourceName); } }
/** * Make the given type expression into an optional type expression, * if possible. */ public static JSTypeExpression makeOptionalArg(JSTypeExpression expr) { if (expr.isOptionalArg() || expr.isVarArgs()) { return expr; } else { return new JSTypeExpression( new Node(Token.EQUALS, expr.root), expr.sourceName); } }
private JSTypeExpression getSuperclassFor(Node superNode) { final String superName; if (superNode.isQualifiedName()) { superName = superNode.getQualifiedName(); } else { checkState(NodeUtil.isCallTo(superNode, "goog.module.get")); superName = superNode.getLastChild().getString(); } return new JSTypeExpression(new Node(Token.BANG, IR.string(superName)), VIRTUAL_FILE); }
/** @return The proper constructor doc for the Polymer call. */ private JSDocInfoBuilder getConstructorDoc(final PolymerClassDefinition cls) { JSDocInfoBuilder constructorDoc = JSDocInfoBuilder.maybeCopyFrom(cls.constructor.info); constructorDoc.recordConstructor(); JSTypeExpression baseType = new JSTypeExpression( new Node(Token.BANG, IR.string(PolymerPassStaticUtils.getPolymerElementType(cls))), VIRTUAL_FILE); constructorDoc.recordBaseType(baseType); String interfaceName = getInterfaceName(cls); JSTypeExpression interfaceType = new JSTypeExpression(new Node(Token.BANG, IR.string(interfaceName)), VIRTUAL_FILE); constructorDoc.recordImplementedInterface(interfaceType); return constructorDoc; }
/** * @return The proper constructor doc for the Polymer call. */ private JSDocInfoBuilder getConstructorDoc(final PolymerClassDefinition cls) { JSDocInfoBuilder constructorDoc = JSDocInfoBuilder.maybeCopyFrom(cls.constructor.info); constructorDoc.recordConstructor(); JSTypeExpression baseType = new JSTypeExpression( new Node(Token.BANG, IR.string(PolymerPassStaticUtils.getPolymerElementType(cls))), PolymerPass.VIRTUAL_FILE); constructorDoc.recordBaseType(baseType); String interfaceName = getInterfaceName(cls); JSTypeExpression interfaceType = new JSTypeExpression( new Node(Token.BANG, IR.string(interfaceName)), PolymerPass.VIRTUAL_FILE); constructorDoc.recordImplementedInterface(interfaceType); return constructorDoc; }
private JSTypeExpression createIObject(NodeTraversal t, Node indexSignature) { Node indexType = convertWithLocation(indexSignature.getFirstChild() .getDeclaredTypeExpression()); Node declaredType = convertWithLocation(indexSignature.getDeclaredTypeExpression()); Node block = new Node(Token.BLOCK, indexType, declaredType); Node iObject = IR.string("IObject"); iObject.addChildToFront(block); JSTypeExpression bang = new JSTypeExpression(new Node(Token.BANG, iObject) .useSourceInfoIfMissingFromForTree(indexSignature), indexSignature.getSourceFileName()); indexSignature.detach(); t.reportCodeChange(); return bang; }
private JSTypeExpression createIObject(Node indexSignature) { Node indexType = convertWithLocation(indexSignature.getFirstChild() .getDeclaredTypeExpression()); Node declaredType = convertWithLocation(indexSignature.getDeclaredTypeExpression()); Node block = new Node(Token.BLOCK, indexType, declaredType); Node iObject = IR.string("IObject"); iObject.addChildrenToFront(block); JSTypeExpression bang = new JSTypeExpression(new Node(Token.BANG, iObject) .useSourceInfoIfMissingFromForTree(indexSignature), indexSignature.getSourceFileName()); indexSignature.detachFromParent(); compiler.reportCodeChange(); return bang; }
private void visitTypeAlias(NodeTraversal t, Node n, Node parent) { String alias = n.getString(); if (t.getScope().hasSlot(alias)) { compiler.report( JSError.make(n, TYPE_ALIAS_ALREADY_DECLARED, alias)); } JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(n.getJSDocInfo()); builder.recordTypedef(new JSTypeExpression( convertWithLocation(n.getFirstChild()), n.getSourceFileName())); Node newName = maybeGetQualifiedNameNode(IR.name(n.getString())).useSourceInfoIfMissingFromForTree(n); Node newDec1 = NodeUtil.newQNameDeclaration( compiler, newName.getQualifiedName(), null, builder.build()).useSourceInfoFromForTree(n); parent.replaceChild(n, newDec1); t.reportCodeChange(); }
private void addGetterExport( Node script, Node forSourceInfo, Node objLit, String exportedName, String localName) { // Type checker doesn't infer getters so mark the return as unknown. // { /** @return {?} */ get foo() { return foo; } } Node getter = Node.newString(Token.GETTER_DEF, exportedName); getter.putBooleanProp(Node.MODULE_EXPORT, true); objLit.addChildToBack(getter); Node name = NodeUtil.newQName(compiler, localName); Node function = IR.function(IR.name(""), IR.paramList(), IR.block(IR.returnNode(name))); getter.addChildToFront(function); JSDocInfoBuilder builder = new JSDocInfoBuilder(true); builder.recordReturnType( new JSTypeExpression(new Node(Token.QMARK), script.getSourceFileName())); getter.setJSDocInfo(builder.build()); getter.useSourceInfoIfMissingFromForTree(forSourceInfo); compiler.reportChangeToEnclosingScope(getter.getFirstChild().getLastChild()); compiler.reportChangeToEnclosingScope(getter); }