本文整理汇总了Java中com.google.javascript.rhino.jstype.JSType.restrictByNotNullOrUndefined方法的典型用法代码示例。如果您正苦于以下问题:Java JSType.restrictByNotNullOrUndefined方法的具体用法?Java JSType.restrictByNotNullOrUndefined怎么用?Java JSType.restrictByNotNullOrUndefined使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.javascript.rhino.jstype.JSType
的用法示例。
在下文中一共展示了JSType.restrictByNotNullOrUndefined方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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());
}
}
示例2: 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;
}
示例3: addInvalidatingType
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
/**
* Invalidates the given type, so that no properties on it will be renamed.
*/
private void addInvalidatingType(JSType type) {
type = type.restrictByNotNullOrUndefined();
if (type instanceof UnionType) {
for (JSType alt : ((UnionType) type).getAlternates()) {
addInvalidatingType(alt);
}
return;
}
typeSystem.addInvalidatingType(type);
ObjectType objType = ObjectType.cast(type);
if (objType != null && objType.getImplicitPrototype() != null) {
typeSystem.addInvalidatingType(objType.getImplicitPrototype());
}
}
示例4: maybeAddAutoboxes
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
private ConcreteType maybeAddAutoboxes(
ConcreteType cType, JSType jsType, String prop) {
jsType = jsType.restrictByNotNullOrUndefined();
if (jsType instanceof UnionType) {
for (JSType alt : ((UnionType) jsType).getAlternates()) {
return maybeAddAutoboxes(cType, alt, prop);
}
}
if (jsType.autoboxesTo() != null) {
JSType autoboxed = jsType.autoboxesTo();
return cType.unionWith(tt.getConcreteInstance((ObjectType) autoboxed));
} else if (jsType.unboxesTo() != null) {
return cType.unionWith(tt.getConcreteInstance((ObjectType) jsType));
}
return cType;
}
示例5: isInvalidatingType
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
/** Returns true if properties on this type should not be renamed. */
private boolean isInvalidatingType(JSType type) {
if (type instanceof UnionType) {
type = type.restrictByNotNullOrUndefined();
if (type instanceof UnionType) {
for (JSType alt : ((UnionType) type).getAlternates()) {
if (isInvalidatingType(alt)) {
return true;
}
}
return false;
}
}
ObjectType objType = ObjectType.cast(type);
return objType == null
|| invalidatingTypes.contains(objType)
|| !objType.hasReferenceName()
|| (objType.isNamedType() && objType.isUnknownType())
|| objType.isEnumType() || objType.autoboxesTo() != null;
}
示例6: addType
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
/** Add this type to this property, calculating */
void addType(JSType newType) {
if (skipAmbiguating) {
return;
}
++numOccurrences;
if (newType instanceof UnionType) {
newType = newType.restrictByNotNullOrUndefined();
if (newType instanceof UnionType) {
for (JSType alt : ((UnionType) newType).getAlternates()) {
addNonUnionType(alt);
}
return;
}
}
addNonUnionType(newType);
}
示例7: testStubsInExterns2
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
public void testStubsInExterns2() {
testSame(
"/** @constructor */ function Extern() {}" +
"/** @type {Extern} */ var myExtern;" +
"/** @type {number} */ myExtern.foo;",
"", null);
JSType e = globalScope.getVar("myExtern").getType();
assertEquals("(Extern|null)", e.toString());
ObjectType externType = (ObjectType) e.restrictByNotNullOrUndefined();
assertTrue(globalScope.getRootNode().toStringTree(),
externType.hasOwnProperty("foo"));
assertTrue(externType.isPropertyTypeDeclared("foo"));
assertEquals("number", externType.getPropertyType("foo").toString());
assertTrue(externType.isPropertyInExterns("foo"));
}
示例8: testStubsInExterns3
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
public void testStubsInExterns3() {
testSame(
"/** @type {number} */ myExtern.foo;" +
"/** @type {Extern} */ var myExtern;" +
"/** @constructor */ function Extern() {}",
"", null);
JSType e = globalScope.getVar("myExtern").getType();
assertEquals("(Extern|null)", e.toString());
ObjectType externType = (ObjectType) e.restrictByNotNullOrUndefined();
assertTrue(globalScope.getRootNode().toStringTree(),
externType.hasOwnProperty("foo"));
assertTrue(externType.isPropertyTypeDeclared("foo"));
assertEquals("number", externType.getPropertyType("foo").toString());
assertTrue(externType.isPropertyInExterns("foo"));
}
示例9: acceptType
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
private void acceptType(JSType type) {
type = type.restrictByNotNullOrUndefined();
if (type.isRecordType()) {
acceptRecordType(toRecordType(type), null);
} else if (isAnonymousFunctionType(type)) {
acceptFunctionType(toFunctionType(type), null);
} else if (type.isTemplatizedType()) {
type.toMaybeTemplatizedType().getTemplateTypes().forEach(this::acceptType);
} else if (type.isUnionType()) {
type.toMaybeUnionType().getAlternates().forEach(this::acceptType);
}
}
示例10: getType
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
/**
* A helper to retrieve the type of a node.
*/
private JSType getType(Node n) {
JSType type = n.getJSType();
if (type == null) {
if (CONSERVATIVE) {
throw new RuntimeException("Type system failed us :(");
} else {
return compiler.getTypeRegistry().getNativeType(
JSTypeNative.UNKNOWN_TYPE);
}
}
// Null-ability does not affect the name graph's result.
return type.restrictByNotNullOrUndefined();
}
示例11: 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);
}
}
示例12: dereferencePointer
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
/**
* If we access a property of a symbol, then that symbol is not
* null or undefined.
*/
private FlowScope dereferencePointer(Node n, FlowScope scope) {
if (n.getType() == Token.NAME) {
JSType type = getJSType(n);
JSType narrowed = type.restrictByNotNullOrUndefined();
if (type != narrowed) {
scope = scope.createChildFlowScope();
redeclare(scope, n.getString(), narrowed);
}
}
return scope;
}
示例13: getTypesToSkipForType
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
@Override public ImmutableSet<JSType> getTypesToSkipForType(JSType type) {
type = type.restrictByNotNullOrUndefined();
if (type instanceof UnionType) {
Set<JSType> types = Sets.newHashSet(type);
for (JSType alt : ((UnionType) type).getAlternates()) {
types.addAll(getTypesToSkipForTypeNonUnion(type));
}
return ImmutableSet.copyOf(types);
}
return ImmutableSet.copyOf(getTypesToSkipForTypeNonUnion(type));
}
示例14: addInvalidatingType
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
/**
* Invalidates the given type, so that no properties on it will be renamed.
*/
private void addInvalidatingType(JSType type) {
type = type.restrictByNotNullOrUndefined();
if (type instanceof UnionType) {
for (JSType alt : ((UnionType) type).getAlternates()) {
addInvalidatingType(alt);
}
}
invalidatingTypes.add(type);
ObjectType objType = ObjectType.cast(type);
if (objType instanceof InstanceObjectType) {
invalidatingTypes.add(objType.getImplicitPrototype());
}
}
示例15: restrictByNotNullOrUndefined
import com.google.javascript.rhino.jstype.JSType; //导入方法依赖的package包/类
@Override public JSType restrictByNotNullOrUndefined(JSType type) {
return type.restrictByNotNullOrUndefined();
}