本文整理汇总了Java中com.google.javascript.rhino.jstype.JSType.isUnknownType方法的典型用法代码示例。如果您正苦于以下问题:Java JSType.isUnknownType方法的具体用法?Java JSType.isUnknownType怎么用?Java JSType.isUnknownType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.javascript.rhino.jstype.JSType
的用法示例。
在下文中一共展示了JSType.isUnknownType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: expectIndexMatch
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
/**
* Expect that the first type can be addressed with GETELEM syntax,
* and that the second type is the right type for an index into the
* first type.
*
* @param t The node traversal.
* @param n The node to issue warnings on.
* @param objType The type of the left side of the GETELEM.
* @param indexType The type inside the brackets of the GETELEM.
*/
void expectIndexMatch(NodeTraversal t, Node n, JSType objType,
JSType indexType) {
if (objType.isUnknownType()) {
expectStringOrNumber(t, n, indexType, "property access");
} else if (objType.toObjectType() != null &&
objType.toObjectType().getIndexType() != null) {
expectCanAssignTo(t, n, indexType, objType.toObjectType().getIndexType(),
"restricted index type");
} else if (objType.isArrayType()) {
expectNumber(t, n, indexType, "array access");
} else if (objType.matchesObjectContext()) {
expectString(t, n, indexType, "property access");
} else {
mismatch(t, n, "only arrays or objects can be accessed",
objType, typeRegistry.createUnionType(ARRAY_TYPE, OBJECT_TYPE));
}
}
示例2: doPercentTypedAccounting
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
/**
* Counts the given node in the typed statistics.
* @param n a node that should be typed
*/
private void doPercentTypedAccounting(NodeTraversal t, Node n) {
JSType type = n.getJSType();
if (type == null) {
nullCount++;
} else if (type.isUnknownType()) {
if (reportUnknownTypes.isOn()) {
String unresolvedReference = getUnresolvedReference(type);
if (unresolvedReference != null) {
compiler.report(JSError.make(t, n, reportUnknownTypes,
UNRESOLVED_TYPE, unresolvedReference));
} else {
compiler.report(JSError.make(t, n, reportUnknownTypes,
UNKNOWN_EXPR_TYPE));
}
}
unknownCount++;
} else {
typedCount++;
}
}
示例3: 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;
}
示例4: traverseNew
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
private FlowScope traverseNew(Node n, FlowScope scope) {
Node constructor = n.getFirstChild();
scope = traverse(constructor, scope);
JSType constructorType = constructor.getJSType();
JSType type = null;
if (constructorType != null) {
constructorType = constructorType.restrictByNotNullOrUndefined();
if (constructorType.isUnknownType()) {
type = getNativeType(UNKNOWN_TYPE);
} else if (constructorType instanceof FunctionType) {
FunctionType ct = (FunctionType) constructorType;
if (ct.isConstructor()) {
type = ct.getInstanceType();
}
}
}
n.setJSType(type);
for (Node arg = constructor.getNext(); arg != null; arg = arg.getNext()) {
scope = traverse(arg, scope);
}
return scope;
}
示例5: maybeAddAutoboxes
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
/**
* Add concrete types for autoboxing types if necessary. The concrete type
* system does not track native types, like string, so add them if they are
* present in the JSType for the node.
*/
private ConcreteType maybeAddAutoboxes(
ConcreteType cType, Node node, String prop) {
JSType jsType = node.getJSType();
if (jsType == null) {
return cType;
} else if (jsType.isUnknownType()) {
for (JSTypeNative nativeType : nativeTypes) {
ConcreteType concrete = tt.getConcreteInstance(
tt.getTypeRegistry().getNativeObjectType(nativeType));
if (concrete != null && !concrete.getPropertyType(prop).isNone()) {
cType = cType.unionWith(concrete);
}
}
return cType;
}
return maybeAddAutoboxes(cType, jsType, prop);
}
示例6: 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);
}
示例7: getFunctionType
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
/**
* Gets the type of the node or {@code null} if the node's type is not a
* function.
*/
private FunctionType getFunctionType(Node n) {
JSType type = getJSType(n).restrictByNotNullOrUndefined();
if (type.isUnknownType()) {
return typeRegistry.getNativeFunctionType(U2U_CONSTRUCTOR_TYPE);
} else if (type instanceof FunctionType) {
return (FunctionType) type;
} else {
return null;
}
}
示例8: completeScope
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
/**
* Look through the given scope, and try to find slots where it doesn't
* have enough type information. Then fill in that type information
* with stuff that we've inferred in the local flow.
*/
public void completeScope(Scope scope) {
for (Iterator<Var> it = scope.getVars(); it.hasNext();) {
Var var = it.next();
if (var.isTypeInferred()) {
JSType type = var.getType();
if (type == null || type.isUnknownType()) {
JSType flowType = getSlot(var.getName()).getType();
var.setType(flowType);
}
}
}
}
示例9: getTypeAnnotation
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
private String getTypeAnnotation(Node node) {
JSType type = node.getJSType();
if (type instanceof FunctionType) {
return getFunctionAnnotation(node);
} else if (type != null && !type.isUnknownType()
&& !type.isEmptyType() && !type.isVoidType()) {
return "/** @type {" + node.getJSType() + "} */\n";
} else {
return "";
}
}
示例10: 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.
}
示例11: isValidDefineType
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
/**
* Determines whether the given type is a valid {@code @define} type.
*/
// TODO(nicksantos): Move this into a check pass.
private boolean isValidDefineType(Node typeNode) {
JSType type = typeRegistry.createFromTypeNodes(typeNode, "", null);
return !type.isUnknownType() && type.isSubtype(
typeRegistry.getNativeType(JSTypeNative.NUMBER_STRING_BOOLEAN));
}
示例12: normalizeClassType
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
/**
* Normalize the type of a constructor, its instance, and its prototype
* all down to the same type (the instance type).
*/
private JSType normalizeClassType(JSType type) {
if (type == null || type.isUnknownType()) {
return type;
} else if (type.isConstructor()) {
return ((FunctionType) type).getInstanceType();
} else if (type.isFunctionPrototypeType()) {
FunctionType owner = ((FunctionPrototypeType) type).getOwnerFunction();
if (owner.isConstructor()) {
return owner.getInstanceType();
}
}
return type;
}
示例13: traverseAdd
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
private FlowScope traverseAdd(Node n, FlowScope scope) {
Node left = n.getFirstChild();
Node right = left.getNext();
scope = traverseChildren(n, scope);
JSType leftType = left.getJSType();
JSType rightType = right.getJSType();
JSType type = getNativeType(UNKNOWN_TYPE);
if (leftType != null && rightType != null) {
boolean leftIsUnknown = leftType.isUnknownType();
boolean rightIsUnknown = rightType.isUnknownType();
if (leftIsUnknown && rightIsUnknown) {
type = getNativeType(UNKNOWN_TYPE);
} else if ((!leftIsUnknown && leftType.isString()) ||
(!rightIsUnknown && rightType.isString())) {
type = getNativeType(STRING_TYPE);
} else if (leftIsUnknown || rightIsUnknown) {
type = getNativeType(UNKNOWN_TYPE);
} else if (isAddedAsNumber(leftType) && isAddedAsNumber(rightType)) {
type = getNativeType(NUMBER_TYPE);
} else {
type = registry.createUnionType(STRING_TYPE, NUMBER_TYPE);
}
}
n.setJSType(type);
if (n.getType() == Token.ASSIGN_ADD) {
updateScopeForTypeChange(scope, left, leftType, type);
}
return scope;
}
示例14: getPropertyType
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
private JSType getPropertyType(JSType objType, String propName,
Node n, FlowScope scope) {
// Scopes sometimes contain inferred type info about qualified names.
String qualifiedName = n.getQualifiedName();
StaticSlot<JSType> var = scope.getSlot(qualifiedName);
if (var != null) {
JSType varType = var.getType();
if (varType != null) {
if (varType.equals(getNativeType(UNKNOWN_TYPE)) &&
var != syntacticScope.getSlot(qualifiedName)) {
// If the type of this qualified name has been checked in this scope,
// then use CHECKED_UNKNOWN_TYPE instead to indicate that.
return getNativeType(CHECKED_UNKNOWN_TYPE);
} else {
return varType;
}
}
}
JSType propertyType = null;
if (objType != null) {
propertyType = objType.findPropertyType(propName);
}
if ((propertyType == null || propertyType.isUnknownType()) &&
qualifiedName != null) {
// If we find this node in the registry, then we can infer its type.
ObjectType regType = ObjectType.cast(registry.getType(qualifiedName));
if (regType != null) {
propertyType = regType.getConstructor();
}
}
return propertyType;
}
示例15: isInvalidatingType
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
@Override public boolean isInvalidatingType(JSType type) {
if (type == null || invalidatingTypes.contains(type) ||
(type.isNamedType() && type.isUnknownType())) {
return true;
}
ObjectType objType = ObjectType.cast(type);
return objType != null && !objType.hasReferenceName();
}