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


Java UnionType类代码示例

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


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


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