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


Java JSTypeRegistry.createFunctionType方法代码示例

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


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

示例1: fixFunctionType

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

示例2: testFunctionMismatch

import com.google.javascript.rhino.jstype.JSTypeRegistry; //导入方法依赖的package包/类
public void testFunctionMismatch() throws Exception {
  testSame(
      "/** \n" +
      " * @param {function(string): number} x \n" +
      " * @return {function(boolean): string} \n" +
      " */ function f(x) { return x; }",
      TYPE_MISMATCH_WARNING);

  JSTypeRegistry registry = compiler.getTypeRegistry();
  JSType string = registry.getNativeType(STRING_TYPE);
  JSType bool = registry.getNativeType(BOOLEAN_TYPE);
  JSType number = registry.getNativeType(NUMBER_TYPE);
  JSType firstFunction = registry.createFunctionType(number, string);
  JSType secondFunction = registry.createFunctionType(string, bool);

  assertMismatches(
      Lists.newArrayList(
          new TypeMismatch(firstFunction, secondFunction),
          fromNatives(STRING_TYPE, BOOLEAN_TYPE),
          fromNatives(NUMBER_TYPE, STRING_TYPE)));
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:22,代码来源:TypeValidatorTest.java

示例3: testFunctionMismatch2

import com.google.javascript.rhino.jstype.JSTypeRegistry; //导入方法依赖的package包/类
public void testFunctionMismatch2() throws Exception {
  testSame(
      "/** \n" +
      " * @param {function(string): number} x \n" +
      " * @return {function(boolean): number} \n" +
      " */ function f(x) { return x; }",
      TYPE_MISMATCH_WARNING);

  JSTypeRegistry registry = compiler.getTypeRegistry();
  JSType string = registry.getNativeType(STRING_TYPE);
  JSType bool = registry.getNativeType(BOOLEAN_TYPE);
  JSType number = registry.getNativeType(NUMBER_TYPE);
  JSType firstFunction = registry.createFunctionType(number, string);
  JSType secondFunction = registry.createFunctionType(number, bool);

  assertMismatches(
      Lists.newArrayList(
          new TypeMismatch(firstFunction, secondFunction),
          fromNatives(STRING_TYPE, BOOLEAN_TYPE)));
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:21,代码来源:TypeValidatorTest.java

示例4: fixFunctionType

import com.google.javascript.rhino.jstype.JSTypeRegistry; //导入方法依赖的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 = JSType.toMaybeFunctionType(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:SpoonLabs,项目名称:astor,代码行数:28,代码来源:DevirtualizePrototypeMethods.java

示例5: testFunctionMismatch

import com.google.javascript.rhino.jstype.JSTypeRegistry; //导入方法依赖的package包/类
public void testFunctionMismatch() throws Exception {
  testSame(
      "/** \n" +
      " * @param {function(string): number} x \n" +
      " * @return {function(boolean): string} \n" +
      " */ function f(x) { return x; }",
      TYPE_MISMATCH_WARNING);

  JSTypeRegistry registry = compiler.getTypeRegistry();
  JSType string = registry.getNativeType(STRING_TYPE);
  JSType bool = registry.getNativeType(BOOLEAN_TYPE);
  JSType number = registry.getNativeType(NUMBER_TYPE);
  JSType firstFunction = registry.createFunctionType(number, string);
  JSType secondFunction = registry.createFunctionType(string, bool);

  assertMismatches(
      Lists.newArrayList(
          new TypeMismatch(firstFunction, secondFunction, null),
          fromNatives(STRING_TYPE, BOOLEAN_TYPE),
          fromNatives(NUMBER_TYPE, STRING_TYPE)));
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:22,代码来源:TypeValidatorTest.java

示例6: testFunctionMismatch2

import com.google.javascript.rhino.jstype.JSTypeRegistry; //导入方法依赖的package包/类
public void testFunctionMismatch2() throws Exception {
  testSame(
      "/** \n" +
      " * @param {function(string): number} x \n" +
      " * @return {function(boolean): number} \n" +
      " */ function f(x) { return x; }",
      TYPE_MISMATCH_WARNING);

  JSTypeRegistry registry = compiler.getTypeRegistry();
  JSType string = registry.getNativeType(STRING_TYPE);
  JSType bool = registry.getNativeType(BOOLEAN_TYPE);
  JSType number = registry.getNativeType(NUMBER_TYPE);
  JSType firstFunction = registry.createFunctionType(number, string);
  JSType secondFunction = registry.createFunctionType(number, bool);

  assertMismatches(
      Lists.newArrayList(
          new TypeMismatch(firstFunction, secondFunction, null),
          fromNatives(STRING_TYPE, BOOLEAN_TYPE)));
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:21,代码来源:TypeValidatorTest.java

示例7: testFunctionMismatch

import com.google.javascript.rhino.jstype.JSTypeRegistry; //导入方法依赖的package包/类
public void testFunctionMismatch() throws Exception {
  testWarning(
      "/** \n"
          + " * @param {function(string): number} x \n"
          + " * @return {function(boolean): string} \n"
          + " */ function f(x) { return x; }",
      TYPE_MISMATCH_WARNING);

  JSTypeRegistry registry = getLastCompiler().getTypeRegistry();
  JSType string = registry.getNativeType(STRING_TYPE);
  JSType bool = registry.getNativeType(BOOLEAN_TYPE);
  JSType number = registry.getNativeType(NUMBER_TYPE);
  JSType firstFunction = registry.createFunctionType(number, string);
  JSType secondFunction = registry.createFunctionType(string, bool);

  assertMismatches(
      ImmutableList.of(
          new TypeMismatch(firstFunction, secondFunction, null),
          fromNatives(STRING_TYPE, BOOLEAN_TYPE),
          fromNatives(NUMBER_TYPE, STRING_TYPE)));
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:22,代码来源:TypeValidatorTest.java

示例8: testFunctionMismatch2

import com.google.javascript.rhino.jstype.JSTypeRegistry; //导入方法依赖的package包/类
public void testFunctionMismatch2() throws Exception {
  testWarning(
      "/** \n"
          + " * @param {function(string): number} x \n"
          + " * @return {function(boolean): number} \n"
          + " */ function f(x) { return x; }",
      TYPE_MISMATCH_WARNING);

  JSTypeRegistry registry = getLastCompiler().getTypeRegistry();
  JSType string = registry.getNativeType(STRING_TYPE);
  JSType bool = registry.getNativeType(BOOLEAN_TYPE);
  JSType number = registry.getNativeType(NUMBER_TYPE);
  JSType firstFunction = registry.createFunctionType(number, string);
  JSType secondFunction = registry.createFunctionType(number, bool);

  assertMismatches(
      ImmutableList.of(
          new TypeMismatch(firstFunction, secondFunction, null),
          fromNatives(STRING_TYPE, BOOLEAN_TYPE)));
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:21,代码来源:TypeValidatorTest.java


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