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


Java ObjectType.hasProperty方法代码示例

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


在下文中一共展示了ObjectType.hasProperty方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: checkPropertyAccess

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

示例3: caseIn

import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的package包/类
/**
 * Given 'property in object', ensures that the object has the property in the
 * informed scope by defining it as a qualified name if the object type lacks
 * the property and it's not in the blind scope.
 * @param object The node of the right-side of the in.
 * @param propertyName The string of the left-side of the in.
 */
private FlowScope caseIn(Node object, String propertyName, FlowScope blindScope) {
  JSType jsType = object.getJSType();
  jsType = this.getRestrictedWithoutNull(jsType);
  jsType = this.getRestrictedWithoutUndefined(jsType);

  boolean hasProperty = false;
  ObjectType objectType = ObjectType.cast(jsType);
  if (objectType != null) {
    hasProperty = objectType.hasProperty(propertyName);
  }
  if (!hasProperty) {
    String qualifiedName = object.getQualifiedName();
    if (qualifiedName != null) {
      String propertyQualifiedName = qualifiedName + "." + propertyName;
      if (blindScope.getSlot(propertyQualifiedName) == null) {
        FlowScope informed = blindScope.createChildFlowScope();
        JSType unknownType = typeRegistry.getNativeType(
            JSTypeNative.UNKNOWN_TYPE);
        informed.inferQualifiedSlot(
            propertyQualifiedName, unknownType, unknownType);
        return informed;
      }
    }
  }
  return blindScope;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:34,代码来源:SemanticReverseAbstractInterpreter.java

示例4: getImplicitActionsFromProp

import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的package包/类
private Collection<Action> getImplicitActionsFromProp(
    JSType jsType, String prop, Node fnNode) {
  List<Action> actions = Lists.newArrayList();
  if (jsType instanceof UnionType) {
    boolean found = false;
    for (JSType alt : ((UnionType) jsType).getAlternates()) {
      ObjectType altObj = ObjectType.cast(alt);
      if (altObj != null) {
        actions.addAll(getImplicitActionsFromPropNonUnion(
              altObj, prop, fnNode));
        if (altObj.hasProperty(prop)) {
          found = true;
        }
      }
    }
    if (found) {
      return actions;
    }
  } else {
    ObjectType objType = ObjectType.cast(jsType);
    if (objType != null &&
        !objType.isUnknownType() && objType.hasProperty(prop)) {
      return getImplicitActionsFromPropNonUnion(objType, prop, fnNode);
    }
  }

  // If we didn't find a type that has the property, then check if there
  // exists a property with this name anywhere in the externs.
  Set<ObjectType> types = getTypeRegistry().getTypesWithProperty(prop);
  for (ObjectType type : types) {
    actions.addAll(getImplicitActionsFromPropNonUnion(type, prop, fnNode));
  }
  return actions;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:35,代码来源:TightenTypes.java

示例5: ensurePropertyDefined

import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的package包/类
/**
 * Defines a property if the property has not been defined yet.
 */
private void ensurePropertyDefined(Node getprop, JSType rightType) {
  ObjectType objectType = ObjectType.cast(
      getJSType(getprop.getFirstChild()).restrictByNotNullOrUndefined());
  if (objectType != null) {
    if (ensurePropertyDeclaredHelper(getprop, objectType)) {
      return;
    }

    String propName = getprop.getLastChild().getString();
    if (!objectType.isPropertyTypeDeclared(propName)) {
      // We do not want a "stray" assign to define an inferred property
      // for every object of this type in the program. So we use a heuristic
      // approach to determine whether to infer the propery.
      //
      // 1) If the property is already defined, join it with the previously
      //    inferred type.
      // 2) If this isn't an instance object, define it.
      // 3) If the property of an object is being assigned in the constructor,
      //    define it.
      // 4) If this is a stub, define it.
      // 5) Otherwise, do not define the type, but declare it in the registry
      //    so that we can use it for missing property checks.
      if (objectType.hasProperty(propName) ||
          !objectType.isInstanceType()) {
        if ("prototype".equals(propName)) {
          objectType.defineDeclaredProperty(propName, rightType, false);
        } else {
          objectType.defineInferredProperty(propName, rightType, false);
        }
      } else {
        if (getprop.getFirstChild().getType() == Token.THIS &&
            getJSType(syntacticScope.getRootNode()).isConstructor()) {
          objectType.defineInferredProperty(propName, rightType, false);
        } else {
          registry.registerPropertyOnType(propName, objectType);
        }
      }
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:44,代码来源:TypeInference.java


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