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


Java ObjectType.getImplicitPrototype方法代码示例

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


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

示例1: expectAllInterfacePropertiesImplemented

import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的package包/类
/**
 * Expect that all properties on interfaces that this type implements are
 * implemented.
 */
void expectAllInterfacePropertiesImplemented(FunctionType type) {
  ObjectType instance = type.getInstanceType();
  for (ObjectType implemented : type.getAllImplementedInterfaces()) {
    if (implemented.getImplicitPrototype() != null) {
      for (String prop :
          implemented.getImplicitPrototype().getOwnPropertyNames()) {
        if (!instance.hasProperty(prop)) {
          Node source = type.getSource();
          Preconditions.checkNotNull(source);
          String sourceName = (String) source.getProp(Node.SOURCENAME_PROP);
          sourceName = sourceName == null ? "" : sourceName;

          compiler.report(JSError.make(sourceName, source,
              INTERFACE_METHOD_NOT_IMPLEMENTED,
              prop, implemented.toString(), instance.toString()));
          registerMismatch(instance, implemented);
        }
      }
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:26,代码来源:TypeValidator.java

示例2: 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

示例3: getPropertyDeprecationInfo

import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的package包/类
/**
 * Returns the deprecation reason for the property if it is marked
 * as being deprecated. Returns empty string if the property is deprecated
 * but no reason was given. Returns null if the property is not deprecated.
 */
private static String getPropertyDeprecationInfo(ObjectType type,
                                                 String prop) {
  JSDocInfo info = type.getOwnPropertyJSDocInfo(prop);
  if (info != null && info.isDeprecated()) {
    if (info.getDeprecationReason() != null) {
      return info.getDeprecationReason();
    }

    return "";
  }
  ObjectType implicitProto = type.getImplicitPrototype();
  if (implicitProto != null) {
    return getPropertyDeprecationInfo(implicitProto, prop);
  }
  return null;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:22,代码来源:CheckAccessControls.java

示例4: 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

示例5: 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

示例6: createInstanceScope

import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的package包/类
/** @inheritDoc */
public StaticScope<ConcreteType> createInstanceScope(
    ObjectType instanceType) {
  FakeScope parentScope = null;
  if (instanceType.getImplicitPrototype() != null) {
    ConcreteInstanceType prototype =
        createConcreteInstance(instanceType.getImplicitPrototype());
    parentScope = (FakeScope) prototype.getScope();
  }

  FakeScope scope = new FakeScope(parentScope);
  for (String propName : instanceType.getOwnPropertyNames()) {
    scope.addSlot(propName);
  }
  return scope;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:17,代码来源:ConcreteTypeTest.java

示例7: getSuperType

import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的package包/类
private Optional<ObjectType> getSuperType(FunctionType type) {
  ObjectType proto = type.getPrototype();
  if (proto == null) {
    return Optional.empty();
  }

  ObjectType implicitProto = proto.getImplicitPrototype();
  if (implicitProto == null) {
    return Optional.empty();
  }

  return "Object".equals(implicitProto.getDisplayName())
      ? Optional.empty()
      : Optional.of(implicitProto);
}
 
开发者ID:google,项目名称:jsinterop-generator,代码行数:16,代码来源:InheritanceVisitor.java

示例8: propertyIsImplicitCast

import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的package包/类
/**
 * Returns true if any type in the chain has an implictCast annotation for
 * the given property.
 */
private boolean propertyIsImplicitCast(ObjectType type, String prop) {
  for (; type != null; type = type.getImplicitPrototype()) {
    JSDocInfo docInfo = type.getOwnPropertyJSDocInfo(prop);
    if (docInfo != null && docInfo.isImplicitCast()) {
      return true;
    }
  }
  return false;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:14,代码来源:TypeCheck.java

示例9: createInstanceScope

import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的package包/类
@Override
public StaticScope<ConcreteType> createInstanceScope(
    ObjectType instanceType) {
  ConcreteScope parentScope = null;
  if (instanceType.getImplicitPrototype() != null) {
    ConcreteInstanceType prototype =
        createConcreteInstance(instanceType.getImplicitPrototype());
    parentScope = (ConcreteScope) prototype.getScope();
  }
  ConcreteScope scope = new ConcreteScope(parentScope);
  for (String propName : instanceType.getOwnPropertyNames()) {
    scope.declareSlot(propName, null);
  }
  return scope;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:16,代码来源:TightenTypes.java

示例10: getTypesToSkipForTypeNonUnion

import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的package包/类
private 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;
    }
  }
  return types;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:16,代码来源:DisambiguateProperties.java

示例11: getTypeWithProperty

import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的package包/类
@Override public ObjectType getTypeWithProperty(String field, JSType type) {
  if (!(type instanceof ObjectType)) {
    if (type.autoboxesTo() != null) {
      type = type.autoboxesTo();
    } else {
      return null;
    }
  }

  // Ignore the prototype itself at all times.
  if ("prototype".equals(field)) {
    return null;
  }

  // We look up the prototype chain to find the highest place (if any) that
  // this appears.  This will make references to overriden properties look
  // like references to the initial property, so they are renamed alike.
  ObjectType foundType = null;
  ObjectType objType = ObjectType.cast(type);
  while (objType != null && objType.getImplicitPrototype() != objType) {
    if (objType.hasOwnProperty(field)) {
      foundType = objType;
    }
    objType = objType.getImplicitPrototype();
  }
  // If the property does not exist on the referenced type but the original
  // type is an object type, see if any subtype has the property.
  if (foundType == null) {
    ObjectType maybeType = ObjectType.cast(
        registry.getGreatestSubtypeWithProperty(type, field));
    // getGreatestSubtypeWithProperty does not guarantee that the property
    // is defined on the returned type, it just indicates that it might be,
    // so we have to double check.
    if (maybeType != null && maybeType.hasOwnProperty(field)) {
      foundType = maybeType;
    }
  }
  return foundType;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:40,代码来源:DisambiguateProperties.java

示例12: testAddMethodsPrototypeTwoWays

import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的package包/类
public void testAddMethodsPrototypeTwoWays() throws Exception {
  testSame(
      "/** @constructor */function A() {}" +
      "A.prototype = {m1: 5, m2: true};" +
      "A.prototype.m3 = 'third property!';" +
      "var x = new A();");

  ObjectType instanceType = (ObjectType) findNameType("x", globalScope);
  assertEquals(
      getNativeObjectType(OBJECT_TYPE).getPropertiesCount() + 3,
      instanceType.getPropertiesCount());
  assertEquals(getNativeType(NUMBER_TYPE),
      instanceType.getPropertyType("m1"));
  assertEquals(getNativeType(BOOLEAN_TYPE),
      instanceType.getPropertyType("m2"));
  assertEquals(getNativeType(STRING_TYPE),
      instanceType.getPropertyType("m3"));

  // Verify the prototype chain.
  // The prototype property of a Function has to be a FunctionPrototypeType.
  // In order to make the type safety work out correctly, we create
  // a FunctionPrototypeType with the anonymous object as its implicit
  // prototype. Verify this behavior.
  assertFalse(instanceType.hasOwnProperty("m1"));
  assertFalse(instanceType.hasOwnProperty("m2"));
  assertFalse(instanceType.hasOwnProperty("m3"));

  ObjectType proto1 = instanceType.getImplicitPrototype();
  assertFalse(proto1.hasOwnProperty("m1"));
  assertFalse(proto1.hasOwnProperty("m2"));
  assertTrue(proto1.hasOwnProperty("m3"));

  ObjectType proto2 = proto1.getImplicitPrototype();
  assertTrue(proto2.hasOwnProperty("m1"));
  assertTrue(proto2.hasOwnProperty("m2"));
  assertFalse(proto2.hasProperty("m3"));
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:38,代码来源:TypedScopeCreatorTest.java

示例13: getReadableJSTypeName

import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的package包/类
/**
 * Given a node, get a human-readable name for the type of that node so
 * that will be easy for the programmer to find the original declaration.
 *
 * For example, if SubFoo's property "bar" might have the human-readable
 * name "Foo.prototype.bar".
 *
 * @param n The node.
 * @param dereference If true, the type of the node will be dereferenced
 *     to an Object type, if possible.
 */
String getReadableJSTypeName(Node n, boolean dereference) {
  // If we're analyzing a GETPROP, the property may be inherited by the
  // prototype chain. So climb the prototype chain and find out where
  // the property was originally defined.
  if (n.getType() == Token.GETPROP) {
    ObjectType objectType = getJSType(n.getFirstChild()).dereference();
    if (objectType != null) {
      String propName = n.getLastChild().getString();
      while (objectType != null && !objectType.hasOwnProperty(propName)) {
        objectType = objectType.getImplicitPrototype();
      }

      // Don't show complex function names or anonymous types.
      // Instead, try to get a human-readable type name.
      if (objectType != null &&
          (objectType.getConstructor() != null ||
           objectType.isFunctionPrototypeType())) {
        return objectType.toString() + "." + propName;
      }
    }
  }

  JSType type = getJSType(n);
  if (dereference) {
    ObjectType dereferenced = type.dereference();
    if (dereferenced != null) {
      type = dereferenced;
    }
  }

  String qualifiedName = n.getQualifiedName();
  if (type.isFunctionPrototypeType() ||
      (type.toObjectType() != null &&
       type.toObjectType().getConstructor() != null)) {
    return type.toString();
  } else if (qualifiedName != null) {
    return qualifiedName;
  } else if (type instanceof FunctionType) {
    // Don't show complex function names.
    return "function";
  } else {
    return type.toString();
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:56,代码来源:TypeValidator.java


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