Examples of JSType


Examples of com.google.javascript.rhino.jstype.JSType

      String name = paramNode.getString();
      JSTypeExpression expression = info.getParameterType(name);
      Preconditions.checkNotNull(expression,
          "Missing JSDoc for parameter %s of template function %s",
          name, fnName);
      JSType type = expression.evaluate(null, compiler.getTypeRegistry());
      Preconditions.checkNotNull(type);
      params.add(name);
      paramTypes.put(name, type);
    }

    // Find references to local variables and parameters and replace them.
    traverse(fn, new Visitor() {
      @Override
      public void visit(Node n) {
        if (n.isName()) {
          Node parent = n.getParent();
          String name = n.getString();
          if (!name.isEmpty() && parent.isVar() && !locals.contains(name)) {
            locals.add(n.getString());
          }

          if (params.contains(name)) {
            JSType type = paramTypes.get(name);
            replaceNodeInPlace(n,
                createTemplateParameterNode(params.indexOf(name), type));
          } else if (locals.contains(name)) {
            replaceNodeInPlace(n,
                createTemplateLocalNameNode(locals.indexOf(name)));
View Full Code Here

Examples of com.google.javascript.rhino.jstype.JSType

        return ast.isEquivalentTo(previousMatch);
      }

      // Only the types need to match for the template parameters, which allows
      // the template function to express arbitrary expressions.
      JSType templateType = template.getJSType();

      Preconditions.checkNotNull(templateType, "null template parameter type.");

      // TODO(johnlenz): We shouldn't spend time checking template whose
      // types whose definitions aren't included (NoResolvedType). Alternately
      // we should treat them as "unknown" and perform loose matches.
      if (templateType.isNoResolvedType()) {
        return false;
      }

      boolean isMatch = false;
      JSType astType = ast.getJSType();
      if (astType == null || astType.isUnknownType() || astType.isAllType()) {
        isMatch = true;
        isLooseMatch = true;
      } else {
        isMatch = astType.isSubtype(templateType);
      }
      if (isMatch && previousMatch == null) {
        paramNodeMatches.set(paramIndex, ast);
      }
      return isMatch;
View Full Code Here

Examples of com.google.javascript.rhino.jstype.JSType

      }

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

      // Implemented interfaces (for constructors only).
      if (info.getImplementedInterfaceCount() > 0) {
        if (isConstructor) {
          implementedInterfaces = Lists.newArrayList();
          Set<JSType> baseInterfaces = new HashSet<>();
          for (JSTypeExpression t : info.getImplementedInterfaces()) {
            JSType maybeInterType = t.evaluate(scope, typeRegistry);

            if (maybeInterType != null &&
                maybeInterType.setValidator(new ImplementedTypeValidator())) {
              // Disallow implementing the same base (not templatized) interface
              // type more than once.
              JSType baseInterface = maybeInterType;
              if (baseInterface.toMaybeTemplatizedType() != null) {
                baseInterface =
                    baseInterface.toMaybeTemplatizedType().getReferencedType();
              }
              if (baseInterfaces.contains(baseInterface)) {
                reportWarning(SAME_INTERFACE_MULTIPLE_IMPLEMENTS,
                              baseInterface.toString());
              } else {
                baseInterfaces.add(baseInterface);
              }

              implementedInterfaces.add((ObjectType) maybeInterType);
            }
          }
        } else if (isInterface) {
          reportWarning(
              TypeCheck.CONFLICTING_IMPLEMENTED_TYPE, formatFnName());
        } else {
          reportWarning(CONSTRUCTOR_REQUIRED, "@implements", formatFnName());
        }
      }

      // extended interfaces (for interfaces only)
      // We've already emitted a warning if this is not an interface.
      if (isInterface) {
        extendedInterfaces = Lists.newArrayList();
        for (JSTypeExpression t : info.getExtendedInterfaces()) {
          JSType maybeInterfaceType = t.evaluate(scope, typeRegistry);
          if (maybeInterfaceType != null &&
              maybeInterfaceType.setValidator(new ExtendedTypeValidator())) {
            extendedInterfaces.add((ObjectType) maybeInterfaceType);
          }
        }
      }
    }
View Full Code Here

Examples of com.google.javascript.rhino.jstype.JSType

  /**
   * Infers the type of {@code this}.
   * @param info The JSDocInfo for this function.
   */
  FunctionTypeBuilder inferThisType(JSDocInfo info) {
    JSType maybeThisType = null;
    if (info != null && info.hasThisType()) {
      // TODO(johnlenz): In ES5 strict mode a function can have a null or
      // undefined "this" value, but all the existing "@this" annotations
      // don't declare restricted types.
      maybeThisType = info.getThisType().evaluate(scope, typeRegistry)
View Full Code Here

Examples of com.google.javascript.rhino.jstype.JSType

    for (Node arg : argsParent.children()) {
      String argumentName = arg.getString();
      allJsDocParams.remove(argumentName);

      // type from JSDocInfo
      JSType parameterType = null;
      boolean isOptionalParam = isOptionalParameter(arg, info);
      isVarArgs = isVarArgsParameter(arg, info);

      if (info != null && info.hasParameterType(argumentName)) {
        parameterType =
View Full Code Here

Examples of com.google.javascript.rhino.jstype.JSType

   */
  private FunctionType getOrCreateConstructor() {
    FunctionType fnType = typeRegistry.createConstructorType(
        fnName, contents.getSourceNode(), parametersNode, returnType,
        classTemplateTypeNames);
    JSType existingType = typeRegistry.getType(fnName);

    if (makesStructs) {
      fnType.setStruct();
    } else if (makesDicts) {
      fnType.setDict();
    }
    if (existingType != null) {
      boolean isInstanceObject = existingType.isInstanceType();
      if (isInstanceObject || fnName.equals("Function")) {
        FunctionType existingFn =
            isInstanceObject ?
            existingType.toObjectType().getConstructor() :
            typeRegistry.getNativeFunctionType(FUNCTION_FUNCTION_TYPE);

        if (existingFn.getSource() == null) {
          existingFn.setSource(contents.getSourceNode());
        }
View Full Code Here

Examples of com.google.javascript.rhino.jstype.JSType

    asynchRecord = record("service", type(ARRAY_TYPE, NUMBER_TYPE));

  }

  private JSType union(JSType... variants) {
    JSType type = createUnionType(variants);
    assertTrue(type.isUnionType());
    return type;
  }
View Full Code Here

Examples of com.google.javascript.rhino.jstype.JSType

      Scope scope = new TypedScopeCreator(compiler).createScope(
          extraTypeDefs, null);
      // Evaluate the type transformation
      TypeTransformation typeTransformation =
          new TypeTransformation(compiler, scope);
      JSType resultType = typeTransformation.eval(ast, typeVars, nameVars);
      checkReportedWarningsHelper(expectedWarnings);
      assertTypeEquals(expectedType, resultType);
    }
  }
View Full Code Here

Examples of com.google.javascript.rhino.jstype.JSType

      if (!prop.scheduleRenaming(n.getLastChild(),
                                 processProperty(t, prop, type, null))) {
        if (propertiesToErrorFor.containsKey(name)) {
          String suggestion = "";
          if (type instanceof JSType) {
            JSType jsType = (JSType) type;
            if (jsType.isAllType() || jsType.isUnknownType()) {
              if (n.getFirstChild().isThis()) {
                suggestion = "The \"this\" object is unknown in the function," +
                    "consider using @this";
              } else {
                String qName = n.getFirstChild().getQualifiedName();
View Full Code Here

Examples of com.google.javascript.rhino.jstype.JSType

      return ImmutableSet.copyOf(getTypesToSkipForTypeNonUnion(type));
    }

    private static Set<JSType> getTypesToSkipForTypeNonUnion(JSType type) {
      Set<JSType> types = Sets.newHashSet();
      JSType skipType = type;
      while (skipType != null) {
        types.add(skipType);

        ObjectType objSkipType = skipType.toObjectType();
        if (objSkipType != null) {
          skipType = objSkipType.getImplicitPrototype();
        } else {
          break;
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.