• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ObjectType类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: getTypeAlternatives

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


示例17: maybeAddAutoboxes

import com.google.javascript.rhino.jstype.ObjectType; //导入依赖的package包/类
private ConcreteType maybeAddAutoboxes(
    ConcreteType cType, JSType jsType, String prop) {
  jsType = jsType.restrictByNotNullOrUndefined();
  if (jsType instanceof UnionType) {
    for (JSType alt : ((UnionType) jsType).getAlternates()) {
      return maybeAddAutoboxes(cType, alt, prop);
    }
  }

  if (jsType.autoboxesTo() != null) {
    JSType autoboxed = jsType.autoboxesTo();
    return cType.unionWith(tt.getConcreteInstance((ObjectType) autoboxed));
  } else if (jsType.unboxesTo() != null) {
    return cType.unionWith(tt.getConcreteInstance((ObjectType) jsType));
  }

  return cType;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:19,代码来源:DisambiguateProperties.java


示例18: testAbstractMethod

import com.google.javascript.rhino.jstype.ObjectType; //导入依赖的package包/类
public void testAbstractMethod() {
  testSame(
      "/** Abstract method. \n * @type {!Function} */ var abstractMethod;" +
      "/** @constructor */ function Foo() {}" +
      "/** Block description. \n * @param {number} x */" +
      "Foo.prototype.bar = abstractMethod;");
  FunctionType abstractMethod =
      (FunctionType) findGlobalNameType("abstractMethod");
  assertNull(abstractMethod.getJSDocInfo());

  FunctionType ctor = (FunctionType) findGlobalNameType("Foo");
  ObjectType proto = ctor.getInstanceType().getImplicitPrototype();
  FunctionType method = (FunctionType) proto.getPropertyType("bar");
  assertEquals(
      "Block description.",
      method.getJSDocInfo().getBlockDescription());
  assertEquals(
      "Block description.",
      proto.getOwnPropertyJSDocInfo("bar").getBlockDescription());
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:21,代码来源:InferJSDocInfoTest.java


示例19: testNamespacedEnum

import com.google.javascript.rhino.jstype.ObjectType; //导入依赖的package包/类
public void testNamespacedEnum() {
  testSame("var goog = {}; goog.ui = {};" +
      "/** @constructor */goog.ui.Zippy = function() {};" +
      "/** @enum{string} */goog.ui.Zippy.EventType = { TOGGLE: 'toggle' };" +
      "var x = goog.ui.Zippy.EventType;" +
      "var y = goog.ui.Zippy.EventType.TOGGLE;");

  ObjectType x = (ObjectType) findNameType("x", globalScope);
  assertTrue(x.isEnumType());
  assertTrue(x.hasProperty("TOGGLE"));
  assertEquals("enum{goog.ui.Zippy.EventType}", x.getReferenceName());

  ObjectType y = (ObjectType) findNameType("y", globalScope);
  assertTrue(y.isSubtype(getNativeType(STRING_TYPE)));
  assertTrue(y.isEnumElementType());
  assertEquals("goog.ui.Zippy.EventType", y.getReferenceName());
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:18,代码来源:TypedScopeCreatorTest.java


示例20: acceptModule

import com.google.javascript.rhino.jstype.ObjectType; //导入依赖的package包/类
private void acceptModule(StaticTypedSlot<JSType> module) {
  pushCurrentJavaType(module.getType());

  if (visitModule(module)) {
    acceptProperties((ObjectType) module.getType(), true);
  }

  endVisitModule(module);

  popCurrentJavaType();
}
 
开发者ID:google,项目名称:jsinterop-generator,代码行数:12,代码来源:AbstractClosureVisitor.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java JobsInfo类代码示例发布时间:2022-05-22
下一篇:
Java LineNumberTag类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap