本文整理汇总了Java中com.google.javascript.rhino.jstype.JSType.isUnionType方法的典型用法代码示例。如果您正苦于以下问题:Java JSType.isUnionType方法的具体用法?Java JSType.isUnionType怎么用?Java JSType.isUnionType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.javascript.rhino.jstype.JSType
的用法示例。
在下文中一共展示了JSType.isUnionType方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getUnresolvedReference
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的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;
}
示例2: getTypeAlternatives
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的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;
}
}
}
示例3: acceptType
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
private void acceptType(JSType type) {
type = type.restrictByNotNullOrUndefined();
if (type.isRecordType()) {
acceptRecordType(toRecordType(type), null);
} else if (isAnonymousFunctionType(type)) {
acceptFunctionType(toFunctionType(type), null);
} else if (type.isTemplatizedType()) {
type.toMaybeTemplatizedType().getTemplateTypes().forEach(this::acceptType);
} else if (type.isUnionType()) {
type.toMaybeUnionType().getAlternates().forEach(this::acceptType);
}
}
示例4: isPrototypeNameReference
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
/**
* @return true if n MUST be a prototype name reference.
*/
private boolean isPrototypeNameReference(Node n) {
if (!NodeUtil.isGetProp(n)) {
return false;
}
JSType type = getType(n.getFirstChild());
if (type.isUnknownType() || type.isUnionType()) {
return false;
}
return (type instanceof InstanceObjectType || type.autoboxesTo() != null);
}
示例5: createCheckTypeCallNode
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的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);
}
示例6: createType
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的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.
}