com.google.javascript.rhino.jstype.JSTypeNative Java Examples

The following examples show how to use com.google.javascript.rhino.jstype.JSTypeNative. 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_57_ClosureCodingConvention_t.java    From coming with MIT License 6 votes vote down vote up
@Override
public Collection<AssertionFunctionSpec> getAssertionFunctions() {
  return ImmutableList.<AssertionFunctionSpec>of(
      new AssertionFunctionSpec("goog.asserts.assert"),
      new AssertionFunctionSpec("goog.asserts.assertNumber",
          JSTypeNative.NUMBER_TYPE),
      new AssertionFunctionSpec("goog.asserts.assertString",
          JSTypeNative.STRING_TYPE),
      new AssertionFunctionSpec("goog.asserts.assertFunction",
          JSTypeNative.FUNCTION_INSTANCE_TYPE),
      new AssertionFunctionSpec("goog.asserts.assertObject",
          JSTypeNative.OBJECT_TYPE),
      new AssertionFunctionSpec("goog.asserts.assertArray",
          JSTypeNative.ARRAY_TYPE),
      // TODO(agrieve): It would be better if this could make the first
      // parameter the type of the second parameter.
      new AssertionFunctionSpec("goog.asserts.assertInstanceof",
          JSTypeNative.OBJECT_TYPE)
  );
}
 
Example #2
Source File: 1_ClosureCodingConvention.java    From SimFix with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Collection<AssertionFunctionSpec> getAssertionFunctions() {
  return ImmutableList.<AssertionFunctionSpec>of(
      new AssertionFunctionSpec("goog.asserts.assert"),
      new AssertionFunctionSpec("goog.asserts.assertNumber",
          JSTypeNative.NUMBER_TYPE),
      new AssertionFunctionSpec("goog.asserts.assertString",
          JSTypeNative.STRING_TYPE),
      new AssertionFunctionSpec("goog.asserts.assertFunction",
          JSTypeNative.FUNCTION_INSTANCE_TYPE),
      new AssertionFunctionSpec("goog.asserts.assertObject",
          JSTypeNative.OBJECT_TYPE),
      new AssertionFunctionSpec("goog.asserts.assertArray",
          JSTypeNative.ARRAY_TYPE),
      // TODO(agrieve): It would be better if this could make the first
      // parameter the type of the second parameter.
      new AssertionFunctionSpec("goog.asserts.assertInstanceof",
          JSTypeNative.OBJECT_TYPE)
  );
}
 
Example #3
Source File: Closure_57_ClosureCodingConvention_s.java    From coming with MIT License 6 votes vote down vote up
@Override
public Collection<AssertionFunctionSpec> getAssertionFunctions() {
  return ImmutableList.<AssertionFunctionSpec>of(
      new AssertionFunctionSpec("goog.asserts.assert"),
      new AssertionFunctionSpec("goog.asserts.assertNumber",
          JSTypeNative.NUMBER_TYPE),
      new AssertionFunctionSpec("goog.asserts.assertString",
          JSTypeNative.STRING_TYPE),
      new AssertionFunctionSpec("goog.asserts.assertFunction",
          JSTypeNative.FUNCTION_INSTANCE_TYPE),
      new AssertionFunctionSpec("goog.asserts.assertObject",
          JSTypeNative.OBJECT_TYPE),
      new AssertionFunctionSpec("goog.asserts.assertArray",
          JSTypeNative.ARRAY_TYPE),
      // TODO(agrieve): It would be better if this could make the first
      // parameter the type of the second parameter.
      new AssertionFunctionSpec("goog.asserts.assertInstanceof",
          JSTypeNative.OBJECT_TYPE)
  );
}
 
Example #4
Source File: 1_ClosureCodingConvention.java    From SimFix with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Collection<AssertionFunctionSpec> getAssertionFunctions() {
  return ImmutableList.<AssertionFunctionSpec>of(
      new AssertionFunctionSpec("goog.asserts.assert"),
      new AssertionFunctionSpec("goog.asserts.assertNumber",
          JSTypeNative.NUMBER_TYPE),
      new AssertionFunctionSpec("goog.asserts.assertString",
          JSTypeNative.STRING_TYPE),
      new AssertionFunctionSpec("goog.asserts.assertFunction",
          JSTypeNative.FUNCTION_INSTANCE_TYPE),
      new AssertionFunctionSpec("goog.asserts.assertObject",
          JSTypeNative.OBJECT_TYPE),
      new AssertionFunctionSpec("goog.asserts.assertArray",
          JSTypeNative.ARRAY_TYPE),
      // TODO(agrieve): It would be better if this could make the first
      // parameter the type of the second parameter.
      new AssertionFunctionSpec("goog.asserts.assertInstanceof",
          JSTypeNative.OBJECT_TYPE)
  );
}
 
Example #5
Source File: Closure_112_TypeInference_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Any value can be thrown, so it's really impossible to determine the type
 * of a CATCH param. Treat it as the UNKNOWN type.
 */
private FlowScope traverseCatch(Node catchNode, FlowScope scope) {
  Node name = catchNode.getFirstChild();
  JSType type;
  // If the catch expression name was declared in the catch use that type,
  // otherwise use "unknown".
  JSDocInfo info = name.getJSDocInfo();
  if (info != null && info.hasType()) {
    type = info.getType().evaluate(syntacticScope, registry);
  } else {
    type = getNativeType(JSTypeNative.UNKNOWN_TYPE);
  }
  redeclareSimpleVar(scope, name, type);
  name.setJSType(type);
  return scope;
}
 
Example #6
Source File: Closure_25_TypeInference_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Any value can be thrown, so it's really impossible to determine the type
 * of a CATCH param. Treat it as the UNKNOWN type.
 */
private FlowScope traverseCatch(Node n, FlowScope scope) {
  Node name = n.getFirstChild();
  JSType type = getNativeType(JSTypeNative.UNKNOWN_TYPE);
  name.setJSType(type);
  redeclareSimpleVar(scope, name, type);
  return scope;
}
 
Example #7
Source File: Closure_103_DisambiguateProperties_t.java    From coming with MIT License 5 votes vote down vote up
public JSTypeSystem(AbstractCompiler compiler) {
  registry = compiler.getTypeRegistry();
  invalidatingTypes = Sets.newHashSet(
      registry.getNativeType(JSTypeNative.ALL_TYPE),
      registry.getNativeType(JSTypeNative.NO_OBJECT_TYPE),
      registry.getNativeType(JSTypeNative.NO_TYPE),
      registry.getNativeType(JSTypeNative.FUNCTION_PROTOTYPE),
      registry.getNativeType(JSTypeNative.OBJECT_PROTOTYPE),
      registry.getNativeType(JSTypeNative.TOP_LEVEL_PROTOTYPE),
      registry.getNativeType(JSTypeNative.UNKNOWN_TYPE));

}
 
Example #8
Source File: Closure_35_TypeInference_t.java    From coming with MIT License 5 votes vote down vote up
private void redeclareSimpleVar(
    FlowScope scope, Node nameNode, JSType varType) {
  Preconditions.checkState(nameNode.isName());
  String varName = nameNode.getString();
  if (varType == null) {
    varType = getNativeType(JSTypeNative.UNKNOWN_TYPE);
  }
  if (isUnflowable(syntacticScope.getVar(varName))) {
    return;
  }
  scope.inferSlotType(varName, varType);
}
 
Example #9
Source File: Closure_35_TypeInference_s.java    From coming with MIT License 5 votes vote down vote up
private void redeclareSimpleVar(
    FlowScope scope, Node nameNode, JSType varType) {
  Preconditions.checkState(nameNode.isName());
  String varName = nameNode.getString();
  if (varType == null) {
    varType = getNativeType(JSTypeNative.UNKNOWN_TYPE);
  }
  if (isUnflowable(syntacticScope.getVar(varName))) {
    return;
  }
  scope.inferSlotType(varName, varType);
}
 
Example #10
Source File: Closure_112_TypeInference_s.java    From coming with MIT License 5 votes vote down vote up
private void redeclareSimpleVar(
    FlowScope scope, Node nameNode, JSType varType) {
  Preconditions.checkState(nameNode.isName());
  String varName = nameNode.getString();
  if (varType == null) {
    varType = getNativeType(JSTypeNative.UNKNOWN_TYPE);
  }
  if (isUnflowable(syntacticScope.getVar(varName))) {
    return;
  }
  scope.inferSlotType(varName, varType);
}
 
Example #11
Source File: Closure_25_TypeInference_s.java    From coming with MIT License 5 votes vote down vote up
private void redeclareSimpleVar(
    FlowScope scope, Node nameNode, JSType varType) {
  Preconditions.checkState(nameNode.isName());
  String varName = nameNode.getString();
  if (varType == null) {
    varType = getNativeType(JSTypeNative.UNKNOWN_TYPE);
  }
  if (isUnflowable(syntacticScope.getVar(varName))) {
    return;
  }
  scope.inferSlotType(varName, varType);
}
 
Example #12
Source File: Closure_103_DisambiguateProperties_s.java    From coming with MIT License 5 votes vote down vote up
public JSTypeSystem(AbstractCompiler compiler) {
  registry = compiler.getTypeRegistry();
  invalidatingTypes = Sets.newHashSet(
      registry.getNativeType(JSTypeNative.ALL_TYPE),
      registry.getNativeType(JSTypeNative.NO_OBJECT_TYPE),
      registry.getNativeType(JSTypeNative.NO_TYPE),
      registry.getNativeType(JSTypeNative.FUNCTION_PROTOTYPE),
      registry.getNativeType(JSTypeNative.OBJECT_PROTOTYPE),
      registry.getNativeType(JSTypeNative.TOP_LEVEL_PROTOTYPE),
      registry.getNativeType(JSTypeNative.UNKNOWN_TYPE));

}
 
Example #13
Source File: Closure_35_TypeInference_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Any value can be thrown, so it's really impossible to determine the type
 * of a CATCH param. Treat it as the UNKNOWN type.
 */
private FlowScope traverseCatch(Node n, FlowScope scope) {
  Node name = n.getFirstChild();
  JSType type = getNativeType(JSTypeNative.UNKNOWN_TYPE);
  name.setJSType(type);
  redeclareSimpleVar(scope, name, type);
  return scope;
}
 
Example #14
Source File: 1_JsDocInfoParser.java    From SimFix with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Determines whether the given type is a valid {@code @define} type.
 */
// TODO(nicksantos): Move this into a check pass.
private boolean isValidDefineType(Node typeNode) {
  JSType type = typeRegistry.createFromTypeNodes(typeNode, "", null);
  return !type.isUnknownType() && type.isSubtype(
      typeRegistry.getNativeType(JSTypeNative.NUMBER_STRING_BOOLEAN));
}
 
Example #15
Source File: Closure_103_DisambiguateProperties_t.java    From coming with MIT License 5 votes vote down vote up
@Override public JSType getType(
    StaticScope<JSType> scope, Node node, String prop) {
  if (node.getJSType() == null) {
    return registry.getNativeType(JSTypeNative.UNKNOWN_TYPE);
  }
  return node.getJSType();
}
 
Example #16
Source File: Closure_118_DisambiguateProperties_t.java    From coming with MIT License 5 votes vote down vote up
public JSTypeSystem(AbstractCompiler compiler) {
  registry = compiler.getTypeRegistry();
  invalidatingTypes = Sets.newHashSet(
      registry.getNativeType(JSTypeNative.ALL_TYPE),
      registry.getNativeType(JSTypeNative.NO_OBJECT_TYPE),
      registry.getNativeType(JSTypeNative.NO_TYPE),
      registry.getNativeType(JSTypeNative.FUNCTION_PROTOTYPE),
      registry.getNativeType(JSTypeNative.FUNCTION_INSTANCE_TYPE),
      registry.getNativeType(JSTypeNative.OBJECT_PROTOTYPE),
      registry.getNativeType(JSTypeNative.TOP_LEVEL_PROTOTYPE),
      registry.getNativeType(JSTypeNative.UNKNOWN_TYPE));

}
 
Example #17
Source File: Closure_118_DisambiguateProperties_s.java    From coming with MIT License 5 votes vote down vote up
@Override public JSType getType(
    StaticScope<JSType> scope, Node node, String prop) {
  if (node.getJSType() == null) {
    return registry.getNativeType(JSTypeNative.UNKNOWN_TYPE);
  }
  return node.getJSType();
}
 
Example #18
Source File: Closure_118_DisambiguateProperties_s.java    From coming with MIT License 5 votes vote down vote up
public JSTypeSystem(AbstractCompiler compiler) {
  registry = compiler.getTypeRegistry();
  invalidatingTypes = Sets.newHashSet(
      registry.getNativeType(JSTypeNative.ALL_TYPE),
      registry.getNativeType(JSTypeNative.NO_OBJECT_TYPE),
      registry.getNativeType(JSTypeNative.NO_TYPE),
      registry.getNativeType(JSTypeNative.FUNCTION_PROTOTYPE),
      registry.getNativeType(JSTypeNative.FUNCTION_INSTANCE_TYPE),
      registry.getNativeType(JSTypeNative.OBJECT_PROTOTYPE),
      registry.getNativeType(JSTypeNative.TOP_LEVEL_PROTOTYPE),
      registry.getNativeType(JSTypeNative.UNKNOWN_TYPE));

}
 
Example #19
Source File: Closure_11_TypeCheck_s.java    From coming with MIT License 4 votes vote down vote up
private JSType getNativeType(JSTypeNative typeId) {
  return typeRegistry.getNativeType(typeId);
}
 
Example #20
Source File: Closure_11_TypeCheck_s.java    From coming with MIT License 4 votes vote down vote up
private void ensureTyped(NodeTraversal t, Node n, JSTypeNative type) {
  ensureTyped(t, n, getNativeType(type));
}
 
Example #21
Source File: Closure_11_TypeCheck_t.java    From coming with MIT License 4 votes vote down vote up
private void ensureTyped(NodeTraversal t, Node n, JSTypeNative type) {
  ensureTyped(t, n, getNativeType(type));
}
 
Example #22
Source File: Closure_66_TypeCheck_s.java    From coming with MIT License 4 votes vote down vote up
private JSType getNativeType(JSTypeNative typeId) {
  return typeRegistry.getNativeType(typeId);
}
 
Example #23
Source File: Closure_19_ChainableReverseAbstractInterpreter_s.java    From coming with MIT License 4 votes vote down vote up
JSType getNativeType(JSTypeNative typeId) {
  return typeRegistry.getNativeType(typeId);
}
 
Example #24
Source File: Closure_70_TypedScopeCreator_t.java    From coming with MIT License 4 votes vote down vote up
private void declareNativeValueType(Scope scope, String name,
    JSTypeNative tId) {
  declareNativeType(scope, name, typeRegistry.getNativeType(tId));
}
 
Example #25
Source File: Closure_11_TypeCheck_t.java    From coming with MIT License 4 votes vote down vote up
private JSType getNativeType(JSTypeNative typeId) {
  return typeRegistry.getNativeType(typeId);
}
 
Example #26
Source File: Closure_66_TypeCheck_s.java    From coming with MIT License 4 votes vote down vote up
private void ensureTyped(NodeTraversal t, Node n, JSTypeNative type) {
  ensureTyped(t, n, getNativeType(type));
}
 
Example #27
Source File: Closure_48_TypedScopeCreator_t.java    From coming with MIT License 4 votes vote down vote up
private void declareNativeFunctionType(Scope scope, JSTypeNative tId) {
  FunctionType t = typeRegistry.getNativeFunctionType(tId);
  declareNativeType(scope, t.getInstanceType().getReferenceName(), t);
  declareNativeType(
      scope, t.getPrototype().getReferenceName(), t.getPrototype());
}
 
Example #28
Source File: Closure_48_TypedScopeCreator_t.java    From coming with MIT License 4 votes vote down vote up
private void declareNativeValueType(Scope scope, String name,
    JSTypeNative tId) {
  declareNativeType(scope, name, typeRegistry.getNativeType(tId));
}
 
Example #29
Source File: Closure_66_TypeCheck_t.java    From coming with MIT License 4 votes vote down vote up
private JSType getNativeType(JSTypeNative typeId) {
  return typeRegistry.getNativeType(typeId);
}
 
Example #30
Source File: Closure_2_TypeCheck_s.java    From coming with MIT License 4 votes vote down vote up
private JSType getNativeType(JSTypeNative typeId) {
  return typeRegistry.getNativeType(typeId);
}