Java Code Examples for com.google.javascript.rhino.jstype.JSType#isRecordType()

The following examples show how to use com.google.javascript.rhino.jstype.JSType#isRecordType() . 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: AbstractClosureVisitor.java    From jsinterop-generator with Apache License 2.0 6 votes vote down vote up
private void acceptTypedef(StaticTypedSlot typedef) {
  // The type linked to symbol is not the type represented in the @typedef annotations.
  JSType realType = checkNotNull(getJsTypeRegistry().getType(
      typedef.getScope(), typedef.getName()));

  if (realType.isRecordType()) {
    acceptRecordType(toRecordType(realType), typedef.getName());
  } else if (isAnonymousFunctionType(realType)) {
    acceptFunctionType(toFunctionType(realType), typedef.getName());
  } else {
    // we are in a case where typedef is used as an alias and doesnt define any RecordType or
    // FunctionType.
    // ex:  /** @typedef {string|number} */ var StringOrNumber;
    // The JsCompiler have already inlined all typedefs at call site, so we don't need to visit
    // the typedef definition.
    return;
  }
}
 
Example 2
Source File: AbstractClosureVisitor.java    From jsinterop-generator with Apache License 2.0 5 votes vote down vote up
private void acceptType(JSType type) {
  type = type.restrictByNotNullOrUndefined();

  if (type.isRecordType()) {
    acceptRecordType(toRecordType(type), null);
  } else if (isAnonymousFunctionType(type)) {
    acceptFunctionType(toFunctionType(type), null);
  } else if (type.isTemplatizedType()) {
    type.toMaybeTemplatizedType().getTemplateTypes().forEach(this::acceptType);
  } else if (type.isUnionType()) {
    type.toMaybeUnionType().getAlternates().forEach(this::acceptType);
  }
}
 
Example 3
Source File: AnonymousTypeCollector.java    From jsinterop-generator with Apache License 2.0 5 votes vote down vote up
@Override
protected void pushCurrentJavaType(JSType jsType) {
  if (jsType.isRecordType() || isAnonymousFunctionType(jsType)) {
    // We are collecting these types and there is no java type associated to them yet.
    // after creation, the visitor will push the type by calling
    // pushCurrentJavaType(Type javaType)
    return;
  }

  super.pushCurrentJavaType(jsType);
}
 
Example 4
Source File: DeclarationGenerator.java    From clutz with MIT License 2 votes vote down vote up
/**
 * Whether the typedef should be emitted by name or by the type it is defining.
 *
 * <p>Because, we do not access the original type signature, the replacement is done for all
 * references of the type (through the typedef or direct). Thus it is undesirable to always emit
 * by name. For example:
 *
 * <pre>
 * \@constructor A;
 * \@typedef {A} B;
 * \@const {A} var a;
 * </pre>
 *
 * If we emit the name, we would emit `var a: B;`, which is undesirable (consider A being string).
 *
 * <p>For now, only emit by name typedefs that are unlikely to have more than one name referring
 * to them - record types, templatized types and function types.
 */
private boolean shouldEmitTypedefByName(JSType realType) {
  return realType.isRecordType() || realType.isTemplatizedType() || realType.isFunctionType();
}