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


Java ObjectType.defineDeclaredProperty方法代码示例

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


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

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

示例2: createInstance

import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的package包/类
/** Creates a fake instance with the given description. */
private ConcreteInstanceType createInstance(
    String name, String... propNames) {
  ObjectType objType = typeRegistry.createObjectType(name, null,
      typeRegistry.createObjectType(name + ".prototype", null, null));
  for (int i = 0; i < propNames.length; ++i) {
    objType.defineDeclaredProperty(propNames[i], unknownType, false);
  }
  return new ConcreteInstanceType(factory, objType);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:11,代码来源:ConcreteTypeTest.java

示例3: addMethod

import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的package包/类
private static void addMethod(
    JSTypeRegistry registry, ObjectType receivingType, String methodName,
    JSType returnType) {
  receivingType.defineDeclaredProperty(methodName,
      new FunctionType(registry, null, null, null, returnType), true);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:7,代码来源:BaseJSTypeTestCase.java

示例4: defineSlot

import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的package包/类
/**
 * Defines a typed variable. The defining node will be annotated with the
 * variable's type of {@link JSTypeNative#UNKNOWN_TYPE} if its type is
 * inferred.
 *
 * Slots may be any variable or any qualified name in the global scope.
 *
 * @param n the defining NAME or GETPROP node.
 * @param parent the {@code n}'s parent.
 * @param type the variable's type. It may be {@code null} if
 *     {@code inferred} is {@code true}.
 */
void defineSlot(Node n, Node parent, JSType type, boolean inferred) {
  Preconditions.checkArgument(inferred || type != null);

  // Only allow declarations of NAMEs and qualfied names.
  boolean shouldDeclareOnGlobalThis = false;
  if (n.getType() == Token.NAME) {
    Preconditions.checkArgument(
        parent.getType() == Token.FUNCTION ||
        parent.getType() == Token.VAR ||
        parent.getType() == Token.LP ||
        parent.getType() == Token.CATCH);
    shouldDeclareOnGlobalThis = scope.isGlobal() &&
        (parent.getType() == Token.VAR ||
         parent.getType() == Token.FUNCTION);
  } else {
    Preconditions.checkArgument(
        n.getType() == Token.GETPROP &&
        (parent.getType() == Token.ASSIGN ||
         parent.getType() == Token.EXPR_RESULT));
  }
  String variableName = n.getQualifiedName();
  Preconditions.checkArgument(!variableName.isEmpty());

  // declared in closest scope?
  if (scope.isDeclared(variableName, false)) {
    Var oldVar = scope.getVar(variableName);
    validator.expectUndeclaredVariable(
        sourceName, n, parent, oldVar, variableName, type);
  } else {
    if (!inferred) {
      n.setJSType(type);
    }
    CompilerInput input = compiler.getInput(sourceName);
    scope.declare(variableName, n, type, input, inferred);

    if (shouldDeclareOnGlobalThis) {
      ObjectType globalThis =
          typeRegistry.getNativeObjectType(JSTypeNative.GLOBAL_THIS);
      boolean isExtern = input.isExtern();
      if (inferred) {
        globalThis.defineInferredProperty(variableName,
            type == null ?
                typeRegistry.getNativeType(JSTypeNative.NO_TYPE) :
                type,
            isExtern);
      } else {
        globalThis.defineDeclaredProperty(variableName, type, isExtern);
      }
    }

    // If we're in the global scope, also declare var.prototype
    // in the scope chain.
    if (scope.isGlobal() && type instanceof FunctionType) {
      FunctionType fnType = (FunctionType) type;
      if (fnType.isConstructor() || fnType.isInterface()) {
        FunctionType superClassCtor = fnType.getSuperClassConstructor();
        scope.declare(variableName + ".prototype", n,
            fnType.getPrototype(), compiler.getInput(sourceName),
            /* declared iff there's an explicit supertype */
            superClassCtor == null ||
            superClassCtor.getInstanceType().equals(
                typeRegistry.getNativeType(OBJECT_TYPE)));
      }
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:79,代码来源:TypedScopeCreator.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.defineDeclaredProperty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。