• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java UnionType类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: getUnresolvedReference

import com.google.javascript.rhino.jstype.UnionType; //导入依赖的package包/类
/**
 * Looks through the type to see if it contains an unresolved reference.  This
 * is often the reason that a type is unresolved, and it can occur because of
 * a simple misspelling of a type name.
 */
private String getUnresolvedReference(JSType type) {
  if (type.isNamedType()) {
    NamedType namedType = (NamedType) type;
    if (!namedType.isResolved()) {
      return namedType.getReferenceName();
    }
  } else if (type.isUnionType()) {
    for (JSType alt : ((UnionType) type).getAlternates()) {
      if (alt.isUnknownType()) {
        String unresolvedReference = getUnresolvedReference(alt);
        if (unresolvedReference != null) {
          return unresolvedReference;
        }
      }
    }
  }
  return null;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:24,代码来源:TypeCheck.java


示例2: getImplicitActionsFromArgument

import com.google.javascript.rhino.jstype.UnionType; //导入依赖的package包/类
private Collection<Action> getImplicitActionsFromArgument(
    Node arg, ObjectType thisType, JSType paramType) {
  if (paramType instanceof UnionType) {
    List<Action> actions = Lists.newArrayList();
    for (JSType paramAlt : ((UnionType) paramType).getAlternates()) {
      actions.addAll(
          getImplicitActionsFromArgument(arg, thisType, paramAlt));
    }
    return actions;
  } else if (paramType instanceof FunctionType) {
    return Lists.<Action>newArrayList(createExternFunctionCall(
        arg, thisType, (FunctionType) paramType));
  } else {
    return Lists.<Action>newArrayList(createExternFunctionCall(
        arg, thisType, null));
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:18,代码来源:TightenTypes.java


示例3: createTypeWithSubTypes

import com.google.javascript.rhino.jstype.UnionType; //导入依赖的package包/类
/**
 * Returns a concrete type from the given JSType that includes the concrete
 * types for subtypes and implementing types for any interfaces.
 */
private ConcreteType createTypeWithSubTypes(JSType jsType) {
  ConcreteType ret = ConcreteType.NONE;
  if (jsType instanceof UnionType) {
    for (JSType alt : ((UnionType) jsType).getAlternates()) {
      ret = ret.unionWith(createTypeWithSubTypes(alt));
    }
  } else {
    ObjectType instType = ObjectType.cast(jsType);
    if (instType != null &&
        instType.getConstructor() != null &&
        instType.getConstructor().isInterface()) {
      Collection<FunctionType> implementors =
          getTypeRegistry().getDirectImplementors(instType);

      for (FunctionType implementor : implementors) {
        ret = ret.unionWith(createTypeWithSubTypes(
            implementor.getInstanceType()));
      }
    } else {
      ret = ret.unionWith(createUnionWithSubTypes(createType(jsType)));
    }
  }
  return ret;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:29,代码来源:TightenTypes.java


示例4: addInvalidatingType

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

import com.google.javascript.rhino.jstype.UnionType; //导入依赖的package包/类
@Override public Iterable<JSType> getTypeAlternatives(JSType type) {
  if (type.isUnionType()) {
    return ((UnionType) type).getAlternates();
  } else {
    ObjectType objType = type.toObjectType();
    if (objType != null &&
        objType.getConstructor() != null &&
        objType.getConstructor().isInterface()) {
      List<JSType> list = Lists.newArrayList();
      for (FunctionType impl
               : registry.getDirectImplementors(objType)) {
        list.add(impl.getInstanceType());
      }
      return list;
    } else {
      return null;
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:20,代码来源:DisambiguateProperties.java


示例6: maybeAddAutoboxes

import com.google.javascript.rhino.jstype.UnionType; //导入依赖的package包/类
private ConcreteType maybeAddAutoboxes(
    ConcreteType cType, JSType jsType, String prop) {
  jsType = jsType.restrictByNotNullOrUndefined();
  if (jsType instanceof UnionType) {
    for (JSType alt : ((UnionType) jsType).getAlternates()) {
      return maybeAddAutoboxes(cType, alt, prop);
    }
  }

  if (jsType.autoboxesTo() != null) {
    JSType autoboxed = jsType.autoboxesTo();
    return cType.unionWith(tt.getConcreteInstance((ObjectType) autoboxed));
  } else if (jsType.unboxesTo() != null) {
    return cType.unionWith(tt.getConcreteInstance((ObjectType) jsType));
  }

  return cType;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:19,代码来源:DisambiguateProperties.java


示例7: isInvalidatingType

import com.google.javascript.rhino.jstype.UnionType; //导入依赖的package包/类
/** Returns true if properties on this type should not be renamed. */
private boolean isInvalidatingType(JSType type) {
  if (type instanceof UnionType) {
    type = type.restrictByNotNullOrUndefined();
    if (type instanceof UnionType) {
      for (JSType alt : ((UnionType) type).getAlternates()) {
        if (isInvalidatingType(alt)) {
          return true;
        }
      }
      return false;
    }
  }
  ObjectType objType = ObjectType.cast(type);
  return objType == null
      || invalidatingTypes.contains(objType)
      || !objType.hasReferenceName()
      || (objType.isNamedType() && objType.isUnknownType())
      || objType.isEnumType() || objType.autoboxesTo() != null;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:21,代码来源:AmbiguateProperties.java


示例8: addType

import com.google.javascript.rhino.jstype.UnionType; //导入依赖的package包/类
/** Add this type to this property, calculating */
void addType(JSType newType) {
  if (skipAmbiguating) {
    return;
  }

  ++numOccurrences;

  if (newType instanceof UnionType) {
    newType = newType.restrictByNotNullOrUndefined();
    if (newType instanceof UnionType) {
      for (JSType alt : ((UnionType) newType).getAlternates()) {
        addNonUnionType(alt);
      }
      return;
    }
  }
  addNonUnionType(newType);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:20,代码来源:AmbiguateProperties.java


示例9: createCheckTypeCallNode

import com.google.javascript.rhino.jstype.UnionType; //导入依赖的package包/类
/**
 * Creates a function call to check that the given expression matches the
 * given type at runtime.
 *
 * <p>For example, if the type is {@code (string|Foo)}, the function call is
 * {@code checkType(expr, [valueChecker('string'), classChecker('Foo')])}.
 *
 * @return the function call node or {@code null} if the type is not checked
 */
private Node createCheckTypeCallNode(JSType type, Node expr) {
  Node arrayNode = new Node(Token.ARRAYLIT);
  Collection<JSType> alternates;
  if (type.isUnionType()) {
    alternates = Sets.newTreeSet(ALPHA);
    Iterables.addAll(alternates, ((UnionType)type).getAlternates());
  } else {
    alternates = ImmutableList.of(type);
  }
  for (JSType alternate : alternates) {
    Node checkerNode = createCheckerNode(alternate);
    if (checkerNode == null) {
      return null;
    }
    arrayNode.addChildToBack(checkerNode);
  }
  return new Node(Token.CALL, jsCode("checkType"), expr, arrayNode);
}
 
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:28,代码来源:RuntimeTypeCheck.java


示例10: isInvalidatingType

import com.google.javascript.rhino.jstype.UnionType; //导入依赖的package包/类
/** Returns true if properties on this type should not be renamed. */
private boolean isInvalidatingType(JSType type) {
  if (type instanceof UnionType) {
    type = type.restrictByNotNullOrUndefined();
    if (type instanceof UnionType) {
      for (JSType alt : ((UnionType) type).getAlternates()) {
        if (isInvalidatingType(alt)) {
          return true;
        }
      }
      return false;
    }
  }
  ObjectType objType = ObjectType.cast(type);
  return objType == null
      || invalidatingTypes.contains(objType)
      || !objType.hasReferenceName()
      || objType.isUnknownType() /* unresolved types */
      || objType.isEnumType() || objType.autoboxesTo() != null;
}
 
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:21,代码来源:AmbiguateProperties.java


示例11: visitRecordType

import com.google.javascript.rhino.jstype.UnionType; //导入依赖的package包/类
private void visitRecordType(RecordType type) {
  emit("{");
  Iterator<String> it = getSortedPropertyNamesToEmit(type).iterator();
  while (it.hasNext()) {
    String propName = it.next();
    emit(propName);
    UnionType unionType = type.getPropertyType(propName).toMaybeUnionType();
    if (unionType != null
        && unionType
            .getAlternatesWithoutStructuralTyping()
            .stream()
            .anyMatch(JSType::isVoidType)) {
      emit("?");
      visitTypeDeclaration(type.getPropertyType(propName), false, true);
    } else {
      visitTypeDeclaration(type.getPropertyType(propName), false, false);
    }
    if (it.hasNext()) {
      emit(",");
    }
  }
  emit("}");
}
 
开发者ID:angular,项目名称:clutz,代码行数:24,代码来源:DeclarationGenerator.java


示例12: testUnresolvedUnions

import com.google.javascript.rhino.jstype.UnionType; //导入依赖的package包/类
public void testUnresolvedUnions() throws Exception {
  assertPartialCompilationSucceeds("/** @type {some.thing.Foo|some.thing.Bar} */", "var x;");
  TypedVar x = compiler.getTopScope().getSlot("x");
  assertThat(x.getType().isUnionType()).named("type %s", x.getType()).isTrue();
  UnionType unionType = (UnionType) x.getType();

  Collection<JSType> alternatives = unionType.getAlternates();
  assertThat(alternatives).hasSize(3);

  int nullTypeCount = 0;
  List<String> namedTypes = new ArrayList<>();
  for (JSType alternative : alternatives) {
    assertThat(alternative.isNamedType() || alternative.isNullType()).isTrue();
    if (alternative.isNamedType()) {
      assertThat(alternative.isNoResolvedType()).isTrue();
      namedTypes.add(((NamedType) alternative).getReferenceName());
    }
    if (alternative.isNullType()) {
      nullTypeCount++;
    }
  }
  assertThat(nullTypeCount).isEqualTo(1);
  assertThat(namedTypes).containsExactly("some.thing.Foo", "some.thing.Bar");
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:25,代码来源:PartialCompilationTest.java


示例13: addEventize

import com.google.javascript.rhino.jstype.UnionType; //导入依赖的package包/类
private void addEventize(JSType thisType, JSType thatType) {
  if (collectorFilterType(thisType) ||
      collectorFilterType(thatType) ||
      thisType.isEquivalentTo(thatType)) {
    return;
  }

  String className = thisType.getDisplayName();
  if (thatType.isUnionType()) {
    UnionType ut = thatType.toMaybeUnionType();
    for (JSType type : ut.getAlternates()) {
      if (type.isObject()) {
        addEventizeClass(className, type);
      }
    }
  } else {
    addEventizeClass(className, thatType);
  }
}
 
开发者ID:nicks,项目名称:closure-compiler-old,代码行数:20,代码来源:CheckEventfulObjectDisposal.java


示例14: caseUnionType

import com.google.javascript.rhino.jstype.UnionType; //导入依赖的package包/类
@Override
public JSType caseUnionType(UnionType type) {
  if (target.isUnknownType()) {
    return type;
  }

  FunctionType funcTarget = (FunctionType) target;
  if (funcTarget.hasInstanceType()) {
    return type.getRestrictedUnion(funcTarget.getInstanceType());
  }

  return null;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:14,代码来源:SemanticReverseAbstractInterpreter.java


示例15: createCheckTypeCallNode

import com.google.javascript.rhino.jstype.UnionType; //导入依赖的package包/类
/**
 * Creates a function call to check that the given expression matches the
 * given type at runtime.
 *
 * <p>For example, if the type is {@code (string|Foo)}, the function call is
 * {@code checkType(expr, [valueChecker('string'), classChecker('Foo')])}.
 *
 * @return the function call node or {@code null} if the type is not checked
 */
private Node createCheckTypeCallNode(JSType type, Node expr) {
  Node arrayNode = new Node(Token.ARRAYLIT);
  Iterable<JSType> alternates = type.isUnionType()
           ? Sets.newTreeSet(ALPHA, ((UnionType) type).getAlternates())
           : ImmutableList.of(type);
  for (JSType alternate : alternates) {
    Node checkerNode = createCheckerNode(alternate);
    if (checkerNode == null) {
      return null;
    }
    arrayNode.addChildToBack(checkerNode);
  }
  return new Node(Token.CALL, jsCode("checkType"), expr, arrayNode);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:24,代码来源:RuntimeTypeCheck.java


示例16: getImplicitActionsFromProp

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


示例17: createType

import com.google.javascript.rhino.jstype.UnionType; //导入依赖的package包/类
/** Returns a concrete type from the given JSType. */
private ConcreteType createType(JSType jsType) {
  if (jsType.isUnknownType() || jsType.isEmptyType()) {
    return ConcreteType.ALL;
  }

  if (jsType.isUnionType()) {
    ConcreteType type = ConcreteType.NONE;
    for (JSType alt : ((UnionType) jsType).getAlternates()) {
      type = type.unionWith(createType(alt));
    }
    return type;
  }

  if (jsType.isFunctionType()) {
    if (getConcreteFunction((FunctionType) jsType) != null) {
      return getConcreteFunction((FunctionType) jsType);
    }
    // Since we don't have a declaration, it's not concrete.
    return ConcreteType.ALL;
  }

  if (jsType.isObject()) {
    return createConcreteInstance(jsType.toObjectType());
  }

  return ConcreteType.NONE;  // Not a reference type.
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:29,代码来源:TightenTypes.java


示例18: caseUnionType

import com.google.javascript.rhino.jstype.UnionType; //导入依赖的package包/类
public JSType caseUnionType(UnionType type) {
  JSType restricted = null;
  for (JSType alternate : type.getAlternates()) {
    JSType restrictedAlternate = alternate.visit(this);
    if (restrictedAlternate != null) {
      if (restricted == null) {
        restricted = restrictedAlternate;
      } else {
        restricted = restrictedAlternate.getLeastSupertype(restricted);
      }
    }
  }
  return restricted;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:15,代码来源:ChainableReverseAbstractInterpreter.java


示例19: getTypesToSkipForType

import com.google.javascript.rhino.jstype.UnionType; //导入依赖的package包/类
@Override public ImmutableSet<JSType> getTypesToSkipForType(JSType type) {
  type = type.restrictByNotNullOrUndefined();
  if (type instanceof UnionType) {
    Set<JSType> types = Sets.newHashSet(type);
    for (JSType alt : ((UnionType) type).getAlternates()) {
      types.addAll(getTypesToSkipForTypeNonUnion(type));
    }
    return ImmutableSet.copyOf(types);
  }
  return ImmutableSet.copyOf(getTypesToSkipForTypeNonUnion(type));
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:12,代码来源:DisambiguateProperties.java


示例20: addInvalidatingType

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

  invalidatingTypes.add(type);
  ObjectType objType = ObjectType.cast(type);
  if (objType instanceof InstanceObjectType) {
    invalidatingTypes.add(objType.getImplicitPrototype());
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:18,代码来源:AmbiguateProperties.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java MessagingServiceMBean类代码示例发布时间:2022-05-22
下一篇:
Java TemporalAction类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap