本文整理汇总了Java中com.google.javascript.rhino.JSDocInfo.hasType方法的典型用法代码示例。如果您正苦于以下问题:Java JSDocInfo.hasType方法的具体用法?Java JSDocInfo.hasType怎么用?Java JSDocInfo.hasType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.javascript.rhino.JSDocInfo
的用法示例。
在下文中一共展示了JSDocInfo.hasType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ensureTyped
import com.google.javascript.rhino.JSDocInfo; //导入方法依赖的package包/类
/**
* Enforces type casts, and ensures the node is typed.
*
* A cast in the way that we use it in JSDoc annotations never
* alters the generated code and therefore never can induce any runtime
* operation. What this means is that a 'cast' is really just a compile
* time constraint on the underlying value. In the future, we may add
* support for run-time casts for compiled tests.
*
* To ensure some shred of sanity, we enforce the notion that the
* type you are casting to may only meaningfully be a narrower type
* than the underlying declared type. We also invalidate optimizations
* on bad type casts.
*
* @param t The traversal object needed to report errors.
* @param n The node getting a type assigned to it.
* @param type The type to be assigned.
*/
private void ensureTyped(NodeTraversal t, Node n, JSType type) {
// Make sure FUNCTION nodes always get function type.
Preconditions.checkState(n.getType() != Token.FUNCTION ||
type instanceof FunctionType ||
type.isUnknownType());
JSDocInfo info = n.getJSDocInfo();
if (info != null) {
if (info.hasType()) {
JSType infoType = info.getType().evaluate(t.getScope());
validator.expectCanCast(t, n, infoType, type);
type = infoType;
}
if (info.isImplicitCast() && !inExterns) {
String propName = n.getType() == Token.GETPROP ?
n.getLastChild().getString() : "(missing)";
compiler.report(
JSError.make(t, n, ILLEGAL_IMPLICIT_CAST, propName));
}
}
if (n.getJSType() == null) {
n.setJSType(type);
}
}
示例2: getDeclaredGetPropType
import com.google.javascript.rhino.JSDocInfo; //导入方法依赖的package包/类
/**
* Look for a type declaration on a GETPROP node.
*
* @param info The doc info for this property.
* @param n A top-level GETPROP node (it should not be contained inside
* another GETPROP).
* @param rhsValue The node that {@code n} is being initialized to,
* or {@code null} if this is a stub declaration.
*/
private JSType getDeclaredGetPropType(NodeTraversal t, JSDocInfo info,
Node n, Node rhsValue) {
if (info != null && info.hasType()) {
return getDeclaredTypeInAnnotation(t, n, info);
} else if (info != null && info.hasEnumParameterType()) {
return n.getJSType();
} else if (rhsValue != null &&
rhsValue.getType() == Token.FUNCTION) {
return rhsValue.getJSType();
} else {
return getDeclaredTypeInAnnotation(t, n, info);
}
}
示例3: inferThisType
import com.google.javascript.rhino.JSDocInfo; //导入方法依赖的package包/类
/**
* Infers the type of {@code this}.
* @param type The type of this.
*/
FunctionTypeBuilder inferThisType(JSDocInfo info, JSType type) {
ObjectType objType = ObjectType.cast(type);
if (objType != null && (info == null || !info.hasType())) {
thisType = objType;
}
return this;
}
示例4: getDeclaredTypeInAnnotation
import com.google.javascript.rhino.JSDocInfo; //导入方法依赖的package包/类
JSType getDeclaredTypeInAnnotation(String sourceName,
Node node, JSDocInfo info) {
JSType jsType = null;
Node objNode = node.getType() == Token.GETPROP ?
node.getFirstChild() : null;
if (info != null) {
if (info.hasType()) {
jsType = info.getType().evaluate(scope);
} else if (FunctionTypeBuilder.isFunctionTypeDeclaration(info)) {
String fnName = node.getQualifiedName();
// constructors are often handled separately.
if (info.isConstructor() && typeRegistry.getType(fnName) != null) {
return null;
}
FunctionTypeBuilder builder =
new FunctionTypeBuilder(
fnName, compiler, node, sourceName, scope)
.inferTemplateTypeName(info)
.inferReturnType(info)
.inferParameterTypes(info)
.inferInheritance(info);
// Infer the context type.
boolean searchedForThisType = false;
if (objNode != null) {
if (objNode.getType() == Token.GETPROP &&
objNode.getLastChild().getString().equals("prototype")) {
builder.inferThisType(info, objNode.getFirstChild());
searchedForThisType = true;
} else if (objNode.getType() == Token.THIS) {
builder.inferThisType(info, objNode.getJSType());
searchedForThisType = true;
}
}
if (!searchedForThisType) {
builder.inferThisType(info, (Node) null);
}
jsType = builder.buildAndRegister();
}
}
return jsType;
}