本文整理汇总了Java中com.google.javascript.rhino.jstype.JSType.canAssignTo方法的典型用法代码示例。如果您正苦于以下问题:Java JSType.canAssignTo方法的具体用法?Java JSType.canAssignTo怎么用?Java JSType.canAssignTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.javascript.rhino.jstype.JSType
的用法示例。
在下文中一共展示了JSType.canAssignTo方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDescriptionForThrownType
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
/**
* Returns the description for the given thrown type, if it
* exists.
*/
public String getDescriptionForThrownType(JSType type,
StaticScope<JSType> scope) {
if (documentation == null || documentation.throwsDescriptions == null) {
return null;
}
for (JSTypeExpression typeExpr :
documentation.throwsDescriptions.keySet()) {
if (type.canAssignTo(typeExpr.evaluate(scope))) {
return documentation.throwsDescriptions.get(typeExpr);
}
}
return null;
}
示例2: expectCanAssignToPropertyOf
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
/**
* Expect that the first type can be assigned to a symbol of the second
* type.
*
* @param t The node traversal.
* @param n The node to issue warnings on.
* @param rightType The type on the RHS of the assign.
* @param leftType The type of the symbol on the LHS of the assign.
* @param owner The owner of the property being assigned to.
* @param propName The name of the property being assigned to.
* @return True if the types matched, false otherwise.
*/
boolean expectCanAssignToPropertyOf(NodeTraversal t, Node n, JSType rightType,
JSType leftType, Node owner, String propName) {
// The NoType check is a hack to make typedefs work ok.
if (!leftType.isNoType() && !rightType.canAssignTo(leftType)) {
if (bothIntrinsics(rightType, leftType)) {
// We have a superior warning for this mistake, which gives you
// the line numbers of both types.
registerMismatch(rightType, leftType);
} else {
mismatch(t, n,
"assignment to property " + propName + " of " +
getReadableJSTypeName(owner, true),
rightType, leftType);
}
return false;
}
return true;
}
示例3: registerMismatch
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的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());
}
}
示例4: expectCanAssignTo
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
/**
* Expect that the first type can be assigned to a symbol of the second
* type.
*
* @param t The node traversal.
* @param n The node to issue warnings on.
* @param rightType The type on the RHS of the assign.
* @param leftType The type of the symbol on the LHS of the assign.
* @param msg An extra message for the mismatch warning, if necessary.
* @return True if the types matched, false otherwise.
*/
boolean expectCanAssignTo(NodeTraversal t, Node n, JSType rightType,
JSType leftType, String msg) {
if (!rightType.canAssignTo(leftType)) {
if (bothIntrinsics(rightType, leftType)) {
// We have a superior warning for this mistake, which gives you
// the line numbers of both types.
registerMismatch(rightType, leftType);
} else {
mismatch(t, n, msg, rightType, leftType);
}
return false;
}
return true;
}
示例5: expectCanCast
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
/**
* Expect that the first type can be cast to the second type. The first type
* should be either a subtype or supertype of the second.
*
* @param t The node traversal.
* @param n The node where warnings should point.
* @param type The type being cast from.
* @param castType The type being cast to.
*/
void expectCanCast(NodeTraversal t, Node n, JSType type, JSType castType) {
castType = castType.restrictByNotNullOrUndefined();
type = type.restrictByNotNullOrUndefined();
if (!type.canAssignTo(castType) && !castType.canAssignTo(type)) {
compiler.report(
JSError.make(t, n, INVALID_CAST,
castType.toString(), type.toString()));
registerMismatch(type, castType);
}
}
示例6: registerIfMismatch
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
private void registerIfMismatch(JSType found, JSType required) {
if (found != null && required != null &&
!found.canAssignTo(required)) {
registerMismatch(found, required);
}
}
示例7: expectArgumentMatchesParameter
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
/**
* Expect that the type of an argument matches the type of the parameter
* that it's fulfilling.
*
* @param t The node traversal.
* @param n The node to issue warnings on.
* @param argType The type of the argument.
* @param paramType The type of the parameter.
* @param callNode The call node, to help with the warning message.
* @param ordinal The argument ordinal, to help with the warning message.
*/
void expectArgumentMatchesParameter(NodeTraversal t, Node n, JSType argType,
JSType paramType, Node callNode, int ordinal) {
if (!argType.canAssignTo(paramType)) {
mismatch(t, n,
String.format("actual parameter %d of %s does not match " +
"formal parameter", ordinal,
getReadableJSTypeName(callNode.getFirstChild(), false)),
argType, paramType);
}
}
示例8: expectCanOverride
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
/**
* Expect that the first type can override a property of the second
* type.
*
* @param t The node traversal.
* @param n The node to issue warnings on.
* @param overridingType The overriding type.
* @param hiddenType The type of the property being overridden.
* @param propertyName The name of the property, for use in the
* warning message.
* @param ownerType The type of the owner of the property, for use
* in the warning message.
*/
void expectCanOverride(NodeTraversal t, Node n, JSType overridingType,
JSType hiddenType, String propertyName, JSType ownerType) {
if (!overridingType.canAssignTo(hiddenType)) {
registerMismatch(overridingType, hiddenType);
compiler.report(
JSError.make(t, n, HIDDEN_PROPERTY_MISMATCH,
propertyName, ownerType.toString(),
hiddenType.toString(), overridingType.toString()));
}
}