Java Code Examples for com.google.javascript.rhino.jstype.ObjectType#getParameterType()

The following examples show how to use com.google.javascript.rhino.jstype.ObjectType#getParameterType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Closure_25_TypeInference_s.java    From coming with MIT License 5 votes vote down vote up
private FlowScope traverseGetElem(Node n, FlowScope scope) {
  scope = traverseChildren(n, scope);
  ObjectType objType = ObjectType.cast(
      getJSType(n.getFirstChild()).restrictByNotNullOrUndefined());
  if (objType != null) {
    JSType type = objType.getParameterType();
    if (type != null) {
      n.setJSType(type);
    }
  }
  return dereferencePointer(n.getFirstChild(), scope);
}
 
Example 2
Source File: Closure_25_TypeInference_t.java    From coming with MIT License 5 votes vote down vote up
private FlowScope traverseGetElem(Node n, FlowScope scope) {
  scope = traverseChildren(n, scope);
  ObjectType objType = ObjectType.cast(
      getJSType(n.getFirstChild()).restrictByNotNullOrUndefined());
  if (objType != null) {
    JSType type = objType.getParameterType();
    if (type != null) {
      n.setJSType(type);
    }
  }
  return dereferencePointer(n.getFirstChild(), scope);
}
 
Example 3
Source File: Closure_35_TypeInference_s.java    From coming with MIT License 5 votes vote down vote up
private FlowScope traverseGetElem(Node n, FlowScope scope) {
  scope = traverseChildren(n, scope);
  ObjectType objType = ObjectType.cast(
      getJSType(n.getFirstChild()).restrictByNotNullOrUndefined());
  if (objType != null) {
    JSType type = objType.getParameterType();
    if (type != null) {
      n.setJSType(type);
    }
  }
  return dereferencePointer(n.getFirstChild(), scope);
}
 
Example 4
Source File: Closure_35_TypeInference_t.java    From coming with MIT License 5 votes vote down vote up
private FlowScope traverseGetElem(Node n, FlowScope scope) {
  scope = traverseChildren(n, scope);
  ObjectType objType = ObjectType.cast(
      getJSType(n.getFirstChild()).restrictByNotNullOrUndefined());
  if (objType != null) {
    JSType type = objType.getParameterType();
    if (type != null) {
      n.setJSType(type);
    }
  }
  return dereferencePointer(n.getFirstChild(), scope);
}
 
Example 5
Source File: TypeInference.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private FlowScope traverseGetElem(Node n, FlowScope scope) {
  scope = traverseChildren(n, scope);
  ObjectType objType = ObjectType.cast(
      getJSType(n.getFirstChild()).restrictByNotNullOrUndefined());
  if (objType != null) {
    JSType type = objType.getParameterType();
    if (type != null) {
      n.setJSType(type);
    }
  }
  return dereferencePointer(n.getFirstChild(), scope);
}
 
Example 6
Source File: TypeInference.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
private void maybeResolveTemplatedType(
    JSType paramType,
    JSType argType,
    Map<TemplateType, JSType> resolvedTypes) {
  if (paramType.isTemplateType()) {
    // @param {T}
    resolvedTemplateType(
        resolvedTypes, paramType.toMaybeTemplateType(), argType);
  } else if (paramType.isUnionType()) {
    // @param {Array.<T>|NodeList|Arguments|{length:number}}
    UnionType unionType = paramType.toMaybeUnionType();
    for (JSType alernative : unionType.getAlternates()) {
      maybeResolveTemplatedType(alernative, argType, resolvedTypes);
    }
  } else if (paramType.isFunctionType()) {
    FunctionType paramFunctionType = paramType.toMaybeFunctionType();
    FunctionType argFunctionType = argType
        .restrictByNotNullOrUndefined()
        .collapseUnion()
        .toMaybeFunctionType();
    if (argFunctionType != null && argFunctionType.isSubtype(paramType)) {
      // infer from return type of the function type
      maybeResolveTemplatedType(
          paramFunctionType.getTypeOfThis(),
          argFunctionType.getTypeOfThis(), resolvedTypes);
      // infer from return type of the function type
      maybeResolveTemplatedType(
          paramFunctionType.getReturnType(),
          argFunctionType.getReturnType(), resolvedTypes);
      // infer from parameter types of the function type
      maybeResolveTemplateTypeFromNodes(
          paramFunctionType.getParameters(),
          argFunctionType.getParameters(), resolvedTypes);
    }
  } else if (paramType.isParameterizedType()) {
    ParameterizedType paramObjectType = paramType.toMaybeParameterizedType();
    JSType typeParameter = paramObjectType.getParameterType();
    Preconditions.checkNotNull(typeParameter);
    if (typeParameter != null) {
      // @param {Array.<T>}
      ObjectType argObjectType = argType
          .restrictByNotNullOrUndefined()
          .collapseUnion()
          .toMaybeParameterizedType();
      if (argObjectType != null && argObjectType.isSubtype(paramType)) {
        JSType argTypeParameter = argObjectType.getParameterType();
        Preconditions.checkNotNull(argTypeParameter);
        maybeResolveTemplatedType(
            typeParameter, argTypeParameter, resolvedTypes);
      }
    }
  }
}