Java Code Examples for com.google.javascript.rhino.Token#QMARK

The following examples show how to use com.google.javascript.rhino.Token#QMARK . 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: TypeConversionPass.java    From clutz with MIT License 5 votes vote down vote up
private boolean containsObject(Node typedefNode) {
  Token typedefToken = typedefNode.getToken();
  if (typedefToken == Token.LC) {
    return true;
  }

  if ((typedefToken == Token.QMARK || typedefToken == Token.BANG)
      && typedefNode.hasOneChild()) {
    // child Node is a simple type or a LC
    return containsObject(typedefNode.getFirstChild());
  }

  return false;
}
 
Example 2
Source File: JSTypeRegistryTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testTypeResolutionModes() {
  SimpleErrorReporter reporter = new SimpleErrorReporter();

  JSTypeRegistry lazyExprRegistry = new JSTypeRegistry(reporter);
  lazyExprRegistry.setResolveMode(ResolveMode.LAZY_EXPRESSIONS);

  JSTypeRegistry lazyNameRegistry = new JSTypeRegistry(reporter);
  lazyNameRegistry.setResolveMode(ResolveMode.LAZY_NAMES);

  JSTypeRegistry immediateRegistry = new JSTypeRegistry(reporter);
  immediateRegistry.setResolveMode(ResolveMode.IMMEDIATE);

  Node expr = new Node(Token.QMARK, Node.newString("foo"));
  StaticScope<JSType> empty = MapBasedScope.emptyScope();

  JSType type = lazyExprRegistry.createFromTypeNodes(
      expr, "source.js", empty);
  assertTrue(type instanceof UnresolvedTypeExpression);
  assertTrue(type.isUnknownType());
  assertEquals("?", type.toString());
  assertNull("Unexpected warnings: " + reporter.warnings(),
      reporter.warnings());

  type = lazyNameRegistry.createFromTypeNodes(
      expr, "source.js", empty);
  assertTrue(type instanceof UnionType);
  assertTrue(type.isUnknownType());
  assertEquals("(foo|null)", type.toString());
  assertNull("Unexpected warnings: " + reporter.warnings(),
      reporter.warnings());

  type = immediateRegistry.createFromTypeNodes(
      expr, "source.js", empty);
  assertTrue(type instanceof UnknownType);
  assertEquals("Expected warnings", 1, reporter.warnings().size());
}
 
Example 3
Source File: JSTypeRegistryTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testForceResolve() {
  SimpleErrorReporter reporter = new SimpleErrorReporter();

  JSTypeRegistry lazyExprRegistry = new JSTypeRegistry(reporter);
  lazyExprRegistry.setResolveMode(ResolveMode.LAZY_EXPRESSIONS);

  Node expr = new Node(Token.QMARK, Node.newString("foo"));
  StaticScope<JSType> empty = MapBasedScope.emptyScope();

  JSType type = lazyExprRegistry.createFromTypeNodes(
      expr, "source.js", empty);
  assertFalse(type.isResolved());
  assertTrue(type.forceResolve(reporter, empty).isResolved());
  assertEquals("Expected warnings", 1, reporter.warnings().size());
}
 
Example 4
Source File: TypeInspector.java    From js-dossier with Apache License 2.0 5 votes vote down vote up
private boolean isKnownType(JsDoc.TypedDescription description) {
  if (!description.getType().isPresent()) {
    return false;
  }
  JSTypeExpression expression = description.getType().get();
  return expression.getRoot().getToken() != Token.QMARK
      || expression.getRoot().getFirstChild() != null;
}