本文整理汇总了Java中jdk.nashorn.internal.runtime.Property.getType方法的典型用法代码示例。如果您正苦于以下问题:Java Property.getType方法的具体用法?Java Property.getType怎么用?Java Property.getType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.nashorn.internal.runtime.Property
的用法示例。
在下文中一共展示了Property.getType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createObject
import jdk.nashorn.internal.runtime.Property; //导入方法依赖的package包/类
private Object createObject(final PropertyMap propertyMap, final List<Object> values, final ArrayData arrayData) {
final long[] primitiveSpill = dualFields ? new long[values.size()] : null;
final Object[] objectSpill = new Object[values.size()];
for (final Property property : propertyMap.getProperties()) {
if (!dualFields || property.getType() == Object.class) {
objectSpill[property.getSlot()] = values.get(property.getSlot());
} else {
primitiveSpill[property.getSlot()] = ObjectClassGenerator.pack((Number) values.get(property.getSlot()));
}
}
final ScriptObject object = dualFields ?
new JD(propertyMap, primitiveSpill, objectSpill) : new JO(propertyMap, null, objectSpill);
object.setInitialProto(global.getObjectPrototype());
object.setArray(arrayData);
return object;
}
示例2: getPropertyType
import jdk.nashorn.internal.runtime.Property; //导入方法依赖的package包/类
private static Type getPropertyType(final ScriptObject sobj, final String name) {
final FindProperty find = sobj.findProperty(name, true);
if (find == null) {
return null;
}
final Property property = find.getProperty();
final Class<?> propertyClass = property.getType();
if (propertyClass == null) {
// propertyClass == null means its value is Undefined. It is probably not initialized yet, so we won't make
// a type assumption yet.
return null;
} else if (propertyClass.isPrimitive()) {
return Type.typeFor(propertyClass);
}
final ScriptObject owner = find.getOwner();
if (property.hasGetterFunction(owner)) {
// Can have side effects, so we can't safely evaluate it; since !propertyClass.isPrimitive(), it's Object.
return Type.OBJECT;
}
// Safely evaluate the property, and return the narrowest type for the actual value (e.g. Type.INT for a boxed
// integer).
final Object value = property.needsDeclaration() ? ScriptRuntime.UNDEFINED : property.getObjectValue(owner, owner);
if (value == ScriptRuntime.UNDEFINED) {
return null;
}
return Type.typeFor(JSType.unboxedFieldType(value));
}