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


Java JSType类代码示例

本文整理汇总了Java中com.google.javascript.rhino.jstype.JSType的典型用法代码示例。如果您正苦于以下问题:Java JSType类的具体用法?Java JSType怎么用?Java JSType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: checkConstructorDeprecation

import com.google.javascript.rhino.jstype.JSType; //导入依赖的package包/类
/**
 * Checks the given NEW node to ensure that access restrictions are obeyed.
 */
private void checkConstructorDeprecation(NodeTraversal t, Node n,
    Node parent) {
  JSType type = n.getJSType();

  if (type != null) {
    String deprecationInfo = getTypeDeprecationInfo(type);

    if (deprecationInfo != null &&
        shouldEmitDeprecationWarning(t, n, parent)) {

      if (!deprecationInfo.isEmpty()) {
          compiler.report(
              JSError.make(t, n, DEPRECATED_CLASS_REASON,
                           type.toString(), deprecationInfo));
      } else {
        compiler.report(
            JSError.make(t, n, DEPRECATED_CLASS, type.toString()));
      }
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:25,代码来源:CheckAccessControls.java

示例2: accept

import com.google.javascript.rhino.jstype.JSType; //导入依赖的package包/类
private void accept(StaticTypedSlot<JSType> var, boolean isStatic) {
  JSType type = var.getType();

  if ((type.isInterface() || type.isConstructor())
      && !type.isInstanceType()
      && toFunctionType(type).getSource() != null
      && !isTypeAlias(var)) {
    acceptClassOrInterface(toFunctionType(type));
  } else if (isModule(type)) {
    acceptModule(var);
  } else if (isTypedef(var)) {
    acceptTypedef(var);
  } else if (type.isEnumType()) {
    acceptEnumType(toEnumType(type));
  } else if (isTypeAlias(var)) {
    // We don't process type alias.
    //   /** @constructor */ function Foo() {};
    //   /** @const */ var Bar = Foo;
  } else {
    acceptMember(var, isStatic);
  }
}
 
开发者ID:google,项目名称:jsinterop-generator,代码行数:23,代码来源:AbstractClosureVisitor.java

示例3: acceptTypedef

import com.google.javascript.rhino.jstype.JSType; //导入依赖的package包/类
private void acceptTypedef(StaticTypedSlot<JSType> typedef) {
  // The type linked to symbol is not the type represented in the @typedef annotations.
  JSType realType = checkNotNull(getJsTypeRegistry().getType(typedef.getName()));

  if (realType.isRecordType()) {
    acceptRecordType(toRecordType(realType), typedef.getName());
  } else if (isAnonymousFunctionType(realType)) {
    acceptFunctionType(toFunctionType(realType), typedef.getName());
  } else {
    // we are in a case where typedef is used as an alias and doesnt define any RecordType or
    // FunctionType.
    // ex:  /** @typedef {string|number} */ var StringOrNumber;
    // The JsCompiler have already inlined all typedefs at call site, so we don't need to visit
    // the typedef definition.
    return;
  }
}
 
开发者ID:google,项目名称:jsinterop-generator,代码行数:18,代码来源:AbstractClosureVisitor.java

示例4: getDescriptionForThrownType

import com.google.javascript.rhino.jstype.JSType; //导入依赖的package包/类
/**
 * Returns the description for the given thrown type, if it
 * exists.
 */
public String getDescriptionForThrownType(JSType type,
    StaticScope<JSType> scope) {
  if (documentation == null || documentation.throwsDescriptions == null) {
    return null;
  }

  for (JSTypeExpression typeExpr :
           documentation.throwsDescriptions.keySet()) {
    if (type.canAssignTo(typeExpr.evaluate(scope))) {
      return documentation.throwsDescriptions.get(typeExpr);
    }
  }

  return null;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:20,代码来源:JSDocInfo.java

示例5: testStubsInExterns4

import com.google.javascript.rhino.jstype.JSType; //导入依赖的package包/类
public void testStubsInExterns4() {
  testSame(
      "Extern.prototype.foo;" +
      "/** @constructor */ function Extern() {}",
      "", null);

  JSType e = globalScope.getVar("Extern").getType();
  assertEquals("function (this:Extern): ?", e.toString());

  ObjectType externProto = ((FunctionType) e).getPrototype();
  assertTrue(globalScope.getRootNode().toStringTree(),
      externProto.hasOwnProperty("foo"));
  assertTrue(externProto.isPropertyTypeInferred("foo"));
  assertEquals("?", externProto.getPropertyType("foo").toString());
  assertTrue(externProto.isPropertyInExterns("foo"));
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:17,代码来源:TypedScopeCreatorTest.java

示例6: traverseNew

import com.google.javascript.rhino.jstype.JSType; //导入依赖的package包/类
private FlowScope traverseNew(Node n, FlowScope scope) {
  Node constructor = n.getFirstChild();
  scope = traverse(constructor, scope);

  JSType constructorType = constructor.getJSType();
  JSType type = null;
  if (constructorType != null) {
    constructorType = constructorType.restrictByNotNullOrUndefined();
    if (constructorType.isUnknownType()) {
      type = getNativeType(UNKNOWN_TYPE);
    } else if (constructorType instanceof FunctionType) {
      FunctionType ct = (FunctionType) constructorType;
      if (ct.isConstructor()) {
        type = ct.getInstanceType();
      }
    }
  }
  n.setJSType(type);

  for (Node arg = constructor.getNext(); arg != null; arg = arg.getNext()) {
    scope = traverse(arg, scope);
  }
  return scope;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:25,代码来源:TypeInference.java

示例7: recordStaticNameDefinition

import com.google.javascript.rhino.jstype.JSType; //导入依赖的package包/类
private Name recordStaticNameDefinition(NodeTraversal t, String name,
    JSType type, Node n, Node parent, Node gParent, Node rValue) {
  if (getNamedContainingFunction() != graph.MAIN) {
    // TODO(user): if A.B() defines A.C(), there is a dependence from
    // A.C() -> A.B(). However, this is not important in module code motion
    // and will be ignored (for now).
  }
  if (type.isFunctionType() && type.isConstructor()) {
    return recordClassConstructorOrInterface(
        name, (FunctionType) type, n, parent, parent.getParent(), rValue);
  } else {
    Name symbol = graph.defineNameIfNotExists(name, isExtern);
    symbol.setType(type);
    if (NodeUtil.isAssign(n)) {
      symbol.addAssignmentDeclaration(n);
    } else {
      symbol.addFunctionDeclaration(n);
    }
    return symbol;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:22,代码来源:NameReferenceGraphConstruction.java

示例8: caseAndOrMaybeShortCircuiting

import com.google.javascript.rhino.jstype.JSType; //导入依赖的package包/类
private FlowScope caseAndOrMaybeShortCircuiting(Node left, Node right,
    FlowScope blindScope, boolean condition) {
  FlowScope leftScope = firstPreciserScopeKnowingConditionOutcome(
      left, blindScope, !condition);
  StaticSlot<JSType> leftVar = leftScope.findUniqueRefinedSlot(blindScope);
  if (leftVar == null) {
    return blindScope;
  }
  FlowScope rightScope = firstPreciserScopeKnowingConditionOutcome(
      left, blindScope, condition);
  rightScope = firstPreciserScopeKnowingConditionOutcome(
      right, rightScope, !condition);
  StaticSlot<JSType> rightVar = rightScope.findUniqueRefinedSlot(blindScope);
  if (rightVar == null || !leftVar.getName().equals(rightVar.getName())) {
    return blindScope;
  }
  JSType type = leftVar.getType().getLeastSupertype(rightVar.getType());
  FlowScope informed = blindScope.createChildFlowScope();
  informed.inferSlotType(leftVar.getName(), type);
  return informed;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:22,代码来源:SemanticReverseAbstractInterpreter.java

示例9: testStubsInExterns3

import com.google.javascript.rhino.jstype.JSType; //导入依赖的package包/类
public void testStubsInExterns3() {
  testSame(
      "/** @type {number} */ myExtern.foo;" +
      "/** @type {Extern} */ var myExtern;" +
      "/** @constructor */ function Extern() {}",
      "", null);

  JSType e = globalScope.getVar("myExtern").getType();
  assertEquals("(Extern|null)", e.toString());

  ObjectType externType = (ObjectType) e.restrictByNotNullOrUndefined();
  assertTrue(globalScope.getRootNode().toStringTree(),
      externType.hasOwnProperty("foo"));
  assertTrue(externType.isPropertyTypeDeclared("foo"));
  assertEquals("number", externType.getPropertyType("foo").toString());
  assertTrue(externType.isPropertyInExterns("foo"));
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:18,代码来源:TypedScopeCreatorTest.java

示例10: getTypeAlternatives

import com.google.javascript.rhino.jstype.JSType; //导入依赖的package包/类
@Override public Iterable<JSType> getTypeAlternatives(JSType type) {
  if (type.isUnionType()) {
    return ((UnionType) type).getAlternates();
  } else {
    ObjectType objType = type.toObjectType();
    if (objType != null &&
        objType.getConstructor() != null &&
        objType.getConstructor().isInterface()) {
      List<JSType> list = Lists.newArrayList();
      for (FunctionType impl
               : registry.getDirectImplementors(objType)) {
        list.add(impl.getInstanceType());
      }
      return list;
    } else {
      return null;
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:20,代码来源:DisambiguateProperties.java

示例11: expectCanAssignToPropertyOf

import com.google.javascript.rhino.jstype.JSType; //导入依赖的package包/类
/**
 * Expect that the first type can be assigned to a symbol of the second
 * type.
 *
 * @param t The node traversal.
 * @param n The node to issue warnings on.
 * @param rightType The type on the RHS of the assign.
 * @param leftType The type of the symbol on the LHS of the assign.
 * @param owner The owner of the property being assigned to.
 * @param propName The name of the property being assigned to.
 * @return True if the types matched, false otherwise.
 */
boolean expectCanAssignToPropertyOf(NodeTraversal t, Node n, JSType rightType,
    JSType leftType, Node owner, String propName) {
  // The NoType check is a hack to make typedefs work ok.
  if (!leftType.isNoType() && !rightType.canAssignTo(leftType)) {
    if (bothIntrinsics(rightType, leftType)) {
      // We have a superior warning for this mistake, which gives you
      // the line numbers of both types.
      registerMismatch(rightType, leftType);
    } else {
      mismatch(t, n,
          "assignment to property " + propName + " of " +
          getReadableJSTypeName(owner, true),
          rightType, leftType);
    }
    return false;
  }
  return true;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:31,代码来源:TypeValidator.java

示例12: fixFunctionType

import com.google.javascript.rhino.jstype.JSType; //导入依赖的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

示例13: checkPropertyAccess

import com.google.javascript.rhino.jstype.JSType; //导入依赖的package包/类
/**
 * Make sure that the access of this property is ok.
 */
private void checkPropertyAccess(JSType childType, String propName,
    NodeTraversal t, Node n) {
  ObjectType objectType = childType.dereference();
  if (objectType != null) {
    JSType propType = getJSType(n);
    if ((!objectType.hasProperty(propName) ||
         objectType.equals(typeRegistry.getNativeType(UNKNOWN_TYPE))) &&
        propType.equals(typeRegistry.getNativeType(UNKNOWN_TYPE))) {
      if (objectType instanceof EnumType) {
        t.report(n, INEXISTENT_ENUM_ELEMENT, propName);
      } else if (!objectType.isEmptyType() &&
          reportMissingProperties && !isPropertyTest(n)) {
        if (!typeRegistry.canPropertyBeDefined(objectType, propName)) {
          t.report(n, INEXISTENT_PROPERTY, propName,
              validator.getReadableJSTypeName(n.getFirstChild(), true));
        }
      }
    }
  } else {
    // TODO(nicksantos): might want to flag the access on a non object when
    // it's impossible to get a property from this type.
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:27,代码来源:TypeCheck.java

示例14: testPropertyInExterns1

import com.google.javascript.rhino.jstype.JSType; //导入依赖的package包/类
public void testPropertyInExterns1() {
  testSame(
      "/** @constructor */ function Extern() {}" +
      "/** @type {Extern} */ var extern;" +
      "/** @return {number} */ extern.one;",
      "/** @constructor */ function Normal() {}" +
      "/** @type {Normal} */ var normal;" +
      "/** @return {number} */ normal.one;", null);

  JSType e = globalScope.getVar("Extern").getType();
  ObjectType externInstance = ((FunctionType) e).getInstanceType();
  assertTrue(externInstance.hasOwnProperty("one"));
  assertTrue(externInstance.isPropertyTypeDeclared("one"));
  assertTypeEquals("function (): number",
      externInstance.getPropertyType("one"));

  JSType n = globalScope.getVar("Normal").getType();
  ObjectType normalInstance = ((FunctionType) n).getInstanceType();
  assertFalse(normalInstance.hasOwnProperty("one"));
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:21,代码来源:TypedScopeCreatorTest.java

示例15: updateTypeOfParametersOnClosure

import com.google.javascript.rhino.jstype.JSType; //导入依赖的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


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