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

The following examples show how to use com.google.javascript.rhino.jstype.TemplatizedType. 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: TypeExpressionParser.java    From js-dossier with Apache License 2.0 6 votes vote down vote up
@Override
public Void caseTemplatizedType(TemplatizedType type) {
  type.getReferencedType().visit(this);
  Iterator<JSType> types = type.getTemplateTypes().iterator();

  if (currentExpression().getNamedType() == null) {
    throw new IllegalStateException("unexpected templatized type structure");
  }
  com.github.jsdossier.proto.NamedType.Builder namedType =
      currentExpression().getNamedTypeBuilder();

  while (types.hasNext()) {
    JSType templateType = types.next();
    expressions.addLast(namedType.addTemplateTypeBuilder());
    templateType.visit(this);
    expressions.removeLast();
  }
  return null;
}
 
Example #2
Source File: TypeParameterCollector.java    From jsinterop-generator with Apache License 2.0 5 votes vote down vote up
@Override
public Void caseTemplatizedType(TemplatizedType type) {
  type.getTemplateTypeMap().getTemplateKeys().stream()
      .map(k -> type.getTemplateTypeMap().getResolvedTemplateType(k))
      .filter(Objects::nonNull)
      .forEach(t -> t.visit(this));
  return null;
}
 
Example #3
Source File: AbstractNoOpVisitor.java    From jsinterop-generator with Apache License 2.0 4 votes vote down vote up
@Override
public T caseTemplatizedType(TemplatizedType type) {
  return null;
}
 
Example #4
Source File: ClosureTypeRegistry.java    From jsinterop-generator with Apache License 2.0 4 votes vote down vote up
@Override
public TypeReference caseTemplatizedType(TemplatizedType type) {
  return createParametrizedTypeReference(type.getReferencedType(), type.getTemplateTypes());
}
 
Example #5
Source File: DeclarationGenerator.java    From clutz with MIT License 4 votes vote down vote up
private Void emitTemplatizedType(TemplatizedType type, boolean inImplementsExtendsPosition) {
  ObjectType referencedType = type.getReferencedType();
  String templateTypeName = getAbsoluteName(type);
  final ImmutableList<JSType> templateTypes = type.getTemplateTypes();
  if (typeRegistry.getNativeType(ARRAY_TYPE).equals(referencedType)
      && templateTypes.size() == 1) {
    // As per TS type grammar, array types require primary types.
    // https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#a-grammar
    if (inImplementsExtendsPosition) {
      emit("Array<");
    }
    visitTypeAsPrimary(templateTypes.get(0));
    emit(inImplementsExtendsPosition ? ">" : "[]");
    return null;
  }

  final String displayName = type.getDisplayName();
  if (PlatformSymbols.NOT_TEMPLATIZED_IN_TYPESCRIPT.contains(displayName)) {
    emit(PlatformSymbols.CLOSURE_TO_TYPESCRIPT.getOrDefault(displayName, displayName));
    return null;
  }

  String maybeGlobalName = maybeRenameGlobalType(displayName);
  templateTypeName = maybeGlobalName == null ? templateTypeName : maybeGlobalName;

  if (templateTypes.isEmpty()) {
    // In Closure, subtypes of `TemplatizedType`s that do not take type arguments are still
    // represented by templatized types.
    emit(templateTypeName);
    typesUsed.add(displayName);
    return null;
  }
  if (typeRegistry.getNativeType(OBJECT_TYPE).equals(referencedType)) {
    checkState(templateTypes.size() == 2, templateTypes);
    emit("{");
    emitIndexSignature(templateTypes.get(0), templateTypes.get(1), false);
    emit("}");
    return null;
  }
  emit(templateTypeName);
  typesUsed.add(displayName);
  emitGenericTypeArguments(templateTypes);
  return null;
}
 
Example #6
Source File: DeclarationGenerator.java    From clutz with MIT License 4 votes vote down vote up
@Override
public Void caseTemplatizedType(TemplatizedType type) {
  emitTemplatizedType(type, true);
  return null;
}
 
Example #7
Source File: BaseJSTypeTestCase.java    From ng-closure-runner with MIT License 4 votes vote down vote up
protected TemplatizedType createTemplatizedType(
    ObjectType baseType, ImmutableList<JSType> templatizedTypes) {
  return registry.createTemplatizedType(baseType, templatizedTypes);
}
 
Example #8
Source File: BaseJSTypeTestCase.java    From ng-closure-runner with MIT License 4 votes vote down vote up
protected TemplatizedType createTemplatizedType(
    ObjectType baseType, JSType... templatizedType) {
  return createTemplatizedType(
      baseType, ImmutableList.copyOf(templatizedType));
}
 
Example #9
Source File: TypeInspector.java    From js-dossier with Apache License 2.0 4 votes vote down vote up
private static JSType stripTemplateTypeInformation(JSType type) {
  if (type.isTemplatizedType()) {
    return ((TemplatizedType) type).getReferencedType();
  }
  return type;
}
 
Example #10
Source File: TypeCollectionPass.java    From js-dossier with Apache License 2.0 4 votes vote down vote up
@Override
public Object caseTemplatizedType(TemplatizedType type) {
  return null;
}