本文整理汇总了Java中jdk.nashorn.internal.objects.NativeArray类的典型用法代码示例。如果您正苦于以下问题:Java NativeArray类的具体用法?Java NativeArray怎么用?Java NativeArray使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NativeArray类属于jdk.nashorn.internal.objects包,在下文中一共展示了NativeArray类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getArrayConverter
import jdk.nashorn.internal.objects.NativeArray; //导入依赖的package包/类
/**
* Returns a guarded invocation that converts from a source type that is NativeArray to a Java array or List or
* Deque type.
* @param sourceType the source type (presumably NativeArray a superclass of it)
* @param targetType the target type (presumably an array type, or List or Deque)
* @return a guarded invocation that converts from the source type to the target type. null is returned if
* either the source type is neither NativeArray, nor a superclass of it, or if the target type is not an array
* type, List, or Deque.
*/
private static GuardedInvocation getArrayConverter(final Class<?> sourceType, final Class<?> targetType) {
final boolean isSourceTypeNativeArray = sourceType == NativeArray.class;
// If source type is more generic than NativeArray class, we'll need to use a guard
final boolean isSourceTypeGeneric = !isSourceTypeNativeArray && sourceType.isAssignableFrom(NativeArray.class);
if (isSourceTypeNativeArray || isSourceTypeGeneric) {
final MethodHandle guard = isSourceTypeGeneric ? IS_NATIVE_ARRAY : null;
if(targetType.isArray()) {
return new GuardedInvocation(ARRAY_CONVERTERS.get(targetType), guard);
}
if(targetType == List.class) {
return new GuardedInvocation(JSType.TO_JAVA_LIST.methodHandle(), guard);
}
if(targetType == Deque.class) {
return new GuardedInvocation(JSType.TO_JAVA_DEQUE.methodHandle(), guard);
}
}
return null;
}
示例2: getDynamicSignature
import jdk.nashorn.internal.objects.NativeArray; //导入依赖的package包/类
/**
* Helper function to generate a function signature based on stack contents
* and argument count and return type
*
* @param returnType return type
* @param argCount argument count
*
* @return function signature for stack contents
*/
private String getDynamicSignature(final Type returnType, final int argCount) {
final Type[] paramTypes = new Type[argCount];
int pos = 0;
for (int i = argCount - 1; i >= 0; i--) {
Type pt = stack.peek(pos++);
// "erase" specific ScriptObject subtype info - except for NativeArray.
// NativeArray is used for array/List/Deque conversion for Java calls.
if (ScriptObject.class.isAssignableFrom(pt.getTypeClass()) &&
!NativeArray.class.isAssignableFrom(pt.getTypeClass())) {
pt = Type.SCRIPT_OBJECT;
}
paramTypes[i] = pt;
}
final String descriptor = Type.getMethodDescriptor(returnType, paramTypes);
for (int i = 0; i < argCount; i++) {
popType(paramTypes[argCount - i - 1]);
}
return descriptor;
}
示例3: getArrayConverter
import jdk.nashorn.internal.objects.NativeArray; //导入依赖的package包/类
/**
* Returns a guarded invocation that converts from a source type that is NativeArray to a Java array or List or
* Queue or Deque or Collection type.
* @param sourceType the source type (presumably NativeArray a superclass of it)
* @param targetType the target type (presumably an array type, or List or Queue, or Deque, or Collection)
* @return a guarded invocation that converts from the source type to the target type. null is returned if
* either the source type is neither NativeArray, nor a superclass of it, or if the target type is not an array
* type, List, Queue, Deque, or Collection.
*/
private static GuardedInvocation getArrayConverter(final Class<?> sourceType, final Class<?> targetType) {
final boolean isSourceTypeNativeArray = sourceType == NativeArray.class;
// If source type is more generic than NativeArray class, we'll need to use a guard
final boolean isSourceTypeGeneric = !isSourceTypeNativeArray && sourceType.isAssignableFrom(NativeArray.class);
if (isSourceTypeNativeArray || isSourceTypeGeneric) {
final MethodHandle guard = isSourceTypeGeneric ? IS_NATIVE_ARRAY : null;
if(targetType.isArray()) {
return new GuardedInvocation(ARRAY_CONVERTERS.get(targetType), guard);
} else if(targetType == List.class) {
return new GuardedInvocation(TO_LIST, guard);
} else if(targetType == Deque.class) {
return new GuardedInvocation(TO_DEQUE, guard);
} else if(targetType == Queue.class) {
return new GuardedInvocation(TO_QUEUE, guard);
} else if(targetType == Collection.class) {
return new GuardedInvocation(TO_COLLECTION, guard);
}
}
return null;
}
示例4: argsToString
import jdk.nashorn.internal.objects.NativeArray; //导入依赖的package包/类
/**
* Joins strings by single space between and quoting args containing any space.
* @param arr array of strings
* @return joined quoted strings
*/
public String argsToString(NativeArray arr) {
StringBuilder sb = new StringBuilder();
Iterator<Object> iter = arr.valueIterator();
while (iter.hasNext()) {
String arg = (String) iter.next();
if (arg.length() == 0 || arg.indexOf(' ') >= 0) {
sb.append("\"");
sb.append(arg);
sb.append("\"");
}
else {
sb.append(arg);
}
if (iter.hasNext()) {
sb.append(' ');
}
}
return sb.toString();
}
示例5: getArrayConverter
import jdk.nashorn.internal.objects.NativeArray; //导入依赖的package包/类
/**
* Returns a guarded invocation that converts from a source type that is NativeArray to a Java array or List or
* Deque type.
* @param sourceType the source type (presumably NativeArray a superclass of it)
* @param targetType the target type (presumably an array type, or List or Deque)
* @return a guarded invocation that converts from the source type to the target type. null is returned if
* either the source type is neither NativeArray, nor a superclass of it, or if the target type is not an array
* type, List, or Deque.
*/
private static GuardedInvocation getArrayConverter(final Class<?> sourceType, final Class<?> targetType) {
final boolean isSourceTypeNativeArray = sourceType == NativeArray.class;
// If source type is more generic than ScriptFunction class, we'll need to use a guard
final boolean isSourceTypeGeneric = !isSourceTypeNativeArray && sourceType.isAssignableFrom(NativeArray.class);
if (isSourceTypeNativeArray || isSourceTypeGeneric) {
final MethodHandle guard = isSourceTypeGeneric ? IS_NATIVE_ARRAY : null;
if(targetType.isArray()) {
return new GuardedInvocation(ARRAY_CONVERTERS.get(targetType), guard);
}
if(targetType == List.class) {
return new GuardedInvocation(JSType.TO_JAVA_LIST.methodHandle(), guard);
}
if(targetType == Deque.class) {
return new GuardedInvocation(JSType.TO_JAVA_DEQUE.methodHandle(), guard);
}
}
return null;
}
示例6: compareConversion
import jdk.nashorn.internal.objects.NativeArray; //导入依赖的package包/类
@Override
public Comparison compareConversion(final Class<?> sourceType, final Class<?> targetType1, final Class<?> targetType2) {
if(sourceType == NativeArray.class) {
// Prefer lists, as they're less costly to create than arrays.
if(isList(targetType1)) {
if(!isList(targetType2)) {
return Comparison.TYPE_1_BETTER;
}
} else if(isList(targetType2)) {
return Comparison.TYPE_2_BETTER;
}
// Then prefer arrays
if(targetType1.isArray()) {
if(!targetType2.isArray()) {
return Comparison.TYPE_1_BETTER;
}
} else if(targetType2.isArray()) {
return Comparison.TYPE_2_BETTER;
}
}
if(ScriptObject.class.isAssignableFrom(sourceType)) {
// Prefer interfaces
if(targetType1.isInterface()) {
if(!targetType2.isInterface()) {
return Comparison.TYPE_1_BETTER;
}
} else if(targetType2.isInterface()) {
return Comparison.TYPE_2_BETTER;
}
}
return Comparison.INDETERMINATE;
}
示例7: argConversionFilter
import jdk.nashorn.internal.objects.NativeArray; //导入依赖的package包/类
private static MethodHandle argConversionFilter(final Class<?> handleType, final Class<?> fromType) {
if (handleType == Object.class) {
if (fromType == Object.class) {
return EXPORT_ARGUMENT;
} else if (fromType == NativeArray.class) {
return EXPORT_NATIVE_ARRAY;
} else if (fromType == ScriptObject.class) {
return EXPORT_SCRIPT_OBJECT;
}
}
return null;
}
示例8: compareConversion
import jdk.nashorn.internal.objects.NativeArray; //导入依赖的package包/类
@Override
public Comparison compareConversion(final Class<?> sourceType, final Class<?> targetType1, final Class<?> targetType2) {
if(sourceType == NativeArray.class) {
// Prefer those types we can convert to with just a wrapper (cheaper than Java array creation).
if(isArrayPreferredTarget(targetType1)) {
if(!isArrayPreferredTarget(targetType2)) {
return Comparison.TYPE_1_BETTER;
}
} else if(isArrayPreferredTarget(targetType2)) {
return Comparison.TYPE_2_BETTER;
}
// Then prefer Java arrays
if(targetType1.isArray()) {
if(!targetType2.isArray()) {
return Comparison.TYPE_1_BETTER;
}
} else if(targetType2.isArray()) {
return Comparison.TYPE_2_BETTER;
}
}
if(ScriptObject.class.isAssignableFrom(sourceType)) {
// Prefer interfaces
if(targetType1.isInterface()) {
if(!targetType2.isInterface()) {
return Comparison.TYPE_1_BETTER;
}
} else if(targetType2.isInterface()) {
return Comparison.TYPE_2_BETTER;
}
}
return Comparison.INDETERMINATE;
}
示例9: exportNativeArray
import jdk.nashorn.internal.objects.NativeArray; //导入依赖的package包/类
@SuppressWarnings("unused")
private static Object exportNativeArray(final NativeArray arg) {
return exportArgument(arg, MIRROR_ALWAYS);
}
示例10: exportScriptArray
import jdk.nashorn.internal.objects.NativeArray; //导入依赖的package包/类
@SuppressWarnings("unused")
private static Object exportScriptArray(final NativeArray arg) {
return exportArgument(arg, MIRROR_ALWAYS);
}
示例11: getType
import jdk.nashorn.internal.objects.NativeArray; //导入依赖的package包/类
@Override
public Type getType(final Function<Symbol, Type> localVariableTypes) {
return Type.typeFor(NativeArray.class);
}
示例12: getType
import jdk.nashorn.internal.objects.NativeArray; //导入依赖的package包/类
@Override
public Type getType() {
return Type.typeFor(NativeArray.class);
}
示例13: testCanConvertScriptObjectSubclassToMirror
import jdk.nashorn.internal.objects.NativeArray; //导入依赖的package包/类
@Test
public void testCanConvertScriptObjectSubclassToMirror() {
assertCanConvertToMirror(NativeArray.class);
}