/** * Returns whether the parameter has an attached type. * * @return {@code true} if the parameter has an attached type, {@code false} * if the parameter has no attached type or does not exist. */ public boolean hasParameterType(String parameter) { return getParameterType(parameter) != null; }
/** * Returns whether the parameter has an attached type. * * @return {@code true} if the parameter has an attached type, {@code false} * if the parameter has no attached type or does not exist. */ public boolean hasParameterType(String parameter) { return getParameterType(parameter) != null; }
public static boolean isRestArg(JSDocInfo funJsdoc, String formalParamName) { if (funJsdoc == null) { return false; } JSTypeExpression texp = funJsdoc.getParameterType(formalParamName); Node jsdocNode = texp == null ? null : texp.getRoot(); return jsdocNode != null && jsdocNode.getType() == Token.ELLIPSIS; }
/** * @return Whether the given param is an optional param. */ private boolean isOptionalParameter( Node param, @Nullable JSDocInfo info) { if (codingConvention.isOptionalParameter(param)) { return true; } String paramName = param.getString(); return info != null && info.hasParameterType(paramName) && info.getParameterType(paramName).isOptionalArg(); }
/** * Determine whether this is a var args parameter. * @return Whether the given param is a var args param. */ private boolean isVarArgsParameter( Node param, @Nullable JSDocInfo info) { if (codingConvention.isVarArgsParameter(param)) { return true; } String paramName = param.getString(); return info != null && info.hasParameterType(paramName) && info.getParameterType(paramName).isVarArgs(); }
private String toParameterString() { if (paramNode != null) { return FunctionUtils.toParameterString(getContext(), getContext().getComment(), paramNode, outputJS); } StringBuilder sb = new StringBuilder(); sb.append("("); int len = comment.getParameterCount(); for (int i = 0; i < len; i++) { String parameterName = comment.getParameterNameAt(i); JSTypeExpression parameterType = comment.getParameterType(parameterName); sb.append(FunctionUtils.toParameter(getContext(), comment, parameterName, parameterType, outputJS)); if (i < len - 1) sb.append(", "); } sb.append(")"); return sb.toString(); }
private String toParameterString() { if (paramNode != null) { return FunctionUtils.toParameterString(getContext(), getContext().getComment(), paramNode, outputJS); } StringBuilder sb = new StringBuilder(); sb.append("("); int len = comment.getParameterCount(); for (int i = 0; i < len; i++) { String parameterName = comment.getParameterNameAt(i); JSTypeExpression parameterType = comment.getParameterType(parameterName); sb.append(FunctionUtils.toParameter(getContext(), comment, parameterName, parameterType, outputJS)); if (i < len - 1) sb.append(", "); } sb.append(")"); return sb.toString(); }
private String toParameterString() { if (paramNode != null) { return FunctionUtils.toParameterString(getContext(), getContext().getComment(), paramNode, outputJS); } StringBuilder sb = new StringBuilder(); sb.append("("); int len = comment.getParameterCount(); for (int i = 0; i < len; i++) { String parameterName = comment.getParameterNameAt(i); JSTypeExpression parameterType = comment.getParameterType(parameterName); sb.append(FunctionUtils.toParameter(getContext(), comment, parameterName, parameterType, outputJS)); if (i < len - 1) sb.append(", "); } sb.append(")"); return sb.toString(); }
/** * @param node A getter or setter node. */ @Nullable private JSTypeExpression getTypeFromGetterOrSetter(Node node) { JSDocInfo info = node.getJSDocInfo(); if (info != null) { boolean getter = node.isGetterDef() || node.getBooleanProp(Node.COMPUTED_PROP_GETTER); if (getter && info.getReturnType() != null) { return info.getReturnType(); } else { Set<String> paramNames = info.getParameterNames(); if (paramNames.size() == 1) { JSTypeExpression paramType = info.getParameterType(Iterables.getOnlyElement(info.getParameterNames())); if (paramType != null) { return paramType; } } } } return null; }
JSTypeExpression paramType = jsDoc.getParameterType(name); if (checkParam(t, param, name, paramType)) { return;
/** * @param node A getter or setter node. */ private JSTypeExpression getTypeFromGetterOrSetter(Node node) { JSDocInfo info = node.getJSDocInfo(); if (info != null) { boolean getter = node.isGetterDef() || node.getBooleanProp(Node.COMPUTED_PROP_GETTER); if (getter && info.getReturnType() != null) { return info.getReturnType(); } else { Set<String> paramNames = info.getParameterNames(); if (paramNames.size() == 1) { return info.getParameterType(Iterables.getOnlyElement(info.getParameterNames())); } } } return new JSTypeExpression(new Node(Token.QMARK), node.getSourceFileName()); }
/** Return declared JSDoc type for the given name declaration, or null if none present. */ @Nullable public static JSTypeExpression getDeclaredTypeExpression(Node declaration) { checkArgument(declaration.isName() || declaration.isStringKey()); JSDocInfo nameJsdoc = getBestJSDocInfo(declaration); if (nameJsdoc != null) { return nameJsdoc.getType(); } Node parent = declaration.getParent(); if (parent.isRest() || parent.isDefaultValue()) { parent = parent.getParent(); } if (parent.isParamList()) { JSDocInfo functionJsdoc = getBestJSDocInfo(parent.getParent()); if (functionJsdoc != null) { return functionJsdoc.getParameterType(declaration.getString()); } } return null; }
public static String toParamTypeString(BaseReference reference, String paramName) { JSTypeExpression expression = reference.getComment().getParameterType(paramName); if (expression == null) return "Object"; //most, if not all, types defined with @typedef don't actually exist in //JS, so they cannot be instantiated. if a function uses one of these //types for a parameter, that function will be impossible to call! //we need to fall back to Object instead. JSType jsType = getJsType(reference.getModel(), expression); if(jsType instanceof NamedType) { ClassReference typeDef = reference.getModel().getTypeDefReference(jsType.getDisplayName()); if(typeDef != null) { return "Object"; } } String type = toTypeExpressionString(reference, expression); type = transformType(type); return type; }
public static String toParamTypeString(BaseReference reference, String paramName) { JSTypeExpression expression = reference.getComment().getParameterType(paramName); if (expression == null) return "Object"; //most, if not all, types defined with @typedef don't actually exist in //JS, so they cannot be instantiated. if a function uses one of these //types for a parameter, that function will be impossible to call! //we need to fall back to Object instead. JSType jsType = getJsType(reference.getModel(), expression); if(jsType instanceof NamedType) { ClassReference typeDef = reference.getModel().getTypeDefReference(jsType.getDisplayName()); if(typeDef != null) { return "Object"; } } String type = toTypeExpressionString(reference, expression); type = transformType(type); return type; }
public static String toParamTypeString(BaseReference reference, String paramName) { JSTypeExpression expression = reference.getComment().getParameterType(paramName); if (expression == null) return "Object"; //most, if not all, types defined with @typedef don't actually exist in //JS, so they cannot be instantiated. if a function uses one of these //types for a parameter, that function will be impossible to call! //we need to fall back to Object instead. JSType jsType = getJsType(reference.getModel(), expression); if(jsType instanceof NamedType) { ClassReference typeDef = reference.getModel().getTypeDefReference(jsType.getDisplayName()); if(typeDef != null) { return "Object"; } } String type = toTypeExpressionString(reference, expression); type = transformType(type); return type; }
/** * Checks if current node contains js docs and checks all types specified in the js doc whether * they have Objects with potentially invalid keys. For example: {@code * Object<!Object, number>}. If such type is found, a warning is reported for the current node. */ private void checkJsdocInfoContainsObjectWithBadKey(NodeTraversal t, Node n) { if (n.getJSDocInfo() != null) { JSDocInfo info = n.getJSDocInfo(); checkTypeContainsObjectWithBadKey(t, n, info.getType()); checkTypeContainsObjectWithBadKey(t, n, info.getReturnType()); checkTypeContainsObjectWithBadKey(t, n, info.getTypedefType()); for (String param : info.getParameterNames()) { checkTypeContainsObjectWithBadKey(t, n, info.getParameterType(param)); } } }
protected JSType evaluateParam(MethodReference method, String paramName) { JSType jsType = method.getComment().getParameterType(paramName).evaluate(null, client.getCompiler().getJSCompiler().getTypeRegistry()); return jsType; }
/** * Checks if current node contains js docs and checks all types specified in the js doc whether * they have Objects with potentially invalid keys. For example: {@code * Object<!Object, number>}. If such type is found, a warning is reported for the current node. */ private void checkJsdocInfoContainsObjectWithBadKey(NodeTraversal t, Node n) { if (n.getJSDocInfo() != null) { JSDocInfo info = n.getJSDocInfo(); checkTypeContainsObjectWithBadKey(t, n, info.getType()); checkTypeContainsObjectWithBadKey(t, n, info.getReturnType()); checkTypeContainsObjectWithBadKey(t, n, info.getTypedefType()); for (String param : info.getParameterNames()) { checkTypeContainsObjectWithBadKey(t, n, info.getParameterType(param)); } } }
private JSType getJSType(String methodName, boolean isStatic, String paramName) { MethodReference method = null; if(isStatic) { method = model.getClassReference("Foo").getStaticMethod(methodName); } else { method = model.getClassReference("Foo").getInstanceMethod(methodName); } JSDocInfo comment = method.getComment(); JSTypeExpression parameterType = comment.getParameterType(paramName); JSType jsType = model.evaluate(parameterType); return jsType; }
return false; JSTypeExpression parameterType = parentDocInfo.getParameterType(node.getString()); if (parameterType == null) { return false;