本文整理汇总了Java中com.google.javascript.rhino.jstype.ObjectType.defineDeclaredProperty方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectType.defineDeclaredProperty方法的具体用法?Java ObjectType.defineDeclaredProperty怎么用?Java ObjectType.defineDeclaredProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.javascript.rhino.jstype.ObjectType
的用法示例。
在下文中一共展示了ObjectType.defineDeclaredProperty方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ensurePropertyDeclaredHelper
import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的package包/类
/**
* Declares a property on its owner, if necessary.
* @return True if a property was declared.
*/
private boolean ensurePropertyDeclaredHelper(
Node getprop, ObjectType objectType) {
String propName = getprop.getLastChild().getString();
String qName = getprop.getQualifiedName();
if (qName != null) {
Var var = syntacticScope.getVar(qName);
if (var != null && !var.isTypeInferred()) {
// Handle normal declarations that could not be addressed earlier.
if (propName.equals("prototype") ||
// Handle prototype declarations that could not be addressed earlier.
(!objectType.hasOwnProperty(propName) &&
(!objectType.isInstanceType() ||
(var.isExtern() && !objectType.isNativeObjectType())))) {
return objectType.defineDeclaredProperty(
propName, var.getType(), var.isExtern());
}
}
}
return false;
}
示例2: createInstance
import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的package包/类
/** Creates a fake instance with the given description. */
private ConcreteInstanceType createInstance(
String name, String... propNames) {
ObjectType objType = typeRegistry.createObjectType(name, null,
typeRegistry.createObjectType(name + ".prototype", null, null));
for (int i = 0; i < propNames.length; ++i) {
objType.defineDeclaredProperty(propNames[i], unknownType, false);
}
return new ConcreteInstanceType(factory, objType);
}
示例3: addMethod
import com.google.javascript.rhino.jstype.ObjectType; //导入方法依赖的package包/类
private static void addMethod(
JSTypeRegistry registry, ObjectType receivingType, String methodName,
JSType returnType) {
receivingType.defineDeclaredProperty(methodName,
new FunctionType(registry, null, null, null, returnType), true);
}
示例4: 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)));
}
}
}
}
示例5: 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);
}
}
}
}
}