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


Java FunctionType类代码示例

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


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

示例1: visitClassOrInterface

import com.google.javascript.rhino.jstype.FunctionType; //导入依赖的package包/类
@Override
protected boolean visitClassOrInterface(FunctionType type) {
  Type currentJavaType = getCurrentJavaType();
  List<TypeReference> generics = convertTypeParametersDefinition(type);

  currentJavaType.getTypeParameters().addAll(generics);

  // If the type is an external type and have extension point, we need to retrofit the generics on
  // the extension type as well
  if (currentJavaType.isExtern()
      && getJavaTypeRegistry().containsExtensionType(currentJavaType)) {
    Type extensionType = getJavaTypeRegistry().getExtensionType(currentJavaType);
    extensionType.getTypeParameters().addAll(generics);
    // parametrize the extension clause
    TypeReference currentExtensionReference =
        Iterables.getOnlyElement(extensionType.getInheritedTypes());
    checkState(currentExtensionReference instanceof JavaTypeReference);
    extensionType.getInheritedTypes().clear();
    extensionType
        .getInheritedTypes()
        .add(new ParametrizedTypeReference(currentExtensionReference, generics));
  }

  return true;
}
 
开发者ID:google,项目名称:jsinterop-generator,代码行数:26,代码来源:TypeParameterCollector.java

示例2: visitFunctionType

import com.google.javascript.rhino.jstype.FunctionType; //导入依赖的package包/类
@Override
protected boolean visitFunctionType(String name, FunctionType type) {
  // Named FunctionType can be visited several times (when we visit its definition and all
  // references to the FunctionType). We just need to visit them once.
  if (visitedTypes.add(type)) {
    Method jsFunction = new Method();
    jsFunction.setName("onInvoke");
    jsFunction.setReturnType(getJavaTypeRegistry().createTypeReference(type.getReturnType()));
    getCurrentJavaType().addMethod(jsFunction);

    currentJavaMethodDeque.push(jsFunction);

    return true;
  }

  return false;
}
 
开发者ID:google,项目名称:jsinterop-generator,代码行数:18,代码来源:MemberCollector.java

示例3: acceptFunctionType

import com.google.javascript.rhino.jstype.FunctionType; //导入依赖的package包/类
private void acceptFunctionType(FunctionType type, String name) {
  if (type.isConstructor()) {
    // constructor function {function(new:Foo)} are mapped to JsConstructorFn type and don't
    // generate any java type
    return;
  }

  pushCurrentJavaType(type);

  if (visitFunctionType(name, type)) {
    acceptType(type.getReturnType());
    acceptParameters(type);
  }

  endVisitFunctionType(name, type);

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

示例4: acceptClassOrInterface

import com.google.javascript.rhino.jstype.FunctionType; //导入依赖的package包/类
private void acceptClassOrInterface(FunctionType type) {
  pushCurrentJavaType(type.getInstanceType());

  if (visitClassOrInterface(type)) {
    if (type.isConstructor()) {
      acceptConstructor(type);
    }

    // static side
    acceptProperties(type, true);
    //instance side
    acceptProperties(type.getPrototype(), false);
  }

  endVisitClassOrInterface(type);

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

示例5: visitParameter

import com.google.javascript.rhino.jstype.FunctionType; //导入依赖的package包/类
@Override
protected boolean visitParameter(Node parameter, FunctionType owner, int index) {
  String ownerName;
  String paramName;
  if (isAnonymousFunctionType(owner)) {
    // FunctionType case. There is only one method called "onInvoke" and adding method name
    // doesn't make it unique.
    ownerName = "";
    // The java method name will be onInvoke and we need to use it in order to find the parameter
    // name replacement if provided.
    paramName = getParameterNameByMethodName(owner, index, "onInvoke");
  } else {
    // Extract method name as the owner from the fully qualified method name.
    ownerName = extractName(owner.getDisplayName());
    paramName = getParameterNameByMethodName(owner, index, ownerName);
  }

  String baseName = ownerName + toCamelUpperCase(paramName);
  initNameForRecordType(baseName, "Type");
  initNameForFunctionType(baseName);
  return true;
}
 
开发者ID:google,项目名称:jsinterop-generator,代码行数:23,代码来源:AnonymousTypeCollector.java

示例6: recordStaticNameDefinition

import com.google.javascript.rhino.jstype.FunctionType; //导入依赖的package包/类
private Name recordStaticNameDefinition(NodeTraversal t, String name,
    JSType type, Node n, Node parent, Node gParent, Node rValue) {
  if (getNamedContainingFunction() != graph.MAIN) {
    // TODO(user): if A.B() defines A.C(), there is a dependence from
    // A.C() -> A.B(). However, this is not important in module code motion
    // and will be ignored (for now).
  }
  if (type.isFunctionType() && type.isConstructor()) {
    return recordClassConstructorOrInterface(
        name, (FunctionType) type, n, parent, parent.getParent(), rValue);
  } else {
    Name symbol = graph.defineNameIfNotExists(name, isExtern);
    symbol.setType(type);
    if (NodeUtil.isAssign(n)) {
      symbol.addAssignmentDeclaration(n);
    } else {
      symbol.addFunctionDeclaration(n);
    }
    return symbol;
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:22,代码来源:NameReferenceGraphConstruction.java

示例7: recordClassConstructorOrInterface

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

示例8: caseObjectType

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

示例9: visitFunction

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

示例10: visitReturn

import com.google.javascript.rhino.jstype.FunctionType; //导入依赖的package包/类
private void visitReturn(NodeTraversal t, Node n) {
  Node function = t.getEnclosingFunction();
  FunctionType funType = (FunctionType) function.getJSType();

  Node retValue = n.getFirstChild();
  if (retValue == null) {
    return;
  }

  Node checkNode = createCheckTypeCallNode(
      funType.getReturnType(), retValue.cloneTree());

  if (checkNode == null) {
    return;
  }

  n.replaceChild(retValue, checkNode);
  compiler.reportCodeChange();
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:20,代码来源:RuntimeTypeCheck.java

示例11: expectSuperType

import com.google.javascript.rhino.jstype.FunctionType; //导入依赖的package包/类
/**
 * Expect that the first type is the direct superclass of the second type.
 *
 * @param t The node traversal.
 * @param n The node where warnings should point to.
 * @param superObject The expected super instance type.
 * @param subObject The sub instance type.
 */
void expectSuperType(NodeTraversal t, Node n, ObjectType superObject,
    ObjectType subObject) {
  FunctionType subCtor = subObject.getConstructor();
  ObjectType declaredSuper =
      subObject.getImplicitPrototype().getImplicitPrototype();
  if (!declaredSuper.equals(superObject)) {
    if (declaredSuper.equals(getNativeType(OBJECT_TYPE))) {
      compiler.report(
          JSError.make(t, n, MISSING_EXTENDS_TAG_WARNING,
              subObject.toString()));
      registerMismatch(superObject, declaredSuper);
    } else {
      mismatch(t.getSourceName(), n,
          "mismatch in declaration of superclass type",
          superObject, declaredSuper);
    }

    // Correct the super type.
    if (!subCtor.hasCachedValues()) {
      subCtor.setPrototypeBasedOn(superObject);
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:32,代码来源:TypeValidator.java

示例12: expectAllInterfacePropertiesImplemented

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

示例13: registerMismatch

import com.google.javascript.rhino.jstype.FunctionType; //导入依赖的package包/类
private void registerMismatch(JSType found, JSType required) {
  // Don't register a mismatch for differences in null or undefined or if the
  // code didn't downcast.
  found = found.restrictByNotNullOrUndefined();
  required = required.restrictByNotNullOrUndefined();
  if (found.canAssignTo(required) || required.canAssignTo(found)) {
    return;
  }

  mismatches.add(new TypeMismatch(found, required));
  if (found instanceof FunctionType &&
      required instanceof FunctionType) {
    FunctionType fnTypeA = ((FunctionType) found);
    FunctionType fnTypeB = ((FunctionType) required);
    Iterator<Node> paramItA = fnTypeA.getParameters().iterator();
    Iterator<Node> paramItB = fnTypeB.getParameters().iterator();
    while (paramItA.hasNext() && paramItB.hasNext()) {
      registerIfMismatch(paramItA.next().getJSType(),
          paramItB.next().getJSType());
    }

    registerIfMismatch(fnTypeA.getReturnType(), fnTypeB.getReturnType());
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:25,代码来源:TypeValidator.java

示例14: visitNew

import com.google.javascript.rhino.jstype.FunctionType; //导入依赖的package包/类
/**
 * Visits a NEW node.
 */
private void visitNew(NodeTraversal t, Node n) {
  Node constructor = n.getFirstChild();
  FunctionType type = getFunctionType(constructor);
  if (type != null && type.isConstructor()) {
    visitParameterList(t, n, type);
    ensureTyped(t, n, type.getInstanceType());
  } else {
    // TODO(user): add support for namespaced objects.
    if (constructor.getType() != Token.GETPROP) {
      // TODO(user): make the constructor node have lineno/charno
      // and use constructor for a more precise error indication.
      // It seems that GETPROP nodes are missing this information.
      Node line;
      if (constructor.getLineno() < 0 || constructor.getCharno() < 0) {
        line = n;
      } else {
        line = constructor;
      }
      t.report(line, NOT_A_CONSTRUCTOR);
    }
    ensureTyped(t, n);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:27,代码来源:TypeCheck.java

示例15: ensureTyped

import com.google.javascript.rhino.jstype.FunctionType; //导入依赖的package包/类
/**
 * Enforces type casts, and ensures the node is typed.
 *
 * A cast in the way that we use it in JSDoc annotations never
 * alters the generated code and therefore never can induce any runtime
 * operation. What this means is that a 'cast' is really just a compile
 * time constraint on the underlying value. In the future, we may add
 * support for run-time casts for compiled tests.
 *
 * To ensure some shred of sanity, we enforce the notion that the
 * type you are casting to may only meaningfully be a narrower type
 * than the underlying declared type. We also invalidate optimizations
 * on bad type casts.
 *
 * @param t The traversal object needed to report errors.
 * @param n The node getting a type assigned to it.
 * @param type The type to be assigned.
 */
private void ensureTyped(NodeTraversal t, Node n, JSType type) {
  // Make sure FUNCTION nodes always get function type.
  Preconditions.checkState(n.getType() != Token.FUNCTION ||
          type instanceof FunctionType ||
          type.isUnknownType());
  JSDocInfo info = n.getJSDocInfo();
  if (info != null) {
    if (info.hasType()) {
      JSType infoType = info.getType().evaluate(t.getScope());
      validator.expectCanCast(t, n, infoType, type);
      type = infoType;
    }

    if (info.isImplicitCast() && !inExterns) {
      String propName = n.getType() == Token.GETPROP ?
          n.getLastChild().getString() : "(missing)";
      compiler.report(
          JSError.make(t, n, ILLEGAL_IMPLICIT_CAST, propName));
    }
  }

  if (n.getJSType() == null) {
    n.setJSType(type);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:44,代码来源:TypeCheck.java


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