Java Code Examples for com.google.javascript.rhino.JSDocInfo#hasBaseType()

The following examples show how to use com.google.javascript.rhino.JSDocInfo#hasBaseType() . 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: Closure_90_FunctionTypeBuilder_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Infer the role of the function (whether it's a constructor or interface)
 * and what it inherits from in JSDocInfo.
 */
FunctionTypeBuilder inferInheritance(@Nullable JSDocInfo info) {
  if (info != null) {
    isConstructor = info.isConstructor();
    isInterface = info.isInterface();

    // base type
    if (info.hasBaseType()) {
      if (isConstructor || isInterface) {
        JSType maybeBaseType =
            info.getBaseType().evaluate(scope, typeRegistry);
        if (maybeBaseType != null &&
            maybeBaseType.setValidator(new ExtendedTypeValidator())) {
          baseType = (ObjectType) maybeBaseType;
        }
      } else {
        reportWarning(EXTENDS_WITHOUT_TYPEDEF, fnName);
      }
    }

    // implemented interfaces
    if (isConstructor || isInterface) {
      implementedInterfaces = Lists.newArrayList();
      for (JSTypeExpression t : info.getImplementedInterfaces()) {
        JSType maybeInterType = t.evaluate(scope, typeRegistry);
        if (maybeInterType != null &&
            maybeInterType.setValidator(new ImplementedTypeValidator())) {
          implementedInterfaces.add((ObjectType) maybeInterType);
        }
      }
      if (baseType != null) {
        JSType maybeFunctionType = baseType.getConstructor();
        if (maybeFunctionType instanceof FunctionType) {
          FunctionType functionType = baseType.getConstructor();
          Iterables.addAll(
              implementedInterfaces,
              functionType.getImplementedInterfaces());
        }
      }
    } else if (info.getImplementedInterfaceCount() > 0) {
      reportWarning(IMPLEMENTS_WITHOUT_CONSTRUCTOR, fnName);
    }
  }

  return this;
}
 
Example 2
Source File: Closure_90_FunctionTypeBuilder_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Infer the role of the function (whether it's a constructor or interface)
 * and what it inherits from in JSDocInfo.
 */
FunctionTypeBuilder inferInheritance(@Nullable JSDocInfo info) {
  if (info != null) {
    isConstructor = info.isConstructor();
    isInterface = info.isInterface();

    // base type
    if (info.hasBaseType()) {
      if (isConstructor || isInterface) {
        JSType maybeBaseType =
            info.getBaseType().evaluate(scope, typeRegistry);
        if (maybeBaseType != null &&
            maybeBaseType.setValidator(new ExtendedTypeValidator())) {
          baseType = (ObjectType) maybeBaseType;
        }
      } else {
        reportWarning(EXTENDS_WITHOUT_TYPEDEF, fnName);
      }
    }

    // implemented interfaces
    if (isConstructor || isInterface) {
      implementedInterfaces = Lists.newArrayList();
      for (JSTypeExpression t : info.getImplementedInterfaces()) {
        JSType maybeInterType = t.evaluate(scope, typeRegistry);
        if (maybeInterType != null &&
            maybeInterType.setValidator(new ImplementedTypeValidator())) {
          implementedInterfaces.add((ObjectType) maybeInterType);
        }
      }
      if (baseType != null) {
        JSType maybeFunctionType = baseType.getConstructor();
        if (maybeFunctionType instanceof FunctionType) {
          FunctionType functionType = baseType.getConstructor();
          Iterables.addAll(
              implementedInterfaces,
              functionType.getImplementedInterfaces());
        }
      }
    } else if (info.getImplementedInterfaceCount() > 0) {
      reportWarning(IMPLEMENTS_WITHOUT_CONSTRUCTOR, fnName);
    }
  }

  return this;
}