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

The following examples show how to use com.google.javascript.rhino.jstype.ObjectType#isSubtype() . 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: SemanticReverseAbstractInterpreter.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Override
public JSType caseObjectType(ObjectType type) {
  if (target.isUnknownType()) {
    return type;
  }

  FunctionType funcTarget = target.toMaybeFunctionType();
  if (funcTarget.hasInstanceType()) {
    if (type.isSubtype(funcTarget.getInstanceType())) {
      return null;
    }

    return type;
  }

  return null;
}
 
Example 2
Source File: Closure_7_ChainableReverseAbstractInterpreter_t.java    From coming with MIT License 5 votes vote down vote up
@Override
public JSType caseObjectType(ObjectType type) {
  if (value.equals("function")) {
    JSType ctorType = getNativeType(U2U_CONSTRUCTOR_TYPE);
    if (resultEqualsValue) {
      // Objects are restricted to "Function", subtypes are left
      return ctorType.getGreatestSubtype(type);
    } else {
      // Only filter out subtypes of "function"
      return type.isSubtype(ctorType) ? null : type;
    }
  }
  return matchesExpectation("object") ? type : null;
}
 
Example 3
Source File: ChainableReverseAbstractInterpreter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
public JSType caseObjectType(ObjectType type) {
  if (value.equals("function")) {
    JSType ctorType = getNativeType(U2U_CONSTRUCTOR_TYPE);
    if (resultEqualsValue) {
      // Objects are restricted to "Function", subtypes are left
      return ctorType.getGreatestSubtype(type);
    } else {
      // Only filter out subtypes of "function"
      return type.isSubtype(ctorType) ? null : type;
    }
  }
  return matchesExpectation("object") ? type : null;
}
 
Example 4
Source File: Closure_111_ClosureReverseAbstractInterpreter_s.java    From coming with MIT License 4 votes vote down vote up
@Override
public JSType caseObjectType(ObjectType type) {
  return type.isSubtype(getNativeType(ARRAY_TYPE)) ? null : type;
}
 
Example 5
Source File: Closure_111_ClosureReverseAbstractInterpreter_t.java    From coming with MIT License 4 votes vote down vote up
@Override
public JSType caseObjectType(ObjectType type) {
  return type.isSubtype(getNativeType(ARRAY_TYPE)) ? null : type;
}
 
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);
      }
    }
  }
}
 
Example 7
Source File: ClosureReverseAbstractInterpreter.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Override
public JSType caseObjectType(ObjectType type) {
  return type.isSubtype(getNativeType(ARRAY_TYPE)) ? null : type;
}