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


Java ObjectType类代码示例

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


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

示例1: recordClassConstructorOrInterface

import com.google.javascript.rhino.jstype.ObjectType; //导入依赖的package包/类
/**
 * Creates the name in the graph if it does not already exist. Also puts all
 * the properties and prototype properties of this name in the graph.
 */
private Name recordClassConstructorOrInterface(
    String name, FunctionType type, @Nullable Node n, @Nullable Node parent,
    @Nullable Node gParent, @Nullable Node rhs) {
  Preconditions.checkArgument(type.isConstructor() || type.isInterface());
  Name symbol = graph.defineNameIfNotExists(name, isExtern);
  if (rhs != null) {
    // TODO(user): record the definition.
    symbol.setType(getType(rhs));
    if (NodeUtil.isAssign(n)) {
      symbol.addAssignmentDeclaration(n);
    } else {
      symbol.addFunctionDeclaration(n);
    }
  }
  ObjectType prototype = type.getPrototype();
  for (String prop : prototype.getOwnPropertyNames()) {
    graph.defineNameIfNotExists(
        name + ".prototype." + prop, isExtern);
  }
  return symbol;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:26,代码来源:NameReferenceGraphConstruction.java

示例2: caseObjectType

import com.google.javascript.rhino.jstype.ObjectType; //导入依赖的package包/类
@Override
public JSType caseObjectType(ObjectType type) {
  if (target.isUnknownType()) {
    return type;
  }

  FunctionType funcTarget = (FunctionType) target;
  if (funcTarget.hasInstanceType()) {
    if (type.isSubtype(funcTarget.getInstanceType())) {
      return null;
    }

    return type;
  }

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

示例3: testStubsInExterns3

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

示例4: visitFunction

import com.google.javascript.rhino.jstype.ObjectType; //导入依赖的package包/类
private void visitFunction(NodeTraversal t, Node n) {
  FunctionType funType = (FunctionType) n.getJSType();
  if (!funType.isConstructor()) {
    return;
  }

  Node nodeToInsertAfter = findNodeToInsertAfter(n);

  nodeToInsertAfter = addMarker(funType, nodeToInsertAfter, null);

  for (ObjectType interfaceType :
      Sets.newTreeSet(ALPHA, funType.getAllImplementedInterfaces())) {
    nodeToInsertAfter =
        addMarker(funType, nodeToInsertAfter, interfaceType);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:17,代码来源:RuntimeTypeCheck.java

示例5: testObjectLiteral

import com.google.javascript.rhino.jstype.ObjectType; //导入依赖的package包/类
public void testObjectLiteral() throws Exception {
  Node n = parseAndTypeCheck("var a = {m1: 7, m2: 'hello'}");

  Node nameNode = n.getFirstChild().getFirstChild();
  Node objectNode = nameNode.getFirstChild();

  // node extraction
  assertEquals(Token.NAME, nameNode.getType());
  assertEquals(Token.OBJECTLIT, objectNode.getType());

  // value's type
  ObjectType objectType =
      (ObjectType) objectNode.getJSType();
  assertEquals(NUMBER_TYPE, objectType.getPropertyType("m1"));
  assertEquals(STRING_TYPE, objectType.getPropertyType("m2"));

  // variable's type
  assertEquals(objectType, nameNode.getJSType());
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:20,代码来源:TypeCheckTest.java

示例6: testAbstractMethod

import com.google.javascript.rhino.jstype.ObjectType; //导入依赖的package包/类
public void testAbstractMethod() {
  testSame(
      "/** @type {!Function} */ var abstractMethod;" +
      "/** @constructor */ function Foo() {}" +
      "/** @param {number} x */ Foo.prototype.bar = abstractMethod;");
  assertEquals(
      "Function", findNameType("abstractMethod", globalScope).toString());

  FunctionType ctor = (FunctionType) findNameType("Foo", globalScope);
  ObjectType instance = ctor.getInstanceType();
  assertEquals("Foo", instance.toString());

  ObjectType proto = instance.getImplicitPrototype();
  assertEquals("Foo.prototype", proto.toString());

  assertEquals(
      "function (this:Foo, number): ?",
      proto.getPropertyType("bar").toString());
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:20,代码来源:TypedScopeCreatorTest.java

示例7: fixFunctionType

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

示例8: testStubsInExterns2

import com.google.javascript.rhino.jstype.ObjectType; //导入依赖的package包/类
public void testStubsInExterns2() {
  testSame(
      "/** @constructor */ function Extern() {}" +
      "/** @type {Extern} */ var myExtern;" +
      "/** @type {number} */ myExtern.foo;",
      "", 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

示例9: testTypedStubsInExterns

import com.google.javascript.rhino.jstype.ObjectType; //导入依赖的package包/类
public void testTypedStubsInExterns() {
  testSame(
      "/** @constructor \n * @param {*} var_args */ " +
      "function Function(var_args) {}" +
      "/** @type {!Function} */ Function.prototype.apply;",
      "var f = new Function();", null);

  ObjectType f = (ObjectType) globalScope.getVar("f").getType();

  // The type of apply() on a function instance is resolved dynamically,
  // since apply varies with the type of the function it's called on.
  assertEquals(
      "function ((Object|null|undefined), (Object|null|undefined)): ?",
      f.getPropertyType("apply").toString());

  // The type of apply() on the function prototype just takes what it was
  // declared with.
  FunctionType func = (FunctionType) globalScope.getVar("Function").getType();
  assertEquals("Function",
      func.getPrototype().getPropertyType("apply").toString());
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:22,代码来源:TypedScopeCreatorTest.java

示例10: getImplicitActionsFromArgument

import com.google.javascript.rhino.jstype.ObjectType; //导入依赖的package包/类
private Collection<Action> getImplicitActionsFromArgument(
    Node arg, ObjectType thisType, JSType paramType) {
  if (paramType instanceof UnionType) {
    List<Action> actions = Lists.newArrayList();
    for (JSType paramAlt : ((UnionType) paramType).getAlternates()) {
      actions.addAll(
          getImplicitActionsFromArgument(arg, thisType, paramAlt));
    }
    return actions;
  } else if (paramType instanceof FunctionType) {
    return Lists.<Action>newArrayList(createExternFunctionCall(
        arg, thisType, (FunctionType) paramType));
  } else {
    return Lists.<Action>newArrayList(createExternFunctionCall(
        arg, thisType, null));
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:18,代码来源:TightenTypes.java

示例11: createTypeWithSubTypes

import com.google.javascript.rhino.jstype.ObjectType; //导入依赖的package包/类
/**
 * Returns a concrete type from the given JSType that includes the concrete
 * types for subtypes and implementing types for any interfaces.
 */
private ConcreteType createTypeWithSubTypes(JSType jsType) {
  ConcreteType ret = ConcreteType.NONE;
  if (jsType instanceof UnionType) {
    for (JSType alt : ((UnionType) jsType).getAlternates()) {
      ret = ret.unionWith(createTypeWithSubTypes(alt));
    }
  } else {
    ObjectType instType = ObjectType.cast(jsType);
    if (instType != null &&
        instType.getConstructor() != null &&
        instType.getConstructor().isInterface()) {
      Collection<FunctionType> implementors =
          getTypeRegistry().getDirectImplementors(instType);

      for (FunctionType implementor : implementors) {
        ret = ret.unionWith(createTypeWithSubTypes(
            implementor.getInstanceType()));
      }
    } else {
      ret = ret.unionWith(createUnionWithSubTypes(createType(jsType)));
    }
  }
  return ret;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:29,代码来源:TightenTypes.java

示例12: testPropertiesOnInterface

import com.google.javascript.rhino.jstype.ObjectType; //导入依赖的package包/类
public void testPropertiesOnInterface() throws Exception {
  testSame("/** @interface */ var I = function() {};" +
      "/** @type {number} */ I.prototype.bar;" +
      "I.prototype.baz = function(){};");

  Var i = globalScope.getVar("I");
  assertEquals("function (this:I)", i.getType().toString());
  assertTrue(i.getType().isInterface());

  ObjectType iPrototype = (ObjectType)
      ((ObjectType) i.getType()).getPropertyType("prototype");
  assertEquals("I.prototype", iPrototype.toString());
  assertTrue(iPrototype.isFunctionPrototypeType());

  assertEquals("number", iPrototype.getPropertyType("bar").toString());
  assertEquals("function (this:I): ?",
      iPrototype.getPropertyType("baz").toString());

  assertEquals(iPrototype, globalScope.getVar("I.prototype").getType());
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:21,代码来源:TypedScopeCreatorTest.java

示例13: getTypeDeprecationInfo

import com.google.javascript.rhino.jstype.ObjectType; //导入依赖的package包/类
/**
 * Returns the deprecation reason for the type if it is marked
 * as being deprecated. Returns empty string if the type is deprecated
 * but no reason was given. Returns null if the type is not deprecated.
 */
private static String getTypeDeprecationInfo(JSType type) {
  if (type == null) {
    return null;
  }

  JSDocInfo info = type.getJSDocInfo();
  if (info != null && info.isDeprecated()) {
    if (info.getDeprecationReason() != null) {
      return info.getDeprecationReason();
    }
    return "";
  }
  ObjectType objType = ObjectType.cast(type);
  if (objType != null) {
    ObjectType implicitProto = objType.getImplicitPrototype();
    if (implicitProto != null) {
      return getTypeDeprecationInfo(implicitProto);
    }
  }
  return null;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:27,代码来源:CheckAccessControls.java

示例14: ensurePropertyDeclaredHelper

import com.google.javascript.rhino.jstype.ObjectType; //导入依赖的package包/类
/**
 * Declares a property on its owner, if necessary.
 * @return True if a property was declared.
 */
private boolean ensurePropertyDeclaredHelper(
    Node getprop, ObjectType objectType) {
  String propName = getprop.getLastChild().getString();
  String qName = getprop.getQualifiedName();
  if (qName != null) {
    Var var = syntacticScope.getVar(qName);
    if (var != null && !var.isTypeInferred()) {
      // Handle normal declarations that could not be addressed earlier.
      if (propName.equals("prototype") ||
      // Handle prototype declarations that could not be addressed earlier.
          (!objectType.hasOwnProperty(propName) &&
           (!objectType.isInstanceType() ||
               (var.isExtern() && !objectType.isNativeObjectType())))) {
        return objectType.defineDeclaredProperty(
            propName, var.getType(), var.isExtern());
      }
    }
  }
  return false;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:25,代码来源:TypeInference.java

示例15: addInvalidatingType

import com.google.javascript.rhino.jstype.ObjectType; //导入依赖的package包/类
/**
 * Invalidates the given type, so that no properties on it will be renamed.
 */
private void addInvalidatingType(JSType type) {
  type = type.restrictByNotNullOrUndefined();
  if (type instanceof UnionType) {
    for (JSType alt : ((UnionType) type).getAlternates()) {
      addInvalidatingType(alt);
    }
    return;
  }

  typeSystem.addInvalidatingType(type);
  ObjectType objType = ObjectType.cast(type);
  if (objType != null && objType.getImplicitPrototype() != null) {
    typeSystem.addInvalidatingType(objType.getImplicitPrototype());
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:19,代码来源:DisambiguateProperties.java


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