本文整理汇总了Java中com.google.javascript.rhino.jstype.FunctionBuilder类的典型用法代码示例。如果您正苦于以下问题:Java FunctionBuilder类的具体用法?Java FunctionBuilder怎么用?Java FunctionBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FunctionBuilder类属于com.google.javascript.rhino.jstype包,在下文中一共展示了FunctionBuilder类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: traverseSuper
import com.google.javascript.rhino.jstype.FunctionBuilder; //导入依赖的package包/类
private void traverseSuper(Node superNode) {
// We only need to handle cases of super() constructor calls for now.
// All super.method() uses are transpiled away before this pass.
JSType jsType = functionScope.getRootNode().getJSType();
FunctionType constructorType = (jsType == null) ? null : jsType.toMaybeFunctionType();
FunctionType superConstructorType =
(constructorType == null) ? null : constructorType.getSuperClassConstructor();
if (superConstructorType != null) {
// Treat super() like a function with the same signature as the
// superclass constructor, but don't require 'new' or 'this'.
superNode.setJSType(
new FunctionBuilder(registry)
.copyFromOtherFunction(superConstructorType)
// Invocations of super() don't use new
.setIsConstructor(false)
// Even if the super class is abstract, we still need to call its constructor.
.withIsAbstract(false) //
.withTypeOfThis(null)
.build());
} else {
superNode.setJSType(unknownType);
}
}
开发者ID:google,项目名称:closure-compiler,代码行数:24,代码来源:TypeInference.java
示例2: matchFunction
import com.google.javascript.rhino.jstype.FunctionBuilder; //导入依赖的package包/类
/**
* Take the current function type, and try to match the expected function
* type. This is a form of backwards-inference, like record-type constraint
* matching.
*/
private FunctionType matchFunction(
FunctionType expectedType, FunctionType currentType, boolean declared) {
if (declared) {
// If the function was declared but it doesn't have a known "this"
// but the expected type does, back fill it.
if (currentType.getTypeOfThis().isUnknownType()
&& !expectedType.getTypeOfThis().isUnknownType()) {
FunctionType replacement = new FunctionBuilder(registry)
.copyFromOtherFunction(currentType)
.withTypeOfThis(expectedType.getTypeOfThis())
.build();
return replacement;
}
} else {
// For now, we just make sure the current type has enough
// arguments to match the expected type, and return the
// expected type if it does.
if (currentType.getMaxArity() <= expectedType.getMaxArity()) {
return expectedType;
}
}
return currentType;
}
开发者ID:google,项目名称:closure-compiler,代码行数:29,代码来源:TypeInference.java
示例3: matchFunction
import com.google.javascript.rhino.jstype.FunctionBuilder; //导入依赖的package包/类
/**
* Take the current function type, and try to match the expected function
* type. This is a form of backwards-inference, like record-type constraint
* matching.
*/
private FunctionType matchFunction(
FunctionType expectedType, FunctionType currentType, boolean declared) {
if (declared) {
// If the function was declared but it doesn't have a known "this"
// but the expected type does, back fill it.
if (currentType.getTypeOfThis().isUnknownType()
&& !expectedType.getTypeOfThis().isUnknownType()) {
FunctionType replacement = new FunctionBuilder(registry)
.copyFromOtherFunction(currentType)
.withTypeOfThis(expectedType.getTypeOfThis())
.build();
return replacement;
}
} else {
// For now, we just make sure the current type has enough
// arguments to match the expected type, and return the
// expected type if it does.
if (currentType.getMaxArguments() <= expectedType.getMaxArguments()) {
return expectedType;
}
}
return currentType;
}
开发者ID:nicks,项目名称:closure-compiler-old,代码行数:29,代码来源:TypeInference.java
示例4: buildAndRegister
import com.google.javascript.rhino.jstype.FunctionBuilder; //导入依赖的package包/类
/**
* Builds the function type, and puts it in the registry.
*/
FunctionType buildAndRegister() {
if (returnType == null) {
returnType = typeRegistry.getNativeType(UNKNOWN_TYPE);
}
if (parametersNode == null) {
throw new IllegalStateException(
"All Function types must have params and a return type");
}
FunctionType fnType;
if (isConstructor) {
fnType = getOrCreateConstructor();
} else if (isInterface) {
fnType = typeRegistry.createInterfaceType(fnName, sourceNode);
if (scope.isGlobal() && !fnName.isEmpty()) {
typeRegistry.declareType(fnName, fnType.getInstanceType());
}
maybeSetBaseType(fnType);
} else {
fnType = new FunctionBuilder(typeRegistry)
.withName(fnName)
.withSourceNode(sourceNode)
.withParamsNode(parametersNode)
.withReturnType(returnType, returnTypeInferred)
.withTypeOfThis(thisType)
.withTemplateName(templateTypeName)
.build();
maybeSetBaseType(fnType);
}
if (implementedInterfaces != null) {
fnType.setImplementedInterfaces(implementedInterfaces);
}
typeRegistry.clearTemplateTypeName();
return fnType;
}
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:43,代码来源:FunctionTypeBuilder.java
示例5: addMethod
import com.google.javascript.rhino.jstype.FunctionBuilder; //导入依赖的package包/类
private static void addMethod(
JSTypeRegistry registry, ObjectType receivingType, String methodName,
JSType returnType) {
receivingType.defineDeclaredProperty(methodName,
new FunctionBuilder(registry).withReturnType(returnType).build(),
null);
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:8,代码来源:BaseJSTypeTestCase.java
示例6: updateBind
import com.google.javascript.rhino.jstype.FunctionBuilder; //导入依赖的package包/类
/**
* When "bind" is called on a function, we infer the type of the returned
* "bound" function by looking at the number of parameters in the call site.
* We also infer the "this" type of the target, if it's a function expression.
*/
private void updateBind(Node n) {
CodingConvention.Bind bind =
compiler.getCodingConvention().describeFunctionBind(n, false, true);
if (bind == null) {
return;
}
Node target = bind.target;
FunctionType callTargetFn = getJSType(target)
.restrictByNotNullOrUndefined().toMaybeFunctionType();
if (callTargetFn == null) {
return;
}
if (bind.thisValue != null && target.isFunction()) {
JSType thisType = getJSType(bind.thisValue);
if (thisType.toObjectType() != null && !thisType.isUnknownType()
&& callTargetFn.getTypeOfThis().isUnknownType()) {
callTargetFn = new FunctionBuilder(registry)
.copyFromOtherFunction(callTargetFn)
.withTypeOfThis(thisType.toObjectType())
.build();
target.setJSType(callTargetFn);
}
}
n.setJSType(
callTargetFn.getBindReturnType(
// getBindReturnType expects the 'this' argument to be included.
bind.getBoundParameterCount() + 1));
}
开发者ID:google,项目名称:closure-compiler,代码行数:37,代码来源:TypeInference.java
示例7: addMethod
import com.google.javascript.rhino.jstype.FunctionBuilder; //导入依赖的package包/类
private static void addMethod(
JSTypeRegistry registry, ObjectType receivingType, String methodName,
JSType returnType) {
receivingType.defineDeclaredProperty(methodName,
new FunctionBuilder(registry).withReturnType(returnType).build(), true);
}
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:7,代码来源:BaseJSTypeTestCase.java
示例8: buildAndRegister
import com.google.javascript.rhino.jstype.FunctionBuilder; //导入依赖的package包/类
/**
* Builds the function type, and puts it in the registry.
*/
FunctionType buildAndRegister() {
if (returnType == null) {
// Infer return types.
// We need to be extremely conservative about this, because of two
// competing needs.
// 1) If we infer the return type of f too widely, then we won't be able
// to assign f to other functions.
// 2) If we infer the return type of f too narrowly, then we won't be
// able to override f in subclasses.
// So we only infer in cases where the user doesn't expect to write
// @return annotations--when it's very obvious that the function returns
// nothing.
if (!contents.mayHaveNonEmptyReturns() &&
!contents.mayHaveSingleThrow() &&
!contents.mayBeFromExterns()) {
returnType = typeRegistry.getNativeType(VOID_TYPE);
returnTypeInferred = true;
}
}
if (returnType == null) {
returnType = typeRegistry.getNativeType(UNKNOWN_TYPE);
}
if (parametersNode == null) {
throw new IllegalStateException(
"All Function types must have params and a return type");
}
FunctionType fnType;
if (isConstructor) {
fnType = getOrCreateConstructor();
} else if (isInterface) {
fnType = typeRegistry.createInterfaceType(
fnName, contents.getSourceNode());
if (getScopeDeclaredIn().isGlobal() && !fnName.isEmpty()) {
typeRegistry.declareType(fnName, fnType.getInstanceType());
}
maybeSetBaseType(fnType);
} else {
fnType = new FunctionBuilder(typeRegistry)
.withName(fnName)
.withSourceNode(contents.getSourceNode())
.withParamsNode(parametersNode)
.withReturnType(returnType, returnTypeInferred)
.withTypeOfThis(thisType)
.withTemplateKeys(templateTypeNames)
.build();
maybeSetBaseType(fnType);
}
if (implementedInterfaces != null) {
fnType.setImplementedInterfaces(implementedInterfaces);
}
if (extendedInterfaces != null) {
fnType.setExtendedInterfaces(extendedInterfaces);
}
typeRegistry.clearTemplateTypeNames();
return fnType;
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:67,代码来源:FunctionTypeBuilder.java
示例9: buildAndRegister
import com.google.javascript.rhino.jstype.FunctionBuilder; //导入依赖的package包/类
/**
* Builds the function type, and puts it in the registry.
*/
FunctionType buildAndRegister() {
if (returnType == null) {
// Infer return types.
// We need to be extremely conservative about this, because of two
// competing needs.
// 1) If we infer the return type of f too widely, then we won't be able
// to assign f to other functions.
// 2) If we infer the return type of f too narrowly, then we won't be
// able to override f in subclasses.
// So we only infer in cases where the user doesn't expect to write
// @return annotations--when it's very obvious that the function returns
// nothing.
if (!contents.mayHaveNonEmptyReturns() &&
!contents.mayHaveSingleThrow() &&
!contents.mayBeFromExterns()) {
returnType = typeRegistry.getNativeType(VOID_TYPE);
returnTypeInferred = true;
}
}
if (returnType == null) {
returnType = typeRegistry.getNativeType(UNKNOWN_TYPE);
}
if (parametersNode == null) {
throw new IllegalStateException(
"All Function types must have params and a return type");
}
FunctionType fnType;
if (isConstructor) {
fnType = getOrCreateConstructor();
} else if (isInterface) {
fnType = typeRegistry.createInterfaceType(
fnName, contents.getSourceNode(), classTemplateTypeNames, makesStructs);
if (getScopeDeclaredIn().isGlobal() && !fnName.isEmpty()) {
typeRegistry.declareType(fnName, fnType.getInstanceType());
}
maybeSetBaseType(fnType);
} else {
fnType =
new FunctionBuilder(typeRegistry)
.withName(fnName)
.withSourceNode(contents.getSourceNode())
.withParamsNode(parametersNode)
.withReturnType(returnType, returnTypeInferred)
.withTypeOfThis(thisType)
.withTemplateKeys(templateTypeNames)
.withIsAbstract(isAbstract)
.build();
maybeSetBaseType(fnType);
}
if (implementedInterfaces != null && fnType.isConstructor()) {
fnType.setImplementedInterfaces(implementedInterfaces);
}
if (extendedInterfaces != null) {
fnType.setExtendedInterfaces(extendedInterfaces);
}
typeRegistry.clearTemplateTypeNames();
return fnType;
}
开发者ID:google,项目名称:closure-compiler,代码行数:69,代码来源:FunctionTypeBuilder.java
示例10: buildAndRegister
import com.google.javascript.rhino.jstype.FunctionBuilder; //导入依赖的package包/类
/**
* Builds the function type, and puts it in the registry.
*/
FunctionType buildAndRegister() {
if (returnType == null) {
// Infer return types.
// We need to be extremely conservative about this, because of two
// competing needs.
// 1) If we infer the return type of f too widely, then we won't be able
// to assign f to other functions.
// 2) If we infer the return type of f too narrowly, then we won't be
// able to override f in subclasses.
// So we only infer in cases where the user doesn't expect to write
// @return annotations--when it's very obvious that the function returns
// nothing.
if (!contents.mayHaveNonEmptyReturns() &&
!contents.mayHaveSingleThrow() &&
!contents.mayBeFromExterns()) {
returnType = typeRegistry.getNativeType(VOID_TYPE);
returnTypeInferred = true;
}
}
if (returnType == null) {
returnType = typeRegistry.getNativeType(UNKNOWN_TYPE);
}
if (parametersNode == null) {
throw new IllegalStateException(
"All Function types must have params and a return type");
}
FunctionType fnType;
if (isConstructor) {
fnType = getOrCreateConstructor();
} else if (isInterface) {
fnType = typeRegistry.createInterfaceType(
fnName, contents.getSourceNode(), classTemplateTypeNames);
if (getScopeDeclaredIn().isGlobal() && !fnName.isEmpty()) {
typeRegistry.declareType(fnName, fnType.getInstanceType());
}
maybeSetBaseType(fnType);
} else {
fnType = new FunctionBuilder(typeRegistry)
.withName(fnName)
.withSourceNode(contents.getSourceNode())
.withParamsNode(parametersNode)
.withReturnType(returnType, returnTypeInferred)
.withTypeOfThis(thisType)
.withTemplateKeys(templateTypeNames)
.build();
maybeSetBaseType(fnType);
}
if (implementedInterfaces != null) {
fnType.setImplementedInterfaces(implementedInterfaces);
}
if (extendedInterfaces != null) {
fnType.setExtendedInterfaces(extendedInterfaces);
}
typeRegistry.clearTemplateTypeNames();
return fnType;
}
开发者ID:nicks,项目名称:closure-compiler-old,代码行数:67,代码来源:FunctionTypeBuilder.java
注:本文中的com.google.javascript.rhino.jstype.FunctionBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论