Search in sources :

Example 1 with TypeI

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();
}
Also used : TypeI(com.google.javascript.rhino.TypeI) FunctionTypeI(com.google.javascript.rhino.FunctionTypeI) FunctionTypeI(com.google.javascript.rhino.FunctionTypeI) JSDocInfo(com.google.javascript.rhino.JSDocInfo)

Example 2 with TypeI

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);
    }
}
Also used : JSType(com.google.javascript.jscomp.newtypes.JSType) TypeI(com.google.javascript.rhino.TypeI)

Example 3 with TypeI

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();
}
Also used : FunctionTypeI(com.google.javascript.rhino.FunctionTypeI) TypeI(com.google.javascript.rhino.TypeI)

Example 4 with TypeI

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) + "=";
}
Also used : TypeI(com.google.javascript.rhino.TypeI) ObjectTypeI(com.google.javascript.rhino.ObjectTypeI) FunctionTypeI(com.google.javascript.rhino.FunctionTypeI)

Example 5 with TypeI

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));
        }
    }
}
Also used : TypeI(com.google.javascript.rhino.TypeI) FunctionTypeI(com.google.javascript.rhino.FunctionTypeI)

Aggregations

TypeI (com.google.javascript.rhino.TypeI)37 ObjectTypeI (com.google.javascript.rhino.ObjectTypeI)24 FunctionTypeI (com.google.javascript.rhino.FunctionTypeI)23 Node (com.google.javascript.rhino.Node)10 TypeIRegistry (com.google.javascript.rhino.TypeIRegistry)4 LinkedHashMap (java.util.LinkedHashMap)4 JSType (com.google.javascript.jscomp.newtypes.JSType)3 JSDocInfo (com.google.javascript.rhino.JSDocInfo)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 IdentityHashMap (java.util.IdentityHashMap)2 Map (java.util.Map)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 DiGraphNode (com.google.javascript.jscomp.graph.DiGraph.DiGraphNode)1 Visibility (com.google.javascript.rhino.JSDocInfo.Visibility)1 JSDocInfoBuilder (com.google.javascript.rhino.JSDocInfoBuilder)1 JSTypeExpression (com.google.javascript.rhino.JSTypeExpression)1 Token (com.google.javascript.rhino.Token)1 ArrayList (java.util.ArrayList)1