use of com.google.javascript.rhino.TypeI in project closure-compiler by google.
the class CheckNullableReturn method isReturnTypeNullable.
/**
* @return True if n is a function node which is explicitly annotated
* as returning a nullable type, other than {?}.
*/
private static boolean isReturnTypeNullable(Node n) {
if (n == null || !n.isFunction()) {
return false;
}
FunctionTypeI functionType = n.getTypeI().toMaybeFunctionType();
if (functionType == null) {
// If the JSDoc declares a non-function type on a function node, we still shouldn't crash.
return false;
}
TypeI returnType = functionType.getReturnType();
if (returnType == null || returnType.isUnknownType() || !returnType.isNullable()) {
return false;
}
JSDocInfo info = NodeUtil.getBestJSDocInfo(n);
return info != null && info.hasReturnType();
}
use of com.google.javascript.rhino.TypeI in project closure-compiler by google.
the class NewTypeInference method maybeSetTypeI.
private void maybeSetTypeI(Node n, JSType t) {
TypeI oldType = n.getTypeI();
checkState(oldType == null || oldType instanceof JSType);
// outer scope; we've already computed a good type for it, don't lose it.
if (oldType == null) {
n.setTypeI(t);
}
}
use of com.google.javascript.rhino.TypeI in project closure-compiler by google.
the class PureFunctionIdentifier method isLocalValueType.
/**
* TODO: This could be greatly improved.
*
* @return Whether the jstype is something known to be a local value.
*/
private static boolean isLocalValueType(TypeI typei, AbstractCompiler compiler) {
checkNotNull(typei);
TypeI nativeObj = compiler.getTypeIRegistry().getNativeType(JSTypeNative.OBJECT_TYPE);
TypeI subtype = typei.meetWith(nativeObj);
// anything about the locality of the value.
return subtype.isBottom();
}
use of com.google.javascript.rhino.TypeI in project closure-compiler by google.
the class TypedCodeGenerator method getParameterJSDocType.
/**
* Creates a JSDoc-suitable String representation of the type of a parameter.
*/
private String getParameterJSDocType(List<TypeI> types, int index, int minArgs, int maxArgs) {
TypeI type = types.get(index);
if (index < minArgs) {
return type.toAnnotationString(Nullability.EXPLICIT);
}
boolean isRestArgument = maxArgs == Integer.MAX_VALUE && index == types.size() - 1;
if (isRestArgument) {
return "..." + restrictByUndefined(type).toAnnotationString(Nullability.EXPLICIT);
}
return restrictByUndefined(type).toAnnotationString(Nullability.EXPLICIT) + "=";
}
use of com.google.javascript.rhino.TypeI in project closure-compiler by google.
the class J2clChecksPass method checkReferenceEquality.
/**
* Reports an error if the node is a reference equality check of the specified type.
*/
private void checkReferenceEquality(NodeTraversal t, Node n, String typeName, String fileName) {
if (n.getToken() == Token.SHEQ || n.getToken() == Token.EQ || n.getToken() == Token.SHNE || n.getToken() == Token.NE) {
TypeI firstJsType = n.getFirstChild().getTypeI();
TypeI lastJsType = n.getLastChild().getTypeI();
boolean hasType = isType(firstJsType, fileName) || isType(lastJsType, fileName);
boolean hasNullType = isNullType(firstJsType) || isNullType(lastJsType);
if (hasType && !hasNullType) {
compiler.report(t.makeError(n, J2CL_REFERENCE_EQUALITY, typeName));
}
}
}
Aggregations