本文整理汇总了Java中com.google.javascript.rhino.jstype.JSTypeRegistry类的典型用法代码示例。如果您正苦于以下问题:Java JSTypeRegistry类的具体用法?Java JSTypeRegistry怎么用?Java JSTypeRegistry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JSTypeRegistry类属于com.google.javascript.rhino.jstype包,在下文中一共展示了JSTypeRegistry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: TypeCheck
import com.google.javascript.rhino.jstype.JSTypeRegistry; //导入依赖的package包/类
public TypeCheck(AbstractCompiler compiler,
ReverseAbstractInterpreter reverseInterpreter,
JSTypeRegistry typeRegistry,
Scope topScope,
ScopeCreator scopeCreator,
CheckLevel reportMissingOverride,
CheckLevel reportUnknownTypes) {
this.compiler = compiler;
this.validator = compiler.getTypeValidator();
this.reverseInterpreter = reverseInterpreter;
this.typeRegistry = typeRegistry;
this.topScope = topScope;
this.scopeCreator = scopeCreator;
this.reportMissingOverride = reportMissingOverride;
this.reportUnknownTypes = reportUnknownTypes;
this.inferJSDocInfo = new InferJSDocInfo(compiler);
}
示例2: fixFunctionType
import com.google.javascript.rhino.jstype.JSTypeRegistry; //导入依赖的package包/类
/**
* Creates a new JSType based on the original function type by
* adding the original this pointer type to the beginning of the
* argument type list and replacing the this pointer type with
* NO_TYPE.
*/
private void fixFunctionType(Node functionNode) {
FunctionType type = (FunctionType) functionNode.getJSType();
if (type != null) {
JSTypeRegistry typeRegistry = compiler.getTypeRegistry();
List<JSType> parameterTypes = Lists.newArrayList();
parameterTypes.add(type.getTypeOfThis());
for (Node param : type.getParameters()) {
parameterTypes.add(param.getJSType());
}
ObjectType thisType =
typeRegistry.getNativeObjectType(JSTypeNative.UNKNOWN_TYPE);
JSType returnType = type.getReturnType();
JSType newType = typeRegistry.createFunctionType(
thisType, returnType, parameterTypes);
functionNode.setJSType(newType);
}
}
示例3: AmbiguateProperties
import com.google.javascript.rhino.jstype.JSTypeRegistry; //导入依赖的package包/类
AmbiguateProperties(AbstractCompiler compiler,
char[] reservedCharacters) {
this.compiler = compiler;
this.reservedCharacters = reservedCharacters;
JSTypeRegistry r = compiler.getTypeRegistry();
invalidatingTypes = Sets.newHashSet(
r.getNativeType(JSTypeNative.ALL_TYPE),
r.getNativeType(JSTypeNative.NO_OBJECT_TYPE),
r.getNativeType(JSTypeNative.NO_TYPE),
r.getNativeType(JSTypeNative.NULL_TYPE),
r.getNativeType(JSTypeNative.VOID_TYPE),
r.getNativeType(JSTypeNative.FUNCTION_FUNCTION_TYPE),
r.getNativeType(JSTypeNative.FUNCTION_PROTOTYPE),
r.getNativeType(JSTypeNative.GLOBAL_THIS),
r.getNativeType(JSTypeNative.OBJECT_TYPE),
r.getNativeType(JSTypeNative.OBJECT_PROTOTYPE),
r.getNativeType(JSTypeNative.OBJECT_FUNCTION_TYPE),
r.getNativeType(JSTypeNative.TOP_LEVEL_PROTOTYPE),
r.getNativeType(JSTypeNative.UNKNOWN_TYPE));
for (TypeMismatch mis : compiler.getTypeValidator().getMismatches()) {
addInvalidatingType(mis.typeA);
addInvalidatingType(mis.typeB);
}
}
示例4: testFunctionMismatch
import com.google.javascript.rhino.jstype.JSTypeRegistry; //导入依赖的package包/类
public void testFunctionMismatch() throws Exception {
testSame(
"/** \n" +
" * @param {function(string): number} x \n" +
" * @return {function(boolean): string} \n" +
" */ function f(x) { return x; }",
TYPE_MISMATCH_WARNING);
JSTypeRegistry registry = compiler.getTypeRegistry();
JSType string = registry.getNativeType(STRING_TYPE);
JSType bool = registry.getNativeType(BOOLEAN_TYPE);
JSType number = registry.getNativeType(NUMBER_TYPE);
JSType firstFunction = registry.createFunctionType(number, string);
JSType secondFunction = registry.createFunctionType(string, bool);
assertMismatches(
Lists.newArrayList(
new TypeMismatch(firstFunction, secondFunction),
fromNatives(STRING_TYPE, BOOLEAN_TYPE),
fromNatives(NUMBER_TYPE, STRING_TYPE)));
}
示例5: testFunctionMismatch2
import com.google.javascript.rhino.jstype.JSTypeRegistry; //导入依赖的package包/类
public void testFunctionMismatch2() throws Exception {
testSame(
"/** \n" +
" * @param {function(string): number} x \n" +
" * @return {function(boolean): number} \n" +
" */ function f(x) { return x; }",
TYPE_MISMATCH_WARNING);
JSTypeRegistry registry = compiler.getTypeRegistry();
JSType string = registry.getNativeType(STRING_TYPE);
JSType bool = registry.getNativeType(BOOLEAN_TYPE);
JSType number = registry.getNativeType(NUMBER_TYPE);
JSType firstFunction = registry.createFunctionType(number, string);
JSType secondFunction = registry.createFunctionType(number, bool);
assertMismatches(
Lists.newArrayList(
new TypeMismatch(firstFunction, secondFunction),
fromNatives(STRING_TYPE, BOOLEAN_TYPE)));
}
示例6: buildInvalidatingTypeSet
import com.google.javascript.rhino.jstype.JSTypeRegistry; //导入依赖的package包/类
private void buildInvalidatingTypeSet() {
JSTypeRegistry registry = compiler.getTypeRegistry();
invalidatingTypes = Sets.newHashSet(
registry.getNativeType(JSTypeNative.ALL_TYPE),
registry.getNativeType(JSTypeNative.NO_OBJECT_TYPE),
registry.getNativeType(JSTypeNative.NO_TYPE),
registry.getNativeType(JSTypeNative.NULL_TYPE),
registry.getNativeType(JSTypeNative.VOID_TYPE),
registry.getNativeType(JSTypeNative.FUNCTION_FUNCTION_TYPE),
registry.getNativeType(JSTypeNative.FUNCTION_INSTANCE_TYPE),
registry.getNativeType(JSTypeNative.FUNCTION_PROTOTYPE),
registry.getNativeType(JSTypeNative.GLOBAL_THIS),
registry.getNativeType(JSTypeNative.OBJECT_TYPE),
registry.getNativeType(JSTypeNative.OBJECT_PROTOTYPE),
registry.getNativeType(JSTypeNative.OBJECT_FUNCTION_TYPE),
registry.getNativeType(JSTypeNative.TOP_LEVEL_PROTOTYPE),
registry.getNativeType(JSTypeNative.UNKNOWN_TYPE));
for (TypeMismatch mis : compiler.getTypeValidator().getMismatches()) {
addInvalidatingType(mis.typeA);
addInvalidatingType(mis.typeB);
}
}
示例7: TypeCheck
import com.google.javascript.rhino.jstype.JSTypeRegistry; //导入依赖的package包/类
public TypeCheck(AbstractCompiler compiler,
ReverseAbstractInterpreter reverseInterpreter,
JSTypeRegistry typeRegistry,
Scope topScope,
MemoizedScopeCreator scopeCreator,
CheckLevel reportMissingOverride,
CheckLevel reportUnknownTypes) {
this.compiler = compiler;
this.validator = compiler.getTypeValidator();
this.reverseInterpreter = reverseInterpreter;
this.typeRegistry = typeRegistry;
this.topScope = topScope;
this.scopeCreator = scopeCreator;
this.reportMissingOverride = reportMissingOverride;
this.reportUnknownTypes = reportUnknownTypes;
this.inferJSDocInfo = new InferJSDocInfo(compiler);
}
示例8: fixFunctionType
import com.google.javascript.rhino.jstype.JSTypeRegistry; //导入依赖的package包/类
/**
* Creates a new JSType based on the original function type by
* adding the original this pointer type to the beginning of the
* argument type list and replacing the this pointer type with
* NO_TYPE.
*/
private void fixFunctionType(Node functionNode) {
FunctionType type = JSType.toMaybeFunctionType(functionNode.getJSType());
if (type != null) {
JSTypeRegistry typeRegistry = compiler.getTypeRegistry();
List<JSType> parameterTypes = Lists.newArrayList();
parameterTypes.add(type.getTypeOfThis());
for (Node param : type.getParameters()) {
parameterTypes.add(param.getJSType());
}
ObjectType thisType =
typeRegistry.getNativeObjectType(JSTypeNative.UNKNOWN_TYPE);
JSType returnType = type.getReturnType();
JSType newType = typeRegistry.createFunctionType(
thisType, returnType, parameterTypes);
functionNode.setJSType(newType);
}
}
示例9: getAssertedType
import com.google.javascript.rhino.jstype.JSTypeRegistry; //导入依赖的package包/类
/**
* Returns the type for a type assertion, or null if the function asserts
* that the node must not be null or undefined.
*/
@Override
public JSType getAssertedType(Node call, JSTypeRegistry registry) {
if (call.getChildCount() > 2) {
Node constructor = call.getFirstChild().getNext().getNext();
if (constructor != null) {
JSType ownerType = constructor.getJSType();
if (ownerType != null
&& ownerType.isFunctionType()
&& ownerType.isConstructor()) {
FunctionType functionType = ((FunctionType) ownerType);
return functionType.getInstanceType();
}
}
}
return super.getAssertedType(call, registry);
}
示例10: testApplySubclassRelationship
import com.google.javascript.rhino.jstype.JSTypeRegistry; //导入依赖的package包/类
public void testApplySubclassRelationship() {
JSTypeRegistry registry = new JSTypeRegistry(null);
Node nodeA = new Node(Token.FUNCTION);
FunctionType ctorA = registry.createConstructorType("A", nodeA,
new Node(Token.PARAM_LIST), null, null);
Node nodeB = new Node(Token.FUNCTION);
FunctionType ctorB = registry.createConstructorType("B", nodeB,
new Node(Token.PARAM_LIST), null, null);
conv.applySubclassRelationship(ctorA, ctorB, SubclassType.INHERITS);
assertTrue(ctorB.getPrototype().hasOwnProperty("constructor"));
assertEquals(nodeB, ctorB.getPrototype().getPropertyNode("constructor"));
assertTrue(ctorB.hasOwnProperty("superClass_"));
assertEquals(nodeB, ctorB.getPropertyNode("superClass_"));
}
示例11: testFunctionMismatch
import com.google.javascript.rhino.jstype.JSTypeRegistry; //导入依赖的package包/类
public void testFunctionMismatch() throws Exception {
testSame(
"/** \n" +
" * @param {function(string): number} x \n" +
" * @return {function(boolean): string} \n" +
" */ function f(x) { return x; }",
TYPE_MISMATCH_WARNING);
JSTypeRegistry registry = compiler.getTypeRegistry();
JSType string = registry.getNativeType(STRING_TYPE);
JSType bool = registry.getNativeType(BOOLEAN_TYPE);
JSType number = registry.getNativeType(NUMBER_TYPE);
JSType firstFunction = registry.createFunctionType(number, string);
JSType secondFunction = registry.createFunctionType(string, bool);
assertMismatches(
Lists.newArrayList(
new TypeMismatch(firstFunction, secondFunction, null),
fromNatives(STRING_TYPE, BOOLEAN_TYPE),
fromNatives(NUMBER_TYPE, STRING_TYPE)));
}
示例12: testFunctionMismatch2
import com.google.javascript.rhino.jstype.JSTypeRegistry; //导入依赖的package包/类
public void testFunctionMismatch2() throws Exception {
testSame(
"/** \n" +
" * @param {function(string): number} x \n" +
" * @return {function(boolean): number} \n" +
" */ function f(x) { return x; }",
TYPE_MISMATCH_WARNING);
JSTypeRegistry registry = compiler.getTypeRegistry();
JSType string = registry.getNativeType(STRING_TYPE);
JSType bool = registry.getNativeType(BOOLEAN_TYPE);
JSType number = registry.getNativeType(NUMBER_TYPE);
JSType firstFunction = registry.createFunctionType(number, string);
JSType secondFunction = registry.createFunctionType(number, bool);
assertMismatches(
Lists.newArrayList(
new TypeMismatch(firstFunction, secondFunction, null),
fromNatives(STRING_TYPE, BOOLEAN_TYPE)));
}
示例13: TypeCheck
import com.google.javascript.rhino.jstype.JSTypeRegistry; //导入依赖的package包/类
public TypeCheck(
AbstractCompiler compiler,
ReverseAbstractInterpreter reverseInterpreter,
JSTypeRegistry typeRegistry,
TypedScope topScope,
MemoizedTypedScopeCreator scopeCreator) {
this.compiler = compiler;
this.validator = compiler.getTypeValidator();
this.reverseInterpreter = reverseInterpreter;
this.typeRegistry = typeRegistry;
this.topScope = topScope;
this.scopeCreator = scopeCreator;
this.reportUnknownTypes = ((Compiler) compiler).getOptions().enables(
DiagnosticGroups.REPORT_UNKNOWN_TYPES);
this.inferJSDocInfo = new InferJSDocInfo(compiler);
}
示例14: getAssertedOldType
import com.google.javascript.rhino.jstype.JSTypeRegistry; //导入依赖的package包/类
/**
* Returns the type for a type assertion, or null if the function asserts
* that the node must not be null or undefined.
*/
@Override
public com.google.javascript.rhino.jstype.JSType
getAssertedOldType(Node call, JSTypeRegistry registry) {
if (call.getChildCount() > 2) {
Node constructor = call.getSecondChild().getNext();
if (constructor != null) {
com.google.javascript.rhino.jstype.JSType ownerType =
constructor.getJSType();
if (ownerType != null
&& ownerType.isFunctionType()
&& ownerType.isConstructor()) {
FunctionType functionType = ((FunctionType) ownerType);
return functionType.getInstanceType();
}
}
}
return registry.getNativeType(JSTypeNative.UNKNOWN_TYPE);
}
示例15: testApplySubclassRelationship
import com.google.javascript.rhino.jstype.JSTypeRegistry; //导入依赖的package包/类
public void testApplySubclassRelationship() {
JSTypeRegistry registry = new JSTypeRegistry(null);
Node nodeA = new Node(Token.FUNCTION);
FunctionType ctorA =
registry.createConstructorType("A", nodeA, new Node(Token.PARAM_LIST), null, null, false);
Node nodeB = new Node(Token.FUNCTION);
FunctionType ctorB =
registry.createConstructorType("B", nodeB, new Node(Token.PARAM_LIST), null, null, false);
conv.applySubclassRelationship(
new NominalTypeBuilderOti(ctorA, ctorA.getInstanceType()),
new NominalTypeBuilderOti(ctorB, ctorB.getInstanceType()),
SubclassType.INHERITS);
assertTrue(ctorB.getPrototype().hasOwnProperty("constructor"));
assertEquals(nodeB, ctorB.getPrototype().getPropertyNode("constructor"));
assertTrue(ctorB.hasOwnProperty("superClass_"));
assertEquals(nodeB, ctorB.getPropertyNode("superClass_"));
}