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

The following examples show how to use com.google.javascript.rhino.jstype.JSType#isNamedType() . 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: TypeInspector.java    From js-dossier with Apache License 2.0 6 votes vote down vote up
private Set<JSType> getAssignableTypes(JSType type) {
  if (type.isNamedType()
      && registry.isType(
          ((com.google.javascript.rhino.jstype.NamedType) type).getReferenceName())) {
    type =
        registry
            .getType(((com.google.javascript.rhino.jstype.NamedType) type).getReferenceName())
            .getType();
  }

  Set<JSType> types = new LinkedHashSet<>();
  if (type.toMaybeFunctionType() != null && type.toMaybeFunctionType().hasInstanceType()) {
    types.add(type.toMaybeFunctionType().getInstanceType());
  }

  types.addAll(registry.getImplementedInterfaces(type));
  types.addAll(registry.getTypeHierarchy(type));
  return types;
}
 
Example 2
Source File: Closure_103_DisambiguateProperties_s.java    From coming with MIT License 5 votes vote down vote up
@Override public boolean isInvalidatingType(JSType type) {
  if (type == null || invalidatingTypes.contains(type) ||
      (type.isNamedType() && type.isUnknownType())) {
    return true;
  }

  ObjectType objType = ObjectType.cast(type);
  return objType != null && !objType.hasReferenceName();
}
 
Example 3
Source File: Closure_103_DisambiguateProperties_t.java    From coming with MIT License 5 votes vote down vote up
@Override public boolean isInvalidatingType(JSType type) {
  if (type == null || invalidatingTypes.contains(type) ||
      (type.isNamedType() && type.isUnknownType())) {
    return true;
  }

  ObjectType objType = ObjectType.cast(type);
  return objType != null && !objType.hasReferenceName();
}
 
Example 4
Source File: TypeRegistry.java    From js-dossier with Apache License 2.0 5 votes vote down vote up
private JSType getSuperInstance(
    ObjectType instance,
    FunctionType ctor,
    StaticTypedScope globalScope,
    JSTypeRegistry jsRegistry) {
  JSType superInstance;
  if (ctor.getJSDocInfo() != null && ctor.getJSDocInfo().getBaseType() != null) {
    List<TemplateType> templateTypes = instance.getTemplateTypeMap().getTemplateKeys();
    StaticTypedScope scope =
        templateTypes.isEmpty()
            ? globalScope
            : jsRegistry.createScopeWithTemplates(globalScope, templateTypes);

    JSTypeExpression baseTypeExpression = ctor.getJSDocInfo().getBaseType();
    superInstance = Types.evaluate(baseTypeExpression, scope, jsRegistry);

    // The type expression will resolve to a named type if it is an aliased reference to
    // a module's exported type. Compensate by checking dossier's type registry, which
    // tracks exported types by their exported name (whereas the compiler tracks them by
    // their initially declared name from within the module).
    if (superInstance.isNamedType()
        && isType(superInstance.toMaybeNamedType().getReferenceName())) {
      superInstance = getType(superInstance.toMaybeNamedType().getReferenceName()).getType();
      if (superInstance.isConstructor() || superInstance.isInterface()) {
        superInstance = superInstance.toMaybeFunctionType().getTypeOfThis();
      }
    }

  } else {
    FunctionType superCtor = ctor.getSuperClassConstructor();
    if (superCtor == null) {
      return null;
    }
    superInstance = superCtor.getTypeOfThis();
  }
  return superInstance;
}