本文整理汇总了Java中com.google.javascript.rhino.jstype.ObjectType.cast方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectType.cast方法的具体用法?Java ObjectType.cast怎么用?Java ObjectType.cast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.javascript.rhino.jstype.ObjectType
的用法示例。
在下文中一共展示了ObjectType.cast方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createTypeWithSubTypes
import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的package包/类
/**
* Returns a concrete type from the given JSType that includes the concrete
* types for subtypes and implementing types for any interfaces.
*/
private ConcreteType createTypeWithSubTypes(JSType jsType) {
ConcreteType ret = ConcreteType.NONE;
if (jsType instanceof UnionType) {
for (JSType alt : ((UnionType) jsType).getAlternates()) {
ret = ret.unionWith(createTypeWithSubTypes(alt));
}
} else {
ObjectType instType = ObjectType.cast(jsType);
if (instType != null &&
instType.getConstructor() != null &&
instType.getConstructor().isInterface()) {
Collection<FunctionType> implementors =
getTypeRegistry().getDirectImplementors(instType);
for (FunctionType implementor : implementors) {
ret = ret.unionWith(createTypeWithSubTypes(
implementor.getInstanceType()));
}
} else {
ret = ret.unionWith(createUnionWithSubTypes(createType(jsType)));
}
}
return ret;
}
示例2: getTypeDeprecationInfo
import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的package包/类
/**
* Returns the deprecation reason for the type if it is marked
* as being deprecated. Returns empty string if the type is deprecated
* but no reason was given. Returns null if the type is not deprecated.
*/
private static String getTypeDeprecationInfo(JSType type) {
if (type == null) {
return null;
}
JSDocInfo info = type.getJSDocInfo();
if (info != null && info.isDeprecated()) {
if (info.getDeprecationReason() != null) {
return info.getDeprecationReason();
}
return "";
}
ObjectType objType = ObjectType.cast(type);
if (objType != null) {
ObjectType implicitProto = objType.getImplicitPrototype();
if (implicitProto != null) {
return getTypeDeprecationInfo(implicitProto);
}
}
return null;
}
示例3: addInvalidatingType
import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的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: isInvalidatingType
import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的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;
}
示例5: caseIn
import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的package包/类
/**
* Given 'property in object', ensures that the object has the property in the
* informed scope by defining it as a qualified name if the object type lacks
* the property and it's not in the blind scope.
* @param object The node of the right-side of the in.
* @param propertyName The string of the left-side of the in.
*/
private FlowScope caseIn(Node object, String propertyName, FlowScope blindScope) {
JSType jsType = object.getJSType();
jsType = this.getRestrictedWithoutNull(jsType);
jsType = this.getRestrictedWithoutUndefined(jsType);
boolean hasProperty = false;
ObjectType objectType = ObjectType.cast(jsType);
if (objectType != null) {
hasProperty = objectType.hasProperty(propertyName);
}
if (!hasProperty) {
String qualifiedName = object.getQualifiedName();
if (qualifiedName != null) {
String propertyQualifiedName = qualifiedName + "." + propertyName;
if (blindScope.getSlot(propertyQualifiedName) == null) {
FlowScope informed = blindScope.createChildFlowScope();
JSType unknownType = typeRegistry.getNativeType(
JSTypeNative.UNKNOWN_TYPE);
informed.inferQualifiedSlot(
propertyQualifiedName, unknownType, unknownType);
return informed;
}
}
}
return blindScope;
}
示例6: visitFunction
import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的package包/类
/**
* Visits a {@link Token#FUNCTION} node.
*
* @param t The node traversal object that supplies context, such as the
* scope chain to use in name lookups as well as error reporting.
* @param n The node being visited.
*/
private void visitFunction(NodeTraversal t, Node n) {
JSDocInfo info = n.getJSDocInfo();
FunctionType functionType = (FunctionType) n.getJSType();
String functionPrivateName = n.getFirstChild().getString();
if (functionType.isInterface() || functionType.isConstructor()) {
FunctionType baseConstructor = functionType.
getPrototype().getImplicitPrototype().getConstructor();
if (baseConstructor != null &&
baseConstructor != getNativeType(OBJECT_FUNCTION_TYPE) &&
(baseConstructor.isConstructor() && functionType.isInterface() ||
baseConstructor.isInterface() && functionType.isConstructor())) {
compiler.report(
JSError.make(t, n, CONFLICTING_EXTENDED_TYPE, functionPrivateName));
}
for (JSType baseInterface : functionType.getImplementedInterfaces()) {
boolean badImplementedType = false;
ObjectType baseInterfaceObj = ObjectType.cast(baseInterface);
if (baseInterfaceObj != null) {
FunctionType interfaceConstructor =
baseInterfaceObj.getConstructor();
if (interfaceConstructor != null &&
!interfaceConstructor.isInterface()) {
badImplementedType = true;
}
} else {
badImplementedType = true;
}
if (badImplementedType) {
t.report(n, BAD_IMPLEMENTED_TYPE, functionPrivateName);
}
}
if (functionType.isConstructor()) {
validator.expectAllInterfacePropertiesImplemented(functionType);
}
}
}
示例7: getObjectSlot
import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的package包/类
/**
* Find the ObjectType associated with the given slot.
* @param slotName The name of the slot to find the type in.
* @return An object type, or null if this slot does not contain an object.
*/
private ObjectType getObjectSlot(String slotName) {
Var ownerVar = scope.getVar(slotName);
if (ownerVar != null) {
JSType ownerVarType = ownerVar.getType();
return ObjectType.cast(ownerVarType == null ?
null : ownerVarType.restrictByNotNullOrUndefined());
}
return null;
}
示例8: getImplicitActionsFromProp
import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的package包/类
private Collection<Action> getImplicitActionsFromProp(
JSType jsType, String prop, Node fnNode) {
List<Action> actions = Lists.newArrayList();
if (jsType instanceof UnionType) {
boolean found = false;
for (JSType alt : ((UnionType) jsType).getAlternates()) {
ObjectType altObj = ObjectType.cast(alt);
if (altObj != null) {
actions.addAll(getImplicitActionsFromPropNonUnion(
altObj, prop, fnNode));
if (altObj.hasProperty(prop)) {
found = true;
}
}
}
if (found) {
return actions;
}
} else {
ObjectType objType = ObjectType.cast(jsType);
if (objType != null &&
!objType.isUnknownType() && objType.hasProperty(prop)) {
return getImplicitActionsFromPropNonUnion(objType, prop, fnNode);
}
}
// If we didn't find a type that has the property, then check if there
// exists a property with this name anywhere in the externs.
Set<ObjectType> types = getTypeRegistry().getTypesWithProperty(prop);
for (ObjectType type : types) {
actions.addAll(getImplicitActionsFromPropNonUnion(type, prop, fnNode));
}
return actions;
}
示例9: checkPropertyDeprecation
import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的package包/类
/**
* Checks the given GETPROP node to ensure that access restrictions are
* obeyed.
*/
private void checkPropertyDeprecation(NodeTraversal t, Node n, Node parent) {
// Don't bother checking constructors.
if (parent.getType() == Token.NEW) {
return;
}
ObjectType objectType =
ObjectType.cast(dereference(n.getFirstChild().getJSType()));
String propertyName = n.getLastChild().getString();
if (objectType != null) {
String deprecationInfo
= getPropertyDeprecationInfo(objectType, propertyName);
if (deprecationInfo != null &&
shouldEmitDeprecationWarning(t, n, parent)) {
if (!deprecationInfo.isEmpty()) {
compiler.report(
JSError.make(t, n, DEPRECATED_PROP_REASON, propertyName,
validator.getReadableJSTypeName(n.getFirstChild(), true),
deprecationInfo));
} else {
compiler.report(
JSError.make(t, n, DEPRECATED_PROP, propertyName,
validator.getReadableJSTypeName(n.getFirstChild(), true)));
}
}
}
}
示例10: ensurePropertyDeclared
import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的package包/类
/**
* Defines a declared property if it has not been defined yet.
*
* This handles the case where a property is declared on an object where
* the object type is inferred, and so the object type will not
* be known in {@code TypedScopeCreator}.
*/
private void ensurePropertyDeclared(Node getprop) {
ObjectType ownerType = ObjectType.cast(
getJSType(getprop.getFirstChild()).restrictByNotNullOrUndefined());
if (ownerType != null) {
ensurePropertyDeclaredHelper(getprop, ownerType);
}
}
示例11: traverseGetElem
import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的package包/类
private FlowScope traverseGetElem(Node n, FlowScope scope) {
scope = traverseChildren(n, scope);
ObjectType objType = ObjectType.cast(
getJSType(n.getFirstChild()).restrictByNotNullOrUndefined());
if (objType != null) {
JSType type = objType.getParameterType();
if (type != null) {
n.setJSType(type);
}
}
return dereferencePointer(n.getFirstChild(), scope);
}
示例12: getPropertyType
import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的package包/类
private JSType getPropertyType(JSType objType, String propName,
Node n, FlowScope scope) {
// Scopes sometimes contain inferred type info about qualified names.
String qualifiedName = n.getQualifiedName();
StaticSlot<JSType> var = scope.getSlot(qualifiedName);
if (var != null) {
JSType varType = var.getType();
if (varType != null) {
if (varType.equals(getNativeType(UNKNOWN_TYPE)) &&
var != syntacticScope.getSlot(qualifiedName)) {
// If the type of this qualified name has been checked in this scope,
// then use CHECKED_UNKNOWN_TYPE instead to indicate that.
return getNativeType(CHECKED_UNKNOWN_TYPE);
} else {
return varType;
}
}
}
JSType propertyType = null;
if (objType != null) {
propertyType = objType.findPropertyType(propName);
}
if ((propertyType == null || propertyType.isUnknownType()) &&
qualifiedName != null) {
// If we find this node in the registry, then we can infer its type.
ObjectType regType = ObjectType.cast(registry.getType(qualifiedName));
if (regType != null) {
propertyType = regType.getConstructor();
}
}
return propertyType;
}
示例13: isInvalidatingType
import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的package包/类
@Override public boolean isInvalidatingType(JSType type) {
if (type == null || invalidatingTypes.contains(type) ||
(type.isNamedType() && type.isUnknownType())) {
return true;
}
ObjectType objType = ObjectType.cast(type);
return objType != null && !objType.hasReferenceName();
}
示例14: getTypeWithProperty
import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的package包/类
@Override public ObjectType getTypeWithProperty(String field, JSType type) {
if (!(type instanceof ObjectType)) {
if (type.autoboxesTo() != null) {
type = type.autoboxesTo();
} else {
return null;
}
}
// Ignore the prototype itself at all times.
if ("prototype".equals(field)) {
return null;
}
// We look up the prototype chain to find the highest place (if any) that
// this appears. This will make references to overriden properties look
// like references to the initial property, so they are renamed alike.
ObjectType foundType = null;
ObjectType objType = ObjectType.cast(type);
while (objType != null && objType.getImplicitPrototype() != objType) {
if (objType.hasOwnProperty(field)) {
foundType = objType;
}
objType = objType.getImplicitPrototype();
}
// If the property does not exist on the referenced type but the original
// type is an object type, see if any subtype has the property.
if (foundType == null) {
ObjectType maybeType = ObjectType.cast(
registry.getGreatestSubtypeWithProperty(type, field));
// getGreatestSubtypeWithProperty does not guarantee that the property
// is defined on the returned type, it just indicates that it might be,
// so we have to double check.
if (maybeType != null && maybeType.hasOwnProperty(field)) {
foundType = maybeType;
}
}
return foundType;
}
示例15: inferThisType
import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的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;
}