Exemplo n.º 1
0
  /**
   * Resolves a type by looking up its first component in the scope, and subsequent components as
   * properties. The scope must have been fully parsed and a symbol table constructed.
   *
   * @return The type of the symbol, or null if the type could not be found.
   */
  private JSType lookupViaProperties(ErrorReporter reporter, StaticTypedScope<JSType> enclosing) {
    String[] componentNames = reference.split("\\.", -1);
    if (componentNames[0].length() == 0) {
      return null;
    }
    StaticTypedSlot<JSType> slot = enclosing.getSlot(componentNames[0]);
    if (slot == null) {
      return null;
    }
    // If the first component has a type of 'Unknown', then any type
    // names using it should be regarded as silently 'Unknown' rather than be
    // noisy about it.
    JSType slotType = slot.getType();
    if (slotType == null || slotType.isAllType() || slotType.isNoType()) {
      return null;
    }
    JSType value = getTypedefType(reporter, slot);
    if (value == null) {
      return null;
    }

    // resolving component by component
    for (int i = 1; i < componentNames.length; i++) {
      ObjectType parentClass = ObjectType.cast(value);
      if (parentClass == null) {
        return null;
      }
      if (componentNames[i].length() == 0) {
        return null;
      }
      value = parentClass.getPropertyType(componentNames[i]);
    }
    return value;
  }
Exemplo n.º 2
0
 private JSType getTypedefType(ErrorReporter t, StaticTypedSlot<JSType> slot) {
   JSType type = slot.getType();
   if (type != null) {
     return type;
   }
   handleUnresolvedType(t, true);
   return null;
 }