Node processTypeName(TypeNameTree tree) { Node typeNode; if (tree.segments.size() == 1) { String typeName = tree.segments.get(0); if (typeName.equals("any")) typeNode = cloneProps(anyType()); else if (typeName.equals("number")) typeNode = cloneProps(numberType()); else if (typeName.equals("boolean")) typeNode = cloneProps(booleanType()); else if (typeName.equals("string")) typeNode = cloneProps(stringType()); else if (typeName.equals("void")) typeNode = cloneProps(voidType()); else if (typeName.equals("undefined")) typeNode = cloneProps(undefinedType()); else typeNode = cloneProps(namedType(tree.segments)); } else { typeNode = cloneProps(namedType(tree.segments)); } setSourceInfo(typeNode, tree); return typeNode; }
Node processParameterizedType(ParameterizedTypeTree tree) { ImmutableList.Builder<TypeDeclarationNode> arguments = ImmutableList.builder(); for (ParseTree arg : tree.typeArguments) { arguments.add((TypeDeclarationNode) transform(arg)); } TypeDeclarationNode typeName = (TypeDeclarationNode) transform(tree.typeName); return cloneProps(parameterizedType(typeName, arguments.build())); }
public static TypeDeclarationNode unionType(TypeDeclarationNode... options) { return unionType(Arrays.asList(options)); }
case Token.STAR: case Token.EMPTY: // for function types that don't declare a return type return anyType(); case Token.VOID: return undefinedType(); case Token.BANG: String typeName = n.getString(); if (typeName.equals("boolean")) return booleanType(); else if (typeName.equals("number")) return numberType(); else if (typeName.equals("string")) return stringType(); else if (typeName.equals("null") || typeName.equals("undefined") || typeName.equals("void")) return null; else { TypeDeclarationNode root = namedType(typeName); if (n.getChildCount() > 0 && n.getFirstChild().isBlock()) { Node block = n.getFirstChild(); if ("Array".equals(typeName)) { return arrayType(convertTypeNodeAST(block.getFirstChild())); return parameterizedType(root, Iterables.filter( Iterables.transform(block.children(), CONVERT_TYPE_NODE), Node child = n.getFirstChild(); return child == null
return anyType(); case VOID: return isReturnType ? voidType() : undefinedType(); Node child = n.getFirstChild(); if (child == null) { return anyType(); } else { ImmutableList<TypeDeclarationNode> types = switch (typeName) { case "boolean": return booleanType(); case "number": return numberType(); case "string": return stringType(); case "null": return isReturnType ? voidType() : undefinedType(); default: String newTypeName = convertTypeName(n.getSourceFileName(), typeName); newTypeName = convertExternNameToTypingName(newTypeName); TypeDeclarationNode root = namedType(newTypeName); if (n.getChildCount() > 0 && n.getFirstChild().isNormalBlock()) { Node block = n.getFirstChild(); return arrayType(convertTypeNodeAST(block.getFirstChild()));
private Node maybeProcessOptionalProperty(Node n, Node type) { if (n.isOptionalEs6Typed()) { n.putBooleanProp(Node.OPT_ES6_TYPED, false); TypeDeclarationNode baseType = (TypeDeclarationNode) maybeCreateAnyType(n, type); type = TypeDeclarationsIR.unionType( ImmutableList.of(baseType, TypeDeclarationsIR.undefinedType())); type.useSourceInfoIfMissingFromForTree(baseType); } else { type = maybeCreateAnyType(n, type); } return convertWithLocation(type); }
TypeDeclarationsIR.functionType(returnType, required, optional, restName, restType); memberVariable.setDeclaredTypeExpression(type); } else { memberVariable.setDeclaredTypeExpression(TypeDeclarationsIR.namedType("Function"));
/** * Splits a '.' separated qualified name into a tree of type segments. * * @param typeName a qualified name such as "goog.ui.Window" * @return a new node representing the type * @see #namedType(Iterable) */ public static TypeDeclarationNode namedType(String typeName) { return namedType(Splitter.on('.').split(typeName)); }
private Node maybeCreateAnyType(Node n, Node type) { return type == null ? TypeDeclarationsIR.anyType().useSourceInfoIfMissingFrom(n) : type; }
Node processArrayType(ArrayTypeTree tree) { return cloneProps(arrayType(transform(tree.elementType))); }
return cloneProps(functionType(transform(tree.returnType), requiredParams, optionalParams, restName, restType));
private Node maybeProcessOptionalProperty(Node n, Node type) { if (n.isOptionalEs6Typed()) { n.putBooleanProp(Node.OPT_ES6_TYPED, false); TypeDeclarationNode baseType = (TypeDeclarationNode) maybeCreateAnyType(n, type); type = TypeDeclarationsIR.unionType( ImmutableList.of(baseType, TypeDeclarationsIR.undefinedType())); type.useSourceInfoIfMissingFromForTree(baseType); } else { type = maybeCreateAnyType(n, type); } return convertWithLocation(type); }
TypeDeclarationsIR.functionType(returnType, required, optional, restName, restType); memberVariable.setDeclaredTypeExpression(type); } else { memberVariable.setDeclaredTypeExpression(TypeDeclarationsIR.namedType("Function"));
/** * Splits a '.' separated qualified name into a tree of type segments. * * @param typeName a qualified name such as "goog.ui.Window" * @return a new node representing the type * @see #namedType(Iterable) */ public static TypeDeclarationNode namedType(String typeName) { return namedType(Splitter.on('.').split(typeName)); }
private Node maybeCreateAnyType(Node n, Node type) { return type == null ? TypeDeclarationsIR.anyType().useSourceInfoIfMissingFrom(n) : type; }
Node processArrayType(ArrayTypeTree tree) { return cloneProps(arrayType(transform(tree.elementType))); }
return cloneProps(functionType(transform(tree.returnType), requiredParams, optionalParams, restName, restType));
switch (typeName) { case "any": typeNode = cloneProps(anyType()); break; case "number": typeNode = cloneProps(numberType()); break; case "boolean": typeNode = cloneProps(booleanType()); break; case "string": typeNode = cloneProps(stringType()); break; case "void": typeNode = cloneProps(voidType()); break; case "undefined": typeNode = cloneProps(undefinedType()); break; default: typeNode = cloneProps(namedType(tree.segments)); break; typeNode = cloneProps(namedType(tree.segments));
public static TypeDeclarationNode unionType(TypeDeclarationNode... options) { return unionType(Arrays.asList(options)); }