本文整理汇总了Java中com.google.javascript.rhino.jstype.ObjectType.defineInferredProperty方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectType.defineInferredProperty方法的具体用法?Java ObjectType.defineInferredProperty怎么用?Java ObjectType.defineInferredProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.javascript.rhino.jstype.ObjectType
的用法示例。
在下文中一共展示了ObjectType.defineInferredProperty方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolveStubDeclarations
import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的package包/类
/**
* Resolve any stub delcarations to unknown types if we could not
* find types for them during traversal.
*/
private void resolveStubDeclarations() {
for (StubDeclaration stub : stubDeclarations) {
Node n = stub.node;
Node parent = n.getParent();
String qName = n.getQualifiedName();
String propName = n.getLastChild().getString();
String ownerName = stub.ownerName;
boolean isExtern = stub.isExtern;
if (scope.isDeclared(qName, false)) {
continue;
}
// If we see a stub property, make sure to register this property
// in the type registry.
ObjectType ownerType = getObjectSlot(ownerName);
ObjectType unknownType = typeRegistry.getNativeObjectType(UNKNOWN_TYPE);
defineSlot(n, parent, unknownType, true);
if (ownerType != null &&
(isExtern || ownerType.isFunctionPrototypeType())) {
// If this is a stub for a prototype, just declare it
// as an unknown type. These are seen often in externs.
ownerType.defineInferredProperty(
propName, unknownType, isExtern);
} else {
typeRegistry.registerPropertyOnType(
propName, ownerType == null ? unknownType : ownerType);
}
}
}
示例2: traverseObjectLiteral
import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的package包/类
private FlowScope traverseObjectLiteral(Node n, FlowScope scope) {
if (n.getJSType() != null) {
// The node has already been traversed by the data-flow analysis
// framework. Don't re-generate the anonymous object as it might lead to
// pernicious bugs.
return scope;
}
ObjectType objectType = registry.createAnonymousObjectType();
for (Node name = n.getFirstChild(); name != null;
name = name.getNext().getNext()) {
Node value = name.getNext();
scope = traverse(name, scope);
scope = traverse(value, scope);
String memberName = NodeUtil.getStringValue(name);
if (memberName != null) {
// TODO(nicksantos): We need to fix the parser so that we can
// attach JSDoc to the individual elements of object literals.
// Right now, this is not possible.
objectType.defineInferredProperty(memberName, getJSType(value), false);
} else {
n.setJSType(getNativeType(UNKNOWN_TYPE));
return scope;
}
}
n.setJSType(objectType);
return scope;
}
示例3: defineSlot
import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的package包/类
/**
* Defines a typed variable. The defining node will be annotated with the
* variable's type of {@link JSTypeNative#UNKNOWN_TYPE} if its type is
* inferred.
*
* Slots may be any variable or any qualified name in the global scope.
*
* @param n the defining NAME or GETPROP node.
* @param parent the {@code n}'s parent.
* @param type the variable's type. It may be {@code null} if
* {@code inferred} is {@code true}.
*/
void defineSlot(Node n, Node parent, JSType type, boolean inferred) {
Preconditions.checkArgument(inferred || type != null);
// Only allow declarations of NAMEs and qualfied names.
boolean shouldDeclareOnGlobalThis = false;
if (n.getType() == Token.NAME) {
Preconditions.checkArgument(
parent.getType() == Token.FUNCTION ||
parent.getType() == Token.VAR ||
parent.getType() == Token.LP ||
parent.getType() == Token.CATCH);
shouldDeclareOnGlobalThis = scope.isGlobal() &&
(parent.getType() == Token.VAR ||
parent.getType() == Token.FUNCTION);
} else {
Preconditions.checkArgument(
n.getType() == Token.GETPROP &&
(parent.getType() == Token.ASSIGN ||
parent.getType() == Token.EXPR_RESULT));
}
String variableName = n.getQualifiedName();
Preconditions.checkArgument(!variableName.isEmpty());
// declared in closest scope?
if (scope.isDeclared(variableName, false)) {
Var oldVar = scope.getVar(variableName);
validator.expectUndeclaredVariable(
sourceName, n, parent, oldVar, variableName, type);
} else {
if (!inferred) {
n.setJSType(type);
}
CompilerInput input = compiler.getInput(sourceName);
scope.declare(variableName, n, type, input, inferred);
if (shouldDeclareOnGlobalThis) {
ObjectType globalThis =
typeRegistry.getNativeObjectType(JSTypeNative.GLOBAL_THIS);
boolean isExtern = input.isExtern();
if (inferred) {
globalThis.defineInferredProperty(variableName,
type == null ?
typeRegistry.getNativeType(JSTypeNative.NO_TYPE) :
type,
isExtern);
} else {
globalThis.defineDeclaredProperty(variableName, type, isExtern);
}
}
// If we're in the global scope, also declare var.prototype
// in the scope chain.
if (scope.isGlobal() && type instanceof FunctionType) {
FunctionType fnType = (FunctionType) type;
if (fnType.isConstructor() || fnType.isInterface()) {
FunctionType superClassCtor = fnType.getSuperClassConstructor();
scope.declare(variableName + ".prototype", n,
fnType.getPrototype(), compiler.getInput(sourceName),
/* declared iff there's an explicit supertype */
superClassCtor == null ||
superClassCtor.getInstanceType().equals(
typeRegistry.getNativeType(OBJECT_TYPE)));
}
}
}
}
示例4: ensurePropertyDefined
import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的package包/类
/**
* Defines a property if the property has not been defined yet.
*/
private void ensurePropertyDefined(Node getprop, JSType rightType) {
ObjectType objectType = ObjectType.cast(
getJSType(getprop.getFirstChild()).restrictByNotNullOrUndefined());
if (objectType != null) {
if (ensurePropertyDeclaredHelper(getprop, objectType)) {
return;
}
String propName = getprop.getLastChild().getString();
if (!objectType.isPropertyTypeDeclared(propName)) {
// We do not want a "stray" assign to define an inferred property
// for every object of this type in the program. So we use a heuristic
// approach to determine whether to infer the propery.
//
// 1) If the property is already defined, join it with the previously
// inferred type.
// 2) If this isn't an instance object, define it.
// 3) If the property of an object is being assigned in the constructor,
// define it.
// 4) If this is a stub, define it.
// 5) Otherwise, do not define the type, but declare it in the registry
// so that we can use it for missing property checks.
if (objectType.hasProperty(propName) ||
!objectType.isInstanceType()) {
if ("prototype".equals(propName)) {
objectType.defineDeclaredProperty(propName, rightType, false);
} else {
objectType.defineInferredProperty(propName, rightType, false);
}
} else {
if (getprop.getFirstChild().getType() == Token.THIS &&
getJSType(syntacticScope.getRootNode()).isConstructor()) {
objectType.defineInferredProperty(propName, rightType, false);
} else {
registry.registerPropertyOnType(propName, objectType);
}
}
}
}
}