当前位置: 首页>>代码示例>>Java>>正文


Java Node.setJSType方法代码示例

本文整理汇总了Java中com.google.javascript.rhino.Node.setJSType方法的典型用法代码示例。如果您正苦于以下问题:Java Node.setJSType方法的具体用法?Java Node.setJSType怎么用?Java Node.setJSType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.javascript.rhino.Node的用法示例。


在下文中一共展示了Node.setJSType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fixFunctionType

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Creates a new JSType based on the original function type by
 * adding the original this pointer type to the beginning of the
 * argument type list and replacing the this pointer type with
 * NO_TYPE.
 */
private void fixFunctionType(Node functionNode) {
  FunctionType type = (FunctionType) functionNode.getJSType();
  if (type != null) {
    JSTypeRegistry typeRegistry = compiler.getTypeRegistry();

    List<JSType> parameterTypes = Lists.newArrayList();
    parameterTypes.add(type.getTypeOfThis());

    for (Node param : type.getParameters()) {
      parameterTypes.add(param.getJSType());
    }

    ObjectType thisType =
        typeRegistry.getNativeObjectType(JSTypeNative.UNKNOWN_TYPE);
    JSType returnType = type.getReturnType();

    JSType newType = typeRegistry.createFunctionType(
        thisType, returnType, parameterTypes);
    functionNode.setJSType(newType);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:28,代码来源:DevirtualizePrototypeMethods.java

示例2: replaceReferencesToThis

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Replaces references to "this" with references to name.  Do not
 * traverse function boundaries.
 */
private void replaceReferencesToThis(Node node, String name) {
  if (NodeUtil.isFunction(node)) {
    return;
  }

  for (Node child : node.children()) {
    if (NodeUtil.isThis(child)) {
      Node newName = Node.newString(Token.NAME, name);
      newName.setJSType(child.getJSType());
      node.replaceChild(child, newName);
    } else {
      replaceReferencesToThis(child, name);
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:20,代码来源:DevirtualizePrototypeMethods.java

示例3: createFunction

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/** Creates a fake function with the given description. */
private ConcreteFunctionType createFunction(
    String name, String... paramNames) {
  Node args = new Node(Token.LP);
  for (int i = 0; i < paramNames.length; ++i) {
    args.addChildToBack(Node.newString(Token.NAME, paramNames[i]));
  }

  Node decl = new Node(Token.FUNCTION,
                       Node.newString(Token.NAME, name),
                       args,
                       new Node(Token.BLOCK));

  JSType[] paramTypes = new JSType[paramNames.length];
  Arrays.fill(paramTypes, unknownType);
  decl.setJSType(
      typeRegistry.createConstructorType(name, decl, args, unknownType));

  return new ConcreteFunctionType(factory, decl, null);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:21,代码来源:ConcreteTypeTest.java

示例4: traverseCall

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private FlowScope traverseCall(Node n, FlowScope scope) {
  scope = traverseChildren(n, scope);

  Node left = n.getFirstChild();
  JSType functionType = getJSType(left).restrictByNotNullOrUndefined();
  if (functionType != null) {
    if (functionType instanceof FunctionType) {
      FunctionType fnType = (FunctionType) functionType;
      n.setJSType(fnType.getReturnType());
      updateTypeOfParametersOnClosure(n, fnType);
      updateTypeOfThisOnClosure(n, fnType);
    } else if (functionType.equals(getNativeType(CHECKED_UNKNOWN_TYPE))) {
      n.setJSType(getNativeType(CHECKED_UNKNOWN_TYPE));
    }
  }
  return scope;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:18,代码来源:TypeInference.java

示例5: updateTypeOfParametersOnClosure

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * For functions with function parameters, type inference will set the type of
 * a function literal argument from the function parameter type.
 */
private void updateTypeOfParametersOnClosure(Node n, FunctionType fnType) {
  int i = 0;
  for (Node iParameter : fnType.getParameters()) {
    JSType iParameterType = iParameter.getJSType();
    if (iParameterType instanceof FunctionType) {
      FunctionType iParameterFnType = (FunctionType) iParameterType;

      if (i + 1 >= n.getChildCount()) {
        // TypeCheck#visitParametersList will warn so we bail.
        return;
      }
      Node iArgument = n.getChildAtIndex(i + 1);
      JSType iArgumentType = getJSType(iArgument);
      if (iArgument.getType() == Token.FUNCTION &&
          iArgumentType instanceof FunctionType &&
          iArgumentType.getJSDocInfo() == null) {
        iArgument.setJSType(iParameterFnType);
      }
    }
    i++;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:27,代码来源:TypeInference.java

示例6: createVar

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private Node createVar(FlowScope scope, String name, JSType type) {
  Node n = Node.newString(Token.NAME, name);
  functionScope.declare(name, n, null, null);
  ((LinkedFlowScope) scope).inferSlotType(name, type);
  n.setJSType(type);
  return n;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:8,代码来源:SemanticReverseAbstractInterpreterTest.java

示例7: traverseAssign

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private FlowScope traverseAssign(Node n, FlowScope scope) {
  Node left = n.getFirstChild();
  Node right = n.getLastChild();
  scope = traverseChildren(n, scope);

  JSType leftType = left.getJSType();
  JSType rightType = getJSType(right);
  n.setJSType(rightType);

  updateScopeForTypeChange(scope, left, leftType, rightType);
  return scope;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:13,代码来源:TypeInference.java

示例8: traverseName

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private FlowScope traverseName(Node n, FlowScope scope) {
  String varName = n.getString();
  Node value = n.getFirstChild();
  JSType type = n.getJSType();
  if (value != null) {
    scope = traverse(value, scope);
    updateScopeForTypeChange(scope, n, n.getJSType() /* could be null */,
        getJSType(value));
    return scope;
  } else {
    StaticSlot<JSType> var = scope.getSlot(varName);
    if (var != null) {
      // There are two situations where we don't want to use type information
      // from the scope, even if we have it.

      // 1) The var is escaped in a weird way, e.g.,
      // function f() { var x = 3; function g() { x = null } (x); }
      boolean isInferred = var.isTypeInferred();
      boolean unflowable =
          isInferred && unflowableVarNames.contains(varName);

      // 2) We're reading type information from another scope for an
      // inferred variable.
      // var t = null; function f() { (t); }
      boolean nonLocalInferredSlot =
          isInferred &&
          syntacticScope.getParent() != null &&
          var == syntacticScope.getParent().getSlot(varName);

      if (!unflowable && !nonLocalInferredSlot) {
        type = var.getType();
        if (type == null) {
          type = getNativeType(UNKNOWN_TYPE);
        }
      }
    }
  }
  n.setJSType(type);
  return scope;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:41,代码来源:TypeInference.java

示例9: traverseObjectLiteral

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private FlowScope traverseObjectLiteral(Node n, FlowScope scope) {
  if (n.getJSType() != null) {
    // The node has already been traversed by the data-flow analysis
    // framework. Don't re-generate the anonymous object as it might lead to
    // pernicious bugs.
    return scope;
  }
  ObjectType objectType = registry.createAnonymousObjectType();
  for (Node name = n.getFirstChild(); name != null;
       name = name.getNext().getNext()) {
    Node value = name.getNext();
    scope = traverse(name, scope);
    scope = traverse(value, scope);
    String memberName = NodeUtil.getStringValue(name);
    if (memberName != null) {
      // TODO(nicksantos): We need to fix the parser so that we can
      // attach JSDoc to the individual elements of object literals.
      // Right now, this is not possible.
      objectType.defineInferredProperty(memberName, getJSType(value), false);
    } else {
      n.setJSType(getNativeType(UNKNOWN_TYPE));
      return scope;
    }
  }
  n.setJSType(objectType);
  return scope;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:28,代码来源:TypeInference.java

示例10: traverseAdd

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private FlowScope traverseAdd(Node n, FlowScope scope) {
  Node left = n.getFirstChild();
  Node right = left.getNext();
  scope = traverseChildren(n, scope);

  JSType leftType = left.getJSType();
  JSType rightType = right.getJSType();

  JSType type = getNativeType(UNKNOWN_TYPE);
  if (leftType != null && rightType != null) {
    boolean leftIsUnknown = leftType.isUnknownType();
    boolean rightIsUnknown = rightType.isUnknownType();
    if (leftIsUnknown && rightIsUnknown) {
      type = getNativeType(UNKNOWN_TYPE);
    } else if ((!leftIsUnknown && leftType.isString()) ||
               (!rightIsUnknown && rightType.isString())) {
      type = getNativeType(STRING_TYPE);
    } else if (leftIsUnknown || rightIsUnknown) {
      type = getNativeType(UNKNOWN_TYPE);
    } else if (isAddedAsNumber(leftType) && isAddedAsNumber(rightType)) {
      type = getNativeType(NUMBER_TYPE);
    } else {
      type = registry.createUnionType(STRING_TYPE, NUMBER_TYPE);
    }
  }
  n.setJSType(type);

  if (n.getType() == Token.ASSIGN_ADD) {
    updateScopeForTypeChange(scope, left, leftType, type);
  }

  return scope;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:34,代码来源:TypeInference.java

示例11: traverseHook

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private FlowScope traverseHook(Node n, FlowScope scope) {
  Node condition = n.getFirstChild();
  Node trueNode = condition.getNext();
  Node falseNode = n.getLastChild();

  // verify the condition
  scope = traverse(condition, scope);

  // reverse abstract interpret the condition to produce two new scopes
  FlowScope trueScope = reverseInterpreter.
      getPreciserScopeKnowingConditionOutcome(
          condition, scope, true);
  FlowScope falseScope = reverseInterpreter.
      getPreciserScopeKnowingConditionOutcome(
          condition, scope, false);

  // traverse the true node with the trueScope
  traverse(trueNode, trueScope.createChildFlowScope());

  // traverse the false node with the falseScope
  traverse(falseNode, falseScope.createChildFlowScope());

  // meet true and false nodes' types and assign
  JSType trueType = trueNode.getJSType();
  JSType falseType = falseNode.getJSType();
  if (trueType != null && falseType != null) {
    n.setJSType(trueType.getLeastSupertype(falseType));
  } else {
    n.setJSType(null);
  }

  return scope.createChildFlowScope();
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:34,代码来源:TypeInference.java

示例12: traverseGetElem

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private FlowScope traverseGetElem(Node n, FlowScope scope) {
  scope = traverseChildren(n, scope);
  ObjectType objType = ObjectType.cast(
      getJSType(n.getFirstChild()).restrictByNotNullOrUndefined());
  if (objType != null) {
    JSType type = objType.getParameterType();
    if (type != null) {
      n.setJSType(type);
    }
  }
  return dereferencePointer(n.getFirstChild(), scope);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:13,代码来源:TypeInference.java

示例13: newParameter

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private Node newParameter(JSType type) {
  Node paramNode = Node.newString(Token.NAME, "");
  paramNode.setJSType(type);
  root.addChildToBack(paramNode);
  return paramNode;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:7,代码来源:FunctionParamBuilder.java

示例14: getPropertyType

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
@Override
public JSType getPropertyType(String name) {
  if ("prototype".equals(name)) {
    return getPrototype();
  } else {
    if (!hasOwnProperty(name)) {
      if ("call".equals(name)) {
        // Define the "call" function lazily.
        Node params = getParametersNode();
        if (params == null) {
          // If there's no params array, don't do any type-checking
          // in this CALL function.
          defineDeclaredProperty(name,
              new FunctionType(registry, null, null,
                  null, getReturnType()),
              false);
        } else {
          params = params.cloneTree();
          Node thisTypeNode = Node.newString(Token.NAME, "thisType");
          thisTypeNode.setJSType(
              registry.createOptionalNullableType(getTypeOfThis()));
          params.addChildToFront(thisTypeNode);
          thisTypeNode.setOptionalArg(true);

          defineDeclaredProperty(name,
              new FunctionType(registry, null, null,
                  params, getReturnType()),
              false);
        }
      } else if ("apply".equals(name)) {
        // Define the "apply" function lazily.
        FunctionParamBuilder builder = new FunctionParamBuilder(registry);

        // Ecma-262 says that apply's second argument must be an Array
        // or an arguments object. We don't model the arguments object,
        // so let's just be forgiving for now.
        // TODO(nicksantos): Model the Arguments object.
        builder.addOptionalParams(
            registry.createNullableType(getTypeOfThis()),
            registry.createNullableType(
                registry.getNativeType(JSTypeNative.OBJECT_TYPE)));

        defineDeclaredProperty(name,
            new FunctionType(registry, null, null,
                builder.build(), getReturnType()),
            false);
      }
    }

    return super.getPropertyType(name);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:53,代码来源:FunctionType.java

示例15: expectUndeclaredVariable

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Expect that the given variable has not been declared with a type.
 *
 * @param sourceName The name of the source file we're in.
 * @param n The node where warnings should point to.
 * @param parent The parent of {@code n}.
 * @param var The variable that we're checking.
 * @param variableName The name of the variable.
 * @param newType The type being applied to the variable. Mostly just here
 *     for the benefit of the warning.
 */
void expectUndeclaredVariable(String sourceName, Node n, Node parent, Var var,
    String variableName, JSType newType) {
  boolean allowDupe = false;
  if (n.getType() == Token.GETPROP) {
    JSDocInfo info = n.getJSDocInfo();
    if (info == null) {
      info = parent.getJSDocInfo();
    }
    allowDupe =
        info != null && info.getSuppressions().contains("duplicate");
  }

  JSType varType = var.getType();

  // Only report duplicate declarations that have types. Other duplicates
  // will be reported by the syntactic scope creator later in the
  // compilation process.
  if (varType != null &&
      varType != typeRegistry.getNativeType(UNKNOWN_TYPE) &&
      newType != null &&
      newType != typeRegistry.getNativeType(UNKNOWN_TYPE)) {
    // If there are two typed declarations of the same variable, that
    // is an error and the second declaration is ignored, except in the
    // case of native types. A null input type means that the declaration
    // was made in TypedScopeCreator#createInitialScope and is a
    // native type.
    if (var.input == null) {
      n.setJSType(varType);
      if (parent.getType() == Token.VAR) {
        if (n.getFirstChild() != null) {
          n.getFirstChild().setJSType(varType);
        }
      } else {
        Preconditions.checkState(parent.getType() == Token.FUNCTION);
        parent.setJSType(varType);
      }
    } else {
      // Always warn about duplicates if the overridden type does not
      // match the original type.
      //
      // If the types match, suppress the warning iff there was a @suppress
      // tag, or if the original declaration was a stub.
      if (!(allowDupe ||
            var.getParentNode().getType() == Token.EXPR_RESULT) ||
          !newType.equals(varType)) {
        compiler.report(
            JSError.make(sourceName, n, DUP_VAR_DECLARATION,
                variableName, newType.toString(), var.getInputName(),
                String.valueOf(var.nameNode.getLineno()),
                varType.toString()));
      }
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:66,代码来源:TypeValidator.java


注:本文中的com.google.javascript.rhino.Node.setJSType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。